Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DB to support ordered channel, ICA and packet fee #14

Merged
merged 34 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7240e6f
use sqlite to store events
ALPAC-4 Sep 13, 2024
d2bc4b6
merge main
ALPAC-4 Sep 13, 2024
8f18b49
delete unuse file
ALPAC-4 Sep 13, 2024
0ae46c7
Merge branch 'main' into feat/store-events
ALPAC-4 Sep 13, 2024
c77f519
fix main
ALPAC-4 Sep 13, 2024
9e58402
fix conflicts
ALPAC-4 Sep 13, 2024
1f4b299
fix: fix db type, transactoin
ALPAC-4 Sep 26, 2024
3adcc88
remove db folder
ALPAC-4 Sep 26, 2024
5ea1a38
add gitignore deafult db path
ALPAC-4 Sep 26, 2024
a73a5bf
add status query
ALPAC-4 Sep 26, 2024
1fac155
fix: filter packet that create in latest height
ALPAC-4 Sep 27, 2024
6b65084
update logger
ALPAC-4 Sep 27, 2024
f055a38
support create channel
ALPAC-4 Oct 4, 2024
9622103
support packet fee filter
ALPAC-4 Oct 8, 2024
0571f4d
add channel close
ALPAC-4 Oct 14, 2024
5c4977d
fix: fix release time
ALPAC-4 Oct 14, 2024
bd53ed5
support ordered channels
ALPAC-4 Oct 16, 2024
08cb13a
add config example, fix readme
ALPAC-4 Nov 1, 2024
3e83c80
add metric app
ALPAC-4 Nov 1, 2024
6aeedce
fix: delete right channel-open-close row
ALPAC-4 Nov 4, 2024
3a1ddef
support base64 events
ALPAC-4 Nov 4, 2024
4041416
fix lint
ALPAC-4 Nov 4, 2024
d80118e
add tests
ALPAC-4 Nov 11, 2024
9324fa8
add tests
ALPAC-4 Nov 11, 2024
efaf272
feat: add changelog
ALPAC-4 Nov 11, 2024
e7172ef
fix: handle seq mismatch error
ALPAC-4 Nov 21, 2024
9bd3ea3
fix: rest after update latest height
ALPAC-4 Nov 26, 2024
73d5ca4
fix typo and minor correction
beer-1 Dec 2, 2024
91bef04
add comments
beer-1 Dec 2, 2024
d213591
Merge pull request #16 from initia-labs/fix/typo
ALPAC-4 Dec 2, 2024
36dd4a2
fix: revert default value
ALPAC-4 Dec 2, 2024
c0d899f
Merge branch 'main' into feat/store-events
ALPAC-4 Dec 5, 2024
6521916
fix: fix errors from comments
ALPAC-4 Dec 5, 2024
d322283
fix: set timeout for close init event
ALPAC-4 Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
node_modules/

config.json
/.idea
/.idea

/.db
99 changes: 58 additions & 41 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

- 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

- 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,53 @@ 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",
"lcdUri": "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" }]
}
}
]
},
{
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0.15gas",
"lcdUri": "https://rest.chain-2.com",
"rpcUri": "https://rpc.chain-2.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10
}
]
}
]
}
Expand All @@ -81,17 +97,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
77 changes: 48 additions & 29 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",
"lcdUri": "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" }]
},
"feeFilter": {
"recvFee": "100gas",
"timeoutFee": "200gas",
"ackFee": "300gas"
}
}
},
"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"
}
]
},
{
"bech32Prefix": "init",
"chainId": "chain-2",
"gasPrice": "0umin",
"lcdUri": "https://rest.chain-2.com",
"rpcUri": "https://rpc.chain-2.com",
"wallets": [
{
"key": {
"type": "raw",
"privateKey": "123..."
},
"maxHandlePacket": 10
}
]
}
]
}
142 changes: 142 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"$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"
},
"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",
"lcdUri",
"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"
},
"lcdUri": {
"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