blockchain

package
v0.0.0-...-de85661 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Unlicense Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TriesInMemory = 128
)

Variables

View Source
var (
	// 如果事务已包含在池中,则返回ErrAlreadyKnown。
	ErrAlreadyKnown = errors.New("already known")

	// 如果事务包含无效签名,则返回ErrInvalidSender。
	ErrInvalidSender = errors.New("invalid sender")

	// 如果交易的天然气价格低于为交易池配置的最低价格,则返回ErrUnderpriced。
	ErrUnderpriced = errors.New("transaction underpriced")

	// 如果事务池已满且无法访问其他远程事务,则返回ErrTxPoolOverflow。
	ErrTxPoolOverflow = errors.New("txpool is full")

	// 如果试图用不同的交易替换交易而没有所需的涨价,则返回errReplaceUnpriced。
	ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")

	// 如果事务的请求气体限制超过当前块的最大允许量,则返回ErrGasLimit。
	ErrGasLimit = errors.New("exceeds block gas limit")

	// ErrNegativeValue是一个健全错误,用于确保任何人都无法使用负值指定事务。
	ErrNegativeValue = errors.New("negative value")

	// 如果事务的输入数据大于用户可能使用的某个有意义的限制,则返回ErrOversizedData。这不是导致事务无效的一致错误,而是DOS保护。
	ErrOversizedData = errors.New("oversized data")
)
View Source
var (
	//初始交易数量限制
	TxLookupLimit uint64

	//blockchain 主方法
	BindingMethod string

	//blockchain 结构体
	BindingStruct string
)

Functions

func AddBalance

func AddBalance(pool *TxPool, addr entity.Address, amount *big.Int)

func ApplyTransaction

func ApplyTransaction(config *entity.ChainConfig, bc vm.ChainContext, author *entity.Address, gp *transition.GasPool, operationdb *operationdb.OperationDB, header *block2.Header, tx *block2.Transaction, usedGas *uint64, cfg vm.Config) (*block2.Receipt, error)

ApplyTransaction尝试将事务应用于给定的状态数据库,并使用其环境的输入参数。如果交易失败,则返回交易收据、使用的天然气和terr,表明阻塞无效。

func CalcGasLimit

func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64

CalcGasLimit计算父块之后的下一个块的gas极限。其目的是保持基线gas接近所提供的目标,如果基线gas较低,则向目标方向增加。

func SetNonce

func SetNonce(pool *TxPool, addr entity.Address, nonce uint64)

Types

type BlockChain

type BlockChain struct {
	TxLookupLimit uint64 //`autoInjectCfg:"octopus.blockchain.binding.genesis.header.txLookupLimit"` //一个区块容纳最大交易限制
	// contains filtered or unexported fields
}

blockchain结构体

func NewBlockChain

func NewBlockChain(db typedb.Database, cacheConfig *CacheConfig, chainConfig *entity.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *block2.Header) bool) (*BlockChain, error)

构建区块链结构体

func (*BlockChain) Config

func (bc *BlockChain) Config() *entity.ChainConfig

Config检索链的fork配置。

func (*BlockChain) ContractCodeWithPrefix

func (bc *BlockChain) ContractCodeWithPrefix(hash entity.Hash) ([]byte, error)

ContractCodeWithPrefix从临时内存缓存或持久存储中检索与协定哈希相关联的数据块。 如果内存缓存中不存在代码,请使用新的代码方案检查存储。

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *block2.Block

func (*BlockChain) CurrentFastBlock

func (bc *BlockChain) CurrentFastBlock() *block2.Block

func (*BlockChain) CurrentFinalizedBlock

func (bc *BlockChain) CurrentFinalizedBlock() *block2.Block

CurrentFinalizedBlock检索规范链的当前最终块。区块从区块链的内部缓存中检索。

func (*BlockChain) CurrentHeader

func (bc *BlockChain) CurrentHeader() *block2.Header

func (*BlockChain) Engine

func (bc *BlockChain) Engine() consensus.Engine

func (*BlockChain) Export

func (bc *BlockChain) Export(w io.Writer) error

导出将活动链写入给定的写入程序。

func (*BlockChain) ExportN

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

ExportN将活动链的子集写入给定的写入器。

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *block2.Block

Genesis检索链的Genesis块。

func (*BlockChain) GetAncestor

func (bc *BlockChain) GetAncestor(hash entity.Hash, number, ancestor uint64, maxNonCanonical *uint64) (entity.Hash, uint64)

获取给定块的第n个祖先。 它假设给定的块或其近祖先是规范的。maxnoncanonic指向一个向下的计数器,该计数器限制在我们到达正则链之前要单独检查的块的数量。 注意:祖先==0返回同一块,1返回其父块,依此类推。

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash entity.Hash, number uint64) *block2.Block

GetBlock通过哈希和数字从数据库中检索块,如果找到,则将其缓存。

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash entity.Hash) *block2.Block

GetBlockByHash通过哈希从数据库中检索块,如果找到,则将其缓存。

func (*BlockChain) GetBlockByNumber

func (bc *BlockChain) GetBlockByNumber(number uint64) *block2.Block

GetBlockByNumber按编号从数据库中检索块,如果找到,则缓存它(与其哈希关联)。

func (*BlockChain) GetBlocksFromHash

func (bc *BlockChain) GetBlocksFromHash(hash entity.Hash, n int) (blocks []*block2.Block)

GetBlocksFromHash返回与哈希对应的块,最多返回n-1个祖先。

func (*BlockChain) GetBodyRLP

func (bc *BlockChain) GetBodyRLP(hash entity.Hash) rlp.RawValue

GetBodyRLP通过哈希从数据库中检索RLP编码的块体,如果找到,则将其缓存。

func (*BlockChain) GetCanonicalHash

func (bc *BlockChain) GetCanonicalHash(number uint64) entity.Hash

GetCanonicalHash返回给定块号的规范哈希

func (*BlockChain) GetDB

func (bc *BlockChain) GetDB() typedb.Database

func (*BlockChain) GetHeader

func (bc *BlockChain) GetHeader(hash entity.Hash, number uint64) *block2.Header

func (*BlockChain) GetHeaderByHash

func (bc *BlockChain) GetHeaderByHash(hash entity.Hash) *block2.Header

func (*BlockChain) GetHeaderByNumber

func (bc *BlockChain) GetHeaderByNumber(number uint64) *block2.Header

func (*BlockChain) GetHeadersFrom

func (bc *BlockChain) GetHeadersFrom(number, count uint64) []rlp.RawValue

GetHeadersFrom以rlp形式返回从给定数字向后的连续标头段。

func (*BlockChain) GetReceiptsByHash

func (bc *BlockChain) GetReceiptsByHash(hash entity.Hash) block2.Receipts

GetReceiptsByHash检索给定块中所有事务的收据。

func (*BlockChain) GetTd

func (bc *BlockChain) GetTd(hash entity.Hash, number uint64) *big.Int

func (*BlockChain) GetVMConfig

func (bc *BlockChain) GetVMConfig() *vm.Config

GetVMConfig返回块链VM配置。

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash entity.Hash, number uint64) bool

HasBlock检查数据库中是否完全存在块。

func (*BlockChain) HasBlockAndState

func (bc *BlockChain) HasBlockAndState(hash entity.Hash, number uint64) bool

HasBlockAndState检查块和关联状态trie是否完全存在于数据库中,如果存在,则缓存它。

func (*BlockChain) HasFastBlock

func (bc *BlockChain) HasFastBlock(hash entity.Hash, u uint64) bool

func (*BlockChain) HasHeader

func (bc *BlockChain) HasHeader(hash entity.Hash, u uint64) bool

func (*BlockChain) HasState

func (bc *BlockChain) HasState(hash entity.Hash) bool

HasState检查状态trie是否完全存在于数据库中。

func (*BlockChain) InsertChain

func (bc *BlockChain) InsertChain(chain block2.Blocks) (int, error)

func (*BlockChain) InsertHeaderChain

func (bc *BlockChain) InsertHeaderChain(headers []*block2.Header, i int) (int, error)

func (*BlockChain) InsertReceiptChain

func (bc *BlockChain) InsertReceiptChain(blocks block2.Blocks, receipts []block2.Receipts, u uint64) (int, error)

func (*BlockChain) Processor

func (bc *BlockChain) Processor() Processor

Processor返回当前处理器。

func (*BlockChain) Reset

func (bc *BlockChain) Reset() error

重置清除整个区块链,将其恢复到起源状态。

func (*BlockChain) ResetWithGenesisBlock

func (bc *BlockChain) ResetWithGenesisBlock(genesis *block2.Block) error

ResetWithGenesisBlock清除整个区块链,将其恢复到指定的genesis状态。

func (*BlockChain) SetHead

func (bc *BlockChain) SetHead(u uint64) error

func (*BlockChain) SetTxLookupLimit

func (bc *BlockChain) SetTxLookupLimit(limit uint64)

如果新的txlookup限制与旧的不匹配,则SetTxlookup限制负责将txlookup限制更新为存储在db中的原始限制。

func (*BlockChain) SnapSyncCommitHead

func (bc *BlockChain) SnapSyncCommitHead(hash entity.Hash) error

func (*BlockChain) StateAt

func (bc *BlockChain) StateAt(root entity.Hash) (*operationdb.OperationDB, error)

StateAt基于特定时间点返回新的可变状态。

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

停止停止区块链服务。如果当前正在进行任何导入,它将使用procInterrupt中止它们。

func (*BlockChain) StopInsert

func (bc *BlockChain) StopInsert()

StopInsert中断所有插入方法,使它们尽快返回errInsertionInterrupted。 调用此方法后,将永久禁用插入。

func (*BlockChain) SubscribeChainEvent

func (bc *BlockChain) SubscribeChainEvent(ch chan<- event.ChainEvent) event.Subscription

SubscribeChainEvent注册ChainEvent的订阅。

func (*BlockChain) SubscribeChainHeadEvent

func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- event.ChainHeadEvent) event.Subscription

Subscribe ChainHeadEvent注册ChainHeadEvent的订阅。

func (*BlockChain) SubscribeLogsEvent

func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*block2.Log) event.Subscription

SubscribeLogsEvent注册[]*类型的订阅。日志

func (*BlockChain) SubscribeRemovedLogsEvent

func (bc *BlockChain) SubscribeRemovedLogsEvent(ch chan<- event.RemovedLogsEvent) event.Subscription

SubscribeRemovedLogsEvent注册RemovedLogsEvent的订阅。

func (*BlockChain) TrieNode

func (bc *BlockChain) TrieNode(hash entity.Hash) ([]byte, error)

TrioNode从临时内存缓存或持久存储中检索与trie节点相关的数据块。

func (*BlockChain) WriteBlockAndSetHead

func (bc *BlockChain) WriteBlockAndSetHead(block *block2.Block, receipts []*block2.Receipt, logs []*log.Logger, state *operationdb.OperationDB, emitHeadEvent bool) (status WriteStatus, err error)

WriteBlockAndSetHead将给定块和所有关联状态写入数据库,并将该块作为新链头应用。

type BlockChainStart

type BlockChainStart struct {
	Db *db.DbStart `autoRelyonLang:"db.DbStart"`
	Bc *BlockChain `autoInjectLang:"blockchain.BlockChain"`
}

区块链启动配置cfg结构体

func (*BlockChainStart) Start

func (bc *BlockChainStart) Start()

type BlockChainStop

type BlockChainStop struct {
}

func (*BlockChainStop) Stop

func (bc *BlockChainStop) Stop()

type BlockProcessor

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

处理器结构体

func NewBlockProcessor

func NewBlockProcessor(bc *BlockChain, engine consensus.Engine) *BlockProcessor

构建处理器

func (*BlockProcessor) Process

func (p *BlockProcessor) Process(b *block2.Block, operationdb *operationdb.OperationDB, cfg vm.Config) (block2.Receipts, []*log.Logger, uint64, error)

type BlockValidator

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

func NewBlockValidator

func NewBlockValidator(blockchain *BlockChain, engine consensus.Engine) *BlockValidator

type CacheConfig

type CacheConfig struct {
	TrieCleanLimit      int           // 用于在内存中缓存trie节点的内存余量(MB)
	TrieCleanJournal    string        // 用于保存干净缓存项的磁盘日志。
	TrieCleanRejournal  time.Duration // 定期将干净缓存转储到磁盘的时间间隔
	TrieCleanNoPrefetch bool          // 是否禁用后续块的启发式状态预取
	TrieDirtyLimit      int           // 开始将脏trie节点刷新到磁盘的内存限制(MB)
	TrieDirtyDisabled   bool          // 是否同时禁用trie写缓存和GC(存档节点)
	TrieTimeLimit       time.Duration // 将内存中的电流刷新到磁盘的时间限制
	SnapshotLimit       int           // 用于在内存中缓存快照项的内存余量(MB)
	Preimages           bool          // 是否将trie密钥的前映像存储到磁盘

	SnapshotWait bool // 等待启动时创建快照.
}

CacheConfig包含驻留在区块链中的trie缓存/精简的配置值。

type ChainReader

type ChainReader interface {
	// 链配置
	Config() *entity.ChainConfig

	// 返回本地块总难度
	GetTd(entity.Hash, uint64) *big.Int
}

type ForkChoice

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

func NewForkChoice

func NewForkChoice(chainReader ChainReader, preserve func(header *block2.Header) bool) *ForkChoice

func (*ForkChoice) ReorgNeeded

func (f *ForkChoice) ReorgNeeded(current *block2.Header, header *block2.Header) (bool, error)

ReorgNeeded返回reorg是否应该被应用 基于给定的外部头和当地规范链。 在td模式下,新负责人如果相应的选择 总体难度较高。在外面的模式下,信任 头总是选为头。

type HeaderChain

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

func NewHeaderChain

func NewHeaderChain(chainDb typedb.Database, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error)

NewHeaderChain创建新的HeaderChain结构。ProcInterrupt指向父级的中断信号量。

func (*HeaderChain) CurrentHeader

func (hc *HeaderChain) CurrentHeader() *block2.Header

func (*HeaderChain) GetAncestor

func (hc *HeaderChain) GetAncestor(hash entity.Hash, number, ancestor uint64, maxNonCanonical *uint64) (entity.Hash, uint64)

获取给定块的第n个祖先。 它假设给定的块或其近祖先是规范的。maxnoncanonic指向一个向下的计数器,该计数器限制在我们到达正则链之前要单独检查的块的数量。 注意:祖先==0返回同一块,1返回其父块,依此类推。

func (*HeaderChain) GetBlockNumber

func (hc *HeaderChain) GetBlockNumber(hash entity.Hash) *uint64

GetBlockNumber从缓存或数据库中检索属于给定哈希的块号

func (*HeaderChain) GetCanonicalHash

func (hc *HeaderChain) GetCanonicalHash(number uint64) entity.Hash

func (*HeaderChain) GetHeader

func (hc *HeaderChain) GetHeader(hash entity.Hash, number uint64) *block2.Header

GetHeader通过哈希和数字从数据库中检索块头,如果找到,则将其缓存。

func (*HeaderChain) GetHeaderByHash

func (hc *HeaderChain) GetHeaderByHash(hash entity.Hash) *block2.Header

func (*HeaderChain) GetHeaderByNumber

func (hc *HeaderChain) GetHeaderByNumber(number uint64) *block2.Header

GetHeaderByNumber按编号从数据库中检索块头,如果找到,则缓存它(与其哈希关联)。

func (*HeaderChain) GetHeadersFrom

func (hc *HeaderChain) GetHeadersFrom(number, count uint64) []rlp.RawValue

GetHeadersFrom以rlp形式返回从给定数字向后的连续标头段。 如果“number”高于最高的本地标头,此方法将返回一个best effort响应,其中包含我们确实拥有的标头。

func (*HeaderChain) GetTd

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

func (*HeaderChain) SetCurrentHeader

func (hc *HeaderChain) SetCurrentHeader(head *block2.Header)

SetCurrentHeader将规范通道的内存标头标记设置为给定标头。

func (*HeaderChain) SetGenesis

func (hc *HeaderChain) SetGenesis(head *block2.Header)

SetGenesis为链设置新的genesis块标题

type Processor

type Processor interface {
	//处理改变区块状态,将区块加入主链
	Process(block *block2.Block, operationdb *operationdb.OperationDB, cfg vm.Config) (block2.Receipts, []*log.Logger, uint64, error)
}

处理器接口

type TxPool

type TxPool struct {
	InitDoneCh chan struct{} // 池初始化后关闭(用于测试)
	// contains filtered or unexported fields
}

* 交易池定义

func NewTxPool

func NewTxPool(config blockchainconfig.TxPoolConfig, chain blockChainop) *TxPool

NewTxPool创建一个新的事务池来收集、排序和过滤网络中的入站事务。

func (*TxPool) AddLocal

func (pool *TxPool) AddLocal(tx *block2.Transaction) error

AddLocal将单个本地事务排入池(如果有效)。这是一个围绕AddLocals的方便包装器。

func (*TxPool) AddLocals

func (pool *TxPool) AddLocals(txs []*block2.Transaction) []error

AddLocals将一批有效的事务排入池中,将发件人标记为本地发件人,确保他们绕过本地定价限制。 此方法用于从RPC API添加事务,并执行同步池重组和事件传播。

func (*TxPool) AddRemote

func (pool *TxPool) AddRemote(tx *block2.Transaction) error

AddRemote将单个事务排队到池中(如果该事务有效)。 这是一个围绕AddRemotes的方便包装器。不推荐使用:使用AddRemotes

func (*TxPool) AddRemotes

func (pool *TxPool) AddRemotes(txs []*block2.Transaction) []error

AddRemotes将一批有效的事务排入池中。 如果发件人不在本地跟踪的发件人中,则将应用完整的定价约束。 此方法用于从p2p网络添加事务,不等待池重组和内部事件传播。

func (*TxPool) Get

func (pool *TxPool) Get(hash entity.Hash) *block2.Transaction

如果事务包含在池中,Get返回事务,否则返回nil。

func (*TxPool) GetBalance

func (pool *TxPool) GetBalance(address entity.Address) *big.Int

func (*TxPool) Has

func (pool *TxPool) Has(hash entity.Hash) bool

Has返回一个指示符,指示txpool是否使用给定哈希缓存了事务。

func (*TxPool) Locals

func (pool *TxPool) Locals() []entity.Address

Locals检索池当前认为是本地的帐户。

func (*TxPool) Nonce

func (pool *TxPool) Nonce(addr entity.Address) uint64

Nonce返回帐户的下一个Nonce,池中可执行的所有事务都已在其顶部应用。

func (*TxPool) Pending

func (pool *TxPool) Pending(enforceTips bool) map[entity.Address]block2.Transactions

func (*TxPool) SetGasPrice

func (pool *TxPool) SetGasPrice(price *big.Int)

SetGasPrice更新新交易的交易池所需的最低价格,并将所有低于此阈值的交易删除。

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop终止事务池。

func (*TxPool) SubscribeNewTxsEvent

func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- event.NewTxsEvent) event.Subscription

SubscribeNewTxsEvent注册NewTxsEvent的订阅,并开始向给定通道发送事件。

type Validator

type Validator interface {
	// contains filtered or unexported methods
}

定义验证器处理接口

type WriteStatus

type WriteStatus byte
const (
	NonStatTy WriteStatus = iota
	CanonStatTy
	SideStatTy
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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