Skip to content

Commit

Permalink
Merge pull request #2904 from autonomys/mmr-sync
Browse files Browse the repository at this point in the history
Introduce MMR-sync and MMR-request handler.
  • Loading branch information
shamil-gadelshin committed Jul 29, 2024
2 parents 14e043e + d0c84f9 commit 48d9922
Show file tree
Hide file tree
Showing 6 changed files with 584 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions crates/subspace-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ include = [
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
array-bytes = "6.2.2"
async-channel = "1.8.0"
async-trait = "0.1.80"
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
domain-runtime-primitives = { version = "0.1.0", path = "../../domains/primitives/runtime" }
Expand All @@ -41,7 +43,9 @@ sc-domains = { version = "0.1.0", path = "../sc-domains" }
sc-executor = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-informant = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-network = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-network-light = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-network-sync = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-network-transactions = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-offchain = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-proof-of-time = { version = "0.1.0", path = "../sc-proof-of-time" }
sc-rpc = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
Expand All @@ -53,6 +57,8 @@ sc-telemetry = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb
sc-tracing = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-transaction-pool = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-transaction-pool-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sc-utils = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
schnellru = "0.2.1"
schnorrkel = "0.11.4"
sp-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
sp-blockchain = { git = "https://github.com/subspace/polkadot-sdk", rev = "0cbfcb0232bbf71ac5b14cc8c99bf043cec420ef" }
Expand Down
34 changes: 30 additions & 4 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
pub mod config;
pub mod dsn;
mod metrics;
pub(crate) mod mmr;
pub mod rpc;
pub mod sync_from_dsn;
pub mod transaction_pool;

use crate::config::{ChainSyncMode, SubspaceConfiguration, SubspaceNetworking};
use crate::dsn::{create_dsn_instance, DsnConfigurationError};
use crate::metrics::NodeMetrics;
use crate::mmr::request_handler::MmrRequestHandler;
use crate::sync_from_dsn::piece_validator::SegmentCommitmentPieceValidator;
use crate::sync_from_dsn::snap_sync::snap_sync;
use crate::transaction_pool::FullPool;
Expand Down Expand Up @@ -72,7 +74,7 @@ use sc_consensus_subspace::verifier::{SubspaceVerifier, SubspaceVerifierOptions}
use sc_consensus_subspace::SubspaceLink;
use sc_domains::ExtensionsFactory as DomainsExtensionFactory;
use sc_network::service::traits::NetworkService;
use sc_network::{NotificationMetrics, NotificationService};
use sc_network::{NetworkWorker, NotificationMetrics, NotificationService};
use sc_proof_of_time::source::gossip::pot_gossip_peers_set_config;
use sc_proof_of_time::source::{PotSlotInfo, PotSourceWorker};
use sc_proof_of_time::verifier::PotVerifier;
Expand Down Expand Up @@ -730,6 +732,7 @@ where
} = other;

let offchain_indexing_enabled = config.offchain_worker.indexing_enabled;
let fork_id = config.base.chain_spec.fork_id().map(String::from);
let (node, bootstrap_nodes) = match config.subspace_networking {
SubspaceNetworking::Reuse {
node,
Expand Down Expand Up @@ -844,6 +847,31 @@ where
pot_gossip_peers_set_config();
net_config.add_notification_protocol(pot_gossip_notification_config);
let pause_sync = Arc::clone(&net_config.network_config.pause_sync);

if let Some(offchain_storage) = backend.offchain_storage() {
let num_peer_hint = net_config.network_config.default_peers_set_num_full as usize
+ net_config
.network_config
.default_peers_set
.reserved_nodes
.len();

// Allow both outgoing and incoming requests.
let (handler, protocol_config) =
MmrRequestHandler::new::<NetworkWorker<Block, <Block as BlockT>::Hash>, _>(
&config.base.protocol_id(),
fork_id.as_deref(),
client.clone(),
num_peer_hint,
offchain_storage,
);
task_manager
.spawn_handle()
.spawn("mmr-request-handler", Some("networking"), handler.run());

net_config.add_request_response_protocol(protocol_config);
}

let (network_service, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config.base,
Expand Down Expand Up @@ -933,12 +961,10 @@ where
pause_sync.store(true, Ordering::Release);
}

let fork_id = config.base.chain_spec.fork_id().map(String::from);

let snap_sync_task = snap_sync(
segment_headers_store.clone(),
node.clone(),
fork_id,
fork_id.clone(),
Arc::clone(&client),
import_queue_service1,
pause_sync.clone(),
Expand Down
9 changes: 9 additions & 0 deletions crates/subspace-service/src/mmr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use sp_mmr_primitives::utils::NodesUtils;
use sp_mmr_primitives::{NodeIndex, INDEXING_PREFIX};

pub(crate) mod request_handler;
pub(crate) mod sync;

pub(crate) fn get_offchain_key(index: NodeIndex) -> Vec<u8> {
NodesUtils::node_canon_offchain_key(INDEXING_PREFIX, index)
}
Loading

0 comments on commit 48d9922

Please sign in to comment.