diff --git a/beacon-chain/blockchain/forkchoice/BUILD.bazel b/beacon-chain/blockchain/forkchoice/BUILD.bazel index 5d19d2d48..a11835eaa 100644 --- a/beacon-chain/blockchain/forkchoice/BUILD.bazel +++ b/beacon-chain/blockchain/forkchoice/BUILD.bazel @@ -25,6 +25,7 @@ go_library( "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_go_ssz//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", + "@io_opencensus_go//trace:go_default_library", ], ) diff --git a/beacon-chain/blockchain/forkchoice/process_attestation.go b/beacon-chain/blockchain/forkchoice/process_attestation.go index 7c9637932..c8d54b55b 100644 --- a/beacon-chain/blockchain/forkchoice/process_attestation.go +++ b/beacon-chain/blockchain/forkchoice/process_attestation.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" + "go.opencensus.io/trace" ) // OnAttestation is called whenever an attestation is received, it updates validators latest vote, @@ -50,6 +51,9 @@ import ( // if i not in store.latest_messages or target.epoch > store.latest_messages[i].epoch: // store.latest_messages[i] = LatestMessage(epoch=target.epoch, root=attestation.data.beacon_block_root) func (s *Store) OnAttestation(ctx context.Context, a *ethpb.Attestation) error { + ctx, span := trace.StartSpan(ctx, "forkchoice.onAttestation") + defer span.End() + tgt := a.Data.Target tgtSlot := helpers.StartSlot(tgt.Epoch) diff --git a/beacon-chain/blockchain/forkchoice/process_block.go b/beacon-chain/blockchain/forkchoice/process_block.go index b263b52fe..8d13fa786 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" + "go.opencensus.io/trace" ) // OnBlock is called whenever a block is received. It runs state transition on the block and @@ -48,6 +49,9 @@ import ( // if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch: // store.finalized_checkpoint = state.finalized_checkpoint func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error { + ctx, span := trace.StartSpan(ctx, "forkchoice.onBlock") + defer span.End() + // Verify incoming block has a valid pre state. preState, err := s.verifyBlkPreState(ctx, b) if err != nil { diff --git a/beacon-chain/blockchain/forkchoice/service.go b/beacon-chain/blockchain/forkchoice/service.go index 1cda67d6c..55c275306 100644 --- a/beacon-chain/blockchain/forkchoice/service.go +++ b/beacon-chain/blockchain/forkchoice/service.go @@ -16,6 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" + "go.opencensus.io/trace" ) // ForkChoicer defines a common interface for methods useful for directly applying fork choice @@ -111,6 +112,9 @@ func (s *Store) GenesisStore(ctx context.Context, genesisState *pb.BeaconState) // assert block.slot >= slot // return root if block.slot == slot else get_ancestor(store, block.parent_root, slot) func (s *Store) ancestor(ctx context.Context, root []byte, slot uint64) ([]byte, error) { + ctx, span := trace.StartSpan(ctx, "forkchoice.ancestor") + defer span.End() + b, err := s.db.Block(ctx, bytesutil.ToBytes32(root)) if err != nil { return nil, errors.Wrap(err, "could not get ancestor block") @@ -141,6 +145,9 @@ func (s *Store) ancestor(ctx context.Context, root []byte, slot uint64) ([]byte, // and get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root) // )) func (s *Store) latestAttestingBalance(ctx context.Context, root []byte) (uint64, error) { + ctx, span := trace.StartSpan(ctx, "forkchoice.latestAttestingBalance") + defer span.End() + s.lock.RLock() defer s.lock.RUnlock() h, err := hashutil.HashProto(s.justifiedCheckpt) @@ -206,6 +213,9 @@ func (s *Store) latestAttestingBalance(ctx context.Context, root []byte) (uint64 // # Sort by latest attesting balance with ties broken lexicographically // head = max(children, key=lambda root: (get_latest_attesting_balance(store, root), root)) func (s *Store) Head(ctx context.Context) ([]byte, error) { + ctx, span := trace.StartSpan(ctx, "forkchoice.head") + defer span.End() + head := s.justifiedCheckpt.Root for {