From 9d15196bedb72e92bdc157aeda93f15937bdd319 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Sat, 24 Aug 2019 18:56:25 +0530 Subject: [PATCH] Runtime Fixes (#3300) --- .../blockchain/forkchoice/process_attestation.go | 4 ++++ .../blockchain/forkchoice/process_block.go | 11 ++++++++++- .../blockchain/forkchoice/process_block_test.go | 14 +++++++++----- beacon-chain/blockchain/receive_attestation.go | 6 +++--- beacon-chain/blockchain/service.go | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/beacon-chain/blockchain/forkchoice/process_attestation.go b/beacon-chain/blockchain/forkchoice/process_attestation.go index c8d54b55b..56977c3f9 100644 --- a/beacon-chain/blockchain/forkchoice/process_attestation.go +++ b/beacon-chain/blockchain/forkchoice/process_attestation.go @@ -117,12 +117,16 @@ func (s *Store) saveChkptState(ctx context.Context, baseState *pb.BeaconState, c if err != nil { return nil, errors.Wrap(err, "could not hash justified checkpoint") } + s.lock.RLock() _, exists := s.checkptBlkRoot[h] + s.lock.RUnlock() if !exists { baseState, err = state.ProcessSlots(ctx, baseState, helpers.StartSlot(c.Epoch)) if err != nil { return nil, errors.Wrapf(err, "could not process slots up to %d", helpers.StartSlot(c.Epoch)) } + s.lock.Lock() + defer s.lock.Unlock() s.checkptBlkRoot[h] = bytesutil.ToBytes32(c.Root) } return baseState, nil diff --git a/beacon-chain/blockchain/forkchoice/process_block.go b/beacon-chain/blockchain/forkchoice/process_block.go index 8d13fa786..4050feb7c 100644 --- a/beacon-chain/blockchain/forkchoice/process_block.go +++ b/beacon-chain/blockchain/forkchoice/process_block.go @@ -14,6 +14,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" + "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -68,7 +69,7 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error { if err != nil { return errors.Wrapf(err, "could not get signing root of block %d", b.Slot) } - if err := s.verifyBlkDescendant(ctx, root, b.Slot); err != nil { + if err := s.verifyBlkDescendant(ctx, bytesutil.ToBytes32(b.ParentRoot), b.Slot); err != nil { return err } @@ -77,6 +78,8 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error { return err } + log.WithField("slot", b.Slot).Info("Executing state transition on block") + // Apply new state transition for the block to the store. // Make block root as bad to reject in sync. postState, err := state.ExecuteStateTransition(ctx, preState, b) @@ -102,6 +105,12 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error { s.finalizedCheckpt.Epoch = postState.FinalizedCheckpoint.Epoch } + log.WithFields(logrus.Fields{ + "slot": b.Slot, + "attestations": len(b.Body.Attestations), + "deposits": len(b.Body.Deposits), + }).Info("Completed state transition on block") + // Log epoch summary before the next epoch. if helpers.IsEpochStart(postState.Slot) { logEpochData(postState) diff --git a/beacon-chain/blockchain/forkchoice/process_block_test.go b/beacon-chain/blockchain/forkchoice/process_block_test.go index 7df382dfd..834d7466d 100644 --- a/beacon-chain/blockchain/forkchoice/process_block_test.go +++ b/beacon-chain/blockchain/forkchoice/process_block_test.go @@ -24,8 +24,12 @@ func TestStore_OnBlock(t *testing.T) { t.Fatal(err) } - randaomParentRoot := []byte{'a'} - if err := store.db.SaveState(ctx, &pb.BeaconState{}, bytesutil.ToBytes32(randaomParentRoot)); err != nil { + randomParentRoot := []byte{'a'} + if err := store.db.SaveState(ctx, &pb.BeaconState{}, bytesutil.ToBytes32(randomParentRoot)); err != nil { + t.Fatal(err) + } + randomParentRoot2 := roots[1] + if err := store.db.SaveState(ctx, &pb.BeaconState{}, bytesutil.ToBytes32(randomParentRoot2)); err != nil { t.Fatal(err) } validGenesisRoot := []byte{'g'} @@ -48,19 +52,19 @@ func TestStore_OnBlock(t *testing.T) { }, { name: "block is from the feature", - blk: ðpb.BeaconBlock{ParentRoot: randaomParentRoot, Slot: params.BeaconConfig().FarFutureEpoch}, + blk: ðpb.BeaconBlock{ParentRoot: randomParentRoot, Slot: params.BeaconConfig().FarFutureEpoch}, s: &pb.BeaconState{}, wantErrString: "could not process block from the future", }, { name: "could not get finalized block", - blk: ðpb.BeaconBlock{ParentRoot: randaomParentRoot}, + blk: ðpb.BeaconBlock{ParentRoot: randomParentRoot}, s: &pb.BeaconState{}, wantErrString: "block from slot 0 is not a descendent of the current finalized block", }, { name: "same slot as finalized block", - blk: ðpb.BeaconBlock{Slot: 0, ParentRoot: validGenesisRoot}, + blk: ðpb.BeaconBlock{Slot: 0, ParentRoot: randomParentRoot2}, s: &pb.BeaconState{}, wantErrString: "block is equal or earlier than finalized block, slot 0 < slot 0", }, diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 11ec6833f..a00a01279 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -36,7 +36,7 @@ func (c *ChainService) ReceiveAttestation(ctx context.Context, att *ethpb.Attest } log.WithFields(logrus.Fields{ "attDataRoot": hex.EncodeToString(att.Data.BeaconBlockRoot), - }).Info("Broadcasting attestation") + }).Debug("Broadcasting attestation") if err := c.ReceiveAttestationNoPubsub(ctx, att); err != nil { return err @@ -68,7 +68,7 @@ func (c *ChainService) ReceiveAttestationNoPubsub(ctx context.Context, att *ethp log.WithFields(logrus.Fields{ "attSlot": slot, "attDataRoot": hex.EncodeToString(att.Data.BeaconBlockRoot), - }).Info("Finished updating fork choice store for attestation") + }).Debug("Finished updating fork choice store for attestation") // Run fork choice for head block after updating fork choice store. headRoot, err := c.forkChoiceStore.Head(ctx) @@ -82,7 +82,7 @@ func (c *ChainService) ReceiveAttestationNoPubsub(ctx context.Context, att *ethp log.WithFields(logrus.Fields{ "headSlot": headBlk.Slot, "headRoot": hex.EncodeToString(headRoot), - }).Info("Finished applying fork choice") + }).Debug("Finished applying fork choice") isCompetingAtts(att.Data.BeaconBlockRoot[:], headRoot) diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index ecd936eab..486991431 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -257,7 +257,7 @@ func (c *ChainService) saveHead(ctx context.Context, b *ethpb.BeaconBlock, r [32 log.WithFields(logrus.Fields{ "slots": b.Slot, "root": hex.EncodeToString(r[:]), - }).Info("Saved head info") + }).Debug("Saved head info") return nil }