validation

package
v0.0.0-...-4e0ae02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2016 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package validation implements the Chain Protocol blockchain validation logic.

https://github.com/chain/cp1/blob/main/validation.md

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func ApplyBlock(snapshot *state.Snapshot, block *bc.Block) error

ApplyBlock applies the transactions in the block to the state tree.

func ApplyTx

func ApplyTx(snapshot *state.Snapshot, tx *bc.Tx) error

ApplyTx updates the state tree with all the changes to the ledger.

func CalcMerkleRoot

func CalcMerkleRoot(transactions []*bc.Tx) bc.Hash

CalcMerkleRoot creates a merkle tree from a slice of transactions and returns the root hash of the tree.

func CheckTxWellFormed

func CheckTxWellFormed(tx *bc.Tx) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL