-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(state-transition): make validators epochs handling close to Eth2.0 specs #2226
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7409de1
adding handling for ActivationEligibilityEpoch
abi87 51a12a0
adding handling for ActivationEpoch
abi87 763ed85
wip: adding handling for exit and withdrawable epochs
abi87 23ccf36
wip: some more repackaging
abi87 0c03846
some UT code consolidation
abi87 574099e
wip: fixing UTs
abi87 1cd77bf
simplified slashing reset
abi87 712c4bf
wip: some more UTs fixing
abi87 ee2611b
typos
abi87 7f8df44
wip: fixing returned diffs
abi87 cda83f6
nit
abi87 9f30dd8
fixed Bartio backward compatibility
abi87 a720a15
wip: fixing backward compatibility
abi87 2772911
wip: fixing backward compatibility
abi87 c69dea0
nits
abi87 69c753e
nit
abi87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ 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" | ||
|
@@ -375,36 +374,19 @@ func (sp *StateProcessor[ | |
]) processEpoch( | ||
st BeaconStateT, | ||
) (transition.ValidatorUpdates, error) { | ||
slot, err := st.GetSlot() | ||
if err != nil { | ||
if err := sp.processRewardsAndPenalties(st); err != nil { | ||
return nil, err | ||
} | ||
|
||
switch { | ||
case sp.cs.DepositEth1ChainID() == spec.BartioChainID: | ||
if err = sp.hollowProcessRewardsAndPenalties(st); err != nil { | ||
return nil, err | ||
} | ||
case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && | ||
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.processRegistryUpdates(st); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = sp.processEffectiveBalanceUpdates(st); err != nil { | ||
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) | ||
|
@@ -492,40 +474,6 @@ func (sp *StateProcessor[ | |
return st.SetLatestBlockHeader(lbh) | ||
} | ||
|
||
func (sp *StateProcessor[ | ||
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, | ||
]) hollowProcessRewardsAndPenalties(st BeaconStateT) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to its own file to be out of the way |
||
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 | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
state-transition/core/state_processor_rewards_penalties.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// | ||
// Copyright (C) 2024, Berachain Foundation. All rights reserved. | ||
// Use of this software is governed by the Business Source License included | ||
// in the LICENSE file of this repository and at www.mariadb.com/bsl11. | ||
// | ||
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY | ||
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER | ||
// VERSIONS OF THE LICENSED WORK. | ||
// | ||
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF | ||
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF | ||
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). | ||
// | ||
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON | ||
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, | ||
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND | ||
// TITLE. | ||
|
||
package core | ||
|
||
import ( | ||
"github.com/berachain/beacon-kit/config/spec" | ||
"github.com/berachain/beacon-kit/primitives/constants" | ||
"github.com/berachain/beacon-kit/primitives/math" | ||
) | ||
|
||
func (sp *StateProcessor[ | ||
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, | ||
]) processRewardsAndPenalties(st BeaconStateT) error { | ||
abi87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
slot, err := st.GetSlot() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// processRewardsAndPenalties does not really do anything right now. | ||
// However we cannot simply drop it because appHash accounts | ||
// for the list of operations carried out over the state | ||
// even if the operations does not affect the final state | ||
// (rewards and penalties are always zero at this stage of beaconKit) | ||
|
||
switch { | ||
case sp.cs.DepositEth1ChainID() == spec.BartioChainID: | ||
// go head doing the processing, eve | ||
case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && | ||
slot < math.U64(spec.BoonetFork3Height): | ||
default: | ||
// no real need to perform hollowProcessRewardsAndPenalties | ||
return nil | ||
} | ||
abi87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
} | ||
} | ||
abi87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved into processRewardsAndPenalties to have fork switches less in the way of mostly read code