From 4a4cb28081cb298523c06ed814157624ef3733e1 Mon Sep 17 00:00:00 2001 From: aBear Date: Thu, 5 Dec 2024 13:40:23 -0500 Subject: [PATCH 1/3] restore state sync over boonet --- state-transition/core/state_processor_staking.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 0b0039c9dd..8c3458e714 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -84,7 +84,7 @@ func (sp *StateProcessor[ // We keep it for backward compatibility. depositIndex++ case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && - slot < math.U64(spec.BoonetFork2Height): + slot != 0 && slot < math.U64(spec.BoonetFork2Height): // Boonet pre fork2 has a bug which makes DepositEth1ChainID point to // next deposit index, not latest processed deposit index. // We keep it for backward compatibility. From bc45673f793016af549ef89a1decdbd086484750 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 6 Dec 2024 08:48:35 -0500 Subject: [PATCH 2/3] make processRewardsAndPenalties backward compatible --- config/spec/special_cases.go | 4 ++ state-transition/core/state_processor.go | 64 ++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/config/spec/special_cases.go b/config/spec/special_cases.go index 77dac006cb..1cafd06e66 100644 --- a/config/spec/special_cases.go +++ b/config/spec/special_cases.go @@ -20,6 +20,8 @@ package spec +import "math" + // Special cased Bartio for some ad-hoc handling due to the way // some bugs were handled on Bartio. To be removed. const ( @@ -34,4 +36,6 @@ const ( BoonetFork1Height uint64 = 69420 BoonetFork2Height uint64 = 1722000 + + BoonetFork3Height uint64 = math.MaxUint64 ) diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index cf8ab44330..8ec47d8be6 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -30,6 +30,7 @@ import ( "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/primitives/common" + "github.com/berachain/beacon-kit/primitives/constants" "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" @@ -374,15 +375,36 @@ func (sp *StateProcessor[ ]) processEpoch( st BeaconStateT, ) (transition.ValidatorUpdates, error) { - // currently no processRewardsAndPenalties + slot, err := st.GetSlot() + if err != nil { + return nil, err + } - if err := sp.processEffectiveBalanceUpdates(st); err != nil { + switch { + case sp.cs.DepositEth1ChainID() == spec.BartioChainID: + if err = sp.hollowProcessRewardsAndPenalties(st); err != nil { + return nil, err + } + case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && + slot != 0 && slot < math.U64(spec.BoonetFork3Height): + // We cannot simply drop hollowProcessRewardsAndPenalties because + // appHash accounts for the list of operations carried out + // over the state even if the operations does not affect the state + // (rewards and penalties are always zero at this stage of beaconKit) + if err = sp.hollowProcessRewardsAndPenalties(st); err != nil { + return nil, err + } + default: + // no real need to perform hollowProcessRewardsAndPenalties + } + + if err = sp.processEffectiveBalanceUpdates(st); err != nil { return nil, err } - if err := sp.processSlashingsReset(st); err != nil { + if err = sp.processSlashingsReset(st); err != nil { return nil, err } - if err := sp.processRandaoMixesReset(st); err != nil { + if err = sp.processRandaoMixesReset(st); err != nil { return nil, err } return sp.processValidatorsSetUpdates(st) @@ -470,6 +492,40 @@ func (sp *StateProcessor[ return st.SetLatestBlockHeader(lbh) } +func (sp *StateProcessor[ + _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, +]) hollowProcessRewardsAndPenalties(st BeaconStateT) error { + slot, err := st.GetSlot() + if err != nil { + return err + } + + if sp.cs.SlotToEpoch(slot) == math.U64(constants.GenesisEpoch) { + return nil + } + + // this has been simplified to make clear that + // we are not really doing anything here + valCount, err := st.GetTotalValidators() + if err != nil { + return err + } + + for i := range valCount { + // Increase the balance of the validator. + if err = st.IncreaseBalance(math.ValidatorIndex(i), 0); err != nil { + return err + } + + // Decrease the balance of the validator. + if err = st.DecreaseBalance(math.ValidatorIndex(i), 0); err != nil { + return err + } + } + + return nil +} + // processEffectiveBalanceUpdates as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates // From 4e99f743cde00a471b3481753d25b11f26fb0cb2 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 6 Dec 2024 10:23:17 -0500 Subject: [PATCH 3/3] nit --- state-transition/core/state_processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index 8ec47d8be6..422daf6cf8 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -386,7 +386,7 @@ func (sp *StateProcessor[ return nil, err } case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && - slot != 0 && slot < math.U64(spec.BoonetFork3Height): + slot < math.U64(spec.BoonetFork3Height): // We cannot simply drop hollowProcessRewardsAndPenalties because // appHash accounts for the list of operations carried out // over the state even if the operations does not affect the state