Documentation ¶
Overview ¶
Package validation implements the Chain Protocol blockchain validation logic.
Index ¶
- Variables
- func ApplyBlock(snapshot *state.Snapshot, block *bc.Block) error
- func ApplyTx(snapshot *state.Snapshot, tx *bc.Tx) error
- func CalcMerkleRoot(transactions []*bc.Tx) bc.Hash
- func CheckTxWellFormed(tx *bc.Tx) error
- func ConfirmTx(snapshot *state.Snapshot, initialBlockHash bc.Hash, block *bc.Block, tx *bc.Tx) error
- func ValidateBlock(ctx context.Context, snapshot *state.Snapshot, initialBlockHash bc.Hash, ...) error
- func ValidateBlockForAccept(ctx context.Context, snapshot *state.Snapshot, initialBlockHash bc.Hash, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadPrevHash = errors.New("invalid previous block hash") ErrBadHeight = errors.New("invalid block height") ErrBadTimestamp = errors.New("invalid block timestamp") ErrBadScript = errors.New("unspendable block script") ErrBadSig = errors.New("invalid signature script") ErrBadTxRoot = errors.New("invalid transaction merkle root") ErrBadStateRoot = errors.New("invalid state merkle root") )
Errors returned by the block validation functions.
var ( // ErrBadTx is returned for transactions failing validation ErrBadTx = errors.New("invalid transaction") // ErrFalseVMResult is one of the ways for a transaction to fail validation ErrFalseVMResult = errors.New("false VM result") )
Functions ¶
func ApplyBlock ¶
ApplyBlock applies the transactions in the block to the state tree.
func CalcMerkleRoot ¶
CalcMerkleRoot creates a merkle tree from a slice of transactions and returns the root hash of the tree.
func CheckTxWellFormed ¶
CheckTxWellFormed checks whether tx is "well-formed" (the context-free phase of validation): - inputs and outputs balance - no duplicate input commitments - input scripts pass
Result is nil for well-formed transactions, ErrBadTx with supporting detail otherwise.
func ConfirmTx ¶
func ConfirmTx(snapshot *state.Snapshot, initialBlockHash bc.Hash, block *bc.Block, tx *bc.Tx) error
ConfirmTx validates the given transaction against the given state tree before it's added to a block. If tx is invalid, it returns a non-nil error describing why.
Tx must already have undergone the well-formedness check in CheckTxWellFormed. This should have happened when the tx was added to the pool.
ConfirmTx must not mutate the snapshot or the block.
func ValidateBlock ¶
func ValidateBlock(ctx context.Context, snapshot *state.Snapshot, initialBlockHash bc.Hash, prevBlock, block *bc.Block, validateTx func(*bc.Tx) error) error
ValidateBlock performs the "validate block" procedure from the spec, yielding a new state (recorded in the 'snapshot' argument). See $CHAIN/protocol/doc/spec/validation.md#validate-block. Note that it does not execute prevBlock's consensus program. (See ValidateBlockForAccept for that.)
func ValidateBlockForAccept ¶
func ValidateBlockForAccept(ctx context.Context, snapshot *state.Snapshot, initialBlockHash bc.Hash, prevBlock, block *bc.Block, validateTx func(*bc.Tx) error) error
ValidateBlockForAccept performs steps 1 and 2 of the "accept block" procedure from the spec. See $CHAIN/protocol/doc/spec/validation.md#accept-block. It evaluates the prevBlock's consensus program, then calls ValidateBlock.
Types ¶
This section is empty.