consensus

package
v6.4.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package consensus 系统基础共识包

Index

Constants

This section is empty.

Variables

View Source
var QueryData = types.NewQueryData("Query_")

QueryData 检索数据

Functions

func Reg

func Reg(name string, create Create)

Reg ...

Types

type BaseClient

type BaseClient struct {
	Cfg *types.Consensus
	// contains filtered or unexported fields
}

BaseClient ...

func NewBaseClient

func NewBaseClient(cfg *types.Consensus) *BaseClient

NewBaseClient ...

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

func (bc *BaseClient) Close()

Close 关闭

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

func (bc *BaseClient) EventLoop()

EventLoop 准备新区块

func (*BaseClient) ExecConsensus

func (bc *BaseClient) ExecConsensus(data *types.ChainExecutor) (types.Message, error)

ExecConsensus 执行共识

func (*BaseClient) GetAPI

func (bc *BaseClient) GetAPI() client.QueueProtocolAPI

GetAPI 获取api

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

func (bc *BaseClient) InitBlock()

InitBlock change init block

func (*BaseClient) InitClient

func (bc *BaseClient) InitClient(c queue.Client, minerstartCB func())

InitClient 初始化

func (*BaseClient) InitMiner

func (bc *BaseClient) InitMiner()

InitMiner 初始化矿工

func (*BaseClient) IsCaughtUp

func (bc *BaseClient) IsCaughtUp() bool

IsCaughtUp 是否追上最新高度

func (*BaseClient) IsClosed

func (bc *BaseClient) IsClosed() bool

IsClosed 是否已经关闭

func (*BaseClient) IsMining

func (bc *BaseClient) IsMining() bool

IsMining 是否在挖矿

func (*BaseClient) Lock

func (bc *BaseClient) Lock()

Lock 上锁

func (*BaseClient) PreExecBlock

func (bc *BaseClient) PreExecBlock(block *types.Block, errReturn bool) *types.Block

PreExecBlock 预执行区块, 用于raft, tendermint等共识, errReturn表示区块来源于自己还是别人

func (*BaseClient) RandInt64

func (bc *BaseClient) RandInt64() int64

RandInt64 随机数

func (*BaseClient) ReqBlockByHash

func (bc *BaseClient) ReqBlockByHash(hash []byte) (*types.Block, error)

RequestBlockByHash 通过区块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) SetAPI

func (bc *BaseClient) SetAPI(api client.QueueProtocolAPI)

SetAPI ...

func (*BaseClient) SetChild

func (bc *BaseClient) SetChild(c Miner)

SetChild ...

func (*BaseClient) SetCurrentBlock

func (bc *BaseClient) SetCurrentBlock(b *types.Block)

SetCurrentBlock 设置当前区块

func (*BaseClient) SetQueueClient

func (bc *BaseClient) SetQueueClient(c queue.Client)

SetQueueClient 设置客户端队列

func (*BaseClient) Unlock

func (bc *BaseClient) Unlock()

Unlock 解锁

func (*BaseClient) UpdateCurrentBlock

func (bc *BaseClient) UpdateCurrentBlock(b *types.Block)

UpdateCurrentBlock 更新当前区块

func (*BaseClient) Wait

func (bc *BaseClient) Wait()

Wait wait for ready

func (*BaseClient) WriteBlock

func (bc *BaseClient) WriteBlock(prev []byte, block *types.Block) error

WriteBlock 向blockchain写区块

type Create

type Create func(cfg *types.Consensus, sub []byte) queue.Module

Create 创建共识

func Load

func Load(name string) (create Create, err error)

Load 加载

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
}

Miner 矿工

Directories

Path Synopsis
Package init 初始化系统共识插件
Package init 初始化系统共识插件
Package solo solo共识挖矿
Package solo solo共识挖矿

Jump to

Keyboard shortcuts

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