-
Notifications
You must be signed in to change notification settings - Fork 804
uplift: Add gossip
package from evm repositories
#4310
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
JonathanOppenheimer
wants to merge
7
commits into
master
Choose a base branch
from
JonathanOppenheimer/uplift-gossip
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−0
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28da417
uplift gossip package
JonathanOppenheimer e7a7faf
lint
JonathanOppenheimer 5006786
Merge branch 'master' into JonathanOppenheimer/uplift-gossip
JonathanOppenheimer a3d7ed9
move tx type above generator
JonathanOppenheimer bdc5250
Merge branch 'master' into JonathanOppenheimer/uplift-gossip
JonathanOppenheimer 8fded3c
change return type
JonathanOppenheimer 30a4449
Merge branch 'master' into JonathanOppenheimer/uplift-gossip
JonathanOppenheimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package gossip | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/network/p2p" | ||
"github.com/ava-labs/avalanchego/network/p2p/gossip" | ||
"github.com/ava-labs/avalanchego/snow/engine/common" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
) | ||
|
||
var _ p2p.Handler = (*txGossipHandler)(nil) | ||
|
||
type txGossipHandler struct { | ||
appGossipHandler p2p.Handler | ||
appRequestHandler p2p.Handler | ||
} | ||
|
||
func NewTxGossipHandler[T gossip.Gossipable]( | ||
log logging.Logger, | ||
marshaller gossip.Marshaller[T], | ||
mempool gossip.Set[T], | ||
metrics gossip.Metrics, | ||
maxMessageSize int, | ||
throttlingPeriod time.Duration, | ||
requestsPerPeer float64, | ||
validators p2p.ValidatorSet, | ||
registerer prometheus.Registerer, | ||
namespace string, | ||
) (*txGossipHandler, error) { | ||
// push gossip messages can be handled from any peer | ||
handler := gossip.NewHandler( | ||
log, | ||
marshaller, | ||
mempool, | ||
metrics, | ||
maxMessageSize, | ||
) | ||
|
||
throttledHandler, err := p2p.NewDynamicThrottlerHandler( | ||
log, | ||
handler, | ||
validators, | ||
throttlingPeriod, | ||
requestsPerPeer, | ||
registerer, | ||
namespace, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize throttler handler: %w", err) | ||
} | ||
|
||
// pull gossip requests are filtered by validators and are throttled | ||
// to prevent spamming | ||
validatorHandler := p2p.NewValidatorHandler( | ||
throttledHandler, | ||
validators, | ||
log, | ||
) | ||
|
||
return &txGossipHandler{ | ||
appGossipHandler: handler, | ||
appRequestHandler: validatorHandler, | ||
}, nil | ||
} | ||
|
||
func (t *txGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte) { | ||
t.appGossipHandler.AppGossip(ctx, nodeID, gossipBytes) | ||
} | ||
|
||
func (t *txGossipHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) { | ||
return t.appRequestHandler.AppRequest(ctx, nodeID, deadline, requestBytes) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.