backend

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusMsg         = 0x00
	CtxSignMsg        = 0x31
	GetCtxSyncMsg     = 0x32
	CtxSyncMsg        = 0x33
	GetPendingSyncMsg = 0x34
	PendingSyncMsg    = 0x35
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIDMismatch
	ErrGenesisMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrCrossMainChainMismatch
	ErrCrossSubChainMismatch
)

Variables

View Source
var (
	ErrClosed            = errors.New("peer set is closed")
	ErrAlreadyRegistered = errors.New("peer is already registered")
	ErrNotRegistered     = errors.New("peer is not registered")
)
View Source
var ErrInvalidChainStore = errors.New("invalid chain store, chainID can not be nil")

Functions

This section is empty.

Types

type CrossNodeInfo

type CrossNodeInfo struct {
	MainChain   uint64       `json:"mainChain"`
	MainGenesis common.Hash  `json:"mainGenesis"`
	SubChain    uint64       `json:"subChain"`
	SubGenesis  common.Hash  `json:"subGenesis"`
	Config      cross.Config `json:"config"`
}

type CrossPeerInfo

type CrossPeerInfo struct {
	Version    int      `json:"version"`
	MainHeight *big.Int `json:"mainHeight"`
	SubHeight  *big.Int `json:"subHeight"`
}

type CrossPool added in v1.0.5

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

CrossPool is used for collecting multisign signatures

func NewCrossPool added in v1.0.5

func NewCrossPool(chainID *big.Int, config *cross.Config, store store, txLog finishedLog,
	retriever trigger.ChainRetriever, signHash cc.SignHash) *CrossPool

func (*CrossPool) AddLocals added in v1.0.6

func (pool *CrossPool) AddLocals(txs ...*cc.CrossTransaction) (
	signed []*cc.CrossTransaction, commits []*cc.CrossTransactionWithSignatures, errs []error)

AddLocal CrossTransactions synced from blockchain subscriber @signed: ctx signed by local anchor @commits: ctx signed completely, commit to signedCtxCh @errs: errors

func (*CrossPool) AddRemote added in v1.0.5

func (pool *CrossPool) AddRemote(ctx *cc.CrossTransaction) (signer common.Address, err error)

AddRemote CrossTransactions received from peers

func (*CrossPool) AddRemotes added in v1.0.6

func (pool *CrossPool) AddRemotes(ctxList []*cc.CrossTransaction) ([]common.Address, []error)

func (*CrossPool) Commit added in v1.0.5

func (pool *CrossPool) Commit(txs []*cc.CrossTransactionWithSignatures)

Commit signed ctx with callback

func (*CrossPool) GetLocal added in v1.0.5

func (pool *CrossPool) GetLocal(ctxID common.Hash) *cc.CrossTransaction

GetLocal get local signed CrossTransaction from pool & store

func (*CrossPool) Pending added in v1.0.5

func (pool *CrossPool) Pending(startNumber uint64, limit int) (ids []common.Hash, pending []*cc.CrossTransactionWithSignatures)

Pending return pending ctx by height

func (*CrossPool) Rollback added in v1.0.6

func (pool *CrossPool) Rollback(cws *cc.CrossTransactionWithSignatures, invalidSigIndex []int)

Rollback ctx to pending and remove its invalid signatures

func (*CrossPool) Stats added in v1.0.5

func (pool *CrossPool) Stats() (int, int)

report pending and queue's length

func (*CrossPool) Stop added in v1.0.5

func (pool *CrossPool) Stop()

func (*CrossPool) Store added in v1.0.6

func (pool *CrossPool) Store(cwsList []*cc.CrossTransactionWithSignatures)

Store ctx into CrossStore

func (*CrossPool) SubscribeSignedCtxEvent added in v1.0.5

func (pool *CrossPool) SubscribeSignedCtxEvent(ch chan<- cc.SignedCtxEvent) event.Subscription

type CrossService

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

CrossService implements node.Service

func NewCrossService

func NewCrossService(ctx *node.ServiceContext, main, sub *cross.ServiceContext, config cross.Config) (srv *CrossService, err error)

func (*CrossService) APIs

func (srv *CrossService) APIs() []rpc.API

func (*CrossService) BroadcastCrossTx

func (srv *CrossService) BroadcastCrossTx(ctxs []*cc.CrossTransaction, local bool)

func (*CrossService) NodeInfo

func (srv *CrossService) NodeInfo() *CrossNodeInfo

func (*CrossService) Protocols

func (srv *CrossService) Protocols() []p2p.Protocol

func (*CrossService) Start

func (srv *CrossService) Start(server *p2p.Server) error

func (*CrossService) Stop

func (srv *CrossService) Stop() error

type CrossStore

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

CrossStore store cross transactions into CtxDBs

func NewCrossStore

func NewCrossStore(ctx cdb.ServiceContext, makerDb string) (*CrossStore, error)

func (*CrossStore) Add added in v1.0.6

func (*CrossStore) Adds added in v1.0.6

func (s *CrossStore) Adds(chainID *big.Int, ctxList []*cc.CrossTransactionWithSignatures, replaceable bool) error

func (*CrossStore) Close added in v1.0.5

func (s *CrossStore) Close()

func (*CrossStore) Get added in v1.0.6

func (s *CrossStore) Get(chainID *big.Int, ctxID common.Hash) *cc.CrossTransactionWithSignatures

func (*CrossStore) GetStore added in v1.0.6

func (s *CrossStore) GetStore(chainID *big.Int) (cdb.CtxDB, error)

func (*CrossStore) Height

func (s *CrossStore) Height(chainID *big.Int) uint64

func (*CrossStore) RegisterChain

func (s *CrossStore) RegisterChain(chainID *big.Int) cdb.CtxDB

func (*CrossStore) Stats

func (s *CrossStore) Stats() map[uint64]map[cc.CtxStatus]int

func (*CrossStore) Updates added in v1.0.6

func (s *CrossStore) Updates(chainID *big.Int, txmList []*cc.CrossTransactionModifier) error

Updates change tx status by block logs

type Handler

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

func NewCrossHandler

func NewCrossHandler(ctx *cross.ServiceContext, service *CrossService,
	crossMsgReader <-chan interface{}, crossMsgWriter chan<- interface{}) (h *Handler, err error)

func (*Handler) AddRemoteCtx

func (h *Handler) AddRemoteCtx(ctx *cc.CrossTransaction) error

往pool里添加从P2P网络接收的ctx与节点签名信息

func (*Handler) FindByTxHash added in v1.0.4

func (h *Handler) FindByTxHash(hash common.Hash) *cc.CrossTransactionWithSignatures

func (*Handler) GetByBlockNumber added in v1.0.6

func (h *Handler) GetByBlockNumber(begin, end uint64) []*cc.CrossTransactionWithSignatures

func (*Handler) GetByCtxID added in v1.0.6

func (*Handler) GetCrossTransactionByHeight added in v1.0.6

func (h *Handler) GetCrossTransactionByHeight(height uint64, limit int) []*cc.CrossTransactionWithSignatures

func (*Handler) GetPending added in v1.0.6

func (h *Handler) GetPending(ids []common.Hash) []*cc.CrossTransaction

通过id获取本地pool.pending或store中的交易,并添加自己的签名

func (*Handler) Height added in v1.0.4

func (h *Handler) Height() *big.Int

for cross store sync

func (*Handler) LocalID added in v1.0.5

func (h *Handler) LocalID() uint64

func (*Handler) Pending added in v1.0.4

func (h *Handler) Pending(start uint64, limit int) (ids []common.Hash)

获取未共识完成的跨链交易 @start 起始交易所在区块高度 @limit 限制一次性取的交易条数

func (*Handler) PoolStats added in v1.0.4

func (h *Handler) PoolStats() (int, int)

func (*Handler) QueryByPage added in v1.0.4

func (h *Handler) QueryByPage(localSize, localPage, remoteSize, remotePage int) (
	locals map[uint64][]*cc.CrossTransactionWithSignatures, remotes map[uint64][]*cc.CrossTransactionWithSignatures, lt int, rt int)

func (*Handler) QueryLocalBySenderAndPage added in v1.0.4

func (h *Handler) QueryLocalBySenderAndPage(from common.Address, pageSize, startPage int) (
	locals map[uint64][]*cc.OwnerCrossTransactionWithSignatures, total int)

func (*Handler) QueryLocalIllegalByPage added in v1.0.6

func (h *Handler) QueryLocalIllegalByPage(pageSize, startPage int) []*cc.CrossTransactionWithSignatures

func (*Handler) QueryRemoteByDestinationValueAndPage added in v1.0.4

func (h *Handler) QueryRemoteByDestinationValueAndPage(value *big.Int, pageSize,
	startPage int) (remoteID uint64, txs []*cc.CrossTransactionWithSignatures, total int)

func (*Handler) QueryRemoteByTakerAndPage added in v1.0.6

func (h *Handler) QueryRemoteByTakerAndPage(to common.Address, pageSize, startPage int) (
	remotes map[uint64][]*cc.OwnerCrossTransactionWithSignatures, total int)

func (*Handler) RegisterChain added in v1.0.6

func (h *Handler) RegisterChain(chainID *big.Int)

func (*Handler) RemoteID added in v1.0.5

func (h *Handler) RemoteID() uint64

func (*Handler) RemoveCrossTransactionBefore added in v1.0.6

func (h *Handler) RemoveCrossTransactionBefore(number uint64) int

在store删除number区块高度之前的finished状态的跨链交易,并持久化到txLog中

func (*Handler) SetStoreDelay added in v1.0.6

func (h *Handler) SetStoreDelay(number uint64)

设置store定期清除finished的交易 @number: 在number高度以下的交易会被定期清理

func (*Handler) Start

func (h *Handler) Start()

func (*Handler) Stop

func (h *Handler) Stop()

func (*Handler) StoreStats added in v1.0.4

func (h *Handler) StoreStats() map[uint64]map[cc.CtxStatus]int

type MonitorInfo added in v1.0.6

type MonitorInfo struct {
	Tally    map[common.Address]uint64 `json:"tally"`
	Recently map[common.Address]uint32 `json:"recently"`
}

type NodeInfo added in v1.0.6

type NodeInfo struct {
	MainChain    uint64
	MainContract common.Address
	SubChain     uint64
	SubContract  common.Address
}

type PrivateCrossAdminAPI added in v1.0.4

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

func NewPrivateCrossAdminAPI added in v1.0.4

func NewPrivateCrossAdminAPI(service *CrossService) *PrivateCrossAdminAPI

func (*PrivateCrossAdminAPI) Anchors added in v1.0.6

func (s *PrivateCrossAdminAPI) Anchors() map[uint64][]common.Address

func (*PrivateCrossAdminAPI) Height added in v1.0.4

func (s *PrivateCrossAdminAPI) Height() map[string]hexutil.Uint64

func (*PrivateCrossAdminAPI) ImportMainCtx added in v1.0.6

func (s *PrivateCrossAdminAPI) ImportMainCtx(ctxWithSignsSArgs hexutil.Bytes) error

func (*PrivateCrossAdminAPI) ImportSubCtx added in v1.0.6

func (s *PrivateCrossAdminAPI) ImportSubCtx(ctxWithSignsSArgs hexutil.Bytes) error

func (*PrivateCrossAdminAPI) Peers added in v1.0.4

func (s *PrivateCrossAdminAPI) Peers() (infos []*CrossPeerInfo, err error)

func (*PrivateCrossAdminAPI) Remove added in v1.0.6

func (s *PrivateCrossAdminAPI) Remove(chainID *hexutil.Big, number hexutil.Uint64) bool

func (*PrivateCrossAdminAPI) Repair added in v1.0.4

func (s *PrivateCrossAdminAPI) Repair() (bool, error)

func (*PrivateCrossAdminAPI) SetStoreDelay added in v1.0.6

func (s *PrivateCrossAdminAPI) SetStoreDelay(chainID *hexutil.Big, number hexutil.Uint64) bool

func (*PrivateCrossAdminAPI) Stats added in v1.0.6

func (s *PrivateCrossAdminAPI) Stats() map[uint64]map[cc.CtxStatus]int

func (*PrivateCrossAdminAPI) SyncPending added in v1.0.4

func (s *PrivateCrossAdminAPI) SyncPending() (bool, error)

func (*PrivateCrossAdminAPI) SyncStore added in v1.0.4

func (s *PrivateCrossAdminAPI) SyncStore() (bool, error)

type PublicCrossChainAPI

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

func NewPublicCrossChainAPI

func NewPublicCrossChainAPI(handler *Handler) *PublicCrossChainAPI

func (*PublicCrossChainAPI) CtxContentByPage added in v1.0.4

func (s *PublicCrossChainAPI) CtxContentByPage(localSize, localPage, remoteSize, remotePage int) map[string]RPCPageCrossTransactions

func (*PublicCrossChainAPI) CtxGet added in v1.0.6

func (*PublicCrossChainAPI) CtxGetByNumber added in v1.0.6

func (s *PublicCrossChainAPI) CtxGetByNumber(begin, end hexutil.Uint64) map[cc.CtxStatus][]common.Hash

func (*PublicCrossChainAPI) CtxIllegalByPage added in v1.0.6

func (s *PublicCrossChainAPI) CtxIllegalByPage(pageSize, startPage int) *RPCPageCrossTransactions

func (*PublicCrossChainAPI) CtxOwner

func (*PublicCrossChainAPI) CtxOwnerByPage added in v1.0.4

func (s *PublicCrossChainAPI) CtxOwnerByPage(from common.Address, pageSize, startPage int) RPCPageOwnerCrossTransactions

func (*PublicCrossChainAPI) CtxQuery

func (*PublicCrossChainAPI) CtxQueryDestValue added in v1.0.4

func (s *PublicCrossChainAPI) CtxQueryDestValue(value *hexutil.Big, pageSize, startPage int) *RPCPageCrossTransactions

func (*PublicCrossChainAPI) CtxTakerByPage added in v1.0.6

func (s *PublicCrossChainAPI) CtxTakerByPage(to common.Address, pageSize, startPage int) RPCPageOwnerCrossTransactions

func (*PublicCrossChainAPI) Monitor added in v1.0.6

func (s *PublicCrossChainAPI) Monitor() MonitorInfo

func (*PublicCrossChainAPI) PoolStats added in v1.0.4

func (s *PublicCrossChainAPI) PoolStats() map[string]int

type RPCCrossTransaction

type RPCCrossTransaction struct {
	Value            *hexutil.Big   `json:"value"`
	CTxId            common.Hash    `json:"ctxId"`
	Status           cc.CtxStatus   `json:"status"`
	TxHash           common.Hash    `json:"txHash"`
	From             common.Address `json:"from"`
	To               common.Address `json:"to"`
	BlockHash        common.Hash    `json:"blockHash"`
	BlockNumber      hexutil.Uint64 `json:"blockNumber"`
	DestinationId    *hexutil.Big   `json:"destinationId"`
	DestinationValue *hexutil.Big   `json:"destinationValue"`
	Input            hexutil.Bytes  `json:"input"`
	V                []*hexutil.Big `json:"v"`
	R                []*hexutil.Big `json:"r"`
	S                []*hexutil.Big `json:"s"`
}

type RPCOwnerCrossTransaction

type RPCOwnerCrossTransaction struct {
	Value            *hexutil.Big   `json:"value"`
	Status           cc.CtxStatus   `json:"status"`
	CTxId            common.Hash    `json:"ctxId"`
	TxHash           common.Hash    `json:"txHash"`
	From             common.Address `json:"from"`
	To               common.Address `json:"to"`
	BlockHash        common.Hash    `json:"blockHash"`
	BlockNumber      hexutil.Uint64 `json:"blockNumber"`
	DestinationId    *hexutil.Big   `json:"destinationId"`
	DestinationValue *hexutil.Big   `json:"destinationValue"`
	Input            hexutil.Bytes  `json:"input"`
	Time             hexutil.Uint64 `json:"time"`
	V                []*hexutil.Big `json:"v"`
	R                []*hexutil.Big `json:"r"`
	S                []*hexutil.Big `json:"s"`
}

type RPCPageCrossTransactions added in v1.0.4

type RPCPageCrossTransactions struct {
	Data map[uint64][]*RPCCrossTransaction `json:"data"`
}

type RPCPageOwnerCrossTransactions added in v1.0.4

type RPCPageOwnerCrossTransactions struct {
	Data map[uint64][]*RPCOwnerCrossTransaction `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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