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

chore: fix create connection for axon chain #242

Merged
merged 3 commits into from
Jun 29, 2023
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
85 changes: 81 additions & 4 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,32 @@
))
})?;

let receipts: Receipts = self
let block = self
.rt
.block_on(self.client.get_block_receipts(block_number))
.block_on(self.client.get_block(block_number))
.map_err(|e| Error::rpc_response(e.to_string()))?
.into();
.ok_or_else(|| {
Error::other_error(format!("can't find block with number {}", block_number))
})?;

let tx_receipts = block
.transactions
.into_iter()
.map(|tx_hash| {
let receipt = self
.rt
.block_on(self.client.get_transaction_receipt(tx_hash));
match receipt {
Ok(Some(receipt)) => Ok(receipt),
Ok(None) => Err(Error::other_error(format!(
"can't find transaction receipt with hash {}",
hex::encode(tx_hash)
))),
Err(e) => Err(Error::rpc_response(e.to_string())),
}
})
.collect::<Result<Vec<_>, _>>()?;
let receipts: Receipts = tx_receipts.into();
let receipt_proof = receipts.generate_proof(receipt.transaction_index.as_usize());

let (block, state_root, proof, mut validators) = self
Expand Down Expand Up @@ -1014,6 +1035,61 @@

Ok((block, state_root, proof, validators))
}

fn cache_ics_tx_hash_with_event<T: Into<[u8; 32]>>(
&mut self,
event: IbcEvent,
tx_hash: T,
) -> Result<(), Error> {
let tx_hash_status = match event {
IbcEvent::OpenInitConnection(event) => Some(CacheTxHashStatus::new_with_conn(
event.0.connection_id.unwrap(),
)),
IbcEvent::OpenTryConnection(event) => Some(CacheTxHashStatus::new_with_conn(
event.0.connection_id.unwrap(),
)),
IbcEvent::OpenAckConnection(event) => Some(CacheTxHashStatus::new_with_conn(
event.0.connection_id.unwrap(),
)),
IbcEvent::OpenConfirmConnection(event) => Some(CacheTxHashStatus::new_with_conn(
event.0.connection_id.unwrap(),
)),
IbcEvent::OpenInitChannel(event) => Some(CacheTxHashStatus::new_with_chan(
event.channel_id.unwrap(),
event.port_id,
)),
IbcEvent::OpenTryChannel(event) => Some(CacheTxHashStatus::new_with_chan(
event.channel_id.unwrap(),
event.port_id,
)),
IbcEvent::OpenAckChannel(event) => Some(CacheTxHashStatus::new_with_chan(
event.channel_id.unwrap(),
event.port_id,
)),
IbcEvent::OpenConfirmChannel(event) => Some(CacheTxHashStatus::new_with_chan(
event.channel_id.unwrap(),
event.port_id,
)),
IbcEvent::SendPacket(event) => Some(CacheTxHashStatus::new_with_packet(
event.packet.source_channel,
event.packet.source_port,
event.packet.sequence.into(),
)),
IbcEvent::ReceivePacket(event) => Some(CacheTxHashStatus::new_with_packet(
event.packet.destination_channel,
event.packet.destination_port,
event.packet.sequence.into(),
)),
_ => None,
};
match tx_hash_status {
Some(tx_hash_status) => {
self.cache_ics_tx_hash(tx_hash_status, tx_hash)?;
}
None => {}
}

Check failure on line 1090 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> crates/relayer/src/chain/axon.rs:1085:9 | 1085 | / match tx_hash_status { 1086 | | Some(tx_hash_status) => { 1087 | | self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1088 | | } 1089 | | None => {} 1090 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match note: the lint level is defined here --> crates/relayer/src/lib.rs:3:5 | 3 | warnings, | ^^^^^^^^ = note: `#[deny(clippy::single_match)]` implied by `#[deny(warnings)]` help: try this | 1085 ~ if let Some(tx_hash_status) = tx_hash_status { 1086 + self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1087 + } |

Check failure on line 1090 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> crates/relayer/src/chain/axon.rs:1085:9 | 1085 | / match tx_hash_status { 1086 | | Some(tx_hash_status) => { 1087 | | self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1088 | | } 1089 | | None => {} 1090 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match note: the lint level is defined here --> crates/relayer/src/lib.rs:3:5 | 3 | warnings, | ^^^^^^^^ = note: `#[deny(clippy::single_match)]` implied by `#[deny(warnings)]` help: try this | 1085 ~ if let Some(tx_hash_status) = tx_hash_status { 1086 + self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1087 + } |

Check failure on line 1090 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> crates/relayer/src/chain/axon.rs:1085:9 | 1085 | / match tx_hash_status { 1086 | | Some(tx_hash_status) => { 1087 | | self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1088 | | } 1089 | | None => {} 1090 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match note: the lint level is defined here --> crates/relayer/src/lib.rs:3:5 | 3 | warnings, | ^^^^^^^^ = note: `#[deny(clippy::single_match)]` implied by `#[deny(warnings)]` help: try this | 1085 ~ if let Some(tx_hash_status) = tx_hash_status { 1086 + self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1087 + } |

Check failure on line 1090 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> crates/relayer/src/chain/axon.rs:1085:9 | 1085 | / match tx_hash_status { 1086 | | Some(tx_hash_status) => { 1087 | | self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1088 | | } 1089 | | None => {} 1090 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match note: the lint level is defined here --> crates/relayer/src/lib.rs:3:5 | 3 | warnings, | ^^^^^^^^ = note: `#[deny(clippy::single_match)]` implied by `#[deny(warnings)]` help: try this | 1085 ~ if let Some(tx_hash_status) = tx_hash_status { 1086 + self.cache_ics_tx_hash(tx_hash_status, tx_hash)?; 1087 + } |
Ok(())
}
}

impl AxonChain {
Expand Down Expand Up @@ -1199,7 +1275,7 @@
}
};
let tx_receipt = tx_receipt.ok_or(Error::send_tx(String::from("fail to send tx")))?;
let event = {
let event: IbcEvent = {
use contract::OwnableIBCHandlerEvents::*;
let mut events = tx_receipt
.logs
Expand Down Expand Up @@ -1274,6 +1350,7 @@
})?;
Height::new(u64::MAX, block_height.as_u64()).unwrap()
};
let _ = self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?;

Check failure on line 1353 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

this let-binding has unit value

error: this let-binding has unit value --> crates/relayer/src/chain/axon.rs:1353:9 | 1353 | let _ = self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[deny(clippy::let_unit_value)]` implied by `#[deny(warnings)]`

Check failure on line 1353 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

this let-binding has unit value

error: this let-binding has unit value --> crates/relayer/src/chain/axon.rs:1353:9 | 1353 | let _ = self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[deny(clippy::let_unit_value)]` implied by `#[deny(warnings)]`

Check failure on line 1353 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

this let-binding has unit value

error: this let-binding has unit value --> crates/relayer/src/chain/axon.rs:1353:9 | 1353 | let _ = self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[deny(clippy::let_unit_value)]` implied by `#[deny(warnings)]`

Check failure on line 1353 in crates/relayer/src/chain/axon.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

this let-binding has unit value

error: this let-binding has unit value --> crates/relayer/src/chain/axon.rs:1353:9 | 1353 | let _ = self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `self.cache_ics_tx_hash_with_event(event.clone(), tx_hash)?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[deny(clippy::let_unit_value)]` implied by `#[deny(warnings)]`
Ok(IbcEventWithHeight {
event,
height,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl ChainConfig {
ChainConfig::Cosmos(c) => c.max_block_time,
ChainConfig::Eth(_) => todo!(),
ChainConfig::Ckb(_) => todo!(),
ChainConfig::Axon(_) => todo!(),
ChainConfig::Axon(_) => Duration::from_secs(90),
ChainConfig::Ckb4Ibc(_) => Duration::from_secs(90),
}
}
Expand Down
Loading