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

Initial support of executor gossip #219

Merged
merged 16 commits into from
Dec 31, 2021
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
38 changes: 38 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"cumulus/client/cirrus-executor",
"cumulus/client/consensus/common",
"cumulus/client/consensus/relay-chain",
"cumulus/client/executor-gossip",
"cumulus/parachain-template/node",
"cumulus/parachain-template/runtime",
"cumulus/primitives",
Expand Down
12 changes: 6 additions & 6 deletions crates/cirrus-node-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
use sp_application_crypto::KeyTypeId;
use sp_consensus_slots::Slot;
use sp_core::bytes;
use sp_executor::{ExecutionReceipt, OpaqueBundle};
use sp_executor::{OpaqueBundle, OpaqueExecutionReceipt};
use sp_runtime::traits::Hash as HashT;
use std::pin::Pin;
use subspace_core_primitives::{Randomness, Tag};
Expand Down Expand Up @@ -94,14 +94,14 @@ impl BundleResult {
}

/// Result of the [`ProcessorFn`] invocation.
pub struct ProcessorResult<H = Hash> {
/// The execution receipt that was built.
pub execution_receipt: ExecutionReceipt<H>,
pub struct ProcessorResult {
/// The opaque execution receipt that was built.
pub opaque_execution_receipt: OpaqueExecutionReceipt,
}

impl ProcessorResult {
pub fn to_execution_receipt(self) -> ExecutionReceipt<Hash> {
self.execution_receipt
pub fn to_opaque_execution_receipt(self) -> OpaqueExecutionReceipt {
self.opaque_execution_receipt
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/pallet-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod pallet {
head_hash: T::Hash,
},
/// A new candidate receipt was backed.
ExecutionReceiptStored { receipt_hash: T::Hash },
ExecutionReceiptStored { receipt_hash: H256 },
/// A transaction bundle was included.
TransactionBundleStored { bundle_hash: H256 },
/// A fraud proof was processed.
Expand Down Expand Up @@ -224,6 +224,7 @@ mod pallet {
.build()
}
Call::submit_fraud_proof { fraud_proof } => {
// TODO: prevent the spamming of fraud proof transaction.
if let Err(e) = Self::check_fraud_proof(fraud_proof) {
log::error!(
target: "runtime::subspace::executor",
Expand Down
23 changes: 17 additions & 6 deletions crates/sp-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<Extrinsic: sp_runtime::traits::Extrinsic + Encode> From<Bundle<Extrinsic>>
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)]
pub struct ExecutionReceipt<Hash> {
/// Primary block hash.
pub primary_hash: Hash,
pub primary_hash: H256,
/// Secondary block hash?
pub secondary_hash: Hash,
/// State root after finishing the execution.
Expand All @@ -104,10 +104,21 @@ pub struct ExecutionReceipt<Hash> {
pub state_transition_root: Hash,
}

impl<Hash: Copy> ExecutionReceipt<Hash> {
/// TODO: hash of ER?
pub fn hash(&self) -> Hash {
self.primary_hash
impl<Hash: Encode> ExecutionReceipt<Hash> {
/// Returns the hash of this execution receipt.
pub fn hash(&self) -> H256 {
BlakeTwo256::hash_of(self)
}
}

// TODO: this might be unneccessary, ideally we could interact with the runtime using `ExecutionReceipt` directly.
// Refer to the comment https:/subspace/subspace/pull/219#discussion_r776749767
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)]
pub struct OpaqueExecutionReceipt(Vec<u8>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? I think both nodes should understand ER fully and have it fully typed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that overseer doesn't understand this type as it does not know the Block::Hash type but that's how ExecutionReceipt is built.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use a concrete type there then? It should be possible to transform generic type into this specific type and back if need be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TODO noted b4c5372.

I was also thinking about if OpaqueExecutionReceipt is really necessary but failed to make it compile, maybe just some Rust issues I haven't managed to fix, a TODO added anyway, will have a look later.


impl<Hash: Encode> From<ExecutionReceipt<Hash>> for OpaqueExecutionReceipt {
fn from(inner: ExecutionReceipt<Hash>) -> Self {
Self(inner.encode())
}
}

Expand All @@ -129,7 +140,7 @@ sp_api::decl_runtime_apis! {

/// Submits the execution receipt via an unsigned extrinsic.
fn submit_execution_receipt_unsigned(
execution_receipt: ExecutionReceipt<<Block as BlockT>::Hash>,
opaque_execution_receipt: OpaqueExecutionReceipt,
) -> Option<()>;

/// Submits the transaction bundle via an unsigned extrinsic.
Expand Down
10 changes: 8 additions & 2 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,15 @@ impl_runtime_apis! {
}

fn submit_execution_receipt_unsigned(
execution_receipt: sp_executor::ExecutionReceipt<<Block as BlockT>::Hash>,
opaque_execution_receipt: sp_executor::OpaqueExecutionReceipt,
) -> Option<()> {
Executor::submit_execution_receipt_unsigned(execution_receipt).ok()
<sp_executor::ExecutionReceipt<<Block as BlockT>::Hash>>::decode(
&mut opaque_execution_receipt.encode().as_slice(),
)
.ok()
.and_then(|execution_receipt| {
Executor::submit_execution_receipt_unsigned(execution_receipt).ok()
})
}

fn submit_transaction_bundle_unsigned(opaque_bundle: OpaqueBundle) -> Option<()> {
Expand Down
2 changes: 2 additions & 0 deletions cumulus/client/cirrus-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
# Substrate dependencies
sc-client-api = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
sc-transaction-pool-api = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
sc-utils = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
sp-runtime = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
sp-core = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
sp-consensus = { git = "https:/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
Expand All @@ -30,6 +31,7 @@ tracing = "0.1.25"
polkadot-overseer = { path = "../../../polkadot/node/overseer" }
polkadot-node-subsystem = { path = "../../../polkadot/node/subsystem" }

cirrus-client-executor-gossip = { path = "../executor-gossip" }
cirrus-node-primitives = { path = "../../../crates/cirrus-node-primitives" }
cirrus-primitives = { path = "../../primitives" }
sp-executor = { path = "../../../crates/sp-executor" }
Expand Down
Loading