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

N-ary Test Chains Support #1572

Merged
merged 53 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4fa47e2
Implement N-ary chain test support
soareschen Nov 16, 2021
edc6eaf
Add binary connection test traits
soareschen Nov 19, 2021
bebcc4e
Refactor and share code between N-ary and binary constructs
soareschen Nov 19, 2021
8afb7a5
Add bootstrap N-ary connections code
soareschen Nov 19, 2021
8027f68
Add N-ary connection test traits
soareschen Nov 19, 2021
e2376a5
Remove "experimental" feature flag for N-ary modules
soareschen Nov 19, 2021
b6cbac8
Merge branch 'master' into soares/nary-test-chains
soareschen Feb 11, 2022
efec63e
Propagate bootstrap_with_random_ids flag
soareschen Feb 11, 2022
b8ddb27
Increase timeout limit for assert_eventual_wallet_amount
soareschen Feb 14, 2022
fa89b10
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Feb 14, 2022
e003706
Add N-ary self connected chains test
soareschen Feb 14, 2022
a8cc330
Fix cargo doc
soareschen Feb 14, 2022
ed9a154
Adding documentation for N-ary constructs
soareschen Feb 14, 2022
106e776
Add more documentation
soareschen Feb 15, 2022
8de8469
Add CI workflow to publish cargo doc
soareschen Feb 15, 2022
98e531c
Merge branch 'master' into soares/nary-test-chains
soareschen Feb 15, 2022
3fbf9df
Add documentation for array utilities
soareschen Feb 15, 2022
31c5d4a
Publish cargo doc only on master
soareschen Feb 15, 2022
8c1ecb6
Remove stale code
soareschen Feb 15, 2022
0da8a2f
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Feb 16, 2022
5de1f47
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Feb 16, 2022
004578d
Add should_spawn_supervisor() method in TestOverrides
soareschen Feb 16, 2022
3c9c3b2
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Feb 17, 2022
138beb1
Merge branch 'master' into soares/nary-test-chains
soareschen Feb 18, 2022
ba64161
Fix errors from merge
soareschen Feb 18, 2022
ac50eed
Test deploy cargo doc
soareschen Feb 18, 2022
1958d6a
WIP Ternary IBC transfer test
soareschen Feb 18, 2022
ee3c80d
Require tests to spawn supervisor explicitly
soareschen Feb 18, 2022
7e1fcd5
2-hop IBC transfer test is now working
soareschen Feb 18, 2022
0c46810
Full ternary transfer test is now working
soareschen Feb 18, 2022
d232524
Fix supervisor test
soareschen Feb 18, 2022
ac0344e
Merge branch 'master' into soares/nary-test-chains
soareschen Feb 21, 2022
4c5a328
Trying to find the correct syntax for GitHub publish condition
soareschen Feb 21, 2022
7fcda10
Refactor N-ary foreign client pairs
soareschen Feb 22, 2022
85c524e
Introduce ForeignClientPair
soareschen Feb 22, 2022
ba088dd
Fix publish docs CI
soareschen Feb 22, 2022
3ebac23
Refactor self connected chain tests to single node test
soareschen Feb 23, 2022
a12bf23
Refine N-ary constructs naming
soareschen Feb 24, 2022
bb69bc6
Update Rust to 1.59.0
soareschen Feb 24, 2022
54ceaa8
Place const generics parameters at the front of N-ary constructs
soareschen Feb 24, 2022
af8e0d6
Merge branch 'master' into soares/nary-test-chains
soareschen Mar 2, 2022
a6148a2
Fix unordered test CI
soareschen Mar 2, 2022
59b3269
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Mar 7, 2022
b7961ac
Fix conflict error
soareschen Mar 7, 2022
af668ff
Fix cargo doc
soareschen Mar 9, 2022
3d7ae6f
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Mar 9, 2022
33d260e
Add some documentation
soareschen Mar 9, 2022
4ed1427
Introduce ConnectionDelayOverride
soareschen Mar 11, 2022
1cf90e8
Simplify spawning of refresh client tasks
soareschen Mar 11, 2022
d5c649a
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Mar 11, 2022
6d50583
Merge remote-tracking branch 'origin/master' into soares/nary-test-ch…
soareschen Mar 14, 2022
2d54740
Add some documentation
soareschen Mar 14, 2022
e67fcb7
Revert publish doc step to master even though it is still not working
soareschen Mar 14, 2022
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
12 changes: 12 additions & 0 deletions relayer/src/foreign_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,18 @@ impl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcCh
},
}
}

pub fn map_chain<DstChain2: ChainHandle, SrcChain2: ChainHandle>(
self,
map_dst: impl Fn(DstChain) -> DstChain2,
map_src: impl Fn(SrcChain) -> SrcChain2,
) -> ForeignClient<DstChain2, SrcChain2> {
ForeignClient {
id: self.id,
dst_chain: map_dst(self.dst_chain),
src_chain: map_src(self.src_chain),
}
}
}

#[derive(Clone, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl BinaryChannelTest for Test {
fn run<ChainA: ChainHandle, ChainB: ChainHandle>(
&self,
_config: &TestConfig,
_relayer: RelayerDriver,
_chains: ConnectedChains<ChainA, ChainB>,
_channel: ConnectedChannel<ChainA, ChainB>,
) -> Result<(), Error> {
Expand Down
35 changes: 28 additions & 7 deletions tools/integration-test/src/bootstrap/binary/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::Arc;
use std::sync::RwLock;
use tracing::{debug, info};

use crate::relayer::driver::RelayerDriver;
use crate::types::binary::chains::ConnectedChains;
use crate::types::config::TestConfig;
use crate::types::single::node::FullNode;
Expand All @@ -35,7 +36,13 @@ pub fn boostrap_chain_pair_with_nodes(
node_a: FullNode,
node_b: FullNode,
config_modifier: impl FnOnce(&mut Config),
) -> Result<ConnectedChains<impl ChainHandle, impl ChainHandle>, Error> {
) -> Result<
(
RelayerDriver,
ConnectedChains<impl ChainHandle, impl ChainHandle>,
),
Error,
> {
let mut config = Config::default();

add_chain_config(&mut config, &node_a)?;
Expand Down Expand Up @@ -65,10 +72,13 @@ pub fn boostrap_chain_pair_with_nodes(
let client_a_to_b = bootstrap_foreign_client(&handle_a, &handle_b)?;
let client_b_to_a = bootstrap_foreign_client(&handle_b, &handle_a)?;

let chains = ConnectedChains::new(
let relayer = RelayerDriver {
config_path,
config,
registry,
};

let chains = ConnectedChains::new(
handle_a,
handle_b,
MonoTagged::new(node_a),
Expand All @@ -77,7 +87,7 @@ pub fn boostrap_chain_pair_with_nodes(
client_b_to_a,
);

Ok(chains)
Ok((relayer, chains))
}

/**
Expand All @@ -96,7 +106,13 @@ pub fn boostrap_self_connected_chain(
test_config: &TestConfig,
node: FullNode,
config_modifier: impl FnOnce(&mut Config),
) -> Result<ConnectedChains<impl ChainHandle, impl ChainHandle>, Error> {
) -> Result<
(
RelayerDriver,
ConnectedChains<impl ChainHandle, impl ChainHandle>,
),
Error,
> {
let mut config = Config::default();

add_chain_config(&mut config, &node)?;
Expand All @@ -115,17 +131,22 @@ pub fn boostrap_self_connected_chain(

let foreign_client = bootstrap_foreign_client(&handle, &handle)?;

Ok(ConnectedChains::new(
let relayer = RelayerDriver {
config_path,
config,
registry,
};

let chains = ConnectedChains::new(
handle.clone(),
handle,
MonoTagged::new(node.clone()),
MonoTagged::new(node),
foreign_client.clone(),
foreign_client,
))
);

Ok((relayer, chains))
}

pub fn pad_client_ids<ChainA: ChainHandle, ChainB: ChainHandle>(
Expand All @@ -148,7 +169,7 @@ pub fn pad_client_ids<ChainA: ChainHandle, ChainB: ChainHandle>(
client collects information from `ChainA` and submits them as transactions
to `ChainB`.

The returned `ForeignClient` is tagged in contravariant position, i.e.
The returned `ForeignClient` is tagged in contravariant ordering, i.e.
`ChainB` then `ChainB`, because `ForeignClient` takes the the destination
chain in the first position.
*/
Expand Down
1 change: 1 addition & 0 deletions tools/integration-test/src/bootstrap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

pub mod binary;
pub mod init;
pub mod nary;
pub mod single;
98 changes: 98 additions & 0 deletions tools/integration-test/src/bootstrap/nary/chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use core::convert::TryInto;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::config::Config;
use ibc_relayer::foreign_client::ForeignClient;
use ibc_relayer::registry::SharedRegistry;
use std::sync::Arc;
use std::sync::RwLock;

use crate::bootstrap::binary::chain::{
add_chain_config, add_keys_to_chain_handle, bootstrap_foreign_client, new_registry,
save_relayer_config,
};
use crate::error::{handle_generic_error, Error};
use crate::relayer::driver::RelayerDriver;
use crate::types::config::TestConfig;
use crate::types::nary::chains::{ConnectedChains, DynamicConnectedChains};
use crate::types::single::node::FullNode;

pub fn boostrap_chains_with_nodes<const SIZE: usize>(
test_config: &TestConfig,
full_nodes: [FullNode; SIZE],
config_modifier: impl FnOnce(&mut Config),
) -> Result<(RelayerDriver, ConnectedChains<impl ChainHandle, SIZE>), Error> {
let (relayer, chains) =
boostrap_chains_with_any_nodes(test_config, full_nodes.into(), config_modifier)?;

Ok((relayer, chains.try_into()?))
}

pub fn boostrap_chains_with_any_nodes(
test_config: &TestConfig,
full_nodes: Vec<FullNode>,
config_modifier: impl FnOnce(&mut Config),
) -> Result<(RelayerDriver, DynamicConnectedChains<impl ChainHandle>), Error> {
let mut config = Config::default();

for node in full_nodes.iter() {
add_chain_config(&mut config, node)?;
}

config_modifier(&mut config);

let config_path = test_config.chain_store_dir.join("relayer-config.toml");

save_relayer_config(&config, &config_path)?;

let config = Arc::new(RwLock::new(config));

let registry = new_registry(config.clone());

let mut chain_handles = Vec::new();

for node in full_nodes.iter() {
let handle = spawn_chain_handle(&registry, node)?;
chain_handles.push(handle);
}

let mut foreign_clients: Vec<Vec<ForeignClient<_, _>>> = Vec::new();

for handle_a in chain_handles.iter() {
let mut foreign_clients_b = Vec::new();

for handle_b in chain_handles.iter() {
let foreign_client = bootstrap_foreign_client(handle_a, handle_b)?;
foreign_clients_b.push(foreign_client);
}

foreign_clients.push(foreign_clients_b);
}

let relayer = RelayerDriver {
config_path,
config,
registry,
};

let connected_chains = DynamicConnectedChains {
chain_handles,
full_nodes,
foreign_clients,
};

Ok((relayer, connected_chains))
}

pub fn spawn_chain_handle<Handle: ChainHandle>(
registry: &SharedRegistry<Handle>,
node: &FullNode,
) -> Result<Handle, Error> {
let chain_id = &node.chain_driver.chain_id;
let handle = registry
.get_or_spawn(chain_id)
.map_err(handle_generic_error)?;

add_keys_to_chain_handle(&handle, &node.wallets)?;

Ok(handle)
}
107 changes: 107 additions & 0 deletions tools/integration-test/src/bootstrap/nary/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use core::convert::TryInto;
use ibc::core::ics24_host::identifier::PortId;
use ibc_relayer::chain::handle::ChainHandle;

use crate::bootstrap::binary::channel::bootstrap_channel_with_connection;
use crate::bootstrap::nary::connection::bootstrap_connections_dynamic;
use crate::error::{handle_generic_error, Error};
use crate::types::binary::channel::ConnectedChannel;
use crate::types::nary::chains::{ConnectedChains, DynamicConnectedChains};
use crate::types::nary::channel::{ConnectedChannels, DynamicConnectedChannels};
use crate::types::nary::connection::{ConnectedConnections, DynamicConnectedConnections};
use crate::types::tagged::*;
use crate::util::array::{assert_same_dimension, into_nested_vec};

pub fn bootstrap_channels_with_connections_dynamic<Handle: ChainHandle>(
connections: DynamicConnectedConnections<Handle>,
chains: &[Handle],
ports: &[Vec<PortId>],
bootstrap_with_random_ids: bool,
) -> Result<DynamicConnectedChannels<Handle>, Error> {
let size = chains.len();

assert_same_dimension(size, &connections.connections)?;
assert_same_dimension(size, ports)?;

let mut channels: Vec<Vec<ConnectedChannel<Handle, Handle>>> = Vec::new();

for (i, connections_b) in connections.connections.into_iter().enumerate() {
let mut channels_b: Vec<ConnectedChannel<Handle, Handle>> = Vec::new();

for (j, connection) in connections_b.into_iter().enumerate() {
if i <= j {
let chain_a = &chains[i];
let chain_b = &chains[j];

let port_a = &ports[i][j];
let port_b = &ports[j][i];

let channel = bootstrap_channel_with_connection(
chain_a,
chain_b,
connection,
&DualTagged::new(port_a),
&DualTagged::new(port_b),
bootstrap_with_random_ids,
)?;

channels_b.push(channel);
} else {
let counter_channel = &channels[j][i];
let channel = counter_channel.clone().flip();

channels_b.push(channel);
}
}

channels.push(channels_b);
}

Ok(DynamicConnectedChannels { channels })
}

pub fn bootstrap_channels_with_connections<Handle: ChainHandle, const SIZE: usize>(
connections: ConnectedConnections<Handle, SIZE>,
chains: &[Handle; SIZE],
ports: [[PortId; SIZE]; SIZE],
bootstrap_with_random_ids: bool,
) -> Result<ConnectedChannels<Handle, SIZE>, Error> {
let channels = bootstrap_channels_with_connections_dynamic(
connections.into(),
chains,
&into_nested_vec(ports),
bootstrap_with_random_ids,
)?;

channels.try_into().map_err(handle_generic_error)
}

pub fn bootstrap_channels_dynamic<Handle: ChainHandle>(
chains: &DynamicConnectedChains<Handle>,
ports: &[Vec<PortId>],
bootstrap_with_random_ids: bool,
) -> Result<DynamicConnectedChannels<Handle>, Error> {
let connections =
bootstrap_connections_dynamic(&chains.foreign_clients, bootstrap_with_random_ids)?;

bootstrap_channels_with_connections_dynamic(
connections,
&chains.chain_handles,
ports,
bootstrap_with_random_ids,
)
}

pub fn bootstrap_channels<Handle: ChainHandle, const SIZE: usize>(
chains: &ConnectedChains<Handle, SIZE>,
ports: [[PortId; SIZE]; SIZE],
bootstrap_with_random_ids: bool,
) -> Result<ConnectedChannels<Handle, SIZE>, Error> {
let channels = bootstrap_channels_dynamic(
&chains.clone().into(),
&into_nested_vec(ports),
bootstrap_with_random_ids,
)?;

channels.try_into()
}
59 changes: 59 additions & 0 deletions tools/integration-test/src/bootstrap/nary/connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use core::convert::TryInto;
use ibc_relayer::chain::handle::ChainHandle;
use ibc_relayer::foreign_client::ForeignClient;

use crate::bootstrap::binary::connection::bootstrap_connection;
use crate::error::Error;
use crate::types::binary::connection::ConnectedConnection;
use crate::types::nary::connection::{ConnectedConnections, DynamicConnectedConnections};
use crate::util::array::{assert_same_dimension, into_nested_vec};

pub fn bootstrap_connections_dynamic<Handle: ChainHandle>(
foreign_clients: &[Vec<ForeignClient<Handle, Handle>>],
bootstrap_with_random_ids: bool,
) -> Result<DynamicConnectedConnections<Handle>, Error> {
let size = foreign_clients.len();

assert_same_dimension(size, foreign_clients)?;

let mut connections: Vec<Vec<ConnectedConnection<Handle, Handle>>> = Vec::new();

for (i, foreign_clients_b) in foreign_clients.iter().enumerate() {
let mut connections_b: Vec<ConnectedConnection<Handle, Handle>> = Vec::new();

for (j, foreign_client) in foreign_clients_b.iter().enumerate() {
if i <= j {
let counter_foreign_client = &foreign_clients[j][i];

let connection = bootstrap_connection(
counter_foreign_client,
foreign_client,
bootstrap_with_random_ids,
)?;

connections_b.push(connection);
} else {
let counter_connection = &connections[j][i];
let connection = counter_connection.clone().flip();

connections_b.push(connection);
}
}

connections.push(connections_b);
}

Ok(DynamicConnectedConnections { connections })
}

pub fn bootstrap_connections<Handle: ChainHandle, const SIZE: usize>(
foreign_clients: [[ForeignClient<Handle, Handle>; SIZE]; SIZE],
bootstrap_with_random_ids: bool,
) -> Result<ConnectedConnections<Handle, SIZE>, Error> {
let connections = bootstrap_connections_dynamic(
&into_nested_vec(foreign_clients),
bootstrap_with_random_ids,
)?;

connections.try_into()
}
Loading