Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions node/src/chain_spec/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub fn parachain_config() -> Result<ChainSpec, String> {
create_testnet_claims(),
// parachain ID
PARA_ID.into(),
// is_testnet
true,
DusterConfig {
account_whitelist: vec![get_account_id_from_seed::<sr25519::Public>("Duster")],
},
Expand Down
4 changes: 4 additions & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn parachain_genesis(
token_balances: Vec<(AccountId, Vec<(AssetId, Balance)>)>,
claims_data: Vec<(EthereumAddress, Balance)>,
parachain_id: ParaId,
is_testnet: bool,
duster: DusterConfig,
) -> serde_json::Value {
serde_json::json!({
Expand Down Expand Up @@ -157,6 +158,9 @@ pub fn parachain_genesis(
"currencies": accepted_assets,
"accountCurrencies": Vec::<(AccountId, AssetId)>::new(),
},
"parameters": {
"isTestnet": is_testnet,
},
"tokens": {
"balances": if registered_assets.is_empty() {
vec![]
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec/rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub fn _parachain_config_rococo() -> Result<ChainSpec, String> {
Default::default(),
// parachain ID
PARA_ID.into(),
// is_testnet
false,
// duster
DusterConfig {
// treasury
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub fn parachain_config() -> Result<ChainSpec, String> {
Default::default(),
// parachain ID
PARA_ID.into(),
// is_testnet
false,
// duster
DusterConfig {
// treasury
Expand Down
54 changes: 35 additions & 19 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::{sync::Arc, time::Duration};

use cumulus_client_cli::CollatorOptions;
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_aura::collators::slot_based::{SlotBasedBlockImport, SlotBasedBlockImportHandle};
use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
use cumulus_client_consensus_proposer::Proposer;
use cumulus_client_service::{
Expand All @@ -38,7 +39,7 @@ use cumulus_primitives_core::{
relay_chain::{CollatorPair, ValidationCode},
ParaId,
};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
use cumulus_relay_chain_interface::RelayChainInterface;

use fc_db::kv::Backend as FrontierBackend;
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
Expand Down Expand Up @@ -74,7 +75,8 @@ type ParachainClient = TFullClient<

type ParachainBackend = TFullBackend<Block>;

type ParachainBlockImport = TParachainBlockImport<Block, Arc<ParachainClient>, ParachainBackend>;
type ParachainBlockImport =
TParachainBlockImport<Block, SlotBasedBlockImport<Block, Arc<ParachainClient>, ParachainClient>, ParachainBackend>;

pub struct TxDetailProvider;
impl TransactionDetailProvider for TxDetailProvider {
Expand Down Expand Up @@ -136,6 +138,7 @@ pub fn new_partial(
sc_transaction_pool::TransactionPoolHandle<Block, ParachainClient>,
(
evm::BlockImport<Block, ParachainBlockImport, ParachainClient>,
SlotBasedBlockImportHandle<Block>,
Option<Telemetry>,
Option<TelemetryWorkerHandle>,
Arc<FrontierBackend<Block, ParachainClient>>,
Expand Down Expand Up @@ -237,8 +240,9 @@ pub fn new_partial(
let evm_since = chain_spec::Extensions::try_get(&config.chain_spec)
.map(|e| e.evm_since)
.unwrap_or(1);
let (slot_based_block_import, block_import_handle) = SlotBasedBlockImport::new(client.clone(), client.clone());
let block_import = evm::BlockImport::new(
ParachainBlockImport::new(client.clone(), backend.clone()),
ParachainBlockImport::new(slot_based_block_import, backend.clone()),
client.clone(),
frontier_backend.clone(),
evm_since,
Expand All @@ -265,6 +269,7 @@ pub fn new_partial(
select_chain: (),
other: (
block_import,
block_import_handle,
telemetry,
telemetry_worker_handle,
frontier_backend,
Expand All @@ -290,8 +295,15 @@ async fn start_node_impl(
let parachain_config = prepare_node_config(parachain_config);

let params = new_partial(&parachain_config, no_tx_priority_override)?;
let (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, filter_pool, fee_history_cache) =
params.other;
let (
block_import,
block_import_handle,
mut telemetry,
telemetry_worker_handle,
frontier_backend,
filter_pool,
fee_history_cache,
) = params.other;

let prometheus_registry = parachain_config.prometheus_registry().cloned();
let net_config = sc_network::config::FullNetworkConfiguration::<_, _, sc_network::NetworkWorker<Block, Hash>>::new(
Expand Down Expand Up @@ -507,6 +519,7 @@ async fn start_node_impl(
client.clone(),
backend,
block_import,
block_import_handle,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
&task_manager,
Expand All @@ -516,7 +529,6 @@ async fn start_node_impl(
relay_chain_slot_duration,
para_id,
collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle,
announce_block,
)?;
}
Expand Down Expand Up @@ -557,6 +569,7 @@ fn start_consensus(
client: Arc<ParachainClient>,
backend: Arc<ParachainBackend>,
block_import: evm::BlockImport<Block, ParachainBlockImport, ParachainClient>,
block_import_handle: SlotBasedBlockImportHandle<Block>,
prometheus_registry: Option<&Registry>,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
Expand All @@ -566,13 +579,9 @@ fn start_consensus(
relay_chain_slot_duration: Duration,
para_id: ParaId,
collator_key: CollatorPair,
overseer_handle: OverseerHandle,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
) -> Result<(), sc_service::Error> {
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams};

// NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant`
// when starting the network.
use cumulus_client_consensus_aura::collators::slot_based::{self as slot_based, Params as SlotBasedParams};

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
Expand All @@ -591,8 +600,8 @@ fn start_consensus(
client.clone(),
);

// let (client_clone, relay_chain_interface_clone) = (client.clone(), relay_chain_interface.clone());
let params = AuraParams {
let client_for_aura = client.clone();
let params = SlotBasedParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
// FIXME: Disabled due to https://github.com/galacticcouncil/hydration-node/issues/1346
// create_inherent_data_providers: move |parent, ()| {
Expand All @@ -610,21 +619,28 @@ fn start_consensus(
para_client: client.clone(),
para_backend: backend.clone(),
relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash()),
code_hash_provider: move |block_hash| {
client_for_aura
.code_at(block_hash)
.ok()
.map(|c| ValidationCode::from(c).hash())
},
keystore,
collator_key,
para_id,
overseer_handle,
relay_chain_slot_duration,
proposer,
collator_service,
authoring_duration: Duration::from_millis(1500),
reinitialize: false,
max_pov_percentage: None, // Defaults to 85% of max PoV size (safe default)
slot_offset: Duration::from_secs(1),
block_import_handle,
spawner: task_manager.spawn_handle(),
relay_chain_slot_duration,
export_pov: None,
max_pov_percentage: None,
};

let fut = aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);
slot_based::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _, _>(params);

Ok(())
}
Expand Down
36 changes: 36 additions & 0 deletions pallets/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::manual_inspect)]

use core::marker::PhantomData;
#[cfg(test)]
pub mod mock;
#[cfg(test)]
Expand All @@ -51,11 +52,46 @@ pub mod pallet {
#[pallet::getter(fn is_testnet)]
pub type IsTestnet<T> = StorageValue<_, bool, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn relay_parent_offset_override)]
pub type RelayParentOffsetOverride<T> = StorageValue<_, bool, ValueQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub is_testnet: bool,
pub relay_parent_offset_override: bool,
pub _phantom: PhantomData<T>,
}

impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
is_testnet: false,
relay_parent_offset_override: false,
_phantom: PhantomData,
}
}
}

#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
IsTestnet::<T>::put(self.is_testnet);
RelayParentOffsetOverride::<T>::put(self.relay_parent_offset_override);
}
}

impl<T: Config> Pallet<T> {
/// Set the flag. Only used for tests.
#[cfg(feature = "std")]
pub fn set_testnet_flag(is_testnet: bool) {
IsTestnet::<T>::put(is_testnet);
}

/// Set the relay parent offset override. Only used for tests.
#[cfg(feature = "std")]
pub fn set_relay_parent_offset_override(override_enabled: bool) {
RelayParentOffsetOverride::<T>::put(override_enabled);
}
}
}
17 changes: 16 additions & 1 deletion pallets/parameters/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// $$$

use crate::mock::*;
use crate::{IsTestnet, Pallet as Parameters};
use crate::{IsTestnet, Pallet as Parameters, RelayParentOffsetOverride};

#[test]
fn is_testnet_false_by_default() {
Expand All @@ -42,3 +42,18 @@ fn is_testnet_true_when_set() {
assert!(Parameters::<Test>::is_testnet());
});
}

#[test]
fn relay_parent_offset_override_false_by_default() {
ExtBuilder.build().execute_with(|| {
assert!(!Parameters::<Test>::relay_parent_offset_override());
});
}

#[test]
fn relay_parent_offset_override_true_when_set() {
ExtBuilder.build().execute_with(|| {
RelayParentOffsetOverride::<Test>::put(true);
assert!(Parameters::<Test>::relay_parent_offset_override());
});
}
3 changes: 2 additions & 1 deletion primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ pub mod chain {
pub const STABLESWAP_SOURCE: [u8; 8] = *b"stablesw";
pub const XYK_SOURCE: [u8; 8] = *b"hydraxyk";

pub const DEFAULT_RELAY_PARENT_OFFSET: u32 = 1;
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
/// relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = (3 + DEFAULT_RELAY_PARENT_OFFSET) * BLOCK_PROCESSING_VELOCITY;
/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
/// blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
Expand Down
1 change: 1 addition & 0 deletions runtime-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub fn hydradx_mocked_runtime() -> TestExternalities {
duster: DusterConfig {
account_whitelist: vec![],
},
parameters: Default::default(),
omnipool_warehouse_lm: Default::default(),
omnipool_liquidity_mining: Default::default(),
evm_chain_id: hydradx_runtime::EVMChainIdConfig {
Expand Down
15 changes: 15 additions & 0 deletions runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,15 @@ impl_runtime_apis! {
}
}

impl cumulus_primitives_core::GetCoreSelectorApi<Block> for Runtime {
fn core_selector() -> (
cumulus_primitives_core::CoreSelector,
cumulus_primitives_core::ClaimQueueOffset,
) {
ParachainSystem::core_selector()
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down Expand Up @@ -1112,6 +1121,12 @@ impl_runtime_apis! {
}
}

impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
fn relay_parent_offset() -> u32 {
RelayParentOffset::get()
}
}

impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(
origin: OriginCaller,
Expand Down
18 changes: 15 additions & 3 deletions runtime/hydradx/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use pallet_transaction_multi_payment::{DepositAll, TransferFees, WeightInfo};
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use primitives::constants::{
chain::{
BLOCK_PROCESSING_VELOCITY, CORE_ASSET_ID, MAXIMUM_BLOCK_WEIGHT, RELAY_CHAIN_SLOT_DURATION_MILLIS,
UNINCLUDED_SEGMENT_CAPACITY,
BLOCK_PROCESSING_VELOCITY, CORE_ASSET_ID, DEFAULT_RELAY_PARENT_OFFSET, MAXIMUM_BLOCK_WEIGHT,
RELAY_CHAIN_SLOT_DURATION_MILLIS, UNINCLUDED_SEGMENT_CAPACITY,
},
currency::{deposit, CENTS, DOLLARS, MILLICENTS},
time::{DAYS, HOURS, SLOT_DURATION},
Expand Down Expand Up @@ -286,6 +286,18 @@ pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
UNINCLUDED_SEGMENT_CAPACITY,
>;

pub struct RelayParentOffset;

impl Get<u32> for RelayParentOffset {
fn get() -> u32 {
if Parameters::relay_parent_offset_override() {
0
} else {
DEFAULT_RELAY_PARENT_OFFSET
}
}
}

impl cumulus_pallet_parachain_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnSystemEvent = pallet_relaychain_info::OnValidationDataHandler<Runtime>;
Expand All @@ -299,7 +311,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type WeightInfo = weights::cumulus_pallet_parachain_system::HydraWeight<Runtime>;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type RelayParentOffset = ConstU32<0>;
type RelayParentOffset = RelayParentOffset;
}

parameter_types! {
Expand Down
Loading