Skip to content

Commit

Permalink
electra local net
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Jan 8, 2025
1 parent 1dc8c16 commit 0c382c3
Show file tree
Hide file tree
Showing 20 changed files with 317 additions and 1,090 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

# ethereum
foundry-bin
#go-ethereum Geth 1.14.9 is not in nix flakes yet
go-ethereum
# gnupg for forge install
gnupg

Expand Down Expand Up @@ -87,7 +87,7 @@
export RUSTUP_HOME=$PWD/.rustup
export RUST_NIGHTLY_VERSION=nightly-2024-02-08
export PATH=$CARGO_HOME/bin:$PATH
export LODESTAR_VERSION=v1.19.0
export LODESTAR_VERSION=v1.23.1
eval "$(direnv hook bash)"
Expand Down
10 changes: 8 additions & 2 deletions relayer/relays/beacon/header/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,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 @@ -266,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
46 changes: 0 additions & 46 deletions relayer/relays/beacon/header/syncer/api/api_electra.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,10 @@
package api

import (
"math/big"

"github.com/snowfork/go-substrate-rpc-client/v4/types"
"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"
)

func ElectraExecutionPayloadToScale(e *state.ExecutionPayloadElectra) (scale.ExecutionPayloadHeaderElectra, error) {
var payloadHeader scale.ExecutionPayloadHeaderElectra
transactionsContainer := state.TransactionsRootContainer{}
transactionsContainer.Transactions = e.Transactions

transactionsRoot, err := transactionsContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

withdrawalContainer := state.WithdrawalsRootContainerMainnet{}
withdrawalContainer.Withdrawals = e.Withdrawals
withdrawalRoot, err := withdrawalContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

baseFeePerGas := big.Int{}
// Change BaseFeePerGas back from little-endian to big-endian
baseFeePerGas.SetBytes(util.ChangeByteOrder(e.BaseFeePerGas[:]))

return scale.ExecutionPayloadHeaderElectra{
ParentHash: types.NewH256(e.ParentHash[:]),
FeeRecipient: e.FeeRecipient,
StateRoot: types.NewH256(e.StateRoot[:]),
ReceiptsRoot: types.NewH256(e.ReceiptsRoot[:]),
LogsBloom: e.LogsBloom[:],
PrevRandao: types.NewH256(e.PrevRandao[:]),
BlockNumber: types.NewU64(e.BlockNumber),
GasLimit: types.NewU64(e.GasLimit),
GasUsed: types.NewU64(e.GasUsed),
Timestamp: types.NewU64(e.Timestamp),
ExtraData: e.ExtraData,
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(e.BlockHash[:]),
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalRoot,
BlobGasUsed: types.NewU64(e.BlobGasUsed),
ExcessBlobGas: types.NewU64(e.ExcessBlobGas),
}, nil
}

func (a AttesterSlashingResponse) ToFastSSZElectra() (*state.AttesterSlashingElectra, error) {
attestation1, err := a.Attestation1.ToFastSSZElectra()
if err != nil {
Expand Down
45 changes: 1 addition & 44 deletions relayer/relays/beacon/header/syncer/api/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func (b BeaconBlockResponse) ToFastSSZ(forkVersion protocol.ForkVersion) (state.
SyncCommitteeBits: syncCommitteeBits,
SyncCommitteeSignature: syncCommitteeSignature,
},
ExecutionPayload: &state.ExecutionPayloadElectra{
ExecutionPayload: &state.ExecutionPayloadDeneb{
ParentHash: parentHash,
FeeRecipient: feeRecipient,
StateRoot: executionStateRoot,
Expand Down Expand Up @@ -1116,46 +1116,3 @@ func CapellaExecutionPayloadToScale(e *state.ExecutionPayloadCapella) (scale.Exe
WithdrawalsRoot: withdrawalRoot,
}, nil
}

func CapellaJsonExecutionPayloadHeaderToScale(e *beaconjson.FullExecutionPayloadHeaderJson) (scale.ExecutionPayloadHeaderCapella, error) {
var executionPayloadHeader scale.ExecutionPayloadHeaderCapella
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
}
return scale.ExecutionPayloadHeaderCapella{
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.Hex2Bytes(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.Hex2Bytes(e.ExtraData),
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(common.HexToHash(e.ParentHash).Bytes()),
TransactionsRoot: types.NewH256(common.HexToHash(e.TransactionsRoot).Bytes()),
WithdrawalsRoot: types.NewH256(common.HexToHash(e.WithdrawalsRoot).Bytes()),
}, nil
}
2 changes: 1 addition & 1 deletion relayer/relays/beacon/header/syncer/json/beacon_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func removeLeadingZeroHash(s string) string {
type VersionedExecutionPayloadHeader struct {
Capella *ExecutionPayloadHeaderCapella `json:"Capella,omitempty"`
Deneb *ExecutionPayloadHeaderDeneb `json:"Deneb,omitempty"`
Electra *ExecutionPayloadHeaderElectra `json:"Electra,omitempty"`
Electra *ExecutionPayloadHeaderDeneb `json:"Electra,omitempty"` // Execution payload header does not change in Electra
}

func (v *VersionedExecutionPayloadHeader) RemoveLeadingZeroHashes() {
Expand Down
83 changes: 0 additions & 83 deletions relayer/relays/beacon/header/syncer/json/beacon_json_electra.go

This file was deleted.

75 changes: 0 additions & 75 deletions relayer/relays/beacon/header/syncer/scale/beacon_electra.go

This file was deleted.

2 changes: 1 addition & 1 deletion relayer/relays/beacon/header/syncer/scale/beacon_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type BeaconState struct {
type VersionedExecutionPayloadHeader struct {
Capella *ExecutionPayloadHeaderCapella
Deneb *ExecutionPayloadHeaderDeneb
Electra *ExecutionPayloadHeaderElectra
Electra *ExecutionPayloadHeaderDeneb // Did not change in Electra
}

var (
Expand Down
8 changes: 1 addition & 7 deletions relayer/relays/beacon/header/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,7 @@ func (s *Syncer) GetHeaderUpdate(blockRoot common.Hash, checkpoint *cache.Proof)

var versionedExecutionPayloadHeader scale.VersionedExecutionPayloadHeader
forkVersion := s.protocol.ForkVersion(slot)
if forkVersion == protocol.Electra {
executionPayloadScale, err := api.ElectraExecutionPayloadToScale(sszBlock.ExecutionPayloadElectra())
if err != nil {
return scale.HeaderUpdatePayload{}, err
}
versionedExecutionPayloadHeader = scale.VersionedExecutionPayloadHeader{Electra: &executionPayloadScale}
} else if forkVersion == protocol.Deneb {
if forkVersion == protocol.Electra || forkVersion == protocol.Deneb {
executionPayloadScale, err := api.DenebExecutionPayloadToScale(sszBlock.ExecutionPayloadDeneb())
if err != nil {
return scale.HeaderUpdatePayload{}, err
Expand Down
5 changes: 0 additions & 5 deletions relayer/relays/beacon/state/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ type BeaconBlock interface {
GetBeaconSlot() uint64
ExecutionPayloadCapella() *ExecutionPayloadCapella
ExecutionPayloadDeneb() *ExecutionPayloadDeneb
ExecutionPayloadElectra() *ExecutionPayloadElectra
GetTree() (*ssz.Node, error)
GetBlockBodyTree() (*ssz.Node, error)
}
Expand Down Expand Up @@ -300,10 +299,6 @@ func (b *BeaconBlockCapellaMainnet) ExecutionPayloadDeneb() *ExecutionPayloadDen
return nil
}

func (b *BeaconBlockCapellaMainnet) ExecutionPayloadElectra() *ExecutionPayloadElectra {
return nil
}

func (b *BeaconStateCapellaMainnet) GetSlot() uint64 {
return b.Slot
}
Expand Down
4 changes: 0 additions & 4 deletions relayer/relays/beacon/state/beacon_deneb.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ func (b *BeaconBlockDenebMainnet) ExecutionPayloadDeneb() *ExecutionPayloadDeneb
return b.Body.ExecutionPayload
}

func (b *BeaconBlockDenebMainnet) ExecutionPayloadElectra() *ExecutionPayloadElectra {
return nil
}

func (b *BeaconStateDenebMainnet) GetSlot() uint64 {
return b.Slot
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/relays/beacon/state/beacon_deneb_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0c382c3

Please sign in to comment.