lock in receive block

This commit is contained in:
Raul Jordan
2019-04-03 12:13:47 -05:00
parent 880cf6382c
commit 151b10829d
3 changed files with 6 additions and 0 deletions

View File

@@ -39,6 +39,8 @@ type BlockProcessor interface {
// 4. Process and cleanup any block operations, such as attestations and deposits, which would need to be
// either included or flushed from the beacon node's runtime.
func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) (*pb.BeaconState, error) {
c.lock.Lock()
defer c.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "beacon-chain.blockchain.ReceiveBlock")
defer span.End()
beaconState, err := c.beaconDB.HistoricalStateFromSlot(ctx, block.Slot-1)

View File

@@ -122,6 +122,8 @@ func (c *ChainService) ApplyForkChoiceRule(
block *pb.BeaconBlock,
postState *pb.BeaconState,
) error {
c.lock.Lock()
defer c.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "beacon-chain.blockchain.ApplyForkChoiceRule")
defer span.End()
log.Info("Applying LMD-GHOST Fork Choice Rule")

View File

@@ -6,6 +6,7 @@ package blockchain
import (
"context"
"fmt"
"sync"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/attestation"
@@ -44,6 +45,7 @@ type ChainService struct {
finalizedEpoch uint64
stateInitializedFeed *event.Feed
p2p p2p.Broadcaster
lock sync.Mutex
}
// Config options for the service.