-
Notifications
You must be signed in to change notification settings - Fork 208
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
Track uptime & distribute rewards based on it #618
Conversation
consensus/istanbul/backend/pos.go
Outdated
} | ||
|
||
// the uptimes array is aligned with the validator set | ||
validatorUptime := uptimes[validatorIndex].Score / (sb.EpochSize() - sb.LookbackWindow() + 1) |
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.
Won't this return 0? I think we actually want (uptimes[validatorIndex].Score * 10^24) / (sb.EpochSize() - sb.LookbackWindow() + 1)
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.
yeah logic in the pos file was still WIP, should be fixed now
core/blockchain.go
Outdated
var validatorsSize uint64 | ||
if len(uptime) == 0 { | ||
// the number of validators is upper bound by 3/2 of the number of 1s in the bitmap | ||
// TODO: due to this maybe we create an uptimeScore array which is 1 element bigger than required |
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.
So actually, since we're recording the uptime based on the signatures on the previous block, of which there may be more than 2F+1, we're likely to create an uptimeScore array much bigger than required
core/blockchain.go
Outdated
|
||
signedValidatorsBitmap := extra.ParentAggregatedSeal.Bitmap | ||
uptime := bc.GetAccumulatedUptime() | ||
uptime = updateUptime(uptime, block.NumberU64(), signedValidatorsBitmap, bc.chainConfig.Istanbul.LookbackWindow) |
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.
Where is the per-epoch reset happening?
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 changed the uptimes per epoch to be saved in different keys, so there is no direct need to save the data in order to calculate the uptime properly
7026e7b
to
1bb1ac0
Compare
78a5d66
to
a5f7ce0
Compare
ca05652
to
68dd946
Compare
core/blockchain.go
Outdated
if bitmap.Bit(i) == 1 { | ||
// update their latest signed block and reward them | ||
uptime[i].LastSignedBlock = blockNumber | ||
if blockNumber >= firstBlockInEpoch+window-1 { |
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 think that this should be firstBlockInEpoch + window + 1
. The aggregatedParentSignatures
for the firstBlockInEpoch will be for a different valset than the current valset.
core/blockchain.go
Outdated
uptime[i].LastSignedBlock = blockNumber - 1 | ||
} | ||
|
||
// If we are within the validator uptime tally window, then update the validator's score if it's last signed block is within |
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.
// If we are within the validator uptime tally window, then update the validator's score if it's last signed block is within | |
// If we are within the validator uptime tally window, then update the validator's score if its last signed block is within |
|
||
// If we are within the validator uptime tally window, then update the validator's score if it's last signed block is within | ||
// the lookback window | ||
if valScoreTallyFirstBlockNum <= blockNumber && blockNumber <= valScoreTallyLastBlockNum { |
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.
LGTM, nit: we could maybe extract this and the valScoreTally{First, Last}BlockNum
functions together to another function, isInLookbackWindow
if valScoreTallyFirstBlockNum <= blockNumber && blockNumber <= valScoreTallyLastBlockNum { | ||
lastSignedBlock := uptime[i].LastSignedBlock | ||
// TODO (kevjue) add comment about 2nd check | ||
if signedBlockWindowFirstBlockNum <= lastSignedBlock && lastSignedBlock <= signedBlockWindowLastBlockNum { |
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.
if signedBlockWindowFirstBlockNum <= lastSignedBlock && lastSignedBlock <= signedBlockWindowLastBlockNum { | |
// increase our score as long as we signed at least one block within the lookback window, | |
// (even if we did not sign on the current block) | |
if signedBlockWindowFirstBlockNum <= lastSignedBlock && lastSignedBlock <= signedBlockWindowLastBlockNum { |
if bc.engine.Protocol().Name == "istanbul" { | ||
// The epoch's first block's aggregated parent signatures is for the previous epoch's valset. | ||
// We can ignore updating the tally for that block. | ||
if !istanbul.IsFirstBlockOfEpoch(block.NumberU64(), bc.chainConfig.Istanbul.Epoch) { |
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.
Nice catch! There's probably merit in us documenting all the edge cases we've encountered so far in this and my previous PR about parent seals regarding epoch transitions
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.
Looks great! Mostly nits
Description
Will close #457. Idea is that we track a validator's uptime by the bitmap from my previous PR.
window
blocks per epochTested
Other changes