Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/girazoki-more-logs-state-pruning…
Browse files Browse the repository at this point in the history
…' into perm-v0.4.1
  • Loading branch information
tmpolaczyk committed Jan 29, 2024
2 parents 13d0df3 + c4ae7e7 commit 6975ca2
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 289 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ jobs:
id: prepare
run: |
dancebox='{"runtime_name": "dancebox","runtime_path" : "./runtime/dancebox/src/lib.rs"}'
flashbox='{"runtime_name": "flashbox","runtime_path" : "./runtime/flashbox/src/lib.rs"}'
frontier_template='{"runtime_name": "frontier-template","runtime_path" : "./container-chains/templates/frontier/runtime/src/lib.rs"}'
simple_template='{"runtime_name": "simple-template","runtime_path" : "./container-chains/templates/simple/runtime/src/lib.rs"}'
if [[ ${{ github.event.inputs.chains }} = "tanssi-only" ]]; then
echo "matrix_tests=[$dancebox]" >> $GITHUB_OUTPUT
echo "matrix_tests=[$dancebox, $flashbox]" >> $GITHUB_OUTPUT
elif [[ ${{ github.event.inputs.chains }} = "templates-only" ]]; then
echo "matrix_tests=[$simple_template, $frontier_template]" >> $GITHUB_OUTPUT
else
echo "matrix_tests=[$dancebox, $simple_template, $frontier_template]" >> $GITHUB_OUTPUT
echo "matrix_tests=[$dancebox, $flashbox, $simple_template, $frontier_template]" >> $GITHUB_OUTPUT
fi
build-srtool-runtimes:
needs: ["setup-scripts", "matrix_prep"]
Expand Down
550 changes: 276 additions & 274 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ cumulus-client-pov-recovery = { git = "https://github.com/moondance-labs/polkado
cumulus-client-service = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
cumulus-primitives-parachain-inherent = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
cumulus-relay-chain-interface = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
cumulus-relay-chain-inprocess-interface = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
cumulus-relay-chain-minimal-node = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
cumulus-test-relay-sproof-builder = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }
xcm-emulator = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.3.0", default-features = false }

Expand Down
2 changes: 2 additions & 0 deletions client/node-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ cumulus-client-service = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
cumulus-relay-chain-inprocess-interface = { workspace = true }
cumulus-relay-chain-minimal-node = { workspace = true }
36 changes: 25 additions & 11 deletions client/node-common/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
cumulus_client_cli::CollatorOptions,
cumulus_client_consensus_common::ParachainConsensus,
cumulus_client_service::{
build_relay_chain_interface, CollatorSybilResistance, StartFullNodeParams,
CollatorSybilResistance, StartFullNodeParams,
},
cumulus_primitives_core::ParaId,
cumulus_relay_chain_interface::RelayChainInterface,
Expand Down Expand Up @@ -251,6 +251,9 @@ where
}
}

use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node_with_rpc;

impl<T: NodeBuilderConfig, SNetwork, STxHandler, SImportQueueService>
NodeBuilder<T, SNetwork, STxHandler, SImportQueueService>
where
Expand All @@ -270,16 +273,27 @@ where
Arc<(dyn RelayChainInterface + 'static)>,
Option<CollatorPair>,
)> {
build_relay_chain_interface(
polkadot_config,
parachain_config,
self.telemetry_worker_handle.clone(),
&mut self.task_manager,
collator_options.clone(),
self.hwbench.clone(),
)
.await
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))
log::info!("polkadot config {:?}", parachain_config);
if let cumulus_client_cli::RelayChainMode::ExternalRpc(rpc_target_urls) =
collator_options.relay_chain_mode
{
build_minimal_relay_chain_node_with_rpc(
polkadot_config,
&mut self.task_manager,
rpc_target_urls,
)
.await
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))
} else {
build_inprocess_relay_chain(
polkadot_config,
parachain_config,
self.telemetry_worker_handle.clone(),
&mut self.task_manager,
self.hwbench.clone(),
)
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))
}
}

/// Given an import queue, calls `cumulus_client_service::build_network` and
Expand Down
4 changes: 3 additions & 1 deletion runtime/flashbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub use sp_runtime::BuildStorage;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;

pub mod migrations;

use {
cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases,
cumulus_primitives_core::{relay_chain::SessionIndex, BodyId, ParaId},
Expand Down Expand Up @@ -923,7 +925,7 @@ impl pallet_proxy::Config for Runtime {

impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MigrationsList = ();
type MigrationsList = (migrations::FlashboxMigrations<Runtime>,);
type XcmExecutionManager = ();
}

Expand Down
132 changes: 132 additions & 0 deletions runtime/flashbox/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! # Migrations
//!
//! This module acts as a registry where each migration is defined. Each migration should implement
//! the "Migration" trait declared in the pallet-migrations crate.

use {
crate::{ParaId, Runtime, ServicesPayment},
frame_support::{
pallet_prelude::ValueQuery, storage::types::StorageMap, weights::Weight, Blake2_128Concat,
},
pallet_migrations::{GetMigrations, Migration},
sp_core::Get,
sp_runtime::BoundedVec,
sp_std::{collections::btree_set::BTreeSet, marker::PhantomData, prelude::*},
};

pub struct MigrateServicesPaymentAddCredits<T>(pub PhantomData<T>);
impl<T> Migration for MigrateServicesPaymentAddCredits<T>
where
T: pallet_configuration::Config,
{
fn friendly_name(&self) -> &str {
"TM_MigrateServicesPaymentAddCredits"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
// For each parachain in pallet_registrar (active, pending or pending_verification),
// insert `MaxCreditsStored` to pallet_services_payment,
// and mark that parachain as "given_free_credits".
let mut para_ids = BTreeSet::new();
let active = pallet_registrar::RegisteredParaIds::<Runtime>::get();
let pending = pallet_registrar::PendingParaIds::<Runtime>::get();
let pending_verification = pallet_registrar::PendingVerification::<Runtime>::get();
// This migration ignores Paused and PendingPaused because they do not exist yet in flashbox

para_ids.extend(active);
para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
para_ids.extend(pending_verification);

let reads = 3 + 2 * para_ids.len() as u64;
let writes = 2 * para_ids.len() as u64;

for para_id in para_ids {
// 2 reads 2 writes
ServicesPayment::give_free_credits(&para_id);
}

let db_weights = T::DbWeight::get();
db_weights.reads_writes(reads, writes)
}
}

pub struct RegistrarBootNodesStorageValuePrefix<T>(PhantomData<T>);
impl<T> frame_support::traits::StorageInstance for RegistrarBootNodesStorageValuePrefix<T> {
const STORAGE_PREFIX: &'static str = "BootNodes";
fn pallet_prefix() -> &'static str {
"Registrar"
}
}
pub type RegistrarBootNodesStorageMap<T> = StorageMap<
RegistrarBootNodesStorageValuePrefix<T>,
Blake2_128Concat,
ParaId,
//BoundedVec<BoundedVec<u8, T::MaxBootNodeUrlLen>, T::MaxBootNodes>,
Vec<Vec<u8>>,
ValueQuery,
>;

pub struct MigrateBootNodes<T>(pub PhantomData<T>);
impl<T> Migration for MigrateBootNodes<T>
where
T: pallet_configuration::Config,
{
fn friendly_name(&self) -> &str {
"TM_MigrateBootNodes"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
let mut len = 0;
for (para_id, bootnodes) in RegistrarBootNodesStorageMap::<Runtime>::drain() {
len += 1;
// Convert Vec<Vec<u8>> into BoundedVec<BoundedVec<u8>>
// Cannot fail because the old storage was actually a BoundedVec with the same limit as the new one
let bootnodes: Vec<_> = bootnodes
.into_iter()
.map(|bootnode| bootnode.try_into().unwrap())
.collect();
let bootnodes: BoundedVec<_, _> = bootnodes.try_into().unwrap();
pallet_data_preservers::BootNodes::<Runtime>::insert(para_id, bootnodes);
}

let db_weights = T::DbWeight::get();
let reads = len;
let writes = len;
db_weights.reads_writes(reads, writes)
}
}

pub struct FlashboxMigrations<Runtime>(PhantomData<Runtime>);

impl<Runtime> GetMigrations for FlashboxMigrations<Runtime>
where
Runtime: pallet_balances::Config,
Runtime: pallet_configuration::Config,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
let migrate_services_payment =
MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());

vec![
Box::new(migrate_services_payment),
Box::new(migrate_boot_nodes),
]
}
}
2 changes: 1 addition & 1 deletion tools/github/generate-runtimes-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function main() {
getRuntimeInfo(argv["srtool-report-folder"], runtimeName as string)
);

const moduleLinks = ["substrate", "polkadot", "cumulus", "frontier"].map((repoName) => ({
const moduleLinks = ["polkadot-sdk", "frontier"].map((repoName) => ({
name: repoName,
link: getCompareLink(repoName, previousTag, newTag),
}));
Expand Down

0 comments on commit 6975ca2

Please sign in to comment.