Relayer

Introduction

This document defines the procedure for Relayer to join, setup involved or leave the network.

Constants

Name Type Value
REWARD_TYPE bytes32 "perByte"
RELAYER_EXIT_WAIT_TIME uint TBD

Data Structures

Type Aliases

Name Type Description Example
Protocol bytes32 Name of the protocol "ETH", "BTC"
Latency uint Latency in nano seconds
Bandwidth uint Bandwidth in kilobytes/second
Reward uint Reward in LIN
NetworkId bytes32 Id of the network

Capability

struct Capability {
    Latency latency
    Bandwidth bandwidth
}
struct ContractContainer {
    bytes32 key
    uint value
}

Storage

exitBlock

mapping(NetworkId => uint) exitBlocks

Operations

Setup

Register Node

Relayer who wants to join the Marlin network can register the Relayer node on relayer marketplace by sending a transaction to the RelayMarketplace contract.

func registerNode(Protocol protocol, Capability capabilties, Reward reward, bytes32 stakerAddress, bytes32 withdrawalAddress):
    for key in keys(capabilities):
        capabilityContainers.push(ContractContainer(key, capabilities[key]))
    RelayerMarketplace::addRelayerProfile(protocol, capabilityContainers, [ContractContainer(REWARD_TYPE, reward)]).send(self.privKey)

Select network

Once the relayer is registered in the marketplace, Relayer is eligible to join any network. Relayer can list the networks and then select the network to join. Relayer can then allocate LIN to the network in the LIN token contract that needs to be staked to join.

func bytes32[] getNetworks(Protocol protocol):
    networksIds = NetworkMarketplace::Events::NetworkCreated().query(protocol)
    return networkIds
func bytes32 getNetworkAddress(bytes32 networkId):
    return NetworkMarketplace::NetworkMap(networkId).query()

Allocate Stake

Allocated stake should be higher than the stake threshold for the network.

func allocateStake(bytes32 networkContractAddress, uint stake):
    LINTokenContract::approve(networkContractAddress, stake).send(self.stakingPrivKey)

Join Network

Relayer can then send a transaction to the network contract to join.

func joinNetwork(bytes32 networkContractAddress, bytes32 withdrawalAddress, uint stake):
    NetworkContract::joinNetwork(self.pubKey, self.stakingPubKey, withdrawalAddress, stake).send(self.privKey)

Connect to Network

Relayer who joined the network smart contract can connect to nodes in the network.

func onRelayNodeJoinedNetwork(event):
    if event.relayerAddress == self.pubKey:
        ParentManagement::findParents()
        ChildManagement::findChildren()

Exit Network

Create Exit Proposal

Relayer will disconnect from all nodes before proposing an exit to the smart contract

func exitNetwork(NetworkId networkId):
    ParentManagement::disconnectParents()
    ParentManagement::disconnectChildren()
    proposeExit(networkId)

Once disconnected, relayer will send an exit proposal to network contract. Proposal that is published to contractwill be listened by every other actor in the network and disconnect from the relayer.

func proposeExit(NetworkId networkId):
    NetworkContract::proposeExit().send(self.privKey)
    NetworkContract::events::RelayerExitProposedEvent(self.pubKey).onEvent()

Once the relayer exit proposal is published on the network contract, relayer waits for RELAYER_EXIT_WAIT_TIME and then sends an exit transaction to the network contract where the remaining stake that is locked with the contract is also returned.

func onRelayerExitProposedEvent(NetworkId networkId, bytes32 relayer):
    if relayer == self.pubKey:
        exitBlocks[networkId] = event.block + RELAYER_EXIT_WAIT_TIME

Wait and Exit

func onExitWaitCompleted(NetworkId networkId):
    NetworkContract::exit().send(self.privKey)