Skip to content

Commit

Permalink
Merge branch 'master' into combine-remove-paraids-and-collator-assign…
Browse files Browse the repository at this point in the history
…ment-hook
  • Loading branch information
tmpolaczyk authored Nov 25, 2024
2 parents 3152372 + be79416 commit 8620e17
Show file tree
Hide file tree
Showing 17 changed files with 905 additions and 120 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

38 changes: 0 additions & 38 deletions client/service-container-chain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,11 @@
use {
sc_chain_spec::{ChainSpecExtension, ChainSpecGroup},
serde::{Deserialize, Serialize},
std::collections::BTreeMap,
};

/// Specialized `ChainSpec` for container chains that only allows raw genesis format.
pub type RawChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Helper type that implements the traits needed to be used as a "GenesisConfig",
/// but whose implementation panics because we only expect it to be used with raw ChainSpecs,
/// so it will never be serialized or deserialized.
/// This is because container chains must use raw chain spec files where the "genesis"
/// field only has one field: "raw".
pub struct RawGenesisConfig {
pub storage_raw: BTreeMap<Vec<u8>, Vec<u8>>,
}

impl Serialize for RawGenesisConfig {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
panic!("RawGenesisConfigDummy should never be serialized")
}
}

impl<'de> Deserialize<'de> for RawGenesisConfig {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
panic!("Attempted to read a non-raw ContainerChain ChainSpec.\nHelp: add `--raw` flag to `build-spec` command to generate a raw chain spec")
}
}

impl sp_runtime::BuildStorage for RawGenesisConfig {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
storage
.top
.extend(self.storage_raw.iter().map(|(k, v)| (k.clone(), v.clone())));

Ok(())
}
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
Expand Down
6 changes: 1 addition & 5 deletions client/service-container-chain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::chain_spec::RawGenesisConfig,
cumulus_client_cli::{CollatorOptions, RelayChainMode},
dc_orchestrator_chain_interface::ContainerChainGenesisData,
dp_container_chain_genesis_data::json::properties_to_map,
Expand Down Expand Up @@ -181,9 +180,6 @@ impl ContainerChainCli {
relay_chain,
para_id,
};
let raw_genesis_config = RawGenesisConfig {
storage_raw: storage_raw.clone(),
};

let chain_spec = crate::chain_spec::RawChainSpec::builder(
// This code is not used, we override it in `set_storage` below
Expand All @@ -210,7 +206,7 @@ impl ContainerChainCli {
let mut chain_spec = chain_spec.build();

chain_spec.set_storage(Storage {
top: raw_genesis_config.storage_raw,
top: storage_raw,
children_default: Default::default(),
});

Expand Down
28 changes: 15 additions & 13 deletions pallets/external-validators/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use {
frame_support::traits::{Currency, EnsureOrigin, Get},
frame_system::{EventRecord, RawOrigin},
pallet_session::{self as session, SessionManager},
sp_runtime::traits::Convert,
rand::{RngCore, SeedableRng},
sp_runtime::{codec, traits::Convert},
sp_std::prelude::*,
};
const SEED: u32 = 0;
Expand All @@ -52,21 +53,22 @@ fn create_funded_user<T: Config + pallet_balances::Config>(
user
}

fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};

let keys = {
let mut keys = [0u8; 256];
struct InputFromRng<'a, T>(&'a mut T);
impl<'a, T: RngCore> codec::Input for InputFromRng<'a, T> {
fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
Ok(None)
}

if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));
rng.fill_bytes(&mut keys);
}
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
self.0.fill_bytes(into);
Ok(())
}
}

keys
};
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));

Decode::decode(&mut &keys[..]).unwrap()
Decode::decode(&mut InputFromRng(&mut rng)).unwrap()
}

fn invulnerable<T: Config + session::Config + pallet_balances::Config>(
Expand Down
28 changes: 15 additions & 13 deletions pallets/invulnerables/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use {
},
frame_system::{EventRecord, RawOrigin},
pallet_session::{self as session, SessionManager},
sp_runtime::traits::AtLeast32BitUnsigned,
rand::{RngCore, SeedableRng},
sp_runtime::{codec, traits::AtLeast32BitUnsigned},
sp_std::prelude::*,
tp_traits::DistributeRewards,
};
Expand Down Expand Up @@ -56,21 +57,22 @@ fn create_funded_user<T: Config + pallet_balances::Config>(
user
}

fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};

let keys = {
let mut keys = [0u8; 128];
struct InputFromRng<'a, T>(&'a mut T);
impl<'a, T: RngCore> codec::Input for InputFromRng<'a, T> {
fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
Ok(None)
}

if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));
rng.fill_bytes(&mut keys);
}
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
self.0.fill_bytes(into);
Ok(())
}
}

keys
};
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));

Decode::decode(&mut &keys[..]).unwrap()
Decode::decode(&mut InputFromRng(&mut rng)).unwrap()
}

fn invulnerable<T: Config + session::Config + pallet_balances::Config>(
Expand Down
2 changes: 2 additions & 0 deletions solo-chains/node/tanssi-relay-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sp-api = { workspace = true }
sp-authority-discovery = { workspace = true }
sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true, features = [ "std" ] }
sp-inherents = { workspace = true, features = [ "std" ] }
Expand Down Expand Up @@ -81,6 +82,7 @@ async-io = { workspace = true }
async-trait = { workspace = true }
bitvec = { workspace = true, optional = true }
codec = { workspace = true }
flume = { workspace = true }
futures = { workspace = true }
gum = { workspace = true }
hex-literal = { workspace = true }
Expand Down
81 changes: 81 additions & 0 deletions solo-chains/node/tanssi-relay-service/src/dev_rpcs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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/>

//! Development Polkadot service. Adapted from `polkadot_service` crate
//! and removed un-necessary components which are not required in dev node.
use codec::Encode;
use jsonrpsee::{
core::RpcResult,
proc_macros::rpc,
types::{
error::{INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG},
ErrorObjectOwned,
},
};

/// This RPC interface is used to provide methods in dev mode only
#[rpc(server)]
#[jsonrpsee::core::async_trait]
pub trait DevApi {
/// Indicate the mock parachain candidate insertion to be active
#[method(name = "mock_enableParaInherentCandidate")]
async fn enable_para_inherent_candidate(&self) -> RpcResult<()>;

/// Indicate the mock parachain candidate insertion to be disabled
#[method(name = "mock_disableParaInherentCandidate")]
async fn disable_para_inherent_candidate(&self) -> RpcResult<()>;
}

pub struct DevRpc {
pub mock_para_inherent_channel: flume::Sender<Vec<u8>>,
}

#[jsonrpsee::core::async_trait]
impl DevApiServer for DevRpc {
async fn enable_para_inherent_candidate(&self) -> RpcResult<()> {
let mock_para_inherent_channel = self.mock_para_inherent_channel.clone();
// Push the message to the shared channel where it will be queued up
// to be injected in to an upcoming block.
mock_para_inherent_channel
.send_async(true.encode())
.await
.map_err(|err| internal_err(err.to_string()))?;

Ok(())
}

async fn disable_para_inherent_candidate(&self) -> RpcResult<()> {
let mock_para_inherent_channel = self.mock_para_inherent_channel.clone();
// Push the message to the shared channel where it will be queued up
// to be injected in to an upcoming block.
mock_para_inherent_channel
.send_async(false.encode())
.await
.map_err(|err| internal_err(err.to_string()))?;

Ok(())
}
}

// This bit cribbed from frontier.
pub fn internal_err<T: ToString>(message: T) -> ErrorObjectOwned {
ErrorObjectOwned::owned(
INTERNAL_ERROR_CODE,
INTERNAL_ERROR_MSG,
Some(message.to_string()),
)
}
Loading

0 comments on commit 8620e17

Please sign in to comment.