Documentation ¶
Overview ¶
Package snailchain implements the taichain snailchain protocol.
Index ¶
- Variables
- func GenerateChain(config *params.ChainConfig, fastChain *core.BlockChain, ...) []*types.SnailBlock
- func MakeSnailBlock(chain *SnailBlockChain, fastchain *core.BlockChain, parent *types.SnailBlock, ...) (*types.SnailBlock, error)
- func MakeSnailBlockBlockChain(chain *SnailBlockChain, fastchain *core.BlockChain, parent *types.SnailBlock, ...) ([]*types.SnailBlock, error)
- func MakeSnailBlockFruit(chain *SnailBlockChain, fastchain *core.BlockChain, makeBlockNum int, ...) (*types.SnailBlock, error)
- func MakeSnailBlockFruits(chain *SnailBlockChain, fastchain *core.BlockChain, makeStarblockNumber int, ...) ([]*types.SnailBlock, error)
- func MakeSnailBlockFruitsWithoutInsert(chain *SnailBlockChain, fastchain *core.BlockChain, makeStarblockNumber int, ...) ([]*types.SnailBlock, error)
- func MakeSnailBlocks(fastchain *core.BlockChain, snailchain *SnailBlockChain, ...) ([]*types.SnailBlock, error)
- type BlockGen
- func (b *BlockGen) AddFruit(block *types.SnailBlock)
- func (b *BlockGen) AddUncle(h *types.SnailHeader)
- func (b *BlockGen) Number() *big.Int
- func (b *BlockGen) OffsetTime(seconds int64)
- func (b *BlockGen) PrevBlock(index int) *types.SnailBlock
- func (b *BlockGen) SetCoinbase(addr common.Address)
- func (b *BlockGen) SetExtra(data []byte)
- type BlockValidator
- func (v *BlockValidator) ValidateBody(block *types.SnailBlock, verifyFruits bool) error
- func (v *BlockValidator) ValidateFruit(fruit *types.SnailBlock, headerNumber *big.Int, canonical bool) error
- func (v *BlockValidator) ValidateRewarded(number uint64, hash common.Hash) error
- func (v *BlockValidator) VerifySnailSeal(chain consensus.SnailChainReader, header *types.SnailHeader, isFruit bool) error
- type ChainIndexer
- func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer)
- func (c *ChainIndexer) AddKnownSectionHead(section uint64, shead common.Hash)
- func (c *ChainIndexer) Close() error
- func (c *ChainIndexer) SectionHead(section uint64) common.Hash
- func (c *ChainIndexer) Sections() (uint64, uint64, common.Hash)
- func (c *ChainIndexer) Start(chain IndexerChain)
- func (c *ChainIndexer) StartSnail(chain IndexerChain)
- type ChainIndexerBackend
- type ChainIndexerChain
- type DeleteCallback
- type HeaderChain
- func (hc *HeaderChain) Config() *params.ChainConfig
- func (hc *HeaderChain) CurrentHeader() *types.SnailHeader
- func (hc *HeaderChain) Engine() consensus.Engine
- func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.SnailBlock
- func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64
- func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *types.SnailHeader
- func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.SnailHeader
- func (hc *HeaderChain) GetHeaderByNumber(number uint64) *types.SnailHeader
- func (hc *HeaderChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (hc *HeaderChain) GetTdByHash(hash common.Hash) *big.Int
- func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool
- func (hc *HeaderChain) InsertHeaderChain(chain []*types.SnailHeader, writeHeader WhCallback, start time.Time) (int, error)
- func (hc *HeaderChain) SetCurrentHeader(head *types.SnailHeader)
- func (hc *HeaderChain) SetGenesis(head *types.SnailHeader)
- func (hc *HeaderChain) SetHead(head uint64, delFn DeleteCallback)
- func (hc *HeaderChain) ValidateHeaderChain(chain []*types.SnailHeader, checkFreq int) (int, error)
- func (hc *HeaderChain) WriteHeader(header *types.SnailHeader) (status WriteStatus, err error)
- func (hc *HeaderChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error
- type IndexerChain
- type MakechianConfig
- type SnailBlockChain
- func MakeChain(fastBlockNumbers int, snailBlockNumbers int, genesis *core.Genesis, ...) (*SnailBlockChain, *core.BlockChain)
- func MakeSnailChain(snailBlockNumbers int, genesis *core.Genesis, engine consensus.Engine) (*SnailBlockChain, *core.BlockChain)
- func NewSnailBlockChain(db taidb.Database, chainConfig *params.ChainConfig, engine consensus.Engine, ...) (*SnailBlockChain, error)
- func (bc *SnailBlockChain) BadBlocks() []*types.SnailBlock
- func (bc *SnailBlockChain) Config() *params.ChainConfig
- func (bc *SnailBlockChain) CurrentBlock() *types.SnailBlock
- func (bc *SnailBlockChain) CurrentFastBlock() *types.SnailBlock
- func (bc *SnailBlockChain) CurrentHeader() *types.SnailHeader
- func (bc *SnailBlockChain) Engine() consensus.Engine
- func (bc *SnailBlockChain) Export(w io.Writer) error
- func (bc *SnailBlockChain) ExportN(w io.Writer, first uint64, last uint64) error
- func (bc *SnailBlockChain) FastInsertChain(chain types.SnailBlocks) (int, error)
- func (bc *SnailBlockChain) Genesis() *types.SnailBlock
- func (bc *SnailBlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (bc *SnailBlockChain) GetBlock(hash common.Hash, number uint64) *types.SnailBlock
- func (bc *SnailBlockChain) GetBlockByHash(hash common.Hash) *types.SnailBlock
- func (bc *SnailBlockChain) GetBlockByNumber(number uint64) *types.SnailBlock
- func (bc *SnailBlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (bc *SnailBlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.SnailBlock)
- func (bc *SnailBlockChain) GetBlocksFromNumber(fromNumber uint64) (blocks []*types.SnailBlock)
- func (bc *SnailBlockChain) GetBody(hash common.Hash) *types.SnailBody
- func (bc *SnailBlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue
- func (bc *SnailBlockChain) GetDatabase() taidb.Database
- func (bc *SnailBlockChain) GetFruit(fastHash common.Hash) *types.SnailBlock
- func (bc *SnailBlockChain) GetFruitByFastHash(fastHash common.Hash) (*types.SnailBlock, uint64)
- func (bc *SnailBlockChain) GetFruitsHash(header *types.SnailHeader, fruits []*types.SnailBlock) common.Hash
- func (bc *SnailBlockChain) GetHeader(hash common.Hash, number uint64) *types.SnailHeader
- func (bc *SnailBlockChain) GetHeaderByHash(hash common.Hash) *types.SnailHeader
- func (bc *SnailBlockChain) GetHeaderByNumber(number uint64) *types.SnailHeader
- func (bc *SnailBlockChain) GetHeadsFromNumber(fromNumber uint64) (blocks []*types.SnailHeader)
- func (bc *SnailBlockChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (bc *SnailBlockChain) GetTdByHash(hash common.Hash) *big.Int
- func (bc *SnailBlockChain) HasBlock(hash common.Hash, number uint64) bool
- func (bc *SnailBlockChain) HasConfirmedBlock(hash common.Hash, number uint64) bool
- func (bc *SnailBlockChain) HasHeader(hash common.Hash, number uint64) bool
- func (bc *SnailBlockChain) InsertChain(chain types.SnailBlocks) (int, error)
- func (bc *SnailBlockChain) InsertHeaderChain(chain []*types.SnailHeader, checkFreq int) (int, error)
- func (bc *SnailBlockChain) IsCanonicalBlock(hash common.Hash, number uint64) bool
- func (bc *SnailBlockChain) PostChainEvents(events []interface{})
- func (bc *SnailBlockChain) Reset() error
- func (bc *SnailBlockChain) ResetWithGenesisBlock(genesis *types.SnailBlock) error
- func (bc *SnailBlockChain) Rollback(chain []common.Hash)
- func (bc *SnailBlockChain) SetHead(head uint64) error
- func (bc *SnailBlockChain) SetValidator(validator core.SnailValidator)
- func (bc *SnailBlockChain) Stop()
- func (bc *SnailBlockChain) SubscribeChainEvent(ch chan<- types.SnailChainEvent) event.Subscription
- func (bc *SnailBlockChain) SubscribeChainHeadEvent(ch chan<- types.SnailChainHeadEvent) event.Subscription
- func (bc *SnailBlockChain) SubscribeChainSideEvent(ch chan<- types.SnailChainSideEvent) event.Subscription
- func (bc *SnailBlockChain) SubscribeFastBlockEvent(ch chan<- types.NewFastBlocksEvent) event.Subscription
- func (bc *SnailBlockChain) SubscribeNewFruitEvent(ch chan<- types.NewMinedFruitEvent) event.Subscription
- func (bc *SnailBlockChain) Validator() core.SnailValidator
- func (bc *SnailBlockChain) WriteBlock(block *types.SnailBlock, td *big.Int) (err error)
- func (bc *SnailBlockChain) WriteMinedCanonicalBlock(block *types.SnailBlock) (status WriteStatus, err error)
- type SnailPool
- func (pool *SnailPool) AddLocals(fruits []*types.SnailBlock) []error
- func (pool *SnailPool) AddRemoteFruits(fruits []*types.SnailBlock, local bool) []error
- func (pool *SnailPool) Content() []*types.SnailBlock
- func (pool *SnailPool) Inspect() []*types.SnailBlock
- func (pool *SnailPool) PendingFruits() map[common.Hash]*types.SnailBlock
- func (pool *SnailPool) RemovePendingFruitByFastHash(fasthash common.Hash)
- func (pool *SnailPool) Start()
- func (pool *SnailPool) Stats() (int, int)
- func (pool *SnailPool) Stop()
- func (pool *SnailPool) SubscribeNewFruitEvent(ch chan<- types.NewFruitsEvent) event.Subscription
- type SnailPoolConfig
- type WhCallback
- type WriteStatus
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSignHash is returned if the fruit contains an invalid signatures hash. ErrInvalidSignHash = errors.New("invalid sign") //ErrInvalidFast is returned if the fastchain not have the hash ErrInvalidFast = errors.New("invalid fast hash") //ErrNoFruits is returned if the block not contains the exact fruit count ErrNoFruits = errors.New("invalid fruits count") //ErrInvalidFruits is returned if the fruits in block not continuity ErrInvalidFruits = errors.New("invalid fruits number") //ErrGapFruits is returned if the fruits's fastblock time gap less than 360s ErrGapFruits = errors.New("invalid fruits time gap") //ErrFruitTime is returned if the fruit's time less than fastblock's time ErrFruitTime = errors.New("invalid fruit time") //ErrBlockTime is returned if the block's time less than the last fruit's time ErrBlockTime = errors.New("invalid block time") )
var ( // ErrKnownBlock is returned when a block to import is already known locally. ErrKnownBlock = errors.New("block already known") // ErrBlacklistedHash is returned if a block to import is on the blacklist. ErrBlacklistedHash = errors.New("blacklisted hash") //ErrRewardedBlock is returned if a block to import is already rewarded. ErrRewardedBlock = errors.New("block already rewarded") )
var BadHashes = map[common.Hash]bool{}
BadHashes represent a set of manually tracked bad hashes (usually hard forks)
var DefaultSnailPoolConfig = SnailPoolConfig{ Journal: "fruits.rlp", Rejournal: time.Hour, FruitCount: 8192, }
DefaultSnailPoolConfig contains the default configurations for the fruit pool.
var ( //ErrNoGenesis is returned if the Genesis not found in chain. ErrNoGenesis = errors.New("Genesis not found in chain") )
var ( // ErrNotExist is returned if the fast block not exist in fastchain. ErrNotExist = errors.New("not exist") )
Functions ¶
func GenerateChain ¶
func GenerateChain(config *params.ChainConfig, fastChain *core.BlockChain, parents []*types.SnailBlock, n int, freshPoint int, gen func(int, *BlockGen)) []*types.SnailBlock
GenerateChain creates a chain of n blocks. The first block's parent will be the provided parent. db is used to store intermediate states and should contain the parent's state trie.
The generator function is called with a new block generator for every block. Any transactions and uncles added to the generator become part of the block. If gen is nil, the blocks will be empty and their coinbase will be the zero address.
Blocks created by GenerateChain do not contain valid proof of work values. Inserting them into BlockChain requires use of FakePow or a similar non-validating proof of work implementation.
func MakeSnailBlock ¶
func MakeSnailBlock(chain *SnailBlockChain, fastchain *core.BlockChain, parent *types.SnailBlock, makeFruitSize int, diff *big.Int, blocks []*types.SnailBlock) (*types.SnailBlock, error)
MakeSnailBlockFruit retrieves a snailblock or fruit by given parameter create block,fruit chain: for snail chain fastchian: for fast chain makeStartFastNum,makeFruitSize :if you create a block the fruitset startnumber and size this is fastblock number pubkey : for election coinbaseAddr: for coin
func MakeSnailBlockBlockChain ¶
func MakeSnailBlockBlockChain(chain *SnailBlockChain, fastchain *core.BlockChain, parent *types.SnailBlock, n int, DifficultyLevel int) ([]*types.SnailBlock, error)
MakeSnailBlockFruits return fruits or blocks by given params and insert these in the chain
func MakeSnailBlockFruit ¶
func MakeSnailBlockFruit(chain *SnailBlockChain, fastchain *core.BlockChain, makeBlockNum int, makeFruitSize int, pubkey []byte, coinbaseAddr common.Address, isBlock bool, diff *big.Int) (*types.SnailBlock, error)
MakeSnailBlockFruit retrieves a snailblock or fruit by given parameter
func MakeSnailBlockFruits ¶
func MakeSnailBlockFruits(chain *SnailBlockChain, fastchain *core.BlockChain, makeStarblockNumber int, makeblockSize int, makeStartFastNum int, makeFruitSize int, pubkey []byte, coinbaseAddr common.Address, isBlock bool, diff *big.Int) ([]*types.SnailBlock, error)
MakeSnailBlockFruits return fruits or blocks by given params and insert these in the chain
func MakeSnailBlockFruitsWithoutInsert ¶
func MakeSnailBlockFruitsWithoutInsert(chain *SnailBlockChain, fastchain *core.BlockChain, makeStarblockNumber int, makeblockSize int, pubkey []byte, coinbaseAddr common.Address, isBlock bool, diff *big.Int) ([]*types.SnailBlock, error)
MakeSnailBlockFruitsWithoutInsert return fruits or blocks by given params
func MakeSnailBlocks ¶
func MakeSnailBlocks(fastchain *core.BlockChain, snailchain *SnailBlockChain, snailparents []*types.SnailBlock, blockCount int64, config MakechianConfig) ([]*types.SnailBlock, error)
Types ¶
type BlockGen ¶
type BlockGen struct {
// contains filtered or unexported fields
}
BlockGen creates blocks for testing. See GenerateChain for a detailed explanation.
func (*BlockGen) AddFruit ¶
func (b *BlockGen) AddFruit(block *types.SnailBlock)
AddFruit add a given fruit into the fruit array
func (*BlockGen) AddUncle ¶
func (b *BlockGen) AddUncle(h *types.SnailHeader)
AddUncle adds an uncle header to the generated block.
func (*BlockGen) OffsetTime ¶
OffsetTime modifies the time instance of a block, implicitly changing its associated difficulty. It's useful to test scenarios where forking is not tied to chain length directly.
func (*BlockGen) PrevBlock ¶
func (b *BlockGen) PrevBlock(index int) *types.SnailBlock
PrevBlock returns a previously generated block by number. It panics if num is greater or equal to the number of the block being generated. For index -1, PrevBlock returns the parent block given to GenerateChain.
func (*BlockGen) SetCoinbase ¶
SetCoinbase sets the coinbase of the generated block. It can be called at most once.
type BlockValidator ¶
type BlockValidator struct {
// contains filtered or unexported fields
}
BlockValidator is responsible for validating block headers, uncles and processed state.
BlockValidator implements Validator.
func NewBlockValidator ¶
func NewBlockValidator(config *params.ChainConfig, fc *core.BlockChain, sc *SnailBlockChain, engine consensus.Engine) *BlockValidator
NewBlockValidator returns a new block validator which is safe for re-use
func (*BlockValidator) ValidateBody ¶
func (v *BlockValidator) ValidateBody(block *types.SnailBlock, verifyFruits bool) error
ValidateBody validates the given block's uncles and verifies the the block header's transaction and uncle roots. The headers are assumed to be already validated at this point.
func (*BlockValidator) ValidateFruit ¶
func (v *BlockValidator) ValidateFruit(fruit *types.SnailBlock, headerNumber *big.Int, canonical bool) error
ValidateFruit is to verify if the fruit is legal
func (*BlockValidator) ValidateRewarded ¶
func (v *BlockValidator) ValidateRewarded(number uint64, hash common.Hash) error
ValidateRewarded verify whether the block has been rewarded.
func (*BlockValidator) VerifySnailSeal ¶
func (v *BlockValidator) VerifySnailSeal(chain consensus.SnailChainReader, header *types.SnailHeader, isFruit bool) error
VerifySnailSeal checking whether the given block satisfies the PoW difficulty requirements.
type ChainIndexer ¶
type ChainIndexer struct {
// contains filtered or unexported fields
}
ChainIndexer does a post-processing job for equally sized sections of the canonical chain (like BlooomBits and CHT structures). A ChainIndexer is connected to the blockchain through the event system by starting a ChainEventLoop in a goroutine.
Further child ChainIndexers can be added which use the output of the parent section indexer. These child indexers receive new head notifications only after an entire section has been finished or in case of rollbacks that might affect already finished sections.
func NewChainIndexer ¶
func NewChainIndexer(chainDb, indexDb taidb.Database, backend ChainIndexerBackend, section, confirm uint64, throttling time.Duration, kind string) *ChainIndexer
NewChainIndexer creates a new chain indexer to do background processing on chain segments of a given size after certain number of confirmations passed. The throttling parameter might be used to prevent database thrashing.
func (*ChainIndexer) AddChildIndexer ¶
func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer)
AddChildIndexer adds a child ChainIndexer that can use the output of this one
func (*ChainIndexer) AddKnownSectionHead ¶
func (c *ChainIndexer) AddKnownSectionHead(section uint64, shead common.Hash)
AddKnownSectionHead marks a new section head as known/processed if it is newer than the already known best section head
func (*ChainIndexer) Close ¶
func (c *ChainIndexer) Close() error
Close tears down all goroutines belonging to the indexer and returns any error that might have occurred internally.
func (*ChainIndexer) SectionHead ¶
func (c *ChainIndexer) SectionHead(section uint64) common.Hash
SectionHead retrieves the last block hash of a processed section from the index database.
func (*ChainIndexer) Sections ¶
func (c *ChainIndexer) Sections() (uint64, uint64, common.Hash)
Sections returns the number of processed sections maintained by the indexer and also the information about the last header indexed for potential canonical verifications.
func (*ChainIndexer) Start ¶
func (c *ChainIndexer) Start(chain IndexerChain)
Start creates a goroutine to feed chain head events into the indexer for cascading background processing. Children do not need to be started, they are notified about new events by their parents.
func (*ChainIndexer) StartSnail ¶
func (c *ChainIndexer) StartSnail(chain IndexerChain)
StartSnail start snail chain,not use now
type ChainIndexerBackend ¶
type ChainIndexerBackend interface { // Reset initiates the processing of a new chain segment, potentially terminating // any partially completed operations (in case of a reorg). Reset(section uint64, prevHead common.Hash) error // Process crunches through the next header in the chain segment. The caller // will ensure a sequential order of headers. Process(header *types.SnailHeader) // Commit finalizes the section metadata and stores it into the database. Commit() error }
ChainIndexerBackend defines the methods needed to process chain segments in the background and write the segment results into the database. These can be used to create filter blooms or CHTs.
type ChainIndexerChain ¶
type ChainIndexerChain interface { // CurrentHeader retrieves the latest locally known header. CurrentHeader() *types.SnailHeader // SubscribeChainEvent subscribes to new head header notifications. SubscribeChainEvent(ch chan<- types.SnailChainEvent) event.Subscription }
ChainIndexerChain interface is used for connecting the indexer to a blockchain
type DeleteCallback ¶
type DeleteCallback func(rawdb.DatabaseDeleter, common.Hash, uint64)
DeleteCallback is a callback function that is called by SetHead before each header is deleted.
type HeaderChain ¶
type HeaderChain struct {
// contains filtered or unexported fields
}
HeaderChain implements the basic block header chain logic that is shared by core.BlockChain and light.LightChain. It is not usable in itself, only as a part of either structure. It is not thread safe either, the encapsulating chain structures should do the necessary mutex locking/unlocking.
func NewHeaderChain ¶
func NewHeaderChain(chainDb taidb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error)
NewHeaderChain creates a new HeaderChain structure.
getValidator should return the parent's validator procInterrupt points to the parent's interrupt semaphore wg points to the parent's shutdown wait group
func (*HeaderChain) Config ¶
func (hc *HeaderChain) Config() *params.ChainConfig
Config retrieves the header chain's chain configuration.
func (*HeaderChain) CurrentHeader ¶
func (hc *HeaderChain) CurrentHeader() *types.SnailHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.
func (*HeaderChain) Engine ¶
func (hc *HeaderChain) Engine() consensus.Engine
Engine retrieves the header chain's consensus engine.
func (*HeaderChain) GetAncestor ¶
func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the number of blocks to be individually checked before we reach the canonical chain.
Note: ancestor == 0 returns the same block, 1 returns its parent and so on.
func (*HeaderChain) GetBlock ¶
func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.SnailBlock
GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.
func (*HeaderChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*HeaderChain) GetBlockNumber ¶
func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64
GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
func (*HeaderChain) GetHeader ¶
func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *types.SnailHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*HeaderChain) GetHeaderByHash ¶
func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.SnailHeader
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*HeaderChain) GetHeaderByNumber ¶
func (hc *HeaderChain) GetHeaderByNumber(number uint64) *types.SnailHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*HeaderChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*HeaderChain) GetTdByHash ¶
func (hc *HeaderChain) GetTdByHash(hash common.Hash) *big.Int
GetTdByHash retrieves a block's total difficulty in the canonical chain from the database by hash, caching it if found.
func (*HeaderChain) HasHeader ¶
func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is present in the database or not.
func (*HeaderChain) InsertHeaderChain ¶
func (hc *HeaderChain) InsertHeaderChain(chain []*types.SnailHeader, writeHeader WhCallback, start time.Time) (int, error)
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verfy nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*HeaderChain) SetCurrentHeader ¶
func (hc *HeaderChain) SetCurrentHeader(head *types.SnailHeader)
SetCurrentHeader sets the current head header of the canonical chain.
func (*HeaderChain) SetGenesis ¶
func (hc *HeaderChain) SetGenesis(head *types.SnailHeader)
SetGenesis sets a new genesis block header for the chain
func (*HeaderChain) SetHead ¶
func (hc *HeaderChain) SetHead(head uint64, delFn DeleteCallback)
SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.
func (*HeaderChain) ValidateHeaderChain ¶
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.SnailHeader, checkFreq int) (int, error)
ValidateHeaderChain validate the header of the snailchain
func (*HeaderChain) WriteHeader ¶
func (hc *HeaderChain) WriteHeader(header *types.SnailHeader) (status WriteStatus, err error)
WriteHeader writes a header into the local chain, given that its parent is already known. If the total difficulty of the newly inserted header becomes greater than the current known TD, the canonical chain is re-routed.
Note: This method is not concurrent-safe with inserting blocks simultaneously into the chain, as side effects caused by reorganisations cannot be emulated without the real blocks. Hence, writing headers directly should only be done in two scenarios: pure-header mode of operation (light clients), or properly separated header/block phases (non-archive clients).
type IndexerChain ¶
type IndexerChain interface { // CurrentHeader retrieves the latest locally known header. CurrentHeader() *types.SnailHeader // SubscribeChainEvent subscribes to new head header notifications. SubscribeChainEvent(ch chan<- types.SnailChainEvent) event.Subscription }
IndexerChain interface is used for connecting the indexer to a snail blockchain
type MakechianConfig ¶
type SnailBlockChain ¶
type SnailBlockChain struct {
// contains filtered or unexported fields
}
SnailBlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations.
Importing blocks in to the block chain happens according to the set of rules defined by the two stage Validator. Processing of blocks is done using the Processor which processes the included transaction. The validation of the state is done in the second part of the Validator. Failing results in aborting of the import.
The BlockChain also helps in returning blocks from **any** chain included in the database as well as blocks that represents the canonical chain. It's important to note that GetBlock can return any block and does not need to be included in the canonical one where as GetBlockByNumber always represents the canonical chain.
func MakeChain ¶
func MakeChain(fastBlockNumbers int, snailBlockNumbers int, genesis *core.Genesis, engine consensus.Engine) (*SnailBlockChain, *core.BlockChain)
MakeChain return snailChain and fastchain by given fastBlockNumbers and snailBlockNumbers
func MakeSnailChain ¶
func MakeSnailChain(snailBlockNumbers int, genesis *core.Genesis, engine consensus.Engine) (*SnailBlockChain, *core.BlockChain)
MakeSnailChain return snailChain and fastchain by given snailBlockNumbers and a default fastBlockNumbers(60)
func NewSnailBlockChain ¶
func NewSnailBlockChain(db taidb.Database, chainConfig *params.ChainConfig, engine consensus.Engine, blockchain *core.BlockChain) (*SnailBlockChain, error)
NewSnailBlockChain returns a fully initialised block chain using information available in the database. It initialises the default Ethereum Validator and Processor.
func (*SnailBlockChain) BadBlocks ¶
func (bc *SnailBlockChain) BadBlocks() []*types.SnailBlock
BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
func (*SnailBlockChain) Config ¶
func (bc *SnailBlockChain) Config() *params.ChainConfig
Config retrieves the blockchain's chain configuration.
func (*SnailBlockChain) CurrentBlock ¶
func (bc *SnailBlockChain) CurrentBlock() *types.SnailBlock
CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.
func (*SnailBlockChain) CurrentFastBlock ¶
func (bc *SnailBlockChain) CurrentFastBlock() *types.SnailBlock
CurrentFastBlock retrieves the current fast-sync head block of the canonical chain. The block is retrieved from the blockchain's internal cache.
func (*SnailBlockChain) CurrentHeader ¶
func (bc *SnailBlockChain) CurrentHeader() *types.SnailHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.
func (*SnailBlockChain) Engine ¶
func (bc *SnailBlockChain) Engine() consensus.Engine
Engine retrieves the blockchain's consensus engine.
func (*SnailBlockChain) Export ¶
func (bc *SnailBlockChain) Export(w io.Writer) error
Export writes the active chain to the given writer.
func (*SnailBlockChain) FastInsertChain ¶
func (bc *SnailBlockChain) FastInsertChain(chain types.SnailBlocks) (int, error)
FastInsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork. If an error is returned it will return the index number of the failing block as well an error describing what went wrong. This does not check fruits
After insertion is done, all accumulated events will be fired.
func (*SnailBlockChain) Genesis ¶
func (bc *SnailBlockChain) Genesis() *types.SnailBlock
Genesis retrieves the chain's genesis block.
func (*SnailBlockChain) GetAncestor ¶
func (bc *SnailBlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the number of blocks to be individually checked before we reach the canonical chain.
Note: ancestor == 0 returns the same block, 1 returns its parent and so on.
func (*SnailBlockChain) GetBlock ¶
func (bc *SnailBlockChain) GetBlock(hash common.Hash, number uint64) *types.SnailBlock
GetBlock retrieves a block from the database by hash and number, caching it if found.
func (*SnailBlockChain) GetBlockByHash ¶
func (bc *SnailBlockChain) GetBlockByHash(hash common.Hash) *types.SnailBlock
GetBlockByHash retrieves a block from the database by hash, caching it if found.
func (*SnailBlockChain) GetBlockByNumber ¶
func (bc *SnailBlockChain) GetBlockByNumber(number uint64) *types.SnailBlock
GetBlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.
func (*SnailBlockChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*SnailBlockChain) GetBlocksFromHash ¶
func (bc *SnailBlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.SnailBlock)
GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors. [deprecated by eth/62]
func (*SnailBlockChain) GetBlocksFromNumber ¶
func (bc *SnailBlockChain) GetBlocksFromNumber(fromNumber uint64) (blocks []*types.SnailBlock)
GetBlocksFromNumber return snailblocks between given number to currentNumber just for test
func (*SnailBlockChain) GetBody ¶
func (bc *SnailBlockChain) GetBody(hash common.Hash) *types.SnailBody
GetBody retrieves a block body (fruits and signs) from the database by hash, caching it if found.
func (*SnailBlockChain) GetBodyRLP ¶
func (bc *SnailBlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue
GetBodyRLP retrieves a block body in RLP encoding from the database by hash, caching it if found.
func (*SnailBlockChain) GetDatabase ¶
func (bc *SnailBlockChain) GetDatabase() taidb.Database
GetDatabase Get lowlevel persistence database
func (*SnailBlockChain) GetFruit ¶
func (bc *SnailBlockChain) GetFruit(fastHash common.Hash) *types.SnailBlock
GetFruit retrieves a fruit from the database by FastHash
func (*SnailBlockChain) GetFruitByFastHash ¶
func (bc *SnailBlockChain) GetFruitByFastHash(fastHash common.Hash) (*types.SnailBlock, uint64)
GetFruitByFastHash retrieves a block from the database by FastHash
func (*SnailBlockChain) GetFruitsHash ¶
func (bc *SnailBlockChain) GetFruitsHash(header *types.SnailHeader, fruits []*types.SnailBlock) common.Hash
func (*SnailBlockChain) GetHeader ¶
func (bc *SnailBlockChain) GetHeader(hash common.Hash, number uint64) *types.SnailHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*SnailBlockChain) GetHeaderByHash ¶
func (bc *SnailBlockChain) GetHeaderByHash(hash common.Hash) *types.SnailHeader
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*SnailBlockChain) GetHeaderByNumber ¶
func (bc *SnailBlockChain) GetHeaderByNumber(number uint64) *types.SnailHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*SnailBlockChain) GetHeadsFromNumber ¶
func (bc *SnailBlockChain) GetHeadsFromNumber(fromNumber uint64) (blocks []*types.SnailHeader)
GetHeadsFromNumber return snailheaders between given number to currentNumber just for test
func (*SnailBlockChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*SnailBlockChain) GetTdByHash ¶
func (bc *SnailBlockChain) GetTdByHash(hash common.Hash) *big.Int
GetTdByHash retrieves a block's total difficulty in the canonical chain from the database by hash, caching it if found.
func (*SnailBlockChain) HasBlock ¶
func (bc *SnailBlockChain) HasBlock(hash common.Hash, number uint64) bool
HasBlock checks if a block is fully present in the database or not.
func (*SnailBlockChain) HasConfirmedBlock ¶
func (bc *SnailBlockChain) HasConfirmedBlock(hash common.Hash, number uint64) bool
HasConfirmedBlock checks if a block is fully present in the database or not.and number must bigger than currentBlockNumber
func (*SnailBlockChain) HasHeader ¶
func (bc *SnailBlockChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is present in the database or not, caching it if present.
func (*SnailBlockChain) InsertChain ¶
func (bc *SnailBlockChain) InsertChain(chain types.SnailBlocks) (int, error)
InsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork. If an error is returned it will return the index number of the failing block as well an error describing what went wrong.
After insertion is done, all accumulated events will be fired.
func (*SnailBlockChain) InsertHeaderChain ¶
func (bc *SnailBlockChain) InsertHeaderChain(chain []*types.SnailHeader, checkFreq int) (int, error)
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verify nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*SnailBlockChain) IsCanonicalBlock ¶
func (bc *SnailBlockChain) IsCanonicalBlock(hash common.Hash, number uint64) bool
IsCanonicalBlock checks if a block on the Canonical block chain or not, caching it if present.
func (*SnailBlockChain) PostChainEvents ¶
func (bc *SnailBlockChain) PostChainEvents(events []interface{})
PostChainEvents iterates over the events generated by a chain insertion and posts them into the event feed.
func (*SnailBlockChain) Reset ¶
func (bc *SnailBlockChain) Reset() error
Reset purges the entire blockchain, restoring it to its genesis state.
func (*SnailBlockChain) ResetWithGenesisBlock ¶
func (bc *SnailBlockChain) ResetWithGenesisBlock(genesis *types.SnailBlock) error
ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.
func (*SnailBlockChain) Rollback ¶
func (bc *SnailBlockChain) Rollback(chain []common.Hash)
Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.
func (*SnailBlockChain) SetHead ¶
func (bc *SnailBlockChain) SetHead(head uint64) error
SetHead rewinds the local chain to a new head. In the case of headers, everything above the new head will be deleted and the new one set. In the case of blocks though, the head may be further rewound if block bodies are missing (non-archive nodes after a fast sync).
func (*SnailBlockChain) SetValidator ¶
func (bc *SnailBlockChain) SetValidator(validator core.SnailValidator)
SetValidator sets the validator which is used to validate incoming blocks.
func (*SnailBlockChain) Stop ¶
func (bc *SnailBlockChain) Stop()
Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.
func (*SnailBlockChain) SubscribeChainEvent ¶
func (bc *SnailBlockChain) SubscribeChainEvent(ch chan<- types.SnailChainEvent) event.Subscription
SubscribeChainEvent registers a subscription of SnailChainEvent.
func (*SnailBlockChain) SubscribeChainHeadEvent ¶
func (bc *SnailBlockChain) SubscribeChainHeadEvent(ch chan<- types.SnailChainHeadEvent) event.Subscription
SubscribeChainHeadEvent registers a subscription of types.SnailChainHeadEvent.
func (*SnailBlockChain) SubscribeChainSideEvent ¶
func (bc *SnailBlockChain) SubscribeChainSideEvent(ch chan<- types.SnailChainSideEvent) event.Subscription
SubscribeChainSideEvent registers a subscription of types.SnailChainSideEvent.
func (*SnailBlockChain) SubscribeFastBlockEvent ¶
func (bc *SnailBlockChain) SubscribeFastBlockEvent(ch chan<- types.NewFastBlocksEvent) event.Subscription
SubscribeFastBlockEvent registers a subscription of fruits.
func (*SnailBlockChain) SubscribeNewFruitEvent ¶
func (bc *SnailBlockChain) SubscribeNewFruitEvent(ch chan<- types.NewMinedFruitEvent) event.Subscription
SubscribeNewFruitEvent registers a subscription of fruits.
func (*SnailBlockChain) Validator ¶
func (bc *SnailBlockChain) Validator() core.SnailValidator
Validator returns the current validator.
func (*SnailBlockChain) WriteBlock ¶
func (bc *SnailBlockChain) WriteBlock(block *types.SnailBlock, td *big.Int) (err error)
WriteBlock writes only the block and its metadata to the database, but does not write any state. This is used to construct competing side forks up to the point where they exceed the canonical total difficulty.
func (*SnailBlockChain) WriteMinedCanonicalBlock ¶
func (bc *SnailBlockChain) WriteMinedCanonicalBlock(block *types.SnailBlock) (status WriteStatus, err error)
WriteMinedCanonicalBlock writes the minedblock to the database.
type SnailPool ¶
type SnailPool struct {
// contains filtered or unexported fields
}
SnailPool contains all currently known fruit. fruits enter the pool when they are received from the network or submitted locally. They exit the pool when they are included in the blockchain.
The pool separates processable fruits (which can be applied to the current state) and future fruits. fruits move between those two states over time as they are received and processed.
func NewSnailPool ¶
func NewSnailPool(config SnailPoolConfig, fastBlockChain *core.BlockChain, chain core.SnailChain, engine consensus.Engine) *SnailPool
NewSnailPool creates a new fruit pool to gather, sort and filter inbound fruits from the network.
func (*SnailPool) AddLocals ¶
func (pool *SnailPool) AddLocals(fruits []*types.SnailBlock) []error
AddLocals enqueues a batch of fruits into the pool if they are valid, marking the senders as a local ones in the mean time, ensuring they go around the local pricing constraints.
func (*SnailPool) AddRemoteFruits ¶
func (pool *SnailPool) AddRemoteFruits(fruits []*types.SnailBlock, local bool) []error
AddRemoteFruits enqueues a batch of fruits into the pool if they are valid.
func (*SnailPool) Content ¶
func (pool *SnailPool) Content() []*types.SnailBlock
Content returning all the pending fruits sorted by fast number.
func (*SnailPool) Inspect ¶
func (pool *SnailPool) Inspect() []*types.SnailBlock
Inspect returning all the unverifiedFruits fruits sorted by fast number.
func (*SnailPool) PendingFruits ¶
func (pool *SnailPool) PendingFruits() map[common.Hash]*types.SnailBlock
PendingFruits retrieves all currently verified fruits. The returned fruit set is a copy and can be freely modified by calling code.
func (*SnailPool) RemovePendingFruitByFastHash ¶
RemovePendingFruitByFastHash remove unVerifyFreshness fruit
func (*SnailPool) Stats ¶
Stats returning all the pending fruits count and unverifiedFruits fruits count.
func (*SnailPool) SubscribeNewFruitEvent ¶
func (pool *SnailPool) SubscribeNewFruitEvent(ch chan<- types.NewFruitsEvent) event.Subscription
SubscribeNewFruitEvent registers a subscription of NewFruitEvent and starts sending event to the given channel.
type SnailPoolConfig ¶
type SnailPoolConfig struct { Journal string // Journal of local fruits to survive node restarts Rejournal time.Duration // Time interval to regenerate the local fruit journal FruitCount uint64 }
SnailPoolConfig are the configuration parameters of the fruit pool.
type WhCallback ¶
type WhCallback func(*types.SnailHeader) error
WhCallback is a callback function for inserting individual headers. A callback is used for two reasons: first, in a LightChain, status should be processed and light chain events sent, while in a BlockChain this is not necessary since chain events are sent after inserting blocks. Second, the header writes should be protected by the parent chain mutex individually.
type WriteStatus ¶
type WriteStatus byte
WriteStatus status of write
const ( NonStatTy WriteStatus = iota CanonStatTy SideStatTy )
the three kind of status