Skip to content
Merged

Fulu v1 #1599

Show file tree
Hide file tree
Changes from all commits
Commits
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 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", "BlockRootsContainerMainnet,TransactionsRootContainer,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,SignedBeaconBlockDeneb,SignedBeaconBlockElectra,BeaconStateElectra,BeaconBlockElectra")
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BlockRootsContainerMainnet,TransactionsRootContainer,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,SignedBeaconBlockDeneb,SignedBeaconBlockElectra,BeaconStateElectra,BeaconBlockElectra,BeaconStateFulu")
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions relayer/relays/beacon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SpecSettings struct {
type ForkVersions struct {
Deneb uint64 `mapstructure:"deneb"`
Electra uint64 `mapstructure:"electra"`
Fulu uint64 `mapstructure:"fulu"`
}

type SourceConfig struct {
Expand Down
33 changes: 13 additions & 20 deletions relayer/relays/beacon/header/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ func TestSyncInterimFinalizedUpdate_WithDataFromAPI(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
ForkVersions: forkVersions(),
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -84,10 +81,7 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStore(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
ForkVersions: forkVersions(),
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -153,10 +147,7 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStoreWithDifferentBlocks(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
ForkVersions: forkVersions(),
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -222,10 +213,7 @@ func TestSyncInterimFinalizedUpdate_BeaconStateNotAvailableInAPIAndStore(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
ForkVersions: forkVersions(),
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -269,10 +257,7 @@ func TestSyncInterimFinalizedUpdate_NoValidBlocksFound(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
ForkVersions: forkVersions(),
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -440,3 +425,11 @@ func TestFindLatestCheckPoint(t *testing.T) {
assert.Equal(t, headerIndex4, header.BeaconBlockRoot)
assert.Equal(t, uint64(46), header.BeaconSlot)
}

func forkVersions() config.ForkVersions {
return config.ForkVersions{
Deneb: 0,
Electra: 800000,
Fulu: 1000000,
}
}
10 changes: 7 additions & 3 deletions relayer/relays/beacon/header/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ func (s *Syncer) GetBlockRoots(slot uint64) (scale.BlockRootProof, error) {
forkVersion := s.protocol.ForkVersion(slot)

blockRootsContainer = &state.BlockRootsContainerMainnet{}
if forkVersion == protocol.Electra {
if forkVersion == protocol.Fulu {
beaconState = &state.BeaconStateFulu{}
} else if forkVersion == protocol.Electra {
beaconState = &state.BeaconStateElectra{}
} else {
beaconState = &state.BeaconStateDenebMainnet{}
Expand Down Expand Up @@ -557,7 +559,7 @@ func (s *Syncer) GetHeaderUpdate(blockRoot common.Hash, checkpoint *cache.Proof)

var signedBlock state.SignedBeaconBlock
forkVersion := s.protocol.ForkVersion(slot)
if forkVersion == protocol.Electra {
if forkVersion == protocol.Fulu || forkVersion == protocol.Electra {
signedBlock = &state.SignedBeaconBlockElectra{}
} else {
signedBlock = &state.SignedBeaconBlockDeneb{}
Expand Down Expand Up @@ -635,7 +637,9 @@ func (s *Syncer) getBeaconStateAtSlot(slot uint64) (state.BeaconState, error) {
func (s *Syncer) UnmarshalBeaconState(slot uint64, data []byte) (state.BeaconState, error) {
var beaconState state.BeaconState
forkVersion := s.protocol.ForkVersion(slot)
if forkVersion == protocol.Electra {
if forkVersion == protocol.Fulu {
beaconState = &state.BeaconStateFulu{}
} else if forkVersion == protocol.Electra {
beaconState = &state.BeaconStateElectra{}
} else {
beaconState = &state.BeaconStateDenebMainnet{}
Expand Down
28 changes: 20 additions & 8 deletions relayer/relays/beacon/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,58 @@ type ForkVersion string
const (
Deneb ForkVersion = "Deneb"
Electra ForkVersion = "Electra"
Fulu ForkVersion = "Fulu"
)

func (p *Protocol) ForkVersion(slot uint64) ForkVersion {
epoch := p.ComputeEpochAtSlot(slot)
if epoch >= p.Settings.ForkVersions.Electra {
return Electra
var fv ForkVersion
if epoch >= p.Settings.ForkVersions.Fulu {
fv = Fulu
} else if epoch >= p.Settings.ForkVersions.Electra {
fv = Electra
} else {
fv = Deneb
}
return Deneb
log.WithField("ForkVersion", fv).Info("Found fork version")
return fv
}

func (p *Protocol) BlockRootGeneralizedIndex(slot uint64) int {
if p.ForkVersion(slot) == Electra {
forkVersion := p.ForkVersion(slot)
if forkVersion == Fulu || forkVersion == Electra {
return ElectraBlockRootGeneralizedIndex
}
return AltairBlockRootGeneralizedIndex
}

func (p *Protocol) FinalizedCheckpointGeneralizedIndex(slot uint64) int {
if p.ForkVersion(slot) == Electra {
forkVersion := p.ForkVersion(slot)
if forkVersion == Fulu || forkVersion == Electra {
return ElectraFinalizedCheckpointGeneralizedIndex
}
return AltairFinalizedCheckpointGeneralizedIndex
}

func (p *Protocol) CurrentSyncCommitteeGeneralizedIndex(slot uint64) int {
if p.ForkVersion(slot) == Electra {
forkVersion := p.ForkVersion(slot)
if forkVersion == Fulu || forkVersion == Electra {
return ElectraCurrentSyncCommitteeGeneralizedIndex
}
return AltairCurrentSyncCommitteeGeneralizedIndex
}

func (p *Protocol) NextSyncCommitteeGeneralizedIndex(slot uint64) int {
if p.ForkVersion(slot) == Electra {
forkVersion := p.ForkVersion(slot)
if forkVersion == Fulu || forkVersion == Electra {
return ElectraNextSyncCommitteeGeneralizedIndex
}
return AltairNextSyncCommitteeGeneralizedIndex
}

func (p *Protocol) ExecutionPayloadGeneralizedIndex(slot uint64) int {
if p.ForkVersion(slot) == Electra {
forkVersion := p.ForkVersion(slot)
if forkVersion == Fulu || forkVersion == Electra {
return ElectraExecutionPayloadGeneralizedIndex
}
return AltairExecutionPayloadGeneralizedIndex
Expand Down
138 changes: 138 additions & 0 deletions relayer/relays/beacon/protocol/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"testing"

"github.com/snowfork/snowbridge/relayer/relays/beacon/config"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -119,3 +120,140 @@ func TestSyncCommitteeBits(t *testing.T) {
assert.Equal(t, tt.expected, result, "expected %t but found %t", tt.expected, result)
}
}

func TestForkVersion(t *testing.T) {
values := []struct {
name string
slot uint64
expected ForkVersion
}{
{
name: "deneb fork - slot before electra epoch",
slot: 0,
expected: Deneb,
},
{
name: "deneb fork - slot just before electra activation",
slot: 25599999, // epoch 799999
expected: Deneb,
},
{
name: "electra fork - first slot of electra epoch",
slot: 25600000, // epoch 800000 (32 slots per epoch)
expected: Electra,
},
{
name: "electra fork - middle of electra era",
slot: 29000000, // epoch ~906250
expected: Electra,
},
{
name: "electra fork - just before fulu activation",
slot: 31999999, // epoch 999999
expected: Electra,
},
{
name: "fulu fork - first slot of fulu epoch",
slot: 32000000, // epoch 1000000 (32 slots per epoch)
expected: Fulu,
},
{
name: "fulu fork - well into fulu era",
slot: 50000000, // epoch 1562500
expected: Fulu,
},
}

p := Protocol{}
p.Settings.SlotsInEpoch = 32
p.Settings.ForkVersions = config.ForkVersions{
Deneb: 0,
Electra: 800000,
Fulu: 1000000,
}

for _, tt := range values {
t.Run(tt.name, func(t *testing.T) {
result := p.ForkVersion(tt.slot)
assert.Equal(t, tt.expected, result, "expected %s but found %s for slot %d", tt.expected, result, tt.slot)
})
}
}

func TestForkVersionEdgeCases(t *testing.T) {
values := []struct {
name string
slot uint64
expected ForkVersion
}{
{
name: "slot 0 is deneb",
slot: 0,
expected: Deneb,
},
{
name: "exact electra boundary",
slot: 800000 * 32, // First slot of epoch 800000
expected: Electra,
},
{
name: "exact fulu boundary",
slot: 1000000 * 32, // First slot of epoch 1000000
expected: Fulu,
},
}

p := Protocol{}
p.Settings.SlotsInEpoch = 32
p.Settings.ForkVersions = config.ForkVersions{
Deneb: 0,
Electra: 800000,
Fulu: 1000000,
}

for _, tt := range values {
t.Run(tt.name, func(t *testing.T) {
result := p.ForkVersion(tt.slot)
assert.Equal(t, tt.expected, result, "expected %s but found %s for slot %d", tt.expected, result, tt.slot)
})
}
}

func TestForkVersionWithDifferentSlotsPerEpoch(t *testing.T) {
values := []struct {
name string
slot uint64
expected ForkVersion
}{
{
name: "deneb with 8 slots per epoch",
slot: 0,
expected: Deneb,
},
{
name: "electra boundary with 8 slots per epoch",
slot: 8 * 800000, // epoch 800000 with 8 slots per epoch
expected: Electra,
},
{
name: "fulu boundary with 8 slots per epoch",
slot: 8 * 1000000, // epoch 1000000 with 8 slots per epoch
expected: Fulu,
},
}

p := Protocol{}
p.Settings.SlotsInEpoch = 8 // Different from default 32
p.Settings.ForkVersions = config.ForkVersions{
Deneb: 0,
Electra: 800000,
Fulu: 1000000,
}

for _, tt := range values {
t.Run(tt.name, func(t *testing.T) {
result := p.ForkVersion(tt.slot)
assert.Equal(t, tt.expected, result, "expected %s but found %s for slot %d", tt.expected, result, tt.slot)
})
}
}
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.

2 changes: 1 addition & 1 deletion relayer/relays/beacon/state/beacon_electra_encoding.go

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

2 changes: 1 addition & 1 deletion relayer/relays/beacon/state/beacon_encoding.go

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

Loading
Loading