protocol

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: AGPL-3.0 Imports: 19 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")

	// 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 (

	// ErrTransactionNotExist is the pre-defined error message
	ErrTransactionNotExist = errors.New("transaction are not existed in the mempool")
	// ErrPoolIsFull indicates the pool is full
	ErrPoolIsFull = errors.New("transaction pool reach the max number")
)
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")
)

Functions

This section is empty.

Types

type BlockIndex added in v0.4.3

type BlockIndex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BlockIndex is the struct for help chain trace block chain as tree

func NewBlockIndex added in v0.4.3

func NewBlockIndex() *BlockIndex

NewBlockIndex will create a empty BlockIndex

func (*BlockIndex) AddNode added in v0.4.3

func (bi *BlockIndex) AddNode(node *BlockNode)

AddNode will add node to the index map

func (*BlockIndex) BestNode added in v0.4.3

func (bi *BlockIndex) BestNode() *BlockNode

func (*BlockIndex) BlockExist added in v0.4.3

func (bi *BlockIndex) BlockExist(hash *bc.Hash) bool

BlockExist check does the block existed in blockIndex

func (*BlockIndex) GetNode added in v0.4.3

func (bi *BlockIndex) GetNode(hash *bc.Hash) *BlockNode

GetNode will search node from the index map

func (*BlockIndex) InMainchain added in v0.4.3

func (bi *BlockIndex) InMainchain(hash bc.Hash) bool

TODO: THIS FUNCTION MIGHT BE DELETED

func (*BlockIndex) NodeByHeight added in v0.4.3

func (bi *BlockIndex) NodeByHeight(height uint64) *BlockNode

NodeByHeight returns the block node at the specified height.

func (*BlockIndex) SetMainChain added in v0.4.3

func (bi *BlockIndex) SetMainChain(node *BlockNode)

SetMainChain will set the the mainChain array

type BlockNode added in v0.4.3

type BlockNode struct {
	Hash bc.Hash // hash of the block.
	// contains filtered or unexported fields
}

BlockNode represents a block within the block chain and is primarily used to aid in selecting the best chain to be the main chain.

func NewBlockNode added in v0.4.3

func NewBlockNode(bh *types.BlockHeader, parent *BlockNode) (*BlockNode, error)

func (*BlockNode) CalcNextBits added in v0.4.3

func (node *BlockNode) CalcNextBits() uint64

CalcNextBits calculate the seed for next block

func (*BlockNode) CalcNextSeed added in v0.4.3

func (node *BlockNode) CalcNextSeed() *bc.Hash

CalcNextSeed calculate the seed for next block

func (*BlockNode) CalcPastMedianTime added in v0.4.3

func (node *BlockNode) CalcPastMedianTime() uint64

type BlockStoreStateJSON added in v0.4.3

type BlockStoreStateJSON struct {
	Height uint64
	Hash   *bc.Hash
}

BlockStoreStateJSON represents the core's db status

type Chain

type Chain struct {
	// 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(store Store, txPool *TxPool) (*Chain, error)

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

func (*Chain) BestBlockHash added in v0.1.4

func (c *Chain) BestBlockHash() *bc.Hash

BestBlockHash return the hash of the chain tail block

func (*Chain) BestBlockHeader added in v0.4.3

func (c *Chain) BestBlockHeader() *types.BlockHeader

BestBlock returns the chain tail block

func (*Chain) BlockExist added in v0.1.4

func (c *Chain) BlockExist(hash *bc.Hash) bool

BlockExist check is a block in chain or orphan

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) CalcNextBits added in v0.4.3

func (c *Chain) CalcNextBits(preBlock *bc.Hash) (uint64, error)

CalcNextBits return the seed for the given block

func (*Chain) CalcNextSeed added in v0.4.3

func (c *Chain) CalcNextSeed(preBlock *bc.Hash) (*bc.Hash, error)

CalcNextSeed return the seed for the given block

func (*Chain) ConnectBlock added in v0.1.4

func (c *Chain) ConnectBlock(block *types.Block) error

ConnectBlock append block to end of chain

func (*Chain) GetBlockByHash added in v0.1.4

func (c *Chain) GetBlockByHash(hash *bc.Hash) (*types.Block, error)

GetBlockByHash return a block by given hash

func (*Chain) GetBlockByHeight added in v0.1.4

func (c *Chain) GetBlockByHeight(height uint64) (*types.Block, error)

GetBlockByHeight return a block by given height

func (*Chain) GetTransactionStatus added in v0.4.1

func (c *Chain) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error)

GetTransactionStatus return the transaction status of give block

func (*Chain) GetTransactionsUtxo added in v0.3.0

func (c *Chain) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) error

GetTransactionsUtxo return all the utxos that related to the txs' inputs

func (*Chain) GetUtxo added in v0.3.0

func (c *Chain) GetUtxo(hash *bc.Hash) (*storage.UtxoEntry, error)

GetUtxo try to find the utxo status in db

func (*Chain) Height

func (c *Chain) Height() uint64

Height returns the current height of the blockchain.

func (*Chain) InMainChain added in v0.2.0

func (c *Chain) InMainChain(hash bc.Hash) bool

InMainChain checks wheather a block is in the main chain

func (*Chain) ProcessBlock added in v0.1.4

func (c *Chain) ProcessBlock(block *types.Block) (bool, error)

func (*Chain) SaveBlock added in v0.1.4

func (c *Chain) SaveBlock(block *types.Block) error

SaveBlock will validate and save block into storage

func (*Chain) ValidateTx

func (c *Chain) ValidateTx(tx *types.Tx) (bool, error)

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

type OrphanManage added in v0.1.4

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

OrphanManage is use to handle all the orphan block

func NewOrphanManage added in v0.1.4

func NewOrphanManage() *OrphanManage

NewOrphanManage return a new orphan block

func (*OrphanManage) Add added in v0.1.4

func (o *OrphanManage) Add(block *types.Block)

Add will add the block to OrphanManage

func (*OrphanManage) BlockExist added in v0.1.4

func (o *OrphanManage) BlockExist(hash *bc.Hash) bool

BlockExist check is the block in OrphanManage

func (*OrphanManage) Delete added in v0.1.4

func (o *OrphanManage) Delete(hash *bc.Hash)

Delete will delelte the block from OrphanManage

func (*OrphanManage) Get added in v0.1.4

func (o *OrphanManage) Get(hash *bc.Hash) (*types.Block, bool)

Get return the orphan block by hash

type Store

type Store interface {
	BlockExist(*bc.Hash) bool

	GetBlock(*bc.Hash) (*types.Block, error)
	GetStoreStatus() BlockStoreStateJSON
	GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error)
	GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error
	GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)

	LoadBlockIndex() (*BlockIndex, error)
	SaveBlock(*types.Block, *bc.TransactionStatus) error
	SaveChainStatus(*types.Block, *state.UtxoViewpoint) error
}

Store provides storage interface for blockchain data

type TxDesc

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

TxDesc store tx and related info for mining strategy

type TxPool

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

TxPool is use for store the unconfirmed transaction

func NewTxPool

func NewTxPool() *TxPool

NewTxPool init a new TxPool

func (*TxPool) AddErrCache

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

AddErrCache add a failed transaction record to lru cache

func (*TxPool) AddTransaction

func (tp *TxPool) AddTransaction(tx *types.Tx, gasOnlyTx bool, height, fee uint64) (*TxDesc, error)

AddTransaction add a verified transaction to pool

func (*TxPool) Count

func (tp *TxPool) Count() int

Count return number of transcation in pool

func (*TxPool) GetErrCache

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

GetErrCache return the error of the transaction

func (*TxPool) GetNewTxCh

func (tp *TxPool) GetNewTxCh() chan *types.Tx

GetNewTxCh return a unconfirmed transaction feed channel

func (*TxPool) GetTransaction

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

GetTransaction return the TxDesc by hash

func (*TxPool) GetTransactionUTXO added in v0.4.0

func (tp *TxPool) GetTransactionUTXO(tx *bc.Tx) *state.UtxoViewpoint

GetTransactionUTXO return unconfirmed utxo

func (*TxPool) GetTransactions

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

GetTransactions return all the transactions in the pool

func (*TxPool) HaveTransaction

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

HaveTransaction IsTransactionInErrCache check is transaction in errCache or pool

func (*TxPool) IsTransactionInErrCache

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

IsTransactionInErrCache check wheather a transaction in errCache or not

func (*TxPool) IsTransactionInPool

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

IsTransactionInPool check wheather a transaction in pool or not

func (*TxPool) RemoveTransaction

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

RemoveTransaction remove a transaction from the pool

Directories

Path Synopsis
bc
Package bc is a generated protocol buffer package.
Package bc is a generated protocol buffer package.
vm

Jump to

Keyboard shortcuts

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