Skip to content

Commit

Permalink
check ibc masp action
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Jul 10, 2024
1 parent f563af1 commit 45d2798
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions crates/events/src/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
40 changes: 26 additions & 14 deletions crates/namada/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -2403,7 +2403,7 @@ async fn get_indexed_masp_events_at_height<C: Client + Sync>(
)
.ok();
let ibc_tx_data_refs =
IbcTxBatchRefsAttr::read_from_event_attributes(
IbcMaspTxBatchRefsAttr::read_from_event_attributes(
&event.attributes,
)
.ok();
Expand Down

0 comments on commit 45d2798

Please sign in to comment.