mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
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 <90280386+james-prysm@users.noreply.github.com>
This commit is contained in:
@@ -94,6 +94,14 @@ func (vs *Server) deposits(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// In the post-electra phase, this function will usually return an empty list,
|
||||
// as the legacy deposit process is deprecated. (EIP-6110)
|
||||
// NOTE: During the transition period, the legacy deposit process
|
||||
// may still be active and managed. This function handles that scenario.
|
||||
if !isLegacyDepositProcessPeriod(beaconState, canonicalEth1Data) {
|
||||
return []*ethpb.Deposit{}, nil
|
||||
}
|
||||
|
||||
_, genesisEth1Block := vs.Eth1InfoFetcher.GenesisExecutionChainInfo()
|
||||
if genesisEth1Block.Cmp(canonicalEth1DataHeight) == 0 {
|
||||
return []*ethpb.Deposit{}, nil
|
||||
@@ -277,3 +285,21 @@ func shouldRebuildTrie(totalDepCount, unFinalizedDeps uint64) bool {
|
||||
unFinalizedCompute := unFinalizedDeps * params.BeaconConfig().DepositContractTreeDepth
|
||||
return unFinalizedCompute > totalDepCount
|
||||
}
|
||||
|
||||
// isLegacyDepositProcessPeriod determines if the current state should use the legacy deposit process.
|
||||
func isLegacyDepositProcessPeriod(beaconState state.BeaconState, canonicalEth1Data *ethpb.Eth1Data) bool {
|
||||
// Before the Electra upgrade, always use the legacy deposit process.
|
||||
if beaconState.Version() < version.Electra {
|
||||
return true
|
||||
}
|
||||
|
||||
// Handle the transition period between the legacy and the new deposit process.
|
||||
requestsStartIndex, err := beaconState.DepositRequestsStartIndex()
|
||||
if err != nil {
|
||||
// If we can't get the deposit requests start index,
|
||||
// we should default to the legacy deposit process.
|
||||
return true
|
||||
}
|
||||
eth1DepositIndexLimit := math.Min(canonicalEth1Data.DepositCount, requestsStartIndex)
|
||||
return beaconState.Eth1DepositIndex() < eth1DepositIndexLimit
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositsnapshot"
|
||||
mockExecution "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution/testing"
|
||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
||||
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v5/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v5/container/trie"
|
||||
@@ -212,3 +214,85 @@ func TestProposer_PendingDeposits_Electra(t *testing.T) {
|
||||
assert.Equal(t, 0, len(deposits), "Received unexpected number of pending deposits")
|
||||
|
||||
}
|
||||
|
||||
func TestIsLegacyDepositProcessPeriod(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
state state.BeaconState
|
||||
canonicalEth1Data *ethpb.Eth1Data
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "pre-electra",
|
||||
state: func() state.BeaconState {
|
||||
st, err := state_native.InitializeFromProtoDeneb(ðpb.BeaconStateDeneb{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
Eth1DepositIndex: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return st
|
||||
}(),
|
||||
canonicalEth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "post-electra, pending deposits from pre-electra",
|
||||
state: func() state.BeaconState {
|
||||
st, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
DepositRequestsStartIndex: math.MaxUint64,
|
||||
Eth1DepositIndex: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return st
|
||||
}(),
|
||||
canonicalEth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "post-electra, no pending deposits from pre-alpaca",
|
||||
state: func() state.BeaconState {
|
||||
st, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
DepositRequestsStartIndex: 1,
|
||||
Eth1DepositIndex: 5,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return st
|
||||
}(),
|
||||
canonicalEth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositRoot: make([]byte, 32),
|
||||
DepositCount: 5,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := isLegacyDepositProcessPeriod(tt.state, tt.canonicalEth1Data); got != tt.want {
|
||||
t.Errorf("isLegacyDepositProcessPeriod() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
3
changelog/syjn99_early-return-local-deposits.md
Normal file
3
changelog/syjn99_early-return-local-deposits.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- Fixed deposit packing for post-Electra: early return if EIP-6110 is applied.
|
||||
Reference in New Issue
Block a user