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

implement AstriaEndpoint #1

Merged
merged 15 commits into from
Jan 17, 2024
2,421 changes: 2,185 additions & 236 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions config-astria-localnet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

[global]
log_level = 'debug'

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = false

[mode.connections]
enabled = true

[mode.channels]
enabled = true

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = true

[telemetry]
enabled = false
host = '127.0.0.1'
port = 3001

[[chains]]
id = 'astria'
type = 'Astria'
rpc_addr = 'http://localhost:26657'
grpc_addr = 'http://localhost:8080'
event_source = { mode = 'pull', interval = '1s' }
rpc_timeout = '15s'
account_prefix = 'fake' # not used
key_name = 'astria-wallet'
store_prefix = 'ibc-data'
gas_price = { price = 1, denom = 'nria' } # not used
max_gas = 10000000 # not used
clock_drift = '5s'
trusting_period = '2h' # this should be changed in the future
trust_threshold = { numerator = '1', denominator = '3' }

[[chains]]
id = 'ibc-0'
type = 'CosmosSdk'
rpc_addr = 'http://localhost:27050'
grpc_addr = 'http://localhost:9090'
event_source = { mode = 'push', url = 'ws://localhost:27050/websocket', batch_delay = '200ms' }
rpc_timeout = '15s'
trusted_node = true
account_prefix = 'osmo'
key_name = 'wallet'
store_prefix = 'ibc'
gas_price = { price = 0.0026, denom = 'stake' }
gas_multiplier = 1.2
default_gas = 1000000
max_gas = 10000000
max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '30s'
trusting_period = '14days'
trust_threshold = { numerator = '2', denominator = '3' }
memo_prefix = 'astriawashere'
18 changes: 9 additions & 9 deletions crates/relayer-cli/src/commands/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ impl Runnable for EvidenceCmd {
.exit()
});

if !matches!(chain_config, ChainConfig::CosmosSdk(_)) {
Output::error(format!(
"chain `{}` is not a Cosmos SDK chain",
self.chain_id
))
.exit();
}

if let Some(ref key_name) = self.key_name {
chain_config.set_key_name(key_name.to_string());
}
Expand All @@ -138,7 +130,15 @@ impl Runnable for EvidenceCmd {
.unwrap(),
);

let chain = CosmosSdkChain::bootstrap(chain_config, rt.clone()).unwrap();
let chain = match chain_config {
ChainConfig::Astria(_) => {
todo!("AstriaEndpoint::bootstrap");
}
ChainConfig::CosmosSdk(ref _cfg) => {
CosmosSdkChain::bootstrap(chain_config, rt.clone()).unwrap()
}
};

let res = monitor_misbehaviours(
rt,
&config,
Expand Down
38 changes: 38 additions & 0 deletions crates/relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ibc_relayer::{
},
keyring::{
AnySigningKeyPair,
Ed25519KeyPair,
KeyRing,
Secp256k1KeyPair,
SigningKeyPair,
Expand Down Expand Up @@ -232,6 +233,23 @@ pub fn add_key(
fs::read_to_string(file).map_err(|_| eyre!("error reading the key file"))?;
let key_pair = Secp256k1KeyPair::from_seed_file(&key_contents, hd_path)?;

keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
ChainConfig::Astria(config) => {
let mut keyring = KeyRing::new_ed25519(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;

check_key_exists(&keyring, key_name, overwrite);

let key_contents =
fs::read_to_string(file).map_err(|_| eyre!("error reading the key file"))?;
let key_pair = Ed25519KeyPair::from_seed_file(&key_contents, hd_path)?;

keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
Expand Down Expand Up @@ -268,6 +286,26 @@ pub fn restore_key(
keyring.account_prefix(),
)?;

keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
ChainConfig::Astria(config) => {
let mut keyring = KeyRing::new_ed25519(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;

check_key_exists(&keyring, key_name, overwrite);

let key_pair = Ed25519KeyPair::from_mnemonic(
&mnemonic_content,
hdpath,
&config.address_type,
keyring.account_prefix(),
)?;

keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
Expand Down
2 changes: 2 additions & 0 deletions crates/relayer-cli/src/commands/keys/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn get_balance(chain: impl ChainHandle, key_name: Option<String>, denom: Option<
let chain_config = chain.config().unwrap_or_else(exit_with_unrecoverable_error);
match chain_config {
ChainConfig::CosmosSdk(chain_config) => chain_config.key_name,
ChainConfig::Astria(chain_config) => chain_config.key_name,
}
});

Expand All @@ -110,6 +111,7 @@ fn get_balances(chain: impl ChainHandle, key_name: Option<String>) {
let chain_config = chain.config().unwrap_or_else(exit_with_unrecoverable_error);
match chain_config {
ChainConfig::CosmosSdk(chain_config) => chain_config.key_name,
ChainConfig::Astria(chain_config) => chain_config.key_name,
}
});

Expand Down
21 changes: 21 additions & 0 deletions crates/relayer-cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ pub fn delete_key(config: &ChainConfig, key_name: &str) -> eyre::Result<()> {
)?;
keyring.remove_key(key_name)?;
}
ChainConfig::Astria(config) => {
let mut keyring = KeyRing::new_ed25519(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;
keyring.remove_key(key_name)?;
}
}
Ok(())
}
Expand All @@ -151,6 +160,18 @@ pub fn delete_all_keys(config: &ChainConfig) -> eyre::Result<()> {
keyring.remove_key(&key_name)?;
}
}
ChainConfig::Astria(config) => {
let mut keyring = KeyRing::new_ed25519(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;
let keys = keyring.keys()?;
for (key_name, _) in keys {
keyring.remove_key(&key_name)?;
}
}
}
Ok(())
}
Expand Down
6 changes: 5 additions & 1 deletion crates/relayer-cli/src/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn subscribe(
// Q: Should this be restricted only to backends that support it,
// or are all backends expected to support subscriptions?
match chain_config {
ChainConfig::CosmosSdk(config) => {
ChainConfig::CosmosSdk(config) | ChainConfig::Astria(config) => {
let (event_source, monitor_tx) = match &config.event_source {
EventSourceMode::Push { url, batch_delay } => EventSource::websocket(
chain_config.id().clone(),
Expand Down Expand Up @@ -199,13 +199,17 @@ fn detect_compatibility_mode(
// TODO(erwan): move this to the cosmos sdk endpoint implementation
let rpc_addr = match config {
ChainConfig::CosmosSdk(config) => config.rpc_addr.clone(),
ChainConfig::Astria(config) => config.rpc_addr.clone(),
};
let client = HttpClient::new(rpc_addr)?;
let status = rt.block_on(client.status())?;
let compat_mode = match config {
ChainConfig::CosmosSdk(config) => {
compat_mode_from_version(&config.compat_mode, status.node_info.version)?.into()
}
ChainConfig::Astria(config) => {
compat_mode_from_version(&config.compat_mode, status.node_info.version)?.into()
}
};
Ok(compat_mode)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl Runnable for TxUpdateClientCmd {
if let Some(restart_params) = self.genesis_restart_params() {
match config.find_chain_mut(&reference_chain_id) {
Some(chain_config) => match chain_config {
ChainConfig::CosmosSdk(chain_config) => {
ChainConfig::CosmosSdk(chain_config) | ChainConfig::Astria(chain_config) => {
chain_config.genesis_restart = Some(restart_params)
}
},
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-rest/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type = 'CosmosSdk'
rpc_addr = 'http://127.0.0.1:26557'
grpc_addr = 'http://127.0.0.1:9091'
event_source = { mode = 'push', url = 'ws://127.0.0.1:26557/websocket', batch_delay = '500ms' }
rpc_timeout = '10s'
rpc_timeout = '60s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand Down
2 changes: 2 additions & 0 deletions crates/relayer-types/src/applications/transfer/msgs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod send;
pub mod transfer;

pub const ASTRIA_WITHDRAWAL_TYPE_URL: &str = "/astria.sequencer.v1alpha1.Ics20Withdrawal";
10 changes: 10 additions & 0 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ ibc-proto = { version = "0.39.0", features = ["serde"] }
ibc-telemetry = { version = "0.26.3", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.26.3", path = "../relayer-types", features = ["mocks"] }

# TODO: bump this after IBC PRs (specifically balance query) are merged
astria-core = { git = "https://github.com/astriaorg/astria", rev = "6ffbced612a7244ccea146db90c6cfb8c1aa7466" }
astria-sequencer-client = { git = "https://github.com/astriaorg/astria", rev = "6ffbced612a7244ccea146db90c6cfb8c1aa7466", features = [ "http" ] }
ed25519-consensus = "2.1.0"
ibc-types = "0.10.0"
jmt = "0.6"
penumbra-ibc = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.64.1", default-features = false }
penumbra-proto = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.64.1" }
pbjson-types = "0.6"

subtle-encoding = "0.5"
humantime-serde = "1.1.1"
serde = "1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/relayer/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod astria;
pub mod client;
pub mod cosmos;
pub mod counterparty;
Expand Down
Loading