Skip to content

Commit 1841573

Browse files
claravanstadengirazoki
authored andcommitted
Electra upgrade (Snowfork#1283)
* electra upgrade * relayer progress * more electra work * fix config * fixes * fix tests * update go version * containers * electra changes * try testing lodestar + electra * revert local script * mekong network setup * electra updates * fixes * fixes * fix tests * electra local net * fix config * cleanup * fixes * progress * fix execution header proof * revert testing changes * adds tests * cleanup * cleanup * uses geth binary instead of docker * removes all traces of capella * devnet6 fixes * update bindings
1 parent f9b3fc2 commit 1841573

37 files changed

+4169
-3564
lines changed

.github/workflows/relayer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: setup go
2323
uses: actions/checkout@v4
2424
with:
25-
go-version: '^1.20.1'
25+
go-version: '^1.22.5'
2626

2727
- name: check go version
2828
run: go version

relayer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To generate the SSZ encodings:
4646

4747
```
4848
go install github.com/ferranbt/fastssz/sszgen
49-
sszgen --path relays/beacon/state/beacon.go --objs BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet
49+
sszgen --path relays/beacon/state/beacon.go --objs BlockRootsContainerMainnet,TransactionsRootContainer,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,SignedBeaconBlockDeneb,SignedBeaconBlockElectra,BeaconStateElectra,BeaconBlockElectra
5050
```
5151

5252
## Configuration

relayer/cmd/generate_beacon_data.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
402402
for {
403403
nextFinalizedUpdateScale, err := s.GetFinalizedUpdate()
404404
if err != nil {
405-
return fmt.Errorf("get next finalized header update: %w", err)
405+
log.Error(err)
406+
continue
406407
}
407408
nextFinalizedUpdate := nextFinalizedUpdateScale.Payload.ToJSON()
408409
nextFinalizedUpdatePeriod := p.ComputeSyncPeriodAtSlot(nextFinalizedUpdate.FinalizedHeader.Slot)
@@ -416,7 +417,8 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
416417
// generate nextSyncCommitteeUpdate
417418
nextSyncCommitteeUpdateScale, err := s.GetSyncCommitteePeriodUpdate(initialSyncPeriod+1, 0)
418419
if err != nil {
419-
return fmt.Errorf("get sync committee update: %w", err)
420+
log.Error(err)
421+
continue
420422
}
421423
nextSyncCommitteeUpdate := nextSyncCommitteeUpdateScale.Payload.ToJSON()
422424
err = writeJSONToFile(nextSyncCommitteeUpdate, fmt.Sprintf("%s/%s", pathToBeaconTestFixtureFiles, "next-sync-committee-update.json"))

relayer/cmd/import_beacon_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func importBeaconState(cmd *cobra.Command, _ []string) error {
9292
return fmt.Errorf("read finalized state data from file: %w", err)
9393
}
9494

95-
afterDenebFork := (conf.Source.Beacon.Spec.DenebForkEpoch + 1) * 32
95+
afterDenebFork := (conf.Source.Beacon.Spec.ForkVersions.Deneb + 1) * 32
9696

9797
attestedState, err := syncer.UnmarshalBeaconState(afterDenebFork, attestedData)
9898
if err != nil {

relayer/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func Build() {
1313
}
1414

1515
func BuildMain() error {
16-
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet")
16+
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BlockRootsContainerMainnet,TransactionsRootContainer,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,SignedBeaconBlockDeneb,SignedBeaconBlockElectra,BeaconStateElectra,BeaconBlockElectra")
1717
if err != nil {
1818
return err
1919
}

relayer/relays/beacon/config/config.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ type Config struct {
1111
}
1212

1313
type SpecSettings struct {
14-
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
15-
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
16-
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
17-
DenebForkEpoch uint64 `mapstructure:"denebForkedEpoch"`
14+
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
15+
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
16+
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
17+
ForkVersions ForkVersions `mapstructure:"forkVersions"`
18+
}
19+
20+
type ForkVersions struct {
21+
Deneb uint64 `mapstructure:"deneb"`
22+
Electra uint64 `mapstructure:"electra"`
1823
}
1924

2025
type SourceConfig struct {

relayer/relays/beacon/header/header_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromAPI(t *testing.T) {
2323
settings := config.SpecSettings{
2424
SlotsInEpoch: 32,
2525
EpochsPerSyncCommitteePeriod: 256,
26-
DenebForkEpoch: 0,
26+
ForkVersions: config.ForkVersions{
27+
Deneb: 0,
28+
Electra: 800000,
29+
},
2730
}
2831
p := protocol.New(settings, MaxRedundancy)
2932
client := mock.API{}
@@ -81,7 +84,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStore(t *testing.T) {
8184
settings := config.SpecSettings{
8285
SlotsInEpoch: 32,
8386
EpochsPerSyncCommitteePeriod: 256,
84-
DenebForkEpoch: 0,
87+
ForkVersions: config.ForkVersions{
88+
Deneb: 0,
89+
Electra: 800000,
90+
},
8591
}
8692
p := protocol.New(settings, MaxRedundancy)
8793
client := mock.API{}
@@ -147,7 +153,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStoreWithDifferentBlocks(t *test
147153
settings := config.SpecSettings{
148154
SlotsInEpoch: 32,
149155
EpochsPerSyncCommitteePeriod: 256,
150-
DenebForkEpoch: 0,
156+
ForkVersions: config.ForkVersions{
157+
Deneb: 0,
158+
Electra: 800000,
159+
},
151160
}
152161
p := protocol.New(settings, MaxRedundancy)
153162
client := mock.API{}
@@ -213,7 +222,10 @@ func TestSyncInterimFinalizedUpdate_BeaconStateNotAvailableInAPIAndStore(t *test
213222
settings := config.SpecSettings{
214223
SlotsInEpoch: 32,
215224
EpochsPerSyncCommitteePeriod: 256,
216-
DenebForkEpoch: 0,
225+
ForkVersions: config.ForkVersions{
226+
Deneb: 0,
227+
Electra: 800000,
228+
},
217229
}
218230
p := protocol.New(settings, MaxRedundancy)
219231
client := mock.API{}
@@ -257,7 +269,10 @@ func TestSyncInterimFinalizedUpdate_NoValidBlocksFound(t *testing.T) {
257269
settings := config.SpecSettings{
258270
SlotsInEpoch: 32,
259271
EpochsPerSyncCommitteePeriod: 256,
260-
DenebForkEpoch: 0,
272+
ForkVersions: config.ForkVersions{
273+
Deneb: 0,
274+
Electra: 800000,
275+
},
261276
}
262277
p := protocol.New(settings, MaxRedundancy)
263278
client := mock.API{}
@@ -332,7 +347,6 @@ func TestFindLatestCheckPoint(t *testing.T) {
332347
settings := config.SpecSettings{
333348
SlotsInEpoch: 4,
334349
EpochsPerSyncCommitteePeriod: 2,
335-
DenebForkEpoch: 0,
336350
}
337351
maxRedundancy := uint64(2)
338352
p := protocol.New(settings, maxRedundancy)

relayer/relays/beacon/header/syncer/api/api.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type BeaconAPI interface {
3636
GetBeaconBlockBySlot(slot uint64) (BeaconBlockResponse, error)
3737
GetBeaconBlockRoot(slot uint64) (common.Hash, error)
3838
GetBeaconBlock(blockID common.Hash) (BeaconBlockResponse, error)
39+
GetBeaconBlockBytes(blockID common.Hash) ([]byte, error)
3940
GetSyncCommitteePeriodUpdate(from uint64) (SyncCommitteePeriodUpdateResponse, error)
4041
GetLatestFinalizedUpdate() (LatestFinalisedUpdateResponse, error)
4142
GetBeaconState(stateIdOrSlot string) ([]byte, error)
@@ -417,7 +418,7 @@ func (b *BeaconClient) GetBeaconState(stateIdOrSlot string) ([]byte, error) {
417418
res, err := b.httpClient.Do(req)
418419
endTime := time.Now()
419420
duration := endTime.Sub(startTime)
420-
log.WithFields(log.Fields{"startTime": startTime.Format(time.UnixDate), "endTime": endTime.Format(time.UnixDate), "duration": duration.Seconds()}).Warn("beacon state download time")
421+
log.WithFields(log.Fields{"startTime": startTime.Format(time.UnixDate), "endTime": endTime.Format(time.UnixDate), "duration": duration.Seconds()}).Info("beacon state download time")
421422

422423
if err != nil {
423424
return data, err
@@ -436,3 +437,31 @@ func (b *BeaconClient) GetBeaconState(stateIdOrSlot string) ([]byte, error) {
436437
data = buf.Bytes()
437438
return data, nil
438439
}
440+
441+
func (b *BeaconClient) GetBeaconBlockBytes(blockID common.Hash) ([]byte, error) {
442+
var data []byte
443+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/eth/v2/beacon/blocks/%s", b.stateEndpoint, blockID), nil)
444+
if err != nil {
445+
return data, err
446+
}
447+
448+
req.Header.Add("Accept", "application/octet-stream")
449+
450+
res, err := b.httpClient.Do(req)
451+
if err != nil {
452+
return data, err
453+
}
454+
455+
if res.StatusCode != http.StatusOK {
456+
if res.StatusCode == 404 {
457+
return data, ErrNotFound
458+
}
459+
460+
return data, fmt.Errorf("%s: %d", DoHTTPRequestErrorMessage, res.StatusCode)
461+
}
462+
463+
buf := new(bytes.Buffer)
464+
buf.ReadFrom(res.Body)
465+
data = buf.Bytes()
466+
return data, nil
467+
}

relayer/relays/beacon/header/syncer/api/api_deneb.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package api
33
import (
44
"math/big"
55

6-
"github.com/ethereum/go-ethereum/common"
76
"github.com/snowfork/go-substrate-rpc-client/v4/types"
8-
beaconjson "github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/json"
97
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
108
"github.com/snowfork/snowbridge/relayer/relays/beacon/state"
119
"github.com/snowfork/snowbridge/relayer/relays/util"
@@ -55,49 +53,3 @@ func DenebExecutionPayloadToScale(e *state.ExecutionPayloadDeneb) (scale.Executi
5553
}, nil
5654
}
5755

58-
func DenebJsonExecutionPayloadHeaderToScale(e *beaconjson.FullExecutionPayloadHeaderJson) (scale.ExecutionPayloadHeaderDeneb, error) {
59-
var executionPayloadHeader scale.ExecutionPayloadHeaderDeneb
60-
var baseFeePerGas big.Int
61-
baseFeePerGasU64, err := util.ToUint64(e.BaseFeePerGas)
62-
if err != nil {
63-
return executionPayloadHeader, err
64-
}
65-
blockNumber, err := util.ToUint64(e.BlockNumber)
66-
if err != nil {
67-
return executionPayloadHeader, err
68-
}
69-
baseFeePerGas.SetUint64(baseFeePerGasU64)
70-
gasLimit, err := util.ToUint64(e.GasLimit)
71-
if err != nil {
72-
return executionPayloadHeader, err
73-
}
74-
gasUsed, err := util.ToUint64(e.GasUsed)
75-
if err != nil {
76-
return executionPayloadHeader, err
77-
}
78-
timestamp, err := util.ToUint64(e.Timestamp)
79-
if err != nil {
80-
return executionPayloadHeader, err
81-
}
82-
blobGasUsed, _ := util.ToUint64(e.BlobGasUsed)
83-
excessBlobGas, _ := util.ToUint64(e.ExcessBlobGas)
84-
return scale.ExecutionPayloadHeaderDeneb{
85-
ParentHash: types.NewH256(common.HexToHash(e.ParentHash).Bytes()),
86-
FeeRecipient: types.NewH160(common.HexToAddress(e.FeeRecipient).Bytes()),
87-
StateRoot: types.NewH256(common.HexToHash(e.StateRoot).Bytes()),
88-
ReceiptsRoot: types.NewH256(common.HexToHash(e.ReceiptsRoot).Bytes()),
89-
LogsBloom: common.FromHex(e.LogsBloom),
90-
PrevRandao: types.NewH256(common.HexToHash(e.PrevRandao).Bytes()),
91-
BlockNumber: types.NewU64(blockNumber),
92-
GasLimit: types.NewU64(gasLimit),
93-
GasUsed: types.NewU64(gasUsed),
94-
Timestamp: types.NewU64(timestamp),
95-
ExtraData: common.FromHex(e.ExtraData),
96-
BaseFeePerGas: types.NewU256(baseFeePerGas),
97-
BlockHash: types.NewH256(common.HexToHash(e.BlockHash).Bytes()),
98-
TransactionsRoot: types.NewH256(common.HexToHash(e.TransactionsRoot).Bytes()),
99-
WithdrawalsRoot: types.NewH256(common.HexToHash(e.WithdrawalsRoot).Bytes()),
100-
BlobGasUsed: types.NewU64(blobGasUsed),
101-
ExcessBlobGas: types.NewU64(excessBlobGas),
102-
}, nil
103-
}

0 commit comments

Comments
 (0)