From 2bf31d892aab8719a1ac2be49d90bd4cbd3fc82e Mon Sep 17 00:00:00 2001 From: Edgar Aroutiounian Date: Tue, 3 Dec 2019 02:34:02 -0800 Subject: [PATCH] [reward] Explicitly record block-reward accumulator from beginning of time --- core/blockchain.go | 19 ++----------------- core/genesis.go | 1 + 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 4ffac68ed..4c0617ed6 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -77,7 +77,7 @@ const ( validatorListCacheLimit = 10 validatorListByDelegatorCacheLimit = 1024 pendingCrossLinksCacheLimit = 2 - blockAccumulatorCacheLimit = 1024 + blockAccumulatorCacheLimit = 256 // BlockChainVersion ensures that an incompatible database forces a resync from scratch. 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) } - isFirstTimeStaking := bc.chainConfig.IsStaking( - new(big.Int).Add(block.Epoch(), big.NewInt(1)), - ) && - len(block.Header().ShardState()) > 0 && - !bc.chainConfig.IsStaking(block.Epoch()) + bc.UpdateBlockRewardAccumulator(payout, block.Number().Uint64()) - 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 // If the total difficulty is higher than our known, add it to the canonical chain diff --git a/core/genesis.go b/core/genesis.go index fdc96e7d1..25309cca8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -307,6 +307,7 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block { if err != nil { panic(err) } + rawdb.WriteBlockRewardAccumulator(db, big.NewInt(0), 0) return block }