diff --git a/beacon-chain/attestation/service.go b/beacon-chain/attestation/service.go index 94b17fcfdf45..489fc282aa64 100644 --- a/beacon-chain/attestation/service.go +++ b/beacon-chain/attestation/service.go @@ -237,7 +237,7 @@ func (a *Service) updateAttestation(ctx context.Context, headRoot [32]byte, beac return err } log.WithFields(logrus.Fields{ - "attestationSlot": attestation.Data.Slot - params.BeaconConfig().GenesisSlot, + "attestationSlot": attestation.Data.Slot, "attestationShard": attestation.Data.Shard, "committeesShard": attestation.Data.Shard, "committeesList": committee, @@ -286,8 +286,8 @@ func (a *Service) updateAttestation(ctx context.Context, headRoot [32]byte, beac log.WithFields( logrus.Fields{ - "attestationSlot": attestation.Data.Slot - params.BeaconConfig().GenesisSlot, - "justifiedEpoch": attestation.Data.JustifiedEpoch - params.BeaconConfig().GenesisEpoch, + "attestationSlot": attestation.Data.Slot, + "justifiedEpoch": attestation.Data.JustifiedEpoch, }, ).Debug("Attestation store updated") diff --git a/beacon-chain/attestation/service_test.go b/beacon-chain/attestation/service_test.go index 7ace04038ef4..a257ecef3858 100644 --- a/beacon-chain/attestation/service_test.go +++ b/beacon-chain/attestation/service_test.go @@ -36,19 +36,19 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -62,7 +62,7 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) { attestation := &pb.Attestation{ AggregationBitfield: []byte{0x01}, Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 2, }, } @@ -78,7 +78,7 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) { } beaconState = &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 36, + Slot: 36, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -88,7 +88,7 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) { t.Fatalf("could not save state: %v", err) } - attestation.Data.Slot = params.BeaconConfig().GenesisSlot + 36 + attestation.Data.Slot = 36 attestation.Data.Shard = 36 if err := service.UpdateLatestAttestation(ctx, attestation); err != nil { t.Fatalf("could not update latest attestation: %v", err) @@ -110,16 +110,16 @@ func TestAttestationPool_UpdatesAttestationPool(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, ValidatorRegistry: validators, } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -133,7 +133,7 @@ func TestAttestationPool_UpdatesAttestationPool(t *testing.T) { attestation := &pb.Attestation{ AggregationBitfield: []byte{0x80}, Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 1, }, } @@ -150,7 +150,7 @@ func TestLatestAttestationTarget_CantGetAttestation(t *testing.T) { if err := beaconDB.SaveState(ctx, &pb.BeaconState{ ValidatorRegistry: []*pb.Validator{{}}, - LatestBlock: &pb.BeaconBlock{Slot: params.BeaconConfig().GenesisSlot}, + LatestBlock: &pb.BeaconBlock{Slot: 0}, }); err != nil { t.Fatalf("could not save state: %v", err) } @@ -175,7 +175,7 @@ func TestLatestAttestationTarget_ReturnsLatestAttestedBlock(t *testing.T) { pubKey := []byte{'A'} if err := beaconDB.SaveState(ctx, &pb.BeaconState{ ValidatorRegistry: []*pb.Validator{{Pubkey: pubKey}}, - LatestBlock: &pb.BeaconBlock{Slot: params.BeaconConfig().GenesisSlot}, + LatestBlock: &pb.BeaconBlock{Slot: 0}, }); err != nil { t.Fatalf("could not save state: %v", err) } @@ -230,19 +230,19 @@ func TestUpdateLatestAttestation_CacheEnabledAndMiss(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -256,7 +256,7 @@ func TestUpdateLatestAttestation_CacheEnabledAndMiss(t *testing.T) { attestation := &pb.Attestation{ AggregationBitfield: []byte{0x01}, Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 2, }, } @@ -271,11 +271,11 @@ func TestUpdateLatestAttestation_CacheEnabledAndMiss(t *testing.T) { attestation.Data.Slot, service.store.m[pubkey].Data.Slot) } - attestation.Data.Slot = params.BeaconConfig().GenesisSlot + 36 + attestation.Data.Slot = 36 attestation.Data.Shard = 36 beaconState = &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 36, + Slot: 36, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -315,8 +315,8 @@ func TestUpdateLatestAttestation_CacheEnabledAndHit(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } @@ -325,13 +325,13 @@ func TestUpdateLatestAttestation_CacheEnabledAndHit(t *testing.T) { ctx := context.Background() beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 2, + Slot: 2, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 2, + Slot: 2, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -343,7 +343,7 @@ func TestUpdateLatestAttestation_CacheEnabledAndHit(t *testing.T) { service := NewAttestationService(context.Background(), &Config{BeaconDB: beaconDB}) - slot := params.BeaconConfig().GenesisSlot + 2 + slot := uint64(2) shard := uint64(3) index := uint64(4) attestation := &pb.Attestation{ @@ -389,19 +389,19 @@ func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), ValidatorRegistry: validators, } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -414,7 +414,7 @@ func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) { attestation := &pb.Attestation{ AggregationBitfield: []byte{0xC0}, Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 1, }, } @@ -434,19 +434,19 @@ func TestUpdateLatestAttestation_BatchUpdate(t *testing.T) { for i := 0; i < 64; i++ { validators = append(validators, &pb.Validator{ Pubkey: []byte{byte(i)}, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - ExitEpoch: params.BeaconConfig().GenesisEpoch + 10, + ActivationEpoch: 0, + ExitEpoch: 10, }) } beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), ValidatorRegistry: validators, } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } if err := beaconDB.SaveBlock(block); err != nil { t.Fatal(err) @@ -461,7 +461,7 @@ func TestUpdateLatestAttestation_BatchUpdate(t *testing.T) { attestations = append(attestations, &pb.Attestation{ AggregationBitfield: []byte{0x80}, Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 1, }, }) diff --git a/beacon-chain/attestation/vote_metrics.go b/beacon-chain/attestation/vote_metrics.go index 253bb1f40780..4bc72a00eac8 100644 --- a/beacon-chain/attestation/vote_metrics.go +++ b/beacon-chain/attestation/vote_metrics.go @@ -6,7 +6,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" - "github.com/prysmaticlabs/prysm/shared/params" ) var ( @@ -28,7 +27,6 @@ func reportVoteMetrics(index uint64, block *pb.BeaconBlock) { return } - s := params.BeaconConfig().GenesisSlot validatorLastVoteGauge.WithLabelValues( - "v" + strconv.Itoa(int(index))).Set(float64(block.Slot - s)) + "v" + strconv.Itoa(int(index))).Set(float64(block.Slot)) } diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 94b0e1f52017..a79864fe568b 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -25,7 +25,6 @@ go_library( "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/p2p:go_default_library", - "//shared/params:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/beacon-chain/blockchain/block_processing.go b/beacon-chain/blockchain/block_processing.go index f6bb7df25f07..09f2dd355541 100644 --- a/beacon-chain/blockchain/block_processing.go +++ b/beacon-chain/blockchain/block_processing.go @@ -15,7 +15,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -85,11 +84,11 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) if err := c.SaveAndBroadcastBlock(ctx, block); err != nil { return beaconState, fmt.Errorf( "could not save and broadcast beacon block with slot %d: %v", - block.Slot-params.BeaconConfig().GenesisSlot, err, + block.Slot, err, ) } - log.WithField("slotNumber", block.Slot-params.BeaconConfig().GenesisSlot).Info( + log.WithField("slotNumber", block.Slot).Info( "Executing state transition") // We then apply the block state transition accordingly to obtain the resulting beacon state. @@ -109,8 +108,8 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) } log.WithFields(logrus.Fields{ - "slotNumber": block.Slot - params.BeaconConfig().GenesisSlot, - "currentEpoch": helpers.SlotToEpoch(block.Slot) - params.BeaconConfig().GenesisEpoch, + "slotNumber": block.Slot, + "currentEpoch": helpers.SlotToEpoch(block.Slot), }).Info("State transition complete") // Check state root @@ -133,7 +132,7 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) return beaconState, fmt.Errorf("could not process block deposits, attestations, and other operations: %v", err) } - log.WithField("slot", block.Slot-params.BeaconConfig().GenesisSlot).Info("Finished processing beacon block") + log.WithField("slot", block.Slot).Info("Finished processing beacon block") return beaconState, nil } @@ -194,9 +193,9 @@ func (c *ChainService) VerifyBlockValidity( block *pb.BeaconBlock, beaconState *pb.BeaconState, ) error { - if block.Slot == params.BeaconConfig().GenesisSlot { + if block.Slot == 0 { return fmt.Errorf("cannot process a genesis block: received block with slot %d", - block.Slot-params.BeaconConfig().GenesisSlot) + block.Slot) } powBlockFetcher := c.web3Service.Client().BlockByHash if err := b.IsValidBlock(ctx, beaconState, block, @@ -276,12 +275,12 @@ func (c *ChainService) runStateTransition( return beaconState, &BlockFailedProcessingErr{err} } log.WithField( - "slotsSinceGenesis", newState.Slot-params.BeaconConfig().GenesisSlot, + "slotsSinceGenesis", newState.Slot, ).Info("Slot transition successfully processed") if block != nil { log.WithField( - "slotsSinceGenesis", newState.Slot-params.BeaconConfig().GenesisSlot, + "slotsSinceGenesis", newState.Slot, ).Info("Block transition successfully processed") blockRoot, err := hashutil.HashBeaconBlock(block) @@ -308,7 +307,7 @@ func (c *ChainService) runStateTransition( return newState, fmt.Errorf("could not update FFG checkpts: %v", err) } log.WithField( - "SlotsSinceGenesis", newState.Slot-params.BeaconConfig().GenesisSlot, + "SlotsSinceGenesis", newState.Slot, ).Info("Epoch transition successfully processed") } return newState, nil diff --git a/beacon-chain/blockchain/block_processing_test.go b/beacon-chain/blockchain/block_processing_test.go index 74dc74d0e832..c3e8e62e240d 100644 --- a/beacon-chain/blockchain/block_processing_test.go +++ b/beacon-chain/blockchain/block_processing_test.go @@ -270,7 +270,7 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) { Attestations: []*pb.Attestation{ { Data: &pb.AttestationData{ - JustifiedEpoch: params.BeaconConfig().GenesisSlot * 100, + JustifiedEpoch: 100, }, }, }, @@ -438,7 +438,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) { t.Fatal(err) } - currentSlot := params.BeaconConfig().GenesisSlot + currentSlot := uint64(0) randaoReveal := createRandaoReveal(t, beaconState, privKeys) pendingDeposits := []*pb.Deposit{ @@ -600,7 +600,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) { if err := db.SaveFinalizedState(beaconState); err != nil { t.Fatal(err) } - genesisSlot := params.BeaconConfig().GenesisSlot + genesisSlot := uint64(0) // Top chain slots (see graph) blockSlots := []uint64{1, 2, 3, 5, 8} @@ -735,7 +735,7 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) { t.Fatal("block processing succeeded despite block having no parent saved") } - beaconState.Slot = params.BeaconConfig().GenesisSlot + 10 + beaconState.Slot = 10 stateRoot, err := hashutil.HashProto(beaconState) if err != nil { @@ -754,10 +754,10 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) { DepositRoot: []byte{2}, BlockRoot: []byte{3}, } - beaconState.Slot = params.BeaconConfig().GenesisSlot + beaconState.Slot = 0 - currentSlot := params.BeaconConfig().GenesisSlot + 1 - attestationSlot := params.BeaconConfig().GenesisSlot + currentSlot := uint64(1) + attestationSlot := uint64(0) randaoReveal := createRandaoReveal(t, beaconState, privKeys) block2 := &pb.BeaconBlock{ diff --git a/beacon-chain/blockchain/fork_choice.go b/beacon-chain/blockchain/fork_choice.go index d41c954be687..a8d8ed16aa6f 100644 --- a/beacon-chain/blockchain/fork_choice.go +++ b/beacon-chain/blockchain/fork_choice.go @@ -14,7 +14,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -60,7 +59,7 @@ func (c *ChainService) updateFFGCheckPts(ctx context.Context, state *pb.BeaconSt // until we can get a block. lastAvailBlkSlot := lastJustifiedSlot for newJustifiedBlock == nil { - log.WithField("slot", lastAvailBlkSlot-params.BeaconConfig().GenesisSlot).Debug("Missing block in DB, looking one slot back") + log.WithField("slot", lastAvailBlkSlot).Debug("Missing block in DB, looking one slot back") lastAvailBlkSlot-- newJustifiedBlock, err = c.beaconDB.CanonicalBlockBySlot(ctx, lastAvailBlkSlot) if err != nil { @@ -102,7 +101,7 @@ func (c *ChainService) updateFFGCheckPts(ctx context.Context, state *pb.BeaconSt // until we can get a block. lastAvailBlkSlot := lastFinalizedSlot for newFinalizedBlock == nil { - log.WithField("slot", lastAvailBlkSlot-params.BeaconConfig().GenesisSlot).Debug("Missing block in DB, looking one slot back") + log.WithField("slot", lastAvailBlkSlot).Debug("Missing block in DB, looking one slot back") lastAvailBlkSlot-- newFinalizedBlock, err = c.beaconDB.CanonicalBlockBySlot(ctx, lastAvailBlkSlot) if err != nil { @@ -185,9 +184,9 @@ func (c *ChainService) ApplyForkChoiceRule( newState := postState if !isDescendant && !proto.Equal(currentHead, newHead) { log.WithFields(logrus.Fields{ - "currentSlot": currentHead.Slot - params.BeaconConfig().GenesisSlot, + "currentSlot": currentHead.Slot, "currentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(currentHeadRoot[:])), - "newSlot": newHead.Slot - params.BeaconConfig().GenesisSlot, + "newSlot": newHead.Slot, "newRoot": fmt.Sprintf("%#x", bytesutil.Trunc(newHeadRoot[:])), }).Warn("Reorg happened") // Only regenerate head state if there was a reorg. @@ -204,7 +203,7 @@ func (c *ChainService) ApplyForkChoiceRule( if proto.Equal(currentHead, newHead) { log.WithFields(logrus.Fields{ - "currentSlot": currentHead.Slot - params.BeaconConfig().GenesisSlot, + "currentSlot": currentHead.Slot, "currentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(currentHeadRoot[:])), }).Warn("Head did not change after fork choice, current head has the most votes") } @@ -226,8 +225,8 @@ func (c *ChainService) ApplyForkChoiceRule( } log.WithFields(logrus.Fields{ "headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(h[:])), - "headSlot": newHead.Slot - params.BeaconConfig().GenesisSlot, - "stateSlot": newState.Slot - params.BeaconConfig().GenesisSlot, + "headSlot": newHead.Slot, + "stateSlot": newState.Slot, }).Info("Chain head block and state updated") return nil diff --git a/beacon-chain/blockchain/fork_choice_reorg_test.go b/beacon-chain/blockchain/fork_choice_reorg_test.go index 0a2dfd78b2ba..d852dbf4062b 100644 --- a/beacon-chain/blockchain/fork_choice_reorg_test.go +++ b/beacon-chain/blockchain/fork_choice_reorg_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/internal" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -86,8 +85,8 @@ func TestApplyForkChoice_ChainSplitReorg(t *testing.T) { if chainHead.Slot != justifiedState.Slot+5 { t.Errorf( "Expected chain head with slot %d, received %d", - justifiedState.Slot+5-params.BeaconConfig().GenesisSlot, - chainHead.Slot-params.BeaconConfig().GenesisSlot, + justifiedState.Slot+5, + chainHead.Slot, ) } diff --git a/beacon-chain/blockchain/fork_choice_test.go b/beacon-chain/blockchain/fork_choice_test.go index 6ad53919199c..19f6a53a3641 100644 --- a/beacon-chain/blockchain/fork_choice_test.go +++ b/beacon-chain/blockchain/fork_choice_test.go @@ -54,23 +54,23 @@ func TestApplyForkChoice_SetsCanonicalHead(t *testing.T) { }{ // Higher slot but same state should trigger chain update. { - blockSlot: params.BeaconConfig().GenesisSlot + 64, + blockSlot: 64, state: beaconState, logAssert: "Chain head block and state updated", }, // Higher slot, different state, but higher last finalized slot. { - blockSlot: params.BeaconConfig().GenesisSlot + 64, - state: &pb.BeaconState{FinalizedEpoch: params.BeaconConfig().GenesisEpoch + 2}, + blockSlot: 64, + state: &pb.BeaconState{FinalizedEpoch: 2}, logAssert: "Chain head block and state updated", }, // Higher slot, different state, same last finalized slot, // but last justified slot. { - blockSlot: params.BeaconConfig().GenesisSlot + 64, + blockSlot: 64, state: &pb.BeaconState{ - FinalizedEpoch: params.BeaconConfig().GenesisEpoch, - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch + 2, + FinalizedEpoch: 0, + CurrentJustifiedEpoch: 2, }, logAssert: "Chain head block and state updated", }, @@ -179,7 +179,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) { } potentialHead := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, ParentBlockRoot: genesisRoot[:], } headRoot1, err := hashutil.HashBeaconBlock(potentialHead) @@ -188,7 +188,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) { } potentialHead2 := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 6, + Slot: 6, ParentBlockRoot: genesisRoot[:], } headRoot2, err := hashutil.HashBeaconBlock(potentialHead2) @@ -1243,7 +1243,7 @@ func setupBeaconChainBenchmark(b *testing.B, beaconDB *db.BeaconDB) *ChainServic } func TestUpdateFFGCheckPts_NewJustifiedSlot(t *testing.T) { - genesisSlot := params.BeaconConfig().GenesisSlot + genesisSlot := uint64(0) beaconDB := internal.SetupDB(t) defer internal.TeardownDB(t, beaconDB) ctx := context.Background() @@ -1277,7 +1277,7 @@ func TestUpdateFFGCheckPts_NewJustifiedSlot(t *testing.T) { if err != nil { t.Fatal(err) } - gState.CurrentJustifiedEpoch = params.BeaconConfig().GenesisEpoch + 1 + gState.CurrentJustifiedEpoch = 1 gState.Slot = genesisSlot + offset buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, gState.CurrentJustifiedEpoch) @@ -1320,7 +1320,7 @@ func TestUpdateFFGCheckPts_NewJustifiedSlot(t *testing.T) { } func TestUpdateFFGCheckPts_NewFinalizedSlot(t *testing.T) { - genesisSlot := params.BeaconConfig().GenesisSlot + genesisSlot := uint64(0) beaconDB := internal.SetupDB(t) defer internal.TeardownDB(t, beaconDB) chainSvc := setupBeaconChain(t, beaconDB, nil) @@ -1360,7 +1360,7 @@ func TestUpdateFFGCheckPts_NewFinalizedSlot(t *testing.T) { t.Fatal(err) } - gState.FinalizedEpoch = params.BeaconConfig().GenesisEpoch + 1 + gState.FinalizedEpoch = 1 gState.Slot = genesisSlot + offset buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, gState.FinalizedEpoch) @@ -1404,7 +1404,7 @@ func TestUpdateFFGCheckPts_NewFinalizedSlot(t *testing.T) { } func TestUpdateFFGCheckPts_NewJustifiedSkipSlot(t *testing.T) { - genesisSlot := params.BeaconConfig().GenesisSlot + genesisSlot := uint64(0) beaconDB := internal.SetupDB(t) defer internal.TeardownDB(t, beaconDB) ctx := context.Background() @@ -1441,11 +1441,11 @@ func TestUpdateFFGCheckPts_NewJustifiedSkipSlot(t *testing.T) { if err != nil { t.Fatal(err) } - gState.CurrentJustifiedEpoch = params.BeaconConfig().GenesisEpoch + 1 + gState.CurrentJustifiedEpoch = 1 gState.Slot = genesisSlot + offset buf := make([]byte, 32) - binary.LittleEndian.PutUint64(buf, params.BeaconConfig().GenesisEpoch) - domain := helpers.DomainVersion(gState, params.BeaconConfig().GenesisEpoch, params.BeaconConfig().DomainRandao) + binary.LittleEndian.PutUint64(buf, 0) + domain := helpers.DomainVersion(gState, 0, params.BeaconConfig().DomainRandao) epochSignature := privKeys[proposerIdx].Sign(buf, domain) block := &pb.BeaconBlock{ Slot: genesisSlot + lastAvailableSlot, @@ -1489,10 +1489,10 @@ func TestUpdateFFGCheckPts_NewJustifiedSkipSlot(t *testing.T) { } func setupFFGTest(t *testing.T) ([32]byte, *pb.BeaconBlock, *pb.BeaconState, []*bls.SecretKey) { - genesisSlot := params.BeaconConfig().GenesisSlot + genesisSlot := uint64(0) var crosslinks []*pb.Crosslink for i := 0; i < int(params.BeaconConfig().ShardCount); i++ { - crosslinks = append(crosslinks, &pb.Crosslink{Epoch: params.BeaconConfig().GenesisEpoch}) + crosslinks = append(crosslinks, &pb.Crosslink{Epoch: 0}) } latestRandaoMixes := make( [][]byte, @@ -1535,7 +1535,7 @@ func setupFFGTest(t *testing.T) ([32]byte, *pb.BeaconBlock, *pb.BeaconState, []* Fork: &pb.Fork{ PreviousVersion: params.BeaconConfig().GenesisForkVersion, CurrentVersion: params.BeaconConfig().GenesisForkVersion, - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, }, } return gBlockRoot, gBlock, gState, privKeys @@ -1554,7 +1554,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) { } potentialHead := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, ParentBlockRoot: genesisRoot[:], } pHeadHash, err := hashutil.HashBeaconBlock(potentialHead) @@ -1562,7 +1562,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) { t.Fatal(err) } potentialHead2 := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 6, + Slot: 6, ParentBlockRoot: genesisRoot[:], } pHeadHash2, err := hashutil.HashBeaconBlock(potentialHead2) @@ -1617,12 +1617,12 @@ func TestVoteCount_CacheEnabledAndHit(t *testing.T) { } potentialHead := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, ParentBlockRoot: genesisRoot[:], } pHeadHash, _ := hashutil.HashBeaconBlock(potentialHead) potentialHead2 := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 6, + Slot: 6, ParentBlockRoot: genesisRoot[:], } pHeadHash2, _ := hashutil.HashBeaconBlock(potentialHead2) diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 88a6d6f706e1..8b4e73cf93cb 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -295,7 +295,7 @@ func TestChainStartStop_Uninitialized(t *testing.T) { if err != nil { t.Fatal(err) } - if beaconState == nil || beaconState.Slot != params.BeaconConfig().GenesisSlot { + if beaconState == nil || beaconState.Slot != 0 { t.Error("Expected canonical state feed to send a state with genesis block") } if err := chainService.Stop(); err != nil { diff --git a/beacon-chain/blockchain/stategenerator/BUILD.bazel b/beacon-chain/blockchain/stategenerator/BUILD.bazel index 0b7cf1541cf1..ecc4d411e34b 100644 --- a/beacon-chain/blockchain/stategenerator/BUILD.bazel +++ b/beacon-chain/blockchain/stategenerator/BUILD.bazel @@ -11,7 +11,6 @@ go_library( "//proto/beacon/p2p/v1:go_default_library", "//shared/bytesutil:go_default_library", "//shared/hashutil:go_default_library", - "//shared/params:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@io_opencensus_go//trace:go_default_library", ], @@ -25,7 +24,6 @@ go_test( "//beacon-chain/chaintest/backend:go_default_library", "//beacon-chain/db:go_default_library", "//shared/featureconfig:go_default_library", - "//shared/params:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", ], ) diff --git a/beacon-chain/blockchain/stategenerator/state_generator.go b/beacon-chain/blockchain/stategenerator/state_generator.go index 43845ff0486c..cf66fbff0f98 100644 --- a/beacon-chain/blockchain/stategenerator/state_generator.go +++ b/beacon-chain/blockchain/stategenerator/state_generator.go @@ -9,7 +9,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -39,8 +38,8 @@ func GenerateStateFromBlock(ctx context.Context, db *db.BeaconDB, slot uint64) ( if fState.Slot > slot { return nil, fmt.Errorf( "requested slot %d < current slot %d in the finalized beacon state", - slot-params.BeaconConfig().GenesisSlot, - fState.Slot-params.BeaconConfig().GenesisSlot, + slot, + fState.Slot, ) } @@ -81,7 +80,7 @@ func GenerateStateFromBlock(ctx context.Context, db *db.BeaconDB, slot uint64) ( } log.Infof("Recompute state starting last finalized slot %d and ending slot %d", - fState.Slot-params.BeaconConfig().GenesisSlot, slot-params.BeaconConfig().GenesisSlot) + fState.Slot, slot) postState := fState root := fRoot // this recomputes state up to the last available block. @@ -148,7 +147,7 @@ func GenerateStateFromBlock(ctx context.Context, db *db.BeaconDB, slot uint64) ( } log.Infof("Finished recompute state with slot %d and finalized epoch %d", - postState.Slot-params.BeaconConfig().GenesisSlot, postState.FinalizedEpoch-params.BeaconConfig().GenesisEpoch) + postState.Slot, postState.FinalizedEpoch) return postState, nil } diff --git a/beacon-chain/blockchain/stategenerator/state_generator_test.go b/beacon-chain/blockchain/stategenerator/state_generator_test.go index b9e9a2585226..6657c1597650 100644 --- a/beacon-chain/blockchain/stategenerator/state_generator_test.go +++ b/beacon-chain/blockchain/stategenerator/state_generator_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/chaintest/backend" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/shared/featureconfig" - "github.com/prysmaticlabs/prysm/shared/params" ) func init() { @@ -70,7 +69,7 @@ func TestGenerateState_OK(t *testing.T) { } // Ran 30 slots to save finalized slot then ran another 30 slots. - slotToGenerateTill := params.BeaconConfig().GenesisSlot + slotLimit*2 + slotToGenerateTill := slotLimit * 2 newState, err := stategenerator.GenerateStateFromBlock(context.Background(), beaconDb, slotToGenerateTill) if err != nil { t.Fatalf("Unable to generate new state from previous finalized state %v", err) @@ -147,7 +146,7 @@ func TestGenerateState_WithNilBlocksOK(t *testing.T) { } // Ran 30 slots to save finalized slot then ran another 10 slots w/o blocks and 20 slots w/ blocks. - slotToGenerateTill := params.BeaconConfig().GenesisSlot + slotLimit*2 + slotToGenerateTill := slotLimit * 2 newState, err := stategenerator.GenerateStateFromBlock(context.Background(), beaconDb, slotToGenerateTill) if err != nil { t.Fatalf("Unable to generate new state from previous finalized state %v", err) diff --git a/beacon-chain/chaintest/backend/simulated_backend.go b/beacon-chain/chaintest/backend/simulated_backend.go index ee597c51226f..b814df26882c 100644 --- a/beacon-chain/chaintest/backend/simulated_backend.go +++ b/beacon-chain/chaintest/backend/simulated_backend.go @@ -221,7 +221,7 @@ func (sb *SimulatedBackend) RunStateTransitionTest(testCase *StateTestCase) erro return fmt.Errorf("could not initialize state test %v", err) } averageTimesPerTransition := []time.Duration{} - startSlot := params.BeaconConfig().GenesisSlot + startSlot := uint64(0) for i := startSlot; i < startSlot+testCase.Config.NumSlots; i++ { // If the slot is marked as skipped in the configuration options, diff --git a/beacon-chain/chaintest/backend/simulated_backend_test.go b/beacon-chain/chaintest/backend/simulated_backend_test.go index 13c05c57c37c..4db6a095d18a 100644 --- a/beacon-chain/chaintest/backend/simulated_backend_test.go +++ b/beacon-chain/chaintest/backend/simulated_backend_test.go @@ -52,7 +52,7 @@ func TestGenerateBlockAndAdvanceChain_IncreasesSlot(t *testing.T) { } } - if backend.state.Slot != params.BeaconConfig().GenesisSlot+uint64(slotLimit) { + if backend.state.Slot != uint64(slotLimit) { t.Errorf("Unequal state slot and expected slot %d %d", backend.state.Slot, slotLimit) } @@ -78,7 +78,7 @@ func TestGenerateNilBlockAndAdvanceChain_IncreasesSlot(t *testing.T) { } } - if backend.state.Slot != params.BeaconConfig().GenesisSlot+uint64(slotLimit) { + if backend.state.Slot != uint64(slotLimit) { t.Errorf("Unequal state slot and expected slot %d %d", backend.state.Slot, slotLimit) } diff --git a/beacon-chain/core/blocks/block.go b/beacon-chain/core/blocks/block.go index a6e12d39a4b0..b90c1218c3b5 100644 --- a/beacon-chain/core/blocks/block.go +++ b/beacon-chain/core/blocks/block.go @@ -17,7 +17,7 @@ var clock utils.Clock = &utils.RealClock{} // NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol. func NewGenesisBlock(stateRoot []byte) *pb.BeaconBlock { block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ParentBlockRoot: params.BeaconConfig().ZeroHash[:], StateRoot: stateRoot, Signature: params.BeaconConfig().EmptySignature[:], @@ -48,16 +48,16 @@ func NewGenesisBlock(stateRoot []byte) *pb.BeaconBlock { // assert slot < state.slot // return state.latest_block_roots[slot % LATEST_BLOCK_ROOTS_LENGTH] func BlockRoot(state *pb.BeaconState, slot uint64) ([]byte, error) { - earliestSlot := state.Slot - params.BeaconConfig().LatestBlockRootsLength + earliestSlot := uint64(0) + if state.Slot > params.BeaconConfig().LatestBlockRootsLength { + earliestSlot = state.Slot - params.BeaconConfig().LatestBlockRootsLength + } if slot < earliestSlot || slot >= state.Slot { - if earliestSlot < params.BeaconConfig().GenesisSlot { - earliestSlot = params.BeaconConfig().GenesisSlot - } return []byte{}, fmt.Errorf("slot %d is not within expected range of %d to %d", - slot-params.BeaconConfig().GenesisSlot, - earliestSlot-params.BeaconConfig().GenesisSlot, - state.Slot-params.BeaconConfig().GenesisSlot, + slot, + earliestSlot, + state.Slot, ) } diff --git a/beacon-chain/core/blocks/block_operations.go b/beacon-chain/core/blocks/block_operations.go index 4c276a856847..de22c444f1cf 100644 --- a/beacon-chain/core/blocks/block_operations.go +++ b/beacon-chain/core/blocks/block_operations.go @@ -125,7 +125,7 @@ func verifyBlockRandao(beaconState *pb.BeaconState, body *pb.BeaconBlockBody, pr } if enableLogging { log.WithFields(logrus.Fields{ - "epoch": helpers.CurrentEpoch(beaconState) - params.BeaconConfig().GenesisEpoch, + "epoch": helpers.CurrentEpoch(beaconState), "proposerIndex": proposerIdx, }).Info("Verifying randao") } @@ -413,28 +413,21 @@ func ProcessBlockAttestations( // VerifyAttestation verifies an input attestation can pass through processing using the given beacon state. func VerifyAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verifySignatures bool) error { - if att.Data.Slot < params.BeaconConfig().GenesisSlot { - return fmt.Errorf( - "attestation slot (slot %d) less than genesis slot (%d)", - att.Data.Slot, - params.BeaconConfig().GenesisSlot, - ) - } inclusionDelay := params.BeaconConfig().MinAttestationInclusionDelay if att.Data.Slot+inclusionDelay > beaconState.Slot { return fmt.Errorf( "attestation slot (slot %d) + inclusion delay (%d) beyond current beacon state slot (%d)", - att.Data.Slot-params.BeaconConfig().GenesisSlot, + att.Data.Slot, inclusionDelay, - beaconState.Slot-params.BeaconConfig().GenesisSlot, + beaconState.Slot, ) } if att.Data.Slot+params.BeaconConfig().SlotsPerEpoch < beaconState.Slot { return fmt.Errorf( "attestation slot (slot %d) + epoch length (%d) less than current beacon state slot (%d)", - att.Data.Slot-params.BeaconConfig().GenesisSlot, + att.Data.Slot, params.BeaconConfig().SlotsPerEpoch, - beaconState.Slot-params.BeaconConfig().GenesisSlot, + beaconState.Slot, ) } // Verify that `attestation.data.justified_epoch` is equal to `state.justified_epoch @@ -445,8 +438,8 @@ func VerifyAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verifyS if att.Data.JustifiedEpoch != beaconState.CurrentJustifiedEpoch { return fmt.Errorf( "expected attestation.JustifiedEpoch == state.CurrentJustifiedEpoch, received %d == %d", - att.Data.JustifiedEpoch-params.BeaconConfig().GenesisEpoch, - beaconState.CurrentJustifiedEpoch-params.BeaconConfig().GenesisEpoch, + att.Data.JustifiedEpoch, + beaconState.CurrentJustifiedEpoch, ) } @@ -461,8 +454,8 @@ func VerifyAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verifyS if att.Data.JustifiedEpoch != beaconState.PreviousJustifiedEpoch { return fmt.Errorf( "expected attestation.JustifiedEpoch == state.PreviousJustifiedEpoch, received %d == %d", - att.Data.JustifiedEpoch-params.BeaconConfig().GenesisEpoch, - beaconState.PreviousJustifiedEpoch-params.BeaconConfig().GenesisEpoch, + att.Data.JustifiedEpoch, + beaconState.PreviousJustifiedEpoch, ) } if !bytes.Equal(att.Data.JustifiedBlockRootHash32, beaconState.PreviousJustifiedRoot) { diff --git a/beacon-chain/core/blocks/block_operations_test.go b/beacon-chain/core/blocks/block_operations_test.go index f0d3d83f1602..bd0b669d76e9 100644 --- a/beacon-chain/core/blocks/block_operations_test.go +++ b/beacon-chain/core/blocks/block_operations_test.go @@ -63,7 +63,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) { if err != nil { t.Fatal(err) } - epoch := helpers.SlotToEpoch(params.BeaconConfig().GenesisSlot) + epoch := uint64(0) buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, epoch) domain := helpers.DomainVersion(beaconState, epoch, params.BeaconConfig().DomainRandao) @@ -99,7 +99,7 @@ func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T) if err != nil { t.Fatal(err) } - epoch := helpers.SlotToEpoch(params.BeaconConfig().GenesisSlot) + epoch := uint64(0) buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, epoch) domain := helpers.DomainVersion(beaconState, epoch, params.BeaconConfig().DomainRandao) @@ -198,10 +198,10 @@ func TestProcessProposerSlashings_UnmatchedHeaderEpochs(t *testing.T) { { ProposerIndex: 1, Header_1: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch + 1, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, }, Header_2: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, }, }, } @@ -232,10 +232,10 @@ func TestProcessProposerSlashings_SameHeaders(t *testing.T) { { ProposerIndex: 1, Header_1: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisEpoch, + Slot: 0, }, Header_2: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisEpoch, + Slot: 0, }, }, } @@ -265,8 +265,8 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) { { Pubkey: []byte("key"), Slashed: true, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, - WithdrawableEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, + WithdrawableEpoch: 0, }, } currentSlot := uint64(0) @@ -274,11 +274,11 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) { { ProposerIndex: 0, Header_1: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Signature: []byte("A"), }, Header_2: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Signature: []byte("B"), }, }, @@ -316,9 +316,9 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) { EffectiveBalance: params.BeaconConfig().MaxDepositAmount, Slashed: false, ExitEpoch: params.BeaconConfig().FarFutureEpoch, - SlashedEpoch: params.BeaconConfig().GenesisEpoch + 1, + SlashedEpoch: 1, WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, } } validatorBalances := make([]uint64, len(validators)) @@ -330,16 +330,16 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) { { ProposerIndex: 1, Header_1: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Signature: []byte("A"), }, Header_2: &pb.BeaconBlockHeader{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Signature: []byte("B"), }, }, } - currentSlot := params.BeaconConfig().GenesisSlot + currentSlot := uint64(0) beaconState := &pb.BeaconState{ ValidatorRegistry: validators, Slot: currentSlot, @@ -566,10 +566,10 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { validators := make([]*pb.Validator, params.BeaconConfig().DepositsForChainStart) for i := 0; i < len(validators); i++ { validators[i] = &pb.Validator{ - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Slashed: false, - WithdrawableEpoch: params.BeaconConfig().GenesisEpoch + 1*params.BeaconConfig().SlotsPerEpoch, + WithdrawableEpoch: 1 * params.BeaconConfig().SlotsPerEpoch, } } validatorBalances := make([]uint64, len(validators)) @@ -600,7 +600,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { }, } - currentSlot := params.BeaconConfig().GenesisSlot + 2*params.BeaconConfig().SlotsPerEpoch + currentSlot := 2 * params.BeaconConfig().SlotsPerEpoch beaconState := &pb.BeaconState{ ValidatorRegistry: validators, Slot: currentSlot, @@ -666,7 +666,7 @@ func TestProcessBlockAttestations_InclusionDelayFailure(t *testing.T) { attestations := []*pb.Attestation{ { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, }, }, } @@ -676,7 +676,7 @@ func TestProcessBlockAttestations_InclusionDelayFailure(t *testing.T) { }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, } want := fmt.Sprintf( @@ -698,7 +698,7 @@ func TestProcessBlockAttestations_EpochDistanceFailure(t *testing.T) { attestations := []*pb.Attestation{ { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, }, }, } @@ -708,7 +708,7 @@ func TestProcessBlockAttestations_EpochDistanceFailure(t *testing.T) { }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 5 + 2*params.BeaconConfig().SlotsPerEpoch, + Slot: 5 + 2*params.BeaconConfig().SlotsPerEpoch, } want := fmt.Sprintf( @@ -730,8 +730,8 @@ func TestProcessBlockAttestations_JustifiedEpochVerificationFailure(t *testing.T attestations := []*pb.Attestation{ { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 152, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 2, + Slot: 152, + JustifiedEpoch: 2, }, }, } @@ -741,8 +741,8 @@ func TestProcessBlockAttestations_JustifiedEpochVerificationFailure(t *testing.T }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 158, - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch + 1, + Slot: 158, + CurrentJustifiedEpoch: 1, } want := fmt.Sprintf( @@ -763,8 +763,8 @@ func TestProcessBlockAttestations_PreviousJustifiedEpochVerificationFailure(t *t attestations := []*pb.Attestation{ { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch + 1, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 3, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, + JustifiedEpoch: 3, }, }, } @@ -774,8 +774,8 @@ func TestProcessBlockAttestations_PreviousJustifiedEpochVerificationFailure(t *t }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 2*params.BeaconConfig().SlotsPerEpoch, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch + 2, + Slot: 2 * params.BeaconConfig().SlotsPerEpoch, + PreviousJustifiedEpoch: 2, } want := fmt.Sprintf( @@ -808,8 +808,8 @@ func TestProcessBlockAttestations_CrosslinkRootFailure(t *testing.T) { }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 70, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 70, + PreviousJustifiedEpoch: 0, LatestBlockRoots: blockRoots, PreviousJustifiedRoot: blockRoots[0], LatestCrosslinks: stateLatestCrosslinks, @@ -818,11 +818,11 @@ func TestProcessBlockAttestations_CrosslinkRootFailure(t *testing.T) { { Data: &pb.AttestationData{ Shard: 0, - Slot: params.BeaconConfig().GenesisSlot + 20, + Slot: 20, JustifiedBlockRootHash32: blockRoots[0], LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{2}}, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], - JustifiedEpoch: params.BeaconConfig().GenesisEpoch, + JustifiedEpoch: 0, }, }, } @@ -856,8 +856,8 @@ func TestProcessBlockAttestations_ShardBlockRootEqualZeroHashFailure(t *testing. }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 70, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 70, + PreviousJustifiedEpoch: 0, LatestBlockRoots: blockRoots, LatestCrosslinks: stateLatestCrosslinks, PreviousJustifiedRoot: blockRoots[0], @@ -866,11 +866,11 @@ func TestProcessBlockAttestations_ShardBlockRootEqualZeroHashFailure(t *testing. { Data: &pb.AttestationData{ Shard: 0, - Slot: params.BeaconConfig().GenesisSlot + 20, + Slot: 20, JustifiedBlockRootHash32: blockRoots[0], LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}}, CrosslinkDataRoot: []byte{1}, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch, + JustifiedEpoch: 0, }, }, } @@ -905,8 +905,8 @@ func TestProcessBlockAttestations_CreatePendingAttestations(t *testing.T) { }, } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 70, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 70, + PreviousJustifiedEpoch: 0, LatestBlockRoots: blockRoots, LatestCrosslinks: stateLatestCrosslinks, PreviousJustifiedRoot: blockRoots[0], @@ -914,11 +914,11 @@ func TestProcessBlockAttestations_CreatePendingAttestations(t *testing.T) { att1 := &pb.Attestation{ Data: &pb.AttestationData{ Shard: 0, - Slot: params.BeaconConfig().GenesisSlot + 20, + Slot: 20, JustifiedBlockRootHash32: blockRoots[0], LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}}, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], - JustifiedEpoch: params.BeaconConfig().GenesisEpoch, + JustifiedEpoch: 0, }, AggregationBitfield: []byte{1}, CustodyBitfield: []byte{1}, @@ -946,7 +946,7 @@ func TestProcessBlockAttestations_CreatePendingAttestations(t *testing.T) { pendingAttestations[0].Data, ) } - if pendingAttestations[0].InclusionSlot != params.BeaconConfig().GenesisSlot+70 { + if pendingAttestations[0].InclusionSlot != 70 { t.Errorf( "Pending attestation not included at correct slot: wanted %v, received %v", 64, @@ -979,7 +979,7 @@ func TestConvertToIndexed_OK(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -994,28 +994,28 @@ func TestConvertToIndexed_OK(t *testing.T) { aggregationBitfield: []byte{0x03}, custodyBitfield: []byte{0x01}, wantedCustodyBit0Indices: []uint64{}, - wantedCustodyBit1Indices: []uint64{37, 100}, + wantedCustodyBit1Indices: []uint64{21, 126}, }, { aggregationBitfield: []byte{0x03}, custodyBitfield: []byte{0x02}, wantedCustodyBit0Indices: []uint64{}, - wantedCustodyBit1Indices: []uint64{37, 100}, + wantedCustodyBit1Indices: []uint64{21, 126}, }, { aggregationBitfield: []byte{0x03}, custodyBitfield: []byte{0x03}, wantedCustodyBit0Indices: []uint64{}, - wantedCustodyBit1Indices: []uint64{37, 100}, + wantedCustodyBit1Indices: []uint64{21, 126}, }, } attestation := &pb.Attestation{ Signature: []byte("signed"), Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 2, + Slot: 2, Shard: 3, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + TargetEpoch: 0, }, } for _, tt := range tests { @@ -1213,7 +1213,7 @@ func TestProcessValidatorDeposits_IncorrectMerkleIndex(t *testing.T) { beaconState := &pb.BeaconState{ ValidatorRegistry: registry, Balances: balances, - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, GenesisTime: uint64(0), DepositIndex: 1, LatestEth1Data: &pb.Eth1Data{ @@ -1430,12 +1430,12 @@ func TestProcessValidatorExits_AppliesCorrectStatus(t *testing.T) { registry := []*pb.Validator{ { ExitEpoch: params.BeaconConfig().FarFutureEpoch, - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, }, } state := &pb.BeaconState{ ValidatorRegistry: registry, - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch*5, + Slot: params.BeaconConfig().SlotsPerEpoch * 5, } state.Slot = state.Slot + (params.BeaconConfig().PersistentCommitteePeriod * params.BeaconConfig().SlotsPerEpoch) block := &pb.BeaconBlock{ @@ -1495,7 +1495,7 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) { } balances := []uint64{params.BeaconConfig().MaxDepositAmount} state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: registry, Balances: balances, } @@ -1542,7 +1542,7 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) { } state.ValidatorRegistry[0].WithdrawableEpoch = params.BeaconConfig().FarFutureEpoch - state.ValidatorRegistry[0].ActivationEligibilityEpoch = params.BeaconConfig().GenesisEpoch + state.ValidatorRegistry[0].ActivationEligibilityEpoch = 0 block.Body.Transfers = []*pb.Transfer{ { Fee: params.BeaconConfig().MinDepositAmount, @@ -1559,7 +1559,7 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) { t.Errorf("Expected %s, received %v", want, err) } - state.ValidatorRegistry[0].WithdrawableEpoch = params.BeaconConfig().GenesisEpoch + state.ValidatorRegistry[0].WithdrawableEpoch = 0 state.ValidatorRegistry[0].ActivationEligibilityEpoch = params.BeaconConfig().FarFutureEpoch buf := []byte{params.BeaconConfig().BLSWithdrawalPrefixByte} pubKey := []byte("B") @@ -1591,10 +1591,10 @@ func TestProcessBeaconTransfers_OK(t *testing.T) { validators := make([]*pb.Validator, params.BeaconConfig().DepositsForChainStart) for i := 0; i < len(validators); i++ { validators[i] = &pb.Validator{ - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Slashed: false, - WithdrawableEpoch: params.BeaconConfig().GenesisEpoch, + WithdrawableEpoch: 0, } } validatorBalances := make([]uint64, len(validators)) @@ -1604,7 +1604,7 @@ func TestProcessBeaconTransfers_OK(t *testing.T) { state := &pb.BeaconState{ ValidatorRegistry: validators, - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Balances: validatorBalances, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength), diff --git a/beacon-chain/core/blocks/block_test.go b/beacon-chain/core/blocks/block_test.go index fee1de6ec944..3d9c7f2d6bd1 100644 --- a/beacon-chain/core/blocks/block_test.go +++ b/beacon-chain/core/blocks/block_test.go @@ -83,8 +83,8 @@ func TestBlockRootAtSlot_AccurateBlockRoot(t *testing.T) { }, } for _, tt := range tests { - state.Slot = tt.stateSlot + params.BeaconConfig().GenesisSlot - wantedSlot := tt.slot + params.BeaconConfig().GenesisSlot + state.Slot = tt.stateSlot + wantedSlot := tt.slot result, err := BlockRoot(state, wantedSlot) if err != nil { t.Errorf("failed to get block root at slot %d: %v", wantedSlot, err) @@ -119,16 +119,16 @@ func TestBlockRootAtSlot_OutOfBounds(t *testing.T) { expectedErr string }{ { - slot: params.BeaconConfig().GenesisSlot + 1000, - stateSlot: params.BeaconConfig().GenesisSlot + 500, + slot: 1000, + stateSlot: 500, expectedErr: fmt.Sprintf("slot %d is not within expected range of %d to %d", 1000, 0, 500), }, { - slot: params.BeaconConfig().GenesisSlot + 129, - stateSlot: params.BeaconConfig().GenesisSlot + 400, + slot: 129, + stateSlot: 400, expectedErr: "slot 129 is not within expected range of 272 to 399", }, } diff --git a/beacon-chain/core/blocks/validity_conditions.go b/beacon-chain/core/blocks/validity_conditions.go index 5feff0b8fa3b..7283590f9b52 100644 --- a/beacon-chain/core/blocks/validity_conditions.go +++ b/beacon-chain/core/blocks/validity_conditions.go @@ -58,7 +58,7 @@ func IsValidBlock( // The node's local time is greater than or equal to // state.genesis_time + (block.slot-GENESIS_SLOT)* SECONDS_PER_SLOT. if !IsSlotValid(block.Slot, genesisTime) { - return fmt.Errorf("slot of block is too high: %d", block.Slot-params.BeaconConfig().GenesisSlot) + return fmt.Errorf("slot of block is too high: %d", block.Slot) } return nil @@ -66,7 +66,7 @@ func IsValidBlock( // IsSlotValid compares the slot to the system clock to determine if the block is valid. func IsSlotValid(slot uint64, genesisTime time.Time) bool { - secondsPerSlot := time.Duration((slot-params.BeaconConfig().GenesisSlot)*params.BeaconConfig().SecondsPerSlot) * time.Second + secondsPerSlot := time.Duration((slot)*params.BeaconConfig().SecondsPerSlot) * time.Second validTimeThreshold := genesisTime.Add(secondsPerSlot) now := clock.Now() isValid := now.After(validTimeThreshold) diff --git a/beacon-chain/core/blocks/validity_conditions_test.go b/beacon-chain/core/blocks/validity_conditions_test.go index 78ec3df2f183..913564f0c9d2 100644 --- a/beacon-chain/core/blocks/validity_conditions_test.go +++ b/beacon-chain/core/blocks/validity_conditions_test.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/go-ethereum/common" gethTypes "github.com/ethereum/go-ethereum/core/types" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" ) @@ -43,10 +42,10 @@ func TestIsValidBlock_NoParent(t *testing.T) { db := &mockDB{} powClient := &mockPOWClient{} - beaconState.Slot = params.BeaconConfig().GenesisSlot + 3 + beaconState.Slot = 3 block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } genesisTime := time.Unix(0, 0) @@ -67,15 +66,15 @@ func TestIsValidBlock_InvalidSlot(t *testing.T) { db := &mockDB{} powClient := &mockPOWClient{} - beaconState.Slot = params.BeaconConfig().GenesisSlot + 3 + beaconState.Slot = 3 block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } genesisTime := time.Unix(0, 0) - block.Slot = params.BeaconConfig().GenesisSlot + 3 + block.Slot = 3 db.hasBlock = true beaconState.LatestEth1Data = &pb.Eth1Data{ @@ -96,16 +95,16 @@ func TestIsValidBlock_InvalidPoWReference(t *testing.T) { db := &mockDB{} powClient := &mockPOWClient{} - beaconState.Slot = params.BeaconConfig().GenesisSlot + 3 + beaconState.Slot = 3 block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } genesisTime := time.Unix(0, 0) db.hasBlock = true - block.Slot = params.BeaconConfig().GenesisSlot + 4 + block.Slot = 4 powClient.blockExists = false beaconState.LatestEth1Data = &pb.Eth1Data{ DepositRoot: []byte{2}, @@ -129,7 +128,7 @@ func TestIsValidBlock_InvalidGenesis(t *testing.T) { powClient := &mockPOWClient{} powClient.blockExists = false - beaconState.Slot = params.BeaconConfig().GenesisSlot + 3 + beaconState.Slot = 3 beaconState.LatestEth1Data = &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -137,7 +136,7 @@ func TestIsValidBlock_InvalidGenesis(t *testing.T) { genesisTime := time.Unix(0, 0) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } invalidTime := time.Now().AddDate(1, 2, 3) @@ -159,7 +158,7 @@ func TestIsValidBlock_GoodBlock(t *testing.T) { powClient := &mockPOWClient{} powClient.blockExists = true - beaconState.Slot = params.BeaconConfig().GenesisSlot + 3 + beaconState.Slot = 3 beaconState.LatestEth1Data = &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -168,7 +167,7 @@ func TestIsValidBlock_GoodBlock(t *testing.T) { genesisTime := time.Unix(0, 0) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } if err := IsValidBlock(ctx, beaconState, block, diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index bd709fdf522b..2f4409b7f72f 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -95,7 +95,7 @@ func ProcessJustificationFinalization(state *pb.BeaconState, prevAttestedBal uin *pb.BeaconState, error) { // There's no reason to process justification until the 3rd epoch. currentEpoch := helpers.CurrentEpoch(state) - if currentEpoch <= params.BeaconConfig().GenesisEpoch+1 { + if currentEpoch <= 1 { return state, nil } @@ -179,15 +179,15 @@ func ProcessCrosslink(state *pb.BeaconState) (*pb.BeaconState, error) { for i := uint64(0); i < offset; i++ { shard, err := helpers.EpochStartShard(state, e) if err != nil { - return nil, fmt.Errorf("could not get epoch start shards: %v", err) + return nil, err } committee, err := helpers.CrosslinkCommitteeAtEpoch(state, e, shard) if err != nil { - return nil, fmt.Errorf("could not get crosslink committee: %v", err) + return nil, err } crosslink, indices, err := WinningCrosslink(state, shard, e) if err != nil { - return nil, fmt.Errorf("could not get winning crosslink: %v", err) + return nil, err } attestedBalance := helpers.TotalBalance(state, indices) totalBalance := helpers.TotalBalance(state, committee) @@ -411,7 +411,7 @@ func WinningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*pb.Cr if len(candidateCrosslinks) == 0 { return &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:], PreviousCrosslinkRootHash32: params.BeaconConfig().ZeroHash[:], }, nil, nil @@ -448,66 +448,6 @@ func WinningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*pb.Cr return winnerCrosslink, crosslinkIndices, nil } -// CrosslinkDelta calculates the rewards and penalties of individual -// validator for submitting the correct crosslink. -// Individual rewards and penalties are returned in list. -// -// Spec pseudocode definition: -// def get_crosslink_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]: -// rewards = [0 for index in range(len(state.validator_registry))] -// penalties = [0 for index in range(len(state.validator_registry))] -// epoch = get_previous_epoch(state) -// for offset in range(get_epoch_committee_count(state, epoch)): -// shard = (get_epoch_start_shard(state, epoch) + offset) % SHARD_COUNT -// crosslink_committee = get_crosslink_committee(state, epoch, shard) -// winning_crosslink, attesting_indices = get_winning_crosslink_and_attesting_indices(state, epoch, shard) -// attesting_balance = get_total_balance(state, attesting_indices) -// committee_balance = get_total_balance(state, crosslink_committee) -// for index in crosslink_committee: -// base_reward = get_base_reward(state, index) -// if index in attesting_indices: -// rewards[index] += base_reward * attesting_balance // committee_balance -// else: -// penalties[index] += base_reward -// return rewards, penalties -func CrosslinkDelta(state *pb.BeaconState) ([]uint64, []uint64, error) { - rewards := make([]uint64, len(state.ValidatorRegistry)) - penalties := make([]uint64, len(state.ValidatorRegistry)) - epoch := helpers.PrevEpoch(state) - count := helpers.EpochCommitteeCount(state, epoch) - startShard, err := helpers.EpochStartShard(state, epoch) - if err != nil { - return nil, nil, fmt.Errorf("could not get epoch start shard: %v", err) - } - for i := uint64(0); i < count; i++ { - shard := (startShard + i) % params.BeaconConfig().ShardCount - committee, err := helpers.CrosslinkCommitteeAtEpoch(state, epoch, shard) - if err != nil { - return nil, nil, fmt.Errorf("could not get crosslink's committee: %v", err) - } - _, attestingIndices, err := WinningCrosslink(state, shard, epoch) - if err != nil { - return nil, nil, fmt.Errorf("could not get winning crosslink: %v", err) - } - - attested := make(map[uint64]bool) - // Construct a map to look up validators that voted for crosslink. - for _, index := range attestingIndices { - attested[index] = true - } - committeeBalance := helpers.TotalBalance(state, committee) - attestingBalance := helpers.TotalBalance(state, attestingIndices) - for _, index := range committee { - if _, ok := attested[index]; ok { - rewards[index] += BaseReward(state, index) * attestingBalance / committeeBalance - } else { - penalties[index] += BaseReward(state, index) - } - } - } - return rewards, penalties, nil -} - // UnslashedAttestingIndices returns all the attesting indices from a list of attestations, // it sorts the indices and filters out the slashed ones. // diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 926bad931696..90c08f2353f8 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -62,13 +62,14 @@ func TestCanProcessEpoch_TrueOnEpochs(t *testing.T) { } func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) { + // Generate 2 attestations. atts := make([]*pb.PendingAttestation, 2) for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: uint64(i + 2), }, AggregationBitfield: []byte{0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, @@ -84,7 +85,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) { } } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -115,12 +116,13 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) { } func TestUnslashedAttestingIndices_CantGetIndicesBitfieldError(t *testing.T) { + atts := make([]*pb.PendingAttestation, 2) for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: 2, }, AggregationBitfield: []byte{0xff}, @@ -128,7 +130,7 @@ func TestUnslashedAttestingIndices_CantGetIndicesBitfieldError(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -144,8 +146,8 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: uint64(i + 2), }, AggregationBitfield: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -164,7 +166,7 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) { balances[i] = params.BeaconConfig().MaxDepositAmount } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), ValidatorRegistry: validators, @@ -186,8 +188,8 @@ func TestAttestingBalance_CantGetIndicesBitfieldError(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: 2, }, AggregationBitfield: []byte{0xFF}, @@ -195,7 +197,7 @@ func TestAttestingBalance_CantGetIndicesBitfieldError(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -211,8 +213,8 @@ func TestEarliestAttestation_CanGetEarliest(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: uint64(i + 2), }, InclusionSlot: uint64(i + 100), @@ -231,7 +233,7 @@ func TestEarliestAttestation_CanGetEarliest(t *testing.T) { balances[i] = params.BeaconConfig().MaxDepositAmount } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, Balances: balances, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), @@ -256,8 +258,8 @@ func TestEarliestAttestation_CantGetIndicesBitfieldError(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: uint64(i), + TargetEpoch: 0, Shard: 2, }, AggregationBitfield: []byte{0xFF}, @@ -265,7 +267,7 @@ func TestEarliestAttestation_CantGetIndicesBitfieldError(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -277,7 +279,7 @@ func TestEarliestAttestation_CantGetIndicesBitfieldError(t *testing.T) { func TestMatchAttestations_PrevEpoch(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch - s := params.BeaconConfig().GenesisSlot + s := uint64(0) // slot // The correct epoch for source is the first epoch // The correct vote for target is '1' @@ -312,7 +314,7 @@ func TestMatchAttestations_PrevEpoch(t *testing.T) { LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } - mAtts, err := MatchAttestations(state, params.BeaconConfig().GenesisEpoch) + mAtts, err := MatchAttestations(state, 0) if err != nil { t.Fatal(err) } @@ -354,7 +356,7 @@ func TestMatchAttestations_PrevEpoch(t *testing.T) { func TestMatchAttestations_CurrentEpoch(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch - s := params.BeaconConfig().GenesisSlot + s := uint64(0) // slot // The correct epoch for source is the first epoch // The correct vote for target is '65' @@ -384,7 +386,7 @@ func TestMatchAttestations_CurrentEpoch(t *testing.T) { LatestBlockRoots: blockRoots, } - mAtts, err := MatchAttestations(state, params.BeaconConfig().GenesisEpoch+1) + mAtts, err := MatchAttestations(state, 1) if err != nil { t.Fatal(err) } @@ -426,17 +428,17 @@ func TestMatchAttestations_EpochOutOfBound(t *testing.T) { func TestCrosslinkFromAttsData_CanGetCrosslink(t *testing.T) { s := &pb.BeaconState{ CurrentCrosslinks: []*pb.Crosslink{ - {Epoch: params.BeaconConfig().GenesisEpoch}, + {Epoch: 0}, }, } - slot := (params.BeaconConfig().GenesisEpoch + 100) * params.BeaconConfig().SlotsPerEpoch + slot := (100) * params.BeaconConfig().SlotsPerEpoch a := &pb.AttestationData{ Slot: slot, CrosslinkDataRoot: []byte{'A'}, PreviousCrosslinkRoot: []byte{'B'}, } if !proto.Equal(CrosslinkFromAttsData(s, a), &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch + params.BeaconConfig().MaxCrosslinkEpochs, + Epoch: params.BeaconConfig().MaxCrosslinkEpochs, CrosslinkDataRootHash32: []byte{'A'}, PreviousCrosslinkRootHash32: []byte{'B'}, }) { @@ -447,7 +449,7 @@ func TestCrosslinkFromAttsData_CanGetCrosslink(t *testing.T) { func TestAttsForCrosslink_CanGetAttestations(t *testing.T) { s := &pb.BeaconState{ CurrentCrosslinks: []*pb.Crosslink{ - {Epoch: params.BeaconConfig().GenesisEpoch}, + {Epoch: 0}, }, } c := &pb.Crosslink{ @@ -470,10 +472,10 @@ func TestCrosslinkAttestingIndices_CanGetIndices(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), Shard: uint64(i + 2), PreviousCrosslinkRoot: []byte{'E'}, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + TargetEpoch: 0, }, AggregationBitfield: []byte{0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0}, @@ -488,19 +490,19 @@ func TestCrosslinkAttestingIndices_CanGetIndices(t *testing.T) { } } s := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, CurrentCrosslinks: []*pb.Crosslink{ - {Epoch: params.BeaconConfig().GenesisEpoch}, - {Epoch: params.BeaconConfig().GenesisEpoch}, - {Epoch: params.BeaconConfig().GenesisEpoch}, - {Epoch: params.BeaconConfig().GenesisEpoch}, + {Epoch: 0}, + {Epoch: 0}, + {Epoch: 0}, + {Epoch: 0}, }, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } c := &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, PreviousCrosslinkRootHash32: []byte{'E'}, } indices, err := CrosslinkAttestingIndices(s, c, atts) @@ -521,8 +523,8 @@ func TestCrosslinkAttestingIndices_CanGetIndices(t *testing.T) { func TestWinningCrosslink_CantGetMatchingAtts(t *testing.T) { wanted := fmt.Sprintf("could not get matching attestations: input epoch: %d != current epoch: %d or previous epoch: %d", - 100, params.BeaconConfig().GenesisEpoch, params.BeaconConfig().GenesisEpoch) - _, _, err := WinningCrosslink(&pb.BeaconState{Slot: params.BeaconConfig().GenesisSlot}, 0, 100) + 100, 0, 0) + _, _, err := WinningCrosslink(&pb.BeaconState{Slot: 0}, 0, 100) if err.Error() != wanted { t.Fatal(err) } @@ -530,8 +532,8 @@ func TestWinningCrosslink_CantGetMatchingAtts(t *testing.T) { func TestWinningCrosslink_ReturnGensisCrosslink(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - ge := params.BeaconConfig().GenesisEpoch + gs := uint64(0) // genesis slot + ge := uint64(0) // genesis epoch state := &pb.BeaconState{ Slot: gs + e + 2, @@ -541,7 +543,7 @@ func TestWinningCrosslink_ReturnGensisCrosslink(t *testing.T) { } gCrosslink := &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:], PreviousCrosslinkRootHash32: params.BeaconConfig().ZeroHash[:], } @@ -562,8 +564,8 @@ func TestWinningCrosslink_CanGetWinningRoot(t *testing.T) { t.Skip() // TODO(#2307) unskip after ProcessCrosslinks is finished e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - ge := params.BeaconConfig().GenesisEpoch + gs := uint64(0) // genesis slot + ge := uint64(0) // genesis epoch atts := []*pb.PendingAttestation{ { @@ -630,18 +632,18 @@ func TestProcessCrosslink_NoUpdate(t *testing.T) { blockRoots[i] = []byte{byte(i + 1)} } oldCrosslink := &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: []byte{'A'}, } var crosslinks []*pb.Crosslink for i := uint64(0); i < params.BeaconConfig().ShardCount; i++ { crosslinks = append(crosslinks, &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: []byte{'A'}, }) } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch + 1, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, ValidatorRegistry: validators, Balances: balances, LatestBlockRoots: blockRoots, @@ -662,8 +664,8 @@ func TestProcessCrosslink_NoUpdate(t *testing.T) { func TestProcessCrosslink_SuccessfulUpdate(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - ge := params.BeaconConfig().GenesisEpoch + gs := uint64(0) // genesis slot + ge := uint64(0) // genesis epoch validators := make([]*pb.Validator, params.BeaconConfig().DepositsForChainStart/8) balances := make([]uint64, params.BeaconConfig().DepositsForChainStart/8) @@ -693,7 +695,7 @@ func TestProcessCrosslink_SuccessfulUpdate(t *testing.T) { Slot: gs + 1 + (s % e), Shard: s, CrosslinkDataRoot: []byte{'B'}, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + TargetEpoch: 0, }, AggregationBitfield: []byte{0xC0, 0xC0, 0xC0, 0xC0}, }) @@ -761,10 +763,10 @@ func TestProcessJustificationFinalization_CantJustifyFinalize(t *testing.T) { e := params.BeaconConfig().FarFutureEpoch a := params.BeaconConfig().MaxDepositAmount state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch*2, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch * 2, + PreviousJustifiedEpoch: 0, PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:], - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + CurrentJustifiedEpoch: 0, CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:], ValidatorRegistry: []*pb.Validator{{ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a}}, @@ -787,10 +789,10 @@ func TestProcessJustificationFinalization_NoBlockRootCurrentEpoch(t *testing.T) blockRoots[i] = []byte{byte(i)} } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch*2, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch * 2, + PreviousJustifiedEpoch: 0, PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:], - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + CurrentJustifiedEpoch: 0, CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:], JustificationBitfield: 3, ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, @@ -813,10 +815,10 @@ func TestProcessJustificationFinalization_JustifyCurrentEpoch(t *testing.T) { blockRoots[i] = []byte{byte(i)} } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch*2 + 1, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch*2 + 1, + PreviousJustifiedEpoch: 0, PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:], - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + CurrentJustifiedEpoch: 0, CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:], JustificationBitfield: 3, ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, @@ -832,17 +834,16 @@ func TestProcessJustificationFinalization_JustifyCurrentEpoch(t *testing.T) { t.Errorf("Wanted current justified root: %v, got: %v", []byte{byte(128)}, newState.CurrentJustifiedRoot) } - if newState.CurrentJustifiedEpoch != params.BeaconConfig().GenesisEpoch+2 { + if newState.CurrentJustifiedEpoch != 2 { t.Errorf("Wanted justified epoch: %d, got: %d", - params.BeaconConfig().GenesisEpoch+2, newState.CurrentJustifiedEpoch) + 2, newState.CurrentJustifiedEpoch) } if !bytes.Equal(newState.FinalizedRoot, params.BeaconConfig().ZeroHash[:]) { t.Errorf("Wanted current finalized root: %v, got: %v", params.BeaconConfig().ZeroHash, newState.FinalizedRoot) } - if newState.FinalizedEpoch != params.BeaconConfig().GenesisEpoch { - t.Errorf("Wanted finalized epoch: %d, got: %d", - params.BeaconConfig().GenesisEpoch, newState.FinalizedEpoch) + if newState.FinalizedEpoch != 0 { + t.Errorf("Wanted finalized epoch: %d, got: %d", 0, newState.FinalizedEpoch) } } @@ -854,10 +855,10 @@ func TestProcessJustificationFinalization_JustifyPrevEpoch(t *testing.T) { blockRoots[i] = []byte{byte(i)} } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch*2 + 1, - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch*2 + 1, + PreviousJustifiedEpoch: 0, PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:], - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + CurrentJustifiedEpoch: 0, CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:], JustificationBitfield: 3, ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, @@ -873,23 +874,22 @@ func TestProcessJustificationFinalization_JustifyPrevEpoch(t *testing.T) { t.Errorf("Wanted current justified root: %v, got: %v", []byte{byte(128)}, newState.CurrentJustifiedRoot) } - if newState.CurrentJustifiedEpoch != params.BeaconConfig().GenesisEpoch+2 { + if newState.CurrentJustifiedEpoch != 2 { t.Errorf("Wanted justified epoch: %d, got: %d", - params.BeaconConfig().GenesisEpoch+2, newState.CurrentJustifiedEpoch) + 2, newState.CurrentJustifiedEpoch) } if !bytes.Equal(newState.FinalizedRoot, params.BeaconConfig().ZeroHash[:]) { t.Errorf("Wanted current finalized root: %v, got: %v", params.BeaconConfig().ZeroHash, newState.FinalizedRoot) } - if newState.FinalizedEpoch != params.BeaconConfig().GenesisEpoch { - t.Errorf("Wanted finalized epoch: %d, got: %d", - params.BeaconConfig().GenesisEpoch, newState.FinalizedEpoch) + if newState.FinalizedEpoch != 0 { + t.Errorf("Wanted finalized epoch: %d, got: %d", 0, newState.FinalizedEpoch) } } func TestProcessSlashings_NotSlashed(t *testing.T) { s := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: []*pb.Validator{{Slashed: true}}, Balances: []uint64{params.BeaconConfig().MaxDepositAmount}, LatestSlashedBalances: []uint64{0, 1e9}, @@ -903,10 +903,10 @@ func TestProcessSlashings_NotSlashed(t *testing.T) { func TestProcessSlashings_SlashedLess(t *testing.T) { s := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: []*pb.Validator{ {Slashed: true, - WithdrawableEpoch: params.BeaconConfig().GenesisEpoch + params.BeaconConfig().LatestSlashedExitLength/2, + WithdrawableEpoch: params.BeaconConfig().LatestSlashedExitLength / 2, EffectiveBalance: params.BeaconConfig().MaxDepositAmount}, {ExitEpoch: params.BeaconConfig().FarFutureEpoch, EffectiveBalance: params.BeaconConfig().MaxDepositAmount}}, Balances: []uint64{params.BeaconConfig().MaxDepositAmount, params.BeaconConfig().MaxDepositAmount}, @@ -966,94 +966,6 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) { } } -func TestCrosslinkDelta_NoOneAttested(t *testing.T) { - e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - - validatorCount := uint64(128) - state := buildState(gs+e+2, validatorCount) - - rewards, penalties, err := CrosslinkDelta(state) - if err != nil { - t.Fatal(err) - } - - for i := uint64(0); i < validatorCount; i++ { - // Since no one attested, all the validators should gain 0 reward - if rewards[i] != 0 { - t.Errorf("Wanted reward balance 0, got %d", rewards[i]) - } - // Since no one attested, all the validators should get penalized the same - if penalties[i] != BaseReward(state, i) { - t.Errorf("Wanted penalty balance %d, got %d", - BaseReward(state, i), penalties[i]) - } - } -} - -func TestCrosslinkDelta_SomeAttested(t *testing.T) { - e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - ge := params.BeaconConfig().GenesisEpoch - - state := buildState(gs+e+2, params.BeaconConfig().DepositsForChainStart/8) - startShard := uint64(960) - atts := make([]*pb.PendingAttestation, 2) - for i := 0; i < len(atts); i++ { - atts[i] = &pb.PendingAttestation{ - Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), - TargetEpoch: params.BeaconConfig().GenesisEpoch, - CrosslinkDataRoot: []byte{'A'}, - Shard: startShard + 1, - }, - InclusionSlot: uint64(i + 100), - AggregationBitfield: []byte{0xC0, 0xC0, 0xC0, 0xC0}, - } - } - state.PreviousEpochAttestations = atts - state.CurrentCrosslinks[startShard] = &pb.Crosslink{ - Epoch: ge, - CrosslinkDataRootHash32: []byte{'A'}, - } - state.CurrentCrosslinks[startShard+1] = &pb.Crosslink{ - Epoch: ge, - CrosslinkDataRootHash32: []byte{'A'}, - } - - rewards, penalties, err := CrosslinkDelta(state) - if err != nil { - t.Fatal(err) - } - - attestedIndices := []uint64{184, 638, 714, 1511, 506, 11, 797} - for _, i := range attestedIndices { - // Since all these validators attested, they should get the same rewards. - if rewards[i] != BaseReward(state, i) { - t.Errorf("Wanted reward balance %d, got %d", BaseReward(state, i), rewards[i]) - } - // Since all these validators attested, they shouldn't get penalized. - if penalties[i] != 0 { - t.Errorf("Wanted penalty balance %d, got %d", - 0, penalties[i]) - } - } -} - -func TestCrosslinkDelta_CantGetStartShard(t *testing.T) { - e := params.BeaconConfig().SlotsPerEpoch - gs := params.BeaconConfig().GenesisSlot - - state := buildState(gs+2*e, 1) - state.Slot = 0 - - _, _, err := CrosslinkDelta(state) - wanted := "could not get epoch start shard" - if !strings.Contains(err.Error(), wanted) { - t.Fatalf("Got: %v, want: %v", err.Error(), wanted) - } -} - func buildState(slot uint64, validatorCount uint64) *pb.BeaconState { validators := make([]*pb.Validator, validatorCount) for i := 0; i < len(validators); i++ { @@ -1084,10 +996,8 @@ func buildState(slot uint64, validatorCount uint64) *pb.BeaconState { Slot: slot, Balances: validatorBalances, ValidatorRegistry: validators, - CurrentCrosslinks: make([]*pb.Crosslink, params.BeaconConfig().ShardCount), LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength), - LatestBlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10), } } diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index 9ceec9a0abac..00fa8e4e3002 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -43,10 +43,10 @@ func TestAttestationDataSlot_OK(t *testing.T) { t.Fatal(err) } offset := uint64(0) - committeeCount := helpers.EpochCommitteeCount(beaconState, params.BeaconConfig().GenesisEpoch) - expect := params.BeaconConfig().GenesisSlot + (offset / (committeeCount / params.BeaconConfig().SlotsPerEpoch)) + committeeCount := helpers.EpochCommitteeCount(beaconState, 0) + expect := offset / (committeeCount / params.BeaconConfig().SlotsPerEpoch) attSlot, err := helpers.AttestationDataSlot(beaconState, &pb.AttestationData{ - TargetEpoch: params.BeaconConfig().GenesisEpoch, + TargetEpoch: 0, Crosslink: &pb.Crosslink{ Shard: 0, }, diff --git a/beacon-chain/core/helpers/block.go b/beacon-chain/core/helpers/block.go index ba6398f09f56..1612930ec11b 100644 --- a/beacon-chain/core/helpers/block.go +++ b/beacon-chain/core/helpers/block.go @@ -18,16 +18,16 @@ import ( // assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT // return state.latest_block_roots[slot % SLOTS_PER_HISTORICAL_ROOT] func BlockRootAtSlot(state *pb.BeaconState, slot uint64) ([]byte, error) { - earliestSlot := state.Slot - params.BeaconConfig().SlotsPerHistoricalRoot + earliestSlot := uint64(0) + if state.Slot > params.BeaconConfig().SlotsPerHistoricalRoot { + earliestSlot = state.Slot - params.BeaconConfig().SlotsPerHistoricalRoot + } if slot < earliestSlot || slot >= state.Slot { - if earliestSlot < params.BeaconConfig().GenesisSlot { - earliestSlot = params.BeaconConfig().GenesisSlot - } return []byte{}, fmt.Errorf("slot %d is not within range %d to %d", - slot-params.BeaconConfig().GenesisSlot, - earliestSlot-params.BeaconConfig().GenesisSlot, - state.Slot-params.BeaconConfig().GenesisSlot, + slot, + earliestSlot, + state.Slot, ) } return state.LatestBlockRoots[slot%params.BeaconConfig().SlotsPerHistoricalRoot], nil diff --git a/beacon-chain/core/helpers/block_test.go b/beacon-chain/core/helpers/block_test.go index e3ba3f800d82..5fb7173fb15d 100644 --- a/beacon-chain/core/helpers/block_test.go +++ b/beacon-chain/core/helpers/block_test.go @@ -49,12 +49,12 @@ func TestBlockRootAtSlot_CorrectBlockRoot(t *testing.T) { }, } for _, tt := range tests { - s.Slot = tt.stateSlot + params.BeaconConfig().GenesisSlot - wantedSlot := tt.slot + params.BeaconConfig().GenesisSlot + s.Slot = tt.stateSlot + wantedSlot := tt.slot result, err := BlockRootAtSlot(s, wantedSlot) if err != nil { t.Fatalf("failed to get block root at slot %d: %v", - wantedSlot-params.BeaconConfig().GenesisSlot, err) + wantedSlot, err) } if !bytes.Equal(result, tt.expectedRoot) { t.Errorf( @@ -82,16 +82,16 @@ func TestBlockRootAtSlot_OutOfBounds(t *testing.T) { expectedErr string }{ { - slot: params.BeaconConfig().GenesisSlot + 1000, - stateSlot: params.BeaconConfig().GenesisSlot + 500, + slot: 1000, + stateSlot: 500, expectedErr: fmt.Sprintf("slot %d is not within range %d to %d", 1000, 0, 500), }, { - slot: params.BeaconConfig().GenesisSlot + 129, - stateSlot: params.BeaconConfig().GenesisSlot + 400, + slot: 129, + stateSlot: 400, expectedErr: "slot 129 is not within range 272 to 399", }, } diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index 107583c92523..224980c6d14f 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -230,9 +230,9 @@ func CommitteeAssignment( if wantedEpoch < prevEpoch || wantedEpoch > nextEpoch { return nil, 0, 0, false, fmt.Errorf( "epoch %d out of bounds: %d <= epoch <= %d", - wantedEpoch-params.BeaconConfig().GenesisEpoch, - prevEpoch-params.BeaconConfig().GenesisEpoch, - nextEpoch-params.BeaconConfig().GenesisEpoch, + wantedEpoch, + prevEpoch, + nextEpoch, ) } diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index 0c9b59d20edb..92c394e3f085 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -111,7 +111,7 @@ func TestComputeCommittee_OK(t *testing.T) { state := &pb.BeaconState{ ValidatorRegistry: validators, - Slot: params.BeaconConfig().GenesisSlot + 200, + Slot: 200, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -172,25 +172,25 @@ func TestAttestationParticipants_NoCommitteeCache(t *testing.T) { wanted []uint64 }{ { - attestationSlot: params.BeaconConfig().GenesisSlot + 2, - stateSlot: params.BeaconConfig().GenesisSlot + 5, + attestationSlot: 2, + stateSlot: 5, shard: 3, bitfield: []byte{0x03}, - wanted: []uint64{37, 100}, + wanted: []uint64{21, 126}, }, { - attestationSlot: params.BeaconConfig().GenesisSlot + 1, - stateSlot: params.BeaconConfig().GenesisSlot + 10, + attestationSlot: 1, + stateSlot: 10, shard: 2, bitfield: []byte{0x01}, - wanted: []uint64{2, 35}, + wanted: []uint64{2, 17}, }, { - attestationSlot: params.BeaconConfig().GenesisSlot + 10, - stateSlot: params.BeaconConfig().GenesisSlot + 10, + attestationSlot: 10, + stateSlot: 10, shard: 11, bitfield: []byte{0x03}, - wanted: []uint64{95, 101}, + wanted: []uint64{79, 112}, }, } @@ -198,7 +198,7 @@ func TestAttestationParticipants_NoCommitteeCache(t *testing.T) { state.Slot = tt.stateSlot attestationData.Slot = tt.attestationSlot attestationData.Shard = tt.shard - attestationData.TargetEpoch = params.BeaconConfig().GenesisEpoch + attestationData.TargetEpoch = 0 result, err := AttestingIndices(state, attestationData, tt.bitfield) if err != nil { @@ -288,7 +288,7 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) { } state := &pb.BeaconState{ ValidatorRegistry: validators, - Slot: params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: params.BeaconConfig().SlotsPerEpoch, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -302,28 +302,28 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) { }{ { index: 0, - slot: params.BeaconConfig().GenesisSlot + 151, + slot: 151, committee: []uint64{28, 0}, shard: 88, isProposer: true, }, { index: 105, - slot: params.BeaconConfig().GenesisSlot + 157, + slot: 157, committee: []uint64{105, 40}, shard: 94, isProposer: false, }, { index: 64, - slot: params.BeaconConfig().GenesisSlot + 163, + slot: 163, committee: []uint64{64, 27}, shard: 100, isProposer: false, }, { index: 11, - slot: params.BeaconConfig().GenesisSlot + 160, + slot: 160, committee: []uint64{11, 101}, shard: 97, isProposer: true, @@ -357,7 +357,7 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) { func TestCommitteeAssignment_CantFindValidator(t *testing.T) { state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -377,7 +377,7 @@ func TestAttestationParticipants_CommitteeCacheHit(t *testing.T) { slotOffset := uint64(1111) csInSlot := &cache.CommitteesInSlot{ - Slot: params.BeaconConfig().GenesisSlot + slotOffset, + Slot: slotOffset, Committees: []*cache.CommitteeInfo{ {Shard: 123, Committee: []uint64{55, 105}}, {Shard: 234, Committee: []uint64{11, 14}}, @@ -389,7 +389,7 @@ func TestAttestationParticipants_CommitteeCacheHit(t *testing.T) { attestationData := &pb.AttestationData{ Shard: 234, - Slot: params.BeaconConfig().GenesisSlot + uint64(slotOffset), + Slot: uint64(slotOffset), } result, err := AttestingIndices(&pb.BeaconState{}, attestationData, []byte{0x03}) if err != nil { @@ -418,7 +418,7 @@ func TestAttestationParticipants_CommitteeCacheMissSaved(t *testing.T) { slotOffset := uint64(10) state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + slotOffset, + Slot: slotOffset, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -426,7 +426,7 @@ func TestAttestationParticipants_CommitteeCacheMissSaved(t *testing.T) { attestationData := &pb.AttestationData{ Shard: 11, - Slot: params.BeaconConfig().GenesisSlot + slotOffset, + Slot: slotOffset, } result, err := AttestingIndices(state, attestationData, []byte{0x03}) if err != nil { @@ -443,7 +443,7 @@ func TestAttestationParticipants_CommitteeCacheMissSaved(t *testing.T) { } // Verify the committee for offset slot was cached. - fetchedCommittees, err := committeeCache.CommitteesInfoBySlot(params.BeaconConfig().GenesisSlot + slotOffset) + fetchedCommittees, err := committeeCache.CommitteesInfoBySlot(slotOffset) if err != nil { t.Fatal(err) } @@ -462,7 +462,7 @@ func TestCommitteeAssignment_CommitteeCacheHit(t *testing.T) { // TODO(#2307) unskip after CommitteeAssignments is updated slotOffset := uint64(1111) csInSlot := &cache.CommitteesInSlot{ - Slot: params.BeaconConfig().GenesisSlot + slotOffset, + Slot: slotOffset, Committees: []*cache.CommitteeInfo{ {Shard: 123, Committee: []uint64{55, 105}}, {Shard: 234, Committee: []uint64{11, 14}}, @@ -516,14 +516,14 @@ func TestCommitteeAssignment_CommitteeCacheMissSaved(t *testing.T) { slotOffset := uint64(10) state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + slotOffset, + Slot: slotOffset, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } committee, shard, _, isProposer, err := - CommitteeAssignment(state, params.BeaconConfig().GenesisSlot+slotOffset, 105, false) + CommitteeAssignment(state, slotOffset, 105, false) if err != nil { t.Fatal(err) } @@ -550,7 +550,7 @@ func TestCommitteeAssignment_CommitteeCacheMissSaved(t *testing.T) { } // Verify the committee for offset slot was cached. - fetchedCommittees, err := committeeCache.CommitteesInfoBySlot(params.BeaconConfig().GenesisSlot + slotOffset) + fetchedCommittees, err := committeeCache.CommitteesInfoBySlot(slotOffset) if err != nil { t.Fatal(err) } @@ -585,9 +585,9 @@ func TestShardDelta_Ok(t *testing.T) { } } state := &pb.BeaconState{ValidatorRegistry: validators} - if test.shardDelta != ShardDelta(state, params.BeaconConfig().GenesisEpoch) { + if test.shardDelta != ShardDelta(state, 0) { t.Errorf("wanted: %d, got: %d", - test.shardDelta, ShardDelta(state, params.BeaconConfig().GenesisEpoch)) + test.shardDelta, ShardDelta(state, 0)) } } } diff --git a/beacon-chain/core/helpers/slot_epoch.go b/beacon-chain/core/helpers/slot_epoch.go index 2c085858df38..5b25f44d3d4b 100644 --- a/beacon-chain/core/helpers/slot_epoch.go +++ b/beacon-chain/core/helpers/slot_epoch.go @@ -44,10 +44,10 @@ func CurrentEpoch(state *pb.BeaconState) uint64 { // return (current_epoch - 1) if current_epoch > GENESIS_EPOCH else current_epoch func PrevEpoch(state *pb.BeaconState) uint64 { currentEpoch := CurrentEpoch(state) - if currentEpoch > params.BeaconConfig().GenesisEpoch { + if currentEpoch > 0 { return currentEpoch - 1 } - return params.BeaconConfig().GenesisEpoch + return 0 } // NextEpoch returns the next epoch number calculated form diff --git a/beacon-chain/core/helpers/slot_epoch_test.go b/beacon-chain/core/helpers/slot_epoch_test.go index 9f72f3fbd39c..03767b4bb5cf 100644 --- a/beacon-chain/core/helpers/slot_epoch_test.go +++ b/beacon-chain/core/helpers/slot_epoch_test.go @@ -12,11 +12,11 @@ func TestSlotToEpoch_OK(t *testing.T) { slot uint64 epoch uint64 }{ - {slot: 0, epoch: 0 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 50, epoch: 0 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 64, epoch: 64 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 128, epoch: 128 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 200, epoch: 200 / params.BeaconConfig().SlotsPerEpoch}, + {slot: 0, epoch: 0}, + {slot: 50, epoch: 0}, + {slot: 64, epoch: 1}, + {slot: 128, epoch: 2}, + {slot: 200, epoch: 3}, } for _, tt := range tests { if tt.epoch != SlotToEpoch(tt.slot) { @@ -30,11 +30,11 @@ func TestCurrentEpoch_OK(t *testing.T) { slot uint64 epoch uint64 }{ - {slot: 0, epoch: 0 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 50, epoch: 0 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 64, epoch: 64 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 128, epoch: 128 / params.BeaconConfig().SlotsPerEpoch}, - {slot: 200, epoch: 200 / params.BeaconConfig().SlotsPerEpoch}, + {slot: 0, epoch: 0}, + {slot: 50, epoch: 0}, + {slot: 64, epoch: 1}, + {slot: 128, epoch: 2}, + {slot: 200, epoch: 3}, } for _, tt := range tests { state := &pb.BeaconState{Slot: tt.slot} @@ -49,9 +49,9 @@ func TestPrevEpoch_OK(t *testing.T) { slot uint64 epoch uint64 }{ - {slot: params.BeaconConfig().GenesisSlot, epoch: params.BeaconConfig().GenesisEpoch}, - {slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch + 1, epoch: params.BeaconConfig().GenesisEpoch}, - {slot: params.BeaconConfig().GenesisSlot + 2*params.BeaconConfig().SlotsPerEpoch, epoch: params.BeaconConfig().GenesisEpoch + 1}, + {slot: 0, epoch: 0}, + {slot: 0 + params.BeaconConfig().SlotsPerEpoch + 1, epoch: 0}, + {slot: 2 * params.BeaconConfig().SlotsPerEpoch, epoch: 1}, } for _, tt := range tests { state := &pb.BeaconState{Slot: tt.slot} diff --git a/beacon-chain/core/helpers/validators.go b/beacon-chain/core/helpers/validators.go index 282773a2aee1..f0f47d1970fd 100644 --- a/beacon-chain/core/helpers/validators.go +++ b/beacon-chain/core/helpers/validators.go @@ -134,7 +134,7 @@ func BeaconProposerIndex(state *pb.BeaconState) (uint64, error) { } if len(firstCommittee) == 0 { return 0, fmt.Errorf("empty first committee at slot %d", - state.Slot-params.BeaconConfig().GenesisSlot) + state.Slot) } // Use the generated seed to select proposer from the first committee diff --git a/beacon-chain/core/helpers/validators_test.go b/beacon-chain/core/helpers/validators_test.go index f78c96f12590..da99a6bcb888 100644 --- a/beacon-chain/core/helpers/validators_test.go +++ b/beacon-chain/core/helpers/validators_test.go @@ -42,7 +42,7 @@ func TestBeaconProposerIndex_OK(t *testing.T) { state := &pb.BeaconState{ ValidatorRegistry: validators, - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } @@ -52,24 +52,24 @@ func TestBeaconProposerIndex_OK(t *testing.T) { index uint64 }{ { - slot: params.BeaconConfig().GenesisSlot + 1, - index: 15324, + slot: 1, + index: 828, }, { - slot: params.BeaconConfig().GenesisSlot + 5, - index: 11774, + slot: 5, + index: 11151, }, { - slot: params.BeaconConfig().GenesisSlot + 19, - index: 2719, + slot: 19, + index: 3805, }, { - slot: params.BeaconConfig().GenesisSlot + 30, - index: 7418, + slot: 30, + index: 4507, }, { - slot: params.BeaconConfig().GenesisSlot + 43, - index: 15000, + slot: 43, + index: 9753, }, } @@ -92,7 +92,7 @@ func TestBeaconProposerIndex_OK(t *testing.T) { func TestBeaconProposerIndex_EmptyCommittee(t *testing.T) { beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), } diff --git a/beacon-chain/core/state/state.go b/beacon-chain/core/state/state.go index 76d617cabd77..abaa998cffc6 100644 --- a/beacon-chain/core/state/state.go +++ b/beacon-chain/core/state/state.go @@ -67,7 +67,7 @@ func GenesisBeaconState( latestCrosslinks := make([]*pb.Crosslink, params.BeaconConfig().ShardCount) for i := 0; i < len(latestCrosslinks); i++ { latestCrosslinks[i] = &pb.Crosslink{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: zeroHash, } } @@ -101,36 +101,36 @@ func GenesisBeaconState( state := &pb.BeaconState{ // Misc fields. - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, GenesisTime: genesisTime, Fork: &pb.Fork{ PreviousVersion: params.BeaconConfig().GenesisForkVersion, CurrentVersion: params.BeaconConfig().GenesisForkVersion, - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, }, // Validator registry fields. ValidatorRegistry: validatorRegistry, Balances: latestBalances, - ValidatorRegistryUpdateEpoch: params.BeaconConfig().GenesisEpoch, + ValidatorRegistryUpdateEpoch: 0, // Randomness and committees. LatestRandaoMixes: latestRandaoMixes, PreviousShufflingStartShard: params.BeaconConfig().GenesisStartShard, CurrentShufflingStartShard: params.BeaconConfig().GenesisStartShard, - PreviousShufflingEpoch: params.BeaconConfig().GenesisEpoch, - CurrentShufflingEpoch: params.BeaconConfig().GenesisEpoch, + PreviousShufflingEpoch: 0, + CurrentShufflingEpoch: 0, PreviousShufflingSeedHash32: zeroHash, CurrentShufflingSeedHash32: zeroHash, // Finality. - PreviousJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + PreviousJustifiedEpoch: 0, PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:], - CurrentJustifiedEpoch: params.BeaconConfig().GenesisEpoch, + CurrentJustifiedEpoch: 0, CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:], JustificationBitfield: 0, - FinalizedEpoch: params.BeaconConfig().GenesisEpoch, + FinalizedEpoch: 0, FinalizedRoot: params.BeaconConfig().ZeroHash[:], // Recent state. @@ -181,7 +181,7 @@ func GenesisBeaconState( } } } - activeValidators := helpers.ActiveValidatorIndices(state, params.BeaconConfig().GenesisEpoch) + activeValidators := helpers.ActiveValidatorIndices(state, 0) indicesBytes := []byte{} for _, val := range activeValidators { buf := make([]byte, 8) diff --git a/beacon-chain/core/state/state_test.go b/beacon-chain/core/state/state_test.go index 0bfdfce555b9..448a260b1709 100644 --- a/beacon-chain/core/state/state_test.go +++ b/beacon-chain/core/state/state_test.go @@ -27,10 +27,7 @@ func TestGenesisBeaconState_OK(t *testing.T) { t.Errorf("SlotsPerEpoch should be 64 for these tests to pass") } - if params.BeaconConfig().GenesisSlot != 1<<63 { - t.Error("GenesisSlot should be 2^63 for these tests to pass") - } - genesisEpochNumber := params.BeaconConfig().GenesisEpoch + genesisEpochNumber := uint64(0) if !bytes.Equal(params.BeaconConfig().GenesisForkVersion, []byte{0, 0, 0, 0}) { t.Error("GenesisSlot( should be {0,0,0,0} for these tests to pass") @@ -100,7 +97,7 @@ func TestGenesisBeaconState_OK(t *testing.T) { } // Misc fields checks. - if newState.Slot != params.BeaconConfig().GenesisSlot { + if newState.Slot != 0 { t.Error("Slot was not correctly initialized") } if newState.GenesisTime != genesisTime { @@ -115,7 +112,7 @@ func TestGenesisBeaconState_OK(t *testing.T) { } // Validator registry fields checks. - if newState.ValidatorRegistryUpdateEpoch != params.BeaconConfig().GenesisEpoch { + if newState.ValidatorRegistryUpdateEpoch != 0 { t.Error("ValidatorRegistryUpdateSlot was not correctly initialized") } if len(newState.ValidatorRegistry) != depositsForChainStart { @@ -157,7 +154,7 @@ func TestGenesisBeaconState_OK(t *testing.T) { if !reflect.DeepEqual(newState.BatchedBlockRootHash32S, [][]byte{}) { t.Error("BatchedBlockRootHash32S was not correctly initialized") } - activeValidators := helpers.ActiveValidatorIndices(newState, params.BeaconConfig().GenesisEpoch) + activeValidators := helpers.ActiveValidatorIndices(newState, 0) indicesBytes := []byte{} for _, val := range activeValidators { buf := make([]byte, 8) diff --git a/beacon-chain/core/state/transition.go b/beacon-chain/core/state/transition.go index 47ded0620fcb..5f03499c097a 100644 --- a/beacon-chain/core/state/transition.go +++ b/beacon-chain/core/state/transition.go @@ -12,7 +12,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -122,8 +121,8 @@ func ProcessBlock( if block.Slot != state.Slot { return nil, fmt.Errorf( "block.slot != state.slot, block.slot = %d, state.slot = %d", - block.Slot-params.BeaconConfig().GenesisSlot, - state.Slot-params.BeaconConfig().GenesisSlot, + block.Slot, + state.Slot, ) } diff --git a/beacon-chain/core/state/transition_test.go b/beacon-chain/core/state/transition_test.go index f89764cf0fa0..8604774884cf 100644 --- a/beacon-chain/core/state/transition_test.go +++ b/beacon-chain/core/state/transition_test.go @@ -51,7 +51,7 @@ func createRandaoReveal(t *testing.T, beaconState *pb.BeaconState, privKeys []*b if err != nil { t.Fatal(err) } - epoch := helpers.SlotToEpoch(params.BeaconConfig().GenesisSlot) + epoch := uint64(0) buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, epoch) domain := helpers.DomainVersion(beaconState, epoch, params.BeaconConfig().DomainRandao) @@ -62,10 +62,10 @@ func createRandaoReveal(t *testing.T, beaconState *pb.BeaconState, privKeys []*b func TestProcessBlock_IncorrectSlot(t *testing.T) { beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, } want := fmt.Sprintf( "block.slot != state.slot, block.slot = %d, state.slot = %d", @@ -89,7 +89,7 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) { } randaoReveal := createRandaoReveal(t, beaconState, privKeys) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Eth1Data: &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -130,7 +130,7 @@ func TestProcessBlock_IncorrectAttesterSlashing(t *testing.T) { } randaoReveal := createRandaoReveal(t, beaconState, privKeys) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Eth1Data: &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -196,7 +196,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) { } randaoReveal := createRandaoReveal(t, beaconState, privKeys) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, Eth1Data: &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -266,12 +266,12 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { CrosslinkDataRootHash32: []byte{1}, }, } - beaconState.Slot = params.BeaconConfig().GenesisSlot + 10 + beaconState.Slot = 10 blockAtt := &pb.Attestation{ Data: &pb.AttestationData{ Shard: 0, - Slot: params.BeaconConfig().GenesisSlot, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 0, + JustifiedEpoch: 0, JustifiedBlockRootHash32: params.BeaconConfig().ZeroHash[:], LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}}, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], @@ -286,7 +286,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { } randaoReveal := createRandaoReveal(t, beaconState, privKeys) block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 10, + Slot: 10, Eth1Data: &pb.Eth1Data{ DepositRoot: []byte{2}, BlockRoot: []byte{3}, @@ -358,12 +358,12 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) { }, } slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch - beaconState.Slot = params.BeaconConfig().GenesisSlot + (params.BeaconConfig().PersistentCommitteePeriod * slotsPerEpoch) + beaconState.Slot = (params.BeaconConfig().PersistentCommitteePeriod * slotsPerEpoch) blockAtt := &pb.Attestation{ Data: &pb.AttestationData{ Shard: 0, Slot: beaconState.Slot - params.BeaconConfig().MinAttestationInclusionDelay, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch, + JustifiedEpoch: 0, JustifiedBlockRootHash32: params.BeaconConfig().ZeroHash[:], LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}}, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], @@ -375,7 +375,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) { exits := []*pb.VoluntaryExit{ { ValidatorIndex: 10, - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, }, } randaoReveal := createRandaoReveal(t, beaconState, privKeys) @@ -417,12 +417,12 @@ func TestProcessEpoch_PassesProcessingConditions(t *testing.T) { for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch*2; i++ { attestations = append(attestations, &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: i + params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: i + params.BeaconConfig().SlotsPerEpoch, Shard: 2, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 1, + JustifiedEpoch: 1, JustifiedBlockRootHash32: []byte{0}, }, - InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1 + params.BeaconConfig().GenesisSlot, + InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1, }) } @@ -438,7 +438,7 @@ func TestProcessEpoch_PassesProcessingConditions(t *testing.T) { crosslinkRecord := make([]*pb.Crosslink, params.BeaconConfig().ShardCount) newState := &pb.BeaconState{ - Slot: params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot + 1, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, LatestAttestations: attestations, Balances: validatorBalances, ValidatorRegistry: validatorRegistry, @@ -479,12 +479,12 @@ func TestProcessEpoch_PreventsRegistryUpdateOnNilBlock(t *testing.T) { for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch*2; i++ { attestations = append(attestations, &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: i + params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: i + params.BeaconConfig().SlotsPerEpoch, Shard: 2, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 1, + JustifiedEpoch: 1, JustifiedBlockRootHash32: []byte{0}, }, - InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1 + params.BeaconConfig().GenesisSlot, + InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1, }) } @@ -500,7 +500,7 @@ func TestProcessEpoch_PreventsRegistryUpdateOnNilBlock(t *testing.T) { crosslinkRecord := make([]*pb.Crosslink, 64) newState := &pb.BeaconState{ - Slot: params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot + 1, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, LatestAttestations: attestations, Balances: validatorBalances, ValidatorRegistry: validatorRegistry, @@ -511,18 +511,18 @@ func TestProcessEpoch_PreventsRegistryUpdateOnNilBlock(t *testing.T) { params.BeaconConfig().LatestActiveIndexRootsLength), LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength), - ValidatorRegistryUpdateEpoch: params.BeaconConfig().GenesisEpoch, - FinalizedEpoch: params.BeaconConfig().GenesisEpoch + 1, + ValidatorRegistryUpdateEpoch: 0, + FinalizedEpoch: 1, } newState, err := state.ProcessEpoch(context.Background(), newState, nil, state.DefaultConfig()) if err != nil { t.Errorf("Expected epoch transition to pass processing conditions: %v", err) } - if newState.ValidatorRegistryUpdateEpoch != params.BeaconConfig().GenesisEpoch { + if newState.ValidatorRegistryUpdateEpoch != 0 { t.Errorf( "Expected registry to not have been updated, received update epoch: %v", - newState.ValidatorRegistryUpdateEpoch-params.BeaconConfig().GenesisEpoch, + newState.ValidatorRegistryUpdateEpoch, ) } featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{ @@ -550,13 +550,13 @@ func TestProcessEpoch_InactiveConditions(t *testing.T) { for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch*2; i++ { attestations = append(attestations, &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: i + params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: i + params.BeaconConfig().SlotsPerEpoch, Shard: 1, - JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 1, + JustifiedEpoch: 1, JustifiedBlockRootHash32: []byte{0}, }, AggregationBitfield: []byte{}, - InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1 + params.BeaconConfig().GenesisSlot, + InclusionSlot: i + params.BeaconConfig().SlotsPerEpoch + 1, }) } @@ -573,7 +573,7 @@ func TestProcessEpoch_InactiveConditions(t *testing.T) { crosslinkRecord := make([]*pb.Crosslink, params.BeaconConfig().ShardCount) newState := &pb.BeaconState{ - Slot: params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot + 1, + Slot: params.BeaconConfig().SlotsPerEpoch + 1, LatestAttestations: attestations, Balances: validatorBalances, ValidatorRegistry: validatorRegistry, @@ -596,16 +596,16 @@ func TestProcessEpoch_CantGetBoundaryAttestation(t *testing.T) { t.Skip() // TODO(#2307) unskip after ProcessCrosslinks is finished newState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, LatestAttestations: []*pb.PendingAttestation{ - {Data: &pb.AttestationData{Slot: params.BeaconConfig().GenesisSlot + 100}}, + {Data: &pb.AttestationData{Slot: 100}}, }} want := fmt.Sprintf( "slot %d is not within expected range of %d to %d", - newState.Slot-params.BeaconConfig().GenesisSlot, + newState.Slot, 0, - newState.Slot-params.BeaconConfig().GenesisSlot, + newState.Slot, ) if _, err := state.ProcessEpoch(context.Background(), newState, &pb.BeaconBlock{}, state.DefaultConfig()); !strings.Contains(err.Error(), want) { t.Errorf("Expected: %s, received: %v", want, err) @@ -624,7 +624,7 @@ func TestProcessEpoch_CantGetCurrentValidatorIndices(t *testing.T) { for i := uint64(0); i < params.BeaconConfig().SlotsPerEpoch*2; i++ { attestations = append(attestations, &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, Shard: 1, JustifiedBlockRootHash32: make([]byte, 32), }, @@ -633,7 +633,7 @@ func TestProcessEpoch_CantGetCurrentValidatorIndices(t *testing.T) { } newState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, LatestAttestations: attestations, LatestBlockRoots: latestBlockRoots, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index d307e89ed0d4..0c61e617bbc1 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -162,8 +162,8 @@ func ProcessDeposit( func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.BeaconState, error) { validator := state.ValidatorRegistry[idx] if genesis { - validator.ActivationEligibilityEpoch = params.BeaconConfig().GenesisEpoch - validator.ActivationEpoch = params.BeaconConfig().GenesisEpoch + validator.ActivationEligibilityEpoch = 0 + validator.ActivationEpoch = 0 } else { validator.ActivationEpoch = helpers.DelayedActivationExitEpoch(helpers.CurrentEpoch(state)) } @@ -172,7 +172,7 @@ func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.Bea log.WithFields(logrus.Fields{ "index": idx, - "activationEpoch": validator.ActivationEpoch - params.BeaconConfig().GenesisEpoch, + "activationEpoch": validator.ActivationEpoch, }).Info("Validator activated") return state, nil diff --git a/beacon-chain/core/validators/validator_test.go b/beacon-chain/core/validators/validator_test.go index 88d9a3a70c8c..202d5a20c827 100644 --- a/beacon-chain/core/validators/validator_test.go +++ b/beacon-chain/core/validators/validator_test.go @@ -60,7 +60,7 @@ func TestBoundaryAttesterIndices_OK(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -69,15 +69,15 @@ func TestBoundaryAttesterIndices_OK(t *testing.T) { boundaryAttestations := []*pb.PendingAttestation{ { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 0, + TargetEpoch: 0, Shard: 1, }, AggregationBitfield: []byte{0x03}}, // returns indices 242 { Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 0, + TargetEpoch: 0, Shard: 1, }, AggregationBitfield: []byte{0x03}}, // returns indices 237,224,2 @@ -88,9 +88,9 @@ func TestBoundaryAttesterIndices_OK(t *testing.T) { t.Fatalf("Failed to run BoundaryAttesterIndices: %v", err) } - if !reflect.DeepEqual(attesterIndices, []uint64{25, 87}) { + if !reflect.DeepEqual(attesterIndices, []uint64{16, 113}) { t.Errorf("Incorrect boundary attester indices. Wanted: %v, got: %v", - []uint64{25, 87}, attesterIndices) + []uint64{16, 113}, attesterIndices) } } @@ -107,7 +107,7 @@ func TestAttestingValidatorIndices_OK(t *testing.T) { } state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength), LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength), @@ -115,8 +115,8 @@ func TestAttestingValidatorIndices_OK(t *testing.T) { prevAttestation := &pb.PendingAttestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 3, - TargetEpoch: params.BeaconConfig().GenesisEpoch, + Slot: 3, + TargetEpoch: 0, Shard: 6, CrosslinkDataRoot: []byte{'B'}, }, @@ -133,9 +133,9 @@ func TestAttestingValidatorIndices_OK(t *testing.T) { t.Fatalf("Could not execute AttestingValidatorIndices: %v", err) } - if !reflect.DeepEqual(indices, []uint64{33, 94}) { + if !reflect.DeepEqual(indices, []uint64{13, 51}) { t.Errorf("Could not get incorrect validator indices. Wanted: %v, got: %v", - []uint64{33, 94}, indices) + []uint64{13, 51}, indices) } } @@ -388,11 +388,11 @@ func TestActivateValidatorGenesis_OK(t *testing.T) { if err != nil { t.Fatalf("could not execute activateValidator:%v", err) } - if newState.ValidatorRegistry[0].ActivationEpoch != params.BeaconConfig().GenesisEpoch { + if newState.ValidatorRegistry[0].ActivationEpoch != 0 { t.Errorf("Wanted activation epoch = genesis epoch, got %d", newState.ValidatorRegistry[0].ActivationEpoch) } - if newState.ValidatorRegistry[0].ActivationEligibilityEpoch != params.BeaconConfig().GenesisEpoch { + if newState.ValidatorRegistry[0].ActivationEligibilityEpoch != 0 { t.Errorf("Wanted activation eligibility epoch = genesis epoch, got %d", newState.ValidatorRegistry[0].ActivationEligibilityEpoch) } @@ -489,7 +489,7 @@ func TestExitValidator_OK(t *testing.T) { func TestExitValidator_AlreadyExited(t *testing.T) { state := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisEpoch + 1000, + Slot: 1000, ValidatorRegistry: []*pb.Validator{ {ExitEpoch: params.BeaconConfig().ActivationExitDelay}, }, @@ -551,7 +551,7 @@ func TestInitializeValidatoreStore(t *testing.T) { for i := 0; i < validatorsLimit; i++ { registry = append(registry, &pb.Validator{ Pubkey: []byte(strconv.Itoa(i)), - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, }) indices = append(indices, uint64(i)) @@ -559,7 +559,7 @@ func TestInitializeValidatoreStore(t *testing.T) { bState := &pb.BeaconState{ ValidatorRegistry: registry, - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, } if _, ok := VStore.activatedValidators[helpers.CurrentEpoch(bState)]; ok { diff --git a/beacon-chain/db/block.go b/beacon-chain/db/block.go index 58c245f86f06..6442013ad25a 100644 --- a/beacon-chain/db/block.go +++ b/beacon-chain/db/block.go @@ -12,7 +12,6 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/params" "go.opencensus.io/trace" ) @@ -275,7 +274,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *pb.BeaconBlock, func (db *BeaconDB) CanonicalBlockBySlot(ctx context.Context, slot uint64) (*pb.BeaconBlock, error) { _, span := trace.StartSpan(ctx, "BeaconDB.CanonicalBlockBySlot") defer span.End() - span.AddAttributes(trace.Int64Attribute("slot", int64(slot-params.BeaconConfig().GenesisSlot))) + span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) var block *pb.BeaconBlock slotEnc := encodeSlotNumber(slot) @@ -301,7 +300,7 @@ func (db *BeaconDB) BlocksBySlot(ctx context.Context, slot uint64) ([]*pb.Beacon } _, span := trace.StartSpan(ctx, "BeaconDB.BlocksBySlot") defer span.End() - span.AddAttributes(trace.Int64Attribute("slot", int64(slot-params.BeaconConfig().GenesisSlot))) + span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) blocks := []*pb.BeaconBlock{} slotEnc := encodeSlotNumber(slot) diff --git a/beacon-chain/db/block_test.go b/beacon-chain/db/block_test.go index 9e0b6d2bb468..c4d0bc1fe09b 100644 --- a/beacon-chain/db/block_test.go +++ b/beacon-chain/db/block_test.go @@ -86,7 +86,7 @@ func TestDeleteBlock_OK(t *testing.T) { db := setupDB(t) defer teardownDB(t, db) - block := &pb.BeaconBlock{Slot: params.BeaconConfig().GenesisSlot} + block := &pb.BeaconBlock{Slot: 0} h, _ := hashutil.HashBeaconBlock(block) err := db.SaveBlock(block) @@ -129,7 +129,7 @@ func TestBlocksBySlot_MultipleBlocks(t *testing.T) { defer teardownDB(t, db) ctx := context.Background() - slotNum := params.BeaconConfig().GenesisSlot + 3 + slotNum := uint64(3) b1 := &pb.BeaconBlock{ Slot: slotNum, RandaoReveal: []byte("A"), @@ -152,7 +152,7 @@ func TestBlocksBySlot_MultipleBlocks(t *testing.T) { t.Fatal(err) } - blocks, _ := db.BlocksBySlot(ctx, params.BeaconConfig().GenesisSlot+3) + blocks, _ := db.BlocksBySlot(ctx, 3) if len(blocks) != 3 { t.Errorf("Wanted %d blocks, received %d", 3, len(blocks)) } @@ -207,7 +207,7 @@ func TestUpdateChainHead_OK(t *testing.T) { } block2 := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, ParentBlockRoot: bHash[:], } b2Hash, err := hashutil.HashBeaconBlock(block2) @@ -221,7 +221,7 @@ func TestUpdateChainHead_OK(t *testing.T) { t.Fatalf("failed to record the new head of the main chain: %v", err) } - b2Prime, err := db.CanonicalBlockBySlot(ctx, params.BeaconConfig().GenesisSlot+1) + b2Prime, err := db.CanonicalBlockBySlot(ctx, 1) if err != nil { t.Fatalf("failed to retrieve slot 1: %v", err) } diff --git a/beacon-chain/db/state.go b/beacon-chain/db/state.go index b329594d0aed..1969b5a41a73 100644 --- a/beacon-chain/db/state.go +++ b/beacon-chain/db/state.go @@ -7,8 +7,6 @@ import ( "errors" "fmt" - "github.com/prysmaticlabs/prysm/shared/params" - "github.com/boltdb/bolt" "github.com/gogo/protobuf/proto" "github.com/prometheus/client_golang/prometheus" @@ -47,7 +45,7 @@ func (db *BeaconDB) InitializeState(ctx context.Context, genesisTime uint64, dep blockRoot, _ := hashutil.HashBeaconBlock(genesisBlock) // #nosec G104 blockEnc, _ := proto.Marshal(genesisBlock) - zeroBinary := encodeSlotNumberRoot(params.BeaconConfig().GenesisSlot, blockRoot) + zeroBinary := encodeSlotNumberRoot(0, blockRoot) db.serializedState = stateEnc db.stateHash = stateHash @@ -291,7 +289,7 @@ func (db *BeaconDB) HistoricalStateFromSlot(ctx context.Context, slot uint64, bl } _, span := trace.StartSpan(ctx, "BeaconDB.HistoricalStateFromSlot") defer span.End() - span.AddAttributes(trace.Int64Attribute("slotSinceGenesis", int64(slot))) + span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) var beaconState *pb.BeaconState err := db.view(func(tx *bolt.Tx) error { var err error @@ -322,7 +320,7 @@ func (db *BeaconDB) HistoricalStateFromSlot(ctx context.Context, slot uint64, bl slotBinary := k[:8] slotNumber := decodeToSlotNumber(slotBinary) // find the state with slot closest to the requested slot - if slotNumber > highestStateSlot && slotNumber <= slot { + if slotNumber >= highestStateSlot && slotNumber <= slot { stateExists = true highestStateSlot = slotNumber histStateKey = v diff --git a/beacon-chain/db/state_metrics.go b/beacon-chain/db/state_metrics.go index cc80597968b6..faadd958c248 100644 --- a/beacon-chain/db/state_metrics.go +++ b/beacon-chain/db/state_metrics.go @@ -58,8 +58,6 @@ var ( ) func reportStateMetrics(state *pb.BeaconState) { - s := params.BeaconConfig().GenesisSlot - e := params.BeaconConfig().GenesisEpoch currentEpoch := state.Slot / params.BeaconConfig().SlotsPerEpoch // Validator balances for i, bal := range state.Balances { @@ -73,15 +71,15 @@ func reportStateMetrics(state *pb.BeaconState) { // Track individual Validator's activation epochs validatorActivatedGauge.WithLabelValues( strconv.Itoa(i), //Validator index - ).Set(float64(v.ActivationEpoch - e)) + ).Set(float64(v.ActivationEpoch)) // Track individual Validator's exited epochs validatorExitedGauge.WithLabelValues( strconv.Itoa(i), //Validator index - ).Set(float64(v.ExitEpoch - e)) + ).Set(float64(v.ExitEpoch)) // Track individual Validator's slashed epochs validatorSlashedGauge.WithLabelValues( strconv.Itoa(i), //Validator index - ).Set(float64(v.SlashedEpoch - e)) + ).Set(float64(v.SlashedEpoch)) // Total number of active validators if v.ActivationEpoch <= currentEpoch && currentEpoch < v.ExitEpoch { active++ @@ -90,11 +88,11 @@ func reportStateMetrics(state *pb.BeaconState) { activeValidatorsGauge.Set(active) // Slot number - lastSlotGauge.Set(float64(state.Slot - s)) + lastSlotGauge.Set(float64(state.Slot)) // Last justified slot - lastJustifiedEpochGauge.Set(float64(state.CurrentJustifiedEpoch - e)) + lastJustifiedEpochGauge.Set(float64(state.CurrentJustifiedEpoch)) // Last previous justified slot - lastPrevJustifiedEpochGauge.Set(float64(state.PreviousJustifiedEpoch - e)) + lastPrevJustifiedEpochGauge.Set(float64(state.PreviousJustifiedEpoch)) // Last finalized slot - lastFinalizedEpochGauge.Set(float64(state.FinalizedEpoch - e)) + lastFinalizedEpochGauge.Set(float64(state.FinalizedEpoch)) } diff --git a/beacon-chain/db/state_test.go b/beacon-chain/db/state_test.go index d7c5461d6b97..c8a66ecdda26 100644 --- a/beacon-chain/db/state_test.go +++ b/beacon-chain/db/state_test.go @@ -58,7 +58,7 @@ func TestInitializeState_OK(t *testing.T) { if err != nil { t.Fatalf("Failed to get chain head: %v", err) } - if b.GetSlot() != params.BeaconConfig().GenesisSlot { + if b.GetSlot() != 0 { t.Fatalf("Expected block height to equal 1. Got %d", b.GetSlot()) } @@ -141,7 +141,7 @@ func BenchmarkState_ReadingFromCache(b *testing.B) { savedState := &pb.BeaconState{} savedState.Unmarshal(db.serializedState) - if savedState.Slot != params.BeaconConfig().GenesisSlot+1 { + if savedState.Slot != 1 { b.Fatal("cache should be prepared on state after saving to DB") } @@ -287,9 +287,6 @@ func TestHistoricalState_Pruning(t *testing.T) { ctx := context.Background() epochSize := params.BeaconConfig().SlotsPerEpoch - slotGen := func(slot uint64) uint64 { - return params.BeaconConfig().GenesisSlot + slot - } tests := []struct { histState1 *pb.BeaconState @@ -297,50 +294,50 @@ func TestHistoricalState_Pruning(t *testing.T) { }{ { histState1: &pb.BeaconState{ - Slot: slotGen(0 * epochSize), + Slot: 2 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(1 * epochSize), + Slot: 3 * epochSize, }, }, { histState1: &pb.BeaconState{ - Slot: slotGen(1 * epochSize), + Slot: 1 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(4 * epochSize), + Slot: 4 * epochSize, }, }, { histState1: &pb.BeaconState{ - Slot: slotGen(2 * epochSize), + Slot: 2 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(5 * epochSize), + Slot: 5 * epochSize, }, }, { histState1: &pb.BeaconState{ - Slot: slotGen(6 * epochSize), + Slot: 6 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(14 * epochSize), + Slot: 14 * epochSize, }, }, { histState1: &pb.BeaconState{ - Slot: slotGen(12 * epochSize), + Slot: 12 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(103 * epochSize), + Slot: 103 * epochSize, }, }, { histState1: &pb.BeaconState{ - Slot: slotGen(100 * epochSize), + Slot: 100 * epochSize, }, histState2: &pb.BeaconState{ - Slot: slotGen(600 * epochSize), + Slot: 600 * epochSize, }, }, } @@ -360,26 +357,26 @@ func TestHistoricalState_Pruning(t *testing.T) { } // Save a dummy genesis state so that db doesnt return an error. - if err := db.SaveHistoricalState(context.Background(), &pb.BeaconState{Slot: slotGen(0), FinalizedEpoch: 1}, root); err != nil { + if err := db.SaveHistoricalState(context.Background(), &pb.BeaconState{Slot: 0, FinalizedEpoch: 0}, root); err != nil { t.Fatalf("could not save historical state: %v", err) } retState, err := db.HistoricalStateFromSlot(ctx, tt.histState1.Slot, root) if err != nil { - t.Fatalf("Unable to retrieve state %v", err) + t.Errorf("Unable to retrieve state %v", err) } if proto.Equal(tt.histState1, retState) { - t.Errorf("Saved and retrieved states are equal when they supposed to be different %d", tt.histState1.Slot-params.BeaconConfig().GenesisSlot) + t.Errorf("Saved and retrieved states are equal when they supposed to be different %d", tt.histState1.Slot) } retState, err = db.HistoricalStateFromSlot(ctx, tt.histState2.Slot, root) if err != nil { - t.Fatalf("Unable to retrieve state %v", err) + t.Errorf("Unable to retrieve state %v", err) } if !proto.Equal(tt.histState2, retState) { - t.Errorf("Saved and retrieved states are not equal when they supposed to be for slot %d", tt.histState2.Slot-params.BeaconConfig().GenesisSlot) + t.Errorf("Saved and retrieved states are not equal when they supposed to be for slot %d", tt.histState2.Slot) } } diff --git a/beacon-chain/operations/service.go b/beacon-chain/operations/service.go index d9bc7764a85e..b34b71c7390b 100644 --- a/beacon-chain/operations/service.go +++ b/beacon-chain/operations/service.go @@ -286,7 +286,7 @@ func (s *Service) removePendingAttestations(attestations []*pb.Attestation) erro if err := s.beaconDB.DeleteAttestation(attestation); err != nil { return err } - log.WithField("slot", attestation.Data.Slot-params.BeaconConfig().GenesisSlot).Debug("Attestation removed") + log.WithField("slot", attestation.Data.Slot).Debug("Attestation removed") } } return nil diff --git a/beacon-chain/operations/service_test.go b/beacon-chain/operations/service_test.go index 1e9fd0723767..9877da27e47b 100644 --- a/beacon-chain/operations/service_test.go +++ b/beacon-chain/operations/service_test.go @@ -127,7 +127,7 @@ func TestRetrieveAttestations_OK(t *testing.T) { for i := 0; i < len(origAttestations); i++ { origAttestations[i] = &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, } @@ -136,10 +136,10 @@ func TestRetrieveAttestations_OK(t *testing.T) { } } if err := beaconDB.SaveState(context.Background(), &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 64, - LatestBlock: &pb.BeaconBlock{Slot: params.BeaconConfig().GenesisSlot}, + Slot: 64, + LatestBlock: &pb.BeaconBlock{Slot: 0}, LatestCrosslinks: []*pb.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:]}}}); err != nil { t.Fatal(err) } @@ -164,7 +164,7 @@ func TestRetrieveAttestations_PruneInvalidAtts(t *testing.T) { for i := 0; i < len(origAttestations); i++ { origAttestations[i] = &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, } @@ -175,9 +175,9 @@ func TestRetrieveAttestations_PruneInvalidAtts(t *testing.T) { // At slot 200 only attestations up to from slot 137 to 139 are valid attestations. if err := beaconDB.SaveState(context.Background(), &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 200, + Slot: 200, LatestCrosslinks: []*pb.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch + 2, + Epoch: 2, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:]}}}); err != nil { t.Fatal(err) } @@ -208,7 +208,7 @@ func TestRemoveProcessedAttestations_Ok(t *testing.T) { for i := 0; i < len(attestations); i++ { attestations[i] = &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, } @@ -217,9 +217,9 @@ func TestRemoveProcessedAttestations_Ok(t *testing.T) { } } if err := db.SaveState(context.Background(), &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 15, + Slot: 15, LatestCrosslinks: []*pb.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:]}}}); err != nil { t.Fatal(err) } @@ -253,7 +253,7 @@ func TestCleanUpAttestations_OlderThanOneEpoch(t *testing.T) { for i := 0; i < len(attestations); i++ { attestations[i] = &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), Shard: uint64(i), }, } @@ -263,7 +263,7 @@ func TestCleanUpAttestations_OlderThanOneEpoch(t *testing.T) { } // Assume current slot is 99. All the attestations before (99 - 64) should get removed. - if err := s.removeEpochOldAttestations(params.BeaconConfig().GenesisSlot + slot); err != nil { + if err := s.removeEpochOldAttestations(slot); err != nil { t.Fatalf("Could not remove old attestations: %v", err) } attestations, err := s.beaconDB.Attestations() @@ -287,7 +287,7 @@ func TestReceiveBlkRemoveOps_Ok(t *testing.T) { for i := 0; i < len(attestations); i++ { attestations[i] = &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, } @@ -297,9 +297,9 @@ func TestReceiveBlkRemoveOps_Ok(t *testing.T) { } if err := db.SaveState(context.Background(), &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 15, + Slot: 15, LatestCrosslinks: []*pb.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch, + Epoch: 0, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:]}}}); err != nil { t.Fatal(err) } diff --git a/beacon-chain/rpc/attester_server.go b/beacon-chain/rpc/attester_server.go index ff9480ad3488..2ea6bfa24cd9 100644 --- a/beacon-chain/rpc/attester_server.go +++ b/beacon-chain/rpc/attester_server.go @@ -140,7 +140,7 @@ func (as *AttesterServer) AttestationDataAtSlot(ctx context.Context, req *pb.Att justifiedBlockRoot := headState.CurrentJustifiedRoot // If an attester has to attest for genesis block. - if headState.Slot == params.BeaconConfig().GenesisSlot { + if headState.Slot == 0 { epochBoundaryRoot = params.BeaconConfig().ZeroHash[:] justifiedBlockRoot = params.BeaconConfig().ZeroHash[:] } diff --git a/beacon-chain/rpc/attester_server_test.go b/beacon-chain/rpc/attester_server_test.go index 267741fa99a4..bd0dd459c449 100644 --- a/beacon-chain/rpc/attester_server_test.go +++ b/beacon-chain/rpc/attester_server_test.go @@ -60,13 +60,13 @@ func TestAttestationDataAtSlot_OK(t *testing.T) { ctx := context.Background() block := &pbp2p.BeaconBlock{ - Slot: 1 + params.BeaconConfig().GenesisSlot, + Slot: 1, } epochBoundaryBlock := &pbp2p.BeaconBlock{ - Slot: 1*params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: 1 * params.BeaconConfig().SlotsPerEpoch, } justifiedBlock := &pbp2p.BeaconBlock{ - Slot: 2*params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot, + Slot: 2 * params.BeaconConfig().SlotsPerEpoch, } blockRoot, err := hashutil.HashBeaconBlock(block) if err != nil { @@ -82,8 +82,8 @@ func TestAttestationDataAtSlot_OK(t *testing.T) { } beaconState := &pbp2p.BeaconState{ - Slot: 3*params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().GenesisSlot + 1, - CurrentJustifiedEpoch: 2 + params.BeaconConfig().GenesisEpoch, + Slot: 3*params.BeaconConfig().SlotsPerEpoch + 1, + CurrentJustifiedEpoch: 2 + 0, LatestBlockRoots: make([][]byte, params.BeaconConfig().LatestBlockRootsLength), LatestCrosslinks: []*pbp2p.Crosslink{ { @@ -128,7 +128,7 @@ func TestAttestationDataAtSlot_OK(t *testing.T) { expectedInfo := &pb.AttestationDataResponse{ HeadSlot: beaconState.Slot, BeaconBlockRootHash32: blockRoot[:], - JustifiedEpoch: 2 + params.BeaconConfig().GenesisEpoch, + JustifiedEpoch: 2 + 0, JustifiedBlockRootHash32: justifiedBlockRoot[:], LatestCrosslink: &pbp2p.Crosslink{ CrosslinkDataRootHash32: []byte("A"), @@ -158,13 +158,13 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) { params.OverrideBeaconConfig(cfg) block := &pbp2p.BeaconBlock{ - Slot: 10000 + params.BeaconConfig().GenesisSlot, + Slot: 10000, } epochBoundaryBlock := &pbp2p.BeaconBlock{ - Slot: helpers.StartSlot(helpers.SlotToEpoch(10000 + params.BeaconConfig().GenesisSlot)), + Slot: helpers.StartSlot(helpers.SlotToEpoch(10000)), } justifiedBlock := &pbp2p.BeaconBlock{ - Slot: helpers.StartSlot(helpers.SlotToEpoch(1500+params.BeaconConfig().GenesisSlot)) - 2, // Imagine two skip block + Slot: helpers.StartSlot(helpers.SlotToEpoch(1500)) - 2, // Imagine two skip block } blockRoot, err := hashutil.HashBeaconBlock(block) if err != nil { @@ -179,8 +179,8 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) { t.Fatalf("Could not hash justified block: %v", err) } beaconState := &pbp2p.BeaconState{ - Slot: 10000 + params.BeaconConfig().GenesisSlot, - CurrentJustifiedEpoch: helpers.SlotToEpoch(1500 + params.BeaconConfig().GenesisSlot), + Slot: 10000, + CurrentJustifiedEpoch: helpers.SlotToEpoch(1500), LatestBlockRoots: make([][]byte, params.BeaconConfig().LatestBlockRootsLength), LatestCrosslinks: []*pbp2p.Crosslink{ { @@ -223,9 +223,9 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) { t.Fatalf("Could not get attestation info at slot: %v", err) } expectedInfo := &pb.AttestationDataResponse{ - HeadSlot: 10000 + params.BeaconConfig().GenesisSlot, + HeadSlot: 10000, BeaconBlockRootHash32: blockRoot[:], - JustifiedEpoch: helpers.SlotToEpoch(1500 + params.BeaconConfig().GenesisSlot), + JustifiedEpoch: helpers.SlotToEpoch(1500), JustifiedBlockRootHash32: justifiedBlockRoot[:], LatestCrosslink: &pbp2p.Crosslink{ CrosslinkDataRootHash32: []byte("A"), diff --git a/beacon-chain/rpc/beacon_server_test.go b/beacon-chain/rpc/beacon_server_test.go index 27ad8f5614ed..9fdb3e3e53d6 100644 --- a/beacon-chain/rpc/beacon_server_test.go +++ b/beacon-chain/rpc/beacon_server_test.go @@ -684,7 +684,7 @@ func TestBlockTree_OK(t *testing.T) { validators = append(validators, &pbp2p.Validator{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance}) } justifiedState := &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: validators, } @@ -692,38 +692,38 @@ func TestBlockTree_OK(t *testing.T) { t.Fatal(err) } justifiedBlock := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, } if err := db.SaveJustifiedBlock(justifiedBlock); err != nil { t.Fatal(err) } justifiedRoot, _ := hashutil.HashBeaconBlock(justifiedBlock) b1 := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 3, + Slot: 3, ParentBlockRoot: justifiedRoot[:], RandaoReveal: []byte("A"), } b1Root, _ := hashutil.HashBeaconBlock(b1) b2 := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 3, + Slot: 3, ParentBlockRoot: justifiedRoot[:], RandaoReveal: []byte("C"), } b2Root, _ := hashutil.HashBeaconBlock(b2) b3 := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 3, + Slot: 3, ParentBlockRoot: justifiedRoot[:], RandaoReveal: []byte("D"), } b3Root, _ := hashutil.HashBeaconBlock(b1) b4 := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 4, + Slot: 4, ParentBlockRoot: b1Root[:], RandaoReveal: []byte("B"), } b4Root, _ := hashutil.HashBeaconBlock(b4) b5 := &pbp2p.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + 5, + Slot: 5, ParentBlockRoot: b3Root[:], RandaoReveal: []byte("E"), } diff --git a/beacon-chain/rpc/proposer_server.go b/beacon-chain/rpc/proposer_server.go index a67ec4972e12..11fd7ed1df05 100644 --- a/beacon-chain/rpc/proposer_server.go +++ b/beacon-chain/rpc/proposer_server.go @@ -87,7 +87,7 @@ func (ps *ProposerServer) ProposeBlock(ctx context.Context, blk *pbp2p.BeaconBlo ps.chainService.UpdateCanonicalRoots(blk, h) log.WithFields(logrus.Fields{ "headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(h[:])), - "headSlot": blk.Slot - params.BeaconConfig().GenesisSlot, + "headSlot": blk.Slot, }).Info("Chain head block and state updated") return &pb.ProposeResponse{BlockRootHash32: h[:]}, nil } @@ -144,7 +144,7 @@ func (ps *ProposerServer) PendingAttestations(ctx context.Context, req *pb.Pendi } log.WithError(err).WithFields(logrus.Fields{ - "slot": att.Data.Slot - params.BeaconConfig().GenesisSlot, + "slot": att.Data.Slot, "headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(att.Data.BeaconBlockRootHash32))}).Info( "Deleting failed pending attestation from DB") if err := ps.beaconDB.DeleteAttestation(att); err != nil { diff --git a/beacon-chain/rpc/proposer_server_test.go b/beacon-chain/rpc/proposer_server_test.go index bb74b4558767..211461cfa836 100644 --- a/beacon-chain/rpc/proposer_server_test.go +++ b/beacon-chain/rpc/proposer_server_test.go @@ -141,11 +141,11 @@ func TestPendingAttestations_FiltersWithinInclusionDelay(t *testing.T) { defer internal.TeardownDB(t, db) ctx := context.Background() - stateSlot := params.BeaconConfig().GenesisSlot + params.BeaconConfig().MinAttestationInclusionDelay + 100 + stateSlot := params.BeaconConfig().MinAttestationInclusionDelay + 100 beaconState := &pbp2p.BeaconState{ Slot: stateSlot, LatestCrosslinks: []*pbp2p.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch + 1, + Epoch: 1, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:], }}, } @@ -196,7 +196,7 @@ func TestPendingAttestations_FiltersExpiredAttestations(t *testing.T) { // Edge case: current slot is at the end of an epoch. The pending attestation // for the next slot should come from currentSlot + 1. currentSlot := helpers.StartSlot( - params.BeaconConfig().GenesisEpoch+10, + 10, ) - 1 expectedEpoch := uint64(100) @@ -264,7 +264,7 @@ func TestPendingAttestations_FiltersExpiredAttestations(t *testing.T) { CurrentJustifiedEpoch: expectedEpoch, PreviousJustifiedEpoch: expectedEpoch, LatestCrosslinks: []*pbp2p.Crosslink{{ - Epoch: params.BeaconConfig().GenesisEpoch + 9, + Epoch: 9, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:], }}, } @@ -334,10 +334,9 @@ func TestPendingAttestations_OK(t *testing.T) { beaconDB: db, } beaconState := &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + - params.BeaconConfig().SlotsPerEpoch + + Slot: params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().MinAttestationInclusionDelay, - LatestCrosslinks: []*pbp2p.Crosslink{{Epoch: params.BeaconConfig().GenesisEpoch + 1, + LatestCrosslinks: []*pbp2p.Crosslink{{Epoch: 1, CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:]}}, } if err := db.SaveState(ctx, beaconState); err != nil { diff --git a/beacon-chain/rpc/service_test.go b/beacon-chain/rpc/service_test.go index c084afbca071..1bebd31db905 100644 --- a/beacon-chain/rpc/service_test.go +++ b/beacon-chain/rpc/service_test.go @@ -59,21 +59,21 @@ func (ms *mockOperationService) PendingAttestations(_ context.Context) ([]*pb.At { AggregationBitfield: []byte("A"), Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, }, { AggregationBitfield: []byte("B"), Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, }, { AggregationBitfield: []byte("C"), Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + params.BeaconConfig().SlotsPerEpoch, + Slot: params.BeaconConfig().SlotsPerEpoch, CrosslinkDataRoot: params.BeaconConfig().ZeroHash[:], }, }, diff --git a/beacon-chain/rpc/validator_server.go b/beacon-chain/rpc/validator_server.go index b3a41d6e8cff..7fc6e4518434 100644 --- a/beacon-chain/rpc/validator_server.go +++ b/beacon-chain/rpc/validator_server.go @@ -288,7 +288,7 @@ func (vs *ValidatorServer) validatorStatus( if eth1BlockNumBigInt == nil { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_UNKNOWN_STATUS, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Eth1DepositBlockNumber: 0, } } @@ -296,7 +296,7 @@ func (vs *ValidatorServer) validatorStatus( if !ok { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_UNKNOWN_STATUS, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), } } @@ -304,7 +304,7 @@ func (vs *ValidatorServer) validatorStatus( if !chainStarted { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_UNKNOWN_STATUS, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), } } @@ -322,7 +322,7 @@ func (vs *ValidatorServer) validatorStatus( if err != nil { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_UNKNOWN_STATUS, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), } } @@ -330,7 +330,7 @@ func (vs *ValidatorServer) validatorStatus( if depositBlockSlot == 0 { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_UNKNOWN_STATUS, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), } } @@ -347,7 +347,7 @@ func (vs *ValidatorServer) validatorStatus( if helpers.IsActiveValidator(val, currEpoch) { return &pb.ValidatorStatusResponse{ Status: pb.ValidatorStatus_ACTIVE, - ActivationEpoch: val.ActivationEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: val.ActivationEpoch, Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), DepositInclusionSlot: depositBlockSlot, } @@ -378,7 +378,7 @@ func (vs *ValidatorServer) validatorStatus( Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(), PositionInActivationQueue: positionInQueue, DepositInclusionSlot: depositBlockSlot, - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, } } @@ -468,7 +468,7 @@ func (vs *ValidatorServer) depositBlockSlot(ctx context.Context, currentSlot uin eth2TimeDifference := timeToInclusion.Sub(eth2Genesis).Seconds() depositBlockSlot := uint64(eth2TimeDifference) / params.BeaconConfig().SecondsPerSlot - if depositBlockSlot > currentSlot-params.BeaconConfig().GenesisSlot { + if depositBlockSlot > currentSlot { return 0, nil } diff --git a/beacon-chain/rpc/validator_server_test.go b/beacon-chain/rpc/validator_server_test.go index ca65c395a245..089787242879 100644 --- a/beacon-chain/rpc/validator_server_test.go +++ b/beacon-chain/rpc/validator_server_test.go @@ -132,7 +132,7 @@ func TestNextEpochCommitteeAssignment_WrongPubkeyLength(t *testing.T) { } req := &pb.CommitteeAssignmentsRequest{ PublicKeys: [][]byte{{1}}, - EpochStart: params.BeaconConfig().GenesisEpoch, + EpochStart: 0, } want := fmt.Sprintf("expected public key to have length %d", params.BeaconConfig().BLSPubkeyLength) if _, err := validatorServer.CommitteeAssignment(context.Background(), req); err != nil && !strings.Contains(err.Error(), want) { @@ -160,7 +160,7 @@ func TestNextEpochCommitteeAssignment_CantFindValidatorIdx(t *testing.T) { pubKey := make([]byte, 96) req := &pb.CommitteeAssignmentsRequest{ PublicKeys: [][]byte{pubKey}, - EpochStart: params.BeaconConfig().GenesisEpoch, + EpochStart: 0, } want := fmt.Sprintf("validator %#x does not exist", req.PublicKeys[0]) if _, err := vs.CommitteeAssignment(ctx, req); err != nil && !strings.Contains(err.Error(), want) { @@ -215,7 +215,7 @@ func TestCommitteeAssignment_OK(t *testing.T) { // Test the first validator in registry. req := &pb.CommitteeAssignmentsRequest{ PublicKeys: [][]byte{pubKeyBuf}, - EpochStart: params.BeaconConfig().GenesisSlot, + EpochStart: 0, } res, err := vs.CommitteeAssignment(context.Background(), req) if err != nil { @@ -236,7 +236,7 @@ func TestCommitteeAssignment_OK(t *testing.T) { copy(pubKeyBuf[:], []byte(strconv.FormatUint(lastValidatorIndex, 10))) req = &pb.CommitteeAssignmentsRequest{ PublicKeys: [][]byte{pubKeyBuf}, - EpochStart: params.BeaconConfig().GenesisSlot, + EpochStart: 0, } res, err = vs.CommitteeAssignment(context.Background(), req) if err != nil { @@ -301,7 +301,7 @@ func TestCommitteeAssignment_multipleKeys_OK(t *testing.T) { // Test the first validator in registry. req := &pb.CommitteeAssignmentsRequest{ PublicKeys: [][]byte{pubKeyBuf0, pubKeyBuf1}, - EpochStart: params.BeaconConfig().GenesisSlot, + EpochStart: 0, } res, err := vs.CommitteeAssignment(context.Background(), req) if err != nil { @@ -326,7 +326,9 @@ func TestValidatorStatus_PendingActive(t *testing.T) { // Pending active because activation epoch is still defaulted at far future slot. if err := db.SaveState(ctx, &pbp2p.BeaconState{ValidatorRegistry: []*pbp2p.Validator{ {ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKey}, - }}); err != nil { + }, + Slot: 5000, + }); err != nil { t.Fatalf("could not save state: %v", err) } depositInput := &pbp2p.DepositInput{ @@ -334,7 +336,7 @@ func TestValidatorStatus_PendingActive(t *testing.T) { ProofOfPossession: []byte("hi"), WithdrawalCredentialsHash32: []byte("hey"), } - depData, err := helpers.EncodeDepositData(depositInput, params.BeaconConfig().MaxDepositAmount, 0) + depData, err := helpers.EncodeDepositData(depositInput, params.BeaconConfig().MaxDepositAmount, 0 /*timestamp*/) if err != nil { t.Fatal(err) } @@ -342,7 +344,7 @@ func TestValidatorStatus_PendingActive(t *testing.T) { deposit := &pbp2p.Deposit{ DepositData: depData, } - db.InsertDeposit(ctx, deposit, big.NewInt(0)) + db.InsertDeposit(ctx, deposit, big.NewInt(0) /*blockNum*/) height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix() vs := &ValidatorServer{ @@ -391,10 +393,10 @@ func TestValidatorStatus_Active(t *testing.T) { db.InsertDeposit(ctx, deposit, big.NewInt(0)) // Active because activation epoch <= current epoch < exit epoch. - activeEpoch := helpers.DelayedActivationExitEpoch(params.BeaconConfig().GenesisEpoch) + activeEpoch := helpers.DelayedActivationExitEpoch(0) if err := db.SaveState(ctx, &pbp2p.BeaconState{ GenesisTime: uint64(time.Unix(0, 0).Unix()), - Slot: params.BeaconConfig().GenesisSlot + 10000, + Slot: 10000, ValidatorRegistry: []*pbp2p.Validator{{ ActivationEpoch: activeEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch, @@ -442,7 +444,7 @@ func TestValidatorStatus_InitiatedExit(t *testing.T) { // Initiated exit because validator status flag = Validator_INITIATED_EXIT. if err := db.SaveState(ctx, &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 10000, + Slot: 10000, ValidatorRegistry: []*pbp2p.Validator{{ StatusFlags: pbp2p.Validator_INITIATED_EXIT, Pubkey: pubKey}, @@ -496,7 +498,7 @@ func TestValidatorStatus_Withdrawable(t *testing.T) { // Withdrawable exit because validator status flag = Validator_WITHDRAWABLE. if err := db.SaveState(ctx, &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 10000, + Slot: 10000, ValidatorRegistry: []*pbp2p.Validator{{ StatusFlags: pbp2p.Validator_WITHDRAWABLE, Pubkey: pubKey}, @@ -550,7 +552,7 @@ func TestValidatorStatus_ExitedSlashed(t *testing.T) { // Exit slashed because exit epoch and slashed epoch are =< current epoch. if err := db.SaveState(ctx, &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 10000, + Slot: 10000, ValidatorRegistry: []*pbp2p.Validator{{ Pubkey: pubKey}, }}); err != nil { @@ -603,7 +605,7 @@ func TestValidatorStatus_Exited(t *testing.T) { // Exit because only exit epoch is =< current epoch. if err := db.SaveState(ctx, &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 10000, + Slot: 10000, ValidatorRegistry: []*pbp2p.Validator{{ Pubkey: pubKey, SlashedEpoch: params.BeaconConfig().FarFutureEpoch}, @@ -656,9 +658,9 @@ func TestValidatorStatus_UnknownStatus(t *testing.T) { } if err := db.SaveState(ctx, &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: []*pbp2p.Validator{{ - ActivationEpoch: params.BeaconConfig().GenesisSlot, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKey}, }}); err != nil { @@ -706,7 +708,7 @@ func TestWaitForActivation_ContextClosed(t *testing.T) { ctx := context.Background() beaconState := &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, ValidatorRegistry: []*pbp2p.Validator{}, } if err := db.SaveState(ctx, beaconState); err != nil { @@ -757,13 +759,13 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) { } beaconState := &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 4000, + Slot: 4000, ValidatorRegistry: []*pbp2p.Validator{{ - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKeys[0]}, { - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKeys[1]}, }, @@ -815,7 +817,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) { }, {PublicKey: []byte{'B'}, Status: &pb.ValidatorStatusResponse{ - ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch, + ActivationEpoch: params.BeaconConfig().FarFutureEpoch, }, }, }, @@ -841,17 +843,17 @@ func TestMultipleValidatorStatus_OK(t *testing.T) { } beaconState := &pbp2p.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 4000, + Slot: 4000, ValidatorRegistry: []*pbp2p.Validator{{ - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKeys[0]}, { - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKeys[1]}, { - ActivationEpoch: params.BeaconConfig().GenesisEpoch, + ActivationEpoch: 0, ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKeys[2]}, }, diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index d43c2d61cf5f..31d74156ffdc 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -43,7 +43,6 @@ go_test( "//shared/event:go_default_library", "//shared/hashutil:go_default_library", "//shared/p2p:go_default_library", - "//shared/params:go_default_library", "//shared/testutil:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_libp2p_go_libp2p_peer//:go_default_library", diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index ec11564aba37..c27164cf34dd 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -212,7 +212,7 @@ func (s *InitialSync) exitInitialSync(ctx context.Context, block *pb.BeaconBlock return ErrCanonicalStateMismatch } - log.WithField("canonicalStateSlot", state.Slot-params.BeaconConfig().GenesisSlot).Info("Exiting init sync and starting regular sync") + log.WithField("canonicalStateSlot", state.Slot).Info("Exiting init sync and starting regular sync") s.syncService.ResumeSync() s.cancel() s.nodeIsSynced = true @@ -262,7 +262,7 @@ func (s *InitialSync) run(chainHeadResponses map[peer.ID]*pb.ChainHeadResponse) func (s *InitialSync) syncToPeer(ctx context.Context, chainHeadResponse *pb.ChainHeadResponse, peer peer.ID) error { fields := logrus.Fields{ "peer": peer.Pretty(), - "canonicalSlot": chainHeadResponse.CanonicalSlot - params.BeaconConfig().GenesisSlot, + "canonicalSlot": chainHeadResponse.CanonicalSlot, } log.WithFields(fields).Info("Requesting state from peer") diff --git a/beacon-chain/sync/initial-sync/service_test.go b/beacon-chain/sync/initial-sync/service_test.go index a4a23a6655b1..0272340e85e2 100644 --- a/beacon-chain/sync/initial-sync/service_test.go +++ b/beacon-chain/sync/initial-sync/service_test.go @@ -14,7 +14,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/p2p" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -128,7 +127,7 @@ func TestProcessingBatchedBlocks_OK(t *testing.T) { for i := 1; i <= batchSize; i++ { batchedBlocks[i-1] = &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), } } // edge case: handle out of order block list. Specifically with the highest @@ -163,7 +162,7 @@ func TestProcessingBlocks_SkippedSlots(t *testing.T) { ss := NewInitialSyncService(context.Background(), cfg) batchSize := 20 - blks, err := ss.db.BlocksBySlot(ctx, params.BeaconConfig().GenesisSlot) + blks, err := ss.db.BlocksBySlot(ctx, 0) if err != nil { t.Fatalf("Unable to get genesis block %v", err) } @@ -179,7 +178,7 @@ func TestProcessingBlocks_SkippedSlots(t *testing.T) { continue } block := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot + uint64(i), + Slot: uint64(i), ParentBlockRoot: parentHash, } diff --git a/beacon-chain/sync/initial-sync/sync_blocks.go b/beacon-chain/sync/initial-sync/sync_blocks.go index a411f05f9865..3ce2c95137a0 100644 --- a/beacon-chain/sync/initial-sync/sync_blocks.go +++ b/beacon-chain/sync/initial-sync/sync_blocks.go @@ -11,7 +11,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/p2p" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -110,7 +109,7 @@ func (s *InitialSync) validateAndSaveNextBlock(ctx context.Context, block *pb.Be } log.WithFields(logrus.Fields{ "root": fmt.Sprintf("%#x", bytesutil.Trunc(root[:])), - "slot": block.Slot - params.BeaconConfig().GenesisSlot, + "slot": block.Slot, }).Info("Saving block") s.mutex.Lock() diff --git a/beacon-chain/sync/initial-sync/sync_state.go b/beacon-chain/sync/initial-sync/sync_state.go index 9c916d3b2f2c..86705fba14b9 100644 --- a/beacon-chain/sync/initial-sync/sync_state.go +++ b/beacon-chain/sync/initial-sync/sync_state.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/p2p" - "github.com/prysmaticlabs/prysm/shared/params" "go.opencensus.io/trace" ) @@ -87,7 +86,7 @@ func (s *InitialSync) processState(msg p2p.Message, chainHead *pb.ChainHeadRespo s.stateReceived = true log.Debugf( "Successfully saved beacon state with the last finalized slot: %d", - finalizedState.Slot-params.BeaconConfig().GenesisSlot, + finalizedState.Slot, ) log.WithField("peer", msg.Peer.Pretty()).Info("Requesting batch blocks from peer") s.requestBatchedBlocks(ctx, finalizedBlockRoot[:], chainHead.CanonicalBlockRoot, msg.Peer) diff --git a/beacon-chain/sync/querier.go b/beacon-chain/sync/querier.go index 40da237e4879..a3498b238640 100644 --- a/beacon-chain/sync/querier.go +++ b/beacon-chain/sync/querier.go @@ -172,7 +172,7 @@ func (q *Querier) run() { queryLog.WithField("peerID", q.bestPeer.Pretty()).Info("Peer with highest canonical head") queryLog.Infof( "Latest chain head is at slot: %d and state root: %#x", - q.currentHeadSlot-params.BeaconConfig().GenesisSlot, q.currentStateRoot, + q.currentHeadSlot, q.currentStateRoot, ) ticker.Stop() responseSub.Unsubscribe() @@ -189,7 +189,7 @@ func (q *Querier) run() { if _, ok := q.chainHeadResponses[msg.Peer]; !ok { queryLog.WithFields(logrus.Fields{ "peerID": msg.Peer.Pretty(), - "highestSlot": response.CanonicalSlot - params.BeaconConfig().GenesisSlot, + "highestSlot": response.CanonicalSlot, }).Info("Received chain head from peer") q.chainHeadResponses[msg.Peer] = response } diff --git a/beacon-chain/sync/querier_test.go b/beacon-chain/sync/querier_test.go index a406c0150afd..e31e7a35be94 100644 --- a/beacon-chain/sync/querier_test.go +++ b/beacon-chain/sync/querier_test.go @@ -12,7 +12,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/p2p" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -158,7 +157,7 @@ func TestQuerier_ChainReqResponse(t *testing.T) { expMsg := fmt.Sprintf( "Latest chain head is at slot: %d and state root: %#x", - response.CanonicalSlot-params.BeaconConfig().GenesisSlot, response.CanonicalStateRootHash32, + response.CanonicalSlot, response.CanonicalStateRootHash32, ) <-exitRoutine diff --git a/beacon-chain/sync/receive_block.go b/beacon-chain/sync/receive_block.go index 8ea608204bda..af4a414ce49d 100644 --- a/beacon-chain/sync/receive_block.go +++ b/beacon-chain/sync/receive_block.go @@ -136,8 +136,8 @@ func (rs *RegularSync) validateAndProcessBlock( return nil, nil, false, err } - finalizedSlot := helpers.StartSlot(beaconState.FinalizedEpoch) - params.BeaconConfig().GenesisSlot - slot := block.Slot - params.BeaconConfig().GenesisSlot + finalizedSlot := helpers.StartSlot(beaconState.FinalizedEpoch) + slot := block.Slot span.AddAttributes( trace.Int64Attribute("block.Slot", int64(slot)), trace.Int64Attribute("finalized slot", int64(finalizedSlot)), diff --git a/beacon-chain/sync/regular_sync.go b/beacon-chain/sync/regular_sync.go index cc4e15b65f1b..0d2d9dc0a1da 100644 --- a/beacon-chain/sync/regular_sync.go +++ b/beacon-chain/sync/regular_sync.go @@ -398,7 +398,7 @@ func (rs *RegularSync) receiveAttestation(msg p2p.Message) error { } log.WithFields(logrus.Fields{ "headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attestation.Data.BeaconBlockRootHash32)), - "justifiedEpoch": attestation.Data.JustifiedEpoch - params.BeaconConfig().GenesisEpoch, + "justifiedEpoch": attestation.Data.JustifiedEpoch, }).Debug("Received an attestation") // Skip if attestation has been seen before. @@ -411,16 +411,24 @@ func (rs *RegularSync) receiveAttestation(msg p2p.Message) error { } // Skip if attestation slot is older than last finalized slot in state. - highestSlot := rs.db.HighestBlockSlot() + head, err := rs.db.ChainHead() + if err != nil { + return err + } + highestSlot := head.Slot span.AddAttributes( trace.Int64Attribute("attestation.Data.Slot", int64(attestation.Data.Slot)), trace.Int64Attribute("finalized state slot", int64(highestSlot-params.BeaconConfig().SlotsPerEpoch)), ) - if attestation.Data.Slot < highestSlot-params.BeaconConfig().SlotsPerEpoch { + oneEpochAgo := uint64(0) + if highestSlot > params.BeaconConfig().SlotsPerEpoch { + oneEpochAgo = highestSlot - params.BeaconConfig().SlotsPerEpoch + } + if attestation.Data.Slot < oneEpochAgo { log.WithFields(logrus.Fields{ "receivedSlot": attestation.Data.Slot, - "epochSlot": highestSlot - params.BeaconConfig().SlotsPerEpoch}, + "epochSlot": oneEpochAgo}, ).Debug("Skipping received attestation with slot smaller than one epoch ago") return nil } diff --git a/beacon-chain/sync/regular_sync_test.go b/beacon-chain/sync/regular_sync_test.go index 6bd4b1d642e3..8244fca0faba 100644 --- a/beacon-chain/sync/regular_sync_test.go +++ b/beacon-chain/sync/regular_sync_test.go @@ -199,7 +199,7 @@ func TestProcessBlock_OK(t *testing.T) { ss := NewRegularSyncService(context.Background(), cfg) parentBlock := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, } if err := db.SaveBlock(parentBlock); err != nil { t.Fatalf("failed to save block: %v", err) @@ -215,7 +215,7 @@ func TestProcessBlock_OK(t *testing.T) { BlockRoot: []byte{6, 7, 8, 9, 10}, }, ParentBlockRoot: parentRoot[:], - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, } attestation := &pb.Attestation{ Data: &pb.AttestationData{ @@ -274,7 +274,7 @@ func TestProcessBlock_MultipleBlocksProcessedOK(t *testing.T) { ss := NewRegularSyncService(context.Background(), cfg) parentBlock := &pb.BeaconBlock{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, } if err := db.SaveBlock(parentBlock); err != nil { t.Fatalf("failed to save block: %v", err) @@ -290,7 +290,7 @@ func TestProcessBlock_MultipleBlocksProcessedOK(t *testing.T) { BlockRoot: []byte{6, 7, 8, 9, 10}, }, ParentBlockRoot: parentRoot[:], - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, } responseBlock1 := &pb.BeaconBlockResponse{ @@ -298,7 +298,7 @@ func TestProcessBlock_MultipleBlocksProcessedOK(t *testing.T) { Attestation: &pb.Attestation{ Data: &pb.AttestationData{ CrosslinkDataRoot: []byte{}, - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, }, }, } @@ -354,7 +354,7 @@ func TestReceiveAttestation_OK(t *testing.T) { db := internal.SetupDB(t) defer internal.TeardownDB(t, db) beaconState := &pb.BeaconState{ - Slot: params.BeaconConfig().GenesisSlot + 2, + Slot: 2, } if err := db.SaveState(ctx, beaconState); err != nil { t.Fatalf("Could not save state: %v", err) @@ -380,7 +380,7 @@ func TestReceiveAttestation_OK(t *testing.T) { request1 := &pb.AttestationResponse{ Attestation: &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot + 1, + Slot: 1, }, }, } @@ -405,11 +405,19 @@ func TestReceiveAttestation_OlderThanPrevEpoch(t *testing.T) { db := internal.SetupDB(t) defer internal.TeardownDB(t, db) - state := &pb.BeaconState{Slot: params.BeaconConfig().GenesisSlot + 2*params.BeaconConfig().SlotsPerEpoch} + state := &pb.BeaconState{Slot: 2 * params.BeaconConfig().SlotsPerEpoch} if err := db.SaveState(ctx, state); err != nil { t.Fatalf("Could not save state: %v", err) } + headBlock := &pb.BeaconBlock{Slot: state.Slot} + if err := db.SaveBlock(headBlock); err != nil { + t.Fatalf("failed to save block: %v", err) + } + if err := db.UpdateChainHead(ctx, headBlock, state); err != nil { + t.Fatalf("failed to update chain head: %v", err) + } cfg := &RegularSyncConfig{ + AttsService: &mockAttestationService{}, ChainService: ms, OperationService: os, P2P: &mockP2P{}, @@ -420,7 +428,7 @@ func TestReceiveAttestation_OlderThanPrevEpoch(t *testing.T) { request1 := &pb.AttestationResponse{ Attestation: &pb.Attestation{ Data: &pb.AttestationData{ - Slot: params.BeaconConfig().GenesisSlot, + Slot: 0, }, }, } diff --git a/shared/params/config.go b/shared/params/config.go index 4920d7f1c177..b4093692aeaa 100644 --- a/shared/params/config.go +++ b/shared/params/config.go @@ -42,8 +42,6 @@ type BeaconChainConfig struct { ForkChoiceBalanceIncrement uint64 // ForkChoiceBalanceIncrement is used to track block score based on balances for fork choice. // Initial value constants. - GenesisSlot uint64 // GenesisSlot is used to initialize the genesis state fields. - GenesisEpoch uint64 // GenesisEpoch is used to initialize epoch. FarFutureEpoch uint64 // FarFutureEpoch represents a epoch extremely far away in the future used as the default penalization slot for validators. ZeroHash [32]byte // ZeroHash is used to represent a zeroed out 32 byte array. BLSWithdrawalPrefixByte byte // BLSWithdrawalPrefixByte is used for BLS withdrawal and it's the first byte. @@ -167,8 +165,6 @@ var defaultBeaconConfig = &BeaconChainConfig{ ForkChoiceBalanceIncrement: 1 * 1e9, // Initial value constants. - GenesisSlot: 1 << 63, - GenesisEpoch: 1 << 63 / 64, FarFutureEpoch: 1<<64 - 1, ZeroHash: [32]byte{}, BLSWithdrawalPrefixByte: byte(0), @@ -274,7 +270,6 @@ func DemoBeaconConfig() *BeaconChainConfig { demoConfig.TargetCommitteeSize = 1 demoConfig.DepositsForChainStart = 8 demoConfig.SlotsPerEpoch = 8 - demoConfig.GenesisEpoch = demoConfig.GenesisSlot / 8 demoConfig.MinDepositAmount = 100 demoConfig.MaxDepositAmount = 3.2 * 1e9 demoConfig.EjectionBalance = 3.175 * 1e9 diff --git a/shared/slotutil/BUILD.bazel b/shared/slotutil/BUILD.bazel index 99802af24a52..c56502040893 100644 --- a/shared/slotutil/BUILD.bazel +++ b/shared/slotutil/BUILD.bazel @@ -5,12 +5,10 @@ go_library( srcs = ["slotticker.go"], importpath = "github.com/prysmaticlabs/prysm/shared/slotutil", visibility = ["//visibility:public"], - deps = ["//shared/params:go_default_library"], ) go_test( name = "go_default_test", srcs = ["slotticker_test.go"], embed = [":go_default_library"], - deps = ["//shared/params:go_default_library"], ) diff --git a/shared/slotutil/slotticker.go b/shared/slotutil/slotticker.go index 1318e5fba036..c863d55623bf 100644 --- a/shared/slotutil/slotticker.go +++ b/shared/slotutil/slotticker.go @@ -2,8 +2,6 @@ package slotutil import ( "time" - - "github.com/prysmaticlabs/prysm/shared/params" ) // SlotTicker is a special ticker for the beacon chain block. @@ -57,11 +55,11 @@ func (s *SlotTicker) start( if sinceGenesis < 0 { // Handle when the current time is before the genesis time. nextTickTime = genesisTime - slot = params.BeaconConfig().GenesisSlot + slot = 0 } else { nextTick := sinceGenesis.Truncate(d) + d nextTickTime = genesisTime.Add(nextTick) - slot = uint64(nextTick/d) + params.BeaconConfig().GenesisSlot + slot = uint64(nextTick / d) } for { diff --git a/shared/slotutil/slotticker_test.go b/shared/slotutil/slotticker_test.go index efb387b9887d..d7c1071a6a67 100644 --- a/shared/slotutil/slotticker_test.go +++ b/shared/slotutil/slotticker_test.go @@ -3,8 +3,6 @@ package slotutil import ( "testing" "time" - - "github.com/prysmaticlabs/prysm/shared/params" ) func TestSlotTicker(t *testing.T) { @@ -43,15 +41,15 @@ func TestSlotTicker(t *testing.T) { // Tick once. tick <- time.Now() slot := <-ticker.C() - if slot != 1+params.BeaconConfig().GenesisSlot { - t.Fatalf("Expected %d, got %d", params.BeaconConfig().GenesisSlot+1, slot) + if slot != 1 { + t.Fatalf("Expected %d, got %d", 1, slot) } // Tick twice. tick <- time.Now() slot = <-ticker.C() - if slot != 2+params.BeaconConfig().GenesisSlot { - t.Fatalf("Expected %d, got %d", params.BeaconConfig().GenesisSlot+2, slot) + if slot != 2 { + t.Fatalf("Expected %d, got %d", 2, slot) } } @@ -91,14 +89,14 @@ func TestSlotTickerGenesis(t *testing.T) { // Tick once. tick <- time.Now() slot := <-ticker.C() - if slot != params.BeaconConfig().GenesisSlot { - t.Fatalf("Expected %d, got %d", params.BeaconConfig().GenesisSlot, slot) + if slot != 0 { + t.Fatalf("Expected %d, got %d", 0, slot) } // Tick twice. tick <- time.Now() slot = <-ticker.C() - if slot != 1+params.BeaconConfig().GenesisSlot { - t.Fatalf("Expected %d, got %d", params.BeaconConfig().GenesisSlot+1, slot) + if slot != 1 { + t.Fatalf("Expected %d, got %d", 1, slot) } } diff --git a/validator/client/fake_validator_test.go b/validator/client/fake_validator_test.go index 8557d0cfc676..41578d9413b1 100644 --- a/validator/client/fake_validator_test.go +++ b/validator/client/fake_validator_test.go @@ -5,7 +5,6 @@ import ( "time" pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" - "github.com/prysmaticlabs/prysm/shared/params" ) var _ = Validator(&fakeValidator{}) @@ -48,7 +47,7 @@ func (fv *fakeValidator) WaitForActivation(_ context.Context) error { func (fv *fakeValidator) CanonicalHeadSlot(_ context.Context) (uint64, error) { fv.CanonicalHeadSlotCalled = true - return params.BeaconConfig().GenesisSlot, nil + return 0, nil } func (fv *fakeValidator) SlotDeadline(_ uint64) time.Time { diff --git a/validator/client/runner.go b/validator/client/runner.go index 5ac9f05ea70c..29cb6ac00ffb 100644 --- a/validator/client/runner.go +++ b/validator/client/runner.go @@ -66,7 +66,7 @@ func run(ctx context.Context, v Validator) { // Report this validator client's rewards and penalties throughout its lifecycle. if err := v.LogValidatorGainsAndLosses(slotCtx, slot); err != nil { log.Errorf("Could not report validator's rewards/penalties for slot %d: %v", - slot-params.BeaconConfig().GenesisSlot, err) + slot, err) } // Keep trying to update assignments if they are nil or if we are past an @@ -91,7 +91,7 @@ func run(ctx context.Context, v Validator) { } log.WithFields(logrus.Fields{ "public_key": pk12Char, - "slot": slot - params.BeaconConfig().GenesisSlot, + "slot": slot, "role": role, }).Debug("No active assignment, doing nothing") default: @@ -107,7 +107,7 @@ func run(ctx context.Context, v Validator) { func handleAssignmentError(err error, slot uint64) { if errCode, ok := status.FromError(err); ok && errCode.Code() == codes.NotFound { log.WithField( - "epoch", (slot/params.BeaconConfig().SlotsPerEpoch)-params.BeaconConfig().GenesisEpoch, + "epoch", slot/params.BeaconConfig().SlotsPerEpoch, ).Warn("Validator not yet assigned to epoch") } else { log.WithField("error", err).Error("Failed to update assignments") diff --git a/validator/client/validator.go b/validator/client/validator.go index bc09ed314e5b..673da57b2ae5 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -138,7 +138,7 @@ func (v *validator) checkAndLogValidatorStatus(validatorStatuses []*pb.Validator }).Info("Not yet included in state...") continue } - if status.Status.ActivationEpoch == (params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch) { + if status.Status.ActivationEpoch == (params.BeaconConfig().FarFutureEpoch) { log.WithFields(logrus.Fields{ "publicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)), "status": status.Status.Status.String(), @@ -165,7 +165,7 @@ func (v *validator) CanonicalHeadSlot(ctx context.Context) (uint64, error) { defer span.End() head, err := v.beaconClient.CanonicalHead(ctx, &ptypes.Empty{}) if err != nil { - return params.BeaconConfig().GenesisSlot, err + return 0, err } return head.Slot, nil } @@ -177,7 +177,7 @@ func (v *validator) NextSlot() <-chan uint64 { // SlotDeadline is the start time of the next slot. func (v *validator) SlotDeadline(slot uint64) time.Time { - secs := (slot + 1 - params.BeaconConfig().GenesisSlot) * params.BeaconConfig().SecondsPerSlot + secs := (slot + 1) * params.BeaconConfig().SecondsPerSlot return time.Unix(int64(v.genesisTime), 0 /*ns*/).Add(time.Duration(secs) * time.Second) } @@ -225,12 +225,12 @@ func (v *validator) UpdateAssignments(ctx context.Context, slot uint64) error { } else { attesterSlot = assignment.Slot } - lFields["attesterSlot"] = attesterSlot - params.BeaconConfig().GenesisSlot + lFields["attesterSlot"] = attesterSlot lFields["proposerSlot"] = "Not proposing" lFields["shard"] = assignment.Shard if assignment.IsProposer { - lFields["proposerSlot"] = proposerSlot - params.BeaconConfig().GenesisSlot + lFields["proposerSlot"] = proposerSlot } log.WithFields(lFields).Info("New assignment") diff --git a/validator/client/validator_attest.go b/validator/client/validator_attest.go index 0cf593cf94e2..5724f7e10f39 100644 --- a/validator/client/validator_attest.go +++ b/validator/client/validator_attest.go @@ -74,7 +74,7 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64, idx stri infoRes, err := v.attesterClient.AttestationDataAtSlot(ctx, infoReq) if err != nil { log.Errorf("Could not fetch necessary info to produce attestation at slot %d: %v", - slot-params.BeaconConfig().GenesisSlot, err) + slot, err) return } @@ -129,7 +129,7 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64, idx stri log.WithFields(logrus.Fields{ "shard": attData.Shard, - "slot": slot - params.BeaconConfig().GenesisSlot, + "slot": slot, "validator": truncatedPk, }).Info("Attesting to beacon chain head...") @@ -140,16 +140,16 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64, idx stri } log.WithFields(logrus.Fields{ "headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attData.BeaconBlockRootHash32)), - "slot": attData.Slot - params.BeaconConfig().GenesisSlot, + "slot": attData.Slot, "shard": attData.Shard, "validator": truncatedPk, }).Info("Attested latest head") span.AddAttributes( - trace.Int64Attribute("slot", int64(slot-params.BeaconConfig().GenesisSlot)), + trace.Int64Attribute("slot", int64(slot)), trace.StringAttribute("attestationHash", fmt.Sprintf("%#x", attResp.AttestationHash)), trace.Int64Attribute("shard", int64(attData.Shard)), trace.StringAttribute("blockRoot", fmt.Sprintf("%#x", attestation.Data.BeaconBlockRootHash32)), - trace.Int64Attribute("justifiedEpoch", int64(attData.JustifiedEpoch-params.BeaconConfig().GenesisEpoch)), + trace.Int64Attribute("justifiedEpoch", int64(attData.JustifiedEpoch)), trace.StringAttribute("bitfield", fmt.Sprintf("%#x", aggregationBitfield)), ) } diff --git a/validator/client/validator_metrics.go b/validator/client/validator_metrics.go index c4efb97321a6..7cda62c0db33 100644 --- a/validator/client/validator_metrics.go +++ b/validator/client/validator_metrics.go @@ -25,7 +25,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) } epoch := slot / params.BeaconConfig().SlotsPerEpoch - if epoch == params.BeaconConfig().GenesisEpoch { + if epoch == 0 { v.prevBalance = params.BeaconConfig().MaxDepositAmount } var totalPrevBalance uint64 @@ -45,8 +45,8 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) tpk := hex.EncodeToString(pkey)[:12] if !reported { log.WithFields(logrus.Fields{ - "slot": slot - params.BeaconConfig().GenesisSlot, - "epoch": (slot / params.BeaconConfig().SlotsPerEpoch) - params.BeaconConfig().GenesisEpoch, + "slot": slot, + "epoch": slot / params.BeaconConfig().SlotsPerEpoch, }).Info("Start of a new epoch!") log.WithFields(logrus.Fields{ "totalValidators": resp.TotalValidators, diff --git a/validator/client/validator_propose.go b/validator/client/validator_propose.go index 8af07708ee25..3fed2f3a35be 100644 --- a/validator/client/validator_propose.go +++ b/validator/client/validator_propose.go @@ -22,7 +22,7 @@ import ( // the state root computation, and finally signed by the validator before being // sent back to the beacon node for broadcasting. func (v *validator) ProposeBlock(ctx context.Context, slot uint64, idx string) { - if slot == params.BeaconConfig().GenesisSlot { + if slot == 0 { log.Info("Assigned to genesis slot, skipping proposal") return } @@ -139,7 +139,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot uint64, idx string) { trace.Int64Attribute("numAttestations", int64(len(block.Body.Attestations))), ) log.WithFields(logrus.Fields{ - "slot": block.Slot - params.BeaconConfig().GenesisSlot, + "slot": block.Slot, "blockRoot": fmt.Sprintf("%#x", blkResp.BlockRootHash32), "numAttestations": len(block.Body.Attestations), "numDeposits": len(block.Body.Deposits), diff --git a/validator/client/validator_propose_test.go b/validator/client/validator_propose_test.go index af642e90118b..45db446271dd 100644 --- a/validator/client/validator_propose_test.go +++ b/validator/client/validator_propose_test.go @@ -11,7 +11,6 @@ import ( "github.com/golang/mock/gomock" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" - "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/validator/internal" logTest "github.com/sirupsen/logrus/hooks/test" @@ -47,7 +46,7 @@ func TestProposeBlock_DoesNotProposeGenesisBlock(t *testing.T) { hook := logTest.NewGlobal() validator, _, finish := setup(t) defer finish() - validator.ProposeBlock(context.Background(), params.BeaconConfig().GenesisSlot, hex.EncodeToString(validatorKey.PublicKey.Marshal())) + validator.ProposeBlock(context.Background(), 0, hex.EncodeToString(validatorKey.PublicKey.Marshal())) testutil.AssertLogsContain(t, hook, "Assigned to genesis slot, skipping proposal") } diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index 2e061dd08f4a..b5965f40a27d 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -308,13 +308,13 @@ func TestCanonicalHeadSlot_OK(t *testing.T) { client.EXPECT().CanonicalHead( gomock.Any(), gomock.Any(), - ).Return(&pbp2p.BeaconBlock{Slot: params.BeaconConfig().GenesisSlot}, nil) + ).Return(&pbp2p.BeaconBlock{Slot: 0}, nil) headSlot, err := v.CanonicalHeadSlot(context.Background()) if err != nil { t.Fatalf("Unexpected error: %v", err) } - if headSlot != params.BeaconConfig().GenesisSlot { - t.Errorf("Mismatch slots, wanted: %v, received: %v", params.BeaconConfig().GenesisSlot, headSlot) + if headSlot != 0 { + t.Errorf("Mismatch slots, wanted: %v, received: %v", 0, headSlot) } } func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) {