Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 4.89 KB

relayer.md

File metadata and controls

95 lines (75 loc) · 4.89 KB

Develop for Relayer

1. Development Specifications

This step shows how to develop a relayer for your chain or project. The relayer plays a role in delivering messages between different chains, which is part of the cross-chain ecosystem.

There are two components required: Chain Listener and Chain Submitter.

1.1 Chain Listener

Chain listener fetches data from the source chain and Poly chain, including block header, cross-chain events emitted from CCM, and Merkle proofs used to verify the cross-chain message in the Poly chain. The listed interface is necessary.

type IChainListener interface {
  // Initialize with config
  Init(*config.ListenerConfig, *poly.SDK) error
  // Blocks to confirm
  Defer() int
  // New block check interval
  ListenCheck() time.Duration
  // Chain Id
  ChainId() uint64
  // Optional: Fetch block header and header hash, used to submit to Poly chain for verifications
  Header(height uint64) (header []byte, hash []byte, err error)
  // Optional: Last header sync state in Poly chain.
  LastHeaderSync(uint64, uint64) (uint64, error)
  // Scan cross chain transactions included in the block
  Scan(uint64) ([]*msg.Tx, error)
  // Compose cross chain message before submit to Poly chain
  Compose(*msg.Tx) error
  // Current chain height
  LatestHeight() (uint64, error)
}

1.2 Chain Submitter

Chain Submitter delivers messages to the target chain, including validator changes of Poly chain to CCD and cross-chain messages. Additionally, Chain Submitter checks whether the transaction has been verified within the CCD. The listed interface is necessary.

type IChainSubmitter interface {
  // Initialize with config
  Init(*config.SubmitterConfig) error
  // Submit message/transaction to the chain
  Submit(msg.Message) error
  // Start the thread
  Start(context.Context, *sync.WaitGroup, bus.TxBus, bus.DelayedTxBus, msg.PolyComposer) error  
  // Process the cross chain message from Poly chain
  ProcessTx(*msg.Tx, msg.PolyComposer) error
}

##2. Develop Steps on Poly-Relayer.

Poly-Relayer is a relayer project maintained by Poly Network. If you choose to develop based on Poly-Relayer, please follow the listed steps.

Step1. Prerequisites

The Poly-Relayer project is based on the bridge-common library. So you need to:

  • Add chain ID in the bridge-common project here.
  • Add chain client SDK here for common usage.
  • Add chain wallet here for common usage.

Step2. Interface implementation

Implement interface IChainListener and IChainSubmitter for the new chain.

Step3. Registration

Register ChainListener and ChainSubmitter in selectors located in the relayer.go file.

##3. Preparation for Launch

The configurations are required when launching relayer:

  • Make sure the necessary configuration is specified in config.json, including CCM contract, CCD contract, and other details for the chain.
  • You can see a sample here.

[!Note|style:flat|label:Notice]

  • If you develop the relayer for the chain integrated with Poly Network, you can directly fetch CCD and CCM contracts.
  • If you develop the relayer for a new chain, please complete the contract yourself.
  • Check Poly public nodes in here.
  • Specify roles to enable in roles.json and see a sample here.
Roles Quantity Demand Description
HeaderSync One or multiple for each chain Submits chain headers to the Poly chain.
TxListen Only one for each chain Observes cross-chain transactions from the source chain and pushes them to the message queue.
TxCommit One or multiple for each chain Consumes the message queue and submits the cross-chain transactions to poly.
PolyListen Only One for Poly chain Observes cross-chain transactions from the Poly chain and pushes them to the message queue.
PolyCommit One or multiple for Poly chain Consumes the message queue and submits the cross-chain transaction to the target chain.

You are now ready for the relayer, please refer to the chapter Test and Launch for launching details.