Documentation

Index

Constants

const (

	// ModeNormal 正常启动模式,参与共识
	ModeNormal
	// ModeJoin 以新节点加入集群的模式启动
	ModeJoin
	// ModeWatch 以观察模式启动,不参与共识,只同步区块
	ModeWatch
	// ModeTest 以观察模式启动,但不同步区块,数据通过接口伪造
	ModeTest
)

节点的启动模式


const (
	// BlockInterval 产出区块的频率
	BlockInterval = 10 * time.Second
)

Variables

var (
	ClusterSize      int
	TotalNodeCount   int
	QuorumN          int
	AccuseQuorumN    int
	MaxFaultyN       int
	NodeList         []NodeInfo
	ClusterSnapshot  *Snapshot //节点列表快照
	DbCache          = 16
	DbFileHandles    = 16
	NodeSigners      map[int32]*crypto.SecureSigner
	MultiSigSnapshot MultiSigInfos
	CurrMultiSig     MultiSigInfo
)

Functions

func AddMultiSigInfo

func AddMultiSigInfo(multiSig MultiSigInfo)

AddMultiSigInfo 保存当前多签地址到快照列表

func AddNode

func AddNode(host string, nodeId int32, pubkey string, pubkeyHash string)

AddNode 增加节点到集群信息列表

func AddNodeInfo

func AddNodeInfo(nodeInfo NodeInfo)

AddNodeInfo 将node加入节点列表

func DelSnapShot

func DelSnapShot()

func DeleteNode

func DeleteNode(nodeId int32)

DeleteNode 把相应ID的节点的状态标记为删除

func GetInitNodeHeight

func GetInitNodeHeight() int64

func GetPubkeyList

func GetPubkeyList() []string

GetPubkeyList 获取所有正常状态节点的公钥

func Init

func Init()

Init 初始化集群信息

func InitWithNodeList

func InitWithNodeList(nodeList *pb.NodeList)

InitWithNodeList 根据参数而非配置文件来构建集群信息

func IsNodeExist

func IsNodeExist(nodeId int32) bool

IsNodeExist node 是否已经存在

func LeaderNodeOfTerm

func LeaderNodeOfTerm(term int64) int32

LeaderNodeOfTerm 根据指定的term计算leader的ID并返回

func RecoverNode

func RecoverNode(nodeId int32)

RecoverNode 恢复节点的状态为正常

func SetCurrMultiSig

func SetCurrMultiSig(multiSig MultiSigInfo)

SetCurrMultiSig 设置当前的多签信息

func SetInitNodeHeight

func SetInitNodeHeight(height int64)

func SetMultiSigSnapshot

func SetMultiSigSnapshot(snapshot []MultiSigInfo)

SetMultiSigSnapshot 设置快照

Types

type MultiSigInfo

type MultiSigInfo struct {
	BtcAddress      string `json:"btc_address"`
	BtcRedeemScript []byte `json:"btc_redeem_script"`
	BchAddress      string `json:"bch_address"`
	BchRedeemScript []byte `json:"bch_redeem_script"`
}

MultiSigInfo 多签信息

func (MultiSigInfo) Equal

func (ms MultiSigInfo) Equal(other MultiSigInfo) bool

Equal 比较两个MultiSigInfo是否相等

type MultiSigInfos

type MultiSigInfos struct {
	sync.Mutex
	SigInfos []MultiSigInfo
}

func (MultiSigInfos) GetLatestSigInfo

func (msi MultiSigInfos) GetLatestSigInfo() (MultiSigInfo, error)

func (MultiSigInfos) GetMultiSigInfos

func (msi MultiSigInfos) GetMultiSigInfos() []MultiSigInfo

type NodeInfo

type NodeInfo struct {
	Id        int32  `json:"id:`
	Name      string `json:"name"`
	Url       string `json:"url"`
	PublicKey []byte `json:"public_key"`
	IsNormal  bool   `json:"is_normal"`
}

NodeInfo 节点信息

func NewNodeInfo

func NewNodeInfo(host string, nodeId int32, pubkey string, pubkeyHash string) NodeInfo

NewNodeInfo 创建Node

type PeerManager

type PeerManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PeerManager 管理所有PeerNode的结构体, 负责广播消息

func NewPeerManager

func NewPeerManager(localNodeId int32, txConnPoolSize, blockCoonPoolSize int) *PeerManager

NewPeerManager 新建一个PeerManager对象并返回

func (*PeerManager) AddNode

func (pm *PeerManager) AddNode(nodeInfo NodeInfo)

AddNode 增加节点到manager

func (*PeerManager) Broadcast

func (pm *PeerManager) Broadcast(msg interface{}, excludeSelf bool, selectSome bool)

Broadcast 把msg广播给其他节点 excludeSelf 是否排除本节点,true不发给本节点,false也发给本节点 selectSome 是否仅发送部分节点

func (*PeerManager) DeleteNode

func (pm *PeerManager) DeleteNode(id int32)

DeleteNode del node

func (*PeerManager) GetCommitedCnt

func (pm *PeerManager) GetCommitedCnt(msg *crypto.Digest256) int

func (*PeerManager) GetNode

func (pm *PeerManager) GetNode(nodeId int32) *PeerNode

GetNode 根据指定的节点ID返回对应的PeerNode

func (*PeerManager) GetNodeRuntimeInfos

func (pm *PeerManager) GetNodeRuntimeInfos() map[int32]*pb.NodeRuntimeInfo

获取节点运行时的info,监听的区块的高度和成为leader的次数

func (*PeerManager) GetTxConnAvailableCnt

func (pm *PeerManager) GetTxConnAvailableCnt(nodes []NodeInfo) int

func (*PeerManager) LocalNodeId

func (pm *PeerManager) LocalNodeId() int32

LocalNodeId 返回本节点的节点ID

func (*PeerManager) NotifyCommitMsg

func (pm *PeerManager) NotifyCommitMsg(nodeId int32, msg *pb.CommitMsg) (*pb.Void, error)

NotifyCommitMsg 向nodeid节点发送CommitMsg消息

func (*PeerManager) NotifyHeatbeat

func (pm *PeerManager) NotifyHeatbeat(nodeId int32, msg *pb.HeatbeatMsg) (*pb.Void, error)

NotifyHeatbeat 向node节点发送心跳消息

func (*PeerManager) NotifyInitMsg

func (pm *PeerManager) NotifyInitMsg(nodeId int32, msg *pb.InitMsg) (*pb.Void, error)

NotifyInitMsg 向nodeid节点发送InitMsg消息

func (*PeerManager) NotifyLeave

func (pm *PeerManager) NotifyLeave(nodeId int32, msg *pb.LeaveRequest) (*pb.Void, error)

NotifyLeave 向nodeid节点发送LeaveRequest消息

func (*PeerManager) NotifyPrepareMsg

func (pm *PeerManager) NotifyPrepareMsg(nodeId int32, msg *pb.PrepareMsg) (*pb.Void, error)

NotifyPrepareMsg 向nodeid节点发送PrepareMsg消息

func (*PeerManager) NotifySignTx

func (pm *PeerManager) NotifySignTx(nodeId int32, msg *pb.SignTxRequest) (*pb.SignTxResponse, error)

NotifySignTx 向nodeid节点发送SignTxRequest消息

func (*PeerManager) NotifySignedResult

func (pm *PeerManager) NotifySignedResult(nodeId int32, msg *pb.SignedResult) (*pb.Void, error)

NotifySignedResult 向nodeid节点发送SignedResult消息

func (*PeerManager) NotifyStrongAccuse

func (pm *PeerManager) NotifyStrongAccuse(nodeId int32, msg *pb.StrongAccuse) (*pb.Void, error)

NotifyStrongAccuse 向nodeid节点发送StrongAccuse消息

func (*PeerManager) NotifyTxs

func (pm *PeerManager) NotifyTxs(nodeId int32, msg *pb.Transactions) (*pb.Void, error)

NotifyTxs 向nodeid节点发送Transaction, 已废弃

func (*PeerManager) NotifyVote

func (pm *PeerManager) NotifyVote(nodeId int32, msg *pb.Vote) (*pb.Void, error)

NotifyVote 向nodeid节点发送Vote消息

func (*PeerManager) NotifyWeakAccuse

func (pm *PeerManager) NotifyWeakAccuse(nodeId int32, msg *pb.WeakAccuse) (*pb.Void, error)

NotifyWeakAccuse 向nodeid节点发送WeakAccuse消息

func (*PeerManager) SyncUp

func (pm *PeerManager) SyncUp(nodeId int32, req *pb.SyncUpRequest) (*pb.SyncUpResponse, error)

SyncUp 向nodeId节点发送Syncup消息

func (*PeerManager) WatchSyncUp

func (pm *PeerManager) WatchSyncUp(nodeId int32, req *pb.SyncUpRequest) (*pb.SyncUpResponse, error)

type PeerNode

type PeerNode struct {
	NodeInfo
	// contains filtered or unexported fields
}

PeerNode 维持节点的链接

func NewPeerNode

func NewPeerNode(nodeInfo NodeInfo, txPoolSize, blockPoolSize int) *PeerNode

NewPeerNode 新建一个PeerNode对象并返回

type Snapshot

type Snapshot struct {
	NodeList       []NodeInfo `json:"node_list"`
	ClusterSize    int        `json:"cluster_size"`
	TotalNodeCount int        `json:"total_node_count"`
	QuorumN        int        `json:"quorum_n"`
	AccuseQuorumN  int        `json:"accuse_quorum_n"`
}

Snapshot 集群快照

func CreateSnapShot

func CreateSnapShot() *Snapshot

CreateSnapShot 创建快照保存到变量 ClusterSnapshot

func GetSnapshot

func GetSnapshot() Snapshot