Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electra upgrade #1283

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: setup go
uses: actions/checkout@v4
with:
go-version: '^1.20.1'
go-version: '^1.22.5'

- name: check go version
run: go version
Expand Down
12 changes: 7 additions & 5 deletions relayer/cmd/generate_beacon_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ type InboundFixture struct {

const (
pathToBeaconTestFixtureFiles = "polkadot-sdk/bridges/snowbridge/pallets/ethereum-client/tests/fixtures"
pathToInboundQueueFixtureTemplate = "polkadot-sdk/bridges/snowbridge/templates/beacon-fixtures.mustache"
pathToInboundQueueFixtureTemplate = "relayer/templates/beacon-fixtures.mustache"
pathToInboundQueueFixtureData = "polkadot-sdk/bridges/snowbridge/pallets/ethereum-client/fixtures/src/lib.rs"
pathToInboundQueueFixtureTestCaseTemplate = "polkadot-sdk/bridges/snowbridge/templates/inbound-fixtures.mustache"
pathToInboundQueueFixtureTestCaseTemplate = "relayer/templates/inbound-fixtures.mustache"
pathToInboundQueueFixtureTestCaseData = "polkadot-sdk/bridges/snowbridge/pallets/inbound-queue/fixtures/src/%s.rs"
)

Expand Down Expand Up @@ -206,7 +206,7 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
client := api.NewBeaconClient(conf.Source.Beacon.Endpoint, conf.Source.Beacon.StateEndpoint)
s := syncer.New(client, &store, p)

viper.SetConfigFile("/tmp/snowbridge/execution-relay-asset-hub.json")
viper.SetConfigFile("/tmp/snowbridge/execution-relay-asset-hub-0.json")

if err = viper.ReadInConfig(); err != nil {
return err
Expand Down Expand Up @@ -402,7 +402,8 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
for {
nextFinalizedUpdateScale, err := s.GetFinalizedUpdate()
if err != nil {
return fmt.Errorf("get next finalized header update: %w", err)
log.Error(err)
continue
}
nextFinalizedUpdate := nextFinalizedUpdateScale.Payload.ToJSON()
nextFinalizedUpdatePeriod := p.ComputeSyncPeriodAtSlot(nextFinalizedUpdate.FinalizedHeader.Slot)
Expand All @@ -416,7 +417,8 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
// generate nextSyncCommitteeUpdate
nextSyncCommitteeUpdateScale, err := s.GetSyncCommitteePeriodUpdate(initialSyncPeriod+1, 0)
if err != nil {
return fmt.Errorf("get sync committee update: %w", err)
log.Error(err)
continue
}
nextSyncCommitteeUpdate := nextSyncCommitteeUpdateScale.Payload.ToJSON()
err = writeJSONToFile(nextSyncCommitteeUpdate, fmt.Sprintf("%s/%s", pathToBeaconTestFixtureFiles, "next-sync-committee-update.json"))
Expand Down
2 changes: 1 addition & 1 deletion relayer/cmd/import_beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func importBeaconState(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("read finalized state data from file: %w", err)
}

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

attestedState, err := syncer.UnmarshalBeaconState(afterDenebFork, attestedData)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion relayer/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Build() {
}

func BuildMain() error {
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet")
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,SignedBeaconBlockDeneb,SignedBeaconBlockElectra,BeaconStateElectra,BeaconBlockElectra")
if err != nil {
return err
}
Expand Down
13 changes: 9 additions & 4 deletions relayer/relays/beacon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ type Config struct {
}

type SpecSettings struct {
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
DenebForkEpoch uint64 `mapstructure:"denebForkedEpoch"`
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
ForkVersions ForkVersions `mapstructure:"forkVersions"`
}

type ForkVersions struct {
Deneb uint64 `mapstructure:"deneb"`
Electra uint64 `mapstructure:"electra"`
}

type SourceConfig struct {
Expand Down
26 changes: 20 additions & 6 deletions relayer/relays/beacon/header/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromAPI(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -81,7 +84,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStore(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -147,7 +153,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStoreWithDifferentBlocks(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -213,7 +222,10 @@ func TestSyncInterimFinalizedUpdate_BeaconStateNotAvailableInAPIAndStore(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -257,7 +269,10 @@ func TestSyncInterimFinalizedUpdate_NoValidBlocksFound(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -332,7 +347,6 @@ func TestFindLatestCheckPoint(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 4,
EpochsPerSyncCommitteePeriod: 2,
DenebForkEpoch: 0,
}
maxRedundancy := uint64(2)
p := protocol.New(settings, maxRedundancy)
Expand Down
31 changes: 30 additions & 1 deletion relayer/relays/beacon/header/syncer/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type BeaconAPI interface {
GetBeaconBlockBySlot(slot uint64) (BeaconBlockResponse, error)
GetBeaconBlockRoot(slot uint64) (common.Hash, error)
GetBeaconBlock(blockID common.Hash) (BeaconBlockResponse, error)
GetBeaconBlockBytes(blockID common.Hash) ([]byte, error)
GetSyncCommitteePeriodUpdate(from uint64) (SyncCommitteePeriodUpdateResponse, error)
GetLatestFinalizedUpdate() (LatestFinalisedUpdateResponse, error)
GetBeaconState(stateIdOrSlot string) ([]byte, error)
Expand Down Expand Up @@ -417,7 +418,7 @@ func (b *BeaconClient) GetBeaconState(stateIdOrSlot string) ([]byte, error) {
res, err := b.httpClient.Do(req)
endTime := time.Now()
duration := endTime.Sub(startTime)
log.WithFields(log.Fields{"startTime": startTime.Format(time.UnixDate), "endTime": endTime.Format(time.UnixDate), "duration": duration.Seconds()}).Warn("beacon state download time")
log.WithFields(log.Fields{"startTime": startTime.Format(time.UnixDate), "endTime": endTime.Format(time.UnixDate), "duration": duration.Seconds()}).Info("beacon state download time")

if err != nil {
return data, err
Expand All @@ -436,3 +437,31 @@ func (b *BeaconClient) GetBeaconState(stateIdOrSlot string) ([]byte, error) {
data = buf.Bytes()
return data, nil
}

func (b *BeaconClient) GetBeaconBlockBytes(blockID common.Hash) ([]byte, error) {
var data []byte
req, err := http.NewRequest("GET", fmt.Sprintf("%s/eth/v2/beacon/blocks/%s", b.stateEndpoint, blockID), nil)
if err != nil {
return data, err
}

req.Header.Add("Accept", "application/octet-stream")

res, err := b.httpClient.Do(req)
if err != nil {
return data, err
}

if res.StatusCode != http.StatusOK {
if res.StatusCode == 404 {
return data, ErrNotFound
}

return data, fmt.Errorf("%s: %d", DoHTTPRequestErrorMessage, res.StatusCode)
}

buf := new(bytes.Buffer)
buf.ReadFrom(res.Body)
data = buf.Bytes()
return data, nil
}
48 changes: 0 additions & 48 deletions relayer/relays/beacon/header/syncer/api/api_deneb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package api
import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
beaconjson "github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/json"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
"github.com/snowfork/snowbridge/relayer/relays/beacon/state"
"github.com/snowfork/snowbridge/relayer/relays/util"
Expand Down Expand Up @@ -55,49 +53,3 @@ func DenebExecutionPayloadToScale(e *state.ExecutionPayloadDeneb) (scale.Executi
}, nil
}

func DenebJsonExecutionPayloadHeaderToScale(e *beaconjson.FullExecutionPayloadHeaderJson) (scale.ExecutionPayloadHeaderDeneb, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method.

var executionPayloadHeader scale.ExecutionPayloadHeaderDeneb
var baseFeePerGas big.Int
baseFeePerGasU64, err := util.ToUint64(e.BaseFeePerGas)
if err != nil {
return executionPayloadHeader, err
}
blockNumber, err := util.ToUint64(e.BlockNumber)
if err != nil {
return executionPayloadHeader, err
}
baseFeePerGas.SetUint64(baseFeePerGasU64)
gasLimit, err := util.ToUint64(e.GasLimit)
if err != nil {
return executionPayloadHeader, err
}
gasUsed, err := util.ToUint64(e.GasUsed)
if err != nil {
return executionPayloadHeader, err
}
timestamp, err := util.ToUint64(e.Timestamp)
if err != nil {
return executionPayloadHeader, err
}
blobGasUsed, _ := util.ToUint64(e.BlobGasUsed)
excessBlobGas, _ := util.ToUint64(e.ExcessBlobGas)
return scale.ExecutionPayloadHeaderDeneb{
ParentHash: types.NewH256(common.HexToHash(e.ParentHash).Bytes()),
FeeRecipient: types.NewH160(common.HexToAddress(e.FeeRecipient).Bytes()),
StateRoot: types.NewH256(common.HexToHash(e.StateRoot).Bytes()),
ReceiptsRoot: types.NewH256(common.HexToHash(e.ReceiptsRoot).Bytes()),
LogsBloom: common.FromHex(e.LogsBloom),
PrevRandao: types.NewH256(common.HexToHash(e.PrevRandao).Bytes()),
BlockNumber: types.NewU64(blockNumber),
GasLimit: types.NewU64(gasLimit),
GasUsed: types.NewU64(gasUsed),
Timestamp: types.NewU64(timestamp),
ExtraData: common.FromHex(e.ExtraData),
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(common.HexToHash(e.BlockHash).Bytes()),
TransactionsRoot: types.NewH256(common.HexToHash(e.TransactionsRoot).Bytes()),
WithdrawalsRoot: types.NewH256(common.HexToHash(e.WithdrawalsRoot).Bytes()),
BlobGasUsed: types.NewU64(blobGasUsed),
ExcessBlobGas: types.NewU64(excessBlobGas),
}, nil
}
Loading
Loading