| 498 | } |
| 499 | |
| 500 | func 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. |
| 517 | func ValidateTx(tx *bc.Tx, initialBlockID bc.Hash) error { |