-
Notifications
You must be signed in to change notification settings - Fork 741
Add metric to track the stake weight of block providers #2376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f752ea8
Add metric to track the stake weight of block providers
StephenButtolph 38f29fb
Merge branch 'dev' into add-stake-weight-metric
StephenButtolph 2f61dd1
fix
StephenButtolph 81d6c00
Merge branch 'add-stake-weight-metric' of github.com:ava-labs/avalanc…
StephenButtolph 328cc85
Merge branch 'dev' into add-stake-weight-metric
StephenButtolph 6329d96
rename nit
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 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
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
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 |
---|---|---|
|
@@ -444,7 +444,7 @@ func (t *Transitive) Start(ctx context.Context, startReqID uint32) error { | |
default: | ||
for _, blk := range options { | ||
// note that deliver will set the VM's preference | ||
if err := t.deliver(ctx, blk, false); err != nil { | ||
if err := t.deliver(ctx, t.Ctx.NodeID, blk, false); err != nil { | ||
return err | ||
} | ||
} | ||
|
@@ -650,7 +650,7 @@ func (t *Transitive) issueFrom(ctx context.Context, nodeID ids.NodeID, blk snowm | |
// issue [blk] and its ancestors to consensus. | ||
blkID := blk.ID() | ||
for !t.wasIssued(blk) { | ||
if err := t.issue(ctx, blk, false); err != nil { | ||
if err := t.issue(ctx, nodeID, blk, false); err != nil { | ||
return false, err | ||
} | ||
|
||
|
@@ -690,7 +690,7 @@ func (t *Transitive) issueWithAncestors(ctx context.Context, blk snowman.Block) | |
// issue [blk] and its ancestors into consensus | ||
status := blk.Status() | ||
for status.Fetched() && !t.wasIssued(blk) { | ||
err := t.issue(ctx, blk, true) | ||
err := t.issue(ctx, t.Ctx.NodeID, blk, true) | ||
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. I'm assuming this is only called after 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. Correct - |
||
if err != nil { | ||
return false, err | ||
} | ||
|
@@ -732,7 +732,7 @@ func (t *Transitive) wasIssued(blk snowman.Block) bool { | |
// Issue [blk] to consensus once its ancestors have been issued. | ||
// If [push] is true, a push query will be used. Otherwise, a pull query will be | ||
// used. | ||
func (t *Transitive) issue(ctx context.Context, blk snowman.Block, push bool) error { | ||
func (t *Transitive) issue(ctx context.Context, nodeID ids.NodeID, blk snowman.Block, push bool) error { | ||
blkID := blk.ID() | ||
|
||
// mark that the block is queued to be added to consensus once its ancestors have been | ||
|
@@ -743,9 +743,10 @@ func (t *Transitive) issue(ctx context.Context, blk snowman.Block, push bool) er | |
|
||
// Will add [blk] to consensus once its ancestors have been | ||
i := &issuer{ | ||
t: t, | ||
blk: blk, | ||
push: push, | ||
t: t, | ||
nodeID: nodeID, | ||
blk: blk, | ||
push: push, | ||
} | ||
|
||
// block on the parent if needed | ||
|
@@ -849,7 +850,7 @@ func (t *Transitive) sendQuery( | |
// issue [blk] to consensus | ||
// If [push] is true, a push query will be used. Otherwise, a pull query will be | ||
// used. | ||
func (t *Transitive) deliver(ctx context.Context, blk snowman.Block, push bool) error { | ||
func (t *Transitive) deliver(ctx context.Context, nodeID ids.NodeID, blk snowman.Block, push bool) error { | ||
blkID := blk.ID() | ||
if t.Consensus.Decided(blk) || t.Consensus.Processing(blkID) { | ||
return nil | ||
|
@@ -875,7 +876,7 @@ func (t *Transitive) deliver(ctx context.Context, blk snowman.Block, push bool) | |
// By ensuring that the parent is either processing or accepted, it is | ||
// guaranteed that the parent was successfully verified. This means that | ||
// calling Verify on this block is allowed. | ||
blkAdded, err := t.addUnverifiedBlockToConsensus(ctx, blk) | ||
blkAdded, err := t.addUnverifiedBlockToConsensus(ctx, nodeID, blk) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -899,7 +900,7 @@ func (t *Transitive) deliver(ctx context.Context, blk snowman.Block, push bool) | |
} | ||
|
||
for _, blk := range options { | ||
blkAdded, err := t.addUnverifiedBlockToConsensus(ctx, blk) | ||
blkAdded, err := t.addUnverifiedBlockToConsensus(ctx, nodeID, blk) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -979,12 +980,13 @@ func (t *Transitive) addToNonVerifieds(blk snowman.Block) { | |
|
||
// addUnverifiedBlockToConsensus returns whether the block was added and an | ||
// error if one occurred while adding it to consensus. | ||
func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snowman.Block) (bool, error) { | ||
func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, nodeID ids.NodeID, blk snowman.Block) (bool, error) { | ||
blkID := blk.ID() | ||
|
||
// make sure this block is valid | ||
if err := blk.Verify(ctx); err != nil { | ||
t.Ctx.Log.Debug("block verification failed", | ||
zap.Stringer("nodeID", nodeID), | ||
zap.Stringer("blkID", blkID), | ||
zap.Error(err), | ||
) | ||
|
@@ -997,7 +999,9 @@ func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snow | |
t.nonVerifieds.Remove(blkID) | ||
t.nonVerifiedCache.Evict(blkID) | ||
t.metrics.numNonVerifieds.Set(float64(t.nonVerifieds.Len())) | ||
t.metrics.issuerStake.Observe(float64(t.Validators.GetWeight(t.Ctx.SubnetID, nodeID))) | ||
t.Ctx.Log.Verbo("adding block to consensus", | ||
zap.Stringer("nodeID", nodeID), | ||
zap.Stringer("blkID", blkID), | ||
) | ||
return true, t.Consensus.Add(ctx, &memoryBlock{ | ||
|
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
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.
Similarly assume this is only after
BuildBlock
?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.
This is called during the startup of the engine. This piece of code is really only for completeness w.r.t. oracle blocks. Specifically, if the
ProposalBlock
is accepted during bootstrapping but neither of theOption
blocks are - then we initially add the options with our preferences. For large networks like mainnet / fuji this code path probably isn't needed because other nodes would gossip theOption
blocks and we can just adopt either preference... But this avoids any weird livelock or preference biasing cases.As far as this goes though - the only options would either be considering ourselves as the block builder or trying to somehow track where we got this block from during bootstrapping (which could cross the restart boundary)