Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Aug 4, 2023
1 parent d55e1e7 commit e17334e
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 155 deletions.
168 changes: 84 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sdk-dsn = { path = "dsn" }
sdk-substrate = { path = "substrate" }
sdk-farmer = { path = "farmer" }

subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }

# The only triple tested and confirmed as working in `jemallocator` crate is `x86_64-unknown-linux-gnu`
[target.'cfg(all(target_arch = "x86_64", target_vendor = "unknown", target_os = "linux", target_env = "gnu"))'.dev-dependencies]
Expand All @@ -35,7 +35,7 @@ tracing = "0.1"
tracing-futures = "0.2"
tracing-subscriber = "0.3"

subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of
Expand Down
10 changes: 5 additions & 5 deletions dsn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/subs
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }

subspace-networking = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sc-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
sc-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
18 changes: 7 additions & 11 deletions dsn/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use derive_builder::Builder;
use derive_more::{Deref, DerefMut, Display, From};
use either::*;
use futures::prelude::*;
use sc_consensus_subspace::SegmentHeadersStore;
use sdk_utils::{self, DropCollection, Multiaddr, MultiaddrWithPeerId};
use serde::{Deserialize, Serialize};
use subspace_core_primitives::Piece;
Expand All @@ -21,8 +22,6 @@ use subspace_networking::{
SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest, SegmentHeaderResponse,
KADEMLIA_PROVIDER_TTL_IN_SECS,
};
use subspace_service::segment_headers::SegmentHeaderCache;
use subspace_service::Error;

use super::provider_storage_utils::MaybeProviderStorage;
use super::{FarmerProviderStorage, NodePieceCache, NodeProviderStorage, ProviderStorage};
Expand Down Expand Up @@ -180,6 +179,8 @@ pub struct DsnOptions<C, ASNS, PieceByHash, SegmentHeaderByIndexes> {
pub get_segment_header_by_segment_indexes: SegmentHeaderByIndexes,
/// Farmer total allocated space across all plots
pub farmer_total_space_pledged: usize,
/// Segment header store
pub segment_header_store: SegmentHeadersStore<C>
}

/// Farmer piece store
Expand Down Expand Up @@ -237,7 +238,7 @@ impl Dsn {
+ Sync
+ 'static,
F1: Future<Output = Option<PieceByHashResponse>> + Send + 'static,
SegmentHeaderByIndexes: Fn(&SegmentHeaderRequest, &SegmentHeaderCache<C>) -> Option<SegmentHeaderResponse>
SegmentHeaderByIndexes: Fn(&SegmentHeaderRequest, &SegmentHeadersStore<C>) -> Option<SegmentHeaderResponse>
+ Send
+ Sync
+ 'static,
Expand All @@ -252,6 +253,7 @@ impl Dsn {
get_piece_by_hash,
get_segment_header_by_segment_indexes,
farmer_total_space_pledged,
segment_header_store
} = options;
let farmer_readers_and_pieces = Arc::new(parking_lot::Mutex::new(None));
let farmer_piece_store = Arc::new(tokio::sync::Mutex::new(None));
Expand Down Expand Up @@ -418,17 +420,11 @@ impl Dsn {
}
}),
SegmentHeaderBySegmentIndexesRequestHandler::create({
let segment_header_cache =
SegmentHeaderCache::new(client).map_err(|error| {
Error::Other(
format!("Failed to instantiate segment header cache: {error}")
.into(),
)
})?;
let segment_header_store = segment_header_store.clone();
move |_, req| {
futures::future::ready(get_segment_header_by_segment_indexes(
req,
&segment_header_cache,
&segment_header_store,
))
}
}),
Expand Down
14 changes: 7 additions & 7 deletions farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ sdk-utils = { path = "../utils" }
sdk-dsn = { path = "../dsn" }
sdk-traits = { path = "../traits" }

subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-erasure-coding = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b", features = ["parallel", "chia"] }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-erasure-coding = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4", features = ["parallel", "chia"] }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
30 changes: 15 additions & 15 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ derive_builder = "0.12"
derive_more = "0.99"
futures = "0.3"
hex-literal = "0.4"
parity-scale-codec = "3"
parity-scale-codec = "3.6.3"
parking_lot = "0.12"
pin-project = "1"
serde = { version = "1", features = ["derive"] }
Expand Down Expand Up @@ -42,17 +42,17 @@ sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", r
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-version = { version = "22.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }

pallet-rewards = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
pallet-subspace = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sc-consensus-subspace-rpc = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sc-subspace-chain-specs = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sp-domains = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sp-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-transaction-pool = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
pallet-rewards = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
pallet-subspace = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
sc-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
sc-subspace-chain-specs = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
sp-domains = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
sp-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-transaction-pool = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
26 changes: 13 additions & 13 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use anyhow::Context;
use derivative::Derivative;
use futures::channel::{mpsc, oneshot};
use futures::{FutureExt, SinkExt, Stream, StreamExt};
use sc_consensus_subspace_rpc::SegmentHeaderProvider;
use sc_consensus_subspace::SegmentHeadersStore;
use sc_network::network_state::NetworkState;
use sc_network::{NetworkService, NetworkStateInfo, SyncState};
use sc_rpc_api::state::StateApiClient;
Expand All @@ -37,7 +37,6 @@ use subspace_networking::{
};
use subspace_runtime::RuntimeApi;
use subspace_runtime_primitives::opaque::{Block as RuntimeBlock, Header};
use subspace_service::segment_headers::SegmentHeaderCache;
use subspace_service::SubspaceConfiguration;

mod builder;
Expand Down Expand Up @@ -109,6 +108,8 @@ impl<F: Farmer + 'static> Config<F> {
let bootstrap_nodes =
dsn.boot_nodes.clone().into_iter().map(Into::into).collect::<Vec<_>>();

let segment_header_store = partial_components.other.2.clone();

let (dsn, runner) = dsn.build_dsn(DsnOptions {
client: partial_components.client.clone(),
node_name: name.clone(),
Expand All @@ -123,6 +124,7 @@ impl<F: Farmer + 'static> Config<F> {
get_piece_by_hash: get_piece_by_hash::<F>,
get_segment_header_by_segment_indexes,
farmer_total_space_pledged,
segment_header_store
})?;

tracing::debug!("Subspace networking initialized: Node ID is {}", dsn.node.id());
Expand Down Expand Up @@ -701,7 +703,7 @@ const ROOT_BLOCK_NUMBER_LIMIT: u64 = 100;

fn get_segment_header_by_segment_indexes(
req: &SegmentHeaderRequest,
segment_header_cache: &SegmentHeaderCache<impl sc_client_api::AuxStore>,
segment_header_store: &SegmentHeadersStore<impl sc_client_api::AuxStore>,
) -> Option<SegmentHeaderResponse> {
let segment_indexes = match req {
SegmentHeaderRequest::SegmentIndexes { segment_indexes } => segment_indexes.clone(),
Expand All @@ -713,7 +715,7 @@ fn get_segment_header_by_segment_indexes(
block_limit = ROOT_BLOCK_NUMBER_LIMIT;
}

let max_segment_index = segment_header_cache.max_segment_index();
let max_segment_index = segment_header_store.max_segment_index();

// several last segment indexes
(SegmentIndex::ZERO..=max_segment_index)
Expand All @@ -723,17 +725,15 @@ fn get_segment_header_by_segment_indexes(
}
};

let internal_result = segment_indexes
let maybe_segment_headers = segment_indexes
.iter()
.map(|segment_index| segment_header_cache.get_segment_header(*segment_index))
.collect::<Result<Option<Vec<subspace_core_primitives::SegmentHeader>>, _>>();

match internal_result {
Ok(Some(segment_headers)) => Some(SegmentHeaderResponse { segment_headers }),
Ok(None) => None,
Err(error) => {
tracing::error!(%error, "Failed to get segment header from cache");
.map(|segment_index| segment_header_store.get_segment_header(*segment_index))
.collect::<Option<Vec<subspace_core_primitives::SegmentHeader>>>();

match maybe_segment_headers {
Some(segment_headers) => Some(SegmentHeaderResponse { segment_headers }),
None => {
tracing::error!("Segment header collection contained empty segment headers.");
None
}
}
Expand Down
6 changes: 3 additions & 3 deletions traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async-trait = "0.1"
parking_lot = "0.12"
sdk-dsn = { path = "../dsn" }

subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }

sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
14 changes: 7 additions & 7 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ derive_more = "0.99"
futures = "0.3"
jsonrpsee-core = "0.16"
libp2p-core = "0.39"
parity-scale-codec = "3"
parity-scale-codec = "3.6.3"
serde = { version = "1", features = ["derive"] }
ss58-registry = "1.33"
thiserror = "1"
Expand All @@ -34,11 +34,11 @@ sp-core-hashing = { version = "9.0.0", git = "https://github.com/subspace/substr
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-storage = { version = "13.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }

sc-consensus-subspace-rpc = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
sc-consensus-subspace-rpc = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }

# Unused for now. TODO: add `serde` feature to `subspace-core-primitives` in `subspace-archiver`
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "3640edde1832bd5db94677b542c336c65cef564b" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "1e12a6e258e4562c7411c8dec40c155cf112ade4" }
9 changes: 1 addition & 8 deletions utils/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::pin::Pin;

use futures::prelude::*;
use sc_consensus_subspace_rpc::SubspaceRpcApiClient;
use subspace_core_primitives::{Piece, PieceIndex, SegmentCommitment, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{Piece, PieceIndex, SegmentHeader, SegmentIndex};
use subspace_farmer::node_client::{Error, NodeClient};
use subspace_rpc_primitives::{
FarmerAppInfo, NodeSyncStatus, RewardSignatureResponse, RewardSigningInfo, SlotInfo,
Expand Down Expand Up @@ -69,13 +69,6 @@ impl NodeClient for crate::Rpc {
))
}

async fn segment_commitments(
&self,
segment_indexes: Vec<SegmentIndex>,
) -> Result<Vec<Option<SegmentCommitment>>, Error> {
Ok(SubspaceRpcApiClient::segment_commitments(self, segment_indexes).await?)
}

async fn segment_headers(
&self,
segment_indexes: Vec<SegmentIndex>,
Expand Down

0 comments on commit e17334e

Please sign in to comment.