Implement should_override_forkchoice_update (#11981)

* Implement should_override_forchoice_update

* add tests

* remove unused exported function

* go mod tidy

* fix go mod

* Fix go mod tidy

* Fix context import

* mod tidy

* fix test

* Terence's review

* fix test

---------

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
This commit is contained in:
Potuz
2023-02-18 07:37:03 -03:00
committed by GitHub
parent b687d29d02
commit 166f7119ec
20 changed files with 384 additions and 165 deletions

View File

@@ -230,3 +230,12 @@ func SyncCommitteePeriodStartEpoch(e primitives.Epoch) (primitives.Epoch, error)
}
return primitives.Epoch(startEpoch), nil
}
// SecondsSinceSlotStart returns the number of seconds transcurred since the
// given slot start time
func SecondsSinceSlotStart(s primitives.Slot, genesisTime uint64, timeStamp uint64) (uint64, error) {
if timeStamp < genesisTime+uint64(s)*params.BeaconConfig().SecondsPerSlot {
return 0, errors.New("could not compute seconds since slot start: invalid timestamp")
}
return timeStamp - genesisTime - uint64(s)*params.BeaconConfig().SecondsPerSlot, nil
}

View File

@@ -460,3 +460,26 @@ func TestSyncCommitteePeriodStartEpoch(t *testing.T) {
require.Equal(t, test.wanted, e)
}
}
func TestSecondsSinceSlotStart(t *testing.T) {
tests := []struct {
slot primitives.Slot
genesisTime uint64
timeStamp uint64
wanted uint64
wantedErr bool
}{
{},
{slot: 1, timeStamp: 1, wantedErr: true},
{slot: 1, timeStamp: params.BeaconConfig().SecondsPerSlot + 2, wanted: 2},
}
for _, test := range tests {
w, err := SecondsSinceSlotStart(test.slot, test.genesisTime, test.timeStamp)
if err != nil {
require.Equal(t, true, test.wantedErr)
} else {
require.Equal(t, false, test.wantedErr)
require.Equal(t, w, test.wanted)
}
}
}