Skip to content

Commit c8cb0f3

Browse files
syjn99james-prysm
andauthored
fix: early return for packing local deposits when EIP-6110 is applied (#14697)
* fix: early return for gathering local deposits when EIP-6110 is applied * Add an entry on CHANGELOG.md * Fix weird indent at CHANGELOG.md * Add changelog * Fix CHANGELOG.md --------- Co-authored-by: james-prysm <[email protected]>
1 parent 7872223 commit c8cb0f3

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ func (vs *Server) deposits(
9494
return nil, err
9595
}
9696

97+
// In the post-electra phase, this function will usually return an empty list,
98+
// as the legacy deposit process is deprecated. (EIP-6110)
99+
// NOTE: During the transition period, the legacy deposit process
100+
// may still be active and managed. This function handles that scenario.
101+
if !isLegacyDepositProcessPeriod(beaconState, canonicalEth1Data) {
102+
return []*ethpb.Deposit{}, nil
103+
}
104+
97105
_, genesisEth1Block := vs.Eth1InfoFetcher.GenesisExecutionChainInfo()
98106
if genesisEth1Block.Cmp(canonicalEth1DataHeight) == 0 {
99107
return []*ethpb.Deposit{}, nil
@@ -277,3 +285,21 @@ func shouldRebuildTrie(totalDepCount, unFinalizedDeps uint64) bool {
277285
unFinalizedCompute := unFinalizedDeps * params.BeaconConfig().DepositContractTreeDepth
278286
return unFinalizedCompute > totalDepCount
279287
}
288+
289+
// isLegacyDepositProcessPeriod determines if the current state should use the legacy deposit process.
290+
func isLegacyDepositProcessPeriod(beaconState state.BeaconState, canonicalEth1Data *ethpb.Eth1Data) bool {
291+
// Before the Electra upgrade, always use the legacy deposit process.
292+
if beaconState.Version() < version.Electra {
293+
return true
294+
}
295+
296+
// Handle the transition period between the legacy and the new deposit process.
297+
requestsStartIndex, err := beaconState.DepositRequestsStartIndex()
298+
if err != nil {
299+
// If we can't get the deposit requests start index,
300+
// we should default to the legacy deposit process.
301+
return true
302+
}
303+
eth1DepositIndexLimit := math.Min(canonicalEth1Data.DepositCount, requestsStartIndex)
304+
return beaconState.Eth1DepositIndex() < eth1DepositIndexLimit
305+
}

beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package validator
22

33
import (
44
"context"
5+
"math"
56
"math/big"
67
"testing"
78

89
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
910
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositsnapshot"
1011
mockExecution "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution/testing"
12+
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
1113
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
1214
"github.com/prysmaticlabs/prysm/v5/config/params"
1315
"github.com/prysmaticlabs/prysm/v5/container/trie"
@@ -212,3 +214,85 @@ func TestProposer_PendingDeposits_Electra(t *testing.T) {
212214
assert.Equal(t, 0, len(deposits), "Received unexpected number of pending deposits")
213215

214216
}
217+
218+
func TestIsLegacyDepositProcessPeriod(t *testing.T) {
219+
tests := []struct {
220+
name string
221+
state state.BeaconState
222+
canonicalEth1Data *ethpb.Eth1Data
223+
want bool
224+
}{
225+
{
226+
name: "pre-electra",
227+
state: func() state.BeaconState {
228+
st, err := state_native.InitializeFromProtoDeneb(&ethpb.BeaconStateDeneb{
229+
Eth1Data: &ethpb.Eth1Data{
230+
BlockHash: []byte("0x0"),
231+
DepositRoot: make([]byte, 32),
232+
DepositCount: 5,
233+
},
234+
Eth1DepositIndex: 1,
235+
})
236+
require.NoError(t, err)
237+
return st
238+
}(),
239+
canonicalEth1Data: &ethpb.Eth1Data{
240+
BlockHash: []byte("0x0"),
241+
DepositRoot: make([]byte, 32),
242+
DepositCount: 5,
243+
},
244+
want: true,
245+
},
246+
{
247+
name: "post-electra, pending deposits from pre-electra",
248+
state: func() state.BeaconState {
249+
st, err := state_native.InitializeFromProtoElectra(&ethpb.BeaconStateElectra{
250+
Eth1Data: &ethpb.Eth1Data{
251+
BlockHash: []byte("0x0"),
252+
DepositRoot: make([]byte, 32),
253+
DepositCount: 5,
254+
},
255+
DepositRequestsStartIndex: math.MaxUint64,
256+
Eth1DepositIndex: 1,
257+
})
258+
require.NoError(t, err)
259+
return st
260+
}(),
261+
canonicalEth1Data: &ethpb.Eth1Data{
262+
BlockHash: []byte("0x0"),
263+
DepositRoot: make([]byte, 32),
264+
DepositCount: 5,
265+
},
266+
want: true,
267+
},
268+
{
269+
name: "post-electra, no pending deposits from pre-alpaca",
270+
state: func() state.BeaconState {
271+
st, err := state_native.InitializeFromProtoElectra(&ethpb.BeaconStateElectra{
272+
Eth1Data: &ethpb.Eth1Data{
273+
BlockHash: []byte("0x0"),
274+
DepositRoot: make([]byte, 32),
275+
DepositCount: 5,
276+
},
277+
DepositRequestsStartIndex: 1,
278+
Eth1DepositIndex: 5,
279+
})
280+
require.NoError(t, err)
281+
return st
282+
}(),
283+
canonicalEth1Data: &ethpb.Eth1Data{
284+
BlockHash: []byte("0x0"),
285+
DepositRoot: make([]byte, 32),
286+
DepositCount: 5,
287+
},
288+
want: false,
289+
},
290+
}
291+
for _, tt := range tests {
292+
t.Run(tt.name, func(t *testing.T) {
293+
if got := isLegacyDepositProcessPeriod(tt.state, tt.canonicalEth1Data); got != tt.want {
294+
t.Errorf("isLegacyDepositProcessPeriod() = %v, want %v", got, tt.want)
295+
}
296+
})
297+
}
298+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fixed deposit packing for post-Electra: early return if EIP-6110 is applied.

0 commit comments

Comments
 (0)