Skip to content

Commit

Permalink
Improve logging of unexpected proposer errors (#2646)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 22, 2024
1 parent bd4b381 commit 7a309bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,14 @@ func (t *Transitive) addUnverifiedBlockToConsensus(
issuedMetric prometheus.Counter,
) (bool, error) {
blkID := blk.ID()
blkHeight := blk.Height()

// make sure this block is valid
if err := blk.Verify(ctx); err != nil {
t.Ctx.Log.Debug("block verification failed",
zap.Stringer("nodeID", nodeID),
zap.Stringer("blkID", blkID),
zap.Uint64("height", blkHeight),
zap.Error(err),
)

Expand All @@ -1143,6 +1145,7 @@ func (t *Transitive) addUnverifiedBlockToConsensus(
t.Ctx.Log.Verbo("adding block to consensus",
zap.Stringer("nodeID", nodeID),
zap.Stringer("blkID", blkID),
zap.Uint64("height", blkHeight),
)
return true, t.Consensus.Add(ctx, &memoryBlock{
Block: blk,
Expand Down
11 changes: 6 additions & 5 deletions vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (p *postForkCommonComponents) verifyPreDurangoBlockDelay(

delay := blkTimestamp.Sub(parentTimestamp)
if delay < minDelay {
return false, errProposerWindowNotStarted
return false, fmt.Errorf("%w: delay %s < minDelay %s", errProposerWindowNotStarted, delay, minDelay)
}

return delay < proposer.MaxVerifyDelay, nil
Expand All @@ -364,14 +364,15 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
var (
blkTimestamp = blk.Timestamp()
blkHeight = blk.Height()
currentSlot = proposer.TimeToSlot(parentTimestamp, blkTimestamp)
proposerID = blk.Proposer()
)

expectedProposerID, err := p.vm.Windower.ExpectedProposer(
ctx,
blkHeight,
parentPChainHeight,
proposer.TimeToSlot(parentTimestamp, blkTimestamp),
currentSlot,
)
switch {
case errors.Is(err, proposer.ErrAnyoneCanPropose):
Expand All @@ -386,7 +387,7 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
case expectedProposerID == proposerID:
return true, nil // block should be signed
default:
return false, errUnexpectedProposer
return false, fmt.Errorf("%w: slot %d expects %s", errUnexpectedProposer, currentSlot, expectedProposerID)
}
}

Expand Down Expand Up @@ -454,7 +455,7 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPostDurango(
// In case the inner VM only issued one pendingTxs message, we should
// attempt to re-handle that once it is our turn to build the block.
p.vm.notifyInnerBlockReady()
return false, errProposerWindowNotStarted
return false, fmt.Errorf("%w: slot %d expects %s", errUnexpectedProposer, currentSlot, expectedProposerID)
}

func (p *postForkCommonComponents) shouldBuildSignedBlockPreDurango(
Expand Down Expand Up @@ -499,5 +500,5 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPreDurango(
// In case the inner VM only issued one pendingTxs message, we should
// attempt to re-handle that once it is our turn to build the block.
p.vm.notifyInnerBlockReady()
return false, errProposerWindowNotStarted
return false, fmt.Errorf("%w: delay %s < minDelay %s", errProposerWindowNotStarted, delay, minDelay)
}
2 changes: 1 addition & 1 deletion vms/proposervm/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,6 @@ func TestPostDurangoBuildChildResetScheduler(t *testing.T) {
parentTimestamp,
pChainHeight-1,
)
require.ErrorIs(err, errProposerWindowNotStarted)
require.ErrorIs(err, errUnexpectedProposer)
}
}

0 comments on commit 7a309bc

Please sign in to comment.