Skip to content

Proactively detect and report duplicate gossiped/malformed messages #3839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: master
Choose a base branch
from

Conversation

tsachiherman
Copy link
Contributor

@tsachiherman tsachiherman commented Mar 25, 2025

Why this should be merged

This PR modify the way the existing gossip implementation reports dropped incoming transaction.
When reporting the gossip_count and gossip_bytes for received messages, an additional label was added : dropped. This label would specify the reason for a transaction to be dropped ( malformed / duplicate / other ) in case it was dropped. ( not otherwise ).

How this works

To support the existing avalanchego VMs, a simplified mempool was created. This mempool maintain a map of all the pending transaction, and would label a duplicate transaction as such. The two VMs that are using the gossip, avm and platformvm were modified to use this as the backing mempool in addition to the existing vms/txs/mempool.

Supporting the duplicate transaction on the coreth proven to be slightly more complicated, due to it's subpool architecture. In order to support both cases, the gossip.Metrics was extended to allow labeling transaction during the mempool.Add execution.

The existing, and updated metrics related logic was moved from gossip.go into metrics.go. This cleaned up the former from metrics related logic.

Related PRs ?

The coreth PR is ava-labs/coreth#935

Need to be documented in RELEASES.md?

No

@tsachiherman tsachiherman self-assigned this Mar 25, 2025
@tsachiherman tsachiherman changed the title Tsachi/add duplicate gossip metrics Proactively detect and report duplicate gossiped messages Mar 26, 2025
@tsachiherman tsachiherman marked this pull request as ready for review March 26, 2025 18:09
@tsachiherman tsachiherman force-pushed the tsachi/add-duplicate-gossip-metrics branch from efb20b5 to 6a2bf8e Compare April 14, 2025 20:26
@tsachiherman tsachiherman changed the title Proactively detect and report duplicate gossiped messages Proactively detect and report duplicate gossiped/malformed messages Apr 14, 2025
@@ -119,7 +118,7 @@ func (g *gossipMempool) Add(tx *txs.Tx) error {
// Verify the tx at the currently preferred state
if err := g.txVerifier.VerifyTx(tx); err != nil {
g.Mempool.MarkDropped(txID, err)
return err
return fmt.Errorf("%w: transaction %s verification failed - %s", gossip.ErrGossipableMalformed, txID, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we need a separate error type for malformed vs verification failing

@tsachiherman tsachiherman requested a review from joshua-kim April 22, 2025 18:47
droppedLabel = "dropped"

droppedMalformed = "malformed"
DroppedDuplicate = "duplicate"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to export this label. Beside the code inside the gossip package, we use it in the coreth implementation along with the ObserveIncomingGossipable call. We can definitely define a separate label text ( doesn't have to be duplicate ). As a starting point, I think that keeping it the same is good enough. We can always change that later on if we see that it's unused/unjustified/etc.


"github.com/ava-labs/avalanchego/ids"

xmempool "github.com/ava-labs/avalanchego/vms/txs/mempool"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid having a dependency on vms... I think one way to avoid this is to just remove the error type we're importing but if we really wanted to keep an error we should just define it here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll "port" the error type into here.


// dropped indicate that the gossipable element was not added to the set due to some reason.
// for sent message, we'll use notReceive below.
droppedLabel = "dropped"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the naming for these to be extremely confusing because we use "dropped" even for outbound gossip, for which we can't ever actually drop it (and that's why we have the not_receive label). Without looking at the code I wouldn't understand how to interpret these metric names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to have sentPushLabels and receivedPushLabels defined as a separate counter vector.

var ErrDuplicateTx = xmempool.ErrDuplicateTx

type Mempool[T Gossipable] interface {
Add(tx T) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind us changing names to be tx instead of gossipable going forwards, but whatever we do we should be consistent in this diff (inconsistent w/ handleIncomingGossipables). I actually prefer tx naming, the only reason we use gossipables in the current code is because i thought we were going to use this for ip gossip, but we only ended up using this for txs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me name the tx in the gossip package gossipable for now. We can make a change on the next PR. I want to keep the code consistent and make continues improvements.

tsachiherman and others added 4 commits April 25, 2025 11:09
Co-authored-by: Joshua Kim <[email protected]>
Signed-off-by: Tsachi Herman <[email protected]>
Co-authored-by: Joshua Kim <[email protected]>
Signed-off-by: Tsachi Herman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants