Skip to content

Commit

Permalink
Problem: ibc relayer don't work well with default tx prioritization s…
Browse files Browse the repository at this point in the history
…trategy (#652)

* Problem: ibc relayer don't work well with default tx prioritization stretegy

Closes: #634
Solution:
- set dynamic fee extension option in hermes

* check relayer tx fee in integration test

* Update integration_tests/configs/ibc.jsonnet

* renames
  • Loading branch information
yihuang authored Aug 19, 2022
1 parent 1cfeb0a commit f4d6cf8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 31 deletions.
9 changes: 8 additions & 1 deletion integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ config {
'account-prefix': 'crc',
'coin-type': 60,
key_name: 'signer1',
'app-config'+: {
'index-events': super['index-events'] + ['message.action'],
},
genesis+: {
app_state+: {
feemarket+: {
Expand Down Expand Up @@ -128,9 +131,13 @@ config {
},
},
gas_price: {
price: 10000000000000,
price: 10000000000000000,
denom: 'basetcro',
},
extension_options: [{
type: 'ethermint_dynamic_fee',
value: '1000000',
}],
},
{
id: 'chainmain-1',
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def query_all_txs(self, addr):
)
return json.loads(txs)

def tx_search(self, events: str):
"/tx_search"
return json.loads(
self.raw("query", "txs", events=events, output="json", node=self.node_rpc)
)

def distribution_commission(self, addr):
coin = json.loads(
self.raw(
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ pkgs.mkShell {
pkgs.rocksdb
(import ../nix/testenv.nix { inherit pkgs; })
(import ../nix/chainmain.nix { inherit pkgs; })
(import ../nix/hermes.nix { inherit pkgs; })
pkgs.hermes
];
}
12 changes: 12 additions & 0 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CONTRACTS,
deploy_contract,
eth_to_bech32,
parse_events_rpc,
send_transaction,
wait_for_fn,
wait_for_new_blocks,
Expand Down Expand Up @@ -45,6 +46,17 @@ def check_balance_change():
wait_for_fn("balance change", check_balance_change)
assert old_dst_balance + dst_amount == new_dst_balance

# assert that the relayer transactions do enables the dynamic fee extension option.
cli = ibc.cronos.cosmos_cli()
criteria = "message.action=/ibc.core.channel.v1.MsgChannelOpenInit"
tx = cli.tx_search(criteria)["txs"][0]
events = parse_events_rpc(tx["events"])
fee = int(events["tx"]["fee"].removesuffix("basetcro"))
gas = int(tx["gas_wanted"])
# the effective fee is decided by the max_priority_fee (base fee is zero)
# rather than the normal gas price
assert fee == gas * 1000000


def test_cronos_transfer_tokens(ibc):
"""
Expand Down
17 changes: 17 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import configparser
import json
import os
Expand All @@ -6,6 +7,7 @@
import subprocess
import sys
import time
from collections import defaultdict
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path

Expand Down Expand Up @@ -176,6 +178,21 @@ def parse_events(logs):
}


def parse_events_rpc(events):
result = defaultdict(dict)
for ev in events:
for attr in ev["attributes"]:
if attr["key"] is None:
continue
key = base64.b64decode(attr["key"].encode()).decode()
if attr["value"] is not None:
value = base64.b64decode(attr["value"].encode()).decode()
else:
value = None
result[ev["type"]][key] = value
return result


_next_unique = 0


Expand Down
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import sources.nixpkgs {
paths = with pkgs.openssl; [ out dev ];
};
};
hermes = pkgs.callPackage ./hermes.nix { src = sources.ibc-rs; };
})
(_: pkgs: { test-env = import ./testenv.nix { inherit pkgs; }; })
(_: pkgs: {
Expand Down
52 changes: 23 additions & 29 deletions nix/hermes.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
{ pkgs ? import ./default.nix { } }:
let
version = "v1.0.0-rc.2";
srcUrl = {
x86_64-linux = {
url =
"https://github.com/informalsystems/ibc-rs/releases/download/${version}/hermes-${version}-x86_64-unknown-linux-gnu.tar.gz";
sha256 = "sha256-ms+3Ka8Ijbx63OXQzzNZ1kLrwVJDIVnvyc1TG69bun0=";
};
x86_64-darwin = {
url =
"https://github.com/informalsystems/ibc-rs/releases/download/${version}/hermes-${version}-x86_64-apple-darwin.tar.gz";
sha256 = "sha256-ygp49IPTXKqK12gE8OiyXjXhkJvfUZNuXVnS14SVScQ=";
};
}.${pkgs.stdenv.system} or (throw
"Unsupported system: ${pkgs.stdenv.system}");
in
pkgs.stdenv.mkDerivation {
{ src
, lib
, stdenv
, darwin
, rustPlatform
, symlinkJoin
, openssl
}:
rustPlatform.buildRustPackage rec {
name = "hermes";
inherit version;
src = pkgs.fetchurl srcUrl;
sourceRoot = ".";
installPhase = ''
echo "hermes"
echo $out
install -m755 -D hermes $out/bin/hermes
'';

meta = with pkgs.lib; { platforms = with platforms; linux ++ darwin; };

inherit src;
cargoSha256 = "sha256-42yTWf7fFEko0n/Y7AA2vA2s/gMypcZDvbbd9DAcuRw=";
cargoBuildFlags = "-p ibc-relayer-cli";
buildInputs = lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.libiconv
];
doCheck = false;
RUSTFLAGS = "--cfg ossl111 --cfg ossl110 --cfg ossl101";
OPENSSL_NO_VENDOR = "1";
OPENSSL_DIR = symlinkJoin {
name = "openssl";
paths = with openssl; [ out dev ];
};
}
12 changes: 12 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
"url": "https://github.com/crypto-org-chain/gravity-bridge/archive/3d5bdc8af5227588d04064132335932ee88f57c3.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ibc-rs": {
"branch": "feemarket",
"description": "IBC Relayer (Hermes) and Modules in Rust",
"homepage": "",
"owner": "yihuang",
"repo": "ibc-rs",
"rev": "e33cceaa247d5eda7650c24bd3968dea6a05248a",
"sha256": "1kq73qvhdz35pxcx07rqqygvb3n8z8wsgw8knddj2b1x3yj66444",
"type": "tarball",
"url": "https://github.com/yihuang/ibc-rs/archive/e33cceaa247d5eda7650c24bd3968dea6a05248a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
Expand Down

0 comments on commit f4d6cf8

Please sign in to comment.