node

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BtcConfirms      int //check 交易确认数
	BchConfirms      int
	EthConfirms      int
	ConfirmTolerance time.Duration
	// CheckOnChainCur 链上验证并发数
	CheckOnChainCur int
	// CheckOnChainInterval 探测时间间隔
	CheckOnChainInterval time.Duration
)

Functions

func GetStartMode

func GetStartMode() int

GetStartMode 返回startMode

func InitObserver added in v1.1.0

func InitObserver() error

InitObserver 观察节点初始化

Types

type BlockView

type BlockView struct {
	Height      int64     `json:"height"`
	ID          string    `json:"id"`
	PreID       string    `json:"pre_id"`
	TxCnt       int       `json:"tx_cnt"`
	Txs         []*TxView `json:"txs"`
	Time        int64     `json:"time"`         //unix 时间戳
	Size        int       `json:"size"`         //块大小
	CreatedUsed int64     `json:"created_used"` //块被创建花费的时间
	Miner       string    `json:"miner"`        //产生块的服务器
}

blcokView for api

type BraftNode

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

BraftNode node主结构, 也是程序启动的入口

func NewBraftNode

func NewBraftNode(localNodeInfo cluster.NodeInfo) *BraftNode

NewBraftNode 生成&启动一个node对象并返回

func RunNew

func RunNew(nodeInfo cluster.NodeInfo, multiSigInfos []cluster.MultiSigInfo) (*grpc.Server, *BraftNode)

RunNew 启动server

func (*BraftNode) AddProposal added in v1.1.0

func (node *BraftNode) AddProposal(p *distribution.Proposal) bool

AddProposal 新增一个分配提案

func (*BraftNode) AddSideTx added in v1.0.4

func (node *BraftNode) AddSideTx(txID string, chain string) error

AddSideTx 添加侧链tx

func (*BraftNode) AddWatchedTx

func (node *BraftNode) AddWatchedTx(tx *pb.WatchedTxInfo) error

AddWatchedTx 手动添加交易

func (*BraftNode) ChainRegister

func (node *BraftNode) ChainRegister(regInfo *ChainRegInfo)

ChainRegister 新链注册

func (*BraftNode) DeleteProposal added in v1.1.0

func (node *BraftNode) DeleteProposal(proposalID string) bool

DeleteProposal 删除指定的提案,注意只有处于new或者执行失败的情况下,提案才会被删除

func (*BraftNode) Echo

func (bn *BraftNode) Echo(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error)

Echo just for test echo

func (*BraftNode) ExecuteProposal added in v1.1.0

func (node *BraftNode) ExecuteProposal(proposalID string)

ExecuteProposal 执行指定的提案

func (*BraftNode) FakeCommitBlock

func (node *BraftNode) FakeCommitBlock(blockPack *pb.BlockPack)

FakeCommitBlock 人工写区块,仅做测试用

func (*BraftNode) GetAllProposal added in v1.1.0

func (node *BraftNode) GetAllProposal() []*distribution.DistributionInfo

GetAllProposal 获取所有的提案

func (*BraftNode) GetBlockByID

func (node *BraftNode) GetBlockByID(id string) (*BlockView, error)

func (*BraftNode) GetBlockBytHeight

func (node *BraftNode) GetBlockBytHeight(height int64) *BlockView

根据高度获取block

func (*BraftNode) GetBlockCurrent

func (node *BraftNode) GetBlockCurrent() *BlockView

获取最新区块

func (*BraftNode) GetBlockHeight

func (node *BraftNode) GetBlockHeight() int64

func (*BraftNode) GetBlockInfo

func (node *BraftNode) GetBlockInfo(height int64) *pb.BlockInfo

func (*BraftNode) GetBlocks

func (node *BraftNode) GetBlocks(start, end int64) []*BlockView

获取区块 start 开始高度 end结束高度[start,end)

func (*BraftNode) GetBurnFeeRate

func (node *BraftNode) GetBurnFeeRate() int64

GetBurnFeeRate 返回熔币的手续费

func (*BraftNode) GetChainRegisterID

func (node *BraftNode) GetChainRegisterID(newChain string, targetChain string) *ChainRegID

GetChainRegisterID 查询链注册结果,如果成功,返回chainID,否则返回0

func (*BraftNode) GetClusterNodes

func (bn *BraftNode) GetClusterNodes(ctx context.Context, msg *pb.Void) (*pb.NodeList, error)

GetClusterNodes 处理获取集群节点列表的请求

func (*BraftNode) GetMinBCHMintAmount

func (node *BraftNode) GetMinBCHMintAmount() int64

GetMinBCHMintAmount 返回BCH链铸币的最小金额

func (*BraftNode) GetMinBTCMintAmount

func (node *BraftNode) GetMinBTCMintAmount() int64

GetMinBTCMintAmount 返回BCH链铸币的最小金额

func (*BraftNode) GetMinBurnAmount

func (node *BraftNode) GetMinBurnAmount() int64

GetMinBurnAmount 返回熔币的最小金额

func (*BraftNode) GetMintFeeRate

func (node *BraftNode) GetMintFeeRate() int64

GetMintFeeRate 返回铸币的手续费

func (*BraftNode) GetNodeRuntimeInfo

func (bn *BraftNode) GetNodeRuntimeInfo(ctx context.Context, msg *pb.Void) (*pb.NodeRuntimeInfo, error)

func (*BraftNode) GetNodeTerm

func (node *BraftNode) GetNodeTerm() int64

func (*BraftNode) GetNodes

func (node *BraftNode) GetNodes() []NodeView

func (*BraftNode) GetProposal added in v1.1.0

func (node *BraftNode) GetProposal(proposalID string) *distribution.DistributionInfo

GetProposal 获取指定的提案

func (*BraftNode) GetTokenRegisterID

func (node *BraftNode) GetTokenRegisterID(chain string, contractAddr string) *TokenRegID

GetTokenRegisterID 查询token注册结果,如果成功,则返回tokenID, 否则返回0

func (*BraftNode) GetTransacitonByTxID

func (node *BraftNode) GetTransacitonByTxID(txID string) *TxView

根据tx_id查询 transaction 不同链的tx_id用相同的pre存储

func (*BraftNode) GetTxBySidechainTxId

func (node *BraftNode) GetTxBySidechainTxId(scTxId string) *primitives.TxQueryResult

func (*BraftNode) IsCommited

func (bn *BraftNode) IsCommited(ctx context.Context, msg *crypto.Digest256) (*pb.IsCommitedResponse, error)

func (*BraftNode) LeaveCluster

func (bn *BraftNode) LeaveCluster()

LeaveCluster 先广播LeaveRequest,然后再停止运行

func (*BraftNode) ManualMint

func (node *BraftNode) ManualMint(mintInfo *ManualMintRequest)

ManualMint 手工铸币

func (*BraftNode) NotifyCommitMsg

func (bn *BraftNode) NotifyCommitMsg(ctx context.Context, msg *pb.CommitMsg) (*pb.Void, error)

NotifyCommitMsg 处理收到的commitmsg请求,新区快达成共识

func (*BraftNode) NotifyHeatbeat added in v1.1.1

func (bn *BraftNode) NotifyHeatbeat(ct context.Context, msg *pb.HeatbeatMsg) (*pb.Void, error)

NotifyHeatbeat 处理心跳消息

func (*BraftNode) NotifyInitMsg

func (bn *BraftNode) NotifyInitMsg(ctx context.Context, msg *pb.InitMsg) (*pb.Void, error)

NotifyInitMsg 处理收到的initmsg请求, 新区块开始共识

func (*BraftNode) NotifyJoin

func (bn *BraftNode) NotifyJoin(ctx context.Context, msg *pb.JoinRequest) (*pb.Void, error)

NotifyJoin 处理新节点加入的请求

func (*BraftNode) NotifyJoinCheckSynced

func (bn *BraftNode) NotifyJoinCheckSynced(ctx context.Context, msg *pb.JoinRequest) (*pb.JoinResponse, error)

join check是否同步完成

func (*BraftNode) NotifyLeave

func (bn *BraftNode) NotifyLeave(ctx context.Context, msg *pb.LeaveRequest) (*pb.Void, error)

NotifyLeave 处理节点的退出请求

func (*BraftNode) NotifyPrepareMsg

func (bn *BraftNode) NotifyPrepareMsg(ctx context.Context, msg *pb.PrepareMsg) (*pb.Void, error)

NotifyPrepareMsg 处理收到的preparemsg请求,新区块准备好了共识

func (*BraftNode) NotifySignTx

func (bn *BraftNode) NotifySignTx(ctx context.Context, msg *pb.SignTxRequest) (*pb.Void, error)

NotifySignTx 处理收到的加签请求

func (*BraftNode) NotifySignedResult

func (bn *BraftNode) NotifySignedResult(ctx context.Context, msg *pb.SignedResult) (*pb.Void, error)

func (*BraftNode) NotifyStrongAccuse

func (bn *BraftNode) NotifyStrongAccuse(ctx context.Context, msg *pb.StrongAccuse) (*pb.Void, error)

NotifyStrongAccuse 处理收到的strongaccuse请求,更新term,重新选举leader

func (*BraftNode) NotifyTxs

func (bn *BraftNode) NotifyTxs(ctx context.Context, msg *pb.Transactions) (*pb.Void, error)

NotifyTxs 暂时未使用

func (*BraftNode) NotifyVote

func (bn *BraftNode) NotifyVote(ctx context.Context, msg *pb.Vote) (*pb.Void, error)

NotifyVote 处理收到的投票请求,如果收到的票数超过阈值,自己会成为leader

func (*BraftNode) NotifyWeakAccuse

func (bn *BraftNode) NotifyWeakAccuse(ctx context.Context, msg *pb.WeakAccuse) (*pb.Void, error)

NotifyWeakAccuse 处理收到的weakaccuse请求,记录accuse个数,超过阈值则发起strong accuse

func (*BraftNode) Run

func (bn *BraftNode) Run()

func (*BraftNode) SaveSignedResult

func (node *BraftNode) SaveSignedResult(msg *pb.SignedResult)

func (*BraftNode) Stop

func (bn *BraftNode) Stop()

Stop 节点停止运行

func (*BraftNode) SyncUp

func (bn *BraftNode) SyncUp(ctx context.Context, msg *pb.SyncUpRequest) (*pb.SyncUpResponse, error)

SyncUp 处理收到的同步请求

func (*BraftNode) TokenRegister

func (node *BraftNode) TokenRegister(regInfo *TokenRegInfo)

TokenRegister 新token合约注册

func (*BraftNode) WatchSyncUp

func (bn *BraftNode) WatchSyncUp(ctx context.Context, msg *pb.SyncUpRequest) (*pb.SyncUpResponse, error)

type ChainRegID

type ChainRegID struct {
	ChainID uint32 `json:"chain_id"`
}

type ChainRegInfo

type ChainRegInfo struct {
	NewChain    string `json:"new_chain"`
	TargetChain string `json:"target_chain"`
}

type CheckMode

type CheckMode int
const (
	CheckFull CheckMode = iota
	CheckLite
)

type JoinMsg

type JoinMsg struct {
	LocalID       int32
	MultiSigInfos []cluster.MultiSigInfo
}

func InitJoin

func InitJoin(startMode int32) *JoinMsg

InitJoin 根据引导节点做集群配置信息的初始化

type Leader

type Leader struct {
	BecomeLeaderEvent *util.Event

	NewInitEvent *util.Event
	RetireEvent  *util.Event

	sync.Mutex
	// contains filtered or unexported fields
}

Leader leader节点描述

func NewLeader

func NewLeader(nodeInfo cluster.NodeInfo, bs *primitives.BlockStore, ts *primitives.TxStore,
	signer *crypto.SecureSigner, btcWatcher *btcwatcher.MortgageWatcher, bchWatcher *btcwatcher.MortgageWatcher,
	ethWatcher *ew.Client, xinWatcher *eoswatcher.EOSWatcher, eosWatcher *eoswatcher.EOSWatcherMain, tool *price.PriceTool, pm *cluster.PeerManager) *Leader

NewLeader 新生成一个leader对象,并启动后台任务,循环检查选举相关任务(创建块,投票等)

func (*Leader) AddVote

func (ld *Leader) AddVote(vote *pb.Vote)

AddVote 处理收到的投票

func (*Leader) OnJoinCancel

func (ld *Leader) OnJoinCancel()

func (*Leader) OnNewNodeJoin

func (ld *Leader) OnNewNodeJoin(host string)

func (*Leader) OnNodeJoinedDone

func (ld *Leader) OnNodeJoinedDone(vote *pb.Vote)

func (*Leader) OnNodeLeave

func (ld *Leader) OnNodeLeave(nodeId int32)

func (*Leader) OnNodeLeaveDone

func (ld *Leader) OnNodeLeaveDone()

func (*Leader) Run

func (ld *Leader) Run(ctx context.Context)

func (*Leader) SetFeeRate

func (ld *Leader) SetFeeRate(mintFeeRate int64, burnFeeRate int64)

SetFeeRate 设置网关的交易手续费

type ManualMintRequest

type ManualMintRequest struct {
	Amount   int64  `json:"amount"`
	Address  string `json:"address"`
	Proposal string `json:"proposal"`
	Chain    uint32 `json:"chain"`
	Token    uint32 `json:"token"`
}

ManualMintRequest 手工铸币结构

type NodeView

type NodeView struct {
	IP        string `json:"ip"`
	HostName  string `json:"host_name"`
	IsLeader  bool   `json:"is_leader"`
	IsOnline  bool   `json:"is_online"`
	FiredCnt  int32  `json:"fired_cnt"` //被替换掉leader的次数
	EthHeight int64  `json:"eth_height"`
	BchHeight int64  `json:"bch_height"`
	BtcHeight int64  `json:"btc_height"`
	// contains filtered or unexported fields
}

节点数据

type SignedResultCache

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

统计sign suc的节点数

type SyncDaemon

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

SyncDaemon 后台向其他节点同步的对象,单独goroutine运行

func NewSyncDaemon

func NewSyncDaemon(db *dgwdb.LDBDatabase, bs *primitives.BlockStore, pm *cluster.PeerManager) *SyncDaemon

NewSyncDaemon 新建一个SyncDaemon对象并返回

func (*SyncDaemon) Run

func (sd *SyncDaemon) Run(ctx context.Context)

Run 循环处理事件的入口函数

func (*SyncDaemon) SignalSyncUp

func (sd *SyncDaemon) SignalSyncUp(nodeId int32)

SignalSyncUp 通知syncdaemon发起同步请求

type TokenRegID

type TokenRegID struct {
	TokenID uint32 `json:"token_id"`
}

type TokenRegInfo

type TokenRegInfo struct {
	ContractAddr string `json:"contract_addr"`
	Chain        string `json:"chain"`
	ReceptChain  uint32 `json:"recept_chain"`
	ReceptToken  uint32 `json:"recept_token"`
}

type TxView

type TxView struct {
	FromTxHash  string   `json:"from_tx_hash"` //转出txhash
	ToTxHash    string   `json:"to_tx_hash"`   //转入txhash
	DGWTxHash   string   `json:"dgw_hash"`     //dgwtxhash
	From        string   `json:"from"`         //转出链
	To          string   `json:"to"`           //转入链
	Time        int64    `json:"time"`
	Block       string   `json:"block"`        //所在区块blockID
	BlockHeight int64    `json:"block_height"` //所在区块高度
	Amount      int64    `json:"amount"`
	ToAddrs     []string `json:"to_addrs"`
	FromFee     int64    `json:"from_fee"`
	DGWFee      int64    `json:"dgw_fee"`
	ToFee       int64    `json:"to_fee"`
	TokenCode   uint32   `json:"token_code"`
	AppCode     uint32   `json:"app_code"`
	FinalAmount int64    `json:"final_amount"` //扣除手续费后的金额
}

Jump to

Keyboard shortcuts

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