snailchain

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: GPL-3.0 Imports: 30 Imported by: 6

Documentation

Overview

Package snailchain implements the truechain snailchain protocol.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
var BadHashes = map[common.Hash]bool{}

BadHashes represent a set of manually tracked bad hashes (usually hard forks)

View Source
var DefaultSnailPoolConfig = SnailPoolConfig{
	Journal:    "fruits.rlp",
	Rejournal:  time.Hour,
	FruitCount: 8192,
}

DefaultSnailPoolConfig contains the default configurations for the fruit pool.

View Source
var (

	//ErrNoGenesis is returned if the Genesis not found in chain.
	ErrNoGenesis = errors.New("Genesis not found in chain")
)
View Source
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 added in v0.10.3

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 added in v0.10.3

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

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

func (b *BlockGen) Number() *big.Int

Number returns the block number of the block being generated.

func (*BlockGen) OffsetTime

func (b *BlockGen) OffsetTime(seconds int64)

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

func (b *BlockGen) SetCoinbase(addr common.Address)

SetCoinbase sets the coinbase of the generated block. It can be called at most once.

func (*BlockGen) SetExtra

func (b *BlockGen) SetExtra(data []byte)

SetExtra sets the extra data field of the generated block.

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

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 ChainHeadEventLoop 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 etruedb.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) AddCheckpoint

func (c *ChainIndexer) AddCheckpoint(section uint64, shead common.Hash)

AddCheckpoint adds a checkpoint. Sections are never processed and the chain is not expected to be available before this point. The indexer assumes that the backend has sufficient information available to process subsequent sections.

Note: knownSections == 0 and storedSections == checkpointSections until syncing reaches the checkpoint

func (*ChainIndexer) AddChildIndexer

func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer)

AddChildIndexer adds a child ChainIndexer that can use the output of this one

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

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.

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(ctx context.Context, 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(ctx context.Context, header *types.SnailHeader) error

	// 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.
	SubscribeChainHeadEvent(ch chan<- types.SnailChainHeadEvent) 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 etruedb.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

func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash

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

func (hc *HeaderChain) GetFruitsHash(header *types.SnailHeader, headers []*types.SnailHeader) common.Hash

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

func (hc *HeaderChain) GetTd(hash common.Hash, number uint64) *big.Int

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, fruitHeads [][]*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) IsCanonicalBlock

func (hc *HeaderChain) IsCanonicalBlock(hash common.Hash, number uint64) bool

IsCanonicalBlock checks if a block on the Canonical block chain or not, caching it if present.

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, fruits [][]*types.SnailHeader, checkFreq int, fastchain *core.HeaderChain, checkpoint uint64) (int, error)

ValidateHeaderChain validate the header of the snailchain

func (*HeaderChain) WriteHeader

func (hc *HeaderChain) WriteHeader(header *types.SnailHeader, fruitHeads []*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).

func (*HeaderChain) WriteTd

func (hc *HeaderChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error

WriteTd stores a block's total difficulty into the database, also caching it along the way.

type MakechianConfig added in v1.1.1

type MakechianConfig struct {
	FruitNumber     uint64 //each block fruits number
	FruitFresh      int64  //fruit fresh
	DifficultyLevel int    // 1: low  2 :hight
}

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 etruedb.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) ExportN

func (bc *SnailBlockChain) ExportN(w io.Writer, first uint64, last uint64) error

ExportN writes a subset of the active chain to the given writer.

func (*SnailBlockChain) FastInsertChain added in v1.1.1

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

func (bc *SnailBlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash

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() etruedb.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 added in v1.1.1

func (bc *SnailBlockChain) GetFruitsHash(header *types.SnailHeader, fruits []*types.SnailBlock) common.Hash

func (*SnailBlockChain) GetFruitsHead

func (bc *SnailBlockChain) GetFruitsHead(number uint64) []*types.SnailHeader

GetFruitsHead retrieves fruits included in the snail block

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

func (bc *SnailBlockChain) GetHeadsFromNumber(fromNumber uint64) (blocks []*types.SnailHeader)

GetHeadsFromNumber return snailheaders between given number to currentNumber just for test

func (*SnailBlockChain) GetTd

func (bc *SnailBlockChain) GetTd(hash common.Hash, number uint64) *big.Int

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, fruits [][]*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 added in v1.1.1

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 added in v0.10.2

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

func (pool *SnailPool) RemovePendingFruitByFastHash(fasthash common.Hash)

RemovePendingFruitByFastHash remove unVerifyFreshness fruit

func (*SnailPool) Start

func (pool *SnailPool) Start()

Start load and rotate Journal

func (*SnailPool) Stats

func (pool *SnailPool) Stats() (int, int)

Stats returning all the pending fruits count and unverifiedFruits fruits count.

func (*SnailPool) Stop

func (pool *SnailPool) Stop()

Stop terminates the fruit pool.

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, []*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

Directories

Path Synopsis
Package rawdb contains a collection of low level database accessors.
Package rawdb contains a collection of low level database accessors.

Jump to

Keyboard shortcuts

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