blockchain: Validate early votebits in header sanity.

This moves the test for validating that the vote bits specified by the
header are a specific value before reaching stake validation height into
the checkBlockHeaderSanity function where it more naturally belongs
since it is solely dependent on the header.
This commit is contained in:
Dave Collins 2018-02-01 21:11:56 -06:00
parent 199e24047a
commit d32cb96c47
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -410,8 +410,8 @@ func checkBlockHeaderSanity(header *wire.BlockHeader, timeSource MedianTimeSourc
return ruleError(ErrTimeTooNew, str)
}
// The block must not contain any votes or revocations before stake
// validation begins.
// A block must not contain any votes or revocations and its vote bits
// must be 0x0001 before stake validation begins.
if header.Height < stakeValidationHeight {
if header.Voters > 0 {
errStr := fmt.Sprintf("block at height %d commits to "+
@ -420,6 +420,7 @@ func checkBlockHeaderSanity(header *wire.BlockHeader, timeSource MedianTimeSourc
stakeValidationHeight)
return ruleError(ErrInvalidEarlyStakeTx, errStr)
}
if header.Revocations > 0 {
errStr := fmt.Sprintf("block at height %d commits to "+
"%d revocations before stake validation height %d",
@ -427,6 +428,15 @@ func checkBlockHeaderSanity(header *wire.BlockHeader, timeSource MedianTimeSourc
stakeValidationHeight)
return ruleError(ErrInvalidEarlyStakeTx, errStr)
}
if header.VoteBits != earlyVoteBitsValue {
errStr := fmt.Sprintf("block at height %d commits to "+
"invalid vote bits before stake validation "+
"height %d (expected %x, got %x)",
header.Height, stakeValidationHeight,
earlyVoteBitsValue, header.VoteBits)
return ruleError(ErrInvalidEarlyVoteBits, errStr)
}
}
// A block must not contain more votes than the minimum required to
@ -658,18 +668,6 @@ func checkBlockSanity(block *dcrutil.Block, timeSource MedianTimeSource, flags B
}
}
// Blocks before stake validation height may only have 0x0001 as their
// VoteBits in the header.
if int64(header.Height) < chainParams.StakeValidationHeight {
if header.VoteBits != earlyVoteBitsValue {
str := fmt.Sprintf("pre stake validation height "+
"block %v contained an invalid votebits value"+
" (expected %v, got %v)", block.Hash(),
earlyVoteBitsValue, header.VoteBits)
return ruleError(ErrInvalidEarlyVoteBits, str)
}
}
return nil
}