Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit d446887

Browse files
committed
consortium/v2: distribute finality reward for the voters in parent block
Because the finality votes are assembled after we FinalizeAndAssemble the block and the finality reward distribution transaction is in FinalizeAndAssemble, we cannot reward the finality voters in the current block right away. Instead, the reward distribution is delayed until next block. So in the FinalizeAndAssemble, we look at the finality voters in the parent header and distribute reward to them.
1 parent ee2021c commit d446887

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

consensus/consortium/v2/consortium.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,17 +725,24 @@ func (c *Consortium) processSystemTransactions(chain consensus.ChainHeaderReader
725725
return err
726726
}
727727

728-
if c.chainConfig.IsShillin(header.Number) {
729-
extraData, err := finality.DecodeExtra(header.Extra, c.chainConfig.IsShillin(header.Number))
728+
// If the parent's block includes the finality votes, distribute reward for the voters
729+
if c.chainConfig.IsShillin(new(big.Int).Sub(header.Number, common.Big1)) {
730+
parentHeader := chain.GetHeaderByHash(header.ParentHash)
731+
extraData, err := finality.DecodeExtra(parentHeader.Extra, true)
730732
if err != nil {
731733
return err
732734
}
733735
if extraData.HasFinalityVote == 1 {
736+
parentSnap, err := c.snapshot(chain, parentHeader.Number.Uint64()-1, parentHeader.ParentHash, nil)
737+
if err != nil {
738+
return err
739+
}
740+
734741
votedValidatorPositions := extraData.FinalityVotedValidators.Indices()
735742
var votedValidators []common.Address
736743
for _, position := range votedValidatorPositions {
737744
// The header has been verified so there must be no out of bound here
738-
votedValidators = append(votedValidators, snap.ValidatorsWithBlsPub[position].Address)
745+
votedValidators = append(votedValidators, parentSnap.ValidatorsWithBlsPub[position].Address)
739746
}
740747

741748
if err := c.contract.FinalityReward(transactOpts, votedValidators); err != nil {

0 commit comments

Comments
 (0)