MCPcopy Create free account
hub / github.com/chain/txvm / BlockPrev

Function BlockPrev

protocol/validation/validation.go:129–146  ·  view source on GitHub ↗

BlockPrev performs those parts of block validation that require the previous block's header.

(b *bc.UnsignedBlock, prev *bc.BlockHeader)

Source from the content-addressed store, hash-verified

127// BlockPrev performs those parts of block validation that require the
128// previous block's header.
129func 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}

Callers 2

TestBlockPrevFunction · 0.85
BlockFunction · 0.85

Calls 3

WithDetailfFunction · 0.92
HashMethod · 0.45
BytesMethod · 0.45

Tested by 1

TestBlockPrevFunction · 0.68