Skip to content

Commit 98545dc

Browse files
add slot data from electra (#13042)
Adding slot data to support to Antiquary Co-authored-by: shota.silagadze <shota.silagadze@taal.com>
1 parent 43813d8 commit 98545dc

File tree

13 files changed

+147
-21
lines changed

13 files changed

+147
-21
lines changed

cl/antiquary/state_antiquary_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func runTest(t *testing.T, blocks []*cltypes.SignedBeaconBlock, preState, postSt
4848
require.NoError(t, a.IncrementBeaconState(ctx, blocks[len(blocks)-1].Block.Slot+33))
4949
}
5050

51+
func TestStateAntiquaryElectra(t *testing.T) {
52+
blocks, preState, postState := tests.GetElectraRandom()
53+
runTest(t, blocks, preState, postState)
54+
}
55+
5156
func TestStateAntiquaryCapella(t *testing.T) {
5257
blocks, preState, postState := tests.GetCapellaRandom()
5358
runTest(t, blocks, preState, postState)
64.4 KB
Binary file not shown.
25.1 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:73018ecc96aa42f2d6baef211fb8d504750ad1ab638d94705d3d1b051b4ad71e
3+
size 34
209 KB
Binary file not shown.
197 KB
Binary file not shown.

cl/antiquary/tests/tests.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ import (
3333
"github.com/stretchr/testify/require"
3434
)
3535

36+
//go:embed test_data/electra/blocks_0.ssz_snappy
37+
var electra_blocks_0_ssz_snappy []byte
38+
39+
//go:embed test_data/electra/blocks_1.ssz_snappy
40+
var electra_blocks_1_ssz_snappy []byte
41+
42+
//go:embed test_data/electra/pre.ssz_snappy
43+
var electra_pre_state_ssz_snappy []byte
44+
45+
//go:embed test_data/electra/post.ssz_snappy
46+
var electra_post_state_ssz_snappy []byte
47+
3648
//go:embed test_data/capella/blocks_0.ssz_snappy
3749
var capella_blocks_0_ssz_snappy []byte
3850

@@ -126,6 +138,30 @@ func LoadChain(blocks []*cltypes.SignedBeaconBlock, s *state.CachingBeaconState,
126138
return m
127139
}
128140

141+
func GetElectraRandom() ([]*cltypes.SignedBeaconBlock, *state.CachingBeaconState, *state.CachingBeaconState) {
142+
block1 := cltypes.NewSignedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.ElectraVersion)
143+
block2 := cltypes.NewSignedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.ElectraVersion)
144+
145+
// Lets do te
146+
if err := utils.DecodeSSZSnappy(block1, electra_blocks_0_ssz_snappy, int(clparams.ElectraVersion)); err != nil {
147+
panic(err)
148+
}
149+
if err := utils.DecodeSSZSnappy(block2, electra_blocks_1_ssz_snappy, int(clparams.ElectraVersion)); err != nil {
150+
panic(err)
151+
}
152+
153+
preState := state.New(&clparams.MainnetBeaconConfig)
154+
if err := utils.DecodeSSZSnappy(preState, electra_pre_state_ssz_snappy, int(clparams.ElectraVersion)); err != nil {
155+
panic(err)
156+
157+
}
158+
postState := state.New(&clparams.MainnetBeaconConfig)
159+
if err := utils.DecodeSSZSnappy(postState, electra_post_state_ssz_snappy, int(clparams.ElectraVersion)); err != nil {
160+
panic(err)
161+
}
162+
return []*cltypes.SignedBeaconBlock{block1, block2}, preState, postState
163+
}
164+
129165
func GetCapellaRandom() ([]*cltypes.SignedBeaconBlock, *state.CachingBeaconState, *state.CachingBeaconState) {
130166
block1 := cltypes.NewSignedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.CapellaVersion)
131167
block2 := cltypes.NewSignedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.CapellaVersion)

cl/beacon/handler/rewards.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (a *ApiHandler) GetEthV1BeaconRewardsBlocks(w http.ResponseWriter, r *http.
8686
defer snRoTx.Close()
8787

8888
stateGetter := state_accessors.GetValFnTxAndSnapshot(tx, snRoTx)
89-
slotData, err := state_accessors.ReadSlotData(stateGetter, slot)
89+
slotData, err := state_accessors.ReadSlotData(stateGetter, slot, a.beaconChainCfg)
9090
if err != nil {
9191
return nil, err
9292
}

cl/persistence/state/historical_states_reader/historical_states_reader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (r *HistoricalStatesReader) ReadHistoricalState(ctx context.Context, tx kv.
114114
blockHeader := block.SignedBeaconBlockHeader().Header
115115
blockHeader.Root = common.Hash{}
116116
// Read the epoch and per-slot data.
117-
slotData, err := state_accessors.ReadSlotData(kvGetter, slot)
117+
slotData, err := state_accessors.ReadSlotData(kvGetter, slot, r.cfg)
118118
if err != nil {
119119
return nil, err
120120
}
@@ -673,7 +673,7 @@ func (r *HistoricalStatesReader) ReconstructUint64ListDump(kvGetter state_access
673673

674674
func (r *HistoricalStatesReader) ReadValidatorsForHistoricalState(tx kv.Tx, kvGetter state_accessors.GetValFn, slot uint64) (*solid.ValidatorSet, error) {
675675
// Read the minimal beacon state which have the small fields.
676-
sd, err := state_accessors.ReadSlotData(kvGetter, slot)
676+
sd, err := state_accessors.ReadSlotData(kvGetter, slot, r.cfg)
677677
if err != nil {
678678
return nil, err
679679
}
@@ -777,7 +777,7 @@ func (r *HistoricalStatesReader) ReadParticipations(tx kv.Tx, kvGetter state_acc
777777
}
778778

779779
// Read the minimal beacon state which have the small fields.
780-
sd, err := state_accessors.ReadSlotData(kvGetter, slot)
780+
sd, err := state_accessors.ReadSlotData(kvGetter, slot, r.cfg)
781781
if err != nil {
782782
return nil, nil, err
783783
}
@@ -900,7 +900,7 @@ func (r *HistoricalStatesReader) tryCachingEpochsInParallell(tx kv.Tx, kvGetter
900900
}
901901

902902
func (r *HistoricalStatesReader) ReadValidatorsBalances(tx kv.Tx, kvGetter state_accessors.GetValFn, slot uint64) (solid.Uint64ListSSZ, error) {
903-
sd, err := state_accessors.ReadSlotData(kvGetter, slot)
903+
sd, err := state_accessors.ReadSlotData(kvGetter, slot, r.cfg)
904904
if err != nil {
905905
return nil, err
906906
}

cl/persistence/state/slot_data.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/erigontech/erigon/cl/clparams"
2525
"github.com/erigontech/erigon/cl/cltypes"
26+
"github.com/erigontech/erigon/cl/cltypes/solid"
2627
"github.com/erigontech/erigon/cl/phase1/core/state"
2728
ssz2 "github.com/erigontech/erigon/cl/ssz"
2829
)
@@ -40,6 +41,16 @@ type SlotData struct {
4041
// Capella
4142
NextWithdrawalIndex uint64
4243
NextWithdrawalValidatorIndex uint64
44+
// Electra
45+
DepositRequestsStartIndex uint64
46+
DepositBalanceToConsume uint64
47+
ExitBalanceToConsume uint64
48+
EarliestExitEpoch uint64
49+
ConsolidationBalanceToConsume uint64
50+
EarliestConsolidationEpoch uint64
51+
PendingDeposits *solid.ListSSZ[*solid.PendingDeposit]
52+
PendingPartialWithdrawals *solid.ListSSZ[*solid.PendingPartialWithdrawal]
53+
PendingConsolidations *solid.ListSSZ[*solid.PendingConsolidation]
4354

4455
// BlockRewards for proposer
4556
AttestationsRewards uint64
@@ -56,12 +67,21 @@ func SlotDataFromBeaconState(s *state.CachingBeaconState) *SlotData {
5667
ValidatorLength: uint64(s.ValidatorLength()),
5768
Eth1DataLength: uint64(s.Eth1DataVotes().Len()),
5869

59-
Version: s.Version(),
60-
Eth1Data: s.Eth1Data(),
61-
Eth1DepositIndex: s.Eth1DepositIndex(),
62-
NextWithdrawalIndex: s.NextWithdrawalIndex(),
63-
NextWithdrawalValidatorIndex: s.NextWithdrawalValidatorIndex(),
64-
Fork: s.Fork(),
70+
Version: s.Version(),
71+
Eth1Data: s.Eth1Data(),
72+
Eth1DepositIndex: s.Eth1DepositIndex(),
73+
NextWithdrawalIndex: s.NextWithdrawalIndex(),
74+
NextWithdrawalValidatorIndex: s.NextWithdrawalValidatorIndex(),
75+
DepositRequestsStartIndex: s.DepositRequestsStartIndex(),
76+
DepositBalanceToConsume: s.DepositBalanceToConsume(),
77+
ExitBalanceToConsume: s.ExitBalanceToConsume(),
78+
EarliestExitEpoch: s.EarliestExitEpoch(),
79+
ConsolidationBalanceToConsume: s.ConsolidationBalanceToConsume(),
80+
EarliestConsolidationEpoch: s.EarliestConsolidationEpoch(),
81+
PendingDeposits: s.PendingDeposits(),
82+
PendingPartialWithdrawals: s.PendingPartialWithdrawals(),
83+
PendingConsolidations: s.PendingConsolidations(),
84+
Fork: s.Fork(),
6585
}
6686
}
6787

@@ -87,7 +107,7 @@ func (m *SlotData) WriteTo(w io.Writer) error {
87107
}
88108

89109
// Deserialize deserializes the state from a byte slice with zstd compression.
90-
func (m *SlotData) ReadFrom(r io.Reader) error {
110+
func (m *SlotData) ReadFrom(r io.Reader, cfg *clparams.BeaconChainConfig) error {
91111
m.Eth1Data = &cltypes.Eth1Data{}
92112
m.Fork = &cltypes.Fork{}
93113
var err error
@@ -98,6 +118,12 @@ func (m *SlotData) ReadFrom(r io.Reader) error {
98118
}
99119
m.Version = clparams.StateVersion(versionByte[0])
100120

121+
if m.Version >= clparams.ElectraVersion {
122+
m.PendingDeposits = solid.NewPendingDepositList(cfg)
123+
m.PendingPartialWithdrawals = solid.NewPendingWithdrawalList(cfg)
124+
m.PendingConsolidations = solid.NewPendingConsolidationList(cfg)
125+
}
126+
101127
lenB := make([]byte, 8)
102128
if _, err = r.Read(lenB); err != nil {
103129
return err
@@ -122,5 +148,19 @@ func (m *SlotData) getSchema() []interface{} {
122148
if m.Version >= clparams.CapellaVersion {
123149
schema = append(schema, &m.NextWithdrawalIndex, &m.NextWithdrawalValidatorIndex)
124150
}
151+
152+
if m.Version >= clparams.ElectraVersion {
153+
schema = append(schema,
154+
&m.DepositRequestsStartIndex,
155+
&m.DepositBalanceToConsume,
156+
&m.ExitBalanceToConsume,
157+
&m.EarliestExitEpoch,
158+
&m.ConsolidationBalanceToConsume,
159+
&m.EarliestConsolidationEpoch,
160+
m.PendingDeposits,
161+
m.PendingPartialWithdrawals,
162+
m.PendingConsolidations,
163+
)
164+
}
125165
return schema
126166
}

0 commit comments

Comments
 (0)