Skip to content

Commit

Permalink
Move consolidation limit check outside of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon committed May 15, 2024
1 parent cba374a commit 8141096
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions beacon-chain/core/electra/consolidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func ProcessConsolidations(ctx context.Context, st state.BeaconState, cs []*ethp
return err
}

if helpers.ConsolidationChurnLimit(math.Gwei(totalBalance)) <= math.Gwei(params.BeaconConfig().MinActivationBalance) {
return errors.New("too little available consolidation churn limit")
}

currentEpoch := slots.ToEpoch(st.Slot())

for _, c := range cs {
Expand All @@ -179,10 +183,6 @@ func ProcessConsolidations(ctx context.Context, st state.BeaconState, cs []*ethp
return errors.New("pending consolidations queue is full")
}

if helpers.ConsolidationChurnLimit(math.Gwei(totalBalance)) <= math.Gwei(params.BeaconConfig().MinActivationBalance) {
return errors.New("too little available consolidation churn limit")
}

if c.Message.SourceIndex == c.Message.TargetIndex {
return errors.New("source and target index are the same")
}
Expand Down
7 changes: 2 additions & 5 deletions beacon-chain/core/electra/consolidations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,14 @@ func TestProcessConsolidations(t *testing.T) {
},
{
name: "nil consolidation in slice",
state: func() state.BeaconState {
st, _ := util.DeterministicGenesisStateElectra(t, 1)
return st
}(),
state: stateWithActiveBalanceETH(t, 19_000_000),
scs: []*eth.SignedConsolidation{nil, nil},
wantErr: "nil consolidation",
},
{
name: "state is 100% full of pending consolidations",
state: func() state.BeaconState {
st, _ := util.DeterministicGenesisStateElectra(t, 1)
st := stateWithActiveBalanceETH(t, 19_000_000)
pc := make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit)
require.NoError(t, st.SetPendingConsolidations(pc))
return st
Expand Down

0 comments on commit 8141096

Please sign in to comment.