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

Fix query_tx_events #7

Merged
merged 2 commits into from
Oct 11, 2023
Merged
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
50 changes: 16 additions & 34 deletions crates/relayer/src/chain/namada/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use ibc_relayer_types::core::ics23_commitment::merkle::convert_tm_to_ics_merkle_
use ibc_relayer_types::core::ics23_commitment::merkle::MerkleProof;
use ibc_relayer_types::events::IbcEvent;
use ibc_relayer_types::Height as ICSHeight;
use namada::ledger::events::EventType as NamadaEventType;
use namada::ledger::queries::RPC;
use namada::tendermint::block::Height as TmHeight;
use namada::tendermint_rpc::Client;
use namada::types::storage::{BlockHeight, Epoch, Key, PrefixValue};
use namada_apps::node::ledger::shell::ErrorCodes;
use tendermint::abci::{Event, EventAttribute};
use tendermint::merkle::proof::{ProofOp, ProofOps};

Expand Down Expand Up @@ -112,14 +112,6 @@ impl NamadaChain {

/// Get all IBC events when the tx has been applied
pub fn query_tx_events(&self, tx_hash: &str) -> Result<Vec<IbcEventWithHeight>, Error> {
match self.query_tx_height(tx_hash)? {
Some(height) => self.query_events(height),
None => Ok(vec![]),
}
}

/// Get the height at which the tx has been applied
fn query_tx_height(&self, tx_hash: &str) -> Result<Option<ICSHeight>, Error> {
match self
.rt
.block_on(RPC.shell().applied(
Expand All @@ -136,9 +128,20 @@ impl NamadaChain {
.map_err(|_| Error::invalid_height_no_source())?;
let height = ICSHeight::new(self.config.id.version(), h)
.map_err(|_| Error::invalid_height_no_source())?;
Ok(Some(height))
// Check if the tx is valid
let code = applied.get("code").expect("The code should exist");
if *code != String::from(ErrorCodes::Ok) {
return Ok(vec![IbcEventWithHeight::new(
IbcEvent::ChainError(format!(
"The transaction was invalid: Event {:?}",
applied,
)),
height,
)]);
}
self.query_events(height)
}
None => Ok(None),
None => Ok(vec![]),
}
}

Expand Down Expand Up @@ -242,29 +245,8 @@ impl NamadaChain {
let mut ibc_events = vec![];
for event in &events {
let event = into_abci_event(event);
match ibc_event_try_from_abci_event(&event) {
Ok(e) => ibc_events.push(IbcEventWithHeight::new(e, height)),
Err(_) => {
// check the transaction result
if event.kind == NamadaEventType::Applied.to_string() {
let success_code_tag = EventAttribute {
key: "code".to_string(),
value: "0".to_string(),
index: true,
};
if !event.attributes.contains(&success_code_tag) {
let ibc_event = IbcEventWithHeight::new(
IbcEvent::ChainError(format!(
"The transaction was invalid: Event {:?}",
event,
)),
height,
);
ibc_events.push(ibc_event);
}
}
// skip special ibc-rs events
}
if let Ok(ibc_event) = ibc_event_try_from_abci_event(&event) {
ibc_events.push(IbcEventWithHeight::new(ibc_event, height))
}
}
Ok(ibc_events)
Expand Down
Loading