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