From d11b061ab3e2c39f02480ec8c69a54ce39374d17 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 13 Apr 2023 15:24:23 +0200 Subject: [PATCH] Provides a clean write log for unshielding tx in `process_proposal` --- .../lib/node/ledger/shell/process_proposal.rs | 21 +++++++++++++------ core/src/ledger/storage/write_log.rs | 7 +++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 0c710b2242d..4a8afe7e9fc 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -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; @@ -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, diff --git a/core/src/ledger/storage/write_log.rs b/core/src/ledger/storage/write_log.rs index 05ee7dee59b..dc23dd9fa55 100644 --- a/core/src/ledger/storage/write_log.rs +++ b/core/src/ledger/storage/write_log.rs @@ -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 {