From c0f090da7689ea0861cd76a3684d43e51ed9dc32 Mon Sep 17 00:00:00 2001 From: Owen Date: Wed, 9 Oct 2024 23:50:13 +0400 Subject: [PATCH] add two way communication config for relayer (#187) --- .../05-multichain-relayer-config.mdx | 217 ++++++++++++++++++ ...r-logs.mdx => 06-analyze-relayer-logs.mdx} | 0 2 files changed, 217 insertions(+) create mode 100644 content/course/interchain-messaging/10-running-a-relayer/05-multichain-relayer-config.mdx rename content/course/interchain-messaging/10-running-a-relayer/{05-analyze-relayer-logs.mdx => 06-analyze-relayer-logs.mdx} (100%) diff --git a/content/course/interchain-messaging/10-running-a-relayer/05-multichain-relayer-config.mdx b/content/course/interchain-messaging/10-running-a-relayer/05-multichain-relayer-config.mdx new file mode 100644 index 00000000..e3d9bc09 --- /dev/null +++ b/content/course/interchain-messaging/10-running-a-relayer/05-multichain-relayer-config.mdx @@ -0,0 +1,217 @@ +--- +title: Two-Way Messaging Configuration +description: Learn how to configure a relayer for multiple L1s +updated: 2024-10-09 +authors: [owenwahlgren] +icon: BookOpen +--- + +Important: The relayer needs funds on both L1s to deliver messages. + +### Two-Way Messaging Configuration + +In this section, you’ll learn how to configure a relayer to support two-way messaging between multiple Layer 1 blockchains (L1s). By extending your existing configuration, you can enable the relayer to handle communication in both directions, eliminating the need to run multiple relayers. + +### Accessing the Relayer Configuration File + +The relayer configuration is supplied as a JSON file. To open the configuration file automatically created by the Avalanche-CLI, run the following command: +```bash +code ~/.avalanche-cli/runs/network_xxxx_xxxx/awm-relayer-config.json +``` + +Replace xxxx_xxxx with the name automatically assigned to your local deployment. + +Alternatively, navigate to the directory `~/.avalanche-cli/runs/` and locate the relayer configuration file for your network. + +### Understanding the Existing Configuration + +Assuming you have a configuration as described in the [Relayer Configuration section](/course/interchain-messaging/10-running-a-relayer/04-relayer-configuration), your current configuration should look similar to the following: +```json +{ + "p-chain-api": { + "base-url": "http://127.0.0.1:9650", + "query-parameters": {}, + "http-headers": null + }, + "info-api": { + "base-url": "http://127.0.0.1:9650", + "query-parameters": {}, + "http-headers": null + }, + "source-blockchains": [ + { + "subnet-id": "11111111111111111111111111111111LpoYY", + "blockchain-id": "epm5fG6Pn1Y5rBHdTe36aZYeLqpXugreyHLZB5dV81rVTs7Ku", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "ws-endpoint": { + "base-url": "ws://127.0.0.1:9650/ext/bc//ws", + "query-parameters": null, + "http-headers": null + }, + "message-contracts": { + "0x0000000000000000000000000000000000000000": { + "message-format": "off-chain-registry", + "settings": { + "teleporter-registry-address": "0x" + } + }, + "0x": { + "message-format": "teleporter", + "settings": { + "reward-address": "0x" + } + } + } + } + ], + "destination-blockchains": [ + { + "subnet-id": "11111111111111111111111111111111LpoYY", + "blockchain-id": "epm5fG6Pn1Y5rBHdTe36aZYeLqpXugreyHLZB5dV81rVTs7Ku", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "kms-key-id": "", + "kms-aws-region": "", + "account-private-key": "" + } + ] +} +``` + +### Updating the Configuration for Two-Way Communication + +To enable two-way communication between L1s, you need to extend the configuration to include both blockchains in the source-blockchains and destination-blockchains arrays. + +Updated Configuration: + +```json +{ + "p-chain-api": { + "base-url": "http://127.0.0.1:9650", + "query-parameters": {}, + "http-headers": null + }, + "info-api": { + "base-url": "http://127.0.0.1:9650", + "query-parameters": {}, + "http-headers": null + }, + "source-blockchains": [ + { + "subnet-id": "", + "blockchain-id": "", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "ws-endpoint": { + "base-url": "ws://127.0.0.1:9650/ext/bc//ws", + "query-parameters": null, + "http-headers": null + }, + "message-contracts": { + "0x0000000000000000000000000000000000000000": { + "message-format": "off-chain-registry", + "settings": { + "teleporter-registry-address": "0x" + } + }, + "0x": { + "message-format": "teleporter", + "settings": { + "reward-address": "0x" + } + } + } + }, + { + "subnet-id": "", + "blockchain-id": "", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "ws-endpoint": { + "base-url": "ws://127.0.0.1:9650/ext/bc//ws", + "query-parameters": null, + "http-headers": null + }, + "message-contracts": { + "0x0000000000000000000000000000000000000000": { + "message-format": "off-chain-registry", + "settings": { + "teleporter-registry-address": "0x" + } + }, + "0x": { + "message-format": "teleporter", + "settings": { + "reward-address": "0x" + } + } + } + } + ], + "destination-blockchains": [ + { + "subnet-id": "", + "blockchain-id": "", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "kms-key-id": "", + "kms-aws-region": "", + "account-private-key": "" + }, + { + "subnet-id": "", + "blockchain-id": "", + "vm": "evm", + "rpc-endpoint": { + "base-url": "http://127.0.0.1:9650/ext/bc//rpc", + "query-parameters": null, + "http-headers": null + }, + "kms-key-id": "", + "kms-aws-region": "", + "account-private-key": "" + } + ] +} +``` +### Explanation of Changes + +By adding both blockchains to the source-blockchains and destination-blockchains arrays, the relayer is configured to: + +- Listen for messages on both blockchains. +- Relay messages to the opposite blockchain. + +This setup enables two-way communication between the blockchains using a single relayer instance. + +### Important Considerations + +- **Private Keys**: Ensure that the account-private-key field contains the private key for the respective blockchain. This key is used to sign transactions when relaying messages. +- **Funding**: The relaxyer account must have sufficient funds on both L1s to cover transaction fees. + +### Next Steps + +After updating the configuration file: +- Save the changes. +- Restart the relayer to apply the new configuration. +- Test the two-way communication by sending messages between the blockchains. \ No newline at end of file diff --git a/content/course/interchain-messaging/10-running-a-relayer/05-analyze-relayer-logs.mdx b/content/course/interchain-messaging/10-running-a-relayer/06-analyze-relayer-logs.mdx similarity index 100% rename from content/course/interchain-messaging/10-running-a-relayer/05-analyze-relayer-logs.mdx rename to content/course/interchain-messaging/10-running-a-relayer/06-analyze-relayer-logs.mdx