Runtime Fixes (#3300)

This commit is contained in:
Nishant Das 2019-08-24 18:56:25 +05:30 committed by terence tsao
parent 111f225177
commit 9d15196bed
5 changed files with 27 additions and 10 deletions

View File

@ -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

View File

@ -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)

View File

@ -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: &ethpb.BeaconBlock{ParentRoot: randaomParentRoot, Slot: params.BeaconConfig().FarFutureEpoch},
blk: &ethpb.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: &ethpb.BeaconBlock{ParentRoot: randaomParentRoot},
blk: &ethpb.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: &ethpb.BeaconBlock{Slot: 0, ParentRoot: validGenesisRoot},
blk: &ethpb.BeaconBlock{Slot: 0, ParentRoot: randomParentRoot2},
s: &pb.BeaconState{},
wantErrString: "block is equal or earlier than finalized block, slot 0 < slot 0",
},

View File

@ -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)

View File

@ -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
}