exclude unscheduled forks from the schedule (#15799)

* exclude unscheduled forks from the schedule

* update tests that relied on fulu being far future

* don't mess with the version->epoch mapping

* LastFork cheats the tests by filtering by far_future_epoch

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2025-10-03 10:29:27 -05:00
committed by GitHub
parent 28eb1a4c3c
commit 74c47e25a9
6 changed files with 42 additions and 3 deletions

View File

@@ -117,6 +117,7 @@ func TestService_decodePubsubMessage(t *testing.T) {
func TestExtractDataType(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.BeaconConfig().FuluForkEpoch = params.BeaconConfig().ElectraForkEpoch + 4096*2
params.BeaconConfig().InitializeForkSchedule()
type args struct {
@@ -304,6 +305,9 @@ func TestExtractDataType(t *testing.T) {
}
func TestExtractDataTypeFromTypeMapInvalid(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.BeaconConfig().FuluForkEpoch = params.BeaconConfig().ElectraForkEpoch + 4096*2
params.BeaconConfig().InitializeForkSchedule()
chain := &mock.ChainService{ValidatorsRoot: [32]byte{}}
_, err := extractDataTypeFromTypeMap(types.BlockMap, []byte{0x00, 0x01}, chain)
require.ErrorIs(t, err, errInvalidDigest)

View File

@@ -0,0 +1,2 @@
### Fixed
- Don't include entries in the fork schedule if their epoch is set to far future epoch. Avoids reporting next_fork_version == <unscheduled fork>.

View File

@@ -468,7 +468,7 @@ func (ns *NetworkSchedule) LastEntry() NetworkScheduleEntry {
// LastFork is the last full fork (this is used by e2e testing)
func (ns *NetworkSchedule) LastFork() NetworkScheduleEntry {
for i := len(ns.entries) - 1; i >= 0; i-- {
if ns.entries[i].isFork && ns.entries[i].Epoch != BeaconConfig().FarFutureEpoch {
if ns.entries[i].isFork {
return ns.entries[i]
}
}
@@ -527,6 +527,13 @@ func (ns *NetworkSchedule) index(e NetworkScheduleEntry) {
}
func (ns *NetworkSchedule) prepare(b *BeaconChainConfig) error {
// Only keep entries up to FarFutureEpoch.
for i := range ns.entries {
if ns.entries[i].Epoch == b.FarFutureEpoch {
ns.entries = ns.entries[:i]
break
}
}
if len(ns.entries) == 0 {
return errors.New("cannot compute digests for an empty network schedule")
}

View File

@@ -266,3 +266,24 @@ func testConfigForSchedule(gvr [32]byte) *params.BeaconChainConfig {
}
return cfg
}
func TestFilterFarFuture(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.BeaconConfig().FuluForkEpoch = params.BeaconConfig().FarFutureEpoch
params.BeaconConfig().InitializeForkSchedule()
last := params.LastNetworkScheduleEntry()
require.Equal(t, [4]byte(params.BeaconConfig().ElectraForkVersion), last.ForkVersion)
}
func TestFarFuturePrepareFilter(t *testing.T) {
params.SetupTestConfigCleanup(t)
cfg := params.BeaconConfig()
oldElectra := cfg.ElectraForkEpoch
// This should cause electra to be filtered from the schedule, so looking up the entry for electra's epoch
// should return the previous entry (deneb).
cfg.ElectraForkEpoch = params.BeaconConfig().FarFutureEpoch
cfg.FuluForkEpoch = params.BeaconConfig().FarFutureEpoch
params.OverrideBeaconConfig(cfg)
entry := params.GetNetworkScheduleEntry(oldElectra)
require.Equal(t, [4]byte(params.BeaconConfig().DenebForkVersion), entry.ForkVersion)
}

View File

@@ -101,6 +101,11 @@ func LastForkEpoch() primitives.Epoch {
return BeaconConfig().networkSchedule.LastFork().Epoch
}
func LastNetworkScheduleEntry() NetworkScheduleEntry {
lastIdx := len(BeaconConfig().networkSchedule.entries) - 1
return BeaconConfig().networkSchedule.entries[lastIdx]
}
func GetNetworkScheduleEntry(epoch primitives.Epoch) NetworkScheduleEntry {
entry := BeaconConfig().networkSchedule.ForEpoch(epoch)
return entry

View File

@@ -142,8 +142,8 @@ func TestNextForkData(t *testing.T) {
{
name: "after last bpo - should be far future epoch and 0x00000000",
currEpoch: params.LastForkEpoch() + 1,
wantedForkVersion: [4]byte(cfg.FuluForkVersion),
wantedEpoch: cfg.FarFutureEpoch,
wantedForkVersion: [4]byte(cfg.ElectraForkVersion),
wantedEpoch: cfg.ElectraForkEpoch,
},
}
for _, tt := range tests {