blockchain

package
v0.0.0-...-9259d71 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Overview

实现区块链模块,包含区块链存储

Index

Constants

This section is empty.

Variables

View Source
var (
	LastSequence = []byte("LastSequence")

	HashToSeqPerfix = []byte("HashToSeq:")

	AddBlock int64 = 1
	DelBlock int64 = 2
)
View Source
var (
	MaxFetchBlockNum int64 = 128 * 6 //一次最多申请获取block个数
	TimeoutSeconds   int64 = 2
	BackBlockNum     int64 = 128 //节点高度不增加时向后取blocks的个数
	BackwardBlockNum int64 = 16  //本节点高度不增加时并且落后peer的高度数

	MaxRollBlockNum int64 = 10000 //最大回退block数量

)
View Source
var (
	//cache 存贮的block个数
	DefCacheSize int64 = 128

	InitBlockNum int64 = 10240 //节点刚启动时从db向index和bestchain缓存中添加的blocknode数,和blockNodeCacheLimit保持一致

	FutureBlockDelayTime int64 = 1
)

Functions

func GetLocalDBKeyList

func GetLocalDBKeyList() [][]byte

func GetNtpClockSyncStatus

func GetNtpClockSyncStatus() bool

获取ntp时间是否同步状态

func GetTransactionProofs

func GetTransactionProofs(Txs []*types.Transaction, index int32) ([][]byte, error)

获取指定txindex 在txs中的TransactionDetail ,注释:index从0开始

func LoadBlockStoreHeight

func LoadBlockStoreHeight(db dbm.DB) (int64, error)

func UpdateNtpClockSyncStatus

func UpdateNtpClockSyncStatus(Sync bool)

定时更新ntp时间同步状态

Types

type BestPeerInfo

type BestPeerInfo struct {
	Peer        *PeerInfo
	Height      int64
	Hash        []byte
	Td          *big.Int
	ReqFlag     bool
	IsBestChain bool
}

用于记录最优链的信息

type BlockCache

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

func NewBlockCache

func NewBlockCache(defCacheSize int64) *BlockCache

func (*BlockCache) CheckcacheBlock

func (chain *BlockCache) CheckcacheBlock(height int64) (block *types.BlockDetail)

从cache缓存中获取block信息

func (*BlockCache) GetCacheBlock

func (chain *BlockCache) GetCacheBlock(hash []byte) (block *types.BlockDetail)

不做移动,cache最后的 128个区块

func (*BlockCache) HasCacheTx

func (chain *BlockCache) HasCacheTx(hash []byte) bool

type BlockChain

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

func New

func New(cfg *types.BlockChain) *BlockChain

func (*BlockChain) AddFaultPeer

func (chain *BlockChain) AddFaultPeer(faultpeer *FaultPeerInfo)

添加故障节点到故障FaultPeerList中

func (*BlockChain) CheckBestChain

func (chain *BlockChain) CheckBestChain(isFirst bool)

定时确保本节点在最优链上,定时向peer请求指定高度的header

func (*BlockChain) CheckBestChainProc

func (chain *BlockChain) CheckBestChainProc(headers *types.Headers, pid string)

func (*BlockChain) CheckHeightNoIncrease

func (chain *BlockChain) CheckHeightNoIncrease()

在规定时间本链的高度没有增长,但peerlist中最新高度远远高于本节点高度, 可能当前链是在分支链上,需从指定最长链的peer向后请求指定数量的blockheader 请求bestchain.Height -BackBlockNum -- bestchain.Height的header 需要考虑收不到分叉之后的第一个广播block,这样就会导致后面的广播block都在孤儿节点中了。

func (*BlockChain) CheckTipBlockHash

func (chain *BlockChain) CheckTipBlockHash()

在规定时间本链的高度没有增长,但peerlist中最新高度远远高于本节点高度, 可能当前链是在分支链上,需从指定最长链的peer向后请求指定数量的blockheader 请求bestchain.Height -BackBlockNum -- bestchain.Height的header 需要考虑收不到分叉之后的第一个广播block,这样就会导致后面的广播block都在孤儿节点中了。

func (*BlockChain) Close

func (chain *BlockChain) Close()

func (*BlockChain) DefaultForkInfo

func (chain *BlockChain) DefaultForkInfo()

将forkinfo恢复成默认值

func (*BlockChain) FetchBlock

func (chain *BlockChain) FetchBlock(start int64, end int64, pid []string, syncOrfork bool) (err error)

函数功能: 通过向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)

从指定pid获取start到end之间的headers

func (*BlockChain) FetchPeerList

func (chain *BlockChain) FetchPeerList()

从p2p模块获取peerlist,用于获取active链上最新的高度。 如果没有收到广播block就主动向p2p模块发送请求

func (*BlockChain) GetBestChainPeer

func (chain *BlockChain) GetBestChainPeer(pid string) *BestPeerInfo

func (*BlockChain) GetBestChainPids

func (chain *BlockChain) GetBestChainPids() []string

定时确保本节点在最优链上,定时向peer请求指定高度的header

func (*BlockChain) GetBlock

func (chain *BlockChain) GetBlock(height int64) (block *types.BlockDetail, err error)

用于获取指定高度的block,首先在缓存中获取,如果不存在就从db中获取

func (*BlockChain) GetBlockByHashes

func (chain *BlockChain) GetBlockByHashes(hashes [][]byte) (respblocks *types.BlockDetails, err error)

通过blockhash 获取对应的block信息

func (*BlockChain) GetBlockHeight

func (chain *BlockChain) GetBlockHeight() int64

func (*BlockChain) GetBlockSequences

func (chain *BlockChain) GetBlockSequences(requestblock *types.ReqBlocks) (*types.BlockSequences, error)

通过记录的block序列号获取blockd序列存储的信息

func (*BlockChain) GetDB

func (chain *BlockChain) GetDB() dbm.DB

func (*BlockChain) GetDuplicateTxHashList

func (chain *BlockChain) GetDuplicateTxHashList(txhashlist *types.TxHashList) (duptxhashlist *types.TxHashList, err error)

func (*BlockChain) GetFaultPeer

func (chain *BlockChain) GetFaultPeer(pid string) *FaultPeerInfo

获取指定pid是否在故障faultPeerList中

func (*BlockChain) GetForkInfo

func (chain *BlockChain) GetForkInfo() *ForkInfo

获取forkinfo

func (*BlockChain) GetMaxPeerInfo

func (chain *BlockChain) GetMaxPeerInfo() *PeerInfo

获取peerlist中最高节点的peerinfo

func (*BlockChain) GetOrphanPool

func (chain *BlockChain) GetOrphanPool() *OrphanPool

func (*BlockChain) GetPeerInfo

func (chain *BlockChain) GetPeerInfo(pid string) *PeerInfo

通过peerid获取peerinfo

func (*BlockChain) GetPeerMaxBlkHeight

func (chain *BlockChain) GetPeerMaxBlkHeight() int64

获取peerlist中合法的最新block高度

func (*BlockChain) GetPeers

func (chain *BlockChain) GetPeers() PeerInfoList

获取所有peers

func (*BlockChain) GetRcvLastCastBlkHeight

func (chain *BlockChain) GetRcvLastCastBlkHeight() int64

存储广播的block最新高度

func (*BlockChain) GetStore

func (chain *BlockChain) GetStore() *BlockStore

only used for test

func (*BlockChain) GetTxResultFromDb

func (chain *BlockChain) GetTxResultFromDb(txhash []byte) (tx *types.TxResult, err error)

通过txhash 从txindex db中获取tx信息

type TxResult struct {
	Height int64
	Index  int32
	Tx     *types.Transaction
 Receiptdate *ReceiptData
}

func (*BlockChain) GetsynBlkHeight

func (chain *BlockChain) GetsynBlkHeight() int64

存储已经同步到db的block高度

func (*BlockChain) HasTx

func (chain *BlockChain) HasTx(txhash []byte, onlyquerycache bool) (has bool, err error)

func (*BlockChain) InitBlockChain

func (chain *BlockChain) InitBlockChain()

func (*BlockChain) InitCache

func (chain *BlockChain) InitCache(height int64)

func (*BlockChain) InitForkInfo

func (chain *BlockChain) InitForkInfo(forkStartHeight int64, forkEndHeight int64, pid string)

开始新的fork处理

func (*BlockChain) InitIndexAndBestView

func (chain *BlockChain) InitIndexAndBestView()

第一次启动之后需要将数据库中最新的128个block的node添加到index和bestchain中 主要是为了接下来分叉时的block处理,.........todo

func (*BlockChain) IsCaughtUp

func (chain *BlockChain) IsCaughtUp() bool

本节点是否已经追赶上主链高度,追赶上之后通知本节点的共识模块开始挖矿

func (*BlockChain) IsErrExecBlock

func (chain *BlockChain) IsErrExecBlock(height int64, hash []byte) (bool, error)

判断此block是否被记录在本节点执行错误。

func (*BlockChain) IsFaultPeer

func (chain *BlockChain) IsFaultPeer(pid string) bool

判断指定pid是否在故障faultPeerList中

func (*BlockChain) LoadBlockByHash

func (b *BlockChain) LoadBlockByHash(hash []byte) (block *types.BlockDetail, err error)

func (*BlockChain) PrintFaultPeer

func (chain *BlockChain) PrintFaultPeer()

func (*BlockChain) ProcAddBlockHeadersMsg

func (chain *BlockChain) ProcAddBlockHeadersMsg(headers *types.Headers, pid string) error

处理从peer获取的headers消息

func (*BlockChain) ProcAddBlockMsg

func (chain *BlockChain) ProcAddBlockMsg(broadcast bool, blockdetail *types.BlockDetail, pid string) (*types.BlockDetail, error)

处理从peer对端同步过来的block消息

func (*BlockChain) ProcAddParaChainBlockMsg

func (chain *BlockChain) ProcAddParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (*types.BlockDetail, error)

处理共识过来的add block的消息,目前只提供给平行链使用

func (*BlockChain) ProcBlockChainFork

func (chain *BlockChain) ProcBlockChainFork(forkStartHeight int64, forkEndHeight int64, pid string)

处理从peer获取的headers消息

func (*BlockChain) ProcBlockHeader

func (chain *BlockChain) ProcBlockHeader(headers *types.Headers, peerid string) error

一个block header消息的处理,分tiphash的校验,故障peer的故障block是否恢复的校验

func (*BlockChain) ProcBlockHeaders

func (chain *BlockChain) ProcBlockHeaders(headers *types.Headers, pid string) error

多个headers消息的处理,主要用于寻找分叉节点

func (*BlockChain) ProcDelParaChainBlockMsg

func (chain *BlockChain) ProcDelParaChainBlockMsg(broadcast bool, ParaChainblockdetail *types.ParaChainBlockDetail, pid string) (err error)

处理共识过来的删除block的消息,目前只提供给平行链使用

func (*BlockChain) ProcFutureBlocks

func (chain *BlockChain) ProcFutureBlocks()

循环遍历所有futureblocks,当futureblock的block生成time小于当前系统时间就将此block广播出去

func (*BlockChain) ProcGetAddrOverview

func (chain *BlockChain) ProcGetAddrOverview(addr *types.ReqAddr) (*types.AddrOverview, error)
type  AddrOverview {
	int64 reciver = 1;
	int64 balance = 2;
	int64 txCount = 3;}

获取addrOverview

func (*BlockChain) ProcGetBlockByHashMsg

func (chain *BlockChain) ProcGetBlockByHashMsg(hash []byte) (respblock *types.BlockDetail, err error)

func (*BlockChain) ProcGetBlockDetailsMsg

func (chain *BlockChain) ProcGetBlockDetailsMsg(requestblock *types.ReqBlocks) (respblocks *types.BlockDetails, err error)

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

func (chain *BlockChain) ProcGetBlockHash(height *types.ReqInt) (*types.ReplyHash, error)

通过blockheight 获取blockhash

func (*BlockChain) ProcGetBlockOverview

func (chain *BlockChain) ProcGetBlockOverview(ReqHash *types.ReqHash) (*types.BlockOverview, error)
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)
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)

func (*BlockChain) ProcGetLastHeaderMsg

func (chain *BlockChain) ProcGetLastHeaderMsg() (*types.Header, error)

func (*BlockChain) ProcGetSeqByHash

func (chain *BlockChain) ProcGetSeqByHash(hash []byte) (int64, error)

处理共识过来的通过blockhash获取seq的消息,只提供add block时的seq,用于平行链block回退

func (*BlockChain) ProcGetTransactionByAddr

func (chain *BlockChain) ProcGetTransactionByAddr(addr *types.ReqAddr) (*types.ReplyTxInfos, error)

获取地址对应的所有交易信息 存储格式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)
type TransactionDetails struct {
	Txs []*Transaction
}

通过hashs获取交易详情

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

blockchain模块的消息接收处理

func (*BlockChain) ProcessBlock

func (b *BlockChain) ProcessBlock(broadcast bool, block *types.BlockDetail, pid string, addBlock bool, sequence int64) (*types.BlockDetail, bool, bool, error)

处理共识模块过来的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)

只能从 best chain tip节点开始删除,目前只提供给平行链使用

func (*BlockChain) RecordFaultPeer

func (chain *BlockChain) RecordFaultPeer(pid string, height int64, hash []byte, err error)

当blcok执行出错时,记录出错block高度,hash值,以及出错信息和对应的peerid

func (*BlockChain) RecoveryFaultPeer

func (chain *BlockChain) RecoveryFaultPeer()

尝试恢复故障peer节点,定时从出错的peer获取出错block的头信息。 看对应的block是否有更新。有更新就说明故障peer节点已经恢复ok

func (*BlockChain) RemoveFaultPeer

func (chain *BlockChain) RemoveFaultPeer(pid string)

此pid对应的故障已经修复,将此pid从故障列表中移除

func (*BlockChain) ReqForkBlocks

func (chain *BlockChain) ReqForkBlocks()

请求fork处理的blocks

func (*BlockChain) SendAddBlockEvent

func (chain *BlockChain) SendAddBlockEvent(block *types.BlockDetail) (err error)

blockchain 模块add block到db之后通知mempool 和consense模块做相应的更新

func (*BlockChain) SendBlockBroadcast

func (chain *BlockChain) SendBlockBroadcast(block *types.BlockDetail)

blockchain模块广播此block到网络中

func (*BlockChain) SendDelBlockEvent

func (chain *BlockChain) SendDelBlockEvent(block *types.BlockDetail) (err error)

blockchain 模块 del block从db之后通知mempool 和consense以及wallet模块做相应的更新

func (*BlockChain) SetQueueClient

func (chain *BlockChain) SetQueueClient(client queue.Client)

func (*BlockChain) SynBlocksFromPeers

func (chain *BlockChain) SynBlocksFromPeers()

blockSynSeconds时间检测一次本节点的height是否有增长,没有增长就需要通过对端peerlist获取最新高度,发起同步

func (*BlockChain) SynRoutine

func (chain *BlockChain) SynRoutine()

func (*BlockChain) UpdateFaultPeer

func (chain *BlockChain) UpdateFaultPeer(pid string, reqFlag bool)

更新此故障peer的请求标志位

func (*BlockChain) UpdateForkStartHeight

func (chain *BlockChain) UpdateForkStartHeight(forkStartHeight int64)

更新fork 请求的起始block高度

func (*BlockChain) UpdateRcvCastBlkHeight

func (chain *BlockChain) UpdateRcvCastBlkHeight(height int64)

func (*BlockChain) UpdateRoutine

func (chain *BlockChain) UpdateRoutine()

定时延时广播futureblock

func (*BlockChain) UpdatesynBlkHeight

func (chain *BlockChain) UpdatesynBlkHeight(height int64)

func (*BlockChain) UpgradeChain

func (chain *BlockChain) UpgradeChain()

type BlockStore

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

func NewBlockStore

func NewBlockStore(db dbm.DB, client queue.Client) *BlockStore

func (*BlockStore) AddTxs

func (bs *BlockStore) AddTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error

通过批量存储tx信息到db中

func (*BlockStore) DelBlock

func (bs *BlockStore) DelBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) error

删除block信息从db数据库中

func (*BlockStore) DelTxs

func (bs *BlockStore) DelTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetail) error

通过批量删除tx信息从db中

func (*BlockStore) Get

func (*BlockStore) GetBlockHashByHeight

func (bs *BlockStore) GetBlockHashByHeight(height int64) ([]byte, error)

从db数据库中获取指定height对应的blockhash

func (*BlockStore) GetBlockHeaderByHash

func (bs *BlockStore) GetBlockHeaderByHash(hash []byte) (*types.Header, error)

通过blockhash获取blockheader

func (*BlockStore) GetBlockHeaderByHeight

func (bs *BlockStore) GetBlockHeaderByHeight(height int64) (*types.Header, error)

通过blockheight获取blockheader

func (*BlockStore) GetBlockSequence

func (bs *BlockStore) GetBlockSequence(Sequence int64) (*types.BlockSequence, error)

从db数据库中获取指定Sequence对应的block序列操作信息

func (*BlockStore) GetDbVersion

func (bs *BlockStore) GetDbVersion() int64

获取blockchain的数据库版本号

func (*BlockStore) GetHeightByBlockHash

func (bs *BlockStore) GetHeightByBlockHash(hash []byte) (int64, error)

从db数据库中获取指定hash对应的block高度

func (*BlockStore) GetSequenceByHash

func (bs *BlockStore) GetSequenceByHash(hash []byte) (int64, error)

通过block还是获取对应的seq,只提供给parachain使用

func (*BlockStore) GetTdByBlockHash

func (bs *BlockStore) GetTdByBlockHash(hash []byte) (*big.Int, error)

从db数据库中获取指定blockhash对应的block总难度td

func (*BlockStore) GetTx

func (bs *BlockStore) GetTx(hash []byte) (*types.TxResult, error)

通过tx hash 从db数据库中获取tx交易信息

func (*BlockStore) GetUpgradeMeta

func (bs *BlockStore) GetUpgradeMeta() (*types.UpgradeMeta, error)

func (*BlockStore) HasTx

func (bs *BlockStore) HasTx(key []byte) (bool, error)

func (*BlockStore) Height

func (bs *BlockStore) Height() int64

返回BlockStore保存的当前block高度

func (*BlockStore) LastBlock

func (bs *BlockStore) LastBlock() *types.Block

获取最新的block信息

func (*BlockStore) LastHeader

func (bs *BlockStore) LastHeader() *types.Header

返回BlockStore保存的当前blockheader

func (*BlockStore) LoadBlockByHash

func (bs *BlockStore) LoadBlockByHash(hash []byte) (*types.BlockDetail, error)

通过hash获取BlockDetail信息

func (*BlockStore) LoadBlockByHeight

func (bs *BlockStore) LoadBlockByHeight(height int64) (*types.BlockDetail, error)

通过height高度获取BlockDetail信息

func (*BlockStore) LoadBlockBySequence

func (bs *BlockStore) LoadBlockBySequence(Sequence int64) (*types.BlockDetail, error)

通过seq高度获取BlockDetail信息

func (*BlockStore) LoadBlockLastSequence

func (bs *BlockStore) LoadBlockLastSequence() (int64, error)

获取当前最新的block操作序列号

func (*BlockStore) NewBatch

func (bs *BlockStore) NewBatch(sync bool) dbm.Batch

func (*BlockStore) SaveBlock

func (bs *BlockStore) SaveBlock(storeBatch dbm.Batch, blockdetail *types.BlockDetail, sequence int64) error

批量保存blocks信息到db数据库中

func (*BlockStore) SaveBlockSequence

func (bs *BlockStore) SaveBlockSequence(storeBatch dbm.Batch, hash []byte, height int64, Type int64, sequence int64) error

存储block 序列执行的类型用于blockchain的恢复 获取当前的序列号,将此序列号加1存储本block的hash ,当主链使能isRecordBlockSequence 平行链使能isParaChain时,sequence序列号是传入的

func (*BlockStore) SaveTdByBlockHash

func (bs *BlockStore) SaveTdByBlockHash(storeBatch dbm.Batch, hash []byte, td *big.Int) error

保存block hash对应的总难度到db中

func (*BlockStore) SetDbVersion

func (bs *BlockStore) SetDbVersion(versionNo int64) error

获取blockchain的数据库版本号

func (*BlockStore) SetUpgradeMeta

func (bs *BlockStore) SetUpgradeMeta(meta *types.UpgradeMeta) error

获取blockchain的数据库版本号

func (*BlockStore) UpdateHeight

func (bs *BlockStore) UpdateHeight()

更新db中的block高度到BlockStore.Height

func (*BlockStore) UpdateHeight2

func (bs *BlockStore) UpdateHeight2(height int64)

func (*BlockStore) UpdateLastBlock

func (bs *BlockStore) UpdateLastBlock(hash []byte)

更新LastBlock到缓存中

func (*BlockStore) UpdateLastBlock2

func (bs *BlockStore) UpdateLastBlock2(block *types.Block)

type FaultPeerInfo

type FaultPeerInfo struct {
	Peer        *PeerInfo
	FaultHeight int64
	FaultHash   []byte
	ErrInfo     error
	ReqFlag     bool
}

可疑故障节点信息

type ForkInfo

type ForkInfo struct {
	ForkStartHeight int64
	ForkEndHeight   int64
	ForkPid         string
}

blockchain模块fork处理结构体

type OrphanPool

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

孤儿节点的存储以blockhash作为map的索引。hash转换成string

func NewOrphanPool

func NewOrphanPool() *OrphanPool

func (*OrphanPool) GetChildOrphanCount

func (op *OrphanPool) GetChildOrphanCount(hash string) int

获取父hash对应的子孤儿节点的个数

func (*OrphanPool) GetOrphanRoot

func (op *OrphanPool) GetOrphanRoot(hash []byte) []byte

获取本孤儿节点的祖先节点hash在孤儿链中,没有的话就返回孤儿节点本身hash

func (*OrphanPool) IsKnownOrphan

func (op *OrphanPool) IsKnownOrphan(hash []byte) bool

判断本节点是不是已知的孤儿节点

func (*OrphanPool) RemoveOrphanBlock

func (op *OrphanPool) RemoveOrphanBlock(orphan *orphanBlock)

删除孤儿节点从OrphanPool中,以及prevOrphans中的index

func (*OrphanPool) RemoveOrphanBlock2

func (op *OrphanPool) RemoveOrphanBlock2(block *types.Block, expiration time.Time, broadcast bool, pid string, sequence int64)

type PeerInfo

type PeerInfo struct {
	Name       string
	ParentHash []byte
	Height     int64
	Hash       []byte
}

blockchain模块需要保存的peerinfo

type PeerInfoList

type PeerInfoList []*PeerInfo

func (PeerInfoList) Len

func (list PeerInfoList) Len() int

func (PeerInfoList) Less

func (list PeerInfoList) Less(i, j int) bool

func (PeerInfoList) Swap

func (list PeerInfoList) Swap(i, j int)

type Query

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

func NewQuery

func NewQuery(db dbm.DB, qclient queue.Client, stateHash []byte) *Query

func (*Query) Query

func (q *Query) Query(driver string, funcname string, param types.Message) (types.Message, error)

type Task

type Task struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Task) Cancel

func (t *Task) Cancel() error

func (*Task) Done

func (t *Task) Done(height int64)

func (*Task) InProgress

func (t *Task) InProgress() bool

func (*Task) Start

func (t *Task) Start(start, end int64, cb func()) error

func (*Task) TimerReset

func (t *Task) TimerReset(timeout time.Duration)

func (*Task) TimerStop

func (t *Task) TimerStop()

Jump to

Keyboard shortcuts

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