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

Add memo_overwrite configuration #3863

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add a per-chain configuration `memo_overwrite` allowing users
to overwite the relayer memo used for each transaction
([\#3811](https://github.com/informalsystems/hermes/issues/3811))
7 changes: 7 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ trust_threshold = '2/3'
# operational debugging information, e.g., relayer build version.
memo_prefix = ''

# If this is set to a string, it will overwrite the memo used by Hermes for each transaction
# it submits to this chain.
# Default: not set.
# This is used for chains which have a very small character limit for the memo,
# and the additional information appended by Hermes would overflow that limit.
# memo_overwrite = ''

# This section specifies the filters for policy based relaying.
#
# Default: no policy / filters, allow all packets on all channels.
Expand Down
1 change: 1 addition & 0 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ where
client_refresh_rate: default::client_refresh_rate(),
ccv_consumer_chain: false,
memo_prefix: Memo::default(),
memo_overwrite: None,
proof_specs: Default::default(),
trust_threshold: TrustThreshold::default(),
gas_price: GasPrice {
Expand Down
6 changes: 5 additions & 1 deletion crates/relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ impl Configurable<Config> for CliCmd {
for ccfg in config.chains.iter_mut() {
#[allow(irrefutable_let_patterns)]
if let ChainConfig::CosmosSdk(ref mut cosmos_ccfg) = ccfg {
cosmos_ccfg.memo_prefix.apply_suffix(&suffix);
if let Some(memo) = &cosmos_ccfg.memo_overwrite {
cosmos_ccfg.memo_prefix = memo.clone();
} else {
cosmos_ccfg.memo_prefix.apply_suffix(&suffix);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/relayer/src/chain/cosmos/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ pub struct CosmosSdkConfig {
#[serde(default)]
pub memo_prefix: Memo,

#[serde(default)]
pub memo_overwrite: Option<Memo>,

// This is an undocumented and hidden config to make the relayer wait for
// DeliverTX before sending the next transaction when sending messages in
// multiple batches. We will instruct relayer operators to turn this on
Expand Down
73 changes: 73 additions & 0 deletions tools/integration-test/src/tests/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ use ibc_test_framework::ibc::denom::derive_ibc_denom;
use ibc_test_framework::prelude::*;
use ibc_test_framework::util::random::{random_string, random_u128_range};

const OVERWRITE_MEMO: &str = "Overwritten memo";

#[test]
fn test_memo() -> Result<(), Error> {
let memo = Memo::new(random_string()).unwrap();
let test = MemoTest { memo };
run_binary_channel_test(&test)
}

#[test]
fn test_memo_overwrite() -> Result<(), Error> {
let memo = Memo::new(random_string()).unwrap();
let test = MemoTest { memo };
run_binary_channel_test(&test)
}

pub struct MemoTest {
memo: Memo,
}
Expand Down Expand Up @@ -82,6 +91,70 @@ impl BinaryChannelTest for MemoTest {
}
}

pub struct MemoOverwriteTest {
memo: Memo,
}

impl TestOverrides for MemoOverwriteTest {
fn modify_relayer_config(&self, config: &mut Config) {
for chain in config.chains.iter_mut() {
match chain {
ChainConfig::CosmosSdk(chain_config) => {
chain_config.memo_prefix = self.memo.clone();
chain_config.memo_overwrite = Some(Memo::new(OVERWRITE_MEMO).unwrap())
}
}
}
}
}

impl BinaryChannelTest for MemoOverwriteTest {
fn run<ChainA: ChainHandle, ChainB: ChainHandle>(
&self,
_config: &TestConfig,
_relayer: RelayerDriver,
chains: ConnectedChains<ChainA, ChainB>,
channel: ConnectedChannel<ChainA, ChainB>,
) -> Result<(), Error> {
info!(
"testing IBC transfer with memo configured: \"{}\"",
self.memo
);

let denom_a = chains.node_a.denom();

let a_to_b_amount = random_u128_range(1000, 5000);

chains.node_a.chain_driver().ibc_transfer_token(
&channel.port_a.as_ref(),
&channel.channel_id_a.as_ref(),
&chains.node_a.wallets().user1(),
&chains.node_b.wallets().user1().address(),
&denom_a.with_amount(a_to_b_amount).as_ref(),
)?;

let denom_b = derive_ibc_denom(
&channel.port_b.as_ref(),
&channel.channel_id_b.as_ref(),
&denom_a,
)?;

chains.node_b.chain_driver().assert_eventual_wallet_amount(
&chains.node_b.wallets().user1().address(),
&denom_b.with_amount(a_to_b_amount).as_ref(),
)?;

let tx_info = chains
.node_b
.chain_driver()
.query_recipient_transactions(&chains.node_b.wallets().user1().address())?;

assert_tx_memo_equals(&tx_info, OVERWRITE_MEMO)?;

Ok(())
}
}

fn assert_tx_memo_equals(tx_info: &json::Value, expected_memo: &str) -> Result<(), Error> {
debug!("comparing memo field from json value {}", tx_info);

Expand Down
1 change: 1 addition & 0 deletions tools/test-framework/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl FullNode {
packet_filter: Default::default(),
address_type: chain_type.address_type(),
memo_prefix: Default::default(),
memo_overwrite: None,
proof_specs: Default::default(),
extension_options: Default::default(),
sequential_batch_tx: false,
Expand Down
Loading