Skip to content

Commit

Permalink
#10036 Replace codename Merge with Bellatrix (1st step) (#10044)
Browse files Browse the repository at this point in the history
* Rename BeaconStateMerge to BeaconStateBellatrix

* Rename version.Merge to version.Bellatrix

* Rename ComputeFieldRootsWithHasherMerge to ComputeFieldRootsWithHasherBellatrix

* Rename test names to Bellatrix

* Rename comments and strings to Bellatrix

* Fix formatting in a few files

* Revert wrong renaming in test name

* Revert renaming to Bellatrix in mainnet_config.go

* Revert renaming of db key without migration

* Regenerate from proto changes

* Rename new use of already renamed symbols

* gofmt and goimports after regenerating protofiles

* revert weird imports

Co-authored-by: prestonvanloon <preston@prysmaticlabs.com>
(cherry picked from commit b1c2454)

# Conflicts:
#	beacon-chain/cache/sync_committee_head_state.go
#	beacon-chain/core/execution/upgrade.go
#	beacon-chain/state-proto/v3/state_trie.go
  • Loading branch information
leolara authored and rkapka committed Jan 11, 2022
1 parent d5a24ab commit 04e29d7
Show file tree
Hide file tree
Showing 73 changed files with 532 additions and 532 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
if err != nil {
return err
}
case version.Altair, version.Merge:
case version.Altair, version.Bellatrix:
v, b, err = altair.InitializePrecomputeValidators(ctx, headState)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/cache/sync_committee_head_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestSyncCommitteeHeadState(t *testing.T) {
},
})
require.NoError(t, err)
mergeState, err := v3.InitializeFromProto(&ethpb.BeaconStateMerge{
bellatrixState, err := v3.InitializeFromProto(&ethpb.BeaconStateBellatrix{
Fork: &ethpb.Fork{
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
Expand Down Expand Up @@ -91,22 +91,22 @@ func TestSyncCommitteeHeadState(t *testing.T) {
want: beaconState,
},
{
name: "not found when non-existent key in non-empty cache (merge state)",
name: "not found when non-existent key in non-empty cache (bellatrix state)",
key: types.Slot(2),
put: &put{
slot: types.Slot(1),
state: mergeState,
state: bellatrixState,
},
wantErr: true,
},
{
name: "found with key (merge state)",
name: "found with key (bellatrix state)",
key: types.Slot(100),
put: &put{
slot: types.Slot(100),
state: mergeState,
state: bellatrixState,
},
want: mergeState,
want: bellatrixState,
},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/altair/epoch_precompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ func AttestationsDelta(beaconState state.BeaconState, bal *precompute.Balance, v
baseRewardMultiplier := increment * factor / math.IntegerSquareRoot(bal.ActiveCurrentEpoch)
leak := helpers.IsInInactivityLeak(prevEpoch, finalizedEpoch)

// Modified in Altair and Merge.
// Modified in Altair and Bellatrix.
var inactivityDenominator uint64
bias := cfg.InactivityScoreBias
switch beaconState.Version() {
case version.Altair:
inactivityDenominator = bias * cfg.InactivityPenaltyQuotientAltair
case version.Merge:
case version.Bellatrix:
inactivityDenominator = bias * cfg.InactivityPenaltyQuotientMerge
default:
return nil, nil, errors.Errorf("invalid state type version: %T", beaconState.Version())
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/altair/epoch_precompute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ func TestAttestationsDelta(t *testing.T) {
require.DeepEqual(t, want, penalties)
}

func TestAttestationsDeltaMerge(t *testing.T) {
s, err := testStateMerge()
func TestAttestationsDeltaBellatrix(t *testing.T) {
s, err := testStateBellatrix()
require.NoError(t, err)
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
require.NoError(t, err)
Expand Down Expand Up @@ -493,7 +493,7 @@ func testState() (state.BeaconState, error) {
})
}

func testStateMerge() (state.BeaconState, error) {
func testStateBellatrix() (state.BeaconState, error) {
generateParticipation := func(flags ...uint8) byte {
b := byte(0)
var err error
Expand All @@ -505,7 +505,7 @@ func testStateMerge() (state.BeaconState, error) {
}
return b
}
return v3.InitializeFromProto(&ethpb.BeaconStateMerge{
return v3.InitializeFromProto(&ethpb.BeaconStateBellatrix{
Slot: 2 * params.BeaconConfig().SlotsPerEpoch,
Validators: []*ethpb.Validator{
{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch},
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/altair/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func ProcessEpoch(ctx context.Context, state state.BeaconState) (state.BeaconSta
return nil, errors.Wrap(err, "could not process registry updates")
}

// Modified in Altair and Merge.
// Modified in Altair and Bellatrix.
cfg := params.BeaconConfig()
switch state.Version() {
case version.Altair:
state, err = e.ProcessSlashings(state, cfg.ProportionalSlashingMultiplierAltair)
if err != nil {
return nil, err
}
case version.Merge:
case version.Bellatrix:
state, err = e.ProcessSlashings(state, cfg.ProportionalSlashingMultiplierMerge)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/altair/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestProcessEpoch_CanProcess(t *testing.T) {
require.Equal(t, params.BeaconConfig().SyncCommitteeSize, uint64(len(sc.Pubkeys)))
}

func TestProcessEpoch_CanProcessMerge(t *testing.T) {
func TestProcessEpoch_CanProcessBellatrix(t *testing.T) {
st, _ := util.DeterministicGenesisStateMerge(t, params.BeaconConfig().MaxValidatorsPerCommittee)
require.NoError(t, st.SetSlot(10*params.BeaconConfig().SlotsPerEpoch))
newState, err := altair.ProcessEpoch(context.Background(), st)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func ProcessAttesterSlashing(
slashingQuotient = cfg.MinSlashingPenaltyQuotient
case beaconState.Version() == version.Altair:
slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair
case beaconState.Version() == version.Merge:
case beaconState.Version() == version.Bellatrix:
slashingQuotient = cfg.MinSlashingPenaltyQuotientMerge
default:
return nil, errors.New("unknown state version")
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/attester_slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) {
require.Equal(t, uint64(32000000000), newState.Balances()[2])
}

func TestProcessAttesterSlashings_AppliesCorrectStatusMerge(t *testing.T) {
func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) {
beaconState, privKeys := util.DeterministicGenesisStateMerge(t, 100)
for _, vv := range beaconState.Validators() {
vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func Test_PayloadToHeader(t *testing.T) {
require.Equal(t, h.Timestamp, uint64(0))
}

func BenchmarkMergeComplete(b *testing.B) {
func BenchmarkBellatrixComplete(b *testing.B) {
st, _ := util.DeterministicGenesisStateMerge(b, 1)
require.NoError(b, st.SetLatestExecutionPayloadHeader(emptyPayloadHeader()))

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/proposer_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ProcessProposerSlashing(
slashingQuotient = cfg.MinSlashingPenaltyQuotient
case beaconState.Version() == version.Altair:
slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair
case beaconState.Version() == version.Merge:
case beaconState.Version() == version.Bellatrix:
slashingQuotient = cfg.MinSlashingPenaltyQuotientMerge
default:
return nil, errors.New("unknown state version")
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/proposer_slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestProcessProposerSlashings_AppliesCorrectStatusAltair(t *testing.T) {
require.Equal(t, uint64(32000000000), newState.Balances()[2])
}

func TestProcessProposerSlashings_AppliesCorrectStatusMerge(t *testing.T) {
func TestProcessProposerSlashings_AppliesCorrectStatusBellatrix(t *testing.T) {
// We test the case when data is correct and verify the validator
// registry has been updated.
beaconState, privKeys := util.DeterministicGenesisStateMerge(t, 100)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/epoch/precompute/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func UpdateBalance(vp []*Validator, bBal *Balance, stateVersion int) *Balance {
if stateVersion == version.Phase0 && v.IsPrevEpochAttester {
bBal.PrevEpochAttested += v.CurrentEpochEffectiveBalance
}
if (stateVersion == version.Altair || stateVersion == version.Merge) && v.IsPrevEpochSourceAttester {
if (stateVersion == version.Altair || stateVersion == version.Bellatrix) && v.IsPrevEpochSourceAttester {
bBal.PrevEpochAttested += v.CurrentEpochEffectiveBalance
}
if v.IsPrevEpochTargetAttester {
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/epoch/precompute/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestUpdateBalance(t *testing.T) {
assert.DeepEqual(t, wantedPBal, pBal, "Incorrect balance calculations")
}

func TestUpdateBalanceMergeVersion(t *testing.T) {
func TestUpdateBalanceBellatrixVersion(t *testing.T) {
vp := []*precompute.Validator{
{IsCurrentEpochAttester: true, CurrentEpochEffectiveBalance: 100 * params.BeaconConfig().EffectiveBalanceIncrement},
{IsCurrentEpochTargetAttester: true, IsCurrentEpochAttester: true, CurrentEpochEffectiveBalance: 100 * params.BeaconConfig().EffectiveBalanceIncrement},
Expand All @@ -90,7 +90,7 @@ func TestUpdateBalanceMergeVersion(t *testing.T) {
PrevEpochTargetAttested: 100 * params.BeaconConfig().EffectiveBalanceIncrement,
PrevEpochHeadAttested: 200 * params.BeaconConfig().EffectiveBalanceIncrement,
}
pBal := precompute.UpdateBalance(vp, &precompute.Balance{}, version.Merge)
pBal := precompute.UpdateBalance(vp, &precompute.Balance{}, version.Bellatrix)
assert.DeepEqual(t, wantedPBal, pBal, "Incorrect balance calculations")
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/execution/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func UpgradeToMerge(ctx context.Context, state state.BeaconState) (state.BeaconS
return nil, err
}

s := &ethpb.BeaconStateMerge{
s := &ethpb.BeaconStateBellatrix{
GenesisTime: state.GenesisTime(),
GenesisValidatorsRoot: state.GenesisValidatorRoot(),
Slot: state.Slot(),
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/execution/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/testing/util"
)

func TestUpgradeToMerge(t *testing.T) {
func TestUpgradeToBellatrix(t *testing.T) {
st, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().MaxValidatorsPerCommittee)
preForkState := st.Copy()
mSt, err := execution.UpgradeToMerge(context.Background(), st)
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/time/slot_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func CanUpgradeToAltair(slot types.Slot) bool {
return epochStart && altairEpoch
}

// CanUpgradeToMerge returns true if the input `slot` can upgrade to Bellatrix fork.
// CanUpgradeToBellatrix returns true if the input `slot` can upgrade to Bellatrix fork.
//
// Spec code:
// If state.slot % SLOTS_PER_EPOCH == 0 and compute_epoch_at_slot(state.slot) == BELLATRIX_FORK_EPOCH
func CanUpgradeToMerge(slot types.Slot) bool {
func CanUpgradeToBellatrix(slot types.Slot) bool {
epochStart := slots.IsEpochStart(slot)
mergeEpoch := slots.ToEpoch(slot) == params.BeaconConfig().BellatrixForkEpoch
return epochStart && mergeEpoch
bellatrixEpoch := slots.ToEpoch(slot) == params.BeaconConfig().BellatrixForkEpoch
return epochStart && bellatrixEpoch
}

// CanProcessEpoch checks the eligibility to process epoch.
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/core/time/slot_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestCanUpgradeToAltair(t *testing.T) {
}
}

func TestCanUpgradeToMerge(t *testing.T) {
func TestCanUpgradeBellatrix(t *testing.T) {
params.SetupTestConfigCleanup(t)
bc := params.BeaconConfig()
bc.BellatrixForkEpoch = 5
Expand All @@ -131,20 +131,20 @@ func TestCanUpgradeToMerge(t *testing.T) {
want: false,
},
{
name: "not merge epoch",
name: "not bellatrix epoch",
slot: params.BeaconConfig().SlotsPerEpoch,
want: false,
},
{
name: "merge epoch",
name: "bellatrix epoch",
slot: types.Slot(params.BeaconConfig().BellatrixForkEpoch) * params.BeaconConfig().SlotsPerEpoch,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CanUpgradeToMerge(tt.slot); got != tt.want {
t.Errorf("CanUpgradeToMerge() = %v, want %v", got, tt.want)
if got := CanUpgradeToBellatrix(tt.slot); got != tt.want {
t.Errorf("CanUpgradeToBellatrix() = %v, want %v", got, tt.want)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/transition/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
tracing.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process epoch with optimizations")
}
case version.Altair, version.Merge:
case version.Altair, version.Bellatrix:
state, err = altair.ProcessEpoch(ctx, state)
if err != nil {
tracing.AnnotateError(span, err)
Expand All @@ -265,7 +265,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
}
}

if time.CanUpgradeToMerge(state.Slot()) {
if time.CanUpgradeToBellatrix(state.Slot()) {
state, err = execution.UpgradeToMerge(ctx, state)
if err != nil {
tracing.AnnotateError(span, err)
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/transition/transition_no_verify_sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func CalculateStateRoot(
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not process block")
}
if signed.Version() == version.Altair || signed.Version() == version.Merge {
if signed.Version() == version.Altair || signed.Version() == version.Bellatrix {
sa, err := signed.Block().Body().SyncAggregate()
if err != nil {
return [32]byte{}, err
Expand Down Expand Up @@ -198,7 +198,7 @@ func ProcessBlockNoVerifyAnySig(
if err != nil {
return nil, nil, err
}
if signed.Version() == version.Altair || signed.Version() == version.Merge {
if signed.Version() == version.Altair || signed.Version() == version.Bellatrix {
sa, err := signed.Block().Body().SyncAggregate()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -273,7 +273,7 @@ func ProcessOperationsNoVerifyAttsSigs(
if err != nil {
return nil, err
}
case version.Altair, version.Merge:
case version.Altair, version.Bellatrix:
state, err = altairOperations(ctx, state, signedBeaconBlock)
if err != nil {
return nil, err
Expand Down Expand Up @@ -320,7 +320,7 @@ func ProcessBlockForStateRoot(
return nil, errors.Wrap(err, "could not process block header")
}

if state.Version() == version.Merge {
if state.Version() == version.Bellatrix {
enabled, err := b.ExecutionEnabled(state, blk.Body())
if err != nil {
return nil, errors.Wrap(err, "could not check if execution is enabled")
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/transition/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func TestProcessSlots_OnlyAltairEpoch(t *testing.T) {
require.Equal(t, params.BeaconConfig().SyncCommitteeSize, uint64(len(sc.Pubkeys)))
}

func TestProcessSlots_OnlyMergeEpoch(t *testing.T) {
func TestProcessSlots_OnlyBellatrixEpoch(t *testing.T) {
transition.SkipSlotCache.Disable()
conf := params.BeaconConfig()
conf.BellatrixForkEpoch = 5
Expand All @@ -560,10 +560,10 @@ func TestProcessSlots_OnlyMergeEpoch(t *testing.T) {

st, _ := util.DeterministicGenesisStateMerge(t, params.BeaconConfig().MaxValidatorsPerCommittee)
require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch*6))
require.Equal(t, version.Merge, st.Version())
require.Equal(t, version.Bellatrix, st.Version())
st, err := transition.ProcessSlots(context.Background(), st, params.BeaconConfig().SlotsPerEpoch*10)
require.NoError(t, err)
require.Equal(t, version.Merge, st.Version())
require.Equal(t, version.Bellatrix, st.Version())

require.Equal(t, params.BeaconConfig().SlotsPerEpoch*10, st.Slot())

Expand Down Expand Up @@ -598,7 +598,7 @@ func TestProcessSlots_ThroughMergeEpoch(t *testing.T) {
st, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().MaxValidatorsPerCommittee)
st, err := transition.ProcessSlots(context.Background(), st, params.BeaconConfig().SlotsPerEpoch*10)
require.NoError(t, err)
require.Equal(t, version.Merge, st.Version())
require.Equal(t, version.Bellatrix, st.Version())

require.Equal(t, params.BeaconConfig().SlotsPerEpoch*10, st.Slot())
}
Expand Down
Loading

0 comments on commit 04e29d7

Please sign in to comment.