mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Simplify fcu 2 (#13400)
* change getPayloadAttribute signature * Unify different FCU arguments
This commit is contained in:
@@ -16,6 +16,9 @@ import (
|
||||
// incoming objects. (24 mins with mainnet spec)
|
||||
const MaxSlotBuffer = uint64(1 << 7)
|
||||
|
||||
// votingWindow specifies the deadline for attestations
|
||||
var votingWindow = params.BeaconConfig().SecondsPerSlot / params.BeaconConfig().IntervalsPerSlot
|
||||
|
||||
// startFromTime returns the slot start in terms of genesis time.Time
|
||||
func startFromTime(genesis time.Time, slot primitives.Slot) time.Time {
|
||||
duration := time.Second * time.Duration(slot.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
@@ -264,3 +267,9 @@ func SecondsSinceSlotStart(s primitives.Slot, genesisTime, timeStamp uint64) (ui
|
||||
func TimeIntoSlot(genesisTime uint64) time.Duration {
|
||||
return time.Since(StartTime(genesisTime, CurrentSlot(genesisTime)))
|
||||
}
|
||||
|
||||
// WithinVotingWindow returns whether the current time is within the voting window
|
||||
// (eg. 4 seconds on mainnet) of the current slot.
|
||||
func WithinVotingWindow(genesisTime uint64) bool {
|
||||
return TimeIntoSlot(genesisTime) < time.Duration(votingWindow)*time.Second
|
||||
}
|
||||
|
||||
@@ -600,3 +600,10 @@ func TestTimeIntoSlot(t *testing.T) {
|
||||
require.Equal(t, true, TimeIntoSlot(genesisTime) > 900*time.Millisecond)
|
||||
require.Equal(t, true, TimeIntoSlot(genesisTime) < 3000*time.Millisecond)
|
||||
}
|
||||
|
||||
func TestWithinVotingWindow(t *testing.T) {
|
||||
genesisTime := uint64(time.Now().Add(-37 * time.Second).Unix())
|
||||
require.Equal(t, true, WithinVotingWindow(genesisTime))
|
||||
genesisTime = uint64(time.Now().Add(-40 * time.Second).Unix())
|
||||
require.Equal(t, false, WithinVotingWindow(genesisTime))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user