diff --git a/crates/relayer-cli/src/commands/clear.rs b/crates/relayer-cli/src/commands/clear.rs index d06bd853f6..9e3b9c06a4 100644 --- a/crates/relayer-cli/src/commands/clear.rs +++ b/crates/relayer-cli/src/commands/clear.rs @@ -63,6 +63,12 @@ pub struct ClearPacketsCmd { help = "use the given signing key for the counterparty chain (default: `counterparty_key_name` config)" )] counterparty_key_name: Option, + + #[clap( + long = "query-packets-chunk-size", + help = "number of packets to fetch at once from the chain (default: `query_packets_chunk_size` config)" + )] + query_packets_chunk_size: Option, } impl Override for ClearPacketsCmd { @@ -112,6 +118,17 @@ impl Runnable for ClearPacketsCmd { } } + // If `query_packets_chunk_size` is provided, overwrite the chain's + // `query_packets_chunk_size` parameter + if let Some(chunk_size) = self.query_packets_chunk_size { + match chains.src.config() { + Ok(mut src_chain_cfg) => { + src_chain_cfg.set_query_packets_chunk_size(chunk_size); + } + Err(e) => Output::error(e).exit(), + } + } + let mut ev_list = vec![]; // Construct links in both directions. @@ -180,6 +197,7 @@ mod tests { channel_id: ChannelId::from_str("channel-07").unwrap(), key_name: None, counterparty_key_name: None, + query_packets_chunk_size: None }, ClearPacketsCmd::parse_from([ "test", @@ -201,7 +219,8 @@ mod tests { port_id: PortId::from_str("port_id").unwrap(), channel_id: ChannelId::from_str("channel-07").unwrap(), key_name: None, - counterparty_key_name: None + counterparty_key_name: None, + query_packets_chunk_size: None }, ClearPacketsCmd::parse_from([ "test", @@ -224,6 +243,7 @@ mod tests { channel_id: ChannelId::from_str("channel-07").unwrap(), key_name: Some("key_name".to_owned()), counterparty_key_name: None, + query_packets_chunk_size: None }, ClearPacketsCmd::parse_from([ "test", @@ -248,6 +268,7 @@ mod tests { channel_id: ChannelId::from_str("channel-07").unwrap(), key_name: None, counterparty_key_name: Some("counterparty_key_name".to_owned()), + query_packets_chunk_size: None }, ClearPacketsCmd::parse_from([ "test", @@ -263,6 +284,33 @@ mod tests { ) } + #[test] + fn test_clear_packets_query_packets_chunk_size() { + assert_eq!( + ClearPacketsCmd { + chain_id: ChainId::from_string("chain_id"), + port_id: PortId::from_str("port_id").unwrap(), + channel_id: ChannelId::from_str("channel-07").unwrap(), + key_name: None, + counterparty_key_name: Some("counterparty_key_name".to_owned()), + query_packets_chunk_size: Some(100), + }, + ClearPacketsCmd::parse_from([ + "test", + "--chain", + "chain_id", + "--port", + "port_id", + "--channel", + "channel-07", + "--counterparty-key-name", + "counterparty_key_name", + "--query-packets-chunk-size", + "100" + ]) + ) + } + #[test] fn test_clear_packets_no_chan() { assert!(ClearPacketsCmd::try_parse_from([ diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index f6381d41f4..882a375084 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -660,6 +660,12 @@ impl ChainConfig { Self::CosmosSdk(config) => config.query_packets_chunk_size, } } + + pub fn set_query_packets_chunk_size(&mut self, query_packets_chunk_size: usize) { + match self { + Self::CosmosSdk(config) => config.query_packets_chunk_size = query_packets_chunk_size, + } + } } /// Attempt to load and parse the TOML config file as a `Config`. diff --git a/crates/relayer/src/link/cli.rs b/crates/relayer/src/link/cli.rs index bdcbc3fe9c..230c370e54 100644 --- a/crates/relayer/src/link/cli.rs +++ b/crates/relayer/src/link/cli.rs @@ -111,9 +111,16 @@ impl Link { None => Qualified::SmallerEqual(src_response_height), }; + let chunk_size = self + .a_to_b + .src_chain() + .config() + .map_or(50, |cfg| cfg.query_packets_chunk_size()); + self.relay_packet_messages( sequences, query_height, + chunk_size, query_send_packet_events, TrackingId::new_static("packet-recv"), ) @@ -163,9 +170,16 @@ impl Link { None => Qualified::SmallerEqual(src_response_height), }; + let chunk_size = self + .a_to_b + .src_chain() + .config() + .map_or(50, |cfg| cfg.query_packets_chunk_size()); + self.relay_packet_messages( sequences, query_height, + chunk_size, query_write_ack_events, TrackingId::new_static("packet-ack"), ) @@ -175,6 +189,7 @@ impl Link { &self, sequences: Vec, query_height: Qualified, + chunk_size: usize, query_fn: QueryFn, tracking_id: TrackingId, ) -> Result, LinkError> @@ -191,6 +206,7 @@ impl Link { query_height, self.a_to_b.src_chain(), &self.a_to_b.path_id, + chunk_size, query_fn, );