mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
Attestation is Decoupled From Proposal (#3800)
* fix * add correct test * add helper * gaz * add helper * gaz
This commit is contained in:
parent
97905c3e79
commit
c9a7a9c709
@ -2,10 +2,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["slotticker.go"],
|
||||
srcs = [
|
||||
"slotticker.go",
|
||||
"slottime.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/slotutil",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//shared/roughtime:go_default_library"],
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/roughtime:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
15
shared/slotutil/slottime.go
Normal file
15
shared/slotutil/slottime.go
Normal file
@ -0,0 +1,15 @@
|
||||
package slotutil
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
// SlotStartTime returns the start time in terms of its unix epoch
|
||||
// value.
|
||||
func SlotStartTime(genesis uint64, slot uint64) time.Time {
|
||||
duration := time.Second * time.Duration(slot*params.BeaconConfig().SecondsPerSlot)
|
||||
startTime := time.Unix(int64(genesis), 0).Add(duration)
|
||||
return startTime
|
||||
}
|
@ -92,8 +92,8 @@ func run(ctx context.Context, v Validator) {
|
||||
case pb.ValidatorRole_ATTESTER:
|
||||
v.AttestToBlockHead(slotCtx, slot, id)
|
||||
case pb.ValidatorRole_PROPOSER:
|
||||
go v.AttestToBlockHead(slotCtx, slot, id)
|
||||
v.ProposeBlock(slotCtx, slot, id)
|
||||
v.AttestToBlockHead(slotCtx, slot, id)
|
||||
case pb.ValidatorRole_UNKNOWN:
|
||||
log.Debug("No active role, doing nothing")
|
||||
default:
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@ -135,7 +136,7 @@ func (v *validator) waitToSlotMidpoint(ctx context.Context, slot uint64) {
|
||||
if half == 0 {
|
||||
delay = 500 * time.Millisecond
|
||||
}
|
||||
duration := time.Duration(slot*params.BeaconConfig().SecondsPerSlot) + delay
|
||||
timeToBroadcast := time.Unix(int64(v.genesisTime), 0).Add(duration)
|
||||
startTime := slotutil.SlotStartTime(v.genesisTime, slot)
|
||||
timeToBroadcast := startTime.Add(delay)
|
||||
time.Sleep(roughtime.Until(timeToBroadcast))
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
@ -300,3 +301,19 @@ func TestAttestToBlockHead_CorrectBitfieldLength(t *testing.T) {
|
||||
t.Errorf("Wanted length %d, received %d", 2, len(generatedAttestation.AggregationBits))
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForSlotMidPoint_WaitCorrectly(t *testing.T) {
|
||||
validator, _, finish := setup(t)
|
||||
defer finish()
|
||||
currentTime := uint64(time.Now().Unix())
|
||||
numOfSlots := uint64(4)
|
||||
validator.genesisTime = currentTime - (numOfSlots * params.BeaconConfig().SecondsPerSlot)
|
||||
timeToSleep := params.BeaconConfig().SecondsPerSlot / 2
|
||||
midpointTime := currentTime + timeToSleep
|
||||
validator.waitToSlotMidpoint(context.Background(), numOfSlots)
|
||||
|
||||
currentTime = uint64(time.Now().Unix())
|
||||
if currentTime != midpointTime {
|
||||
t.Errorf("Wanted %d time for slot midpoint but got %d", midpointTime, currentTime)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user