-
Notifications
You must be signed in to change notification settings - Fork 725
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow configuring push gossip to send txs to validators by stake #2835
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
158c202
Implement Top on the p2p validator set manager
StephenButtolph 0199b10
Combine AppGossip and AppGossipSpecific
StephenButtolph b6b03f5
nit
StephenButtolph b407c2e
nit
StephenButtolph 62a5aef
nit
StephenButtolph c955435
nit
StephenButtolph e5f591e
Merge branch 'combine-app-gossip-implementations' into validator-rank…
StephenButtolph 6c9dcf2
Integrate stake weighted selection
StephenButtolph 5f9a281
Update coreth
StephenButtolph 79448aa
document
StephenButtolph 50e01f2
nit
StephenButtolph c157015
merged
StephenButtolph 7b2b4d7
add comment
StephenButtolph 568b7c5
potato potato
StephenButtolph 9e6fe69
Add metrics
StephenButtolph 0d0277c
Merge branch 'master' into validator-rankings
StephenButtolph 293dd9e
Merge branch 'master' into validator-rankings
StephenButtolph 5ecde55
fix merge
StephenButtolph f37699e
temp merge
StephenButtolph dcf67e8
update coreth
StephenButtolph 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 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"github.com/ava-labs/avalanchego/utils/bloom" | ||
"github.com/ava-labs/avalanchego/utils/buffer" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
) | ||
|
||
const ( | ||
|
@@ -89,6 +90,7 @@ type Metrics struct { | |
receivedBytes *prometheus.CounterVec | ||
tracking *prometheus.GaugeVec | ||
trackingLifetimeAverage prometheus.Gauge | ||
topValidators *prometheus.GaugeVec | ||
} | ||
|
||
// NewMetrics returns a common set of metrics | ||
|
@@ -127,6 +129,11 @@ func NewMetrics( | |
Name: "gossip_tracking_lifetime_average", | ||
Help: "average duration a gossipable has been tracked (ns)", | ||
}), | ||
topValidators: prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: namespace, | ||
Name: "top_validators", | ||
Help: "number of validators gossipables are sent to due to stake", | ||
}, metricLabels), | ||
} | ||
err := utils.Err( | ||
metrics.Register(m.sentCount), | ||
|
@@ -135,6 +142,7 @@ func NewMetrics( | |
metrics.Register(m.receivedBytes), | ||
metrics.Register(m.tracking), | ||
metrics.Register(m.trackingLifetimeAverage), | ||
metrics.Register(m.topValidators), | ||
) | ||
return m, err | ||
} | ||
|
@@ -262,6 +270,7 @@ func (p *PullGossiper[_]) handleResponse( | |
func NewPushGossiper[T Gossipable]( | ||
marshaller Marshaller[T], | ||
mempool Set[T], | ||
validators p2p.ValidatorSubset, | ||
client *p2p.Client, | ||
metrics Metrics, | ||
gossipParams BranchingFactor, | ||
|
@@ -288,6 +297,7 @@ func NewPushGossiper[T Gossipable]( | |
return &PushGossiper[T]{ | ||
marshaller: marshaller, | ||
set: mempool, | ||
validators: validators, | ||
client: client, | ||
metrics: metrics, | ||
gossipParams: gossipParams, | ||
|
@@ -306,6 +316,7 @@ func NewPushGossiper[T Gossipable]( | |
type PushGossiper[T Gossipable] struct { | ||
marshaller Marshaller[T] | ||
set Set[T] | ||
validators p2p.ValidatorSubset | ||
client *p2p.Client | ||
metrics Metrics | ||
|
||
|
@@ -323,9 +334,20 @@ type PushGossiper[T Gossipable] struct { | |
} | ||
|
||
type BranchingFactor struct { | ||
Validators int | ||
// StakePercentage determines the percentage of stake that should have | ||
// gossip sent to based on the inverse CDF of stake weights. This value does | ||
// not account for the connectivity of the nodes. | ||
StakePercentage float64 | ||
// Validators specifies the number of connected validators, in addition to | ||
// any validators sent from the StakePercentage parameter, to send gossip | ||
// to. These validators are sampled uniformly rather than by stake. | ||
Validators int | ||
// NonValidators specifies the number of connected non-validators to send | ||
// gossip to. | ||
NonValidators int | ||
Peers int | ||
// Peers specifies the number of connected validators or non-validators, in | ||
// addition to the number sent due to other configs, to send gossip to. | ||
Peers int | ||
} | ||
|
||
func (b *BranchingFactor) Verify() error { | ||
|
@@ -372,6 +394,7 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { | |
p.toGossip, | ||
p.toRegossip, | ||
&cache.Empty[ids.ID, struct{}]{}, // Don't mark dropped unsent transactions as discarded | ||
unsentLabels, | ||
); err != nil { | ||
return fmt.Errorf("unexpected error during gossip: %w", err) | ||
} | ||
|
@@ -383,6 +406,7 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error { | |
p.toRegossip, | ||
p.toRegossip, | ||
p.discarded, // Mark dropped sent transactions as discarded | ||
sentLabels, | ||
); err != nil { | ||
return fmt.Errorf("unexpected error during regossip: %w", err) | ||
} | ||
|
@@ -396,6 +420,7 @@ func (p *PushGossiper[T]) gossip( | |
toGossip buffer.Deque[T], | ||
toRegossip buffer.Deque[T], | ||
discarded cache.Cacher[ids.ID, struct{}], | ||
metricsLabels prometheus.Labels, | ||
) error { | ||
var ( | ||
sentBytes = 0 | ||
|
@@ -450,6 +475,9 @@ func (p *PushGossiper[T]) gossip( | |
if err != nil { | ||
return err | ||
} | ||
|
||
validatorsByStake := p.validators.Top(ctx, gossipParams.StakePercentage) | ||
|
||
sentCountMetric, err := p.metrics.sentCount.GetMetricWith(pushLabels) | ||
if err != nil { | ||
return fmt.Errorf("failed to get sent count metric: %w", err) | ||
|
@@ -458,12 +486,18 @@ func (p *PushGossiper[T]) gossip( | |
if err != nil { | ||
return fmt.Errorf("failed to get sent bytes metric: %w", err) | ||
} | ||
topValidatorsMetric, err := p.metrics.topValidators.GetMetricWith(metricsLabels) | ||
if err != nil { | ||
return fmt.Errorf("failed to get top validators metric: %w", err) | ||
} | ||
sentCountMetric.Add(float64(len(gossip))) | ||
sentBytesMetric.Add(float64(sentBytes)) | ||
topValidatorsMetric.Set(float64(len(validatorsByStake))) | ||
|
||
return p.client.AppGossip( | ||
ctx, | ||
common.SendConfig{ | ||
NodeIDs: set.Of(validatorsByStake...), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Validators: gossipParams.Validators, | ||
NonValidators: gossipParams.NonValidators, | ||
Peers: gossipParams.Peers, | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wonder if it makes sense to take the
num
strategy here like we do for warp?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we don't need to because we don't require determinism.