diff --git a/core/blockchain.go b/core/blockchain.go index 6f2935427e..6d54f2a1ce 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2544,7 +2544,7 @@ func (bc *BlockChain) writeDelegationsByDelegator( // Note: this should only be called within the blockchain insert process. func (bc *BlockChain) UpdateStakingMetaData( batch rawdb.DatabaseWriter, txns staking.StakingTransactions, - state *state.DB, epoch *big.Int, + state *state.DB, epoch *big.Int, isNewEpoch bool, ) (newValidators []common.Address, err error) { newValidators, newDelegations, err := bc.prepareStakingMetaData(txns, state) if err != nil { @@ -2574,6 +2574,14 @@ func (bc *BlockChain) UpdateStakingMetaData( if err := rawdb.WriteValidatorSnapshot(batch, validator, epoch); err != nil { return newValidators, err } + // For validator created at exactly the last block of an epoch, we should create the snapshot + // for next epoch too. + if isNewEpoch { + newEpoch := new(big.Int).Add(epoch, common.Big1) + if err := rawdb.WriteValidatorSnapshot(batch, validator, newEpoch); err != nil { + return newValidators, err + } + } } // Update validator list diff --git a/core/offchain.go b/core/offchain.go index e72a0a3a8d..9f0355d9ce 100644 --- a/core/offchain.go +++ b/core/offchain.go @@ -94,7 +94,7 @@ func (bc *BlockChain) CommitOffChainData( // Do bookkeeping for new staking txns newVals, err := bc.UpdateStakingMetaData( - batch, block.StakingTransactions(), state, epoch, + batch, block.StakingTransactions(), state, epoch, isNewEpoch, ) if err != nil { utils.Logger().Err(err).Msg("UpdateStakingMetaData failed")