Skip to content

Commit

Permalink
Merge branch 'master' into replace-ansi_term
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Jul 20, 2024
2 parents 3b106cc + 59e3315 commit 8631296
Show file tree
Hide file tree
Showing 113 changed files with 2,164 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-node@v4.0.1
- uses: actions/setup-node@v4.0.3
with:
node-version: "18.x"
registry-url: "https://npm.pkg.github.com"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checks-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: actions/setup-node@v4.0.1
uses: actions/setup-node@v4.0.3
with:
node-version: "18.x"
registry-url: "https://npm.pkg.github.com"
Expand Down
88 changes: 86 additions & 2 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ members = [
"bridges/snowbridge/primitives/router",
"bridges/snowbridge/runtime/runtime-common",
"bridges/snowbridge/runtime/test-common",
"cumulus/bin/pov-validator",
"cumulus/client/cli",
"cumulus/client/collator",
"cumulus/client/consensus/aura",
Expand Down Expand Up @@ -90,6 +91,8 @@ members = [
"cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo",
"cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo",
"cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal",
Expand All @@ -104,6 +107,8 @@ members = [
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend",
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-rococo",
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend",
"cumulus/parachains/integration-tests/emulated/tests/people/people-rococo",
"cumulus/parachains/integration-tests/emulated/tests/people/people-westend",
"cumulus/parachains/pallets/collective-content",
Expand Down Expand Up @@ -666,7 +671,9 @@ colored = { version = "2.0.4" }
comfy-table = { version = "7.1.0", default-features = false }
console = { version = "0.15.8" }
contracts-rococo-runtime = { path = "cumulus/parachains/runtimes/contracts/contracts-rococo" }
coretime-rococo-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo" }
coretime-rococo-runtime = { path = "cumulus/parachains/runtimes/coretime/coretime-rococo" }
coretime-westend-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend" }
coretime-westend-runtime = { path = "cumulus/parachains/runtimes/coretime/coretime-westend" }
cpu-time = { version = "1.0.0" }
criterion = { version = "0.5.1", default-features = false }
Expand Down
26 changes: 26 additions & 0 deletions cumulus/bin/pov-validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "cumulus-pov-validator"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true
homepage.workspace = true
description = "A tool for validating PoVs locally"

[dependencies]
codec.workspace = true
clap = { workspace = true, features = ["derive"] }
sc-executor.workspace = true
sp-io.workspace = true
sp-core.workspace = true
sp-maybe-compressed-blob.workspace = true
polkadot-node-primitives.workspace = true
polkadot-parachain-primitives.workspace = true
polkadot-primitives.workspace = true
anyhow.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[lints]
workspace = true
154 changes: 154 additions & 0 deletions cumulus/bin/pov-validator/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// This file is part of Cumulus.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program 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.

// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

use clap::Parser;
use codec::{Decode, Encode};
use polkadot_node_primitives::{BlockData, PoV, POV_BOMB_LIMIT, VALIDATION_CODE_BOMB_LIMIT};
use polkadot_parachain_primitives::primitives::ValidationParams;
use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash, HeadData};
use sc_executor::WasmExecutor;
use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode, WrappedRuntimeCode};
use std::{fs, path::PathBuf, time::Instant};
use tracing::level_filters::LevelFilter;

/// Tool for validating a `PoV` locally.
#[derive(Parser)]
struct Cli {
/// The path to the validation code that should be used to validate the `PoV`.
///
/// The validation code can either be downloaded from the relay chain that the parachain is
/// connected to or by building the runtime manually to obtain the WASM binary.
#[arg(long)]
validation_code: PathBuf,

/// The path to the `PoV` to validate.
///
/// The `PoV`'s can be obtained by running `polkadot-parachains --collator --chain YOUR_CHAIN
/// --export-pov-to-path PATH_TO_EXPORT` and then choose one of the exported `PoV`'s.
#[arg(long)]
pov: PathBuf,
}

fn main() -> anyhow::Result<()> {
let _ = tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env()
.add_directive(LevelFilter::INFO.into()),
)
.with_writer(std::io::stderr)
.try_init();

let cli = Cli::parse();

let validation_code = fs::read(&cli.validation_code).map_err(|error| {
tracing::error!(%error, path = %cli.validation_code.display(), "Failed to read validation code");
anyhow::anyhow!("Failed to read validation code")
})?;

let validation_code =
sp_maybe_compressed_blob::decompress(&validation_code, VALIDATION_CODE_BOMB_LIMIT)
.map_err(|error| {
tracing::error!(%error, "Failed to decompress validation code");
anyhow::anyhow!("Failed to decompress validation code")
})?;

let pov_file = fs::read(&cli.pov).map_err(|error| {
tracing::error!(%error, path = %cli.pov.display(), "Failed to read PoV");
anyhow::anyhow!("Failed to read PoV")
})?;

let executor = WasmExecutor::<sp_io::SubstrateHostFunctions>::builder()
.with_allow_missing_host_functions(true)
.build();

let runtime_code = RuntimeCode {
code_fetcher: &WrappedRuntimeCode(validation_code.into()),
heap_pages: None,
// The hash is used for caching, which we need here, but we only use one wasm file. So, the
// actual hash is not that important.
hash: vec![1, 2, 3],
};

// We are calling `Core_version` to get the wasm file compiled. We don't care about the result.
let _ = executor
.call(
&mut sp_io::TestExternalities::default().ext(),
&runtime_code,
"Core_version",
&[],
CallContext::Offchain,
)
.0;

let pov_file_ptr = &mut &pov_file[..];
let pov = PoV::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to decode `PoV`");
anyhow::anyhow!("Failed to decode `PoV`")
})?;
let head_data = HeadData::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to `HeadData`");
anyhow::anyhow!("Failed to decode `HeadData`")
})?;
let relay_parent_storage_root = RHash::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to relay storage root");
anyhow::anyhow!("Failed to decode relay storage root")
})?;
let relay_parent_number = RBlockNumber::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to relay block number");
anyhow::anyhow!("Failed to decode relay block number")
})?;

let pov = sp_maybe_compressed_blob::decompress(&pov.block_data.0, POV_BOMB_LIMIT).map_err(
|error| {
tracing::error!(%error, "Failed to decompress `PoV`");
anyhow::anyhow!("Failed to decompress `PoV`")
},
)?;

let validation_params = ValidationParams {
relay_parent_number,
relay_parent_storage_root,
parent_head: head_data,
block_data: BlockData(pov.into()),
};

tracing::info!("Starting validation");

let start = Instant::now();

let res = executor
.call(
&mut sp_io::TestExternalities::default().ext(),
&runtime_code,
"validate_block",
&validation_params.encode(),
CallContext::Offchain,
)
.0;

let duration = start.elapsed();

match res {
Ok(_) => tracing::info!("Validation was successful"),
Err(error) => tracing::error!(%error, "Validation failed"),
}

tracing::info!("Validation took {}ms", duration.as_millis());

Ok(())
}
Loading

0 comments on commit 8631296

Please sign in to comment.