Skip to content

Commit dbfcd24

Browse files
authored
Initial support of executor gossip (#219)
* Initial support of executor gossip Now the gossip message for bundle and execution receipt can be sent and received, but still a lot of works to do. * Some cleanups * Impl the execution receipt stream `OpaqueExecutionReceipt` is introduced as `ExecutionReceipt` has both concrete type(`primary_hash`) and generic type `Hash`, used by the client submitting the external ER to runtime. * Validate the gossip message on receiving `GossipMessageHandler` has been changed from `async` to sync due to the `Validator` trait of network-gossip is not async and it's non-trivial to submit a patch to the upstream. * Custom rebroadcast timeout * Clean up the messages that have been rebroadcasted * Add a TODO * Extract `gossip_bundle` and `gossip_execution_receipt` * Nit * Change HandlerOutcome to HandlerResult * Remove HandlerResult Fixes #219 (comment) * Apply the code review Fixes #219 (comment) Fixes #219 (comment) * Add a TODO
1 parent a91a40d commit dbfcd24

File tree

20 files changed

+706
-120
lines changed

20 files changed

+706
-120
lines changed

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"cumulus/client/cirrus-executor",
88
"cumulus/client/consensus/common",
99
"cumulus/client/consensus/relay-chain",
10+
"cumulus/client/executor-gossip",
1011
"cumulus/parachain-template/node",
1112
"cumulus/parachain-template/runtime",
1213
"cumulus/primitives",

crates/cirrus-node-primitives/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
2323
use sp_application_crypto::KeyTypeId;
2424
use sp_consensus_slots::Slot;
2525
use sp_core::bytes;
26-
use sp_executor::{ExecutionReceipt, OpaqueBundle};
26+
use sp_executor::{OpaqueBundle, OpaqueExecutionReceipt};
2727
use sp_runtime::traits::Hash as HashT;
2828
use std::pin::Pin;
2929
use subspace_core_primitives::{Randomness, Tag};
@@ -94,14 +94,14 @@ impl BundleResult {
9494
}
9595

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

102102
impl ProcessorResult {
103-
pub fn to_execution_receipt(self) -> ExecutionReceipt<Hash> {
104-
self.execution_receipt
103+
pub fn to_opaque_execution_receipt(self) -> OpaqueExecutionReceipt {
104+
self.opaque_execution_receipt
105105
}
106106
}
107107

crates/pallet-executor/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod pallet {
5858
head_hash: T::Hash,
5959
},
6060
/// A new candidate receipt was backed.
61-
ExecutionReceiptStored { receipt_hash: T::Hash },
61+
ExecutionReceiptStored { receipt_hash: H256 },
6262
/// A transaction bundle was included.
6363
TransactionBundleStored { bundle_hash: H256 },
6464
/// A fraud proof was processed.
@@ -224,6 +224,7 @@ mod pallet {
224224
.build()
225225
}
226226
Call::submit_fraud_proof { fraud_proof } => {
227+
// TODO: prevent the spamming of fraud proof transaction.
227228
if let Err(e) = Self::check_fraud_proof(fraud_proof) {
228229
log::error!(
229230
target: "runtime::subspace::executor",

crates/sp-executor/src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<Extrinsic: sp_runtime::traits::Extrinsic + Encode> From<Bundle<Extrinsic>>
9595
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)]
9696
pub struct ExecutionReceipt<Hash> {
9797
/// Primary block hash.
98-
pub primary_hash: Hash,
98+
pub primary_hash: H256,
9999
/// Secondary block hash?
100100
pub secondary_hash: Hash,
101101
/// State root after finishing the execution.
@@ -104,10 +104,21 @@ pub struct ExecutionReceipt<Hash> {
104104
pub state_transition_root: Hash,
105105
}
106106

107-
impl<Hash: Copy> ExecutionReceipt<Hash> {
108-
/// TODO: hash of ER?
109-
pub fn hash(&self) -> Hash {
110-
self.primary_hash
107+
impl<Hash: Encode> ExecutionReceipt<Hash> {
108+
/// Returns the hash of this execution receipt.
109+
pub fn hash(&self) -> H256 {
110+
BlakeTwo256::hash_of(self)
111+
}
112+
}
113+
114+
// TODO: this might be unneccessary, ideally we could interact with the runtime using `ExecutionReceipt` directly.
115+
// Refer to the comment https://github.com/subspace/subspace/pull/219#discussion_r776749767
116+
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)]
117+
pub struct OpaqueExecutionReceipt(Vec<u8>);
118+
119+
impl<Hash: Encode> From<ExecutionReceipt<Hash>> for OpaqueExecutionReceipt {
120+
fn from(inner: ExecutionReceipt<Hash>) -> Self {
121+
Self(inner.encode())
111122
}
112123
}
113124

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

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

135146
/// Submits the transaction bundle via an unsigned extrinsic.

crates/subspace-runtime/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,15 @@ impl_runtime_apis! {
891891
}
892892

893893
fn submit_execution_receipt_unsigned(
894-
execution_receipt: sp_executor::ExecutionReceipt<<Block as BlockT>::Hash>,
894+
opaque_execution_receipt: sp_executor::OpaqueExecutionReceipt,
895895
) -> Option<()> {
896-
Executor::submit_execution_receipt_unsigned(execution_receipt).ok()
896+
<sp_executor::ExecutionReceipt<<Block as BlockT>::Hash>>::decode(
897+
&mut opaque_execution_receipt.encode().as_slice(),
898+
)
899+
.ok()
900+
.and_then(|execution_receipt| {
901+
Executor::submit_execution_receipt_unsigned(execution_receipt).ok()
902+
})
897903
}
898904

899905
fn submit_transaction_bundle_unsigned(opaque_bundle: OpaqueBundle) -> Option<()> {

cumulus/client/cirrus-executor/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
# Substrate dependencies
99
sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
1010
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
11+
sc-utils = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
1112
sp-runtime = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
1213
sp-core = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
1314
sp-consensus = { git = "https://github.com/paritytech/substrate", rev = "5bd5b842d4ea520d281b1398e1f54907c9862fcd" }
@@ -30,6 +31,7 @@ tracing = "0.1.25"
3031
polkadot-overseer = { path = "../../../polkadot/node/overseer" }
3132
polkadot-node-subsystem = { path = "../../../polkadot/node/subsystem" }
3233

34+
cirrus-client-executor-gossip = { path = "../executor-gossip" }
3335
cirrus-node-primitives = { path = "../../../crates/cirrus-node-primitives" }
3436
cirrus-primitives = { path = "../../primitives" }
3537
sp-executor = { path = "../../../crates/sp-executor" }

0 commit comments

Comments
 (0)