Documentation ¶
Overview ¶
Package consensus 系统基础共识包
Index ¶
- Variables
- func Reg(name string, create Create)
- func RegCommitter(name string, c Committer)
- type BaseClient
- func (bc *BaseClient) AddBlock(b *types.Block) error
- func (bc *BaseClient) AddTxsToBlock(block *types.Block, txs []*types.Transaction) []*types.Transaction
- func (bc *BaseClient) CheckBlock(block *types.BlockDetail) error
- func (bc *BaseClient) CheckTxDup(txs []*types.Transaction) (transactions []*types.Transaction)
- func (bc *BaseClient) CheckTxExpire(txs []*types.Transaction, height int64, blocktime int64) (transactions []*types.Transaction)
- func (bc *BaseClient) Close()
- func (bc *BaseClient) CmpBestBlock(newBlock *types.Block, cmpHash []byte) bool
- func (bc *BaseClient) ConsensusTicketMiner(iscaughtup *types.IsCaughtUp)
- func (bc *BaseClient) EventLoop()
- func (bc *BaseClient) ExecConsensus(data *types.ChainExecutor) (types.Message, error)
- func (bc *BaseClient) GetAPI() client.QueueProtocolAPI
- func (bc *BaseClient) GetBaseClient() *BaseClient
- func (bc *BaseClient) GetCurrentBlock() (b *types.Block)
- func (bc *BaseClient) GetCurrentHeight() int64
- func (bc *BaseClient) GetGenesisBlockTime() int64
- func (bc *BaseClient) GetQueueClient() queue.Client
- func (bc *BaseClient) InitBlock()
- func (bc *BaseClient) InitClient(c queue.Client, minerstartCB func())
- func (bc *BaseClient) InitMiner()
- func (bc *BaseClient) InitStateCommitter()
- func (bc *BaseClient) IsCaughtUp() bool
- func (bc *BaseClient) IsClosed() bool
- func (bc *BaseClient) IsMining() bool
- func (bc *BaseClient) Lock()
- func (bc *BaseClient) PreExecBlock(block *types.Block, errReturn bool) *types.Block
- func (bc *BaseClient) RandInt64() int64
- func (bc *BaseClient) ReqBlockByHash(hash []byte) (*types.Block, error)
- func (bc *BaseClient) RequestBlock(start int64) (*types.Block, error)
- func (bc *BaseClient) RequestLastBlock() (*types.Block, error)
- func (bc *BaseClient) RequestTx(listSize int, txHashList [][]byte) []*types.Transaction
- func (bc *BaseClient) SetAPI(api client.QueueProtocolAPI)
- func (bc *BaseClient) SetChild(c Miner)
- func (bc *BaseClient) SetCommitter(c Committer)
- func (bc *BaseClient) SetCurrentBlock(b *types.Block)
- func (bc *BaseClient) SetQueueClient(c queue.Client)
- func (bc *BaseClient) Unlock()
- func (bc *BaseClient) UpdateCurrentBlock(b *types.Block)
- func (bc *BaseClient) Wait()
- func (bc *BaseClient) WriteBlock(prev []byte, block *types.Block) error
- type Committer
- type Create
- type Miner
Constants ¶
This section is empty.
Variables ¶
var ModuleName = "consensus"
ModuleName module name
var QueryData = types.NewQueryData("Query_")
QueryData 检索数据
Functions ¶
Types ¶
type BaseClient ¶
type BaseClient struct { Cfg *types.Consensus Context context.Context Cancel context.CancelFunc // contains filtered or unexported fields }
BaseClient ...
func (*BaseClient) AddBlock ¶
func (bc *BaseClient) AddBlock(b *types.Block) error
AddBlock 添加区块的时候,通知系统做处理
func (*BaseClient) AddTxsToBlock ¶
func (bc *BaseClient) AddTxsToBlock(block *types.Block, txs []*types.Transaction) []*types.Transaction
AddTxsToBlock 添加交易到区块中
func (*BaseClient) CheckBlock ¶
func (bc *BaseClient) CheckBlock(block *types.BlockDetail) error
CheckBlock 检查区块
func (*BaseClient) CheckTxDup ¶
func (bc *BaseClient) CheckTxDup(txs []*types.Transaction) (transactions []*types.Transaction)
CheckTxDup 为了不引起交易检查时候产生的无序
func (*BaseClient) CheckTxExpire ¶
func (bc *BaseClient) CheckTxExpire(txs []*types.Transaction, height int64, blocktime int64) (transactions []*types.Transaction)
CheckTxExpire 此时的tx交易组都是展开的,过滤掉已经过期的tx交易,目前只有ticket共识需要在updateBlock时调用
func (*BaseClient) CmpBestBlock ¶
func (bc *BaseClient) CmpBestBlock(newBlock *types.Block, cmpHash []byte) bool
CmpBestBlock 最优区块的比较 height,BlockTime,ParentHash必须一致才可以继续比较 通过比较newBlock是最优区块就返回true,否则返回false
func (*BaseClient) ConsensusTicketMiner ¶
func (bc *BaseClient) ConsensusTicketMiner(iscaughtup *types.IsCaughtUp)
ConsensusTicketMiner ...
func (*BaseClient) ExecConsensus ¶
func (bc *BaseClient) ExecConsensus(data *types.ChainExecutor) (types.Message, error)
ExecConsensus 执行共识
func (*BaseClient) GetBaseClient ¶
func (bc *BaseClient) GetBaseClient() *BaseClient
GetBaseClient get base client
func (*BaseClient) GetCurrentBlock ¶
func (bc *BaseClient) GetCurrentBlock() (b *types.Block)
GetCurrentBlock 获取当前区块
func (*BaseClient) GetCurrentHeight ¶
func (bc *BaseClient) GetCurrentHeight() int64
GetCurrentHeight 获取当前高度
func (*BaseClient) GetGenesisBlockTime ¶
func (bc *BaseClient) GetGenesisBlockTime() int64
GetGenesisBlockTime 获取创世区块时间
func (*BaseClient) GetQueueClient ¶
func (bc *BaseClient) GetQueueClient() queue.Client
GetQueueClient 获取客户端队列
func (*BaseClient) InitClient ¶
func (bc *BaseClient) InitClient(c queue.Client, minerstartCB func())
InitClient 初始化
func (*BaseClient) InitStateCommitter ¶
func (bc *BaseClient) InitStateCommitter()
InitStateCommitter init committer
func (*BaseClient) PreExecBlock ¶
PreExecBlock 预执行区块, 用于raft, tendermint等共识, errReturn表示区块来源于自己还是别人
func (*BaseClient) ReqBlockByHash ¶
func (bc *BaseClient) ReqBlockByHash(hash []byte) (*types.Block, error)
ReqBlockByHash 通过区块hash获取区块信息
func (*BaseClient) RequestBlock ¶
func (bc *BaseClient) RequestBlock(start int64) (*types.Block, error)
RequestBlock 请求区块
func (*BaseClient) RequestLastBlock ¶
func (bc *BaseClient) RequestLastBlock() (*types.Block, error)
RequestLastBlock 获取最新的block从blockchain模块
func (*BaseClient) RequestTx ¶
func (bc *BaseClient) RequestTx(listSize int, txHashList [][]byte) []*types.Transaction
RequestTx Mempool中取交易列表
func (*BaseClient) SetCommitter ¶
func (bc *BaseClient) SetCommitter(c Committer)
SetCommitter set committer
func (*BaseClient) SetCurrentBlock ¶
func (bc *BaseClient) SetCurrentBlock(b *types.Block)
SetCurrentBlock 设置当前区块
func (*BaseClient) SetQueueClient ¶
func (bc *BaseClient) SetQueueClient(c queue.Client)
SetQueueClient 设置客户端队列
func (*BaseClient) UpdateCurrentBlock ¶
func (bc *BaseClient) UpdateCurrentBlock(b *types.Block)
UpdateCurrentBlock 更新当前区块
func (*BaseClient) WriteBlock ¶
func (bc *BaseClient) WriteBlock(prev []byte, block *types.Block) error
WriteBlock 向blockchain写区块
type Committer ¶
type Committer interface { Init(base *BaseClient, subCfg []byte) SubMsg(msg *queue.Message) }
Committer state commiter
type Miner ¶
type Miner interface { CreateGenesisTx() []*types.Transaction GetGenesisBlockTime() int64 CreateBlock() AddBlock(b *types.Block) error CheckBlock(parent *types.Block, current *types.BlockDetail) error ProcEvent(msg *queue.Message) bool CmpBestBlock(newBlock *types.Block, cmpBlock *types.Block) bool GetBaseClient() *BaseClient }
Miner 矿工