mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Fixed Simulator Can't get ParentSlot (#602)
This commit is contained in:
committed by
Raul Jordan
parent
1abed55bdd
commit
d5bf733948
@@ -25,6 +25,7 @@ go_test(
|
||||
"//proto/beacon/rpc/v1:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//validator/internal:go_default_library",
|
||||
"//validator/params:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
|
||||
@@ -135,7 +135,8 @@ func (s *Service) fetchCurrentAssignmentsAndGenesisTime(client pb.BeaconServiceC
|
||||
for _, assign := range res.Assignments {
|
||||
if bytes.Equal(assign.PublicKey.PublicKey, s.pubKey) {
|
||||
s.role = assign.Role
|
||||
s.assignedSlot = s.CurrentCycleStartSlot() + assign.AssignedSlot
|
||||
// + 1 to account for the genesis block being slot 0.
|
||||
s.assignedSlot = s.CurrentCycleStartSlot(params.DemoConfig().CycleLength) + assign.AssignedSlot + 1
|
||||
s.shardID = assign.ShardId
|
||||
|
||||
log.Infof("Validator shuffled. Pub key 0x%s re-assigned to shard ID %d for %v duty at slot %d",
|
||||
@@ -176,7 +177,12 @@ func (s *Service) listenForAssignmentChange(client pb.BeaconServiceClient) {
|
||||
for _, assign := range assignment.Assignments {
|
||||
if bytes.Equal(assign.PublicKey.PublicKey, s.pubKey) {
|
||||
s.role = assign.Role
|
||||
s.assignedSlot = s.CurrentCycleStartSlot() + assign.AssignedSlot
|
||||
if s.CurrentCycleStartSlot(params.DemoConfig().CycleLength) == 0 {
|
||||
// +1 to account for genesis block being slot 0.
|
||||
s.assignedSlot = params.DemoConfig().CycleLength + assign.AssignedSlot + 1
|
||||
} else {
|
||||
s.assignedSlot = s.CurrentCycleStartSlot(params.DemoConfig().CycleLength) + assign.AssignedSlot + 1
|
||||
}
|
||||
s.shardID = assign.ShardId
|
||||
|
||||
log.Infof("Validator with pub key 0x%s re-assigned to shard ID %d for %v duty at slot %d",
|
||||
@@ -280,12 +286,15 @@ func (s *Service) PublicKey() []byte {
|
||||
// CurrentBeaconSlot based on the genesis timestamp of the protocol.
|
||||
func (s *Service) CurrentBeaconSlot() uint64 {
|
||||
secondsSinceGenesis := time.Since(s.genesisTimestamp).Seconds()
|
||||
return uint64(math.Floor(secondsSinceGenesis / params.DefaultConfig().SlotDuration))
|
||||
if secondsSinceGenesis-params.DefaultConfig().SlotDuration < 0 {
|
||||
return 0
|
||||
}
|
||||
return uint64(math.Floor(secondsSinceGenesis/params.DefaultConfig().SlotDuration)) - 1
|
||||
}
|
||||
|
||||
// CurrentCycleStartSlot returns the slot at which the current cycle started.
|
||||
func (s *Service) CurrentCycleStartSlot() uint64 {
|
||||
func (s *Service) CurrentCycleStartSlot(cycleLength uint64) uint64 {
|
||||
currentSlot := s.CurrentBeaconSlot()
|
||||
cycleNum := math.Floor(float64(currentSlot) / float64(params.DefaultConfig().CycleLength))
|
||||
return uint64(cycleNum) * params.DefaultConfig().CycleLength
|
||||
cycleNum := currentSlot / cycleLength
|
||||
return uint64(cycleNum) * cycleLength
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/internal"
|
||||
"github.com/prysmaticlabs/prysm/validator/params"
|
||||
"github.com/sirupsen/logrus"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
@@ -301,7 +302,7 @@ func TestListenForAssignmentProposer(t *testing.T) {
|
||||
stream := internal.NewMockBeaconService_ValidatorAssignmentsClient(ctrl)
|
||||
|
||||
// Testing proposer assignment.
|
||||
assignedSlot := b.CurrentCycleStartSlot() + 2
|
||||
assignedSlot := b.CurrentCycleStartSlot(params.DefaultConfig().CycleLength) + 2
|
||||
stream.EXPECT().Recv().Return(&pb.ValidatorAssignmentResponse{Assignments: []*pb.Assignment{{
|
||||
PublicKey: &pb.PublicKey{PublicKey: []byte{'A'}},
|
||||
ShardId: 2,
|
||||
|
||||
@@ -16,6 +16,14 @@ func DefaultConfig() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
// DemoConfig for running the system under shorter defaults.
|
||||
func DemoConfig() *Config {
|
||||
return &Config{
|
||||
SlotDuration: 8.0,
|
||||
CycleLength: 5,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultCollationSizeLimit is the integer value representing the maximum
|
||||
// number of bytes allowed in a given collation.
|
||||
func DefaultCollationSizeLimit() int64 {
|
||||
|
||||
Reference in New Issue
Block a user