ProofRecorder: Implement transactional support (#13769)

* TrieRecorder: Start adding support for transactions

* Adds `transactions` functions and some test

* More tests

* Docs

* Ensure that we rollback failed transactions in the storage proof

* FMT

* Update primitives/trie/src/recorder.rs

Co-authored-by: Dmitry Markin <dmitry@markin.tech>

* Review comments

* Update primitives/trie/src/recorder.rs

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* For the holy clippy!

* Update primitives/trie/src/recorder.rs

Co-authored-by: Anton <anton.kalyaev@gmail.com>

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Anton <anton.kalyaev@gmail.com>
This commit is contained in:
Bastian Köcher
2023-04-05 16:43:17 +02:00
committed by GitHub
parent 06f84830b6
commit fa8e323231
5 changed files with 573 additions and 40 deletions
+61 -1
View File
@@ -312,7 +312,9 @@ mod tests {
use sp_blockchain::HeaderBackend;
use sp_core::Blake2Hasher;
use sp_state_machine::Backend;
use substrate_test_runtime_client::{DefaultTestClientBuilderExt, TestClientBuilderExt};
use substrate_test_runtime_client::{
runtime::Extrinsic, DefaultTestClientBuilderExt, TestClientBuilderExt,
};
#[test]
fn block_building_storage_proof_does_not_include_runtime_by_default() {
@@ -345,4 +347,62 @@ mod tests {
.unwrap_err()
.contains("Database missing expected key"),);
}
#[test]
fn failing_extrinsic_rolls_back_changes_in_storage_proof() {
let builder = substrate_test_runtime_client::TestClientBuilder::new();
let backend = builder.backend();
let client = builder.build();
let mut block_builder = BlockBuilder::new(
&client,
client.info().best_hash,
client.info().best_number,
RecordProof::Yes,
Default::default(),
&*backend,
)
.unwrap();
block_builder.push(Extrinsic::ReadAndPanic(8)).unwrap_err();
let block = block_builder.build().unwrap();
let proof_with_panic = block.proof.expect("Proof is build on request").encoded_size();
let mut block_builder = BlockBuilder::new(
&client,
client.info().best_hash,
client.info().best_number,
RecordProof::Yes,
Default::default(),
&*backend,
)
.unwrap();
block_builder.push(Extrinsic::Read(8)).unwrap();
let block = block_builder.build().unwrap();
let proof_without_panic = block.proof.expect("Proof is build on request").encoded_size();
let block = BlockBuilder::new(
&client,
client.info().best_hash,
client.info().best_number,
RecordProof::Yes,
Default::default(),
&*backend,
)
.unwrap()
.build()
.unwrap();
let proof_empty_block = block.proof.expect("Proof is build on request").encoded_size();
// Ensure that we rolled back the changes of the panicked transaction.
assert!(proof_without_panic > proof_with_panic);
assert!(proof_without_panic > proof_empty_block);
assert_eq!(proof_empty_block, proof_with_panic);
}
}