Skip to content

Commit

Permalink
Enable async backing (#435)
Browse files Browse the repository at this point in the history
* change(Cargo): update dependencies

* change(zombienet): update config files

* feat(kreivo-runtime): make adjustments to pass / fix challenger

* feat(kreivo-runtime): enable async backing

* fix(chain-spec-generator): minor adjustments

* fix(kreivo-runtime): lint

* fix(kreivo-runtime): fixup memory constraints for contracts to match adjustments in weights.
  • Loading branch information
pandres95 authored Dec 1, 2024
1 parent b6ca4d7 commit 3f57640
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 343 deletions.
888 changes: 583 additions & 305 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repository = 'https://github.com/virto-network/virto-node'
clap = { version = "4.5.3" }
futures = { version = "0.3.28" }
hex-literal = { version = "0.4.1" }
log = { version = "0.4.20" }
log = { version = "0.4.22" }
parity-scale-codec = { version = "3.6.4", default-features = false, features = [
"derive",
] }
Expand Down
2 changes: 2 additions & 0 deletions chain-spec-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ fn main() -> Result<(), String> {

let supported_chains = HashMap::<_, Box<dyn Fn() -> Result<Box<dyn ChainSpec>, String>>>::from([
("kreivo", Box::new(live::chain_spec) as Box<_>),
("live", Box::new(live::chain_spec) as Box<_>),
("kreivo-local", Box::new(local::chain_spec) as Box<_>),
("local", Box::new(local::chain_spec) as Box<_>),
]);

if let Some(function) = supported_chains.get(&*cli.chain) {
Expand Down
4 changes: 0 additions & 4 deletions chain-spec-generator/src/spec/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub fn chain_spec() -> Result<Box<dyn ChainSpec>, String> {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
))
.build(),
))
Expand All @@ -111,12 +110,9 @@ fn local_genesis(
id: ParaId,
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
#[cfg(feature = "paseo")] sudo: AccountId,
) -> serde_json::Value {
let mut config = serde_json::json!({}).as_object().expect("map given; qed").clone();

#[cfg(feature = "paseo")]
config.insert("sudo".into(), serde_json::json!({ "key": sudo }));
config.insert(
"balances".into(),
serde_json::json!({
Expand Down
18 changes: 9 additions & 9 deletions runtime/kreivo/src/configuration/system_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use fc_traits_authn::{composite_authenticator, util::AuthorityFromPalletId, Chal
use frame_support::{traits::EnsureOrigin, PalletId};
use frame_system::EnsureRootWithSuccess;
use pallet_communities::origin::AsSignedByCommunity;
use polkadot_core_primitives::HashT;

use super::*;

Expand Down Expand Up @@ -114,7 +113,7 @@ impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type MinimumPeriod = ConstU64<0>;
type WeightInfo = ();
}

Expand All @@ -133,22 +132,22 @@ parameter_types! {
pub NeverPays: Option<pallet_pass::DepositInformation<Runtime>> = None;
}

pub struct UnincludedBlockChallenger;
pub struct UnincludedBlockHashChallenger;

impl Challenger for UnincludedBlockChallenger {
impl Challenger for UnincludedBlockHashChallenger {
type Context = BlockNumber;

fn generate(cx: &Self::Context) -> Challenge {
System::block_hash(cx).0
}

fn check_challenge(cx: &Self::Context, challenge: &[u8]) -> Option<()> {
(*cx >= System::block_number().saturating_sub(3)).then_some(())?;
Self::generate(cx).eq(challenge).then_some(())
}

fn generate(cx: &Self::Context) -> Challenge {
BlakeTwo256::hash(&cx.to_le_bytes()).0
}
}

pub type WebAuthn = pass_webauthn::Authenticator<UnincludedBlockChallenger, AuthorityFromPalletId<PassPalletId>>;
pub type WebAuthn = pass_webauthn::Authenticator<UnincludedBlockHashChallenger, AuthorityFromPalletId<PassPalletId>>;
pub type Dummy = fc_traits_authn::util::dummy::Dummy<AuthorityFromPalletId<PassPalletId>>;

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down Expand Up @@ -219,6 +218,7 @@ impl pallet_pass::Config for Runtime {
>,
>,
>;
type Scheduler = Scheduler;

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = PassBenchmarkHelper;
Expand Down
7 changes: 5 additions & 2 deletions runtime/kreivo/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ impl frame_support::traits::Contains<RuntimeCall> for AllowBalancesCall {
}

fn schedule<T: pallet_contracts::Config>() -> pallet_contracts::Schedule<T> {
const MB: u32 = 1024 * 1024;
pallet_contracts::Schedule {
limits: pallet_contracts::Limits {
validator_runtime_memory: 1024 * 1024 * 1024,
runtime_memory: 1024 * 1024 * 768,
validator_runtime_memory: 1024 * MB,
// Current `max_storage_size`: 138 MB
// Constraint: `runtime_memory <= validator_runtime_memory - 2 * max_storage_size`
runtime_memory: 748 * MB,
..Default::default()
},
..Default::default()
Expand Down
42 changes: 28 additions & 14 deletions runtime/kreivo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ pub use impls::{EqualOrGreatestRootCmp, ProxyType, RuntimeBlackListedCalls};

pub use parachains_common::{
opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature,
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MINUTES, NORMAL_DISPATCH_RATIO,
};

pub(crate) const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
sp_weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, CommunityId>;

Expand All @@ -129,7 +134,7 @@ pub type SignedExtra = (
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
SkipCheckIfFeeless<Runtime, frame_system::CheckNonce<Runtime>>,
frame_system::CheckWeight<Runtime>,
SkipCheckIfFeeless<Runtime, ChargeTxToPassAccount<ChargeTransaction, Runtime, ()>>,
);
Expand Down Expand Up @@ -319,28 +324,37 @@ impl pallet_message_queue::Config for Runtime {

impl cumulus_pallet_aura_ext::Config for Runtime {}

/// How many parachain blocks are processed by the relay chain per parent.
/// Limits the number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet
/// included into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6_000;
mod async_backing_params {
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet
/// included into the relay chain.
pub(crate) const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent.
/// Limits the number of blocks authored per slot.
pub(crate) const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
pub(crate) const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6_000;
}

/// Aura consensus hook
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
{ async_backing_params::RELAY_CHAIN_SLOT_DURATION_MILLIS },
{ async_backing_params::BLOCK_PROCESSING_VELOCITY },
{ async_backing_params::UNINCLUDED_SEGMENT_CAPACITY },
>;

// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
// up by `pallet_aura` to implement `fn slot_duration()`.
//
// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 6_000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = ConstU32<100_000>;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type AllowMultipleBlocksPerSlot = ConstBool<true>;
type SlotDuration = ConstU64<SLOT_DURATION>;
}

Expand Down
16 changes: 12 additions & 4 deletions zombienet/kreivo-kusama-local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ chain = "kusama-local"
chain_spec_command = "./bin/runtimes/polkadot/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
default_args = ["-lparachain=debug", "-lxcm=trace"]
default_command = "./bin/polkadot"
scheduling_lookahead = 2

[relaychain.async_backing_params]
max_candidate_depth = 3
allowed_ancestry_len = 2

[[relaychain.nodes]]
extra_args = ["--force-authoring -lparachain=debug --unsafe-rpc-external --rpc-cors=all"]
Expand All @@ -29,20 +34,23 @@ name = "dave"
validator = true

[[parachains]]
add_to_genesis = true
id = 2281
chain = "local"
chain_spec_command = "./target/release/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
cumulus_based = true
id = 2281
add_to_genesis = true
onboard_as_parachain = true

[[parachains.collators]]
command = "./bin/polkadot-parachain"
args = ["--force-authoring --log=xcm=trace,parachain=trace"]
command = "./target/release/virto-node"
name = "kreivo1"
ws_port = 20000

[[parachains.collators]]
chain = "dev"
chain_spec_command = "./target/release/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
command = "./bin/polkadot-parachain"
args = ["--force-authoring --log=xcm=trace,parachain=trace"]
command = "./target/release/virto-node"
name = "kreivo2"
ws_port = 21000
16 changes: 12 additions & 4 deletions zombienet/kreivo-paseo-local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ chain = "paseo-local"
chain_spec_command = "./bin/runtimes/paseo/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
default_args = ["-lparachain=debug", "-lxcm=trace"]
default_command = "./bin/polkadot"
scheduling_lookahead = 2

[relaychain.async_backing_params]
max_candidate_depth = 3
allowed_ancestry_len = 2

[[relaychain.nodes]]
extra_args = ["--force-authoring -lparachain=debug --unsafe-rpc-external --rpc-cors=all"]
Expand All @@ -29,20 +34,23 @@ name = "dave"
validator = true

[[parachains]]
add_to_genesis = true
id = 2281
chain = "local"
chain_spec_command = "./target/release/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
cumulus_based = true
id = 2281
add_to_genesis = true
onboard_as_parachain = true

[[parachains.collators]]
command = "./bin/polkadot-parachain"
args = ["--force-authoring --log=xcm=trace,parachain=trace"]
command = "./target/release/virto-node"
name = "kreivo1"
ws_port = 20000

[[parachains.collators]]
chain = "dev"
chain_spec_command = "./target/release/chain-spec-generator {% raw %} {{chainName}} {% endraw %}"
command = "./bin/polkadot-parachain"
args = ["--force-authoring --log=xcm=trace,parachain=trace"]
command = "./target/release/virto-node"
name = "kreivo2"
ws_port = 21000

0 comments on commit 3f57640

Please sign in to comment.