Skip to content

Commit

Permalink
OnBlockCacheFilteredTree (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Jan 14, 2020
1 parent 0bee1de commit 6ef1a71
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
30 changes: 20 additions & 10 deletions beacon-chain/blockchain/forkchoice/process_block.go
Expand Up @@ -93,16 +93,6 @@ func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) er
return errors.Wrap(err, "could not save state")
}

if featureconfig.Get().EnableBlockTreeCache {
tree, err := s.getFilterBlockTree(ctx)
if err != nil {
return errors.Wrap(err, "could not calculate filtered block tree")
}
s.filteredBlockTreeLock.Lock()
s.filteredBlockTree = tree
s.filteredBlockTreeLock.Unlock()
}

// Update justified check point.
if postState.CurrentJustifiedCheckpoint.Epoch > s.justifiedCheckpt.Epoch {
if err := s.updateJustified(ctx, postState); err != nil {
Expand Down Expand Up @@ -155,6 +145,26 @@ func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) er
return nil
}

// OnBlockCacheFilteredTree calls OnBlock with additional of caching of filtered block tree
// for efficient fork choice processing.
func (s *Store) OnBlockCacheFilteredTree(ctx context.Context, signed *ethpb.SignedBeaconBlock) error {
if err := s.OnBlock(ctx, signed); err != nil {
return err
}

if featureconfig.Get().EnableBlockTreeCache {
tree, err := s.getFilterBlockTree(ctx)
if err != nil {
return errors.Wrap(err, "could not calculate filtered block tree")
}
s.filteredBlockTreeLock.Lock()
s.filteredBlockTree = tree
s.filteredBlockTreeLock.Unlock()
}

return nil
}

// OnBlockInitialSyncStateTransition is called when an initial sync block is received.
// It runs state transition on the block and without any BLS verification. The BLS verification
// includes proposer signature, randao and attestation's aggregated signature. It also does not save
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/blockchain/forkchoice/service.go
Expand Up @@ -28,6 +28,7 @@ import (
type ForkChoicer interface {
Head(ctx context.Context) ([]byte, error)
OnBlock(ctx context.Context, b *ethpb.SignedBeaconBlock) error
OnBlockCacheFilteredTree(ctx context.Context, b *ethpb.SignedBeaconBlock) error
OnBlockInitialSyncStateTransition(ctx context.Context, b *ethpb.SignedBeaconBlock) error
OnAttestation(ctx context.Context, a *ethpb.Attestation) error
GenesisStore(ctx context.Context, justifiedCheckpoint *ethpb.Checkpoint, finalizedCheckpoint *ethpb.Checkpoint) error
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/receive_block.go
Expand Up @@ -70,7 +70,7 @@ func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedB
blockCopy := proto.Clone(block).(*ethpb.SignedBeaconBlock)

// Apply state transition on the new block.
if err := s.forkChoiceStore.OnBlock(ctx, blockCopy); err != nil {
if err := s.forkChoiceStore.OnBlockCacheFilteredTree(ctx, blockCopy); err != nil {
err := errors.Wrap(err, "could not process block from fork choice service")
traceutil.AnnotateError(span, err)
return err
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/blockchain/service_test.go
Expand Up @@ -46,6 +46,10 @@ func (s *store) OnBlock(ctx context.Context, b *ethpb.SignedBeaconBlock) error {
return nil
}

func (s *store) OnBlockCacheFilteredTree(ctx context.Context, b *ethpb.SignedBeaconBlock) error {
return nil
}

func (s *store) OnBlockInitialSyncStateTransition(ctx context.Context, b *ethpb.SignedBeaconBlock) error {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/beacon/validators.go
Expand Up @@ -8,13 +8,13 @@ import (

ptypes "github.com/gogo/protobuf/types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/shared/pagination"
"github.com/prysmaticlabs/prysm/shared/params"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// ListValidatorBalances retrieves the validator balances for a given set of public keys.
Expand Down

0 comments on commit 6ef1a71

Please sign in to comment.