From cd6d4d90602f9327465e0e604d6d21376212c00d Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 21 Oct 2020 08:14:26 -0700 Subject: [PATCH 1/2] Add spans for AncestorRoot --- beacon-chain/blockchain/process_block_helpers.go | 11 +++++++---- beacon-chain/forkchoice/protoarray/store.go | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index 7979252d81e2..f23016e433b0 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -25,7 +25,7 @@ func (s *Service) CurrentSlot() uint64 { // to retrieve the state in DB. It verifies the pre state's validity and the incoming block // is in the correct time window. func (s *Service) getBlockPreState(ctx context.Context, b *ethpb.BeaconBlock) (*stateTrie.BeaconState, error) { - ctx, span := trace.StartSpan(ctx, "forkChoice.getBlockPreState") + ctx, span := trace.StartSpan(ctx, "blockChain.getBlockPreState") defer span.End() // Verify incoming block has a valid pre state. @@ -56,7 +56,7 @@ func (s *Service) getBlockPreState(ctx context.Context, b *ethpb.BeaconBlock) (* // verifyBlkPreState validates input block has a valid pre-state. func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) error { - ctx, span := trace.StartSpan(ctx, "chainService.verifyBlkPreState") + ctx, span := trace.StartSpan(ctx, "blockChain.verifyBlkPreState") defer span.End() parentRoot := bytesutil.ToBytes32(b.ParentRoot) @@ -87,7 +87,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) e // VerifyBlkDescendant validates input block root is a descendant of the // current finalized block root. func (s *Service) VerifyBlkDescendant(ctx context.Context, root [32]byte) error { - ctx, span := trace.StartSpan(ctx, "forkChoice.VerifyBlkDescendant") + ctx, span := trace.StartSpan(ctx, "blockChain.VerifyBlkDescendant") defer span.End() fRoot := s.ensureRootNotZeros(bytesutil.ToBytes32(s.finalizedCheckpt.Root)) finalizedBlkSigned, err := s.beaconDB.Block(ctx, fRoot) @@ -255,7 +255,7 @@ func (s *Service) updateFinalized(ctx context.Context, cp *ethpb.Checkpoint) err // # root is older than queried slot, thus a skip slot. Return most recent root prior to slot // return root func (s *Service) ancestor(ctx context.Context, root []byte, slot uint64) ([]byte, error) { - ctx, span := trace.StartSpan(ctx, "forkChoice.ancestor") + ctx, span := trace.StartSpan(ctx, "blockChain.ancestor") defer span.End() r := bytesutil.ToBytes32(root) @@ -276,6 +276,9 @@ func (s *Service) ancestor(ctx context.Context, root []byte, slot uint64) ([]byt // This retrieves an ancestor root using fork choice store. The look up is looping through the a flat array structure. func (s *Service) ancestorByForkChoiceStore(ctx context.Context, r [32]byte, slot uint64) ([]byte, error) { + ctx, span := trace.StartSpan(ctx, "blockChain.ancestorByForkChoiceStore") + defer span.End() + if !s.forkChoiceStore.HasParent(r) { return nil, errors.New("could not find root in fork choice store") } diff --git a/beacon-chain/forkchoice/protoarray/store.go b/beacon-chain/forkchoice/protoarray/store.go index 33a87637d33f..16ea00cbb0c9 100644 --- a/beacon-chain/forkchoice/protoarray/store.go +++ b/beacon-chain/forkchoice/protoarray/store.go @@ -160,6 +160,9 @@ func (f *ForkChoice) HasParent(root [32]byte) bool { // AncestorRoot returns the ancestor root of input block root at a given slot. func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot uint64) ([]byte, error) { + ctx, span := trace.StartSpan(ctx, "protoArray.AncestorRoot") + defer span.End() + f.store.nodesLock.RLock() defer f.store.nodesLock.RUnlock() From b47e41638d0d91411bbcb58dfd4e536b72ee30d9 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 21 Oct 2020 08:24:40 -0700 Subject: [PATCH 2/2] Add span for ancestor by DB --- beacon-chain/blockchain/process_block_helpers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index f23016e433b0..f8967fcd537d 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -287,6 +287,9 @@ func (s *Service) ancestorByForkChoiceStore(ctx context.Context, r [32]byte, slo // This retrieves an ancestor root using DB. The look up is recursively looking up DB. Slower than `ancestorByForkChoiceStore`. func (s *Service) ancestorByDB(ctx context.Context, r [32]byte, slot uint64) ([]byte, error) { + ctx, span := trace.StartSpan(ctx, "blockChain.ancestorByDB") + defer span.End() + // Stop recursive ancestry lookup if context is cancelled. if ctx.Err() != nil { return nil, ctx.Err()