MCPcopy Create free account
hub / github.com/chain/Core / validateBlockAgainstPrev

Function validateBlockAgainstPrev

protocol/validation/validation.go:500–514  ·  view source on GitHub ↗
(b, prev *bc.Block)

Source from the content-addressed store, hash-verified

498}
499
500func validateBlockAgainstPrev(b, prev *bc.Block) error {
501 if b.Version < prev.Version {
502 return errors.WithDetailf(errVersionRegression, "previous block verson %d, current block version %d", prev.Version, b.Version)
503 }
504 if b.Height != prev.Height+1 {
505 return errors.WithDetailf(errMisorderedBlockHeight, "previous block height %d, current block height %d", prev.Height, b.Height)
506 }
507 if prev.ID != *b.PreviousBlockId {
508 return errors.WithDetailf(errMismatchedBlock, "previous block ID %x, current block wants %x", prev.ID.Bytes(), b.PreviousBlockId.Bytes())
509 }
510 if b.TimestampMs <= prev.TimestampMs {
511 return errors.WithDetailf(errMisorderedBlockTime, "previous block time %d, current block time %d", prev.TimestampMs, b.TimestampMs)
512 }
513 return nil
514}
515
516// ValidateTx validates a transaction.
517func ValidateTx(tx *bc.Tx, initialBlockID bc.Hash) error {

Callers 1

ValidateBlockFunction · 0.85

Calls 1

BytesMethod · 0.45

Tested by

no test coverage detected