Skip to content

Commit

Permalink
Update polkadot & substrate (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton authored Apr 15, 2020
1 parent 461b971 commit 7431075
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 602 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ charset=utf-8
trim_trailing_whitespace=true
max_line_length=100
insert_final_newline=true

[*.yml]
indent_style=space
indent_size=2
tab_width=8
end_of_line=lf

[*.sh]
indent_style=space
indent_size=4
tab_width=8
end_of_line=lf
690 changes: 306 additions & 384 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use polkadot_collator::{
PolkadotClient,
};
use polkadot_primitives::{
parachain::{self, BlockData, LocalValidationData, Id as ParaId}, Block as PBlock,
Hash as PHash,
parachain::{self, BlockData, GlobalValidationSchedule, LocalValidationData, Id as ParaId},
Block as PBlock, Hash as PHash,
};

use codec::{Decode, Encode};
Expand Down Expand Up @@ -111,15 +111,16 @@ where
fn produce_candidate(
&mut self,
_relay_chain_parent: PHash,
status: LocalValidationData,
_global_validation: GlobalValidationSchedule,
local_validation: LocalValidationData,
) -> Self::ProduceCandidate {
let factory = self.proposer_factory.clone();
let inherent_providers = self.inherent_data_providers.clone();
let block_import = self.block_import.clone();

trace!(target: "cumulus-collator", "Producing candidate");

let last_head = match HeadData::<Block>::decode(&mut &status.parent_head.0[..]) {
let last_head = match HeadData::<Block>::decode(&mut &local_validation.parent_head.0[..]) {
Ok(x) => x,
Err(e) => {
error!(target: "cumulus-collator", "Could not decode the head data: {:?}", e);
Expand Down Expand Up @@ -479,9 +480,15 @@ mod tests {
let collation = collate(
Default::default(),
id,
GlobalValidationSchedule {
block_number: 0,
max_code_size: 0,
max_head_data_size: 0,
},
LocalValidationData {
parent_head: HeadData(header.encode()),
balance: 10,
code_upgrade_allowed: None,
},
context,
Arc::new(Sr25519Keyring::Alice.pair().into()),
Expand Down
13 changes: 8 additions & 5 deletions runtime/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use hash_db::{HashDB, EMPTY_PREFIX};

use trie_db::{Trie, TrieDB};

use parachain::{ValidationParams, ValidationResult};
use parachain::primitives::{HeadData, ValidationParams, ValidationResult};

use codec::{Decode, Encode};

Expand Down Expand Up @@ -73,12 +73,12 @@ trait Storage {
/// Validate a given parachain block on a validator.
#[doc(hidden)]
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -> ValidationResult {
let block_data = crate::ParachainBlockData::<B>::decode(&mut &params.block_data[..])
let block_data = crate::ParachainBlockData::<B>::decode(&mut &params.block_data.0[..])
.expect("Invalid parachain block data");

let parent_head = B::Header::decode(&mut &params.parent_head[..]).expect("Invalid parent head");
let parent_head = B::Header::decode(&mut &params.parent_head.0[..]).expect("Invalid parent head");
// TODO: Use correct head data
let head_data = block_data.header.encode();
let head_data = HeadData(block_data.header.encode());

// TODO: Add `PolkadotInherent`.
let block = B::new(block_data.header, block_data.extrinsics);
Expand Down Expand Up @@ -110,7 +110,10 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -

E::execute_block(block);

ValidationResult { head_data }
ValidationResult {
head_data,
new_validation_code: None,
}
}

/// The storage implementation used when validating a block that is using the
Expand Down
12 changes: 8 additions & 4 deletions runtime/src/validate_block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{ParachainBlockData, WitnessData};

use parachain::{ValidationParams, ValidationResult};
use parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
use sc_executor::{
error::Result, WasmExecutionMethod, WasmExecutor, sp_wasm_interface::HostFunctions,
};
Expand Down Expand Up @@ -44,8 +44,12 @@ fn call_validate_block(
let mut ext = TestExternalities::default();
let mut ext_ext = ext.ext();
let params = ValidationParams {
block_data: block_data.encode(),
parent_head: parent_head.encode(),
block_data: BlockData(block_data.encode()),
parent_head: HeadData(parent_head.encode()),
code_upgrade_allowed: None,
max_code_size: 1024,
max_head_data_size: 1024,
relay_chain_height: 1,
}
.encode();

Expand All @@ -65,7 +69,7 @@ fn call_validate_block(
&mut ext_ext,
)
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data[..]).expect("Decode `Header`."))
.map(|v| Header::decode(&mut &v.head_data.0[..]).expect("Decode `Header`."))
.map_err(|err| err.into())
}

Expand Down
2 changes: 1 addition & 1 deletion test/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "c
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }

[build-dependencies]
vergen = '3.0.4'
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }

[dev-dependencies]
assert_cmd = "0.12"
Expand Down
7 changes: 3 additions & 4 deletions test/parachain/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

use std::{env, path::PathBuf};

use vergen::{generate_cargo_keys, ConstantsFlags};

const ERROR_MSG: &str = "Failed to generate metadata files";
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};

fn main() {
generate_cargo_keys(ConstantsFlags::SHA_SHORT).expect(ERROR_MSG);
generate_cargo_keys();
rerun_if_git_head_changed();

let mut manifest_dir = PathBuf::from(
env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
Expand Down
125 changes: 63 additions & 62 deletions test/parachain/res/polkadot_chainspec.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/parachain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn get_chain_spec() -> ChainSpec {
ChainSpec::from_genesis(
"Local Testnet",
"parachain_local_testnet",
sc_service::ChainType::Local,
|| {
testnet_genesis(
vec![
Expand Down
10 changes: 9 additions & 1 deletion test/parachain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::path::PathBuf;

use sc_cli;
pub use polkadot_cli::Cli as PolkadotCli;
use structopt::StructOpt;

/// Sub-commands supported by the collator.
Expand Down Expand Up @@ -55,3 +54,12 @@ pub struct Cli {
#[structopt(raw = true)]
pub relaychain_args: Vec<String>,
}

#[derive(Debug, StructOpt, Clone)]
pub struct PolkadotCli {
#[structopt(flatten)]
pub base: polkadot_cli::RunCmd,

#[structopt(skip)]
pub base_path: Option<PathBuf>,
}
Loading

0 comments on commit 7431075

Please sign in to comment.