Skip to content

Commit

Permalink
Genesis == zero (#2653)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon authored and terencechain committed May 19, 2019
1 parent 3c9b099 commit ab35814
Show file tree
Hide file tree
Showing 75 changed files with 611 additions and 792 deletions.
6 changes: 3 additions & 3 deletions beacon-chain/attestation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
72 changes: 36 additions & 36 deletions beacon-chain/attestation/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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),
Expand Down Expand Up @@ -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,
})
}

Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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)
Expand All @@ -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,
},
})
Expand Down
4 changes: 1 addition & 3 deletions beacon-chain/attestation/vote_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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))
}
1 change: 0 additions & 1 deletion beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 10 additions & 11 deletions beacon-chain/blockchain/block_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading

0 comments on commit ab35814

Please sign in to comment.