[reward] Explicitly record block-reward accumulator from beginning of time

pull/1942/head
Edgar Aroutiounian 5 years ago
parent da3fe98c13
commit 2bf31d892a
  1. 19
      core/blockchain.go
  2. 1
      core/genesis.go

@ -77,7 +77,7 @@ const (
validatorListCacheLimit = 10 validatorListCacheLimit = 10
validatorListByDelegatorCacheLimit = 1024 validatorListByDelegatorCacheLimit = 1024
pendingCrossLinksCacheLimit = 2 pendingCrossLinksCacheLimit = 2
blockAccumulatorCacheLimit = 1024 blockAccumulatorCacheLimit = 256
// BlockChainVersion ensures that an incompatible database forces a resync from scratch. // BlockChainVersion ensures that an incompatible database forces a resync from scratch.
BlockChainVersion = 3 BlockChainVersion = 3
@ -1308,23 +1308,8 @@ func (bc *BlockChain) WriteBlockWithState(
utils.Logger().Debug().Msgf("DeleteCommittedFromPendingCrossLinks, crosslinks in header %d, pending crosslinks: %d, error: %+v", len(*crossLinks), num, err) utils.Logger().Debug().Msgf("DeleteCommittedFromPendingCrossLinks, crosslinks in header %d, pending crosslinks: %d, error: %+v", len(*crossLinks), num, err)
} }
isFirstTimeStaking := bc.chainConfig.IsStaking( bc.UpdateBlockRewardAccumulator(payout, block.Number().Uint64())
new(big.Int).Add(block.Epoch(), big.NewInt(1)),
) &&
len(block.Header().ShardState()) > 0 &&
!bc.chainConfig.IsStaking(block.Epoch())
curHeader := bc.CurrentHeader()
if isFirstTimeStaking &&
curHeader.ShardID() == shard.BeaconChainShardID {
bc.WriteBlockRewardAccumulator(big.NewInt(0), curHeader.Number().Uint64())
}
if curHeader.ShardID() == shard.BeaconChainShardID &&
bc.chainConfig.IsStaking(block.Epoch()) {
bc.UpdateBlockRewardAccumulator(payout, block.Number().Uint64())
}
/////////////////////////// END /////////////////////////// END
// If the total difficulty is higher than our known, add it to the canonical chain // If the total difficulty is higher than our known, add it to the canonical chain

@ -307,6 +307,7 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
if err != nil { if err != nil {
panic(err) panic(err)
} }
rawdb.WriteBlockRewardAccumulator(db, big.NewInt(0), 0)
return block return block
} }

Loading…
Cancel
Save