Skip to content

Commit

Permalink
Adds a new tx event attribute to index masp txs
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Jan 4, 2024
1 parent 3607c39 commit c2acfec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ where
},
};

let mut is_committed_fee_unshield = false;
match protocol::dispatch_tx(
tx,
processed_tx.tx.as_ref(),
Expand All @@ -408,6 +409,7 @@ where
&mut self.vp_wasm_cache,
&mut self.tx_wasm_cache,
Some(&native_block_proposer_address),
&mut is_committed_fee_unshield,
)
.map_err(Error::TxApply)
{
Expand All @@ -419,6 +421,9 @@ where
"Wrapper transaction {} was accepted",
tx_event["hash"]
);
if is_committed_fee_unshield {
tx_event["is_valid_masp_tx"] = String::new();
}
self.wl_storage.storage.tx_queue.push(TxInQueue {
tx: wrapper.expect("Missing expected wrapper"),
gas: tx_gas_meter.get_available_gas(),
Expand All @@ -430,6 +435,13 @@ where
tx_event["hash"],
result
);
if result.vps_result.accepted_vps.contains(
&Address::Internal(
address::InternalAddress::Masp,
),
) {
tx_event["is_valid_masp_tx"] = String::new();
}
changed_keys
.extend(result.changed_keys.iter().cloned());
stats.increment_successful_txs();
Expand Down Expand Up @@ -500,7 +512,7 @@ where
msg
);

// If transaction type is Decrypted and didn't failed
// If transaction type is Decrypted and didn't fail
// because of out of gas nor invalid
// section commitment, commit its hash to prevent replays
if let Some(wrapper) = embedding_wrapper {
Expand Down Expand Up @@ -540,6 +552,11 @@ where
if let EventType::Accepted = tx_event.event_type {
// If wrapper, invalid tx error code
tx_event["code"] = ResultCode::InvalidTx.into();
// The fee unshield operation could still have been
// committed
if is_committed_fee_unshield {
tx_event["is_valid_masp_tx"] = String::new();
}
} else {
tx_event["code"] = ResultCode::WasmRuntimeError.into();
}
Expand Down
6 changes: 6 additions & 0 deletions shared/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ pub fn dispatch_tx<'a, D, H, CA>(
wl_storage: &'a mut WlStorage<D, H>,
vp_wasm_cache: &'a mut VpCache<CA>,
tx_wasm_cache: &'a mut TxCache<CA>,
// FIXME: these two params together because they are only needed for
// wrappers
block_proposer: Option<&'a Address>,
is_committed_fee_unshield: &mut bool,
) -> Result<TxResult>
where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
Expand Down Expand Up @@ -187,6 +190,7 @@ where
tx_wasm_cache,
},
block_proposer,
is_committed_fee_unshield,
)?;
Ok(TxResult {
gas_used: tx_gas_meter.get_tx_consumed_gas(),
Expand Down Expand Up @@ -232,6 +236,7 @@ pub(crate) fn apply_wrapper_tx<'a, D, H, CA, WLS>(
tx_bytes: &[u8],
mut shell_params: ShellParams<'a, CA, WLS>,
block_proposer: Option<&Address>,
is_committed_fee_unshield: &mut bool,
) -> Result<BTreeSet<Key>>
where
CA: 'static + WasmCacheAccess + Sync,
Expand All @@ -255,6 +260,7 @@ where
block_proposer,
&mut changed_keys,
)?;
*is_committed_fee_unshield = true;

// Account for gas
shell_params
Expand Down

0 comments on commit c2acfec

Please sign in to comment.