Skip to content

Commit 7a6411a

Browse files
authored
Merge pull request #979 from subspace/core-domain-prototype-refactoring-part-5
Core domain prototype refactoring (part 5)
2 parents aea2cd9 + 0422cb4 commit 7a6411a

25 files changed

+249
-438
lines changed

Diff for: Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/pallet-domains/src/lib.rs

+22-54
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ mod pallet {
9696

9797
#[derive(TypeInfo, Encode, Decode, PalletError, Debug)]
9898
pub enum BundleError {
99-
/// The signer of transaction bundle is unexpected.
99+
/// The signer of bundle is unexpected.
100100
UnexpectedSigner,
101-
/// Invalid transaction bundle signature.
101+
/// Invalid bundle signature.
102102
BadSignature,
103103
/// Invalid vrf proof.
104104
BadVrfProof,
@@ -196,11 +196,7 @@ mod pallet {
196196
) -> DispatchResult {
197197
ensure_none(origin)?;
198198

199-
log::debug!(
200-
target: "runtime::subspace::executor",
201-
"Submitting transaction bundle: {:?}",
202-
signed_opaque_bundle
203-
);
199+
log::trace!(target: "runtime::domains", "Processing bundle: {signed_opaque_bundle:?}");
204200

205201
let domain_id = signed_opaque_bundle.domain_id();
206202

@@ -247,11 +243,7 @@ mod pallet {
247243
pub fn submit_fraud_proof(origin: OriginFor<T>, fraud_proof: FraudProof) -> DispatchResult {
248244
ensure_none(origin)?;
249245

250-
log::debug!(
251-
target: "runtime::subspace::executor",
252-
"Submitting fraud proof: {:?}",
253-
fraud_proof
254-
);
246+
log::trace!(target: "runtime::domains", "Processing fraud proof: {fraud_proof:?}");
255247

256248
// Revert the execution chain.
257249
let (_, mut to_remove) = ReceiptHead::<T>::get();
@@ -284,11 +276,7 @@ mod pallet {
284276
) -> DispatchResult {
285277
ensure_none(origin)?;
286278

287-
log::debug!(
288-
target: "runtime::subspace::executor",
289-
"Submitting bundle equivocation proof: {:?}",
290-
bundle_equivocation_proof
291-
);
279+
log::trace!(target: "runtime::domains", "Processing bundle equivocation proof: {bundle_equivocation_proof:?}");
292280

293281
// TODO: slash the executor accordingly.
294282

@@ -305,11 +293,7 @@ mod pallet {
305293
) -> DispatchResult {
306294
ensure_none(origin)?;
307295

308-
log::debug!(
309-
target: "runtime::subspace::executor",
310-
"Submitting invalid transaction proof: {:?}",
311-
invalid_transaction_proof
312-
);
296+
log::trace!(target: "runtime::domains", "Processing invalid transaction proof: {invalid_transaction_proof:?}");
313297

314298
// TODO: slash the executor accordingly.
315299

@@ -422,9 +406,8 @@ mod pallet {
422406
} => {
423407
if let Err(e) = Self::validate_bundle(signed_opaque_bundle) {
424408
log::error!(
425-
target: "runtime::subspace::executor",
426-
"Invalid signed opaque bundle: {:?}, error: {:?}",
427-
signed_opaque_bundle, e
409+
target: "runtime::domains",
410+
"Bad bundle: {signed_opaque_bundle:?}, error: {e:?}",
428411
);
429412
if let BundleError::Receipt(_) = e {
430413
return InvalidTransactionCode::ExecutionReceipt.into();
@@ -445,9 +428,8 @@ mod pallet {
445428
Call::submit_fraud_proof { fraud_proof } => {
446429
if let Err(e) = Self::validate_fraud_proof(fraud_proof) {
447430
log::error!(
448-
target: "runtime::subspace::executor",
449-
"Invalid fraud proof: {:?}, error: {:?}",
450-
fraud_proof, e
431+
target: "runtime::domains",
432+
"Bad fraud proof: {fraud_proof:?}, error: {e:?}",
451433
);
452434
return InvalidTransactionCode::FraudProof.into();
453435
}
@@ -462,9 +444,8 @@ mod pallet {
462444
Self::validate_bundle_equivocation_proof(bundle_equivocation_proof)
463445
{
464446
log::error!(
465-
target: "runtime::subspace::executor",
466-
"Invalid bundle equivocation proof: {:?}, error: {:?}",
467-
bundle_equivocation_proof, e
447+
target: "runtime::domains",
448+
"Bad bundle equivocation proof: {bundle_equivocation_proof:?}, error: {e:?}",
468449
);
469450
return InvalidTransactionCode::BundleEquivicationProof.into();
470451
}
@@ -481,9 +462,8 @@ mod pallet {
481462
Self::validate_invalid_transaction_proof(invalid_transaction_proof)
482463
{
483464
log::error!(
484-
target: "runtime::subspace::executor",
485-
"Wrong InvalidTransactionProof: {:?}, error: {:?}",
486-
invalid_transaction_proof, e
465+
target: "runtime::domains",
466+
"Bad invalid transaction proof: {invalid_transaction_proof:?}, error: {e:?}",
487467
);
488468
return InvalidTransactionCode::TrasactionProof.into();
489469
}
@@ -833,13 +813,10 @@ where
833813

834814
match SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()) {
835815
Ok(()) => {
836-
log::info!(target: "runtime::subspace::executor", "Submitted transaction bundle");
816+
log::info!(target: "runtime::domains", "Submitted bundle");
837817
}
838818
Err(()) => {
839-
log::error!(
840-
target: "runtime::subspace::executor",
841-
"Error submitting transaction bundle",
842-
);
819+
log::error!(target: "runtime::domains", "Error submitting bundle");
843820
}
844821
}
845822
}
@@ -850,10 +827,10 @@ where
850827

851828
match SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()) {
852829
Ok(()) => {
853-
log::info!(target: "runtime::subspace::executor", "Submitted fraud proof");
830+
log::info!(target: "runtime::domains", "Submitted fraud proof");
854831
}
855832
Err(()) => {
856-
log::error!(target: "runtime::subspace::executor", "Error submitting fraud proof");
833+
log::error!(target: "runtime::domains", "Error submitting fraud proof");
857834
}
858835
}
859836
}
@@ -868,16 +845,10 @@ where
868845

869846
match SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()) {
870847
Ok(()) => {
871-
log::info!(
872-
target: "runtime::subspace::executor",
873-
"Submitted bundle equivocation proof"
874-
);
848+
log::info!(target: "runtime::domains", "Submitted bundle equivocation proof");
875849
}
876850
Err(()) => {
877-
log::error!(
878-
target: "runtime::subspace::executor",
879-
"Error submitting bundle equivocation proof",
880-
);
851+
log::error!(target: "runtime::domains", "Error submitting bundle equivocation proof");
881852
}
882853
}
883854
}
@@ -892,13 +863,10 @@ where
892863

893864
match SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()) {
894865
Ok(()) => {
895-
log::info!(target: "runtime::subspace::executor", "Submitted invalid transaction proof")
866+
log::info!(target: "runtime::domains", "Submitted invalid transaction proof")
896867
}
897868
Err(()) => {
898-
log::error!(
899-
target: "runtime::subspace::executor",
900-
"Error submitting invalid transaction proof",
901-
);
869+
log::error!(target: "runtime::domains", "Error submitting invalid transaction proof");
902870
}
903871
}
904872
}

Diff for: crates/subspace-node/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ do-not-enforce-cost-of-storage = [
7171
runtime-benchmarks = [
7272
"frame-benchmarking/runtime-benchmarks",
7373
"frame-benchmarking-cli/runtime-benchmarks",
74-
"domain-service/runtime-benchmarks",
7574
"subspace-runtime/runtime-benchmarks",
7675
"system-domain-runtime/runtime-benchmarks",
7776
]

Diff for: crates/subspace-node/src/secondary_chain/chain_spec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn development_config() -> ExecutionChainSpec<GenesisConfig> {
3939
// Name
4040
"Development",
4141
// ID
42-
"execution_dev",
42+
"system_domain_dev",
4343
ChainType::Development,
4444
move || {
4545
testnet_genesis(
@@ -85,7 +85,7 @@ pub fn local_testnet_config() -> ExecutionChainSpec<GenesisConfig> {
8585
// Name
8686
"Local Testnet",
8787
// ID
88-
"execution_local_testnet",
88+
"system_domain_local_testnet",
8989
ChainType::Local,
9090
move || {
9191
testnet_genesis(

Diff for: domains/client/domain-executor/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Domain Executor
2+
3+
## Overview
4+
5+
Each executor instance, whether for system domain or core domain, consists of these components:
6+
7+
- `BundleProducer`: Produce a bundle on new slot.
8+
- `BundleElectionSolver`: Attempt to solve the bundle election challenge on each each slot in order to be allowed to author a bundle.
9+
- `DomainBundleProposer`: Collect the transactions from transaction pool and a range of receipts upon solving the bundle election challenge successfully.
10+
- `BundleProcessor`: On each imported primary block, the bundle processor extracts the domain-specific bundles from the primary block, compiles the bundles to a list of extrinsics, construct a custom `BlockBuilder` with compiled extrinsics, execute and import the domain block. The receipt of processing the domain block is stored locally and then submitted to the primary chain in some bundle later.
11+
- domain worker: Run the components `BundleProducer` and `BundleProcessor` on the arrived events(new_slot, import_primary_block).
12+
- `GossipMessageValidator`: Validate the bundle gossiped from the domain node peers. Currently, this part is inactive and will be re-enabled in the future.
13+
14+
## Modules structure
15+
16+
- `domain_{block_processor,bundle_producer,bundle_proposer,worker}.rs`/`gossip_message_validator`
17+
- General executor components, sharing the common logics between system domain and core domain.
18+
- `system_{block_processor,bundle_producer,bundle_proposer,worker}.rs`/`system_gossip_message_validator`
19+
- Executor components specfic to the system domain.
20+
- `core_{block_processor,bundle_producer,bundle_proposer,worker}.rs`/`core_gossip_message_validator`
21+
- Executor components specfic to the core domain.

Diff for: domains/client/domain-executor/src/core_bundle_processor.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::domain_block_processor::DomainBlockProcessor;
22
use crate::utils::{translate_number_type, DomainBundles};
33
use crate::TransactionFor;
44
use domain_runtime_primitives::{AccountId, DomainCoreApi};
5-
use sc_client_api::{AuxStore, BlockBackend};
5+
use sc_client_api::{AuxStore, BlockBackend, StateBackendFor};
66
use sc_consensus::{BlockImport, ForkChoiceStrategy};
77
use sp_api::{NumberFor, ProvideRuntimeApi};
88
use sp_blockchain::HeaderBackend;
@@ -71,10 +71,7 @@ where
7171
HeaderBackend<Block> + BlockBackend<Block> + AuxStore + ProvideRuntimeApi<Block> + 'static,
7272
Client::Api: DomainCoreApi<Block, AccountId>
7373
+ sp_block_builder::BlockBuilder<Block>
74-
+ sp_api::ApiExt<
75-
Block,
76-
StateBackend = sc_client_api::backend::StateBackendFor<Backend, Block>,
77-
>,
74+
+ sp_api::ApiExt<Block, StateBackend = StateBackendFor<Backend, Block>>,
7875
for<'b> &'b Client: BlockImport<
7976
Block,
8077
Transaction = sp_api::TransactionFor<Client, Block>,

Diff for: domains/client/domain-executor/src/core_domain_worker.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::TransactionFor;
2222
use domain_runtime_primitives::{AccountId, DomainCoreApi};
2323
use futures::channel::mpsc;
2424
use futures::{future, FutureExt, Stream, StreamExt, TryFutureExt};
25-
use sc_client_api::{AuxStore, BlockBackend, ProofProvider};
25+
use sc_client_api::{AuxStore, BlockBackend, ProofProvider, StateBackendFor};
2626
use sc_consensus::{BlockImport, ForkChoiceStrategy};
2727
use sp_api::{BlockT, ProvideRuntimeApi};
2828
use sp_block_builder::BlockBuilder;
@@ -80,10 +80,7 @@ pub(super) async fn start_worker<
8080
+ 'static,
8181
Client::Api: DomainCoreApi<Block, AccountId>
8282
+ BlockBuilder<Block>
83-
+ sp_api::ApiExt<
84-
Block,
85-
StateBackend = sc_client_api::backend::StateBackendFor<Backend, Block>,
86-
>,
83+
+ sp_api::ApiExt<Block, StateBackend = StateBackendFor<Backend, Block>>,
8784
for<'b> &'b Client: BlockImport<
8885
Block,
8986
Transaction = sp_api::TransactionFor<Client, Block>,

Diff for: domains/client/domain-executor/src/core_executor.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{active_leaves, EssentialExecutorParams, TransactionFor};
66
use domain_runtime_primitives::{AccountId, DomainCoreApi};
77
use futures::channel::mpsc;
88
use futures::{FutureExt, Stream};
9-
use sc_client_api::{AuxStore, BlockBackend, ProofProvider};
9+
use sc_client_api::{AuxStore, BlockBackend, ProofProvider, StateBackendFor};
1010
use sc_consensus::ForkChoiceStrategy;
1111
use sp_api::ProvideRuntimeApi;
1212
use sp_blockchain::HeaderBackend;
@@ -20,14 +20,13 @@ use std::sync::Arc;
2020
use subspace_core_primitives::Blake2b256Hash;
2121
use system_runtime_primitives::SystemDomainApi;
2222

23-
/// The implementation of the Domain `Executor`.
23+
/// Core domain executor.
2424
pub struct Executor<Block, SBlock, PBlock, Client, SClient, PClient, TransactionPool, Backend, E>
2525
where
2626
Block: BlockT,
2727
SBlock: BlockT,
2828
PBlock: BlockT,
2929
{
30-
// TODO: no longer used in executor, revisit this with ParachainBlockImport together.
3130
primary_chain_client: Arc<PClient>,
3231
client: Arc<Client>,
3332
spawner: Box<dyn SpawnNamed + Send + Sync>,
@@ -71,10 +70,7 @@ where
7170
+ 'static,
7271
Client::Api: DomainCoreApi<Block, AccountId>
7372
+ sp_block_builder::BlockBuilder<Block>
74-
+ sp_api::ApiExt<
75-
Block,
76-
StateBackend = sc_client_api::backend::StateBackendFor<Backend, Block>,
77-
>,
73+
+ sp_api::ApiExt<Block, StateBackend = StateBackendFor<Backend, Block>>,
7874
for<'b> &'b Client: sc_consensus::BlockImport<
7975
Block,
8076
Transaction = sp_api::TransactionFor<Client, Block>,
@@ -163,7 +159,7 @@ where
163159
);
164160

165161
spawn_essential.spawn_essential_blocking(
166-
"executor-worker",
162+
"core-executor-worker",
167163
None,
168164
crate::core_domain_worker::start_worker(
169165
domain_id,

Diff for: domains/client/domain-executor/src/core_gossip_message_validator.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::gossip_message_validator::{GossipMessageError, GossipMessageValidator
33
use crate::utils::to_number_primitive;
44
use crate::{ExecutionReceiptFor, TransactionFor};
55
use domain_client_executor_gossip::{Action, GossipMessageHandler};
6-
use sc_client_api::{AuxStore, BlockBackend, ProofProvider};
6+
use sc_client_api::{AuxStore, BlockBackend, ProofProvider, StateBackendFor};
77
use sp_api::ProvideRuntimeApi;
88
use sp_blockchain::HeaderBackend;
99
use sp_core::traits::{CodeExecutor, SpawnNamed};
@@ -17,7 +17,7 @@ use std::marker::PhantomData;
1717
use std::sync::Arc;
1818
use system_runtime_primitives::SystemDomainApi;
1919

20-
/// The implementation of the Domain `Executor`.
20+
/// Gossip message validator for core domain.
2121
pub struct CoreGossipMessageValidator<
2222
Block,
2323
SBlock,
@@ -33,7 +33,6 @@ pub struct CoreGossipMessageValidator<
3333
SBlock: BlockT,
3434
PBlock: BlockT,
3535
{
36-
// TODO: no longer used in executor, revisit this with ParachainBlockImport together.
3736
primary_chain_client: Arc<PClient>,
3837
client: Arc<Client>,
3938
transaction_pool: Arc<TransactionPool>,
@@ -92,10 +91,7 @@ where
9291
+ ProofProvider<Block>
9392
+ 'static,
9493
Client::Api: sp_block_builder::BlockBuilder<Block>
95-
+ sp_api::ApiExt<
96-
Block,
97-
StateBackend = sc_client_api::backend::StateBackendFor<Backend, Block>,
98-
>,
94+
+ sp_api::ApiExt<Block, StateBackend = StateBackendFor<Backend, Block>>,
9995
SClient: HeaderBackend<SBlock> + ProvideRuntimeApi<SBlock> + 'static,
10096
SClient::Api: SystemDomainApi<SBlock, NumberFor<PBlock>, PBlock::Hash>,
10197
PClient: HeaderBackend<PBlock> + ProvideRuntimeApi<PBlock> + 'static,
@@ -179,10 +175,7 @@ where
179175
+ ProofProvider<Block>
180176
+ 'static,
181177
Client::Api: sp_block_builder::BlockBuilder<Block>
182-
+ sp_api::ApiExt<
183-
Block,
184-
StateBackend = sc_client_api::backend::StateBackendFor<Backend, Block>,
185-
>,
178+
+ sp_api::ApiExt<Block, StateBackend = StateBackendFor<Backend, Block>>,
186179
SClient: HeaderBackend<SBlock> + ProvideRuntimeApi<SBlock> + 'static,
187180
SClient::Api: SystemDomainApi<SBlock, NumberFor<PBlock>, PBlock::Hash>,
188181
PClient: HeaderBackend<PBlock> + ProvideRuntimeApi<PBlock> + 'static,

0 commit comments

Comments
 (0)