blockchain

package
v1.67.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: BSD-3-Clause Imports: 34 Imported by: 17

Documentation

Overview

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

Index

Constants

View Source
const (
	// OnceMaxChunkNum 每次检测最大生成chunk数
	OnceMaxChunkNum int32 = 30
	// DelRollbackChunkNum 删除小于当前chunk为DelRollbackChunkNum
	DelRollbackChunkNum int32 = 10
	// MaxReqChunkRecord 每次请求最大MaxReqChunkRecord个chunk的record
	MaxReqChunkRecord int32 = 100
)

Variables

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

	HashToSeqPrefix = []byte("HashToSeq:")

	HashToParaSeqPrefix = []byte("HashToParaSeq:")
	LastParaSequence    = []byte("LastParaSequence")
	// chunk相关
	BodyHashToChunk    = []byte("BodyHashToChunk:")
	ChunkNumToHash     = []byte("ChunkNumToHash:")
	ChunkHashToNum     = []byte("ChunkHashToNum:")
	RecvChunkNumToHash = []byte("RecvChunkNumToHash:")
	MaxSerialChunkNum  = []byte("MaxSilChunkNum:")
	MaxDeletedChunkNum = []byte("MaxDeletedChunkNum:")
)

var

View Source
var (
	BackBlockNum     int64 = 128 //节点高度不增加时向后取blocks的个数
	BackwardBlockNum int64 = 16  //本节点高度不增加时并且落后peer的高度数

	MaxRollBlockNum    int64 = 10000                //最大回退block数量
	ReduceHeight             = MaxRollBlockNum      // 距离最大高度的可精简高度
	SafetyReduceHeight       = ReduceHeight * 3 / 2 // 安全精简高度

)

var

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

	FutureBlockDelayTime int64 = 1
)

var

View Source
var (
	//ErrNoBlockToChunk ...
	ErrNoBlockToChunk = errors.New("ErrNoBlockToChunk")
	//ErrNoChunkInfoToDownLoad ...
	ErrNoChunkInfoToDownLoad = errors.New("ErrNoChunkInfoToDownLoad")
)
View Source
var (
	ErrIsOrphan                   = errors.New("ErrIsOrphan")
	ErrIsSideChain                = errors.New("ErrIsSideChain")
	ErrBlockHeightDiscontinuous   = errors.New("ErrBlockHeightDiscontinuous")
	ErrCurHeightMoreThanEndHeight = errors.New("ErrCurHeightMoreThanEndHeight")
)

errors

Functions

func GetLocalDBKeyList

func GetLocalDBKeyList() [][]byte

GetLocalDBKeyList 获取本地键值列表 增加chainBody和chainHeader对应的四个key。chainParaTx的可以在区块0高度时是没有的 bodyPrefix,headerPrefix,heightToHeaderPrefix这三个key不再使用

func IsRecordFaultErr

func IsRecordFaultErr(err error) bool

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

func LoadBlockStoreHeight

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

LoadBlockStoreHeight 加载区块高度

func NewBodyTable

func NewBodyTable(kvdb dbm.KV) *table.Table

NewBodyTable 新建表

func NewHeaderTable

func NewHeaderTable(kvdb dbm.KV) *table.Table

NewHeaderTable 新建表

func NewParaTxTable

func NewParaTxTable(kvdb dbm.KV) *table.Table

NewParaTxTable 新建表

func NewReceiptTable

func NewReceiptTable(kvdb dbm.KV) *table.Table

NewReceiptTable 新建表

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) AddBlock added in v1.65.1

func (bc *BlockCache) AddBlock(detail *types.BlockDetail)

AddBlock 区块增长,添加block到cache中,方便快速查询

func (*BlockCache) DelBlock added in v1.65.1

func (bc *BlockCache) DelBlock(height int64)

DelBlock 区块回滚,删除block

func (*BlockCache) GetBlockByHash added in v1.65.1

func (bc *BlockCache) GetBlockByHash(hash []byte) (block *types.BlockDetail)

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

func (*BlockCache) GetBlockByHeight added in v1.65.1

func (bc *BlockCache) GetBlockByHeight(height int64) *types.BlockDetail

GetBlockByHeight 从cache缓存中获取block信息

func (*BlockCache) GetBlockHash added in v1.65.1

func (bc *BlockCache) GetBlockHash(height int64) []byte

GetBlockHash get block hash by height

type BlockChain

type BlockChain struct {

	//cfg
	MaxFetchBlockNum int64 //一次最多申请获取block个数
	TimeoutSeconds   int64
	// contains filtered or unexported fields
}

BlockChain 区块链结构体

func New

func New(cfg *types.Chain33Config) *BlockChain

New new

func (*BlockChain) AddCacheBlock added in v1.65.1

func (chain *BlockChain) AddCacheBlock(detail *types.BlockDetail)

AddCacheBlock 添加区块相关缓存

func (*BlockChain) AddChunkRecord added in v1.65.0

func (chain *BlockChain) AddChunkRecord(req *types.ChunkRecords)

AddChunkRecord ...

func (*BlockChain) AddFaultPeer

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

AddFaultPeer 添加故障节点到故障FaultPeerList中

func (*BlockChain) CalcChunkInfo added in v1.65.0

func (chain *BlockChain) CalcChunkInfo(height int64) (chunkNum, start, end int64)

CalcChunkInfo 主要用于计算验证

func (*BlockChain) CalcSafetyChunkInfo added in v1.65.0

func (chain *BlockChain) CalcSafetyChunkInfo(height int64) (chunkNum, start, end int64)

CalcSafetyChunkInfo 计算安全的chunkNum用于生成chunk时候或者删除时候

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) CheckDeleteBlockBody added in v1.65.0

func (chain *BlockChain) CheckDeleteBlockBody()

CheckDeleteBlockBody 检测是否需要删除已经归档BlockBody

func (*BlockChain) CheckGenChunkNum added in v1.65.0

func (chain *BlockChain) CheckGenChunkNum()

CheckGenChunkNum 检测是否需要生成chunkNum

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) ChunkDownLoadBlocks added in v1.65.0

func (chain *BlockChain) ChunkDownLoadBlocks()

ChunkDownLoadBlocks 开启快速下载区块的模式

func (*BlockChain) ChunkRecordSync added in v1.65.0

func (chain *BlockChain) ChunkRecordSync()

ChunkRecordSync 同步chunkrecord

func (*BlockChain) Close

func (chain *BlockChain) Close()

Close 关闭区块链

func (*BlockChain) DefaultDownLoadInfo

func (chain *BlockChain) DefaultDownLoadInfo()

DefaultDownLoadInfo 将DownLoadInfo恢复成默认值

func (*BlockChain) DelCacheBlock added in v1.65.0

func (chain *BlockChain) DelCacheBlock(height int64, hash []byte)

DelCacheBlock 删除缓存的中对应的区块

func (*BlockChain) DelLastTempBlockHeight

func (chain *BlockChain) DelLastTempBlockHeight()

DelLastTempBlockHeight 快速下载结束时删除此标志位

func (*BlockChain) DeleteBlockBody added in v1.65.0

func (chain *BlockChain) DeleteBlockBody(chunkNum int64) []*types.KeyValue

DeleteBlockBody del chunk body

func (*BlockChain) DownLoadBlocks added in v1.65.0

func (chain *BlockChain) DownLoadBlocks()

DownLoadBlocks 下载区块

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) FetchChunkBlockRoutine added in v1.65.3

func (chain *BlockChain) FetchChunkBlockRoutine()

FetchChunkBlockRoutine requests 4 chunks in same time

func (*BlockChain) FetchChunkRecords added in v1.65.0

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

FetchChunkRecords 从指定pid获取start到end之间的ChunkRecord,只需要获取存储归档索引 blockHeight--->chunkhash

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) (detail *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) GetChunkBlockBody added in v1.65.0

func (chain *BlockChain) GetChunkBlockBody(req *types.ChunkInfoMsg) (*types.BlockBodys, error)

GetChunkBlockBody 从localdb本地获取chunkbody

func (*BlockChain) GetChunkRecord added in v1.65.0

func (chain *BlockChain) GetChunkRecord(req *types.ReqChunkRecords) (*types.ChunkRecords, error)

GetChunkRecord ...

func (*BlockChain) GetCurChunkNum added in v1.65.0

func (chain *BlockChain) GetCurChunkNum() int64

GetCurChunkNum ...

func (*BlockChain) GetCurRecvChunkNum added in v1.65.0

func (chain *BlockChain) GetCurRecvChunkNum() int64

GetCurRecvChunkNum ...

func (*BlockChain) GetDB

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

GetDB 获取DB

func (*BlockChain) GetDownLoadInfo

func (chain *BlockChain) GetDownLoadInfo() *DownLoadInfo

GetDownLoadInfo 获取DownLoadInfo

func (*BlockChain) GetDownloadSyncStatus

func (chain *BlockChain) GetDownloadSyncStatus() int

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

func (chain *BlockChain) GetParaTxByHeight(req *types.ReqParaTxByHeight) (*types.ParaTxDetails, error)

GetParaTxByHeight 通过height以及title获取对应平行连的交易

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

func (chain *BlockChain) GetPeers() PeerInfoList

GetPeers 获取所有peers

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, txHeight int64) (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) InitBlockChain

func (chain *BlockChain) InitBlockChain()

InitBlockChain 区块链初始化

func (*BlockChain) InitCache

func (chain *BlockChain) InitCache(currHeight int64)

InitCache 初始化缓存

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

func (chain *BlockChain) InitReduceLocalDB(height int64)

InitReduceLocalDB 初始化启动时候执行

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 (chain *BlockChain) LoadBlockByHash(hash []byte) (block *types.BlockDetail, err error)

LoadBlockByHash 根据hash值从缓存中查询区块

func (*BlockChain) LoadParaTxByHeight

func (chain *BlockChain) LoadParaTxByHeight(height int64, title string, count, direction int32) (*types.HeightParas, error)

LoadParaTxByHeight 通过height获取本高度上的平行链title前后翻页;预留接口

func (*BlockChain) LoadParaTxByTitle

func (chain *BlockChain) LoadParaTxByTitle(req *types.ReqHeightByTitle) (*types.ReplyHeightByTitle, error)

LoadParaTxByTitle 通过title获取本平行链交易所在的区块高度信息前后翻页

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

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) ProcGetLastPushSeq added in v1.65.0

func (chain *BlockChain) ProcGetLastPushSeq(name string) (int64, error)

ProcGetLastPushSeq Seq的合法值从0开始的,所以没有获取到或者获取失败都应该返回-1

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) 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) ProcListPush added in v1.65.0

func (chain *BlockChain) ProcListPush() (*types.PushSubscribes, error)

ProcListPush 列出所有已经设置的推送订阅

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 (chain *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 (chain *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) ReadChunkBlockToExec added in v1.65.3

func (chain *BlockChain) ReadChunkBlockToExec()

ReadChunkBlockToExec 执行Chunk下载临时存储在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) ReduceChain

func (chain *BlockChain) ReduceChain()

ReduceChain 精简chain

func (*BlockChain) ReduceLocalDB

func (chain *BlockChain) ReduceLocalDB()

ReduceLocalDB 实时精简localdb

func (*BlockChain) RemoveFaultPeer

func (chain *BlockChain) RemoveFaultPeer(pid string)

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

func (*BlockChain) ReqDownLoadBlocks

func (chain *BlockChain) ReqDownLoadBlocks()

ReqDownLoadBlocks 请求DownLoad处理的blocks

func (*BlockChain) Rollback

func (chain *BlockChain) Rollback()

Rollback chain Rollback

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

func (chain *BlockChain) SynRoutine()

SynRoutine 同步事务

func (*BlockChain) TryReduceLocalDB

func (chain *BlockChain) TryReduceLocalDB(flagHeight int64, rangeHeight int64) (newHeight int64)

TryReduceLocalDB TryReduce try reduce

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

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

func (chain *BlockChain) Upgrade()

Upgrade 升级localDB和storeDB

func (*BlockChain) UpgradeChain

func (chain *BlockChain) UpgradeChain()

UpgradeChain 升级localdb

func (*BlockChain) UpgradePlugin

func (chain *BlockChain) UpgradePlugin()

UpgradePlugin 升级插件

func (*BlockChain) UpgradeStore

func (chain *BlockChain) UpgradeStore()

UpgradeStore 升级storedb

func (*BlockChain) Wait

func (chain *BlockChain) Wait()

Wait for ready

func (*BlockChain) WriteBlockToDbTemp

func (chain *BlockChain) WriteBlockToDbTemp(block *types.Block, lastHeightSave bool) error

WriteBlockToDbTemp 快速下载的block临时存贮到数据库

type BlockOnChain

type BlockOnChain struct {
	sync.RWMutex
	Height      int64
	OnChainTime int64
}

BlockOnChain ... 记录最新区块上链的时间,长时间没有更新需要做对应的超时处理 主要是处理联盟链区块高度相差一个区块 整个网络长时间不出块时需要主动去获取最新的区块 BlockOnChain struct

type BlockStore

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

BlockStore 区块存储 TODO:有较多的冗余代码,接口函数需要进行功能梳理和重写

func NewBlockStore

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

NewBlockStore new

func (*BlockStore) AddActiveBlock added in v1.65.0

func (bs *BlockStore) AddActiveBlock(hash string, block *types.BlockDetail) bool

AddActiveBlock :将区块缓存到活跃区块中

func (*BlockStore) AddTxs

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

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

func (*BlockStore) BlockdetailToBlockBody

func (bs *BlockStore) BlockdetailToBlockBody(blockdetail *types.BlockDetail) *types.BlockBody

BlockdetailToBlockBody get block detail

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

Get get

func (*BlockStore) GetActiveBlock added in v1.65.0

func (bs *BlockStore) GetActiveBlock(hash string) (*types.BlockDetail, bool)

GetActiveBlock :从缓存的活跃区块中获取对应高度的区块

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

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

GetKey store通用接口, Get 已经被使用

func (*BlockStore) GetMainSequenceByHash

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

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

func (*BlockStore) GetMaxDeletedChunkNum added in v1.65.1

func (bs *BlockStore) GetMaxDeletedChunkNum() int64

GetMaxDeletedChunkNum gets max chunkNum of deleted chunks.

func (*BlockStore) GetMaxSerialChunkNum added in v1.65.0

func (bs *BlockStore) GetMaxSerialChunkNum() int64

GetMaxSerialChunkNum get max serial chunk num

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

func (bs *BlockStore) List(prefix []byte) ([][]byte, error)

List store通用接口

func (*BlockStore) LoadBlock added in v1.65.1

func (bs *BlockStore) LoadBlock(height int64, hash []byte) (block *types.BlockDetail, err error)

LoadBlock 通过height高度获取BlockDetail信息, hash可为空 首先通过height+hash 主键获取header和body 如果失败使用旧的代码获取block信息 主要考虑到使用新的软件在localdb没有完成升级之前, 启动的过程中通过height获取区块时需要兼容旧的存储格式 升级完成正常启动之后通过loadBlockByIndex获取block不应该有失败 TODO:升级是否是一次性的,升级完成后需要将无效代码移除

func (*BlockStore) LoadBlockByHash

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

LoadBlockByHash 通过hash获取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) NewBatch

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

NewBatch new

func (*BlockStore) PrefixCount

func (bs *BlockStore) PrefixCount(prefix []byte) int64

PrefixCount store通用接口

func (*BlockStore) RemoveActiveBlock added in v1.65.0

func (bs *BlockStore) RemoveActiveBlock(hash string) bool

RemoveActiveBlock :从缓存的活跃区块中删除对应的区块

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

func (bs *BlockStore) Set(key, value []byte) error

Set store通用接口

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) SetMaxDeletedChunkNum added in v1.65.1

func (bs *BlockStore) SetMaxDeletedChunkNum(chunkNum int64) error

SetMaxDeletedChunkNum sets max chunkNum of deleted chunks.

func (*BlockStore) SetMaxSerialChunkNum added in v1.65.0

func (bs *BlockStore) SetMaxSerialChunkNum(chunkNum int64) error

SetMaxSerialChunkNum set max serial chunk num

func (*BlockStore) SetStoreUpgradeMeta

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

SetStoreUpgradeMeta 设置blockchain中的Store的数据库版本号

func (*BlockStore) SetSync

func (bs *BlockStore) SetSync(key, value []byte) error

SetSync 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 TODO:命名不清晰,不能体现和原来函数的区别

func (*BlockStore) UpdateLastBlock

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

UpdateLastBlock 更新LastBlock到缓存中

func (*BlockStore) UpdateLastBlock2

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

UpdateLastBlock2 更新LastBlock到缓存中 TODO:命名不清晰,不能体现和原来函数的区别

type BodyRow

type BodyRow struct {
	*types.BlockBody
}

BodyRow table meta 结构

func NewBodyRow

func NewBodyRow() *BodyRow

NewBodyRow 新建一个meta 结构

func (*BodyRow) CreateRow

func (body *BodyRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*BodyRow) Get

func (body *BodyRow) Get(key string) ([]byte, error)

Get 获取索引对应的key值

func (*BodyRow) SetPayload

func (body *BodyRow) SetPayload(data types.Message) error

SetPayload 设置数据

type CommonStore

type CommonStore interface {
	SetSync(key, value []byte) error
	Set(key, value []byte) error
	GetKey(key []byte) ([]byte, error)
	PrefixCount(prefix []byte) int64
	List(prefix []byte) ([][]byte, error)
}

CommonStore 通用的store 接口 修改大一点,可能可以用 db.KVDB 先改动小一点, 用store, 如果接口一样可以直接换

type DownLoadInfo

type DownLoadInfo struct {
	StartHeight int64
	EndHeight   int64
	Pids        []string
}

DownLoadInfo blockchain模块下载block处理结构体

type ErrCountInfo

type ErrCountInfo struct {
	Height int64
	Count  int64
}

ErrCountInfo 启动download时read一个block失败等待最长时间为2分钟,120秒

type FaultPeerInfo

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

FaultPeerInfo 可疑故障节点信息

type HeaderRow

type HeaderRow struct {
	*types.Header
}

HeaderRow table meta 结构

func NewHeaderRow

func NewHeaderRow() *HeaderRow

NewHeaderRow 新建一个meta 结构

func (*HeaderRow) CreateRow

func (header *HeaderRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*HeaderRow) Get

func (header *HeaderRow) Get(key string) ([]byte, error)

Get 获取索引对应的key值

func (*HeaderRow) SetPayload

func (header *HeaderRow) SetPayload(data types.Message) error

SetPayload 设置数据

type OrphanPool

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

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

func NewOrphanPool

func NewOrphanPool(param *types.Chain33Config) *OrphanPool

NewOrphanPool new

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

type ParaTxRow struct {
	*types.HeightPara
}

ParaTxRow table meta 结构

func NewParaTxRow

func NewParaTxRow() *ParaTxRow

NewParaTxRow 新建一个meta 结构

func (*ParaTxRow) CreateRow

func (paratx *ParaTxRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*ParaTxRow) Get

func (paratx *ParaTxRow) Get(key string) ([]byte, error)

Get 获取索引对应的key值

func (*ParaTxRow) SetPayload

func (paratx *ParaTxRow) SetPayload(data types.Message) error

SetPayload 设置数据

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

type PostService interface {
	PostData(subscribe *types.PushSubscribeReq, postdata []byte, seq int64) (err error)
}

PostService ... post rawdata to subscriber

type Push added in v1.65.0

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

Push ...

func (*Push) Close added in v1.65.0

func (push *Push) Close()

Close ...

func (*Push) UpdateSeq added in v1.65.0

func (push *Push) UpdateSeq(seq int64)

UpdateSeq sequence 更新通知

type PushClient added in v1.65.0

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

PushClient ...

func (*PushClient) PostData added in v1.65.0

func (pushClient *PushClient) PostData(subscribe *types.PushSubscribeReq, postdata []byte, seq int64) (err error)

PostData ...

type PushType added in v1.65.0

type PushType int32

PushType ...

const (
	//PushBlock push block
	PushBlock PushType = iota
	//PushBlockHeader push block header
	PushBlockHeader
	//PushTxReceipt push tx receipt
	PushTxReceipt
	//PushTxResult push tx result
	PushTxResult
	//PushEVMEvent push evem tx event
	PushEVMEvent
)

func (PushType) String added in v1.66.1

func (p PushType) String() string

String format string

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 ReceiptRow

type ReceiptRow struct {
	*types.BlockReceipt
}

ReceiptRow table meta 结构

func NewReceiptRow

func NewReceiptRow() *ReceiptRow

NewReceiptRow 新建一个meta 结构

func (*ReceiptRow) CreateRow

func (recpt *ReceiptRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*ReceiptRow) Get

func (recpt *ReceiptRow) Get(key string) ([]byte, error)

Get 获取索引对应的key值

func (*ReceiptRow) SetPayload

func (recpt *ReceiptRow) SetPayload(data types.Message) error

SetPayload 设置数据

type SequenceStore

type SequenceStore interface {
	LoadBlockLastSequence() (int64, error)
	// seqUpdateChan -> block sequence
	GetBlockSequence(seq int64) (*types.BlockSequence, error)
	// hash -> block header
	GetBlockHeaderByHash(hash []byte) (*types.Header, error)
	// seqUpdateChan -> block, size
	LoadBlockBySequence(seq int64) (*types.BlockDetail, int, error)
	// get last header
	LastHeader() *types.Header
	// hash -> seqUpdateChan
	GetSequenceByHash(hash []byte) (int64, error)
}

SequenceStore ...

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(), timeoutcb func(height int64)) error

Start 计时器启动

func (*Task) TimerReset

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

TimerReset 计时器重置

func (*Task) TimerStop

func (t *Task) TimerStop()

TimerStop 计时器停止

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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