protocol

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadBlock is returned when a block is invalid.
	ErrBadBlock = errors.New("invalid block")

	// ErrStaleState is returned when the Chain does not have a current
	// blockchain state.
	ErrStaleState = errors.New("stale blockchain state")

	// ErrBadStateRoot is returned when the computed assets merkle root
	// disagrees with the one declared in a block header.
	ErrBadStateRoot = errors.New("invalid state merkle root")
)
View Source
var ErrBadTx = errors.New("invalid transaction")

ErrBadTx is returned for transactions failing validation

View Source
var (
	// ErrTheDistantFuture is returned when waiting for a blockheight
	// too far in excess of the tip of the blockchain.
	ErrTheDistantFuture = errors.New("block height too far in future")
)
View Source
var (
	ErrTransactionNotExist = errors.New("transaction are not existed in the mempool")
)

Functions

This section is empty.

Types

type Chain

type Chain struct {
	InitialBlockHash  bc.Hash
	MaxIssuanceWindow time.Duration // only used by generators
	// contains filtered or unexported fields
}

Chain provides a complete, minimal blockchain database. It delegates the underlying storage to other objects, and uses validation logic from package validation to decide what objects can be safely stored.

func NewChain

func NewChain(ctx context.Context, initialBlockHash bc.Hash, store Store, txPool *TxPool, heights <-chan uint64) (*Chain, error)

NewChain returns a new Chain using store as the underlying storage.

func (*Chain) AddBlock

func (c *Chain) AddBlock(ctx context.Context, block *legacy.Block) error

func (*Chain) ApplyValidBlock

func (c *Chain) ApplyValidBlock(block *legacy.Block) (*state.Snapshot, error)

ApplyValidBlock creates an updated snapshot without validating the block.

func (*Chain) BlockSoonWaiter

func (c *Chain) BlockSoonWaiter(ctx context.Context, height uint64) <-chan error

BlockSoonWaiter returns a channel that waits for the block at the given height, but it is an error to wait for a block far in the future. WaitForBlockSoon will timeout if the context times out. To wait unconditionally, the caller should use WaitForBlock.

func (*Chain) BlockWaiter

func (c *Chain) BlockWaiter(height uint64) <-chan struct{}

BlockWaiter returns a channel that waits for the block at the given height.

func (*Chain) CommitAppliedBlock

func (c *Chain) CommitAppliedBlock(ctx context.Context, block *legacy.Block, snapshot *state.Snapshot) error

CommitBlock commits a block to the blockchain. The block must already have been applied with ApplyValidBlock or ApplyNewBlock, which will have produced the new snapshot that's required here.

This function saves the block to the store and sometimes (not more often than saveSnapshotFrequency) saves the state tree to the store. New-block callbacks (via asynchronous block-processor pins) are triggered.

TODO(bobg): rename to CommitAppliedBlock for clarity (deferred from https://github.com/chain/chain/pull/788)

func (*Chain) GetAssetsAmount

func (c *Chain) GetAssetsAmount() []interface{}

func (*Chain) GetBlock

func (c *Chain) GetBlock(height uint64) (*legacy.Block, error)

GetBlock returns the block at the given height, if there is one, otherwise it returns an error.

func (*Chain) GetStore

func (c *Chain) GetStore() *Store

func (*Chain) Height

func (c *Chain) Height() uint64

Height returns the current height of the blockchain.

func (*Chain) Recover

func (c *Chain) Recover(ctx context.Context) (*legacy.Block, *state.Snapshot, error)

Recover performs crash recovery, restoring the blockchain to a complete state. It returns the latest confirmed block and the corresponding state snapshot.

If the blockchain is empty (missing initial block), this function returns a nil block and an empty snapshot.

func (*Chain) SetAssetsAmount

func (c *Chain) SetAssetsAmount(block *legacy.Block)

func (*Chain) State

func (c *Chain) State() (*legacy.Block, *state.Snapshot)

State returns the most recent state available. It will not be current unless the current process is the leader. Callers should examine the returned block header's height if they need to verify the current state.

func (*Chain) TimestampMS

func (c *Chain) TimestampMS() uint64

TimestampMS returns the latest known block timestamp.

func (*Chain) ValidateBlock

func (c *Chain) ValidateBlock(block, prev *legacy.Block) error

ValidateBlock validates an incoming block in advance of applying it to a snapshot (with ApplyValidBlock) and committing it to the blockchain (with CommitAppliedBlock).

func (*Chain) ValidateTx

func (c *Chain) ValidateTx(tx *legacy.Tx) error

ValidateTx validates the given transaction. A cache holds per-transaction validation results and is consulted before performing full validation.

type Store

type Store interface {
	Height() uint64
	GetBlock(uint64) (*legacy.Block, error)
	LatestSnapshot(context.Context) (*state.Snapshot, uint64, error)

	SaveBlock(*legacy.Block) error
	FinalizeBlock(context.Context, uint64) error
	SaveSnapshot(context.Context, uint64, *state.Snapshot) error
}

Store provides storage for blockchain data: blocks and state tree snapshots.

Note, this is different from a state snapshot. A state snapshot provides access to the state at a given point in time -- outputs and issuance memory. The Chain type uses Store to load state from storage and persist validated data.

type TxDesc

type TxDesc struct {
	Tx       *legacy.Tx
	Added    time.Time
	Height   uint64
	Weight   uint64
	Fee      uint64
	FeePerKB uint64
}

type TxPool

type TxPool struct {
	// contains filtered or unexported fields
}

func NewTxPool

func NewTxPool() *TxPool

func (*TxPool) AddErrCache

func (mp *TxPool) AddErrCache(txHash *bc.Hash, err error)

func (*TxPool) AddTransaction

func (mp *TxPool) AddTransaction(tx *legacy.Tx, height, fee uint64) *TxDesc

func (*TxPool) Count

func (mp *TxPool) Count() int

func (*TxPool) GetErrCache

func (mp *TxPool) GetErrCache(txHash *bc.Hash) error

func (*TxPool) GetNewTxCh

func (mp *TxPool) GetNewTxCh() chan *legacy.Tx

func (*TxPool) GetTransaction

func (mp *TxPool) GetTransaction(txHash *bc.Hash) (*TxDesc, error)

func (*TxPool) GetTransactions

func (mp *TxPool) GetTransactions() []*TxDesc

func (*TxPool) HaveTransaction

func (mp *TxPool) HaveTransaction(txHash *bc.Hash) bool

func (*TxPool) IsTransactionInErrCache

func (mp *TxPool) IsTransactionInErrCache(txHash *bc.Hash) bool

func (*TxPool) IsTransactionInPool

func (mp *TxPool) IsTransactionInPool(txHash *bc.Hash) bool

func (*TxPool) RemoveTransaction

func (mp *TxPool) RemoveTransaction(txHash *bc.Hash)

Directories

Path Synopsis
bc
Package bc is a generated protocol buffer package.
Package bc is a generated protocol buffer package.
bctest
Package bctest provides utilities for constructing blockchain data structures.
Package bctest provides utilities for constructing blockchain data structures.
Package patricia computes the Merkle Patricia Tree Hash of a set of bit strings, as described in the Chain Protocol spec.
Package patricia computes the Merkle Patricia Tree Hash of a set of bit strings, as described in the Chain Protocol spec.
Package prottest provides utilities for Chain Protocol testing.
Package prottest provides utilities for Chain Protocol testing.
memstore
MemStore is a Store implementation that keeps all blockchain state in memory.
MemStore is a Store implementation that keeps all blockchain state in memory.
vm

Jump to

Keyboard shortcuts

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