Skip to content

Commit

Permalink
Merge pull request #14 from initia-labs/feat/store-events
Browse files Browse the repository at this point in the history
Use DB to support ordered channel, ICA and packet fee
  • Loading branch information
ALPAC-4 authored Dec 6, 2024
2 parents ef23680 + d322283 commit 8d9143c
Show file tree
Hide file tree
Showing 56 changed files with 11,049 additions and 3,157 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
node_modules/

config.json
/.idea
/.idea

/.db

/test_db
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## v0.0.1 - 2024-11-11

Initial release
106 changes: 64 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Rapid Relayer

Rapid Relayer is a fast, scalable, stateful IBC Relayer optimized for interwoven rollups.

Rapid Relayer does not use the `tx_search` query of Hermes to handle packets from several blocks at once. Initia Labs has developed this IBC Relayer to replace Hermes, only using the necessary functions for packet handling.
Rapid Relayer does not use the `tx_search` query of Hermes to handle packets from several blocks at once. Initia Labs has developed this IBC Relayer to replace Hermes, only using the necessary functions for packet handling.

## Problems We Faced

### Problems We Faced
- Minitia L2s generate blocks extremely quick at 500ms per block.
- Due to the interwoven nature of Initia, often many IBC packets are generated within blocks. Hermes can handle batches of packets but on a single block basis.
- Hermes handles these IBC packets sequentially leading to unprocessed packets accumulating very quickly when having fast blocktimes.
- If Hermes stops, unprocessed packets will continue to pile up.
- If Hermes stops, unprocessed packets will continue to pile up.
- When Hermes misses a packet, it finds them using `tx_search` query on every sequence, this can take minutes for just a few hundred packets.
- We need something more rapid.

### How We Fix This
## How We Fix This

- We removed the `tx_search` query, and handle packets in parallel across several blocks at once.
- Keep track of `synced_height` and `latest_height`.
- Multi-threaded workers: packet handler and event feeder. The event feeder feeds the packet from new blocks to a cache and the packet handler fetches packets from it. This way, even if the packet handler stops, the event feeder will continue to operate.
- We remove the slow call of `tx_search`.

- We remove the slow call of `tx_search`.

## Installation

Expand All @@ -38,39 +40,58 @@ npm install

```json
{
"port": 3000,
"$schema": "./config.schema.json",
"port": 7010,
"metricPort": 70001,
"logLevel": "info",
"pairs": [
"chains": [
{
"name": "chainA - chainB", // default chainA.chainId - chainB.chainId
"chainA": {
"bech32Prefix": "init", // bech 32 prefix
"chainId": "chain-1", // chainId
"gasPrice": "0.2uinit", // gas price
"lcdUri": "http://rest.chain-1.com", // lcd (rest) uri
"rpcUri": "http://rpc.chain-1.com", // rpc uri
"key": {
"type": "raw", // raw | mnemonic
"privateKey": "12af.." // for raw hex based private key, for mnemonic 12/24 words
"bech32Prefix": "init",
"chainId": "chain-1",
"gasPrice": "0.15gas",
"restUri": "https://rest.chain-1.com",
"rpcUri": "https://rpc.chain-1.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10,
"startHeight": 0 // if empty start from the latest height
},
"connectionId": "connection-1", // connection id to relay
"syncInfo": {
"height": 12345, // synced height
"txIndex": 30 // synced tx index
} // Optional, If a syncInfo file exists, this field is ignored.
},
"chainB": {
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0umin",
"lcdUri": "http://rest.chain-2.com",
"rpcUri": "http://rpc.chain-2.com",
"key": {
"type": "mnemonic",
"privateKey": "bus ..."
},
"connectionId": "connection-0"
{
"key": {
"type": "mnemonic",
"privateKey": "repair family apology column ..."
},
"maxHandlePacket": 10,
"packetFilter": {
"connections": [{ "connectionId": "conneciton-1" }]
}
}
],
"feeFilter": {
"recvFee": [{ "denom": "gas", "amount": 100 }],
"timeoutFee": [{ "denom": "gas", "amount": 200 }],
"ackFee": [{ "denom": "gas", "amount": 300 }]
}
},
{
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0umin",
"restUri": "https://rest.chain-2.com",
"rpcUri": "https://rpc.chain-2.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10
}
]
}
]
}
Expand All @@ -81,17 +102,18 @@ npm install
```bash
npm start
```

## Install via docker
```bash

```bash
docker build -t your-tag .
```
mount a volume called '/config' which contains your config.json
and a /syncInfo volume which will contain the state

mount a volume called '/config' which contains your config.json
and a /syncInfo volume which will contain the state

```bash
docker run -it -v/tmp/rr/config:/config -v/tmp/rr/syncInfo:/syncInfo -d rapid-relayer:latest
```
this should start the relayer in a docker container using your config, and placing the state in a separate volume

## SyncInfo

rapid-relayer checks events and stores processed information in `.syncInfo`. To move migrate relayer to other, please copy `.syncInfo`
this should start the relayer in a docker container using your config, and placing the state in a separate volume
75 changes: 47 additions & 28 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
{
"port": 3000,
"$schema": "./config.schema.json",
"port": 7010,
"metricPort": 70001,
"logLevel": "info",
"pairs": [
"chains": [
{
"name": "chainA - chainB",
"chainA": {
"bech32Prefix": "init",
"chainId": "chain-1",
"gasPrice": "0.2uinit",
"lcdUri": "http://rest.chain-1.com",
"rpcUri": "http://rpc.chain-1.com",
"key": {
"type": "raw",
"privateKey": "12af.."
"bech32Prefix": "init",
"chainId": "chain-1",
"gasPrice": "0.15gas",
"restUri": "https://rest.chain-1.com",
"rpcUri": "https://rpc.chain-1.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10,
"startHeight": 0 // if empty start from the latest height
},
"connectionId": "connection-1",
"syncInfo": {
"height": 12345,
"txIndex": 30
{
"key": {
"type": "mnemonic",
"privateKey": "repair family apology column ..."
},
"maxHandlePacket": 10,
"packetFilter": {
"connections": [{ "connectionId": "conneciton-1" }]
}
}
},
"chainB": {
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0umin",
"lcdUri": "http://rest.chain-2.com",
"rpcUri": "http://rpc.chain-2.com",
"key": {
"type": "mnemonic",
"privateKey": "bus ..."
},
"connectionId": "connection-0"
],
"feeFilter": {
"recvFee": [{ "denom": "gas", "amount": 100 }],
"timeoutFee": [{ "denom": "gas", "amount": 200 }],
"ackFee": [{ "denom": "gas", "amount": 300 }]
}
},
{
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0umin",
"restUri": "https://rest.chain-2.com",
"rpcUri": "https://rpc.chain-2.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10
}
]
}
]
}
145 changes: 145 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"title": "Rapid Relayer Config",
"description": "Rapid Relayer config schema",
"type": "object",
"required": ["port", "metricPort", "logLevel", "chains"],
"properties": {
"$schema": {
"type": "string"
},
"port": {
"type": "number"
},
"dbPath": {
"type": "string"
},
"metricPort": {
"type": "number"
},
"logLevel": {
"type": "string"
},
"chains": {
"type": "array",
"items": {
"$ref": "#/$defs/chain"
},
"minContains": 2
}
},
"additionalProperties": false,
"$defs": {
"chain": {
"type": "object",
"required": [
"bech32Prefix",
"chainId",
"gasPrice",
"restUri",
"rpcUri",
"wallets"
],
"properties": {
"bech32Prefix": {
"type": "string",
"description": "bech32 prefix of chain"
},
"chainId": {
"type": "string",
"description": "chain id"
},
"gasPrice": {
"type": "string",
"description": "gas price in format 0.1denom"
},
"restUri": {
"type": "string",
"description": "cosmos rest api uri"
},
"rpcUri": {
"type": "string",
"description": "cosmos rest rpc uri"
},
"wallets": {
"type": "array",
"items": {
"$ref": "#/$defs/wallet"
},
"minContains": "1"
},
"feeFilter": {
"type": "object",
"properties": {
"recvFee": {
"type": "array",
"items": {
"$ref": "#/$defs/coin"
},
"minContains": "1"
},
"ackFee": {
"type": "array",
"items": {
"$ref": "#/$defs/coin"
},
"minContains": "1"
},
"timeoutFee": {
"type": "array",
"items": {
"$ref": "#/$defs/coin"
},
"minContains": "1"
}
}
}
}
},
"wallet": {
"type": "object",
"required": ["key"],
"properties": {
"key": {
"type": "object",
"required": ["type", "privateKey"],
"properties": {
"type": {
"type": "string",
"enum": ["raw", "mnemonic", "env_raw", "env_mnemonic"]
},
"privateKey": {
"type": "string"
},
"options": {
"type": "object",
"properties": {
"account": {
"type": "number"
},
"index": {
"type": "number"
},
"coinType": {
"type": "number"
}
}
}
}
}
}
},
"coin": {
"type": "object",
"required": ["denom", "amount"],
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "number"
}
}
}
}
}
Loading

0 comments on commit 8d9143c

Please sign in to comment.