Skip to content
Merged

Fulu #1592

Show file tree
Hide file tree
Changes from 12 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/contracts/beefy_client.go

Large diffs are not rendered by default.

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: getForkVersions(),
}
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: getForkVersions(),
}
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: getForkVersions(),
}
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: getForkVersions(),
}
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: getForkVersions(),
}
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 getForkVersions() config.ForkVersions {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Golang guidelines suggest that this should be named forkVersions() instead. The suggestion is to drop the get prefix for getters

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
25 changes: 18 additions & 7 deletions relayer/relays/beacon/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,57 @@ type ForkVersion string
const (
Deneb ForkVersion = "Deneb"
Electra ForkVersion = "Electra"
Fulu ForkVersion = "Fulu"
)

func (p *Protocol) ForkVersion(slot uint64) ForkVersion {
epoch := p.ComputeEpochAtSlot(slot)
fv := Deneb
if epoch >= p.Settings.ForkVersions.Fulu {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The order of this if condition need to be reversed as otherwise between fulu and electra, it will always select electra.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in 3f5b1d9.

fv = Fulu
}
if epoch >= p.Settings.ForkVersions.Electra {
return Electra
fv = Electra
}
return Deneb
log.WithField("fork_version", fv).Info("Found fork version")
Comment thread
claravanstaden marked this conversation as resolved.
Outdated
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
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.

69 changes: 69 additions & 0 deletions relayer/relays/beacon/state/beacon_fulu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package state

type BeaconStateFulu struct {
GenesisTime uint64 `json:"genesis_time"`
GenesisValidatorsRoot []byte `json:"genesis_validators_root" ssz-size:"32"`
Slot uint64 `json:"slot"`
Fork *Fork `json:"fork"`
LatestBlockHeader *BeaconBlockHeader `json:"latest_block_header"`
BlockRoots [][]byte `json:"block_roots" ssz-size:"8192,32"`
StateRoots [][]byte `json:"state_roots" ssz-size:"8192,32"`
HistoricalRoots [][]byte `json:"historical_roots" ssz-max:"16777216" ssz-size:"?,32"`
Eth1Data *Eth1Data `json:"eth1_data"`
Eth1DataVotes []*Eth1Data `json:"eth1_data_votes" ssz-max:"2048"`
Eth1DepositIndex uint64 `json:"eth1_deposit_index"`
Validators []*Validator `json:"validators" ssz-max:"1099511627776"`
Balances []uint64 `json:"balances" ssz-max:"1099511627776"`
RandaoMixes [][]byte `json:"randao_mixes" ssz-size:"65536,32"`
Slashings []uint64 `json:"slashings" ssz-size:"8192"`
PreviousEpochParticipation []byte `json:"previous_epoch_participation" ssz-max:"1099511627776"`
CurrentEpochParticipation []byte `json:"current_epoch_participation" ssz-max:"1099511627776"`
JustificationBits []byte `json:"justification_bits" cast-type:"github.com/prysmaticlabs/go-bitfield.Bitvector4" ssz-size:"1"`
PreviousJustifiedCheckpoint *Checkpoint `json:"previous_justified_checkpoint"`
CurrentJustifiedCheckpoint *Checkpoint `json:"current_justified_checkpoint"`
FinalizedCheckpoint *Checkpoint `json:"finalized_checkpoint"`
InactivityScores []uint64 `json:"inactivity_scores" ssz-max:"1099511627776"`
CurrentSyncCommittee *SyncCommittee `json:"current_sync_committee"`
NextSyncCommittee *SyncCommittee `json:"next_sync_committee"`
LatestExecutionPayloadHeader *ExecutionPayloadHeaderDeneb `json:"latest_execution_payload_header"`
NextWithdrawalIndex uint64 `json:"next_withdrawal_index,omitempty"`
NextWithdrawalValidatorIndex uint64 `json:"next_withdrawal_validator_index,omitempty"`
HistoricalSummaries []*HistoricalSummary `json:"historical_summaries,omitempty" ssz-max:"16777216"`
DepositRequestsStartIndex uint64 `json:"deposit_requests_start_index,omitempty"`
DepositBalanceToConsume uint64 `json:"deposit_balance_to_consume,omitempty"`
ExitBalanceToConsume uint64 `json:"exit_balance_to_consume,omitempty"`
EarliestExitEpoch uint64 `json:"earliest_exit_epoch,omitempty"`
ConsolidationBalanceToConsume uint64 `json:"consolidation_balance_to_consume,omitempty"`
EarliestConsolidationEpoch uint64 `json:"earliest_consolidation_epoch,omitempty"`
PendingDeposits []*PendingDeposit `json:"pending_deposits,omitempty" ssz-max:"134217728"`
PendingPartialWithdrawals []*PendingPartialWithdrawal `json:"pending_partial_withdrawals,omitempty" ssz-max:"134217728"`
PendingConsolidations []*PendingConsolidation `json:"pending_consolidations,omitempty" ssz-max:"262144"`
ProposerLookahead []uint64 `json:"proposer_lookahead,omitempty" ssz-size:"64"` // New in Fulu:EIP7917
}

func (b *BeaconStateFulu) GetSlot() uint64 {
return b.Slot
}

func (b *BeaconStateFulu) GetLatestBlockHeader() *BeaconBlockHeader {
return b.LatestBlockHeader
}

func (b *BeaconStateFulu) GetBlockRoots() [][]byte {
return b.BlockRoots
}

func (b *BeaconStateFulu) SetBlockRoots(blockRoots [][]byte) {
b.BlockRoots = blockRoots
}

func (b *BeaconStateFulu) GetFinalizedCheckpoint() *Checkpoint {
return b.FinalizedCheckpoint
}

func (b *BeaconStateFulu) GetNextSyncCommittee() *SyncCommittee {
return b.NextSyncCommittee
}
func (b *BeaconStateFulu) GetCurrentSyncCommittee() *SyncCommittee {
return b.CurrentSyncCommittee
}
Loading