From 001cbd75326b8944187edac4e3e0bc1fe6135321 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 5 Sep 2023 18:35:14 +0100 Subject: [PATCH] feat(storage, tree): respect `Sender Recovery` pruning in the blockchain tree (#4431) --- crates/storage/provider/src/providers/database/mod.rs | 6 ++++++ .../provider/src/providers/database/provider.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/database/mod.rs b/crates/storage/provider/src/providers/database/mod.rs index e9da00b85..525d4c7ba 100644 --- a/crates/storage/provider/src/providers/database/mod.rs +++ b/crates/storage/provider/src/providers/database/mod.rs @@ -468,6 +468,10 @@ mod tests { { let provider = factory.provider_rw().unwrap(); assert_matches!(provider.insert_block(block.clone(), None, None), Ok(_)); + assert_matches!( + provider.transaction_sender(0), Ok(Some(sender)) + if sender == block.body[0].recover_signer().unwrap() + ); assert_matches!(provider.transaction_id(block.body[0].hash), Ok(Some(0))); } @@ -478,12 +482,14 @@ mod tests { block.clone(), None, Some(&PruneModes { + sender_recovery: Some(PruneMode::Full), transaction_lookup: Some(PruneMode::Full), ..PruneModes::none() }) ), Ok(_) ); + assert_matches!(provider.transaction_sender(0), Ok(None)); assert_matches!(provider.transaction_id(block.body[0].hash), Ok(None)); } } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index d811e9ab3..efdf2edbb 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1980,7 +1980,15 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> BlockWriter for DatabaseProvider<' for (transaction, sender) in tx_iter { let hash = transaction.hash(); - self.tx.put::(next_tx_num, sender)?; + + if prune_modes + .and_then(|modes| modes.sender_recovery) + .filter(|prune_mode| prune_mode.is_full()) + .is_none() + { + self.tx.put::(next_tx_num, sender)?; + } + self.tx.put::(next_tx_num, transaction.into())?; if prune_modes