Skip to content

Commit

Permalink
Provides a clean write log for unshielding tx in process_proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Apr 13, 2023
1 parent 9aac475 commit d11b061
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 15 additions & 6 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::collections::BTreeMap;

use namada::core::types::hash::Hash;
use namada::core::types::storage::Key;
use namada::ledger::storage::TempWlStorage;
use namada::types::internal::WrapperTxInQueue;

Expand Down Expand Up @@ -429,19 +430,27 @@ where
);

// check that the fee payer has sufficient balance
// The temporary write log is populated by now. We need a new, empty one, to simulate the unshielding tx (to prevent the already written keys from being passed/triggering VPs) but we cannot commit the tx write log yet cause the unshielding could be invalid. As a workaround, we create a new write log and merge it with the previous one in case of success
let mut clone_wl_storage =
TempWlStorage::new(&self.wl_storage.storage);
match self.wrapper_fee_check(
wrapper,
temp_wl_storage,
&mut clone_wl_storage,
Some(Cow::Borrowed(gas_table)),
vp_wasm_cache,
tx_wasm_cache,
) {
Ok(()) => TxResult {
code: ErrorCodes::Ok.into(),
info: "Process proposal accepted this \
Ok(()) => {
temp_wl_storage.write_log.merge_tx_write_log(
clone_wl_storage.write_log,
);
TxResult {
code: ErrorCodes::Ok.into(),
info: "Process proposal accepted this \
transaction"
.into(),
},
.into(),
}
}
Err(e) => TxResult {
code: ErrorCodes::InvalidTx.into(),
info: e,
Expand Down
7 changes: 7 additions & 0 deletions core/src/ledger/storage/write_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ impl Iterator for PrefixIter {
}
}

impl WriteLog {
/// Merges the write log of the current tx with the one coming from the other instance. This is useful when two or more distincts write logs are required to correctly validate a transaction. This function consumes the passed in parameter to prevent further use of it.
pub fn merge_tx_write_log(&mut self, other: WriteLog) {
self.tx_write_log.extend(other.tx_write_log.into_iter())
}
}

impl Default for WriteLog {
fn default() -> Self {
Self {
Expand Down

0 comments on commit d11b061

Please sign in to comment.