@@ -30,7 +30,7 @@ use namada_sdk::tx::data::{
3030 BatchedTxResult , TxResult , VpStatusFlags , VpsResult , WrapperTx ,
3131 compute_inner_tx_hash,
3232} ;
33- use namada_sdk:: tx:: event:: { MaspEvent , MaspEventKind , MaspTxRef } ;
33+ use namada_sdk:: tx:: event:: { FmdSectionRef , MaspEvent , MaspTxKind , MaspTxRef } ;
3434use namada_sdk:: tx:: { BatchedTxRef , IndexedTx , Tx , TxCommitments } ;
3535use namada_sdk:: validation:: {
3636 EthBridgeNutVp , EthBridgePoolVp , EthBridgeVp , GovernanceVp , IbcVp , MaspVp ,
@@ -395,38 +395,32 @@ where
395395 Ok ( mut batched_tx_result) if batched_tx_result. is_accepted ( ) => {
396396 // If the transaction was a masp one generate the
397397 // appropriate event
398- if let Some ( masp_ref) = get_optional_masp_ref (
398+ if let Some ( ( masp_ref, fmd_ref ) ) = get_optional_masp_refs (
399399 state,
400400 cmt,
401401 Either :: Right ( & batched_tx_result) ,
402402 )
403403 . map_err ( |e| Box :: new ( DispatchError :: from ( e) ) ) ?
404404 {
405- let inner_tx_hash =
406- compute_inner_tx_hash ( wrapper_hash, Either :: Right ( cmt) ) ;
407- batched_tx_result. events . insert (
408- MaspEvent {
409- tx_index : IndexedTx {
410- block_height : height,
411- block_index : tx_index,
412- batch_index : tx
413- . header
414- . batch
415- . get_index_of ( cmt)
416- . map ( |idx| {
417- TxIndex :: must_from_usize ( idx) . into ( )
418- } ) ,
419- } ,
420- kind : MaspEventKind :: Transfer ,
421- data : masp_ref,
422- }
423- . with ( TxHashAttr (
424- // Zero hash if the wrapper is not provided
425- // (governance proposal)
426- wrapper_hash. cloned ( ) . unwrap_or_default ( ) ,
427- ) )
428- . with ( InnerTxHashAttr ( inner_tx_hash) )
429- . into ( ) ,
405+ insert_masp_events (
406+ & mut batched_tx_result,
407+ // Zero hash if the wrapper is not provided
408+ // (governance proposal)
409+ TxHashAttr ( wrapper_hash. cloned ( ) . unwrap_or_default ( ) ) ,
410+ InnerTxHashAttr ( compute_inner_tx_hash (
411+ wrapper_hash,
412+ Either :: Right ( cmt) ,
413+ ) ) ,
414+ IndexedTx {
415+ block_height : height,
416+ block_index : tx_index,
417+ batch_index : tx. header . batch . get_index_of ( cmt) . map (
418+ |idx| TxIndex :: must_from_usize ( idx) . into ( ) ,
419+ ) ,
420+ } ,
421+ MaspTxKind :: Transfer ,
422+ masp_ref,
423+ fmd_ref,
430424 ) ;
431425 }
432426
@@ -467,6 +461,7 @@ where
467461pub struct MaspTxResult {
468462 tx_result : BatchedTxResult ,
469463 masp_section_ref : MaspTxRef ,
464+ fmd_section_ref : FmdSectionRef ,
470465}
471466
472467/// Performs the required operation on a wrapper transaction:
@@ -526,22 +521,21 @@ where
526521 let first_commitments = tx. first_commitments ( ) . unwrap ( ) ;
527522 let mut batch = TxResult :: default ( ) ;
528523 // Generate Masp event if needed
529- masp_tx_result. tx_result . events . insert (
530- MaspEvent {
531- tx_index : IndexedTx {
532- block_height : height,
533- block_index : tx_index. to_owned ( ) ,
534- batch_index : Some ( 0 ) ,
535- } ,
536- kind : MaspEventKind :: FeePayment ,
537- data : masp_tx_result. masp_section_ref ,
538- }
539- . with ( TxHashAttr ( tx. header_hash ( ) ) )
540- . with ( InnerTxHashAttr ( compute_inner_tx_hash (
524+ insert_masp_events (
525+ & mut masp_tx_result. tx_result ,
526+ TxHashAttr ( tx. header_hash ( ) ) ,
527+ InnerTxHashAttr ( compute_inner_tx_hash (
541528 tx. wrapper_hash ( ) . as_ref ( ) ,
542529 Either :: Right ( first_commitments) ,
543- ) ) )
544- . into ( ) ,
530+ ) ) ,
531+ IndexedTx {
532+ block_height : height,
533+ block_index : tx_index. to_owned ( ) ,
534+ batch_index : Some ( 0 ) ,
535+ } ,
536+ MaspTxKind :: FeePayment ,
537+ masp_tx_result. masp_section_ref ,
538+ masp_tx_result. fmd_section_ref ,
545539 ) ;
546540
547541 batch. insert_inner_tx_result (
@@ -839,20 +833,22 @@ where
839833 // Ensure that the transaction is actually a masp one, otherwise
840834 // reject
841835 if is_masp_transfer && result. is_accepted ( ) {
842- let masp_section_ref = get_optional_masp_ref (
843- * state,
844- first_tx. cmt ,
845- Either :: Left ( true ) ,
846- ) ?
847- . ok_or_else ( || {
848- Error :: FeeError (
849- "Missing expected masp section reference"
850- . to_string ( ) ,
851- )
852- } ) ?;
836+ let ( masp_section_ref, fmd_section_ref) =
837+ get_optional_masp_refs (
838+ * state,
839+ first_tx. cmt ,
840+ Either :: Left ( true ) ,
841+ ) ?
842+ . ok_or_else ( || {
843+ Error :: FeeError (
844+ "Missing expected masp section reference"
845+ . to_string ( ) ,
846+ )
847+ } ) ?;
853848 MaspTxResult {
854849 tx_result : result,
855850 masp_section_ref,
851+ fmd_section_ref,
856852 }
857853 } else {
858854 state. write_log_mut ( ) . drop_tx ( ) ;
@@ -893,11 +889,11 @@ where
893889// messing up with indexers/clients. Also a transaction can only be of one of
894890// the two types, not both at the same time (the MASP VP accepts a single
895891// Transaction)
896- fn get_optional_masp_ref < S : Read < Err = state:: Error > > (
892+ fn get_optional_masp_refs < S : Read < Err = state:: Error > > (
897893 state : & S ,
898894 cmt : & TxCommitments ,
899895 is_masp_tx : Either < bool , & BatchedTxResult > ,
900- ) -> Result < Option < MaspTxRef > > {
896+ ) -> Result < Option < ( MaspTxRef , FmdSectionRef ) > > {
901897 // Always check that the transaction was indeed a MASP one by looking at the
902898 // changed keys. A malicious tx could push a MASP Action without touching
903899 // any storage keys associated with the shielded pool
@@ -912,14 +908,27 @@ fn get_optional_masp_ref<S: Read<Err = state::Error>>(
912908 let masp_ref = if action:: is_ibc_shielding_transfer ( state)
913909 . map_err ( Error :: StateError ) ?
914910 {
915- Some ( MaspTxRef :: IbcData ( cmt. data_sechash ( ) . to_owned ( ) ) )
911+ let ibc_data = cmt. data_sechash ( ) . to_owned ( ) ;
912+
913+ Some ( (
914+ MaspTxRef :: IbcData ( ibc_data) ,
915+ FmdSectionRef :: IbcData ( ibc_data) ,
916+ ) )
916917 } else {
917918 let actions = state. read_actions ( ) . map_err ( Error :: StateError ) ?;
918- action:: get_masp_section_ref ( & actions)
919+
920+ let masp_tx = action:: get_masp_section_ref ( & actions)
921+ . map_err ( |msg| {
922+ Error :: StateError ( state:: Error :: new_alloc ( msg. to_string ( ) ) )
923+ } ) ?
924+ . map ( MaspTxRef :: MaspSection ) ;
925+ let fmd_sechash = action:: get_fmd_flag_ciphertexts_ref ( & actions)
919926 . map_err ( |msg| {
920927 Error :: StateError ( state:: Error :: new_alloc ( msg. to_string ( ) ) )
921928 } ) ?
922- . map ( MaspTxRef :: MaspSection )
929+ . map ( FmdSectionRef :: FmdSection ) ;
930+
931+ masp_tx. zip ( fmd_sechash)
923932 } ;
924933
925934 Ok ( masp_ref)
@@ -1499,6 +1508,35 @@ fn merge_vp_results(
14991508 ) )
15001509}
15011510
1511+ /// Insert MASP event data into the provided [`BatchedTxResult`].
1512+ fn insert_masp_events (
1513+ batched_tx_result : & mut BatchedTxResult ,
1514+ wrapper_tx_hash : TxHashAttr ,
1515+ inner_tx_hash : InnerTxHashAttr ,
1516+ tx_index : IndexedTx ,
1517+ masp_tx_kind : MaspTxKind ,
1518+ masp_tx_ref : MaspTxRef ,
1519+ fmd_ref : FmdSectionRef ,
1520+ ) {
1521+ batched_tx_result. events . extend ( [
1522+ MaspEvent :: ShieldedOutput {
1523+ tx_index,
1524+ kind : masp_tx_kind,
1525+ data : masp_tx_ref,
1526+ }
1527+ . with ( TxHashAttr ( wrapper_tx_hash. 0 ) )
1528+ . with ( InnerTxHashAttr ( inner_tx_hash. 0 ) )
1529+ . into ( ) ,
1530+ MaspEvent :: FlagCiphertexts {
1531+ tx_index,
1532+ section : fmd_ref,
1533+ }
1534+ . with ( TxHashAttr ( wrapper_tx_hash. 0 ) )
1535+ . with ( InnerTxHashAttr ( inner_tx_hash. 0 ) )
1536+ . into ( ) ,
1537+ ] ) ;
1538+ }
1539+
15021540#[ cfg( test) ]
15031541mod tests {
15041542 use eyre:: Result ;
0 commit comments