blockchain

package
v6.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

	HashToSeqPerfix = []byte("HashToSeq:")

	AddBlock int64 = 1
	DelBlock int64 = 2
)

var

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

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

)

var

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

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

	FutureBlockDelayTime int64 = 1
)

var

Functions

func GetLocalDBKeyList

func GetLocalDBKeyList() [][]byte

GetLocalDBKeyList 获取本地键值列表

func GetNtpClockSyncStatus

func GetNtpClockSyncStatus() bool

GetNtpClockSyncStatus 获取ntp时间是否同步状态

func GetTransactionProofs

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

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

func IsRecordFaultErr

func IsRecordFaultErr(err error) bool

IsRecordFaultErr 检测此错误是否要记录到故障错误中

func LoadBlockStoreHeight

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

LoadBlockStoreHeight 加载区块高度

func UpdateNtpClockSyncStatus

func UpdateNtpClockSyncStatus(Sync bool)

UpdateNtpClockSyncStatus 定时更新ntp时间同步状态

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 NewBlockCache

func NewBlockCache(defCacheSize int64) *BlockCache

NewBlockCache new

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 {
	// contains filtered or unexported fields
}

BlockChain 区块链结构体

func New

func New(cfg *types.BlockChain) *BlockChain

New new

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

func (chain *BlockChain) Close()

Close 关闭区块链

func (*BlockChain) DefaultForkInfo

func (chain *BlockChain) DefaultForkInfo()

DefaultForkInfo 将forkinfo恢复成默认值

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信息

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

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

GetDB 获取DB

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

func (chain *BlockChain) GetForkInfo() *ForkInfo

GetForkInfo 获取forkinfo

func (*BlockChain) GetMaxPeerInfo

func (chain *BlockChain) GetMaxPeerInfo() *PeerInfo

GetMaxPeerInfo 获取peerlist中最高节点的peerinfo

func (*BlockChain) GetOrphanPool

func (chain *BlockChain) GetOrphanPool() *OrphanPool

GetOrphanPool 获取孤儿链

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

func (chain *BlockChain) GetPeers() PeerInfoList

GetPeers 获取所有peers

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

func (chain *BlockChain) InitBlockChain()

InitBlockChain 区块链初始化

func (*BlockChain) InitCache

func (chain *BlockChain) InitCache(height int64)

InitCache 初始化缓存

func (*BlockChain) InitForkInfo

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

InitForkInfo 开始新的fork处理

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

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

ProcBlockChainFork 处理从peer获取的headers消息

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

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

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

func (chain *BlockChain) ReqForkBlocks()

ReqForkBlocks 请求fork处理的blocks

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

func (chain *BlockChain) SynBlocksFromPeers()

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

func (*BlockChain) SynRoutine

func (chain *BlockChain) SynRoutine()

SynRoutine 同步事务

func (*BlockChain) UpdateFaultPeer

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

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

func (*BlockChain) UpdateForkStartHeight

func (chain *BlockChain) UpdateForkStartHeight(forkStartHeight int64)

UpdateForkStartHeight 更新fork 请求的起始block高度

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

func (chain *BlockChain) UpgradeChain()

UpgradeChain 升级localdb

func (*BlockChain) Wait

func (chain *BlockChain) Wait()

Wait for ready

type BlockStore

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

BlockStore 区块存储

func NewBlockStore

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

Get get

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

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

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

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

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

HasTx 是否包含该交易

func (*BlockStore) Height

func (bs *BlockStore) Height() int64

Height 返回BlockStore保存的当前block高度

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

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

LoadBlockBySequence 通过seq高度获取BlockDetail信息

func (*BlockStore) LoadBlockLastSequence

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

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

func (*BlockStore) NewBatch

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

NewBatch new

func (*BlockStore) SaveBlock

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

SaveBlock 批量保存blocks信息到db数据库中,并返回最新的sequence值

func (*BlockStore) SaveTdByBlockHash

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

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

func (*BlockStore) SetDbVersion

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

SetDbVersion 获取blockchain的数据库版本号

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 FaultPeerInfo

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

FaultPeerInfo 可疑故障节点信息

type ForkInfo

type ForkInfo struct {
	ForkStartHeight int64
	ForkEndHeight   int64
	ForkPid         string
}

ForkInfo blockchain模块fork处理结构体

type OrphanPool

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

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

func NewOrphanPool

func NewOrphanPool() *OrphanPool

NewOrphanPool new

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

type PeerInfo

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

PeerInfo blockchain模块需要保存的peerinfo

type PeerInfoList

type PeerInfoList []*PeerInfo

PeerInfoList 节点列表

func (PeerInfoList) Len

func (list PeerInfoList) Len() int

Len 长度

func (PeerInfoList) Less

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

Less 小于

func (PeerInfoList) Swap

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

Swap 交换

type Query

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

Query 检索

func NewQuery

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

NewQuery new

func (*Query) Query

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

Query 检索

type Task

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

Task 任务

func (*Task) Cancel

func (t *Task) Cancel() error

Cancel 任务取消

func (*Task) Done

func (t *Task) Done(height int64)

Done 任务完成

func (*Task) InProgress

func (t *Task) InProgress() bool

InProgress 是否在执行

func (*Task) Start

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

Start 计时器启动

func (*Task) TimerReset

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

TimerReset 计时器重置

func (*Task) TimerStop

func (t *Task) TimerStop()

TimerStop 计时器停止

Jump to

Keyboard shortcuts

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