Skip to content

Commit

Permalink
add two way communication config
Browse files Browse the repository at this point in the history
  • Loading branch information
owenwahlgren committed Oct 9, 2024
1 parent 42f3341 commit 2b54845
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
---

<Callout>Important: The relayer needs funds on both L1s to deliver messages. </Callout>

### 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
```

<Callout>Replace xxxx_xxxx with the name automatically assigned to your local deployment.</Callout>

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/<blockchain-id>/rpc",
"query-parameters": null,
"http-headers": null
},
"ws-endpoint": {
"base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id>/ws",
"query-parameters": null,
"http-headers": null
},
"message-contracts": {
"0x0000000000000000000000000000000000000000": {
"message-format": "off-chain-registry",
"settings": {
"teleporter-registry-address": "0x<registry-address>"
}
},
"0x<contract-address>": {
"message-format": "teleporter",
"settings": {
"reward-address": "0x<reward-address>"
}
}
}
}
],
"destination-blockchains": [
{
"subnet-id": "11111111111111111111111111111111LpoYY",
"blockchain-id": "epm5fG6Pn1Y5rBHdTe36aZYeLqpXugreyHLZB5dV81rVTs7Ku",
"vm": "evm",
"rpc-endpoint": {
"base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id>/rpc",
"query-parameters": null,
"http-headers": null
},
"kms-key-id": "",
"kms-aws-region": "",
"account-private-key": "<your-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-A>",
"blockchain-id": "<blockchain-id-A>",
"vm": "evm",
"rpc-endpoint": {
"base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-A>/rpc",
"query-parameters": null,
"http-headers": null
},
"ws-endpoint": {
"base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id-A>/ws",
"query-parameters": null,
"http-headers": null
},
"message-contracts": {
"0x0000000000000000000000000000000000000000": {
"message-format": "off-chain-registry",
"settings": {
"teleporter-registry-address": "0x<registry-address-A>"
}
},
"0x<contract-address-A>": {
"message-format": "teleporter",
"settings": {
"reward-address": "0x<reward-address-A>"
}
}
}
},
{
"subnet-id": "<blockchain-id-B>",
"blockchain-id": "<blockchain-id-B>",
"vm": "evm",
"rpc-endpoint": {
"base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-B>/rpc",
"query-parameters": null,
"http-headers": null
},
"ws-endpoint": {
"base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id-B>/ws",
"query-parameters": null,
"http-headers": null
},
"message-contracts": {
"0x0000000000000000000000000000000000000000": {
"message-format": "off-chain-registry",
"settings": {
"teleporter-registry-address": "0x<registry-address-B>"
}
},
"0x<contract-address-B>": {
"message-format": "teleporter",
"settings": {
"reward-address": "0x<reward-address-B>"
}
}
}
}
],
"destination-blockchains": [
{
"subnet-id": "<blockchain-id-A>",
"blockchain-id": "<blockchain-id-A>",
"vm": "evm",
"rpc-endpoint": {
"base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-A>/rpc",
"query-parameters": null,
"http-headers": null
},
"kms-key-id": "",
"kms-aws-region": "",
"account-private-key": "<your-private-key-A>"
},
{
"subnet-id": "<blockchain-id-B>",
"blockchain-id": "<blockchain-id-B>",
"vm": "evm",
"rpc-endpoint": {
"base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-B>/rpc",
"query-parameters": null,
"http-headers": null
},
"kms-key-id": "",
"kms-aws-region": "",
"account-private-key": "<your-private-key-B>"
}
]
}
```
### 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.

0 comments on commit 2b54845

Please sign in to comment.