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

Domain client refactoring #2087

Merged
merged 4 commits into from
Oct 12, 2023
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
1 change: 0 additions & 1 deletion crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ fn main() -> Result<(), Error> {
.new_slot_notification_stream
.clone(),
consensus_sync_service: consensus_chain_node.sync_service.clone(),
select_chain: consensus_chain_node.select_chain.clone(),
domain_message_receiver,
gossip_message_sink: xdm_gossip_worker_builder.gossip_msg_sink(),
};
Expand Down
7 changes: 2 additions & 5 deletions crates/subspace-node/src/domain/domain_instance_starter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sp_domains::{DomainInstanceData, RuntimeType};
use std::sync::Arc;
use subspace_runtime::RuntimeApi as CRuntimeApi;
use subspace_runtime_primitives::opaque::Block as CBlock;
use subspace_service::{FullClient as CFullClient, FullSelectChain};
use subspace_service::FullClient as CFullClient;

/// `DomainInstanceStarter` used to start a domain instance node based on the given
/// bootstrap result
Expand All @@ -32,7 +32,6 @@ pub struct DomainInstanceStarter {
SubspaceNotificationStream<BlockImportingNotification<CBlock>>,
pub new_slot_notification_stream: SubspaceNotificationStream<NewSlotNotification>,
pub consensus_sync_service: Arc<sc_network_sync::SyncingService<CBlock>>,
pub select_chain: FullSelectChain,
pub domain_message_receiver: TracingUnboundedReceiver<Vec<u8>>,
pub gossip_message_sink: TracingUnboundedSender<Message>,
}
Expand Down Expand Up @@ -61,7 +60,6 @@ impl DomainInstanceStarter {
block_importing_notification_stream,
new_slot_notification_stream,
consensus_sync_service,
select_chain,
domain_message_receiver,
gossip_message_sink,
} = self;
Expand Down Expand Up @@ -93,7 +91,6 @@ impl DomainInstanceStarter {
(
slot_notification.new_slot_info.slot,
slot_notification.new_slot_info.global_randomness,
None::<futures::channel::mpsc::Sender<()>>,
)
})
};
Expand All @@ -104,6 +101,7 @@ impl DomainInstanceStarter {
block_importing_notification_stream: block_importing_notification_stream(),
imported_block_notification_stream,
new_slot_notification_stream: new_slot_notification_stream(),
acknowledgement_sender_stream: futures::stream::empty(),
_phantom: Default::default(),
};

Expand Down Expand Up @@ -135,7 +133,6 @@ impl DomainInstanceStarter {
consensus_client,
consensus_offchain_tx_pool_factory,
consensus_network_sync_oracle: consensus_sync_service.clone(),
select_chain,
operator_streams,
gossip_message_sink,
domain_message_receiver,
Expand Down
23 changes: 2 additions & 21 deletions domains/client/domain-operator/src/domain_bundle_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_domains::{
SealedBundleHeader,
};
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, One, Saturating, Zero};
use sp_runtime::traits::{Block as BlockT, Zero};
use sp_runtime::RuntimeAppPublic;
use std::convert::{AsRef, Into};
use std::marker::PhantomData;
Expand Down Expand Up @@ -149,26 +149,7 @@ where
global_randomness,
} = slot_info;

let best_receipt_is_written = crate::aux_schema::latest_consensus_block_hash_for::<
_,
_,
CBlock::Hash,
>(&*self.client, &self.client.info().best_hash)?
.is_some();

// TODO: remove once the receipt generation can be done before the domain block is
// committed to the database, in other words, only when the receipt of block N+1 has
// been generated can the `client.info().best_number` be updated from N to N+1.
//
// This requires:
// 1. Reimplement `runtime_api.intermediate_roots()` on the client side.
// 2. Add a hook before the upstream `client.commit_operation(op)`.
let domain_best_number = if best_receipt_is_written {
self.client.info().best_number
} else {
self.client.info().best_number.saturating_sub(One::one())
};

let domain_best_number = self.client.info().best_number;
let parent_chain_best_hash = self.parent_chain.best_hash();
let should_skip_slot = {
let head_receipt_number = self
Expand Down
31 changes: 4 additions & 27 deletions domains/client/domain-operator/src/domain_bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sp_api::{HeaderT, NumberFor, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::HeaderBackend;
use sp_domains::{BundleHeader, ExecutionReceipt, ProofOfElection};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Hash as HashT, One, Saturating, Zero};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Hash as HashT, One, Zero};
use sp_weights::Weight;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -153,7 +153,7 @@ where
sp_core::storage::StateVersion::V1,
);

let receipt = self.load_bundle_receipt(parent_number, parent_hash, parent_chain)?;
let receipt = self.load_bundle_receipt(parent_number, parent_chain)?;

let header = BundleHeader {
proof_of_election,
Expand All @@ -170,7 +170,6 @@ where
fn load_bundle_receipt<ParentChain, ParentChainBlock>(
&self,
header_number: NumberFor<Block>,
header_hash: Block::Hash,
parent_chain: ParentChain,
) -> sp_blockchain::Result<ExecutionReceiptFor<Block, CBlock>>
where
Expand All @@ -179,37 +178,15 @@ where
{
let parent_chain_block_hash = parent_chain.best_hash();
let head_receipt_number = parent_chain.head_receipt_number(parent_chain_block_hash)?;
let max_drift = parent_chain.block_tree_pruning_depth(parent_chain_block_hash)?;
let receipt_number = (head_receipt_number + One::one()).min(header_number);

tracing::trace!(
?header_number,
?head_receipt_number,
?max_drift,
?receipt_number,
"Collecting receipts at {parent_chain_block_hash:?}"
);

let header_block_receipt_is_written = crate::aux_schema::latest_consensus_block_hash_for::<
_,
_,
CBlock::Hash,
>(&*self.client, &header_hash)?
.is_some();

// TODO: remove once the receipt generation can be done before the domain block is
// committed to the database, in other words, only when the receipt of block N+1 has
// been generated can the `client.info().best_number` be updated from N to N+1.
//
// This requires:
// 1. Reimplement `runtime_api.intermediate_roots()` on the client side.
// 2. Add a hook before the upstream `client.commit_operation(op)`.
let available_best_receipt_number = if header_block_receipt_is_written {
header_number
} else {
header_number.saturating_sub(One::one())
};

let receipt_number = (head_receipt_number + One::one()).min(available_best_receipt_number);

if receipt_number.is_zero() {
let genesis_hash = self.client.info().genesis_hash;
let genesis_header = self.client.header(genesis_hash)?.ok_or_else(|| {
Expand Down
Loading