chain

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//MaxAnchors = 32
	MaxAnchors = 1000000 //FIXME modify after implementing finder.fullscan
	Skip       = 8
)
View Source
const HashNumberUnknown = math.MaxUint64

TODO adhoc flag refactor it

View Source
const (
	TxBatchMax = 10000
)

Variables

View Source
var (
	ErrorBlockVerifySign      = errors.New("Block verify failed, because Tx sign is invalid")
	ErrorBlockVerifyTxRoot    = errors.New("Block verify failed, because Tx root hash is invaild")
	ErrorBlockVerifyStateRoot = errors.New("Block verify failed, because state root hash is not equal")
)
View Source
var (
	// ErrNoChainDB reports chaindb is not prepared.
	ErrNoChainDB       = fmt.Errorf("chaindb not prepared")
	ErrorLoadBestBlock = errors.New("failed to load latest block from DB")
)
View Source
var (
	ErrTxInvalidNonce        = errors.New("invalid nonce")
	ErrTxInsufficientBalance = errors.New("insufficient balance")
	ErrTxInvalidType         = errors.New("invalid type")
	ErrorNoAncestor          = errors.New("not found ancestor")

	InAddBlock = make(chan struct{}, 1)
)
View Source
var (
	// MaxBlockSize is the maximum size of a block.
	MaxBlockSize    uint32
	CoinbaseAccount []byte
	CoinbaseFee     uint64
	MaxAnchorCount  int
	UseFastSyncer   bool
)
View Source
var (
	ErrInvalidBranchRoot  = errors.New("best block can't be branch root block")
	ErrGatherChain        = errors.New("new/old blocks must exist")
	ErrNotExistBranchRoot = errors.New("branch root block doesn't exist")
	ErrInvalidSwapChain   = errors.New("New chain is not longer than old chain")
)
View Source
var (
	ErrTxFormatInvalid = errors.New("tx invalid format")

	DefaultVerifierCnt = runtime.NumCPU()
)
View Source
var (
	ErrBlockExist = errors.New("error! block already exist")
)
View Source
var (
	ErrInvalidCoinbaseAccount = errors.New("invalid coinbase account in config")
)

Functions

func Init

func Init(maxBlockSize uint32, coinbaseAccountStr string, coinbaseFee uint64, isBp bool, maxAnchorCount int, useFastSyncer bool) error

Init initializes the blockchain-related parameters.

func InitGenesisBPs

func InitGenesisBPs(states *state.StateDB, genesis *types.Genesis) error

InitGenesisBPs opens system contract and put initial voting result it also set *State in Genesis to use statedb

func SendRewardCoinbase

func SendRewardCoinbase(bState *state.BlockState, coinbaseAccount []byte) error

Types

type BlockValidator

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

func NewBlockValidator

func NewBlockValidator(sdb *state.ChainStateDB) *BlockValidator

func (*BlockValidator) Stop

func (bv *BlockValidator) Stop()

func (*BlockValidator) ValidateBlock

func (bv *BlockValidator) ValidateBlock(block *types.Block) error

func (*BlockValidator) ValidateBody

func (bv *BlockValidator) ValidateBody(block *types.Block) error

func (*BlockValidator) ValidateHeader

func (bv *BlockValidator) ValidateHeader(header *types.BlockHeader) error

func (*BlockValidator) ValidatePost

func (bv *BlockValidator) ValidatePost(sdbRoot []byte, receipts types.Receipts, block *types.Block) error

type ChainAnchor

type ChainAnchor []([]byte)

type ChainDB

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

func NewChainDB

func NewChainDB(cc consensus.ChainConsensus) *ChainDB

func (*ChainDB) Close

func (cdb *ChainDB) Close()

func (*ChainDB) Get

func (cdb *ChainDB) Get(key []byte) []byte

Get returns the value corresponding to key from the chain DB.

func (*ChainDB) GetBestBlock

func (cdb *ChainDB) GetBestBlock() (*types.Block, error)

func (*ChainDB) GetBlockByNo

func (cdb *ChainDB) GetBlockByNo(blockNo types.BlockNo) (*types.Block, error)

GetBlockByNo returns the block with its block number as blockNo.

func (*ChainDB) GetChainTree

func (cdb *ChainDB) GetChainTree() ([]byte, error)

func (*ChainDB) Init

func (cdb *ChainDB) Init(dbType string, dataDir string) error

type ChainInfo

type ChainInfo struct {
	Height types.BlockNo
	Hash   string
}

type ChainService

type ChainService struct {
	*component.BaseComponent
	consensus.ChainConsensus
	// contains filtered or unexported fields
}

ChainService manage connectivity of blocks

func NewChainService

func NewChainService(cfg *cfg.Config, cc consensus.ChainConsensus, pool *mempool.MemPool) *ChainService

NewChainService create instance of ChainService

func (*ChainService) AfterStart

func (cs *ChainService) AfterStart()

AfterStart ... do nothing

func (*ChainService) BeforeStart

func (cs *ChainService) BeforeStart()

BeforeStart initialize chain database and generate empty genesis block if necessary

func (*ChainService) BeforeStop

func (cs *ChainService) BeforeStop()

BeforeStop close chain database and stop BlockValidator

func (*ChainService) ChainSync

func (cs *ChainService) ChainSync(peerID peer.ID, remoteBestHash []byte)

ChainSync synchronize with peer

func (*ChainService) CloseDB

func (cs *ChainService) CloseDB()

CloseDB close chain database

func (*ChainService) CountTxsInChain

func (cs *ChainService) CountTxsInChain() int

func (*ChainService) GetBestBlock

func (cs *ChainService) GetBestBlock() (*types.Block, error)

func (*ChainService) GetBlock

func (cs *ChainService) GetBlock(blockHash []byte) (*types.Block, error)

func (*ChainService) GetChainTree

func (cs *ChainService) GetChainTree() ([]byte, error)

func (*ChainService) GetHashByNo added in v0.8.1

func (cs *ChainService) GetHashByNo(blockNo types.BlockNo) ([]byte, error)

func (*ChainService) InitGenesisBlock

func (cs *ChainService) InitGenesisBlock(gb *types.Genesis, dbType string, dataDir string) error

InitGenesisBlock initialize chain database and generate specified genesis block if necessary

func (*ChainService) Receive

func (cs *ChainService) Receive(context actor.Context)

Receive actor message

func (*ChainService) Statistics

func (cs *ChainService) Statistics() *map[string]interface{}

type ChainTree

type ChainTree struct {
	Tree []ChainInfo
}

type ErrBlock added in v0.8.1

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

func (*ErrBlock) Error added in v0.8.1

func (ec *ErrBlock) Error() string

type ErrNoBlock

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

ErrNoBlock reports there is no such a block with id (hash or block number).

func (ErrNoBlock) Error

func (e ErrNoBlock) Error() string

type ErrReorgBlock

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

func (*ErrReorgBlock) Error

func (ec *ErrReorgBlock) Error() string

type ErrTx

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

func (*ErrTx) Error

func (ec *ErrTx) Error() string

type OrphanBlock

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

type OrphanPool

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

func NewOrphanPool

func NewOrphanPool() *OrphanPool

type SignVerifier

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

func NewSignVerifier

func NewSignVerifier(workerCnt int) *SignVerifier

func (*SignVerifier) Stop

func (sv *SignVerifier) Stop()

func (*SignVerifier) VerifyTxs

func (sv *SignVerifier) VerifyTxs(txlist *types.TxList) (bool, []error)

type TxExecFn

type TxExecFn func(bState *state.BlockState, tx *types.Tx) error

func NewTxExecutor

func NewTxExecutor(blockNo types.BlockNo, ts int64, preLoadService int) TxExecFn

NewTxExecutor returns a new TxExecFn.

type ValidatePostFn

type ValidatePostFn func() error

type VerifyResult

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

Jump to

Keyboard shortcuts

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