BlockPrev performs those parts of block validation that require the previous block's header.
(b *bc.UnsignedBlock, prev *bc.BlockHeader)
| 127 | // BlockPrev performs those parts of block validation that require the |
| 128 | // previous block's header. |
| 129 | func BlockPrev(b *bc.UnsignedBlock, prev *bc.BlockHeader) error { |
| 130 | if b.Version < prev.Version { |
| 131 | return errors.WithDetailf(errVersionRegression, "previous block verson %d, current block version %d", prev.Version, b.Version) |
| 132 | } |
| 133 | if b.Height != prev.Height+1 { |
| 134 | return errors.WithDetailf(errMisorderedBlockHeight, "previous block height %d, current block height %d", prev.Height, b.Height) |
| 135 | } |
| 136 | if prev.Hash() != *b.PreviousBlockId { |
| 137 | return errors.WithDetailf(errMismatchedBlock, "previous block ID %x, current block wants %x", prev.Hash().Bytes(), b.PreviousBlockId.Bytes()) |
| 138 | } |
| 139 | if b.TimestampMs <= prev.TimestampMs { |
| 140 | return errors.WithDetailf(errMisorderedBlockTime, "previous block time %d, current block time %d", prev.TimestampMs, b.TimestampMs) |
| 141 | } |
| 142 | if b.RefsCount > prev.RefsCount+1 { |
| 143 | return errors.WithDetailf(errRefsCount, "previous block prevblocks %d, current block %d", prev.RefsCount, b.RefsCount) |
| 144 | } |
| 145 | return nil |
| 146 | } |