Skip to content

Commit b8343f3

Browse files
committed
Inner txs success now takes masp fee payment into account
1 parent f0a3426 commit b8343f3

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

shared/src/block_result.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ impl TxAttributesType {
336336
.unwrap_or_default(),
337337
info: attributes.get("info").unwrap().to_owned(),
338338
})),
339-
// FIXME: need a migration?
340339
EventKind::MaspFeePayment => {
341340
let data = attributes
342341
.get("section")
@@ -547,7 +546,7 @@ impl BlockResult {
547546
exit_status.unwrap_or(TransactionExitStatus::Rejected)
548547
}
549548

550-
pub fn masp_ref(&self, indexed_tx: &IndexedTx) -> Option<MaspRef> {
549+
pub fn masp_ref(&self, indexed_tx: &IndexedTx) -> Option<(MaspRef, bool)> {
551550
self.end_events
552551
.iter()
553552
.find_map(|event| match event.kind {
@@ -556,7 +555,7 @@ impl BlockResult {
556555
TxAttributesType::MaspFeePayment(data)
557556
if &data.indexed_tx == indexed_tx =>
558557
{
559-
Some(data)
558+
Some((data.data.to_owned(), true))
560559
}
561560
_ => None,
562561
})
@@ -566,15 +565,14 @@ impl BlockResult {
566565
TxAttributesType::MaspTransfer(data)
567566
if &data.indexed_tx == indexed_tx =>
568567
{
569-
Some(data)
568+
Some((data.data.to_owned(), false))
570569
}
571570
_ => None,
572571
})
573572
}
574573
_ => None,
575574
})
576575
.flatten()
577-
.map(|data| data.data.to_owned())
578576
}
579577
}
580578

shared/src/transaction.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ pub struct InnerTransaction {
321321
pub data: Option<String>,
322322
pub extra_sections: HashMap<Id, Vec<u8>>,
323323
pub notes: u64,
324+
// FIXME: should this be on the wrapper?
325+
pub is_masp_fee_payment: bool,
324326
pub exit_code: TransactionExitStatus,
325327
}
326328

@@ -330,10 +332,12 @@ impl InnerTransaction {
330332
}
331333

332334
/// An inner transaction is successful only if both the inner tx itself and
333-
/// the containing wrapper are marked as applied
335+
/// the containing wrapper are marked as applied or, in case of a failing
336+
/// atomic batch, if the inner tx was applied and did masp fee payment
334337
pub fn was_successful(&self, wrapper_tx: &WrapperTransaction) -> bool {
335-
wrapper_tx.exit_code == TransactionExitStatus::Applied
336-
&& self.exit_code == TransactionExitStatus::Applied
338+
self.exit_code == TransactionExitStatus::Applied
339+
&& (wrapper_tx.exit_code == TransactionExitStatus::Applied
340+
|| self.is_masp_fee_payment)
337341
}
338342

339343
pub fn is_ibc(&self) -> bool {
@@ -503,20 +507,8 @@ impl Transaction {
503507
};
504508
let masp_ref_opt = block_results.masp_ref(&indexed_tx);
505509

506-
// FIXME: here and in other places take into account masp
507-
// fee payment for failed atomic batches
508-
// FIXME: probably better to rework the was_successful
509-
// function and call that one here
510-
// MASP events are emitted only for successful inner txs
511-
let masp_bundle = matches!(
512-
(&wrapper_tx_status, &inner_tx_status),
513-
(
514-
&TransactionExitStatus::Applied,
515-
&TransactionExitStatus::Applied
516-
)
517-
)
518-
.then(|| {
519-
masp_ref_opt.map(|masp_ref| {
510+
let masp_bundle =
511+
masp_ref_opt.map(|(masp_ref, is_masp_fee_payment)| {
520512
// Cast the ref to the appropriate type
521513
let masp_tx_ref = match masp_ref {
522514
crate::block_result::MaspRef::MaspSection(
@@ -527,18 +519,29 @@ impl Transaction {
527519
}
528520
};
529521

530-
extract_masp_transaction(&transaction, &masp_tx_ref)
531-
})
532-
})
533-
.flatten();
534-
535-
let notes = masp_bundle.map_or(0, |bundle| {
536-
bundle.sapling_bundle().map_or(0, |bundle| {
537-
bundle.shielded_spends.len()
538-
+ bundle.shielded_outputs.len()
539-
+ bundle.shielded_converts.len()
540-
})
541-
}) as u64;
522+
(
523+
extract_masp_transaction(
524+
&transaction,
525+
&masp_tx_ref,
526+
),
527+
is_masp_fee_payment,
528+
)
529+
});
530+
531+
let (notes, is_masp_fee_payment) = masp_bundle.map_or(
532+
(0, false),
533+
|(bundle, is_masp_fee_payment)| {
534+
(
535+
bundle.sapling_bundle().map_or(0, |bundle| {
536+
(bundle.shielded_spends.len()
537+
+ bundle.shielded_outputs.len()
538+
+ bundle.shielded_converts.len())
539+
as u64
540+
}),
541+
is_masp_fee_payment,
542+
)
543+
},
544+
);
542545

543546
let inner_tx = InnerTransaction {
544547
tx_id: inner_tx_id,
@@ -550,6 +553,7 @@ impl Transaction {
550553
notes,
551554
exit_code: inner_tx_status,
552555
kind: tx_kind,
556+
is_masp_fee_payment,
553557
};
554558

555559
inner_txs.push(inner_tx);

0 commit comments

Comments
 (0)