protocol

package
v4.8.11+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: AGPL-3.0 Imports: 20 Imported by: 16

Documentation

Index

Constants

View Source
const (
	MsgNewTx = iota
	MsgRemoveTx
)

msg type

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")
	// ErrDustTx indicates transaction is dust tx
	ErrDustTx = errors.New("transaction is dust tx")
)
View Source
var (
	// ErrDoubleSignBlock represent the consensus is double sign in same height of different block
	ErrDoubleSignBlock = errors.New("the consensus is double sign in same height of different block")
)
View Source
var (
	ErrNotFoundConsensusResult = errors.New("can't find the vote result by given sequence")
)

predefine errors

View Source
var ErrNotInitSubProtocolChainStatus = errors.New("node state of sub protocol has not been initialized")

ErrNotInitSubProtocolChainStatus represent the node state of sub protocol has not been initialized

Functions

This section is empty.

Types

type AssetFilter added in v1.1.0

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

AssetFilter is struct for allow open federation asset cross chain

func NewAssetFilter added in v1.1.0

func NewAssetFilter(whitelist string) *AssetFilter

NewAssetFilter returns a assetFilter according a whitelist, which is a strings list cancated via comma

func (*AssetFilter) IsDust added in v1.1.0

func (af *AssetFilter) IsDust(tx *types.Tx) bool

IsDust implements the DustFilterer interface. It filters a transaction as long as there is one asset neither BTM or in the whitelist No need to check the output assets types becauese they must have been cover in input assets types

type BlockStoreState

type BlockStoreState struct {
	Height             uint64
	Hash               *bc.Hash
	IrreversibleHeight uint64
	IrreversibleHash   *bc.Hash
}

BlockStoreState represents the core's db status

type Chain

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

Chain provides functions for working with the Bytom block chain.

func NewChain

func NewChain(store Store, txPool *TxPool, subProtocols []SubProtocol, eventDispatcher *event.Dispatcher) (*Chain, error)

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

func (*Chain) BestBlockHash

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

BestBlockHash return the hash of the main chain tail block

func (*Chain) BestBlockHeader

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

BestBlockHeader returns the chain best block header

func (*Chain) BestBlockHeight

func (c *Chain) BestBlockHeight() uint64

BestBlockHeight returns the current height of the blockchain.

func (*Chain) BlockExist

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

BlockExist check is a block in chain or orphan

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) GetBlockByHash

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

GetBlockByHash return a block by given hash

func (*Chain) GetBlockByHeight

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

GetBlockByHeight return a block by given height

func (*Chain) GetBlocker

func (c *Chain) GetBlocker(prevBlockHash *bc.Hash, timeStamp uint64) (string, error)

GetBlocker return blocker by specified timestamp

func (*Chain) GetConsensusResultByHash added in v0.3.0

func (c *Chain) GetConsensusResultByHash(blockHash *bc.Hash) (*state.ConsensusResult, error)

GetConsensusResultByHash return vote result by block hash

func (*Chain) GetHeaderByHash

func (c *Chain) GetHeaderByHash(hash *bc.Hash) (*types.BlockHeader, error)

GetHeaderByHash return a block header by given hash

func (*Chain) GetHeaderByHeight

func (c *Chain) GetHeaderByHeight(height uint64) (*types.BlockHeader, error)

GetHeaderByHeight return a block header by given height

func (*Chain) GetTransactionStatus

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

GetTransactionStatus return the transaction status of give block

func (*Chain) GetTransactionsUtxo

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

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

func (*Chain) GetTxPool

func (c *Chain) GetTxPool() *TxPool

GetTxPool return chain txpool.

func (*Chain) InMainChain

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

InMainChain checks wheather a block is in the main chain

func (*Chain) LastIrreversibleHeader added in v0.3.0

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

LastIrreversibleHeader returns the chain last irreversible block header

func (*Chain) ProcessBlock

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

ProcessBlock is the entry for chain update

func (*Chain) ProcessBlockSignature

func (c *Chain) ProcessBlockSignature(signature, xPub []byte, blockHash *bc.Hash) error

ProcessBlockSignature process the received block signature messages return whether a block become irreversible, if so, the chain module must update status

func (*Chain) Rollback added in v1.1.0

func (c *Chain) Rollback(targetHeight uint64) error

Rollback rollback the chain from one blockHeight to targetBlockHeight WARNING: we recommend to use this only in commond line

func (*Chain) SignBlockHeader added in v1.0.5

func (c *Chain) SignBlockHeader(blockHeader *types.BlockHeader) error

SignBlockHeader signing the block if current node is consensus node

func (*Chain) SubProtocols added in v1.0.5

func (c *Chain) SubProtocols() []SubProtocol

SubProtocols return list of layer 2 consensus protocol

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 DustFilterer added in v1.0.5

type DustFilterer interface {
	IsDust(tx *types.Tx) bool
}

DustFilterer is inerface for dust transaction filter rule

type OrphanManage

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

OrphanManage is use to handle all the orphan block

func NewOrphanManage

func NewOrphanManage() *OrphanManage

NewOrphanManage return a new orphan block

func (*OrphanManage) Add

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

Add will add the block to OrphanManage

func (*OrphanManage) BlockExist

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

BlockExist check is the block in OrphanManage

func (*OrphanManage) Delete

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

Delete will delete the block from OrphanManage

func (*OrphanManage) Get

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

Get return the orphan block by hash

func (*OrphanManage) GetPrevOrphans

func (o *OrphanManage) GetPrevOrphans(hash *bc.Hash) ([]*bc.Hash, bool)

GetPrevOrphans return the list of child orphans

type Store

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

	GetBlock(*bc.Hash) (*types.Block, error)
	GetBlockHeader(*bc.Hash) (*types.BlockHeader, error)
	GetStoreStatus() *BlockStoreState
	GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error)
	GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error
	GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)
	GetConsensusResult(uint64) (*state.ConsensusResult, error)
	GetMainChainHash(uint64) (*bc.Hash, error)
	GetBlockHashesByHeight(uint64) ([]*bc.Hash, error)

	DeleteConsensusResult(uint64) error
	DeleteBlock(*types.Block) error
	SaveBlock(*types.Block, *bc.TransactionStatus) error
	SaveBlockHeader(*types.BlockHeader) error
	SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error
}

Store provides storage interface for blockchain data

type SubProtocol added in v1.1.1

type SubProtocol interface {
	Name() string
	StartHeight() uint64
	BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error)

	// ChainStatus return the the current block height and block hash of sub protocol.
	// it will return ErrNotInitSubProtocolChainStatus if not initialized.
	ChainStatus() (uint64, *bc.Hash, error)
	InitChainStatus(*bc.Hash) error
	ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
	ValidateTx(tx *types.Tx, verifyResult *bc.TxVerifyResult, blockHeight uint64) error
	ApplyBlock(block *types.Block) error
	DetachBlock(block *types.Block) error
}

SubProtocol is interface for layer 2 consensus protocol

type TxDesc

type TxDesc struct {
	Tx         *types.Tx `json:"transaction"`
	Added      time.Time `json:"-"`
	StatusFail bool      `json:"status_fail"`
	Height     uint64    `json:"-"`
	Weight     uint64    `json:"-"`
	Fee        uint64    `json:"-"`
}

TxDesc store tx and related info for mining strategy

type TxMsgEvent

type TxMsgEvent struct{ TxMsg *TxPoolMsg }

TxMsgEvent is message wrap for subscribe event

type TxPool

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

TxPool is use for store the unconfirmed transaction

func NewTxPool

func NewTxPool(store Store, filters []DustFilterer, dispatcher *event.Dispatcher) *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) GetErrCache

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

GetErrCache return the error of the transaction

func (*TxPool) GetTransaction

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

GetTransaction return the TxDesc by hash

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) IsDust

func (tp *TxPool) IsDust(tx *types.Tx) bool

IsDust checks if a tx has zero output

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) ProcessTransaction

func (tp *TxPool) ProcessTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error)

ProcessTransaction is the main entry for txpool handle new tx, ignore dust tx.

func (*TxPool) RemoveTransaction

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

RemoveTransaction remove a transaction from the pool

type TxPoolMsg

type TxPoolMsg struct {
	*TxDesc
	MsgType int
}

TxPoolMsg is use for notify pool changes

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