Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Kill the light client, CHTs and change tries. (#10080)
Browse files Browse the repository at this point in the history
* Remove light client, change tries and CHTs

* Update tests

* fmt

* Restore changes_root

* Fixed benches

* Cargo fmt

* fmt

* fmt
  • Loading branch information
arkpar authored Nov 12, 2021
1 parent 5d22361 commit c45c1cb
Show file tree
Hide file tree
Showing 141 changed files with 534 additions and 17,809 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ members = [
"client/finality-grandpa",
"client/informant",
"client/keystore",
"client/light",
"client/network",
"client/network-gossip",
"client/network/test",
Expand Down
1 change: 0 additions & 1 deletion bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ fn testnet_genesis(
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
Expand Down
3 changes: 0 additions & 3 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: None,
warp_sync: Some(warp_sync),
})?;
Expand Down Expand Up @@ -234,8 +233,6 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder,
on_demand: None,
remote_blockchain: None,
backend,
system_rpc_tx,
config,
Expand Down
5 changes: 1 addition & 4 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ pub fn testnet_genesis(
const STASH: Balance = ENDOWMENT / 1000;

GenesisConfig {
system: SystemConfig {
code: wasm_binary_unwrap().to_vec(),
changes_trie_config: Default::default(),
},
system: SystemConfig { code: wasm_binary_unwrap().to_vec() },
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
},
Expand Down
7 changes: 2 additions & 5 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ pub fn new_full_base(
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: None,
warp_sync: Some(warp_sync),
})?;
Expand Down Expand Up @@ -369,8 +368,6 @@ pub fn new_full_base(
rpc_extensions_builder: Box::new(rpc_extensions_builder),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
on_demand: None,
remote_blockchain: None,
system_rpc_tx,
telemetry: telemetry.as_mut(),
})?;
Expand Down Expand Up @@ -542,7 +539,7 @@ mod tests {
use sc_service_test::TestNetNode;
use sc_transaction_pool_api::{ChainEvent, MaintainedTransactionPool};
use sp_consensus::{BlockOrigin, Environment, Proposer};
use sp_core::{crypto::Pair as CryptoPair, Public, H256};
use sp_core::{crypto::Pair as CryptoPair, Public};
use sp_inherents::InherentDataProvider;
use sp_keyring::AccountKeyring;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
Expand Down Expand Up @@ -621,7 +618,7 @@ mod tests {
None,
);

let mut digest = Digest::<H256>::default();
let mut digest = Digest::default();

// even though there's only one authority some slots might be empty,
// so we must keep trying the next slots until we can claim one.
Expand Down
4 changes: 2 additions & 2 deletions bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SPEC_VERSION: u32 = node_runtime::VERSION.spec_version;

const HEAP_PAGES: u64 = 20;

type TestExternalities<H> = CoreTestExternalities<H, u64>;
type TestExternalities<H> = CoreTestExternalities<H>;

#[derive(Debug)]
enum ExecutionMethod {
Expand Down Expand Up @@ -188,7 +188,7 @@ fn bench_execute_block(c: &mut Criterion) {

for strategy in execution_methods {
group.bench_function(format!("{:?}", strategy), |b| {
let genesis_config = node_testing::genesis::config(false, Some(compact_code_unwrap()));
let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap()));
let (use_native, wasm_method) = match strategy {
ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted),
ExecutionMethod::Wasm(wasm_method) => (false, wasm_method),
Expand Down
72 changes: 17 additions & 55 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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![
Expand All @@ -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,
Expand Down Expand Up @@ -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![
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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, _> {
Expand Down Expand Up @@ -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, _> {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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, _> {
Expand Down Expand Up @@ -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, _> {
Expand Down Expand Up @@ -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::{
Expand Down
11 changes: 4 additions & 7 deletions bin/node/executor/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit c45c1cb

Please sign in to comment.