Skip to content

Commit

Permalink
Data Preservers Assignments (#563)
Browse files Browse the repository at this point in the history
* add assignments

* rust tests

* update runtimes and tests

* migration

* allow owner to stop assignment + prevent deletion of assigned profile

* switch to btreesets + remove BootNodes storage

* benchmarks

* force start/stop assignment, refactor normal/forced operations

* local benchmark run

* real benchmarks

* fix clippy errors

* typescript api

* clippy

* fmt

* update some ts tests

* fix a couple of things

* just in case, bring api-augment

* fix test

* fix zombienet

* ts lint and fmt

* put bag genesis config with bootnodes

* cargo clippy

* Fix zombie parathread tests

* migration no longer rely on para managers

* fix merge

* properly record migration weight

* move types in distinct file

* move trait in primitives

* add ts tests for start/stop assignment

* Fix zombienet tests that do not run in CI

* remove unused config type + update ts api

* remove type in mock

---------

Co-authored-by: girazoki <[email protected]>
Co-authored-by: Tomasz Polaczyk <[email protected]>
  • Loading branch information
3 people authored Jun 12, 2024
1 parent 7268ddd commit f6bb1f9
Show file tree
Hide file tree
Showing 72 changed files with 4,828 additions and 1,897 deletions.
3 changes: 1 addition & 2 deletions client/consensus/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ where
&mut params.overseer_handle,
&mut params.relay_client,
)
.await
.get(0)
.await.first()
{
*core_index
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/services-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
.client
.runtime_api()
.block_cost(self.client.usage_info().chain.best_hash, para_id)
.map_err(|e| internal_err(e))?;
.map_err(internal_err)?;
Ok(cost)
}

Expand All @@ -77,7 +77,7 @@ where
.client
.runtime_api()
.collator_assignment_cost(self.client.usage_info().chain.best_hash, para_id)
.map_err(|e| internal_err(e))?;
.map_err(internal_err)?;
Ok(cost)
}
}
Expand Down
2 changes: 1 addition & 1 deletion container-chains/nodes/frontier/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};

use fc_storage::StorageOverride;
use {
container_chain_template_frontier_runtime::{opaque::Block, AccountId, Hash, Index},
cumulus_client_parachain_inherent::ParachainInherentData,
cumulus_primitives_core::{ParaId, PersistedValidationData},
cumulus_test_relay_sproof_builder::RelayStateSproofBuilder,
fc_rpc::{EthTask, TxPool},
fc_rpc_core::TxPoolApiServer,
fc_storage::StorageOverride,
fp_rpc::EthereumRuntimeRPCApi,
futures::StreamExt,
jsonrpsee::RpcModule,
Expand Down
13 changes: 7 additions & 6 deletions container-chains/runtime-templates/frontier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,13 @@ where
let deploy_filter: DeployFilter = AddressList::get();

match deploy_filter {
DeployFilter::All => return Ok(()),
DeployFilter::All => Ok(()),
DeployFilter::Whitelisted(addresses_vec) => {
if !addresses_vec.contains(address) {
return Err(pallet_evm::Error::<Runtime>::CreateOriginNotAllowed);
Err(pallet_evm::Error::<Runtime>::CreateOriginNotAllowed)
} else {
Ok(())
}
return Ok(());
}
}
}
Expand Down Expand Up @@ -1366,7 +1367,7 @@ impl_runtime_apis! {
);

// verify initial balance
assert_eq!(Balances::free_balance(&who), balance);
assert_eq!(Balances::free_balance(who), balance);

// set up local asset
let asset_amount = 10u128;
Expand All @@ -1386,10 +1387,10 @@ impl_runtime_apis! {
let verify = Box::new(move || {
// verify native balance after transfer, decreased by transferred fee amount
// (plus transport fees)
assert!(Balances::free_balance(&who) <= balance - fee_amount);
assert!(Balances::free_balance(who) <= balance - fee_amount);
// verify asset balance decreased by exactly transferred amount
assert_eq!(
ForeignAssets::balance(asset_id, &who),
ForeignAssets::balance(asset_id, who),
initial_asset_amount - asset_amount,
);
});
Expand Down
24 changes: 17 additions & 7 deletions node/src/chain_spec/dancebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,26 @@ fn testnet_genesis(
.iter()
.map(|(para_id, _genesis_data, _boot_nodes)| (*para_id, 1000, 100).into())
.collect();
let para_id_boot_nodes: Vec<_> = para_ids
let data_preservers_bootnodes: Vec<_> = para_ids
.iter()
.map(|(para_id, _genesis_data, boot_nodes)| (*para_id, boot_nodes.clone()))
.flat_map(|(para_id, _genesis_data, bootnodes)| {
bootnodes.clone().into_iter().map(|bootnode| {
(
*para_id,
AccountId::from([0u8; 32]),
bootnode,
dancebox_runtime::PreserversAssignementPaymentRequest::Free,
dancebox_runtime::PreserversAssignementPaymentWitness::Free,
)
})
})
.collect();
let para_ids: Vec<_> = para_ids
.into_iter()
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data))
.collect();

let accounts_with_ed = vec![
let accounts_with_ed = [
dancebox_runtime::StakingAccount::get(),
dancebox_runtime::ParachainBondAccount::get(),
dancebox_runtime::PendingRewardsAccount::get(),
Expand Down Expand Up @@ -250,10 +260,6 @@ fn testnet_genesis(
},
parachain_system: Default::default(),
configuration,
data_preservers: DataPreserversConfig {
para_id_boot_nodes,
..Default::default()
},
registrar: RegistrarConfig { para_ids },
services_payment: ServicesPaymentConfig { para_id_credits },
sudo: SudoConfig {
Expand All @@ -271,6 +277,10 @@ fn testnet_genesis(
transaction_payment: Default::default(),
tx_pause: Default::default(),
treasury: Default::default(),
data_preservers: DataPreserversConfig {
bootnodes: data_preservers_bootnodes,
..Default::default()
},
};

serde_json::to_value(g).unwrap()
Expand Down
25 changes: 18 additions & 7 deletions node/src/chain_spec/flashbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,27 @@ fn testnet_genesis(
.iter()
.map(|(para_id, _genesis_data, _boot_nodes)| (*para_id, 1000, 100).into())
.collect();
let para_id_boot_nodes: Vec<_> = para_ids
let data_preservers_bootnodes: Vec<_> = para_ids
.iter()
.map(|(para_id, _genesis_data, boot_nodes)| (*para_id, boot_nodes.clone()))
.flat_map(|(para_id, _genesis_data, bootnodes)| {
bootnodes.clone().into_iter().map(|bootnode| {
(
*para_id,
AccountId::from([0u8; 32]),
bootnode,
flashbox_runtime::PreserversAssignementPaymentRequest::Free,
flashbox_runtime::PreserversAssignementPaymentWitness::Free,
)
})
})
.collect();

let para_ids: Vec<_> = para_ids
.into_iter()
.map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data))
.collect();

let accounts_with_ed = vec![
let accounts_with_ed = [
flashbox_runtime::StakingAccount::get(),
flashbox_runtime::ParachainBondAccount::get(),
flashbox_runtime::PendingRewardsAccount::get(),
Expand Down Expand Up @@ -250,10 +261,6 @@ fn testnet_genesis(
},
parachain_system: Default::default(),
configuration,
data_preservers: DataPreserversConfig {
para_id_boot_nodes,
..Default::default()
},
registrar: RegistrarConfig { para_ids },
services_payment: ServicesPaymentConfig { para_id_credits },
sudo: SudoConfig {
Expand All @@ -269,6 +276,10 @@ fn testnet_genesis(
transaction_payment: Default::default(),
tx_pause: Default::default(),
treasury: Default::default(),
data_preservers: DataPreserversConfig {
bootnodes: data_preservers_bootnodes,
..Default::default()
},
};

serde_json::to_value(g).unwrap()
Expand Down
7 changes: 3 additions & 4 deletions node/src/container_chain_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ fn delete_container_chain_db(db_path: &Path) {
let _ = std::fs::remove_dir_all(db_path);
// Remove all the empty folders inside `simple_container_2002`, including self
if let Some(parent) = db_path.ancestors().nth(2) {
let _ = delete_empty_folders_recursive(parent);
delete_empty_folders_recursive(parent);
}
}

Expand All @@ -821,7 +821,7 @@ fn delete_empty_folders_recursive(path: &Path) {

let path = entry.path();
if path.is_dir() {
let _ = delete_empty_folders_recursive(&path);
delete_empty_folders_recursive(&path);
}
}

Expand Down Expand Up @@ -903,8 +903,7 @@ fn check_paritydb_lock_held(db_path: &Path) -> Result<bool, std::io::Error> {

#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
use {super::*, std::path::PathBuf};

// Copy of ContainerChainSpawner with extra assertions for tests, and mocked spawn function.
struct MockContainerChainSpawner {
Expand Down
3 changes: 2 additions & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ async fn start_node_impl(
.base
.base
.import_params
.wasmtime_precompiled = parachain_config.wasmtime_precompiled.clone();
.wasmtime_precompiled
.clone_from(&parachain_config.wasmtime_precompiled);
}
}

Expand Down
3 changes: 1 addition & 2 deletions node/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ mod panics;
fn create_runner() -> Runner<Cli> {
// tanssi-node args should go here, `--dev` is probably enough
let cli = Cli::from_iter(["--dev"]);
let runner = cli.create_runner(&cli.run.normalize()).unwrap();

runner
cli.create_runner(&cli.run.normalize()).unwrap()
}

// Nice hack from polkadot-sdk to run a unit test in a separate process.
Expand Down
4 changes: 2 additions & 2 deletions pallets/author-noting/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ benchmarks! {
let para_id = 1000.into();
let block_number = 1;
let author: T::AccountId = account("account id", 0u32, 0u32);
}: _(RawOrigin::Root, para_id, block_number, author, (block_number as u64).into())
}: _(RawOrigin::Root, para_id, block_number, author, u64::from(block_number).into())

kill_author_data {
let para_id = 1000.into();
let block_number = 1;
let author: T::AccountId = account("account id", 0u32, 0u32);
assert_ok!(Pallet::<T>::set_author(RawOrigin::Root.into(), para_id, block_number, author, (block_number as u64).into()));
assert_ok!(Pallet::<T>::set_author(RawOrigin::Root.into(), para_id, block_number, author, u64::from(block_number).into()));
}: _(RawOrigin::Root, para_id)

impl_benchmark_test_suite!(
Expand Down
5 changes: 2 additions & 3 deletions pallets/data-preservers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true

dp-core = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
serde = { workspace = true, default-features = false, features = [ "derive" ] }
tp-traits = { workspace = true }

# Substrate
Expand Down Expand Up @@ -52,8 +52,7 @@ std = [
"pallet-balances/std",
"parity-scale-codec/std",
"scale-info/std",
"serde",
"serde?/std",
"serde/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
Loading

0 comments on commit f6bb1f9

Please sign in to comment.