primitives

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotExist = iota
	Valid
	Invalid
	CheckChain
)

Variables

View Source
var (
	// GenesisBlockPack 创世区块
	GenesisBlockPack *pb.BlockPack
)

Functions

func DeleteEthProposal

func DeleteEthProposal(db *dgwdb.LDBDatabase, proposal string)

DeleteEthProposal 删除指定的proposal。只在这笔交易确定失败了的时候才会删除

func DeleteJoinNodeInfo

func DeleteJoinNodeInfo(db *dgwdb.LDBDatabase)

DeleteJoinNodeInfo 删除JoinRequest信息

func DeleteLeaveNodeInfo

func DeleteLeaveNodeInfo(db *dgwdb.LDBDatabase)

DeleteLeaveNodeInfo 删除LeaveRequest信息

func DeleteSignMsg

func DeleteSignMsg(db *dgwdb.LDBDatabase, msgId string)

DeleteSignMsg 清理签名信息

func GetAccuseRecords

func GetAccuseRecords(db *dgwdb.LDBDatabase) iterator.Iterator

GetAccuseRecords 返回所有的accuse记录,返回的是一个iterator

func GetBlockByID

func GetBlockByID(db *dgwdb.LDBDatabase, id []byte) *pb.BlockPack

func GetClusterSnapshot

func GetClusterSnapshot(db *dgwdb.LDBDatabase, scriptAddress string) *cluster.Snapshot

GetClusterSnapshot 返回指定多签地址对应的集群快照

func GetClusterSnapshotIter

func GetClusterSnapshotIter(db *dgwdb.LDBDatabase) iterator.Iterator

GetClusterSnapshotIter 返回查询所有集群快照的迭代器

func GetCommitByHeight

func GetCommitByHeight(db *dgwdb.LDBDatabase, height int64) *pb.BlockPack

GetCommitByHeight 获取指定高度的区块

func GetCommitByID

func GetCommitByID(db *dgwdb.LDBDatabase, blockID *crypto.Digest256) *pb.BlockPack

func GetCommitHeight

func GetCommitHeight(db *dgwdb.LDBDatabase) int64

GetCommitHeight 获取当前区块高度

func GetCommitTop

func GetCommitTop(db *dgwdb.LDBDatabase) *pb.BlockPack

GetCommitTop 获取当前最新区块

func GetCommitsByHeightSec

func GetCommitsByHeightSec(db *dgwdb.LDBDatabase, start, end int64) []*pb.BlockPack

根据height 范围获取区块

func GetCurrentHeight

func GetCurrentHeight(db *dgwdb.LDBDatabase, chainType string) int64

GetCurrentHeight 获取上次某条公链监听到的高度

func GetETHBlockHeight

func GetETHBlockHeight(db *dgwdb.LDBDatabase) *big.Int

GetETHBlockHeight 获取上次ETH监听到的高度

func GetETHBlockTxIndex

func GetETHBlockTxIndex(db *dgwdb.LDBDatabase) int

GetETHBlockTxIndex 获取上次ETH监听到的区块里面的哪一笔交易

func GetETHTxHash

func GetETHTxHash(db *dgwdb.LDBDatabase, proposal string) string

GetETHTxHash 根据proposal获取对应的ETH交易hash

func GetFinalAmount

func GetFinalAmount(db *dgwdb.LDBDatabase, scTxID string) int64

GetFinalAmount 获取最终金额

func GetFresh

func GetFresh(db *dgwdb.LDBDatabase) *pb.BlockPack

GetFresh 获取当前共识中的block

func GetJoinNodeInfo

func GetJoinNodeInfo(db *dgwdb.LDBDatabase) *pb.JoinRequest

GetJoinNodeInfo 获取之前保存的JoinRequest信息

func GetLastTermAccuse

func GetLastTermAccuse(db *dgwdb.LDBDatabase) *pb.StrongAccuse

GetLastTermAccuse 获取最近一次的accuse信息

func GetLeaveNodeInfo

func GetLeaveNodeInfo(db *dgwdb.LDBDatabase) *pb.LeaveRequest

GetLeaveNodeInfo 获取之前保存的LeaveRequest信息

func GetMultiSigSnapshot

func GetMultiSigSnapshot(db *dgwdb.LDBDatabase) []cluster.MultiSigInfo

GetMultiSigSnapshot 返回多签地址的快照

func GetNodeTerm

func GetNodeTerm(db *dgwdb.LDBDatabase) (rst int64)

GetNodeTerm 获取节点的当前term

func GetSignMsg

func GetSignMsg(db *dgwdb.LDBDatabase, msgId string) *pb.SignTxRequest

GetSignMsg 获取签名时的上下文信息

func GetTxIdBySidechainTxId

func GetTxIdBySidechainTxId(db *dgwdb.LDBDatabase, scTxId string) *crypto.Digest256

GetTxIdBySidechainTxId 根据公链交易id获取网关交易的id

func GetTxLookupEntry

func GetTxLookupEntry(db *dgwdb.LDBDatabase, txId *crypto.Digest256) *pb.TxLookupEntry

GetTxLookupEntry 获取指定交易的索引信息

func GetVotie

func GetVotie(db *dgwdb.LDBDatabase) *pb.Votie

GetVotie 获取当前的投票信息

func GetWeakAccuses

func GetWeakAccuses(db *dgwdb.LDBDatabase) *pb.WeakAccuses

GetWeakAccuses 获取当前的weakaccuse

func HasFresh

func HasFresh(db *dgwdb.LDBDatabase) bool

HasFresh 判断当前有没有共识中的block

func InitDB

func InitDB(db *dgwdb.LDBDatabase, genesis *pb.BlockPack)

InitDB 初始化leveldb数据

func IsCommitted

func IsCommitted(db *dgwdb.LDBDatabase, blockId *crypto.Digest256) bool

IsCommitted check whether the blockId is already committed

func IsConnectingTop

func IsConnectingTop(db *dgwdb.LDBDatabase, blockPack *pb.BlockPack) bool

IsConnectingTop check whether the blockPack is right upon the top

func IsProposalExist

func IsProposalExist(db *dgwdb.LDBDatabase, proposal string) bool

IsProposalExist 检查指定的proposal是否存在

func IsSignFailed

func IsSignFailed(db *dgwdb.LDBDatabase, msgId string, term int64) bool

IsSignFailed 判断此term下的签名是否已经确认失败

func JustCommitIt

func JustCommitIt(db *dgwdb.LDBDatabase, blockPack *pb.BlockPack)

JustCommitIt 不做任何校验,直接保存区块

func MarkFailedSignRecord

func MarkFailedSignRecord(db *dgwdb.LDBDatabase, msgId string, term int64)

MarkFailedSignRecord 标记此term下的签名是否已经确认失败,需要重签

func SetAccuseRecord

func SetAccuseRecord(db *dgwdb.LDBDatabase, term int64, localNodeId int32, leaderNodeId int32,
	accuseType int32, reason string)

SetAccuseRecord 保存本节点发起的accuse记录

func SetClusterSnapshot

func SetClusterSnapshot(db *dgwdb.LDBDatabase, scriptAddress string, snapshot cluster.Snapshot)

SetClusterSnapshot 保存相应多签地址对应的节点信息

func SetCurrentHeight

func SetCurrentHeight(db *dgwdb.LDBDatabase, chainType string, height int64)

SetCurrentHeight 保存当前公链监听到的高度

func SetETHBlockHeight

func SetETHBlockHeight(db *dgwdb.LDBDatabase, height *big.Int)

SetETHBlockHeight 保存ETH当前监听到的高度

func SetETHBlockTxIndex

func SetETHBlockTxIndex(db *dgwdb.LDBDatabase, index int)

SetETHBlockTxIndex 保存当前ETH监听到的区块里面的哪一笔交易

func SetETHTxHash

func SetETHTxHash(db *dgwdb.LDBDatabase, proposal string, txHash string)

SetETHTxHash 保存proposal对应的ETH交易hash

func SetEthProposal

func SetEthProposal(db *dgwdb.LDBDatabase, proposal string)

SetEthProposal 保存ETH多签交易的唯一标识

func SetFinalAmount

func SetFinalAmount(db *dgwdb.LDBDatabase, amount int64, scTxID string)

SetFinalAmount 保存扣除手续费后的最终金额

func SetFresh

func SetFresh(db *dgwdb.LDBDatabase, fresh *pb.BlockPack)

SetFresh 保存当前共识中的block

func SetJoinNodeInfo

func SetJoinNodeInfo(db *dgwdb.LDBDatabase, msg *pb.JoinRequest)

SetJoinNodeInfo 保存JoinRequest信息

func SetLastTermAccuse

func SetLastTermAccuse(db *dgwdb.LDBDatabase, accuse *pb.StrongAccuse)

SetLastTermAccuse 设置最近一次StrongAccuse

func SetLeaveNodeInfo

func SetLeaveNodeInfo(db *dgwdb.LDBDatabase, msg *pb.LeaveRequest)

SetLeaveNodeInfo 保存LeaveRequest信息

func SetMultiSigSnapshot

func SetMultiSigSnapshot(db *dgwdb.LDBDatabase, snapshot []cluster.MultiSigInfo)

SetMultiSigSnapshot 保存多签地址的快照

func SetNodeTerm

func SetNodeTerm(db *dgwdb.LDBDatabase, term int64)

SetNodeTerm 设置节点的当前term

func SetSignMsg

func SetSignMsg(db *dgwdb.LDBDatabase, msg *pb.SignTxRequest, msgId string)

SetSignMsg 保存SignTxRequest,方便后面做校验比对

func SetTxIdMap

func SetTxIdMap(db *dgwdb.LDBDatabase, scTxId string, txId *crypto.Digest256)

SetTxIdMap 保存公链交易id和网关交易id的映射

func SetTxLookupEntry

func SetTxLookupEntry(db *dgwdb.LDBDatabase, txId *crypto.Digest256, entry *pb.TxLookupEntry)

SetTxLookupEntry 保存交易的索引信息

func SetVotie

func SetVotie(db *dgwdb.LDBDatabase, votie *pb.Votie)

SetVotie 保存当前的投票信息

func SetWeakAccuses

func SetWeakAccuses(db *dgwdb.LDBDatabase, weakAccuses *pb.WeakAccuses)

SetWeakAccuses 保存当前的weakaccuse

Types

type BlockStore

type BlockStore struct {
	NeedSyncUpEvent            *util.Event
	NewInitedEvent             *util.Event
	NewPreparedEvent           *util.Event
	NewCommittedEvent          *util.Event
	CommittedInLowerTermEvent  *util.Event
	NewTermEvent               *util.Event
	NewWeakAccuseEvent         *util.Event
	NewStrongAccuseEvent       *util.Event
	StrongAccuseProcessedEvent *util.Event
	SignedTxEvent              *util.Event
	SignHandledEvent           *util.Event
	OnJoinEvent                *util.Event
	JoinedEvent                *util.Event
	JoinCancelEvent            *util.Event
	OnLeaveEvent               *util.Event
	LeavedEvent                *util.Event
	LeaveCancelEvent           *util.Event
	ReconfigEvent              *util.Event
	// contains filtered or unexported fields
}

BlockStore 负责区块的处理,整个共识机制

func NewBlockStore

func NewBlockStore(db *dgwdb.LDBDatabase, ts *TxStore, btcWatcher *btcwatcher.MortgageWatcher, bchWatcher *btcwatcher.MortgageWatcher,
	ethWatcher *ew.Client, signer *crypto.SecureSigner, localNodeId int32) *BlockStore

NewBlockStore 生成一个BlockStore对象

func (*BlockStore) AddTransaction

func (bs *BlockStore) AddTransaction(tx *pb.Transaction)

AddTransaction 测试接口

func (*BlockStore) CommitBlockWithCheck

func (bs *BlockStore) CommitBlockWithCheck(blockPack *pb.BlockPack) error

CommitBlockWithCheck commit新区块

func (*BlockStore) CommitSyncBlock

func (bs *BlockStore) CommitSyncBlock(blockPack *pb.BlockPack) error

CommitSyncBlock 提交同步过来的区块

func (*BlockStore) DeleteJoinNodeInfo

func (bs *BlockStore) DeleteJoinNodeInfo()

DeleteJoinNodeInfo 删除缓存的JoinRequest

func (*BlockStore) DeleteLeaveNodeInfo

func (bs *BlockStore) DeleteLeaveNodeInfo()

DeleteLeaveNodeInfo 删除缓存的LeaveMessage

func (*BlockStore) DeleteSignReqMsg

func (bs *BlockStore) DeleteSignReqMsg(txId string)

DeleteSignReqMsg 删除缓存的签名请求

func (*BlockStore) GenSyncUpResponse

func (bs *BlockStore) GenSyncUpResponse(base int64, maxBlockN int64, needFresh bool) *pb.SyncUpResponse

GenSyncUpResponse 生成同步请求的返回

func (*BlockStore) GetBlockByHash

func (bs *BlockStore) GetBlockByHash(blockID *crypto.Digest256) *pb.BlockPack

GetBlockByHash 根据hash获取区块

func (*BlockStore) GetBlockByID

func (bs *BlockStore) GetBlockByID(id []byte) *pb.BlockPack

GetBlockByID 根据blockhash 获取区块

func (*BlockStore) GetClusterSnapshot

func (bs *BlockStore) GetClusterSnapshot(address string) *cluster.Snapshot

GetClusterSnapshot 根据多签地址获取对应的集群快照

func (*BlockStore) GetCommitByHeight

func (bs *BlockStore) GetCommitByHeight(height int64) *pb.BlockPack

GetCommitByHeight 获取指定高度的区块

func (*BlockStore) GetCommitHeight

func (bs *BlockStore) GetCommitHeight() int64

GetCommitHeight 获取当前区块高度

func (*BlockStore) GetCommitTop

func (bs *BlockStore) GetCommitTop() *pb.BlockPack

GetCommitTop 获取当前的最新区块

func (*BlockStore) GetCommitsByHeightSec

func (bs *BlockStore) GetCommitsByHeightSec(start, end int64) []*pb.BlockPack

GetCommitsByHeightSec 根据height 区间获取区块

func (*BlockStore) GetCurrentHeight

func (bs *BlockStore) GetCurrentHeight(chainType string) int64

GetCurrentHeight 获取当前监听到的指定公链的高度

func (*BlockStore) GetETHBlockHeight

func (bs *BlockStore) GetETHBlockHeight() *big.Int

GetETHBlockHeight 获取上次ETH监听到的高度

func (*BlockStore) GetETHBlockTxIndex

func (bs *BlockStore) GetETHBlockTxIndex() int

GetETHBlockTxIndex 获取上次ETH监听到的区块里面的哪一笔交易

func (*BlockStore) GetETHTxHash

func (bs *BlockStore) GetETHTxHash(proposal string) string

GetETHTxHash 根据proposal获取对应的ETH交易hash

func (*BlockStore) GetFinalAmount

func (bs *BlockStore) GetFinalAmount(scTxID string) int64

GetFinalAmount 获取最终金额

func (*BlockStore) GetFresh

func (bs *BlockStore) GetFresh() *pb.BlockPack

GetFresh 获取节点当前共识中的block

func (*BlockStore) GetMultiSigSnapshot

func (bs *BlockStore) GetMultiSigSnapshot() []cluster.MultiSigInfo

GetMultiSigSnapshot 获取全量的多签地址快照

func (*BlockStore) GetNodeTerm

func (bs *BlockStore) GetNodeTerm() int64

GetNodeTerm 获取节点的term

func (*BlockStore) GetSignReqMsg

func (bs *BlockStore) GetSignReqMsg(txId string) *pb.SignTxRequest

GetSignReqMsg 获取缓存的签名源请求

func (*BlockStore) GetVotie

func (bs *BlockStore) GetVotie() *pb.Votie

GetVotie 获取缓存的投票信息

func (*BlockStore) HandleCommitMsg

func (bs *BlockStore) HandleCommitMsg(msg *pb.CommitMsg)

HandleCommitMsg 处理CommitMsg

func (*BlockStore) HandleInitMsg

func (bs *BlockStore) HandleInitMsg(msg *pb.InitMsg)

HandleInitMsg 处理InitMsg

func (*BlockStore) HandleJoinCheckSyncedRequest

func (bs *BlockStore) HandleJoinCheckSyncedRequest(msg *pb.JoinRequest) error

func (*BlockStore) HandleJoinRequest

func (bs *BlockStore) HandleJoinRequest(msg *pb.JoinRequest)

func (*BlockStore) HandleLeaveRequest

func (bs *BlockStore) HandleLeaveRequest(msg *pb.LeaveRequest)

func (*BlockStore) HandlePrepareMsg

func (bs *BlockStore) HandlePrepareMsg(msg *pb.PrepareMsg)

HandlePrepareMsg 处理PrepareMsg

func (*BlockStore) HandleSignTx

func (bs *BlockStore) HandleSignTx(req *pb.SignTxRequest)

HandleSignTx 处理交易加签请求,需要对交易做合法性校验以及重复签名的校验

func (*BlockStore) HandleStrongAccuse

func (bs *BlockStore) HandleStrongAccuse(msg *pb.StrongAccuse)

HandleStrongAccuse 处理strong accuse, 提升term,重选leader

func (*BlockStore) HandleWeakAccuse

func (bs *BlockStore) HandleWeakAccuse(msg *pb.WeakAccuse)

HandleWeakAccuse 处理weak accuse,如果数量超过阈值,触发strong accuse

func (*BlockStore) IsCommitted

func (bs *BlockStore) IsCommitted(blockId *crypto.Digest256) bool

IsCommitted 判断指定区块是否已经commited

func (*BlockStore) IsSignFailed

func (bs *BlockStore) IsSignFailed(txId string, term int64) bool

IsSignFailed 判断此term下的签名是否已经确认失败

func (*BlockStore) JustCommitIt

func (bs *BlockStore) JustCommitIt(blockPack *pb.BlockPack)

JustCommitIt 不做校验,直接保存区块

func (*BlockStore) MarkFailedSignRecord

func (bs *BlockStore) MarkFailedSignRecord(txId string, term int64)

MarkFailedSignRecord 标记此term下的签名是否已经确认失败,需要重签

func (*BlockStore) SaveSnapshot

func (bs *BlockStore) SaveSnapshot(snapshot cluster.Snapshot)

SaveSnapshot 保存多签地址的快照和对应集群的快照

func (*BlockStore) SetCurrentHeight

func (bs *BlockStore) SetCurrentHeight(chainType string, height int64)

SetCurrentHeight 设置当前监听到的公链高度

func (*BlockStore) SetETHBlockHeight

func (bs *BlockStore) SetETHBlockHeight(height *big.Int)

SetETHBlockHeight 保存ETH当前监听到的高度

func (*BlockStore) SetETHBlockTxIndex

func (bs *BlockStore) SetETHBlockTxIndex(index int)

SetETHBlockTxIndex 保存当前ETH监听到的区块里面的哪一笔交易

func (*BlockStore) SetFeeRate

func (bs *BlockStore) SetFeeRate(mintFeeRate int64, burnFeeRate int64)

SetFeeRate 设置网关的交易手续费

func (*BlockStore) SetFinalAmount

func (bs *BlockStore) SetFinalAmount(amount int64, scTxID string)

SetFinalAmount 保存最终金额

func (*BlockStore) SetNodeTerm

func (bs *BlockStore) SetNodeTerm(term int64)

SetNodeTerm 保存节点的term

type TxQueryResult

type TxQueryResult struct {
	Tx      *pb.Transaction
	Height  int64
	BlockID *crypto.Digest256
}

TxQueryResult 保存搜索结果

type TxStore

type TxStore struct {
	TxOverdueEvent *util.Event

	sync.RWMutex
	// contains filtered or unexported fields
}

TxStore 公链监听到的交易以及网关本身交易的内存池

func NewTxStore

func NewTxStore(db *dgwdb.LDBDatabase) *TxStore

NewTxStore 新建一个TxStore对象并返回

func (*TxStore) AddFreshWatchedTx

func (ts *TxStore) AddFreshWatchedTx(tx *pb.WatchedTxInfo)

AddFreshWatchedTx 增加新监听到的交易到待处理列表

func (*TxStore) AddWatchedTx

func (ts *TxStore) AddWatchedTx(tx *pb.WatchedTxInfo)

AddWatchedTx 添加监听到的公链交易到内存池

func (*TxStore) CreateInnerTx

func (ts *TxStore) CreateInnerTx(newlyTxId string, signMsgId string, amount int64)

CreateInnerTx 创建一笔网关本身的交易

func (*TxStore) DeleteFresh

func (ts *TxStore) DeleteFresh(txId string)

DeleteFresh 把交易从待处理的列表中删除

func (*TxStore) DeleteWatchedTx

func (ts *TxStore) DeleteWatchedTx(txId string)

DeleteWatchedTx 把交易从内存池中删除, 只会发生在多签地址的迁移交易里面

func (*TxStore) FetchTxsChan

func (ts *TxStore) FetchTxsChan() <-chan []*pb.Transaction

func (*TxStore) GetFreshWatchedTxs

func (ts *TxStore) GetFreshWatchedTxs() []*WatchedTxInfo

GetFreshWatchedTxs 获取尚未被处理的公链交易

func (*TxStore) GetMemTxs

func (ts *TxStore) GetMemTxs() []*pb.Transaction

GetMemTxs 获取内存池的网关交易

func (*TxStore) GetTx

func (ts *TxStore) GetTx(txid string) *TxQueryResult

func (*TxStore) HasFreshWatchedTx

func (ts *TxStore) HasFreshWatchedTx() bool

HasFreshWatchedTx 是否还有未处理的公链交易

func (*TxStore) HasTxInDB

func (ts *TxStore) HasTxInDB(scTxId string) bool

func (*TxStore) HasTxInMemPool

func (ts *TxStore) HasTxInMemPool(scTxId string) bool

func (*TxStore) HasWatchedTx

func (ts *TxStore) HasWatchedTx(tx *pb.WatchedTxInfo) bool

HasWatchedTx 是否已经接收过tx了,是返回true,否返回false

func (*TxStore) OnNewBlockCommitted

func (ts *TxStore) OnNewBlockCommitted(newBlock *pb.BlockPack)

OnNewBlockCommitted 新区块共识后的回调处理,需要清理内存池

func (*TxStore) OnTermChanged

func (ts *TxStore) OnTermChanged(term int64)

OnTermChanged term更新时的处理

func (*TxStore) QueryTxInfoBySidechainId

func (ts *TxStore) QueryTxInfoBySidechainId(scId string) *TxQueryResult

QueryTxInfoBySidechainId 根据公链的交易id查询对应到的网关交易信息

func (*TxStore) Run

func (ts *TxStore) Run(ctx context.Context)

Run TxStore的循环处理函数

func (*TxStore) TestAddTxs

func (ts *TxStore) TestAddTxs(txs []*pb.Transaction) []int

TestAddTxs just fot test api

func (*TxStore) ValidateTx

func (ts *TxStore) ValidateTx(tx *pb.Transaction) int

ValidateTx 验证交易的合法性

func (*TxStore) ValidateWatchedTx

func (ts *TxStore) ValidateWatchedTx(tx *pb.WatchedTxInfo) int

ValidateWatchedTx 验证leader传过来的公链交易是否和本节点一致

type WatchedTxInfo

type WatchedTxInfo struct {
	Tx *pb.WatchedTxInfo
	// contains filtered or unexported fields
}

WatchedTxInfo watcher监听到的交易信息

Jump to

Keyboard shortcuts

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