Skip to content

Commit

Permalink
Improve logging for block verification failure (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Oct 26, 2023
1 parent 787f0b6 commit 8463690
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand All @@ -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()))
Expand Down
6 changes: 5 additions & 1 deletion vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion vms/proposervm/pre_fork_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package proposervm

import (
"context"
"fmt"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8463690

Please sign in to comment.