Kill the light client, CHTs and change tries. (#10080)

* Remove light client, change tries and CHTs

* Update tests

* fmt

* Restore changes_root

* Fixed benches

* Cargo fmt

* fmt

* fmt
This commit is contained in:
Arkadiy Paronyan
2021-11-12 14:15:01 +01:00
committed by GitHub
parent 112b7dac47
commit 4cbbf0cf43
141 changed files with 532 additions and 17807 deletions
+17 -55
View File
@@ -29,7 +29,7 @@ use sp_runtime::{
use node_primitives::{Balance, Hash};
use node_runtime::{
constants::{currency::*, time::SLOT_DURATION},
Balances, Block, Call, CheckedExtrinsic, Event, Header, Runtime, System, TransactionPayment,
Balances, Call, CheckedExtrinsic, Event, Header, Runtime, System, TransactionPayment,
UncheckedExtrinsic,
};
use node_testing::keyring::*;
@@ -78,7 +78,7 @@ fn set_heap_pages<E: Externalities>(ext: &mut E, heap_pages: u64) {
fn changes_trie_block() -> (Vec<u8>, Hash) {
let time = 42 * 1000;
construct_block(
&mut new_test_ext(compact_code_unwrap(), true),
&mut new_test_ext(compact_code_unwrap()),
1,
GENESIS_HASH.into(),
vec![
@@ -102,7 +102,7 @@ fn changes_trie_block() -> (Vec<u8>, Hash) {
/// are not guaranteed to be deterministic) and to ensure that the correct state is propagated
/// from block1's execution to block2 to derive the correct storage_root.
fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let time1 = 42 * 1000;
let block1 = construct_block(
&mut t,
@@ -160,7 +160,7 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
construct_block(
&mut new_test_ext(compact_code_unwrap(), false),
&mut new_test_ext(compact_code_unwrap()),
1,
GENESIS_HASH.into(),
vec![
@@ -179,7 +179,7 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
#[test]
fn panic_execution_with_foreign_code_gives_error() {
let mut t = new_test_ext(bloaty_code_unwrap(), false);
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(69u128, 0u32, 0u128, 0u128, 0u128).encode(),
@@ -211,7 +211,7 @@ fn panic_execution_with_foreign_code_gives_error() {
#[test]
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode(),
@@ -243,7 +243,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
#[test]
fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
@@ -296,7 +296,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
#[test]
fn successful_execution_with_foreign_code_gives_ok() {
let mut t = new_test_ext(bloaty_code_unwrap(), false);
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
@@ -349,7 +349,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
#[test]
fn full_native_block_import_works() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (block1, block2) = blocks();
@@ -529,7 +529,7 @@ fn full_native_block_import_works() {
#[test]
fn full_wasm_block_import_works() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (block1, block2) = blocks();
@@ -679,7 +679,7 @@ fn deploying_wasm_contract_should_work() {
let time = 42 * 1000;
let b = construct_block(
&mut new_test_ext(compact_code_unwrap(), false),
&mut new_test_ext(compact_code_unwrap()),
1,
GENESIS_HASH.into(),
vec![
@@ -712,7 +712,7 @@ fn deploying_wasm_contract_should_work() {
(time / SLOT_DURATION).into(),
);
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
executor_call::<NeverNativeValue, fn() -> _>(&mut t, "Core_execute_block", &b.0, false, None)
.0
@@ -727,7 +727,7 @@ fn deploying_wasm_contract_should_work() {
#[test]
fn wasm_big_block_import_fails() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
set_heap_pages(&mut t.ext(), 4);
@@ -744,7 +744,7 @@ fn wasm_big_block_import_fails() {
#[test]
fn native_big_block_import_succeeds() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
executor_call::<NeverNativeValue, fn() -> _>(
&mut t,
@@ -759,7 +759,7 @@ fn native_big_block_import_succeeds() {
#[test]
fn native_big_block_import_fails_on_fallback() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
// We set the heap pages to 8 because we know that should give an OOM in WASM with the given
// block.
@@ -778,7 +778,7 @@ fn native_big_block_import_fails_on_fallback() {
#[test]
fn panic_execution_gives_error() {
let mut t = new_test_ext(bloaty_code_unwrap(), false);
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
@@ -815,7 +815,7 @@ fn panic_execution_gives_error() {
#[test]
fn successful_execution_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
@@ -874,44 +874,6 @@ fn successful_execution_gives_ok() {
});
}
#[test]
fn full_native_block_import_works_with_changes_trie() {
let block1 = changes_trie_block();
let block_data = block1.0;
let block = Block::decode(&mut &block_data[..]).unwrap();
let mut t = new_test_ext(compact_code_unwrap(), true);
executor_call::<NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
&block.encode(),
true,
None,
)
.0
.unwrap();
assert!(t.ext().storage_changes_root(&GENESIS_HASH).unwrap().is_some());
}
#[test]
fn full_wasm_block_import_works_with_changes_trie() {
let block1 = changes_trie_block();
let mut t = new_test_ext(compact_code_unwrap(), true);
executor_call::<NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
&block1.0,
false,
None,
)
.0
.unwrap();
assert!(t.ext().storage_changes_root(&GENESIS_HASH).unwrap().is_some());
}
#[test]
fn should_import_block_with_test_client() {
use node_testing::client::{
+4 -7
View File
@@ -81,7 +81,7 @@ pub const SPEC_VERSION: u32 = node_runtime::VERSION.spec_version;
pub const TRANSACTION_VERSION: u32 = node_runtime::VERSION.transaction_version;
pub type TestExternalities<H> = CoreTestExternalities<H, u64>;
pub type TestExternalities<H> = CoreTestExternalities<H>;
pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
@@ -123,14 +123,11 @@ pub fn executor_call<
executor().call::<R, NC>(&mut t, &runtime_code, method, data, use_native, native_call)
}
pub fn new_test_ext(code: &[u8], support_changes_trie: bool) -> TestExternalities<BlakeTwo256> {
let mut ext = TestExternalities::new_with_code(
pub fn new_test_ext(code: &[u8]) -> TestExternalities<BlakeTwo256> {
let ext = TestExternalities::new_with_code(
code,
node_testing::genesis::config(support_changes_trie, Some(code))
.build_storage()
.unwrap(),
node_testing::genesis::config(Some(code)).build_storage().unwrap(),
);
ext.changes_trie_storage().insert(0, GENESIS_HASH.into(), Default::default());
ext
}
+7 -7
View File
@@ -36,7 +36,7 @@ use self::common::{sign, *};
#[test]
fn fee_multiplier_increases_and_decreases_on_big_weight() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
// initial fee multiplier must be one.
let mut prev_multiplier = Multiplier::one();
@@ -45,7 +45,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
assert_eq!(TransactionPayment::next_fee_multiplier(), prev_multiplier);
});
let mut tt = new_test_ext(compact_code_unwrap(), false);
let mut tt = new_test_ext(compact_code_unwrap());
let time1 = 42 * 1000;
// big one in terms of weight.
@@ -151,7 +151,7 @@ fn transaction_fee_is_correct() {
// - 1 MILLICENTS in substrate node.
// - 1 milli-dot based on current polkadot runtime.
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(alice()), new_account_info(100));
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(bob()), new_account_info(10));
t.insert(
@@ -226,9 +226,9 @@ fn block_weight_capacity_report() {
use node_primitives::Index;
// execution ext.
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
// setup ext.
let mut tt = new_test_ext(compact_code_unwrap(), false);
let mut tt = new_test_ext(compact_code_unwrap());
let factor = 50;
let mut time = 10;
@@ -303,9 +303,9 @@ fn block_length_capacity_report() {
use node_primitives::Index;
// execution ext.
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
// setup ext.
let mut tt = new_test_ext(compact_code_unwrap(), false);
let mut tt = new_test_ext(compact_code_unwrap());
let factor = 256 * 1024;
let mut time = 10;
@@ -28,7 +28,7 @@ use self::common::*;
#[test]
fn should_submit_unsigned_transaction() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (pool, state) = TestTransactionPoolExt::new();
t.register_extension(TransactionPoolExt::new(pool));
@@ -56,7 +56,7 @@ const PHRASE: &str = "news slush supreme milk chapter athlete soap sausage put c
#[test]
fn should_submit_signed_transaction() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (pool, state) = TestTransactionPoolExt::new();
t.register_extension(TransactionPoolExt::new(pool));
@@ -99,7 +99,7 @@ fn should_submit_signed_transaction() {
#[test]
fn should_submit_signed_twice_from_the_same_account() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (pool, state) = TestTransactionPoolExt::new();
t.register_extension(TransactionPoolExt::new(pool));
@@ -156,7 +156,7 @@ fn should_submit_signed_twice_from_the_same_account() {
#[test]
fn should_submit_signed_twice_from_all_accounts() {
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (pool, state) = TestTransactionPoolExt::new();
t.register_extension(TransactionPoolExt::new(pool));
@@ -220,7 +220,7 @@ fn submitted_transaction_should_be_valid() {
transaction_validity::{TransactionSource, TransactionTag},
};
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
let (pool, state) = TestTransactionPoolExt::new();
t.register_extension(TransactionPoolExt::new(pool));
@@ -249,7 +249,7 @@ fn submitted_transaction_should_be_valid() {
// check that transaction is valid, but reset environment storage,
// since CreateTransaction increments the nonce
let tx0 = state.read().transactions[0].clone();
let mut t = new_test_ext(compact_code_unwrap(), false);
let mut t = new_test_ext(compact_code_unwrap());
t.execute_with(|| {
let source = TransactionSource::External;
let extrinsic = UncheckedExtrinsic::decode(&mut &*tx0).unwrap();