Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block production #79

Merged
merged 16 commits into from
Apr 16, 2024
Merged
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 .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export POLKADOT_IMAGE=paritypr/polkadot-debug:v1.6.0
export REGIONX_IMAGE=szegoo/regionx-node:latest
29 changes: 29 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Dependency checks

on:
# Triggers the workflow on push or pull request events but only for the main branch
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

jobs:
check-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup

- name: Install Rust
run: |
rustup show
rustup toolchain install nightly
cargo install --git https://github.com/paritytech/psvm psvm

- name: Check Dependency Versions
run: |
chmod +x ./scripts/check-dependency-versions.sh
./scripts/check-dependency-versions.sh
41 changes: 41 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Smoke tests

# Controls when the action will run.
on:
workflow_dispatch:

jobs:
smoke:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Zombienet setup
run: |
wget https://github.com/paritytech/zombienet/releases/download/v1.3.100/zombienet-linux-x64
chmod +x zombienet-linux-x64
yes 2>/dev/null | ./zombienet-linux-x64 setup polkadot || true
echo $GITHUB_WORKSPACE
echo "PATH=$GITHUB_WORKSPACE:$PATH" >> $GITHUB_ENV
echo $PATH

- name: Pull Docker Image
run: docker pull szegoo/regionx-node:latest

- name: Create Container
id: create-container
run: |
container_id=$(docker create szegoo/regionx-node:latest)
echo "::set-output name=container_id::$container_id"

- name: Copy Executable from Container
run: |
docker cp ${{ steps.create-container.outputs.container_id }}:/usr/bin/regionx-node .

- name: Run smoke test 0001
run: ./zombienet-linux-x64 -p native test ./zombienet_tests/0001-smoke-test.zndsl
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# The cache for docker container dependency
/.cargo/config

bin/

.DS_Store
.idea
.vscode
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sp-consensus-beefy = { version = "13.0.0", default-features = false }
sp-core = { version = "28.0.0", default-features = false }
sp-inherents = { version = "26.0.0", default-features = false }
sp-offchain = { version = "26.0.0", default-features = false }
sp-runtime = { version = "31.0.1", default-features = false }
sp-runtime = { version = "31.0.0", default-features = false }
sp-session = { version = "27.0.0", default-features = false }
sp-std = { version = "14.0.0", default-features = false }
sp-transaction-pool = { version = "26.0.0", default-features = false }
Expand All @@ -66,9 +66,9 @@ sp-genesis-builder = { version = "0.7.0", default-features = false }
pallet-xcm = { version = "7.0.0", default-features = false }
polkadot-parachain-primitives = { version = "6.0.0", default-features = false }
polkadot-runtime-common = { version = "7.0.0", default-features = false }
xcm = { package = "staging-xcm", version = "7.0.0", default-features = false }
xcm-builder = { package = "staging-xcm-builder", version = "7.0.0", default-features = false }
xcm-executor = { package = "staging-xcm-executor", version = "7.0.0", default-features = false }
xcm = { version = "7.0.0", package = "staging-xcm", default-features = false }
xcm-builder = { version = "7.0.3", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "7.0.3", package = "staging-xcm-executor", default-features = false }
cumulus-primitives-aura = { version = "0.7.0", default-features = false }
cumulus-pallet-session-benchmarking = { version = "9.0.0", default-features = false }
cumulus-pallet-aura-ext = { version = "0.7.0", default-features = false }
Expand All @@ -78,14 +78,14 @@ cumulus-pallet-xcm = { version = "0.7.0", default-features = false }
cumulus-pallet-xcmp-queue = { version = "0.7.0", default-features = false }
cumulus-primitives-core = { version = "0.7.0", default-features = false }
cumulus-primitives-timestamp = { version = "0.7.0", default-features = false }
cumulus-primitives-utility = { version = "0.7.0", default-features = false }
cumulus-primitives-utility = { version = "0.7.3", default-features = false }
pallet-collator-selection = { version = "9.0.0", default-features = false }
parachain-info = { package = "staging-parachain-info", version = "0.7.0", default-features = false }
parachains-common = { version = "7.0.0", default-features = false }
parachain-info = { version = "0.7.0", package = "staging-parachain-info", default-features = false }
parachains-common = { version = "7.0.0", default-features = false }
sp-timestamp = { version = "26.0.0", default-features = false }
sp-keystore = { version = "0.34.0", default-features = false }
sp-mmr-primitives = { version = "26.0.0", default-features = false }
sp-storage = { version = "19.0.0", default-features = false }
sp-storage = { version = "19.0.0", default-features = false }
pallet-beefy-mmr = { version = "28.0.0", default-features = false }
pallet-mmr = { version = "27.0.0", default-features = false }

Expand Down
32 changes: 0 additions & 32 deletions Containerfile

This file was deleted.

23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:22.04

# show backtraces
ENV RUST_BACKTRACE 1

RUN useradd -m -u 1000 -U -s /bin/sh -d /regionx regionx && \
mkdir /data && \
chown -R regionx:regionx /data

ARG PROFILE=release

# copy the compiled binary to the container
COPY ./regionx-node /usr/bin/regionx-node

USER regionx

# check if executable works in this container
RUN /usr/bin/regionx-node --version

# ws_port
EXPOSE 9333 9944 30333 30334

CMD ["/usr/bin/regionx-node"]
21 changes: 10 additions & 11 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<(), Extensions>;
pub type ChainSpec<T> = sc_service::GenericChainSpec<T, Extensions>;

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
Expand Down Expand Up @@ -72,11 +72,11 @@ where
/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn template_session_keys(keys: AuraId) -> regionx_runtime::SessionKeys {
pub fn session_keys(keys: AuraId) -> regionx_runtime::SessionKeys {
regionx_runtime::SessionKeys { aura: keys }
}

pub fn development_config() -> ChainSpec {
pub fn development_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisConfig> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "REGX".into());
Expand Down Expand Up @@ -122,26 +122,25 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
2000.into(),
id.into(),
))
.build()
}

pub fn local_testnet_config() -> ChainSpec {
pub fn local_testnet_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisConfig> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "REGX".into());
properties.insert("tokenDecimals".into(), 12.into());
// TODO: chose an ss58Format
properties.insert("ss58Format".into(), 42.into());

#[allow(deprecated)]
ChainSpec::builder(
regionx_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 2000,
para_id: id,
},
)
.with_name("RegionX Local")
Expand Down Expand Up @@ -174,7 +173,7 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
2000.into(),
id.into(),
))
.with_protocol_id("regionx-local")
.with_properties(properties)
Expand Down Expand Up @@ -203,9 +202,9 @@ fn testnet_genesis(
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
template_session_keys(aura), // session keys
acc.clone(), // account id
acc, // validator id
session_keys(aura), // session keys
)
})
.collect::<Vec<_>>(),
Expand Down
12 changes: 8 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ use crate::{

fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"regionx-rococo" => Box::new(chain_spec::local_testnet_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
"dev" => Box::new(chain_spec::development_config(2000)),
"regionx-rococo" => Box::new(chain_spec::local_testnet_config(2000)),
"" | "local" => Box::new(chain_spec::local_testnet_config(2000)),
path => Box::new(
chain_spec::ChainSpec::<regionx_runtime::RuntimeGenesisConfig>::from_json_file(
std::path::PathBuf::from(path),
)?,
),
})
}

Expand Down
61 changes: 3 additions & 58 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use cumulus_client_service::{
BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
};
use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId};
use cumulus_relay_chain_interface::{OccupiedCoreAssumption, OverseerHandle, RelayChainInterface};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};

// Substrate Imports
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
Expand Down Expand Up @@ -410,64 +410,9 @@ fn start_consensus(
client.clone(),
);

let client_clone = client.clone();
let relay_chain_interface_clone = relay_chain_interface.clone();
let params = BasicAuraParams {
create_inherent_data_providers: move |parent, ()| {
let relay_chain_interface = relay_chain_interface_clone.clone();
let client = client_clone.clone();

let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

async move {
// TODO: Double check if this is correct
let maybe_validation_data = relay_chain_interface
.persisted_validation_data(parent, para_id, OccupiedCoreAssumption::Included)
.await?;

let validation_data = match maybe_validation_data {
Some(v) => v,
None =>
return Err(format!(
"Couldn't get persisted validation data at: {:?}",
parent
)
.into()),
};

let para_inherent_data =
cumulus_client_parachain_inherent::ParachainInherentDataProvider::create_at(
parent,
&relay_chain_interface.clone(),
&validation_data,
para_id,
)
.await;

let para_inherent_data = match para_inherent_data {
Some(p) => p,
None =>
return Err(
format!("Could not create para inherent data at {:?}", parent).into()
),
};

let consensus_inherent =
ismp_parachain_inherent::ConsensusInherentProvider::create(
client.clone(),
parent,
&relay_chain_interface,
validation_data,
)
.await?;

Ok((slot, timestamp, para_inherent_data, consensus_inherent))
}
},
// TODO:
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
relay_client: relay_chain_interface,
Expand Down
5 changes: 5 additions & 0 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,8 @@ impl_runtime_apis! {
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}
9 changes: 9 additions & 0 deletions scripts/check-dependency-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

output=$(psvm -v "1.6.0")

success="Dependencies in Cargo.toml are already up to date"

if [ "$output" != "$success" ]; then
exit 1
fi
Loading
Loading