sc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenEventChanSize = 10000
	BridgeAddrJournal  = "bridge_addrs.rlp"
)
View Source
const (
	KLAY uint8 = iota
	TOKEN
	NFT
)
View Source
const (
	// Protocol messages belonging to servicechain/1
	StatusMsg = 0x00

	ServiceChainTxsMsg                     = 0x01
	ServiceChainReceiptResponseMsg         = 0x02
	ServiceChainReceiptRequestMsg          = 0x03
	ServiceChainParentChainInfoResponseMsg = 0x04
	ServiceChainParentChainInfoRequestMsg  = 0x05
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrNoStatusMsg
	ErrUnexpectedTxType
)
View Source
const (
	GasLimit = 5000000
)
View Source
const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
View Source
const (
	SyncRequestInterval = 10
)

Variables

View Source
var (
	ErrKnownTx           = errors.New("Known Transaction")
	ErrUnknownTx         = errors.New("Unknown Transaction")
	ErrDuplicatedNonceTx = errors.New("Duplicated Nonce Transaction")
)
View Source
var (
	SCProtocolName    = "servicechain"
	SCProtocolVersion = []uint{1}
	SCProtocolLength  = []uint64{6}
)
View Source
var (
	ErrVtrDisabled       = errors.New("VTR is disabled")
	ErrVtrAlreadyStarted = errors.New("VTR is already started")
)
View Source
var (
	ConnectionFailErr = errors.New("fail to connect remote chain")
)
View Source
var DefaultBridgeTxPoolConfig = BridgeTxPoolConfig{
	ParentChainID: big.NewInt(2018),
	Journal:       "bridge_transactions.rlp",
	Rejournal:     10 * time.Minute,
	GlobalQueue:   8192,
}

DefaultBridgeTxPoolConfig contains the default configurations for the transaction pool.

View Source
var DefaultConfig = SCConfig{
	NetworkId: 1,
	MaxPeer:   50,
}

DefaultConfig contains default settings for use on the Klaytn main net.

View Source
var (
	ErrAlreadyExistentBridgePair = errors.New("bridge already exists")
)
View Source
var (
	ErrGetServiceChainPHInCCEH = errors.New("ServiceChainPH isn't set in ChildChainEventHandler")
)
View Source
var (
	ErrGetServiceChainPHInMCEH = errors.New("ServiceChainPH isn't set in MainChainEventHandler")
)
View Source
var (
	ErrInvalidBridgePair = errors.New("invalid bridge pair")
)
View Source
var (
	ErrNoChildChainID = errors.New("There is no childChainID")
)

Functions

func CreateDB

func CreateDB(ctx *node.ServiceContext, config *SCConfig, name string) database.DBManager

CreateDB creates the chain database.

func MakeTransactOpts

func MakeTransactOpts(accountKey *ecdsa.PrivateKey, nonce *big.Int, chainID *big.Int, gasPrice *big.Int) *bind.TransactOpts

TODO-Klaytn need to refactor for chainID / gasPrice

func NewValueTransferRecovery

func NewValueTransferRecovery(config *SCConfig, scBridgeInfo, mcBridgeInfo *BridgeInfo) *valueTransferRecovery

NewValueTransferRecovery creates a new value transfer recovery structure.

Types

type AddressManager

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

AddressManager manages mapping addresses for bridge,contract,user to exchange value between parent and child chain

func NewAddressManager

func NewAddressManager() (*AddressManager, error)

func (*AddressManager) AddBridge

func (am *AddressManager) AddBridge(bridge1 common.Address, bridge2 common.Address) error

func (*AddressManager) AddToken

func (am *AddressManager) AddToken(token1 common.Address, token2 common.Address) error

func (*AddressManager) DeleteBridge

func (am *AddressManager) DeleteBridge(bridge1 common.Address) (common.Address, common.Address, error)

func (*AddressManager) DeleteToken

func (am *AddressManager) DeleteToken(token1 common.Address) (common.Address, common.Address, error)

func (*AddressManager) GetCounterPartBridge

func (am *AddressManager) GetCounterPartBridge(addr common.Address) common.Address

func (*AddressManager) GetCounterPartToken

func (am *AddressManager) GetCounterPartToken(addr common.Address) common.Address

type Backend

type Backend interface {
	bind.ContractBackend
}

Backend wraps all methods for local and remote backend

type BridgeAccountManager

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

BridgeAccountManager manages bridge account for main/service chain.

func NewBridgeAccountManager

func NewBridgeAccountManager(mcKey, scKey *ecdsa.PrivateKey) (*BridgeAccountManager, error)

NewBridgeAccountManager returns bridgeAccountManager created by main/service bridge account keys.

type BridgeInfo

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

func NewBridgeInfo

func NewBridgeInfo(subBridge *SubBridge, addr common.Address, bridge *bridgecontract.Bridge, cpAddr common.Address, cpBridge *bridgecontract.Bridge, account *accountInfo, local, subscribed bool) *BridgeInfo

func (*BridgeInfo) AddRequestValueTransferEvents

func (bi *BridgeInfo) AddRequestValueTransferEvents(evs []*RequestValueTransferEvent)

AddRequestValueTransferEvents adds events into the pendingRequestEvent.

func (*BridgeInfo) GetReadyRequestValueTransferEvents

func (bi *BridgeInfo) GetReadyRequestValueTransferEvents() []*RequestValueTransferEvent

GetReadyRequestValueTransferEvents returns the processable events with the increasing nonce.

func (*BridgeInfo) UpdateHandledNonce

func (bi *BridgeInfo) UpdateHandledNonce(nonce uint64)

UpdateHandledNonce updates the handled nonce with new nonce.

func (*BridgeInfo) UpdateInfo

func (bi *BridgeInfo) UpdateInfo() error

func (*BridgeInfo) UpdateRequestNonce

func (bi *BridgeInfo) UpdateRequestNonce(nonce uint64)

UpdateRequestNonce updates the request nonce of the bridge.

func (*BridgeInfo) UpdateRequestNonceFromCounterpart

func (bi *BridgeInfo) UpdateRequestNonceFromCounterpart(nonce uint64)

UpdateRequestNonceFromCounterpart updates the request nonce from counterpart bridge.

type BridgeJournal

type BridgeJournal struct {
	LocalAddress  common.Address `json:"localAddress"`
	RemoteAddress common.Address `json:"remoteAddress"`
	Subscribed    bool           `json:"subscribed"`
}

func (*BridgeJournal) DecodeRLP

func (b *BridgeJournal) DecodeRLP(s *rlp.Stream) error

DecodeRLP decodes the Klaytn

func (*BridgeJournal) EncodeRLP

func (b *BridgeJournal) EncodeRLP(w io.Writer) error

EncodeRLP serializes a BridgeJournal into the Klaytn RLP BridgeJournal format.

type BridgeManager

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

BridgeManager manages Bridge SmartContracts for value transfer between service chain and parent chain

func NewBridgeManager

func NewBridgeManager(main *SubBridge) (*BridgeManager, error)

func (*BridgeManager) AddRecovery

func (bm *BridgeManager) AddRecovery(localAddress, remoteAddress common.Address) error

AddRecovery starts value transfer recovery for a given addresses pair.

func (*BridgeManager) DeleteBridgeInfo

func (bm *BridgeManager) DeleteBridgeInfo(addr common.Address) error

DeleteBridgeInfo deletes the bridge info of the specified address.

func (*BridgeManager) DeleteRecovery

func (bm *BridgeManager) DeleteRecovery(localAddress, remoteAddress common.Address) error

DeleteRecovery deletes the journal and stop the value transfer recovery for a given address pair.

func (*BridgeManager) DeployBridge

func (bm *BridgeManager) DeployBridge(backend bind.ContractBackend, local bool) (*bridgecontract.Bridge, common.Address, error)

Deploy Bridge SmartContract on same node or remote node

func (*BridgeManager) GetAllBridge

func (bm *BridgeManager) GetAllBridge() []*BridgeJournal

GetAllBridge returns a slice of journal cache.

func (*BridgeManager) GetBridgeInfo

func (bm *BridgeManager) GetBridgeInfo(addr common.Address) (*BridgeInfo, bool)

GetBridge returns bridge contract of the specified address.

func (*BridgeManager) LogBridgeStatus

func (bm *BridgeManager) LogBridgeStatus()

LogBridgeStatus logs the bridge contract requested/handled nonce status as an information.

func (*BridgeManager) ResetAllSubscribedEvents

func (bm *BridgeManager) ResetAllSubscribedEvents() error

resetAllSubscribedEvents resets watch logs and recreates a goroutine loop to handle event messages.

func (*BridgeManager) RestoreBridges

func (bm *BridgeManager) RestoreBridges() error

RestoreBridges setups bridge subscription by using the journal cache.

func (*BridgeManager) SetBridgeInfo

func (bm *BridgeManager) SetBridgeInfo(addr common.Address, bridge *bridgecontract.Bridge, cpAddr common.Address, cpBridge *bridgecontract.Bridge, account *accountInfo, local bool, subscribed bool) error

SetBridgeInfo stores the address and bridge pair with local/remote and subscription status.

func (*BridgeManager) SetJournal

func (bm *BridgeManager) SetJournal(localAddress, remoteAddress common.Address) error

SetJournal inserts or updates journal for a given addresses pair.

func (*BridgeManager) Stop

func (bm *BridgeManager) Stop()

Stop closes a subscribed event scope of the bridge manager.

func (*BridgeManager) SubscribeEvent

func (bm *BridgeManager) SubscribeEvent(addr common.Address) error

SubscribeEvent registers a subscription of BridgeERC20Received and BridgeTokenWithdrawn

func (*BridgeManager) SubscribeTokenReceived

func (bm *BridgeManager) SubscribeTokenReceived(ch chan<- RequestValueTransferEvent) event.Subscription

SubscribeTokenReceived registers a subscription of TokenReceivedEvent.

func (*BridgeManager) SubscribeTokenWithDraw

func (bm *BridgeManager) SubscribeTokenWithDraw(ch chan<- HandleValueTransferEvent) event.Subscription

SubscribeTokenWithDraw registers a subscription of TokenTransferEvent.

func (*BridgeManager) UnsubscribeEvent

func (bm *BridgeManager) UnsubscribeEvent(addr common.Address)

UnsubscribeEvent cancels the contract's watch logs and initializes the status.

type BridgePeer

type BridgePeer interface {
	// Close signals the broadcast goroutine to terminate.
	Close()

	// Info gathers and returns a collection of metadata known about a peer.
	Info() *BridgePeerInfo

	Head() (hash common.Hash, td *big.Int)

	// AddToKnownTxs adds a transaction hash to knownTxsCache for the peer, ensuring that it
	// will never be propagated to this particular peer.
	AddToKnownTxs(hash common.Hash)

	// Send writes an RLP-encoded message with the given code.
	// data should have been encoded as an RLP list.
	Send(msgcode uint64, data interface{}) error

	// Handshake executes the Klaytn protocol handshake, negotiating version number,
	// network IDs, difficulties, head, genesis blocks, and onChildChain(if the node is on child chain for the peer)
	// and returning if the peer on the same chain or not and error.
	Handshake(network uint64, chainID, td *big.Int, head common.Hash) error

	// ConnType returns the conntype of the peer.
	ConnType() p2p.ConnType

	// GetID returns the id of the peer.
	GetID() string

	// GetP2PPeerID returns the id of the p2p.Peer.
	GetP2PPeerID() discover.NodeID

	// GetChainID returns the chain id of the peer.
	GetChainID() *big.Int

	// GetAddr returns the address of the peer.
	GetAddr() common.Address

	// SetAddr sets the address of the peer.
	SetAddr(addr common.Address)

	// GetVersion returns the version of the peer.
	GetVersion() int

	// KnowsTx returns if the peer is known to have the transaction, based on knownTxsCache.
	KnowsTx(hash common.Hash) bool

	// GetP2PPeer returns the p2p.
	GetP2PPeer() *p2p.Peer

	// GetRW returns the MsgReadWriter of the peer.
	GetRW() p2p.MsgReadWriter

	// Handle is the callback invoked to manage the life cycle of a Klaytn Peer. When
	// this function terminates, the Peer is disconnected.
	Handle(bn *MainBridge) error

	// SendServiceChainTxs sends child chain tx data to from child chain to parent chain.
	SendServiceChainTxs(txs types.Transactions) error

	// SendServiceChainInfoRequest sends a parentChainInfo request from child chain to parent chain.
	SendServiceChainInfoRequest(addr *common.Address) error

	// SendServiceChainInfoResponse sends a parentChainInfo from parent chain to child chain.
	// parentChainInfo includes nonce of an account and gasPrice in the parent chain.
	SendServiceChainInfoResponse(pcInfo *parentChainInfo) error

	// SendServiceChainReceiptRequest sends a receipt request from child chain to parent chain.
	SendServiceChainReceiptRequest(txHashes []common.Hash) error

	// SendServiceChainReceiptResponse sends a receipt as a response to request from child chain.
	SendServiceChainReceiptResponse(receipts []*types.ReceiptForStorage) error
}

type BridgePeerInfo

type BridgePeerInfo struct {
	Version int    `json:"version"` // Klaytn Bridge protocol version negotiated
	Head    string `json:"head"`    // SHA3 hash of the peer's best owned block
}

BridgePeerInfo represents a short summary of the Klaytn Bridge sub-protocol metadata known about a connected peer.

type BridgeTxPool

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

BridgeTxPool contains all currently known chain transactions.

func NewBridgeTxPool

func NewBridgeTxPool(config BridgeTxPoolConfig) *BridgeTxPool

NewBridgeTxPool creates a new transaction pool to gather, sort and filter inbound transactions from the network.

func (*BridgeTxPool) AddLocal

func (pool *BridgeTxPool) AddLocal(tx *types.Transaction) error

AddLocal enqueues a single transaction into the pool if it is valid, marking the sender as a local one.

func (*BridgeTxPool) AddLocals

func (pool *BridgeTxPool) AddLocals(txs []*types.Transaction) []error

AddLocals enqueues a batch of transactions into the pool if they are valid, marking the senders as a local ones.

func (*BridgeTxPool) Content

func (pool *BridgeTxPool) Content() map[common.Address]types.Transactions

Content retrieves the data content of the transaction pool, returning all the queued transactions, grouped by account and sorted by nonce.

func (*BridgeTxPool) Get

func (pool *BridgeTxPool) Get(hash common.Hash) *types.Transaction

Get returns a transaction if it is contained in the pool and nil otherwise.

func (*BridgeTxPool) GetMaxTxNonce

func (pool *BridgeTxPool) GetMaxTxNonce(from *common.Address) uint64

GetMaxTxNonce finds max nonce of the address.

func (*BridgeTxPool) GetTx

func (pool *BridgeTxPool) GetTx(txHash common.Hash) (*types.Transaction, error)

GetTx get the tx by tx hash.

func (*BridgeTxPool) Pending

func (pool *BridgeTxPool) Pending() map[common.Address]types.Transactions

Pending returns all pending transactions by calling internal pending method.

func (*BridgeTxPool) PendingTxHashesByAddress

func (pool *BridgeTxPool) PendingTxHashesByAddress(from *common.Address, limit int) []common.Hash

PendingTxHashesByAddress retrieves pending transaction hashes of from. They are sorted by nonce.

func (*BridgeTxPool) PendingTxsByAddress

func (pool *BridgeTxPool) PendingTxsByAddress(from *common.Address, limit int) types.Transactions

PendingTxsByAddress retrieves pending transactions of from. They are sorted by nonce.

func (*BridgeTxPool) Remove

func (pool *BridgeTxPool) Remove(txs types.Transactions) []error

Remove removes transactions from the queue.

func (*BridgeTxPool) RemoveTx

func (pool *BridgeTxPool) RemoveTx(tx *types.Transaction) error

RemoveTx removes a single transaction from the queue.

func (*BridgeTxPool) SetEIP155Signer

func (pool *BridgeTxPool) SetEIP155Signer(chainID *big.Int)

SetEIP155Signer set signer of txpool.

func (*BridgeTxPool) Stats

func (pool *BridgeTxPool) Stats() int

Stats retrieves the current pool stats, namely the number of pending transactions.

func (*BridgeTxPool) Stop

func (pool *BridgeTxPool) Stop()

Stop terminates the transaction pool.

type BridgeTxPoolConfig

type BridgeTxPoolConfig struct {
	ParentChainID *big.Int
	Journal       string        // Journal of local transactions to survive node restarts
	Rejournal     time.Duration // Time interval to regenerate the local transaction journal

	GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts
}

BridgeTxPoolConfig are the configuration parameters of the transaction pool.

type ChildChainEventHandler

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

func NewChildChainEventHandler

func NewChildChainEventHandler(bridge *SubBridge, handler *SubBridgeHandler) (*ChildChainEventHandler, error)

func (*ChildChainEventHandler) ConvertServiceChainBlockHashToMainChainTxHash

func (cce *ChildChainEventHandler) ConvertServiceChainBlockHashToMainChainTxHash(scBlockHash common.Hash) common.Hash

ConvertServiceChainBlockHashToMainChainTxHash returns a transaction hash of a transaction which contains ChainHashes, with the key made with given service chain block hash. Index is built when service chain indexing is enabled.

func (*ChildChainEventHandler) HandleChainHeadEvent

func (cce *ChildChainEventHandler) HandleChainHeadEvent(block *types.Block) error

func (*ChildChainEventHandler) HandleLogsEvent

func (cce *ChildChainEventHandler) HandleLogsEvent(logs []*types.Log) error

func (*ChildChainEventHandler) HandleTxEvent

func (cce *ChildChainEventHandler) HandleTxEvent(tx *types.Transaction) error

func (*ChildChainEventHandler) HandleTxsEvent

func (cce *ChildChainEventHandler) HandleTxsEvent(txs []*types.Transaction) error

func (*ChildChainEventHandler) ProcessHandleEvent

func (cce *ChildChainEventHandler) ProcessHandleEvent(ev HandleValueTransferEvent) error

func (*ChildChainEventHandler) ProcessRequestEvent

func (cce *ChildChainEventHandler) ProcessRequestEvent(ev RequestValueTransferEvent) error

type HandleValueTransferEvent

type HandleValueTransferEvent struct {
	TokenType    uint8
	ContractAddr common.Address
	TokenAddr    common.Address
	Owner        common.Address
	Amount       *big.Int // Amount is UID in NFT
	HandleNonce  uint64
}

HandleValueTransferEvent from Bridge contract

type LocalBackend

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

TODO-Klaytn currently LocalBackend is only for ServiceChain, especially Bridge SmartContract

func NewLocalBackend

func NewLocalBackend(main *SubBridge) (*LocalBackend, error)

func (*LocalBackend) CallContract

func (lb *LocalBackend) CallContract(ctx context.Context, call klaytn.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*LocalBackend) ChainID

func (lb *LocalBackend) ChainID(ctx context.Context) (*big.Int, error)

ChainID can return the chain ID of the chain.

func (*LocalBackend) CodeAt

func (lb *LocalBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

func (*LocalBackend) EstimateGas

func (lb *LocalBackend) EstimateGas(ctx context.Context, call klaytn.CallMsg) (gas uint64, err error)

func (*LocalBackend) FilterLogs

func (lb *LocalBackend) FilterLogs(ctx context.Context, query klaytn.FilterQuery) ([]types.Log, error)

func (*LocalBackend) PendingCodeAt

func (lb *LocalBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)

func (*LocalBackend) PendingNonceAt

func (lb *LocalBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*LocalBackend) SendTransaction

func (lb *LocalBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*LocalBackend) SubscribeFilterLogs

func (lb *LocalBackend) SubscribeFilterLogs(ctx context.Context, query klaytn.FilterQuery, ch chan<- types.Log) (klaytn.Subscription, error)

func (*LocalBackend) SuggestGasPrice

func (lb *LocalBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*LocalBackend) TransactionReceipt

func (lb *LocalBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

type MainBridge

type MainBridge struct {
	APIBackend *MainBridgeAPI
	// contains filtered or unexported fields
}

CN implements the Klaytn consensus node service.

func NewMainBridge

func NewMainBridge(ctx *node.ServiceContext, config *SCConfig) (*MainBridge, error)

New creates a new CN object (including the initialisation of the common CN object)

func (*MainBridge) APIs

func (s *MainBridge) APIs() []rpc.API

APIs returns the collection of RPC services the ethereum package offers. NOTE, some of these services probably need to be moved to somewhere else.

func (*MainBridge) AccountManager

func (s *MainBridge) AccountManager() *accounts.Manager

func (*MainBridge) BridgePeerSet

func (mb *MainBridge) BridgePeerSet() *bridgePeerSet

implement PeerSetManager

func (*MainBridge) ChainDB

func (s *MainBridge) ChainDB() database.DBManager

func (*MainBridge) Components

func (s *MainBridge) Components() []interface{}

func (*MainBridge) EventMux

func (s *MainBridge) EventMux() *event.TypeMux

func (*MainBridge) IsListening

func (s *MainBridge) IsListening() bool

func (*MainBridge) NetVersion

func (s *MainBridge) NetVersion() uint64

func (*MainBridge) NodeInfo

func (pm *MainBridge) NodeInfo() *MainBridgeInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*MainBridge) ProtocolVersion

func (s *MainBridge) ProtocolVersion() int

func (*MainBridge) Protocols

func (s *MainBridge) Protocols() []p2p.Protocol

Protocols implements node.Service, returning all the currently configured network protocols to start.

func (*MainBridge) SCProtocol

func (s *MainBridge) SCProtocol() SCProtocol

func (*MainBridge) SetComponents

func (sc *MainBridge) SetComponents(components []interface{})

func (*MainBridge) Start

func (s *MainBridge) Start(srvr p2p.Server) error

Start implements node.Service, starting all internal goroutines needed by the Klaytn protocol implementation.

func (*MainBridge) Stop

func (s *MainBridge) Stop() error

Stop implements node.Service, terminating all internal goroutines used by the Klaytn protocol.

type MainBridgeAPI

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

MainBridgeAPI Implementation for main-bridge node

func (*MainBridgeAPI) ConvertServiceChainBlockHashToMainChainTxHash

func (mbapi *MainBridgeAPI) ConvertServiceChainBlockHashToMainChainTxHash(scBlockHash common.Hash) common.Hash

func (*MainBridgeAPI) GetChildChainIndexingEnabled

func (mbapi *MainBridgeAPI) GetChildChainIndexingEnabled() bool

func (*MainBridgeAPI) NodeInfo

func (mbapi *MainBridgeAPI) NodeInfo() (*p2p.NodeInfo, error)

NodeInfo retrieves all the information we know about the host node at the protocol granularity.

func (*MainBridgeAPI) Peers

func (mbapi *MainBridgeAPI) Peers() ([]*p2p.PeerInfo, error)

Peers retrieves all the information we know about each individual peer at the protocol granularity.

type MainBridgeHandler

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

func NewMainBridgeHandler

func NewMainBridgeHandler(scc *SCConfig, main *MainBridge) (*MainBridgeHandler, error)

func (*MainBridgeHandler) HandleSubMsg

func (mbh *MainBridgeHandler) HandleSubMsg(p BridgePeer, msg p2p.Msg) error

type MainBridgeInfo

type MainBridgeInfo struct {
	Network    uint64              `json:"network"`    // Klaytn network ID
	BlockScore *big.Int            `json:"blockscore"` // Total blockscore of the host's blockchain
	Genesis    common.Hash         `json:"genesis"`    // SHA3 hash of the host's genesis block
	Config     *params.ChainConfig `json:"config"`     // Chain configuration for the fork rules
	Head       common.Hash         `json:"head"`       // SHA3 hash of the host's best owned block
}

NodeInfo represents a short summary of the Klaytn sub-protocol metadata known about the host peer.

type MainChainEventHandler

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

func NewMainChainEventHandler

func NewMainChainEventHandler(bridge *MainBridge, handler *MainBridgeHandler) (*MainChainEventHandler, error)

func (*MainChainEventHandler) ConvertServiceChainBlockHashToMainChainTxHash

func (mce *MainChainEventHandler) ConvertServiceChainBlockHashToMainChainTxHash(scBlockHash common.Hash) common.Hash

ConvertServiceChainBlockHashToMainChainTxHash returns a transaction hash of a transaction which contains ChainHashes, with the key made with given service chain block hash. Index is built when service chain indexing is enabled.

func (*MainChainEventHandler) GetChildChainIndexingEnabled

func (mce *MainChainEventHandler) GetChildChainIndexingEnabled() bool

GetChildChainIndexingEnabled returns the current child chain indexing configuration.

func (*MainChainEventHandler) GetLastIndexedBlockNumber

func (mce *MainChainEventHandler) GetLastIndexedBlockNumber() uint64

GetLastIndexedBlockNumber returns the last child block number indexed to chain DB.

func (*MainChainEventHandler) HandleChainHeadEvent

func (mce *MainChainEventHandler) HandleChainHeadEvent(block *types.Block) error

func (*MainChainEventHandler) HandleLogsEvent

func (mce *MainChainEventHandler) HandleLogsEvent(logs []*types.Log) error

func (*MainChainEventHandler) HandleTxEvent

func (mce *MainChainEventHandler) HandleTxEvent(tx *types.Transaction) error

func (*MainChainEventHandler) HandleTxsEvent

func (mce *MainChainEventHandler) HandleTxsEvent(txs []*types.Transaction) error

func (*MainChainEventHandler) WriteChildChainTxHash

func (mce *MainChainEventHandler) WriteChildChainTxHash(ccBlockHash common.Hash, ccTxHash common.Hash)

WriteChildChainTxHash stores a transaction hash of a transaction which contains ChainHashes, with the key made with given child chain block hash. Index is built when child chain indexing is enabled.

func (*MainChainEventHandler) WriteLastIndexedBlockNumber

func (mce *MainChainEventHandler) WriteLastIndexedBlockNumber(blockNum uint64)

WriteLastIndexedBlockNumber writes the last child block number indexed to chain DB.

type PeerSetManager

type PeerSetManager interface {
	BridgePeerSet() *bridgePeerSet
}

type RemoteBackend

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

TODO-Klaytn currently RemoteBackend is only for ServiceChain, especially Bridge SmartContract

func NewRemoteBackend

func NewRemoteBackend(main *SubBridge, rawUrl string) (*RemoteBackend, error)

func (*RemoteBackend) CallContract

func (rb *RemoteBackend) CallContract(ctx context.Context, call klaytn.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*RemoteBackend) ChainID

func (rb *RemoteBackend) ChainID(ctx context.Context) (*big.Int, error)

ChainID can return the chain ID of the chain.

func (*RemoteBackend) CodeAt

func (rb *RemoteBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

func (*RemoteBackend) EstimateGas

func (rb *RemoteBackend) EstimateGas(ctx context.Context, call klaytn.CallMsg) (gas uint64, err error)

func (*RemoteBackend) FilterLogs

func (rb *RemoteBackend) FilterLogs(ctx context.Context, query klaytn.FilterQuery) ([]types.Log, error)

func (*RemoteBackend) PendingCodeAt

func (rb *RemoteBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)

func (*RemoteBackend) PendingNonceAt

func (rb *RemoteBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*RemoteBackend) SendTransaction

func (rb *RemoteBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*RemoteBackend) SubscribeFilterLogs

func (rb *RemoteBackend) SubscribeFilterLogs(ctx context.Context, query klaytn.FilterQuery, ch chan<- types.Log) (klaytn.Subscription, error)

func (*RemoteBackend) SuggestGasPrice

func (rb *RemoteBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*RemoteBackend) TransactionReceipt

func (rb *RemoteBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

type RequestValueTransferEvent

type RequestValueTransferEvent struct {
	TokenType    uint8
	ContractAddr common.Address
	TokenAddr    common.Address
	From         common.Address
	To           common.Address
	Amount       *big.Int // Amount is UID in NFT
	RequestNonce uint64
	BlockNumber  uint64
	// contains filtered or unexported fields
}

RequestValueTransferEvent from Bridge contract

type SCConfig

type SCConfig struct {
	// Name sets the instance name of the node. It must not contain the / character and is
	// used in the devp2p node identifier. The instance name is "kscn". If no
	// value is specified, the basename of the current executable is used.
	Name string `toml:"-"`

	// BridgeService
	EnabledMainBridge bool
	EnabledSubBridge  bool
	DataDir           string

	// Protocol options
	NetworkId uint64 // Network ID to use for selecting peers to connect to

	// Database options
	SkipBcVersionCheck bool `toml:"-"`
	DatabaseHandles    int  `toml:"-"`
	LevelDBCacheSize   int
	TrieCacheSize      int
	TrieTimeout        time.Duration
	TrieBlockInterval  uint
	ChildChainIndexing bool

	// Network
	MainBridgePort string
	SubBridgePort  string
	MaxPeer        int

	// ServiceChain
	MainChainAccountAddr    *common.Address `toml:",omitempty"`
	ServiceChainAccountAddr *common.Address `toml:",omitempty"`
	ServiceChainConsensus   string

	AnchoringPeriod   uint64
	SentChainTxsLimit uint64

	ParentChainID      uint64
	MainChainURL       string
	VTRecovery         bool
	VTRecoveryInterval uint64
	// contains filtered or unexported fields
}

func (*SCConfig) ChainKey

func (c *SCConfig) ChainKey() *ecdsa.PrivateKey

ChainKey retrieves the currently configured private key for parent chain, checking first any manually set key, falling back to the one found in the configured data folder. If no key can be found, a new one is generated.

func (*SCConfig) MainBridges

func (c *SCConfig) MainBridges() []*discover.Node

StaticNodes returns a list of node enode URLs configured as static nodes.

func (SCConfig) MarshalTOML

func (s SCConfig) MarshalTOML() (interface{}, error)

MarshalTOML marshals as TOML.

func (*SCConfig) NodeKey

func (c *SCConfig) NodeKey() *ecdsa.PrivateKey

NodeKey retrieves the currently configured private key for service chain, checking first any manually set key, falling back to the one found in the configured data folder. If no key can be found, a new one is generated.

func (*SCConfig) NodeName

func (c *SCConfig) NodeName() string

NodeName returns the devp2p node identifier.

func (*SCConfig) ResolvePath

func (c *SCConfig) ResolvePath(path string) string

ResolvePath resolves path in the instance directory.

func (*SCConfig) UnmarshalTOML

func (s *SCConfig) UnmarshalTOML(unmarshal func(interface{}) error) error

UnmarshalTOML unmarshals from TOML.

type SCProtocol

type SCProtocol struct {
	// Official short name of the protocol used during capability negotiation.
	Name string
	// Supported versions of the Klaytn protocol (first is primary).
	Versions []uint
	// Number of implemented message corresponding to different protocol versions.
	Lengths []uint64
}

Protocol defines the protocol of the consensus

type SubBridge

type SubBridge struct {
	APIBackend *SubBridgeAPI
	// contains filtered or unexported fields
}

SubBridge implements the Klaytn consensus node service.

func NewSubBridge

func NewSubBridge(ctx *node.ServiceContext, config *SCConfig) (*SubBridge, error)

New creates a new CN object (including the initialisation of the common CN object)

func (*SubBridge) APIs

func (s *SubBridge) APIs() []rpc.API

APIs returns the collection of RPC services the ethereum package offers. NOTE, some of these services probably need to be moved to somewhere else.

func (*SubBridge) AccountManager

func (s *SubBridge) AccountManager() *accounts.Manager

func (*SubBridge) AddressManager

func (s *SubBridge) AddressManager() *AddressManager

func (*SubBridge) BridgePeerSet

func (sb *SubBridge) BridgePeerSet() *bridgePeerSet

implement PeerSetManager

func (*SubBridge) ChainDB

func (s *SubBridge) ChainDB() database.DBManager

func (*SubBridge) Components

func (s *SubBridge) Components() []interface{}

func (*SubBridge) EventMux

func (s *SubBridge) EventMux() *event.TypeMux

func (*SubBridge) GetAnchoringTx

func (sb *SubBridge) GetAnchoringTx() bool

func (*SubBridge) GetBridgeTxPool

func (sb *SubBridge) GetBridgeTxPool() *BridgeTxPool

func (*SubBridge) IsListening

func (s *SubBridge) IsListening() bool

func (*SubBridge) NetVersion

func (s *SubBridge) NetVersion() uint64

func (*SubBridge) NodeInfo

func (pm *SubBridge) NodeInfo() *SubBridgeInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*SubBridge) ProtocolVersion

func (s *SubBridge) ProtocolVersion() int

func (*SubBridge) Protocols

func (s *SubBridge) Protocols() []p2p.Protocol

Protocols implements node.Service, returning all the currently configured network protocols to start.

func (*SubBridge) SCProtocol

func (s *SubBridge) SCProtocol() SCProtocol

func (*SubBridge) SetAnchoringTx

func (sb *SubBridge) SetAnchoringTx(flag bool) bool

func (*SubBridge) SetComponents

func (sc *SubBridge) SetComponents(components []interface{})

func (*SubBridge) Start

func (s *SubBridge) Start(srvr p2p.Server) error

Start implements node.Service, starting all internal goroutines needed by the Klaytn protocol implementation.

func (*SubBridge) Stop

func (s *SubBridge) Stop() error

Stop implements node.Service, terminating all internal goroutines used by the Klaytn protocol.

type SubBridgeAPI

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

SubBridgeAPI Implementation for sub-bridge node

func (*SubBridgeAPI) AddPeer

func (sbapi *SubBridgeAPI) AddPeer(url string) (bool, error)

AddPeer requests connecting to a remote node, and also maintaining the new connection at all times, even reconnecting if it is lost.

func (*SubBridgeAPI) Anchoring

func (sbapi *SubBridgeAPI) Anchoring(flag bool) bool

func (*SubBridgeAPI) ConvertRequestTxHashToHandleTxHash

func (sbapi *SubBridgeAPI) ConvertRequestTxHashToHandleTxHash(hash common.Hash) common.Hash

func (*SubBridgeAPI) ConvertServiceChainBlockHashToMainChainTxHash

func (sbapi *SubBridgeAPI) ConvertServiceChainBlockHashToMainChainTxHash(scBlockHash common.Hash) common.Hash

func (*SubBridgeAPI) DeployBridge

func (sbapi *SubBridgeAPI) DeployBridge() ([]common.Address, error)

func (*SubBridgeAPI) DeregisterBridge

func (sbapi *SubBridgeAPI) DeregisterBridge(cBridgeAddr common.Address, pBridgeAddr common.Address) error

func (*SubBridgeAPI) DeregisterToken

func (sbapi *SubBridgeAPI) DeregisterToken(cBridgeAddr, pBridgeAddr, cTokenAddr, pTokenAddr common.Address) error

func (*SubBridgeAPI) GetAnchoring

func (sbapi *SubBridgeAPI) GetAnchoring() bool

func (*SubBridgeAPI) GetAnchoringPeriod

func (sbapi *SubBridgeAPI) GetAnchoringPeriod() uint64

func (*SubBridgeAPI) GetBridgeInformation

func (sbapi *SubBridgeAPI) GetBridgeInformation(bridgeAddr common.Address) (map[string]interface{}, error)

func (*SubBridgeAPI) GetLatestAnchoredBlockNumber

func (sbapi *SubBridgeAPI) GetLatestAnchoredBlockNumber() uint64

func (*SubBridgeAPI) GetMainChainAccountAddr

func (sbapi *SubBridgeAPI) GetMainChainAccountAddr() string

func (*SubBridgeAPI) GetMainChainAccountNonce

func (sbapi *SubBridgeAPI) GetMainChainAccountNonce() uint64

func (*SubBridgeAPI) GetReceiptFromParentChain

func (sbapi *SubBridgeAPI) GetReceiptFromParentChain(blockHash common.Hash) *types.Receipt

func (*SubBridgeAPI) GetSentChainTxsLimit

func (sbapi *SubBridgeAPI) GetSentChainTxsLimit() uint64

func (*SubBridgeAPI) GetServiceChainAccountAddr

func (sbapi *SubBridgeAPI) GetServiceChainAccountAddr() string

func (*SubBridgeAPI) GetServiceChainAccountNonce

func (sbapi *SubBridgeAPI) GetServiceChainAccountNonce() uint64

func (*SubBridgeAPI) ListBridge

func (sbapi *SubBridgeAPI) ListBridge() []*BridgeJournal

func (*SubBridgeAPI) NodeInfo

func (sbapi *SubBridgeAPI) NodeInfo() (*p2p.NodeInfo, error)

NodeInfo retrieves all the information we know about the host node at the protocol granularity.

func (*SubBridgeAPI) Peers

func (sbapi *SubBridgeAPI) Peers() ([]*p2p.PeerInfo, error)

Peers retrieves all the information we know about each individual peer at the protocol granularity.

func (*SubBridgeAPI) RegisterBridge

func (sbapi *SubBridgeAPI) RegisterBridge(cBridgeAddr common.Address, pBridgeAddr common.Address) error

func (*SubBridgeAPI) RegisterToken

func (sbapi *SubBridgeAPI) RegisterToken(cBridgeAddr, pBridgeAddr, cTokenAddr, pTokenAddr common.Address) error

func (*SubBridgeAPI) RemovePeer

func (sbapi *SubBridgeAPI) RemovePeer(url string) (bool, error)

RemovePeer disconnects from a a remote node if the connection exists

func (*SubBridgeAPI) SubscribeBridge

func (sbapi *SubBridgeAPI) SubscribeBridge(cBridgeAddr, pBridgeAddr common.Address) error

SubscribeBridge enables the given service/main chain bridges to subscribe the events.

func (*SubBridgeAPI) TxPending

func (sbapi *SubBridgeAPI) TxPending() map[common.Address]types.Transactions

func (*SubBridgeAPI) TxPendingCount

func (sbapi *SubBridgeAPI) TxPendingCount() int

func (*SubBridgeAPI) UnsubscribeBridge

func (sbapi *SubBridgeAPI) UnsubscribeBridge(cBridgeAddr, pBridgeAddr common.Address) error

UnsubscribeBridge disables the event subscription of the given service/main chain bridges.

type SubBridgeHandler

type SubBridgeHandler struct {

	// MainChainAccountAddr is a hex account address used for chain identification from parent chain.
	MainChainAccountAddr *common.Address

	ServiceChainAccountAddr *common.Address
	// contains filtered or unexported fields
}

func NewSubBridgeHandler

func NewSubBridgeHandler(scc *SCConfig, main *SubBridge) (*SubBridgeHandler, error)

func (*SubBridgeHandler) GetAnchoringPeriod

func (sbh *SubBridgeHandler) GetAnchoringPeriod() uint64

GetAnchoringPeriod returns the period to make and send a chain transaction to parent chain.

func (*SubBridgeHandler) GetLatestAnchoredBlockNumber

func (sbh *SubBridgeHandler) GetLatestAnchoredBlockNumber() uint64

GetLatestAnchoredBlockNumber returns the latest block number whose data has been anchored to the parent chain.

func (*SubBridgeHandler) GetMainChainAccountAddr

func (sbh *SubBridgeHandler) GetMainChainAccountAddr() *common.Address

GetMainChainAccountAddr returns a pointer of a hex address of an account used for parent chain. If given as a parameter, it will use it. If not given, it will use the address of the public key derived from chainKey.

func (*SubBridgeHandler) GetNextAnchoringBlockNumber

func (sbh *SubBridgeHandler) GetNextAnchoringBlockNumber() uint64

GetNextAnchoringBlockNumber returns the next block number which is needed to be anchored.

func (*SubBridgeHandler) GetReceiptFromParentChain

func (sbh *SubBridgeHandler) GetReceiptFromParentChain(blockHash common.Hash) *types.Receipt

GetReceiptFromParentChain returns a receipt received from parent chain to child chain with corresponding block hash. It assumes that a child chain has only one parent chain.

func (*SubBridgeHandler) GetSentChainTxsLimit

func (sbh *SubBridgeHandler) GetSentChainTxsLimit() uint64

GetSentChainTxsLimit returns the maximum number of stored chain transactions for resending.

func (*SubBridgeHandler) GetServiceChainAccountAddr

func (sbh *SubBridgeHandler) GetServiceChainAccountAddr() *common.Address

GetServiceChainAccountAddr returns a pointer of a hex address of an account used for service chain. If given as a parameter, it will use it. If not given, it will use the address of the public key derived from chainKey.

func (*SubBridgeHandler) HandleMainMsg

func (sbh *SubBridgeHandler) HandleMainMsg(p BridgePeer, msg p2p.Msg) error

func (*SubBridgeHandler) LocalChainHeadEvent

func (sbh *SubBridgeHandler) LocalChainHeadEvent(block *types.Block)

LocalChainHeadEvent deals with servicechain feature to generate/broadcast service chain transactions and request receipts.

func (*SubBridgeHandler) LockMainChainAccount

func (sbh *SubBridgeHandler) LockMainChainAccount()

func (*SubBridgeHandler) RegisterNewPeer

func (sbh *SubBridgeHandler) RegisterNewPeer(p BridgePeer) error

func (*SubBridgeHandler) SyncNonceAndGasPrice

func (scpm *SubBridgeHandler) SyncNonceAndGasPrice()

SyncNonceAndGasPrice requests the nonce of address used for service chain tx to parent chain peers.

func (*SubBridgeHandler) UnLockMainChainAccount

func (sbh *SubBridgeHandler) UnLockMainChainAccount()

func (*SubBridgeHandler) UpdateLastestAnchoredBlockNumber

func (sbh *SubBridgeHandler) UpdateLastestAnchoredBlockNumber(newLastestAnchoredBN uint64)

UpdateLastestAnchoredBlockNumber set the latestAnchoredBlockNumber to the block number of the last anchoring tx which was added into bridge txPool.

func (*SubBridgeHandler) WriteAnchoredBlockNumber

func (sbh *SubBridgeHandler) WriteAnchoredBlockNumber(blockNum uint64)

WriteAnchoredBlockNumber writes the block number whose data has been anchored to the parent chain.

func (*SubBridgeHandler) WriteReceiptFromParentChain

func (sbh *SubBridgeHandler) WriteReceiptFromParentChain(blockHash common.Hash, receipt *types.Receipt)

WriteReceiptFromParentChain writes a receipt received from parent chain to child chain with corresponding block hash. It assumes that a child chain has only one parent chain.

type SubBridgeInfo

type SubBridgeInfo struct {
	Network uint64              `json:"network"` // Klaytn network ID
	Genesis common.Hash         `json:"genesis"` // SHA3 hash of the host's genesis block
	Config  *params.ChainConfig `json:"config"`  // Chain configuration for the fork rules
	Head    common.Hash         `json:"head"`    // SHA3 hash of the host's best owned block
	ChainID *big.Int            `json:"chainid"` // ChainID
}

NodeInfo represents a short summary of the ServiceChain sub-protocol metadata known about the host peer.

Jump to

Keyboard shortcuts

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