Skip to content

Commit

Permalink
Merge branch 'pallet-communities-benchmarking-runtime-parameters' int…
Browse files Browse the repository at this point in the history
…o jgutierrezre-pallet-communities-benchmarking-runtime-parameters
  • Loading branch information
pandres95 committed Mar 8, 2024
2 parents 8c838da + a557da3 commit f15d67c
Show file tree
Hide file tree
Showing 24 changed files with 1,267 additions and 1,165 deletions.
1,035 changes: 537 additions & 498 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
bs58 = { version = "0.5.0", default-features = false }
wasm-bindgen = { version = "0.2.87", optional = true }

pallet-payments = { workspace = true, optional = true }
frame-support = { workspace = true, optional = true }
parity-scale-codec = { workspace = true, optional = true }
scale-info = { workspace = true, optional = true }
Expand All @@ -19,4 +20,9 @@ default = ["runtime"]
alloc = []
js = ["alloc", "wasm-bindgen"]
nightly = []
runtime = ["dep:frame-support", "dep:parity-scale-codec", "dep:scale-info"]
runtime = [
"dep:frame-support",
"dep:parity-scale-codec",
"dep:scale-info",
"dep:pallet-payments",
]
44 changes: 43 additions & 1 deletion common/src/payment_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use wasm_bindgen::prelude::*;

/// A compact identifier for payment
#[cfg_attr(feature = "js", wasm_bindgen)]
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Eq, Copy, PartialEq)]
#[repr(C)]
pub struct PaymentId {
prefix: [u8; 2],
Expand Down Expand Up @@ -126,6 +126,48 @@ impl core::fmt::Display for PaymentId {
}
}

// Manual implementation of Encode/Decode/TypeInfo to treat PaymentId like a u64
#[cfg(feature = "runtime")]
mod runtime {
use super::PaymentId;
use core::mem;
use parity_scale_codec::{Decode, Encode, EncodeLike, Error, Input, MaxEncodedLen};
use scale_info::{TypeDefPrimitive, TypeInfo};

impl EncodeLike for PaymentId {}

impl MaxEncodedLen for PaymentId {
fn max_encoded_len() -> usize {
mem::size_of::<u64>()
}
}
impl Encode for PaymentId {
fn size_hint(&self) -> usize {
mem::size_of::<u64>()
}
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
let buf = self.to_number().to_le_bytes();
f(&buf[..])
}
}
impl Decode for PaymentId {
fn decode<I: Input>(input: &mut I) -> Result<Self, Error> {
let mut buf = [0u8; mem::size_of::<u64>()];
input.read(&mut buf)?;
Ok(<u64>::from_le_bytes(buf).into())
}
fn encoded_fixed_size() -> Option<usize> {
Some(mem::size_of::<u64>())
}
}
impl TypeInfo for PaymentId {
type Identity = u64;
fn type_info() -> scale_info::Type {
TypeDefPrimitive::U64.into()
}
}
}

#[cfg(all(test, feature = "nightly"))]
mod tests {
extern crate alloc;
Expand Down
64 changes: 40 additions & 24 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NOTE: This justfile relies heavily on nushell, make sure to install it: https://www.nushell.sh
set shell := ["nu", "-c"]
podman := `(which podman) ++ (which docker) | (first).path` # use podman otherwise docker
ver := `open node/Cargo.toml | get package.version`
Expand Down Expand Up @@ -66,36 +67,38 @@ build-container-local: build-local
CMD ["--dev"]'
| {{ podman }} build . -t {{ image }}:{{ ver }} -t {{ image }}:latest -f -

### container set-up with base configuration ###
node_args := "--base-path /data '$NODE_ARGS' " + if rol == "collator" {
"--collator"
} else { "--rpc-external --rpc-cors=all" }
container_args := node_args + " -- '$RELAY_ARGS' --sync=warp --state-pruning=200 --blocks-pruning=200 --no-telemetry --chain " + relay + if rol == "full" {
" --rpc-external --rpc-cors=all"
} else { "" }
container_name := chain + "-" + rol
container_net := "podman6"
expose_rpc := if rol == "full" { " -p 9944:9944 -p 9945:9945" } else { "" }

create-container:
@^mkdir -p release
podman rm -f {{ container_name }}
podman network create --ignore --ipv6 {{ container_net }}
podman create --name {{ container_name }}{{ expose_rpc }} -p 30333:30333 -p 30334:30334 -p 9615:9615 --network {{ container_net }} --volume {{ container_name }}-data:/data {{ image }} {{ container_args }}
podman generate systemd --new --no-header --env 'NODE_ARGS=' --env 'RELAY_ARGS=' --name {{ container_name }} | str replace -a '$$' '$' | save -f release/container-{{ chain }}-{{ rol }}.service
open release/container-{{ chain }}-{{ rol }}.service | str replace "ExecStart" "ExecStartPre=/bin/rm -f %t/%n.ctr-id\nExecStart" | save -f release/container-{{ chain }}-{{ rol }}.service

_chain_artifacts:
@^mkdir -p release
_parachain_launch_artifacts:
@mkdir release
{{ node }} export-genesis-state --chain {{ chain }} | save -f release/{{ chain }}_genesis
{{ node }} export-genesis-wasm --chain {{ chain }} | save -f release/{{ chain }}_genesis.wasm
{{ node }} build-spec --disable-default-bootnode --chain {{ chain }} | save -f release/{{ chain }}_chainspec.json

release-artifacts: build-local create-container
release-artifacts:
@mkdir release; rm -f release/*
cp target/release/wbuild/{{ chain }}-runtime/{{ chain }}_runtime.compact.compressed.wasm release/
cp *.container release

release-tag:
git tag {{ ver }}

bump mode="minor":
#!/usr/bin/env nu
let ver = '{{ ver }}' | inc --{{ mode }}
open -r runtime/kreivo/Cargo.toml | str replace -m '^version = "(.+)"$' $'version = "($ver)"' | save -f runtime/kreivo/Cargo.toml
open -r node/Cargo.toml | str replace -m '^version = "(.+)"$' $'version = "($ver)"' | save -f node/Cargo.toml
# bump spec version
const SRC = 'runtime/kreivo/src/lib.rs'
let src = open $SRC
let spec_ver = ($src | grep spec_version | parse -r '\s*spec_version: (?<ver>\w+),' | first | get ver | into int)
$src | str replace -m '(\s*spec_version:) (\w+)' $'$1 ($spec_ver | $in + 1)' | save -f $SRC
# assume minor and major versions channge tx version
let bump_tx = '{{ mode }}' == 'minor' or '{{ mode }}' == 'major'
if $bump_tx {
let src = open $SRC
let tx_ver = ($src | grep transaction_version | parse -r '\s*transaction_version: (?<ver>\w+),' | first | get ver | into int)
$src | str replace -m '(\s*transaction_version:) (\w+)' $'$1 ($tx_ver | $in + 1)' | save -f $SRC
}

_zufix := os() + if os() == "linux" { "-x64" } else { "" }
zombienet network="": build-local
#!/usr/bin/env nu
Expand All @@ -107,11 +110,24 @@ zombienet network="": build-local
}
bin/zombienet-{{ _zufix }} -p native spawn $"zombienet/($net).toml"

get-zombienet-dependencies: (_get-latest "zombienet" "zombienet-"+_zufix) (_get-latest "polkadot" "polkadot") (_get-latest "cumulus" "polkadot-parachain")
get-zombienet-dependencies: (_get-latest "zombienet" "zombienet-"+_zufix) (_get-latest "cumulus" "polkadot-parachain") compile-polkadot-for-zombienet

compile-polkadot-for-zombienet:
#!/usr/bin/env nu
mkdir bin
# Compile polkadot with fast-runtime feature
let polkadot = (open Cargo.toml | get workspace.dependencies.sp-core)
let dir = (mktemp -d polkadot-sdk.XXX)
git clone --branch $polkadot.branch --depth 1 $polkadot.git $dir
echo $"(ansi defb)Compiling Polkadot(ansi reset) \(($polkadot.git):($polkadot.branch)\)"
cargo build --manifest-path ($dir | path join Cargo.toml) --locked --profile testnet --features fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker
mv -f ($dir | path join target/testnet/polkadot) bin/
mv -f ($dir | path join target/testnet/polkadot-prepare-worker) bin/
mv -f ($dir | path join target/testnet/polkadot-execute-worker) bin/

_get-latest repo bin:
#!/usr/bin/env nu
^mkdir -p bin
mkdir bin
http get https://api.github.com/repos/paritytech/{{ repo }}/releases
# cumulus has two kinds of releases, we exclude runtimes
| where "tag_name" !~ "parachains" | first | get assets_url | http get $in
Expand Down
32 changes: 32 additions & 0 deletions kreivo-collator.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[Unit]
Description=Kreivo Collator container
After=network-online.target

[Service]
Environment=BOOTNODES="/dns/eu1.virto.one/tcp/30333/p2p/12D3KooWJY4iZrxXR8iz4185XTdmiuHAGvGRLXKbJ1qoFZSysTwc"
Environment=RELAY_ARGS
Environment=NODE_ARGS

[Container]
Image=ghcr.io/virto-network/virto:latest
ContainerName=kreivo-collator
Volume=kreivo-collator-data:/data
# an IPv6 capable podman network
Network=podman6
PublishPort=30333:30333
PublishPort=30334:30334
PublishPort=9615:9615
LogDriver=passthrough
Exec=--name kreivo-collator-%H \
--collator \
--bootnodes $BOOTNODES \
--base-path /data $NODE_ARGS \
-- $RELAY_ARGS \
--chain kusama \
--sync=warp \
--state-pruning=200 \
--blocks-pruning=200 \
--no-telemetry

[Install]
WantedBy=multi-user.target default.target
37 changes: 37 additions & 0 deletions kreivo-full.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[Unit]
Description=Kreivo full node container
After=network-online.target

[Service]
Environment=BOOTNODES="/dns/eu1.virto.one/tcp/30333/p2p/12D3KooWJY4iZrxXR8iz4185XTdmiuHAGvGRLXKbJ1qoFZSysTwc"
Environment=NODE_ARGS
Environment=RELAY_ARGS

[Container]
Image=ghcr.io/virto-network/virto:latest
ContainerName=kreivo-full
Volume=kreivo-full-data:/data
# an IPv6 capable podman network
Network=podman6
PublishPort=9944:9944
PublishPort=9945:9945
PublishPort=30333:30333
PublishPort=30334:30334
PublishPort=9615:9615
LogDriver=passthrough
Exec=--name kreivo-%H \
--rpc-external \
--rpc-cors=all \
--pruning archive-canonical \
--bootnodes $BOOTNODES \
--base-path /data $NODE_ARGS \
-- $RELAY_ARGS \
--chain kusama \
--rpc-external \
--sync=warp \
--state-pruning=200 \
--blocks-pruning=200 \
--no-telemetry

[Install]
WantedBy=multi-user.target default.target
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "virto-node"
version = "0.6.0"
version = "0.7.3"
authors = ['Virto Team <[email protected]>']
license = "GPL-3.0-only"
homepage = 'https://github.com/virto-network/virto-node'
Expand Down
87 changes: 2 additions & 85 deletions node/src/chain_spec/kreivo.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION};
use cumulus_primitives_core::ParaId;

use hex_literal::hex;
use kreivo_runtime::{constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AuraId, SessionKeys};
use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_core::sr25519;

const DEFAULT_PROTOCOL_ID: &str = "kreivo";

Expand Down Expand Up @@ -176,47 +175,7 @@ pub fn local_testnet_config() -> ChainSpec {
}

pub fn kreivo_kusama_chain_spec() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 2.into());

#[allow(deprecated)]
ChainSpec::builder(
kreivo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "kusama".into(),
// You MUST set this to the correct network!
para_id: KREIVO_PARA_ID,
},
)
.with_name("Kreivo")
.with_id("kreivo")
.with_chain_type(ChainType::Live)
.with_genesis_config_patch(genesis(
// initial collators.
vec![
(
hex!("203aec61cedbfa0cd23f183a972b8646794b9106e62d141c6af4fbbbe293847b").into(),
hex!("203aec61cedbfa0cd23f183a972b8646794b9106e62d141c6af4fbbbe293847b").unchecked_into(),
),
(
hex!("74d538cee938b3f988567a3d0ad4b0dd84735ceab8b51cdfb850ecf58accfd7e").into(),
hex!("74d538cee938b3f988567a3d0ad4b0dd84735ceab8b51cdfb850ecf58accfd7e").unchecked_into(),
),
],
vec![
hex!("68170716ab7c6735dd0a1012045d9ea33891b5f6596cf97eb217d0962d86a518").into(),
hex!("556d3b25d068997f358622cc0f9531e4175d0d10d8ae8511c091d61efc21f65c").into(),
hex!("8a0b6ddc780dbeb1c943caeadc7d09d85b2dc5b74026153f7931e068390d4441").into(),
],
hex!("7b953019065b4342a4f1fcf62be8f3e83c8d15303b674fd7191e598f699e764f").into(),
KREIVO_PARA_ID.into(),
))
.with_protocol_id(DEFAULT_PROTOCOL_ID)
.with_properties(properties)
.build()
ChainSpec::from_json_bytes(include_bytes!("kreivo_chainspec.json").as_slice()).unwrap()
}

fn testnet_genesis(
Expand Down Expand Up @@ -254,45 +213,3 @@ fn testnet_genesis(
"sudo": { "key": Some(root) }
})
}

fn genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root: AccountId,
id: ParaId,
) -> serde_json::Value {
let balances: Vec<_> = endowed_accounts
.iter()
.cloned()
.chain(std::iter::once(root.clone()))
.map(|k| (k, 2_000_000_000_000_000u128))
.collect();
serde_json::json!({
"balances": {
"balances": balances
},
"parachainInfo": {
"parachainId": id,
},
"collatorSelection": {
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
},
"session": {
"keys": invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
session_keys(aura), // session keys
)
})
.collect::<Vec<_>>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root) },
})
}
84 changes: 84 additions & 0 deletions node/src/chain_spec/kreivo_chainspec.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pallets/communities/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use frame_system::{
RawOrigin,
};
use sp_runtime::traits::StaticLookup;
use sp_std::{vec, vec::Vec};

fn assert_has_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_has_event(generic_event.into());
Expand Down
Loading

0 comments on commit f15d67c

Please sign in to comment.