Documentation ¶
Overview ¶
Package blockchain 实现区块链模块,包含区块链存储
Index ¶
- Variables
- func GetLocalDBKeyList() [][]byte
- func GetTransactionProofs(Txs []*types.Transaction, index int32) ([][]byte, error)
- func IsRecordFaultErr(err error) bool
- func LoadBlockStoreHeight(db dbm.DB) (int64, error)
- type BestPeerInfo
- type BlockCache
- type BlockChain
- func (chain *BlockChain) AddFaultPeer(faultpeer *FaultPeerInfo)
- func (chain *BlockChain) CheckBestChain(isFirst bool)
- func (chain *BlockChain) CheckBestChainProc(headers *types.Headers, pid string)
- func (chain *BlockChain) CheckHeightNoIncrease()
- func (chain *BlockChain) CheckTipBlockHash()
- func (chain *BlockChain) Close()
- func (chain *BlockChain) DefaultDownLoadInfo()
- func (chain *BlockChain) DelLastTempBlockHeight()
- func (chain *BlockChain) DownLoadTimeOutProc(height int64)
- func (chain *BlockChain) ExportBlock(title, dbPath string, startHeight int64) error
- func (chain *BlockChain) ExportBlockProc(title string, dir string, startHeight int64)
- func (chain *BlockChain) FastDownLoadBlocks()
- func (chain *BlockChain) FetchBlock(start int64, end int64, pid []string, syncOrfork bool) (err error)
- func (chain *BlockChain) FetchBlockHeaders(start int64, end int64, pid string) (err error)
- func (chain *BlockChain) FetchPeerList()
- func (chain *BlockChain) GetBestChainPeer(pid string) *BestPeerInfo
- func (chain *BlockChain) GetBestChainPids() []string
- func (chain *BlockChain) GetBlock(height int64) (block *types.BlockDetail, err error)
- func (chain *BlockChain) GetBlockByHashes(hashes [][]byte) (respblocks *types.BlockDetails, err error)
- func (chain *BlockChain) GetBlockHeight() int64
- func (chain *BlockChain) GetBlockSequences(requestblock *types.ReqBlocks) (*types.BlockSequences, error)
- func (chain *BlockChain) GetDB() dbm.DB
- func (chain *BlockChain) GetDownLoadInfo() *DownLoadInfo
- func (chain *BlockChain) GetDownloadSyncStatus() bool
- func (chain *BlockChain) GetDuplicateTxHashList(txhashlist *types.TxHashList) (duptxhashlist *types.TxHashList, err error)
- func (chain *BlockChain) GetFaultPeer(pid string) *FaultPeerInfo
- func (chain *BlockChain) GetLastBlockMainSequence(msg *queue.Message)
- func (chain *BlockChain) GetLastTempBlockHeight() int64
- func (chain *BlockChain) GetMainSeqByHash(msg *queue.Message)
- func (chain *BlockChain) GetMaxPeerInfo() *PeerInfo
- func (chain *BlockChain) GetNtpClockSyncStatus() bool
- func (chain *BlockChain) GetOrphanPool() *OrphanPool
- func (chain *BlockChain) GetParaTxByTitle(seq *types.ReqParaTxByTitle) (*types.ParaTxDetails, error)
- func (chain *BlockChain) GetPeerInfo(pid string) *PeerInfo
- func (chain *BlockChain) GetPeerMaxBlkHeight() int64
- func (chain *BlockChain) GetPeers() PeerInfoList
- func (chain *BlockChain) GetPeersMap() map[string]bool
- func (chain *BlockChain) GetRcvLastCastBlkHeight() int64
- func (chain *BlockChain) GetStore() *BlockStore
- func (chain *BlockChain) GetTxResultFromDb(txhash []byte) (tx *types.TxResult, err error)
- func (chain *BlockChain) GetValueByKey(keys *types.LocalDBGet) *types.LocalReplyValue
- func (chain *BlockChain) GetsynBlkHeight() int64
- func (chain *BlockChain) HasTx(txhash []byte, onlyquerycache bool) (has bool, err error)
- func (chain *BlockChain) ImportBlock(filename, dbPath string) error
- func (chain *BlockChain) ImportBlockProc(filename string, dir string)
- func (chain *BlockChain) InitBlockChain()
- func (chain *BlockChain) InitCache(height int64)
- func (chain *BlockChain) InitDownLoadInfo(StartHeight int64, EndHeight int64, pids []string)
- func (chain *BlockChain) InitIndexAndBestView()
- func (chain *BlockChain) IsCaughtUp() bool
- func (chain *BlockChain) IsErrExecBlock(height int64, hash []byte) (bool, error)
- func (chain *BlockChain) IsFaultPeer(pid string) bool
- func (b *BlockChain) LoadBlockByHash(hash []byte) (block *types.BlockDetail, err error)
- func (chain *BlockChain) NeedReExec(meta *types.UpgradeMeta) bool
- func (chain *BlockChain) NeedRollback(curHeight, rollHeight int64) bool
- func (chain *BlockChain) OnChainTimeout(height int64) bool
- func (chain *BlockChain) PrintFaultPeer()
- func (chain *BlockChain) ProcAddBlockHeadersMsg(headers *types.Headers, pid string) error
- func (chain *BlockChain) ProcAddBlockMsg(broadcast bool, blockdetail *types.BlockDetail, pid string) (*types.BlockDetail, error)
- func (chain *BlockChain) ProcAddBlockSeqCB(cb *types.BlockSeqCB) error
- func (chain *BlockChain) ProcAddParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (*types.BlockDetail, error)
- func (chain *BlockChain) ProcBlockHeader(headers *types.Headers, peerid string) error
- func (chain *BlockChain) ProcBlockHeaders(headers *types.Headers, pid string) error
- func (chain *BlockChain) ProcDelParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (err error)
- func (chain *BlockChain) ProcDownLoadBlocks(StartHeight int64, EndHeight int64, pids []string)
- func (chain *BlockChain) ProcFutureBlocks()
- func (chain *BlockChain) ProcGetAddrOverview(addr *types.ReqAddr) (*types.AddrOverview, error)
- func (chain *BlockChain) ProcGetBlockByHashMsg(hash []byte) (respblock *types.BlockDetail, err error)
- func (chain *BlockChain) ProcGetBlockDetailsMsg(requestblock *types.ReqBlocks) (respblocks *types.BlockDetails, err error)
- func (chain *BlockChain) ProcGetBlockHash(height *types.ReqInt) (*types.ReplyHash, error)
- func (chain *BlockChain) ProcGetBlockOverview(ReqHash *types.ReqHash) (*types.BlockOverview, error)
- func (chain *BlockChain) ProcGetHeadersMsg(requestblock *types.ReqBlocks) (respheaders *types.Headers, err error)
- func (chain *BlockChain) ProcGetLastBlockMsg() (respblock *types.Block, err error)
- func (chain *BlockChain) ProcGetLastHeaderMsg() (*types.Header, error)
- func (chain *BlockChain) ProcGetMainSeqByHash(hash []byte) (int64, error)
- func (chain *BlockChain) ProcGetSeqByHash(hash []byte) (int64, error)
- func (chain *BlockChain) ProcGetSeqCBLastNum(name string) int64
- func (chain *BlockChain) ProcGetTransactionByAddr(addr *types.ReqAddr) (*types.ReplyTxInfos, error)
- func (chain *BlockChain) ProcGetTransactionByHashes(hashs [][]byte) (TxDetails *types.TransactionDetails, err error)
- func (chain *BlockChain) ProcListBlockSeqCB() (*types.BlockSeqCBs, error)
- func (chain *BlockChain) ProcQueryTxMsg(txhash []byte) (proof *types.TransactionDetail, err error)
- func (chain *BlockChain) ProcRecvMsg()
- func (b *BlockChain) ProcessBlock(broadcast bool, block *types.BlockDetail, pid string, addBlock bool, ...) (*types.BlockDetail, bool, bool, error)
- func (b *BlockChain) ProcessDelParaChainBlock(broadcast bool, blockdetail *types.BlockDetail, pid string, sequence int64) (*types.BlockDetail, bool, bool, error)
- func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64)
- func (chain *BlockChain) ReadBlockByHeight(height int64) (*types.Block, error)
- func (chain *BlockChain) ReadBlockToExec(height int64, isNewStart bool)
- func (chain *BlockChain) RecordFaultPeer(pid string, height int64, hash []byte, err error)
- func (chain *BlockChain) RecoveryFaultPeer()
- func (chain *BlockChain) RemoveFaultPeer(pid string)
- func (chain *BlockChain) ReqDownLoadBlocks()
- func (chain *BlockChain) Rollback()
- func (chain *BlockChain) Rollbackblock()
- func (chain *BlockChain) SendAddBlockEvent(block *types.BlockDetail) (err error)
- func (chain *BlockChain) SendBlockBroadcast(block *types.BlockDetail)
- func (chain *BlockChain) SendDelBlockEvent(block *types.BlockDetail) (err error)
- func (chain *BlockChain) SetQueueClient(client queue.Client)
- func (chain *BlockChain) SetValueByKey(kvs *types.LocalDBSet) error
- func (chain *BlockChain) SynBlocksFromPeers()
- func (chain *BlockChain) SynRoutine()
- func (chain *BlockChain) UpdateDownLoadPids()
- func (chain *BlockChain) UpdateDownLoadStartHeight(StartHeight int64)
- func (chain *BlockChain) UpdateDownloadSyncStatus(Sync bool)
- func (chain *BlockChain) UpdateFaultPeer(pid string, reqFlag bool)
- func (chain *BlockChain) UpdateNtpClockSyncStatus(Sync bool)
- func (chain *BlockChain) UpdateRcvCastBlkHeight(height int64)
- func (chain *BlockChain) UpdateRoutine()
- func (chain *BlockChain) UpdatesynBlkHeight(height int64)
- func (chain *BlockChain) Upgrade()
- func (chain *BlockChain) UpgradeChain()
- func (chain *BlockChain) UpgradeStore()
- func (chain *BlockChain) Wait()
- func (chain *BlockChain) WriteBlockToDbTemp(block *types.Block, lastHeightSave bool) error
- type BlockOnChain
- type BlockStore
- func (bs *BlockStore) AddTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error
- func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int
- func (bs *BlockStore) CreateSequences(batchSize int64)
- func (bs *BlockStore) DelBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) (int64, error)
- func (bs *BlockStore) DelTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error
- func (bs *BlockStore) Get(keys *types.LocalDBGet) *types.LocalReplyValue
- func (bs *BlockStore) GetBlockByMainSequence(sequence int64) (*types.BlockSequence, error)
- func (bs *BlockStore) GetBlockHashByHeight(height int64) ([]byte, error)
- func (bs *BlockStore) GetBlockHeaderByHash(hash []byte) (*types.Header, error)
- func (bs *BlockStore) GetBlockHeaderByHeight(height int64) (*types.Header, error)
- func (bs *BlockStore) GetBlockSequence(Sequence int64) (*types.BlockSequence, error)
- func (bs *BlockStore) GetDbVersion() int64
- func (bs *BlockStore) GetHeightByBlockHash(hash []byte) (int64, error)
- func (bs *BlockStore) GetMainSequenceByHash(hash []byte) (int64, error)
- func (bs *BlockStore) GetSequenceByHash(hash []byte) (int64, error)
- func (bs *BlockStore) GetStoreUpgradeMeta() (*types.UpgradeMeta, error)
- func (bs *BlockStore) GetTdByBlockHash(hash []byte) (*big.Int, error)
- func (bs *BlockStore) GetTx(hash []byte) (*types.TxResult, error)
- func (bs *BlockStore) GetUpgradeMeta() (*types.UpgradeMeta, error)
- func (bs *BlockStore) HasTx(key []byte) (bool, error)
- func (bs *BlockStore) Height() int64
- func (bs *BlockStore) LastBlock() *types.Block
- func (bs *BlockStore) LastHeader() *types.Header
- func (bs *BlockStore) LoadBlockByHash(hash []byte) (*types.BlockDetail, error)
- func (bs *BlockStore) LoadBlockByHeight(height int64) (*types.BlockDetail, error)
- func (bs *BlockStore) LoadBlockByMainSequence(sequence int64) (*types.BlockDetail, int, error)
- func (bs *BlockStore) LoadBlockBySequence(Sequence int64) (*types.BlockDetail, int, error)
- func (bs *BlockStore) LoadBlockLastMainSequence() (int64, error)
- func (bs *BlockStore) LoadBlockLastSequence() (int64, error)
- func (bs *BlockStore) NewBatch(sync bool) dbm.Batch
- func (bs *BlockStore) SaveBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) (int64, error)
- func (bs *BlockStore) SaveTdByBlockHash(storeBatch dbm.Batch, hash []byte, td *big.Int) error
- func (bs *BlockStore) SetConsensusPara(kvs *types.LocalDBSet) error
- func (bs *BlockStore) SetDbVersion(versionNo int64) error
- func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error
- func (bs *BlockStore) SetUpgradeMeta(meta *types.UpgradeMeta) error
- func (bs *BlockStore) UpdateHeight()
- func (bs *BlockStore) UpdateHeight2(height int64)
- func (bs *BlockStore) UpdateLastBlock(hash []byte)
- func (bs *BlockStore) UpdateLastBlock2(block *types.Block)
- type DownLoadInfo
- type ErrCountInfo
- type FaultPeerInfo
- type OrphanPool
- func (op *OrphanPool) AddOrphanBlock(broadcast bool, block *types.Block, pid string, sequence int64)
- func (op *OrphanPool) GetChildOrphanCount(hash string) int
- func (op *OrphanPool) GetOrphanRoot(hash []byte) []byte
- func (op *OrphanPool) IsKnownOrphan(hash []byte) bool
- func (op *OrphanPool) ProcessOrphans(hash []byte, b *BlockChain) error
- func (op *OrphanPool) RemoveOrphanBlock(orphan *orphanBlock)
- func (op *OrphanPool) RemoveOrphanBlock2(block *types.Block, expiration time.Time, broadcast bool, pid string, ...)
- func (op *OrphanPool) RemoveOrphanBlockByHash(hash []byte)
- type PeerInfo
- type PeerInfoList
- type Query
- type Task
Constants ¶
This section is empty.
Variables ¶
var ( LastSequence = []byte("LastSequence") HashToSeqPrefix = []byte("HashToSeq:") HashToParaSeqPrefix = []byte("HashToParaSeq:") LastParaSequence = []byte("LastParaSequence") )
var
var ( BackBlockNum int64 = 128 //节点高度不增加时向后取blocks的个数 BackwardBlockNum int64 = 16 //本节点高度不增加时并且落后peer的高度数 MaxRollBlockNum int64 = 10000 //最大回退block数量 )
var
var ( //cache 存贮的block个数 MaxSeqCB int64 = 20 InitBlockNum int64 = 10240 //节点刚启动时从db向index和bestchain缓存中添加的blocknode数,和blockNodeCacheLimit保持一致 FutureBlockDelayTime int64 = 1 )
var
Functions ¶
func GetTransactionProofs ¶
func GetTransactionProofs(Txs []*types.Transaction, index int32) ([][]byte, error)
GetTransactionProofs 获取指定txindex 在txs中的TransactionDetail ,注释:index从0开始
Types ¶
type BestPeerInfo ¶
type BestPeerInfo struct { Peer *PeerInfo Height int64 Hash []byte Td *big.Int ReqFlag bool IsBestChain bool }
BestPeerInfo 用于记录最优链的信息
type BlockCache ¶
type BlockCache struct {
// contains filtered or unexported fields
}
BlockCache 区块缓存
func (*BlockCache) CheckcacheBlock ¶
func (chain *BlockCache) CheckcacheBlock(height int64) (block *types.BlockDetail)
CheckcacheBlock 从cache缓存中获取block信息
func (*BlockCache) GetCacheBlock ¶
func (chain *BlockCache) GetCacheBlock(hash []byte) (block *types.BlockDetail)
GetCacheBlock 不做移动,cache最后的 128个区块
func (*BlockCache) HasCacheTx ¶
func (chain *BlockCache) HasCacheTx(hash []byte) bool
HasCacheTx 缓存中是否包含该交易
type BlockChain ¶
type BlockChain struct { //cfg MaxFetchBlockNum int64 //一次最多申请获取block个数 TimeoutSeconds int64 DefCacheSize int64 // contains filtered or unexported fields }
BlockChain 区块链结构体
func (*BlockChain) AddFaultPeer ¶
func (chain *BlockChain) AddFaultPeer(faultpeer *FaultPeerInfo)
AddFaultPeer 添加故障节点到故障FaultPeerList中
func (*BlockChain) CheckBestChain ¶
func (chain *BlockChain) CheckBestChain(isFirst bool)
CheckBestChain 定时确保本节点在最优链上,定时向peer请求指定高度的header
func (*BlockChain) CheckBestChainProc ¶
func (chain *BlockChain) CheckBestChainProc(headers *types.Headers, pid string)
CheckBestChainProc 检查最优链
func (*BlockChain) CheckHeightNoIncrease ¶
func (chain *BlockChain) CheckHeightNoIncrease()
CheckHeightNoIncrease 在规定时间本链的高度没有增长,但peerlist中最新高度远远高于本节点高度, 可能当前链是在分支链上,需从指定最长链的peer向后请求指定数量的blockheader 请求bestchain.Height -BackBlockNum -- bestchain.Height的header 需要考虑收不到分叉之后的第一个广播block,这样就会导致后面的广播block都在孤儿节点中了。
func (*BlockChain) CheckTipBlockHash ¶
func (chain *BlockChain) CheckTipBlockHash()
CheckTipBlockHash 在规定时间本链的高度没有增长,但peerlist中最新高度远远高于本节点高度, 可能当前链是在分支链上,需从指定最长链的peer向后请求指定数量的blockheader 请求bestchain.Height -BackBlockNum -- bestchain.Height的header 需要考虑收不到分叉之后的第一个广播block,这样就会导致后面的广播block都在孤儿节点中了。
func (*BlockChain) DefaultDownLoadInfo ¶
func (chain *BlockChain) DefaultDownLoadInfo()
DefaultDownLoadInfo 将DownLoadInfo恢复成默认值
func (*BlockChain) DelLastTempBlockHeight ¶
func (chain *BlockChain) DelLastTempBlockHeight()
DelLastTempBlockHeight 快速下载结束时删除此标志位
func (*BlockChain) DownLoadTimeOutProc ¶
func (chain *BlockChain) DownLoadTimeOutProc(height int64)
DownLoadTimeOutProc 快速下载模式下载区块超时的处理函数
func (*BlockChain) ExportBlock ¶
func (chain *BlockChain) ExportBlock(title, dbPath string, startHeight int64) error
ExportBlock 通过指定title和起始高度将block信息导出到一个指定文件中。 title:chain33/bityuan startHeight:需要导入/导出的起始高度 dbPath:存储到指定路径,默认当前目录下
func (*BlockChain) ExportBlockProc ¶
func (chain *BlockChain) ExportBlockProc(title string, dir string, startHeight int64)
ExportBlockProc 通过title导出对应的区块到指定文件中
func (*BlockChain) FastDownLoadBlocks ¶
func (chain *BlockChain) FastDownLoadBlocks()
FastDownLoadBlocks 开启快速下载区块的模式
func (*BlockChain) FetchBlock ¶
func (chain *BlockChain) FetchBlock(start int64, end int64, pid []string, syncOrfork bool) (err error)
FetchBlock 函数功能: 通过向P2P模块送 EventFetchBlock(types.RequestGetBlock),向其他节点主动请求区块, P2P区块收到这个消息后,会向blockchain 模块回复, EventReply。 其他节点如果有这个范围的区块,P2P模块收到其他节点发来的数据, 会发送送EventAddBlocks(types.Blocks) 给 blockchain 模块, blockchain 模块回复 EventReply syncOrfork:true fork分叉处理,不需要处理请求block的个数
:fasle 区块同步处理,一次请求128个block
func (*BlockChain) FetchBlockHeaders ¶
func (chain *BlockChain) FetchBlockHeaders(start int64, end int64, pid string) (err error)
FetchBlockHeaders 从指定pid获取start到end之间的headers
func (*BlockChain) FetchPeerList ¶
func (chain *BlockChain) FetchPeerList()
FetchPeerList 从p2p模块获取peerlist,用于获取active链上最新的高度。 如果没有收到广播block就主动向p2p模块发送请求
func (*BlockChain) GetBestChainPeer ¶
func (chain *BlockChain) GetBestChainPeer(pid string) *BestPeerInfo
GetBestChainPeer 获取最优节点
func (*BlockChain) GetBestChainPids ¶
func (chain *BlockChain) GetBestChainPids() []string
GetBestChainPids 定时确保本节点在最优链上,定时向peer请求指定高度的header
func (*BlockChain) GetBlock ¶
func (chain *BlockChain) GetBlock(height int64) (block *types.BlockDetail, err error)
GetBlock 用于获取指定高度的block,首先在缓存中获取,如果不存在就从db中获取
func (*BlockChain) GetBlockByHashes ¶
func (chain *BlockChain) GetBlockByHashes(hashes [][]byte) (respblocks *types.BlockDetails, err error)
GetBlockByHashes 通过blockhash 获取对应的block信息 从数据库获取区块不能太多,防止内存异常。一次最多获取100M区块数据从数据库
func (*BlockChain) GetBlockHeight ¶
func (chain *BlockChain) GetBlockHeight() int64
GetBlockHeight 获取区块高度
func (*BlockChain) GetBlockSequences ¶
func (chain *BlockChain) GetBlockSequences(requestblock *types.ReqBlocks) (*types.BlockSequences, error)
GetBlockSequences 通过记录的block序列号获取blockd序列存储的信息
func (*BlockChain) GetDownLoadInfo ¶
func (chain *BlockChain) GetDownLoadInfo() *DownLoadInfo
GetDownLoadInfo 获取DownLoadInfo
func (*BlockChain) GetDownloadSyncStatus ¶
func (chain *BlockChain) GetDownloadSyncStatus() bool
GetDownloadSyncStatus 获取下载区块的同步模式
func (*BlockChain) GetDuplicateTxHashList ¶
func (chain *BlockChain) GetDuplicateTxHashList(txhashlist *types.TxHashList) (duptxhashlist *types.TxHashList, err error)
GetDuplicateTxHashList 获取重复的交易
func (*BlockChain) GetFaultPeer ¶
func (chain *BlockChain) GetFaultPeer(pid string) *FaultPeerInfo
GetFaultPeer 获取指定pid是否在故障faultPeerList中
func (*BlockChain) GetLastBlockMainSequence ¶
func (chain *BlockChain) GetLastBlockMainSequence(msg *queue.Message)
GetLastBlockMainSequence 获取最新的block执行序列号
func (*BlockChain) GetLastTempBlockHeight ¶
func (chain *BlockChain) GetLastTempBlockHeight() int64
GetLastTempBlockHeight 从数据库中获取快速下载的最新的block高度
func (*BlockChain) GetMainSeqByHash ¶
func (chain *BlockChain) GetMainSeqByHash(msg *queue.Message)
GetMainSeqByHash parachian 通过blockhash获取对应的seq,只记录了addblock时的seq
func (*BlockChain) GetMaxPeerInfo ¶
func (chain *BlockChain) GetMaxPeerInfo() *PeerInfo
GetMaxPeerInfo 获取peerlist中最高节点的peerinfo
func (*BlockChain) GetNtpClockSyncStatus ¶
func (chain *BlockChain) GetNtpClockSyncStatus() bool
GetNtpClockSyncStatus 获取ntp时间是否同步状态
func (*BlockChain) GetOrphanPool ¶
func (chain *BlockChain) GetOrphanPool() *OrphanPool
GetOrphanPool 获取孤儿链
func (*BlockChain) GetParaTxByTitle ¶
func (chain *BlockChain) GetParaTxByTitle(seq *types.ReqParaTxByTitle) (*types.ParaTxDetails, error)
GetParaTxByTitle 通过seq以及title获取对应平行连的交易
func (*BlockChain) GetPeerInfo ¶
func (chain *BlockChain) GetPeerInfo(pid string) *PeerInfo
GetPeerInfo 通过peerid获取peerinfo
func (*BlockChain) GetPeerMaxBlkHeight ¶
func (chain *BlockChain) GetPeerMaxBlkHeight() int64
GetPeerMaxBlkHeight 获取peerlist中合法的最新block高度
func (*BlockChain) GetPeersMap ¶
func (chain *BlockChain) GetPeersMap() map[string]bool
GetPeersMap 获取peers的map列表方便查找
func (*BlockChain) GetRcvLastCastBlkHeight ¶
func (chain *BlockChain) GetRcvLastCastBlkHeight() int64
GetRcvLastCastBlkHeight 存储广播的block最新高度
func (*BlockChain) GetStore ¶
func (chain *BlockChain) GetStore() *BlockStore
GetStore only used for test
func (*BlockChain) GetTxResultFromDb ¶
func (chain *BlockChain) GetTxResultFromDb(txhash []byte) (tx *types.TxResult, err error)
GetTxResultFromDb 通过txhash 从txindex db中获取tx信息
type TxResult struct { Height int64 Index int32 Tx *types.Transaction Receiptdate *ReceiptData }
func (*BlockChain) GetValueByKey ¶
func (chain *BlockChain) GetValueByKey(keys *types.LocalDBGet) *types.LocalReplyValue
GetValueByKey 通过key值从blockchain数据库中获取value值
func (*BlockChain) GetsynBlkHeight ¶
func (chain *BlockChain) GetsynBlkHeight() int64
GetsynBlkHeight 存储已经同步到db的block高度
func (*BlockChain) HasTx ¶
func (chain *BlockChain) HasTx(txhash []byte, onlyquerycache bool) (has bool, err error)
HasTx 是否包含该交易
func (*BlockChain) ImportBlock ¶
func (chain *BlockChain) ImportBlock(filename, dbPath string) error
ImportBlock通过指定文件导入block
func (*BlockChain) ImportBlockProc ¶
func (chain *BlockChain) ImportBlockProc(filename string, dir string)
ImportBlockProc 导入区块的处理,区块导入结束后退出整个系统
func (*BlockChain) InitDownLoadInfo ¶
func (chain *BlockChain) InitDownLoadInfo(StartHeight int64, EndHeight int64, pids []string)
InitDownLoadInfo 开始新的DownLoad处理
func (*BlockChain) InitIndexAndBestView ¶
func (chain *BlockChain) InitIndexAndBestView()
InitIndexAndBestView 第一次启动之后需要将数据库中最新的128个block的node添加到index和bestchain中 主要是为了接下来分叉时的block处理,.........todo
func (*BlockChain) IsCaughtUp ¶
func (chain *BlockChain) IsCaughtUp() bool
IsCaughtUp 本节点是否已经追赶上主链高度,追赶上之后通知本节点的共识模块开始挖矿
func (*BlockChain) IsErrExecBlock ¶
func (chain *BlockChain) IsErrExecBlock(height int64, hash []byte) (bool, error)
IsErrExecBlock 判断此block是否被记录在本节点执行错误。
func (*BlockChain) IsFaultPeer ¶
func (chain *BlockChain) IsFaultPeer(pid string) bool
IsFaultPeer 判断指定pid是否在故障faultPeerList中
func (*BlockChain) LoadBlockByHash ¶
func (b *BlockChain) LoadBlockByHash(hash []byte) (block *types.BlockDetail, err error)
LoadBlockByHash 根据hash值从缓存中查询区块
func (*BlockChain) NeedReExec ¶
func (chain *BlockChain) NeedReExec(meta *types.UpgradeMeta) bool
NeedReExec 是否需要重新执行
func (*BlockChain) NeedRollback ¶
func (chain *BlockChain) NeedRollback(curHeight, rollHeight int64) bool
NeedRollback need Rollback
func (*BlockChain) OnChainTimeout ¶
func (chain *BlockChain) OnChainTimeout(height int64) bool
onChainTimeout 最新区块长时间没有更新并超过设置的超时时间
func (*BlockChain) PrintFaultPeer ¶
func (chain *BlockChain) PrintFaultPeer()
PrintFaultPeer 打印出错的节点
func (*BlockChain) ProcAddBlockHeadersMsg ¶
func (chain *BlockChain) ProcAddBlockHeadersMsg(headers *types.Headers, pid string) error
ProcAddBlockHeadersMsg 处理从peer获取的headers消息
func (*BlockChain) ProcAddBlockMsg ¶
func (chain *BlockChain) ProcAddBlockMsg(broadcast bool, blockdetail *types.BlockDetail, pid string) (*types.BlockDetail, error)
ProcAddBlockMsg 处理从peer对端同步过来的block消息
func (*BlockChain) ProcAddBlockSeqCB ¶
func (chain *BlockChain) ProcAddBlockSeqCB(cb *types.BlockSeqCB) error
ProcAddBlockSeqCB 添加seq callback
func (*BlockChain) ProcAddParaChainBlockMsg ¶
func (chain *BlockChain) ProcAddParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (*types.BlockDetail, error)
ProcAddParaChainBlockMsg 处理共识过来的add block的消息,目前只提供给平行链使用
func (*BlockChain) ProcBlockHeader ¶
func (chain *BlockChain) ProcBlockHeader(headers *types.Headers, peerid string) error
ProcBlockHeader 一个block header消息的处理,分tiphash的校验,故障peer的故障block是否恢复的校验
func (*BlockChain) ProcBlockHeaders ¶
func (chain *BlockChain) ProcBlockHeaders(headers *types.Headers, pid string) error
ProcBlockHeaders 多个headers消息的处理,主要用于寻找分叉节点
func (*BlockChain) ProcDelParaChainBlockMsg ¶
func (chain *BlockChain) ProcDelParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (err error)
ProcDelParaChainBlockMsg 处理共识过来的删除block的消息,目前只提供给平行链使用
func (*BlockChain) ProcDownLoadBlocks ¶
func (chain *BlockChain) ProcDownLoadBlocks(StartHeight int64, EndHeight int64, pids []string)
ProcDownLoadBlocks 处理下载blocks
func (*BlockChain) ProcFutureBlocks ¶
func (chain *BlockChain) ProcFutureBlocks()
ProcFutureBlocks 循环遍历所有futureblocks,当futureblock的block生成time小于当前系统时间就将此block广播出去
func (*BlockChain) ProcGetAddrOverview ¶
func (chain *BlockChain) ProcGetAddrOverview(addr *types.ReqAddr) (*types.AddrOverview, error)
ProcGetAddrOverview 获取addrOverview
type AddrOverview { int64 reciver = 1; int64 balance = 2; int64 txCount = 3;}
func (*BlockChain) ProcGetBlockByHashMsg ¶
func (chain *BlockChain) ProcGetBlockByHashMsg(hash []byte) (respblock *types.BlockDetail, err error)
ProcGetBlockByHashMsg 获取最新区块hash
func (*BlockChain) ProcGetBlockDetailsMsg ¶
func (chain *BlockChain) ProcGetBlockDetailsMsg(requestblock *types.ReqBlocks) (respblocks *types.BlockDetails, err error)
ProcGetBlockDetailsMsg EventGetBlocks(types.RequestGetBlock): rpc 模块 会向 blockchain 模块发送 EventGetBlocks(types.RequestGetBlock) 消息, 功能是查询 区块的信息, 回复消息是 EventBlocks(types.Blocks)
type ReqBlocks struct { Start int64 `protobuf:"varint,1,opt,name=start" json:"start,omitempty"` End int64 `protobuf:"varint,2,opt,name=end" json:"end,omitempty"`}
type Blocks struct {Items []*Block `protobuf:"bytes,1,rep,name=items" json:"items,omitempty"`}
func (*BlockChain) ProcGetBlockHash ¶
ProcGetBlockHash 通过blockheight 获取blockhash
func (*BlockChain) ProcGetBlockOverview ¶
func (chain *BlockChain) ProcGetBlockOverview(ReqHash *types.ReqHash) (*types.BlockOverview, error)
ProcGetBlockOverview 返回值
type BlockOverview { Header head = 1; int64 txCount = 2; repeated bytes txHashes = 3;}
获取BlockOverview
func (*BlockChain) ProcGetHeadersMsg ¶
func (chain *BlockChain) ProcGetHeadersMsg(requestblock *types.ReqBlocks) (respheaders *types.Headers, err error)
ProcGetHeadersMsg 返回值
type Header struct { Version int64 ParentHash []byte TxHash []byte Height int64 BlockTime int64 }
func (*BlockChain) ProcGetLastBlockMsg ¶
func (chain *BlockChain) ProcGetLastBlockMsg() (respblock *types.Block, err error)
ProcGetLastBlockMsg 获取最新区块信息
func (*BlockChain) ProcGetLastHeaderMsg ¶
func (chain *BlockChain) ProcGetLastHeaderMsg() (*types.Header, error)
ProcGetLastHeaderMsg 获取最新区块头信息
func (*BlockChain) ProcGetMainSeqByHash ¶
func (chain *BlockChain) ProcGetMainSeqByHash(hash []byte) (int64, error)
ProcGetMainSeqByHash 处理共识过来的通过blockhash获取seq的消息,只提供add block时的seq,用于平行链block回退
func (*BlockChain) ProcGetSeqByHash ¶
func (chain *BlockChain) ProcGetSeqByHash(hash []byte) (int64, error)
ProcGetSeqByHash 处理共识过来的通过blockhash获取seq的消息,只提供add block时的seq,用于平行链block回退
func (*BlockChain) ProcGetSeqCBLastNum ¶
func (chain *BlockChain) ProcGetSeqCBLastNum(name string) int64
ProcGetSeqCBLastNum 获取指定name的callback已经push的最新seq num
func (*BlockChain) ProcGetTransactionByAddr ¶
func (chain *BlockChain) ProcGetTransactionByAddr(addr *types.ReqAddr) (*types.ReplyTxInfos, error)
ProcGetTransactionByAddr 获取地址对应的所有交易信息 存储格式key:addr:flag:height ,value:txhash key=addr :获取本地参与的所有交易 key=addr:1 :获取本地作为from方的所有交易 key=addr:2 :获取本地作为to方的所有交易
func (*BlockChain) ProcGetTransactionByHashes ¶
func (chain *BlockChain) ProcGetTransactionByHashes(hashs [][]byte) (TxDetails *types.TransactionDetails, err error)
ProcGetTransactionByHashes 返回类型
type TransactionDetails struct { Txs []*Transaction }
通过hashs获取交易详情
func (*BlockChain) ProcListBlockSeqCB ¶
func (chain *BlockChain) ProcListBlockSeqCB() (*types.BlockSeqCBs, error)
ProcListBlockSeqCB 列出所有已经设置的seq callback
func (*BlockChain) ProcQueryTxMsg ¶
func (chain *BlockChain) ProcQueryTxMsg(txhash []byte) (proof *types.TransactionDetail, err error)
ProcQueryTxMsg 函数功能: EventQueryTx(types.ReqHash) : rpc模块会向 blockchain 模块 发送 EventQueryTx(types.ReqHash) 消息 , 查询交易的默克尔树,回复消息 EventTransactionDetail(types.TransactionDetail) 结构体: type ReqHash struct {Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`} type TransactionDetail struct {Hashs [][]byte `protobuf:"bytes,1,rep,name=hashs,proto3" json:"hashs,omitempty"}
func (*BlockChain) ProcRecvMsg ¶
func (chain *BlockChain) ProcRecvMsg()
ProcRecvMsg blockchain模块的消息接收处理
func (*BlockChain) ProcessBlock ¶
func (b *BlockChain) ProcessBlock(broadcast bool, block *types.BlockDetail, pid string, addBlock bool, sequence int64) (*types.BlockDetail, bool, bool, error)
ProcessBlock 处理共识模块过来的blockdetail,peer广播过来的block,以及从peer同步过来的block 共识模块和peer广播过来的block需要广播出去 共识模块过来的Receipts不为空,广播和同步过来的Receipts为空 返回参数说明:是否主链,是否孤儿节点,具体err
func (*BlockChain) ProcessDelParaChainBlock ¶
func (b *BlockChain) ProcessDelParaChainBlock(broadcast bool, blockdetail *types.BlockDetail, pid string, sequence int64) (*types.BlockDetail, bool, bool, error)
ProcessDelParaChainBlock 只能从 best chain tip节点开始删除,目前只提供给平行链使用
func (*BlockChain) ReExecBlock ¶
func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64)
ReExecBlock 从对应高度本地重新执行区块
func (*BlockChain) ReadBlockByHeight ¶
func (chain *BlockChain) ReadBlockByHeight(height int64) (*types.Block, error)
ReadBlockByHeight 从数据库中读取快速下载临时存储的block信息
func (*BlockChain) ReadBlockToExec ¶
func (chain *BlockChain) ReadBlockToExec(height int64, isNewStart bool)
ReadBlockToExec 执行快速下载临时存储在db中的block
func (*BlockChain) RecordFaultPeer ¶
func (chain *BlockChain) RecordFaultPeer(pid string, height int64, hash []byte, err error)
RecordFaultPeer 当blcok执行出错时,记录出错block高度,hash值,以及出错信息和对应的peerid
func (*BlockChain) RecoveryFaultPeer ¶
func (chain *BlockChain) RecoveryFaultPeer()
RecoveryFaultPeer 尝试恢复故障peer节点,定时从出错的peer获取出错block的头信息。 看对应的block是否有更新。有更新就说明故障peer节点已经恢复ok
func (*BlockChain) RemoveFaultPeer ¶
func (chain *BlockChain) RemoveFaultPeer(pid string)
RemoveFaultPeer 此pid对应的故障已经修复,将此pid从故障列表中移除
func (*BlockChain) ReqDownLoadBlocks ¶
func (chain *BlockChain) ReqDownLoadBlocks()
ReqDownLoadBlocks 请求DownLoad处理的blocks
func (*BlockChain) Rollbackblock ¶
func (chain *BlockChain) Rollbackblock()
Rollbackblock chain Rollbackblock
func (*BlockChain) SendAddBlockEvent ¶
func (chain *BlockChain) SendAddBlockEvent(block *types.BlockDetail) (err error)
SendAddBlockEvent blockchain 模块add block到db之后通知mempool 和consense模块做相应的更新
func (*BlockChain) SendBlockBroadcast ¶
func (chain *BlockChain) SendBlockBroadcast(block *types.BlockDetail)
SendBlockBroadcast blockchain模块广播此block到网络中
func (*BlockChain) SendDelBlockEvent ¶
func (chain *BlockChain) SendDelBlockEvent(block *types.BlockDetail) (err error)
SendDelBlockEvent blockchain 模块 del block从db之后通知mempool 和consense以及wallet模块做相应的更新
func (*BlockChain) SetQueueClient ¶
func (chain *BlockChain) SetQueueClient(client queue.Client)
SetQueueClient 设置队列
func (*BlockChain) SetValueByKey ¶
func (chain *BlockChain) SetValueByKey(kvs *types.LocalDBSet) error
SetValueByKey 设置kv对到blockchain数据库
func (*BlockChain) SynBlocksFromPeers ¶
func (chain *BlockChain) SynBlocksFromPeers()
SynBlocksFromPeers blockSynSeconds时间检测一次本节点的height是否有增长,没有增长就需要通过对端peerlist获取最新高度,发起同步
func (*BlockChain) UpdateDownLoadPids ¶
func (chain *BlockChain) UpdateDownLoadPids()
UpdateDownLoadPids 更新bestpeers列表
func (*BlockChain) UpdateDownLoadStartHeight ¶
func (chain *BlockChain) UpdateDownLoadStartHeight(StartHeight int64)
UpdateDownLoadStartHeight 更新DownLoad请求的起始block高度
func (*BlockChain) UpdateDownloadSyncStatus ¶
func (chain *BlockChain) UpdateDownloadSyncStatus(Sync bool)
UpdateDownloadSyncStatus 更新下载区块的同步模式
func (*BlockChain) UpdateFaultPeer ¶
func (chain *BlockChain) UpdateFaultPeer(pid string, reqFlag bool)
UpdateFaultPeer 更新此故障peer的请求标志位
func (*BlockChain) UpdateNtpClockSyncStatus ¶
func (chain *BlockChain) UpdateNtpClockSyncStatus(Sync bool)
UpdateNtpClockSyncStatus 定时更新ntp时间同步状态
func (*BlockChain) UpdateRcvCastBlkHeight ¶
func (chain *BlockChain) UpdateRcvCastBlkHeight(height int64)
UpdateRcvCastBlkHeight 更新广播的block最新高度
func (*BlockChain) UpdateRoutine ¶
func (chain *BlockChain) UpdateRoutine()
UpdateRoutine 定时延时广播futureblock
func (*BlockChain) UpdatesynBlkHeight ¶
func (chain *BlockChain) UpdatesynBlkHeight(height int64)
UpdatesynBlkHeight 更新已经同步到db的block高度
func (*BlockChain) WriteBlockToDbTemp ¶
func (chain *BlockChain) WriteBlockToDbTemp(block *types.Block, lastHeightSave bool) error
WriteBlockToDbTemp 快速下载的block临时存贮到数据库
type BlockOnChain ¶
记录最新区块上链的时间,长时间没有更新需要做对应的超时处理 主要是处理联盟链区块高度相差一个区块 整个网络长时间不出块时需要主动去获取最新的区块
type BlockStore ¶
type BlockStore struct {
// contains filtered or unexported fields
}
BlockStore 区块存储
func NewBlockStore ¶
func NewBlockStore(chain *BlockChain, db dbm.DB, client queue.Client) *BlockStore
NewBlockStore new
func (*BlockStore) AddTxs ¶
func (bs *BlockStore) AddTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error
AddTxs 通过批量存储tx信息到db中
func (*BlockStore) CheckSequenceStatus ¶
func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int
CheckSequenceStatus 配置的合法性检测
func (*BlockStore) CreateSequences ¶
func (bs *BlockStore) CreateSequences(batchSize int64)
CreateSequences 根据高度生成sequence记录
func (*BlockStore) DelBlock ¶
func (bs *BlockStore) DelBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) (int64, error)
DelBlock 删除block信息从db数据库中
func (*BlockStore) DelTxs ¶
func (bs *BlockStore) DelTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error
DelTxs 通过批量删除tx信息从db中
func (*BlockStore) Get ¶
func (bs *BlockStore) Get(keys *types.LocalDBGet) *types.LocalReplyValue
Get get
func (*BlockStore) GetBlockByMainSequence ¶
func (bs *BlockStore) GetBlockByMainSequence(sequence int64) (*types.BlockSequence, error)
GetBlockByMainSequence 从db数据库中获取指定Sequence对应的block序列操作信息
func (*BlockStore) GetBlockHashByHeight ¶
func (bs *BlockStore) GetBlockHashByHeight(height int64) ([]byte, error)
GetBlockHashByHeight 从db数据库中获取指定height对应的blockhash
func (*BlockStore) GetBlockHeaderByHash ¶
func (bs *BlockStore) GetBlockHeaderByHash(hash []byte) (*types.Header, error)
GetBlockHeaderByHash 通过blockhash获取blockheader
func (*BlockStore) GetBlockHeaderByHeight ¶
func (bs *BlockStore) GetBlockHeaderByHeight(height int64) (*types.Header, error)
GetBlockHeaderByHeight 通过blockheight获取blockheader
func (*BlockStore) GetBlockSequence ¶
func (bs *BlockStore) GetBlockSequence(Sequence int64) (*types.BlockSequence, error)
GetBlockSequence 从db数据库中获取指定Sequence对应的block序列操作信息
func (*BlockStore) GetDbVersion ¶
func (bs *BlockStore) GetDbVersion() int64
GetDbVersion 获取blockchain的数据库版本号
func (*BlockStore) GetHeightByBlockHash ¶
func (bs *BlockStore) GetHeightByBlockHash(hash []byte) (int64, error)
GetHeightByBlockHash 从db数据库中获取指定hash对应的block高度
func (*BlockStore) GetMainSequenceByHash ¶
func (bs *BlockStore) GetMainSequenceByHash(hash []byte) (int64, error)
GetMainSequenceByHash 通过block还是获取对应的seq,只提供给parachain使用
func (*BlockStore) GetSequenceByHash ¶
func (bs *BlockStore) GetSequenceByHash(hash []byte) (int64, error)
GetSequenceByHash 通过block还是获取对应的seq
func (*BlockStore) GetStoreUpgradeMeta ¶
func (bs *BlockStore) GetStoreUpgradeMeta() (*types.UpgradeMeta, error)
GetStoreUpgradeMeta 获取存在blockchain中的Store的数据库版本号
func (*BlockStore) GetTdByBlockHash ¶
func (bs *BlockStore) GetTdByBlockHash(hash []byte) (*big.Int, error)
GetTdByBlockHash 从db数据库中获取指定blockhash对应的block总难度td
func (*BlockStore) GetTx ¶
func (bs *BlockStore) GetTx(hash []byte) (*types.TxResult, error)
GetTx 通过tx hash 从db数据库中获取tx交易信息
func (*BlockStore) GetUpgradeMeta ¶
func (bs *BlockStore) GetUpgradeMeta() (*types.UpgradeMeta, error)
GetUpgradeMeta 获取blockchain的数据库版本号
func (*BlockStore) LastBlock ¶
func (bs *BlockStore) LastBlock() *types.Block
LastBlock 获取最新的block信息
func (*BlockStore) LastHeader ¶
func (bs *BlockStore) LastHeader() *types.Header
LastHeader 返回BlockStore保存的当前blockheader
func (*BlockStore) LoadBlockByHash ¶
func (bs *BlockStore) LoadBlockByHash(hash []byte) (*types.BlockDetail, error)
LoadBlockByHash 通过hash获取BlockDetail信息
func (*BlockStore) LoadBlockByHeight ¶
func (bs *BlockStore) LoadBlockByHeight(height int64) (*types.BlockDetail, error)
LoadBlockByHeight 通过height高度获取BlockDetail信息
func (*BlockStore) LoadBlockByMainSequence ¶
func (bs *BlockStore) LoadBlockByMainSequence(sequence int64) (*types.BlockDetail, int, error)
LoadBlockByMainSequence 通过main seq高度获取BlockDetail信息
func (*BlockStore) LoadBlockBySequence ¶
func (bs *BlockStore) LoadBlockBySequence(Sequence int64) (*types.BlockDetail, int, error)
LoadBlockBySequence 通过seq高度获取BlockDetail信息
func (*BlockStore) LoadBlockLastMainSequence ¶
func (bs *BlockStore) LoadBlockLastMainSequence() (int64, error)
LoadBlockLastMainSequence 获取当前最新的block操作序列号
func (*BlockStore) LoadBlockLastSequence ¶
func (bs *BlockStore) LoadBlockLastSequence() (int64, error)
LoadBlockLastSequence 获取当前最新的block操作序列号
func (*BlockStore) SaveBlock ¶
func (bs *BlockStore) SaveBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) (int64, error)
SaveBlock 批量保存blocks信息到db数据库中,并返回最新的sequence值
func (*BlockStore) SaveTdByBlockHash ¶
SaveTdByBlockHash 保存block hash对应的总难度到db中
func (*BlockStore) SetConsensusPara ¶
func (bs *BlockStore) SetConsensusPara(kvs *types.LocalDBSet) error
SetConsensusPara 设置kv到数据库,当value是空时需要delete操作
func (*BlockStore) SetDbVersion ¶
func (bs *BlockStore) SetDbVersion(versionNo int64) error
SetDbVersion 获取blockchain的数据库版本号
func (*BlockStore) SetStoreUpgradeMeta ¶
func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error
SetStoreUpgradeMeta 设置blockchain中的Store的数据库版本号
func (*BlockStore) SetUpgradeMeta ¶
func (bs *BlockStore) SetUpgradeMeta(meta *types.UpgradeMeta) error
SetUpgradeMeta 设置blockchain的数据库版本号
func (*BlockStore) UpdateHeight ¶
func (bs *BlockStore) UpdateHeight()
UpdateHeight 更新db中的block高度到BlockStore.Height
func (*BlockStore) UpdateHeight2 ¶
func (bs *BlockStore) UpdateHeight2(height int64)
UpdateHeight2 更新指定的block高度到BlockStore.Height
func (*BlockStore) UpdateLastBlock ¶
func (bs *BlockStore) UpdateLastBlock(hash []byte)
UpdateLastBlock 更新LastBlock到缓存中
func (*BlockStore) UpdateLastBlock2 ¶
func (bs *BlockStore) UpdateLastBlock2(block *types.Block)
UpdateLastBlock2 更新LastBlock到缓存中
type DownLoadInfo ¶
DownLoadInfo blockchain模块下载block处理结构体
type ErrCountInfo ¶
ErrCountInfo 启动download时read一个block失败等待最长时间为2分钟,120秒
type FaultPeerInfo ¶
type FaultPeerInfo struct { Peer *PeerInfo FaultHeight int64 FaultHash []byte ErrInfo error ReqFlag bool }
FaultPeerInfo 可疑故障节点信息
type OrphanPool ¶
type OrphanPool struct {
// contains filtered or unexported fields
}
OrphanPool 孤儿节点的存储以blockhash作为map的索引。hash转换成string
func (*OrphanPool) AddOrphanBlock ¶
func (op *OrphanPool) AddOrphanBlock(broadcast bool, block *types.Block, pid string, sequence int64)
AddOrphanBlock adds the passed block (which is already determined to be an orphan prior calling this function) to the orphan pool. It lazily cleans up any expired blocks so a separate cleanup poller doesn't need to be run. It also imposes a maximum limit on the number of outstanding orphan blocks and will remove the oldest received orphan block if the limit is exceeded.
func (*OrphanPool) GetChildOrphanCount ¶
func (op *OrphanPool) GetChildOrphanCount(hash string) int
GetChildOrphanCount 获取父hash对应的子孤儿节点的个数
func (*OrphanPool) GetOrphanRoot ¶
func (op *OrphanPool) GetOrphanRoot(hash []byte) []byte
GetOrphanRoot 获取本孤儿节点的祖先节点hash在孤儿链中,没有的话就返回孤儿节点本身hash
func (*OrphanPool) IsKnownOrphan ¶
func (op *OrphanPool) IsKnownOrphan(hash []byte) bool
IsKnownOrphan 判断本节点是不是已知的孤儿节点
func (*OrphanPool) ProcessOrphans ¶
func (op *OrphanPool) ProcessOrphans(hash []byte, b *BlockChain) error
ProcessOrphans 孤儿链的处理,将本hash对应的子block插入chain中
func (*OrphanPool) RemoveOrphanBlock ¶
func (op *OrphanPool) RemoveOrphanBlock(orphan *orphanBlock)
RemoveOrphanBlock 删除孤儿节点从OrphanPool中,以及prevOrphans中的index
func (*OrphanPool) RemoveOrphanBlock2 ¶
func (op *OrphanPool) RemoveOrphanBlock2(block *types.Block, expiration time.Time, broadcast bool, pid string, sequence int64)
RemoveOrphanBlock2 删除孤儿节点从OrphanPool中,以及prevOrphans中的index
func (*OrphanPool) RemoveOrphanBlockByHash ¶
func (op *OrphanPool) RemoveOrphanBlockByHash(hash []byte)
RemoveOrphanBlockByHash 通过指定的区块hash 删除孤儿区块从OrphanPool中,以及prevOrphans中的index.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query 检索