From 8463690a6fe6327e3a8d323d23170120ef4c3365 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 26 Oct 2023 00:12:05 -0400 Subject: [PATCH] Improve logging for block verification failure (#2224) --- snow/engine/snowman/transitive.go | 4 +++- vms/proposervm/block.go | 6 +++++- vms/proposervm/pre_fork_block.go | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 629ad0dc2be1..803c03237c96 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -965,9 +965,12 @@ func (t *Transitive) addToNonVerifieds(blk snowman.Block) { // addUnverifiedBlockToConsensus returns whether the block was added and an // error if one occurred while adding it to consensus. func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snowman.Block) (bool, error) { + blkID := blk.ID() + // make sure this block is valid if err := blk.Verify(ctx); err != nil { t.Ctx.Log.Debug("block verification failed", + zap.Stringer("blkID", blkID), zap.Error(err), ) @@ -976,7 +979,6 @@ func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snow return false, nil } - blkID := blk.ID() t.nonVerifieds.Remove(blkID) t.nonVerifiedCache.Evict(blkID) t.metrics.numNonVerifieds.Set(float64(t.nonVerifieds.Len())) diff --git a/vms/proposervm/block.go b/vms/proposervm/block.go index 1355eb46dd7b..f07362708611 100644 --- a/vms/proposervm/block.go +++ b/vms/proposervm/block.go @@ -135,7 +135,11 @@ func (p *postForkCommonComponents) Verify( return err } if childPChainHeight > currentPChainHeight { - return errPChainHeightNotReached + return fmt.Errorf("%w: %d > %d", + errPChainHeightNotReached, + childPChainHeight, + currentPChainHeight, + ) } childHeight := child.Height() diff --git a/vms/proposervm/pre_fork_block.go b/vms/proposervm/pre_fork_block.go index 0b11ef8e4716..ed665e473910 100644 --- a/vms/proposervm/pre_fork_block.go +++ b/vms/proposervm/pre_fork_block.go @@ -5,6 +5,7 @@ package proposervm import ( "context" + "fmt" "time" "go.uber.org/zap" @@ -128,7 +129,11 @@ func (b *preForkBlock) verifyPostForkChild(ctx context.Context, child *postForkB return err } if childPChainHeight > currentPChainHeight { - return errPChainHeightNotReached + return fmt.Errorf("%w: %d > %d", + errPChainHeightNotReached, + childPChainHeight, + currentPChainHeight, + ) } if childPChainHeight < b.vm.minimumPChainHeight { return errPChainHeightTooLow