From 45d27984250960c9ac2540e9204990f14f161ba2 Mon Sep 17 00:00:00 2001 From: yito88 Date: Wed, 10 Jul 2024 21:47:03 +0200 Subject: [PATCH] check ibc masp action --- crates/events/src/extend.rs | 4 +-- crates/namada/src/ledger/protocol/mod.rs | 40 +++++++++++++++--------- crates/node/src/shell/finalize_block.rs | 4 +-- crates/sdk/src/masp.rs | 4 +-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/crates/events/src/extend.rs b/crates/events/src/extend.rs index 83a9834c2e..ea68e4cb65 100644 --- a/crates/events/src/extend.rs +++ b/crates/events/src/extend.rs @@ -519,9 +519,9 @@ impl EventAttributeEntry<'static> for MaspTxBatchRefs { } /// Extend an [`Event`] with data sections for IBC shielding transfer. -pub struct IbcTxBatchRefs(pub IbcTxDataRefs); +pub struct IbcMaspTxBatchRefs(pub IbcTxDataRefs); -impl EventAttributeEntry<'static> for IbcTxBatchRefs { +impl EventAttributeEntry<'static> for IbcMaspTxBatchRefs { type Value = IbcTxDataRefs; type ValueOwned = Self::Value; diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index b6ac832058..ca97c62f87 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -18,7 +18,7 @@ use namada_parameters::get_gas_scale; use namada_state::TxWrites; use namada_token::event::{TokenEvent, TokenOperation}; use namada_token::utils::is_masp_transfer; -use namada_tx::action::Read; +use namada_tx::action::{is_ibc_shielding_transfer, Read}; use namada_tx::data::protocol::{ProtocolTx, ProtocolTxType}; use namada_tx::data::{ BatchResults, BatchedTxResult, ExtendedTxResult, TxResult, VpStatusFlags, @@ -431,7 +431,7 @@ where .0 .push(masp_section_ref); } - if namada_tx::action::is_ibc_shielding_transfer(state) + if is_ibc_shielding_transfer(&*state) .map_err(Error::StateError)? { extended_tx_result @@ -765,20 +765,32 @@ where ); } - let masp_section_ref = - match namada_tx::action::get_masp_section_ref(*state) - .map_err(Error::StateError)? - { - Some(masp_tx_id) => Either::Left(masp_tx_id), - None => Either::Right(*first_tx.cmt.data_sechash()), - }; // Ensure that the transaction is actually a masp one, otherwise // reject - (is_masp_transfer(&result.changed_keys) && result.is_accepted()) - .then_some(MaspTxResult { - tx_result: result, - masp_section_ref, - }) + if is_masp_transfer(&result.changed_keys) + && result.is_accepted() + { + if let Some(masp_tx_id) = + namada_tx::action::get_masp_section_ref(*state) + .map_err(Error::StateError)? + { + Some(MaspTxResult { + tx_result: result, + masp_section_ref: Either::Left(masp_tx_id), + }) + } else { + is_ibc_shielding_transfer(*state) + .map_err(Error::StateError)? + .then_some(MaspTxResult { + tx_result: result, + masp_section_ref: Either::Right( + *first_tx.cmt.data_sechash(), + ), + }) + } + } else { + None + } } Err(e) => { state.write_log_mut().drop_tx(); diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 20fa39460b..be5c6ea7c3 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -9,7 +9,7 @@ use namada::gas::event::GasUsed; use namada::governance::pgf::inflation as pgf_inflation; use namada::hash::Hash; use namada::ledger::events::extend::{ - ComposeEvent, Height, IbcTxBatchRefs, Info, MaspTxBatchRefs, + ComposeEvent, Height, IbcMaspTxBatchRefs, Info, MaspTxBatchRefs, MaspTxBlockIndex, TxHash, }; use namada::ledger::events::EmitEvents; @@ -1060,7 +1060,7 @@ impl<'finalize> TempTxLogs { if !extended_tx_result.ibc_tx_data_refs.0.is_empty() { self.tx_event .extend(MaspTxBlockIndex(TxIndex::must_from_usize(tx_index))); - self.tx_event.extend(IbcTxBatchRefs( + self.tx_event.extend(IbcMaspTxBatchRefs( extended_tx_result.ibc_tx_data_refs.clone(), )); } diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index a943fbf9b0..c6e5dda719 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -49,7 +49,7 @@ use namada_core::storage::{BlockHeight, TxIndex}; use namada_core::time::DateTimeUtc; use namada_core::uint::Uint; use namada_events::extend::{ - IbcTxBatchRefs as IbcTxBatchRefsAttr, + IbcMaspTxBatchRefs as IbcMaspTxBatchRefsAttr, MaspTxBatchRefs as MaspTxBatchRefsAttr, MaspTxBlockIndex as MaspTxBlockIndexAttr, ReadFromEventAttributes, }; @@ -2403,7 +2403,7 @@ async fn get_indexed_masp_events_at_height( ) .ok(); let ibc_tx_data_refs = - IbcTxBatchRefsAttr::read_from_event_attributes( + IbcMaspTxBatchRefsAttr::read_from_event_attributes( &event.attributes, ) .ok();