mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 04:54:05 -05:00
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:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user