diff --git a/crates/sc-consensus-subspace-rpc/src/lib.rs b/crates/sc-consensus-subspace-rpc/src/lib.rs index 27ebb67541..65a128dd98 100644 --- a/crates/sc-consensus-subspace-rpc/src/lib.rs +++ b/crates/sc-consensus-subspace-rpc/src/lib.rs @@ -41,7 +41,7 @@ use sp_consensus_slots::Slot; use sp_consensus_subspace::{FarmerPublicKey, FarmerSignature, SubspaceApi as SubspaceRuntimeApi}; use sp_core::crypto::ByteArray; use sp_core::H256; -use sp_runtime::traits::{Block as BlockT, Zero}; +use sp_runtime::traits::Block as BlockT; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::error::Error; @@ -49,14 +49,12 @@ use std::marker::PhantomData; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; use std::time::Duration; -use subspace_core_primitives::{ - Piece, PieceIndex, SegmentCommitment, SegmentHeader, SegmentIndex, Solution, -}; +use subspace_core_primitives::{Piece, PieceIndex, SegmentHeader, SegmentIndex, Solution}; use subspace_farmer_components::FarmerProtocolInfo; use subspace_networking::libp2p::Multiaddr; use subspace_rpc_primitives::{ FarmerAppInfo, NodeSyncStatus, RewardSignatureResponse, RewardSigningInfo, SlotInfo, - SolutionResponse, MAX_SEGMENT_INDEXES_PER_REQUEST, + SolutionResponse, MAX_SEGMENT_HEADERS_PER_REQUEST, }; use tracing::{debug, error, warn}; @@ -109,12 +107,6 @@ pub trait SubspaceRpcApi { )] fn subscribe_node_sync_status_change(&self); - #[method(name = "subspace_segmentCommitments")] - async fn segment_commitments( - &self, - segment_indexes: Vec, - ) -> RpcResult>>; - #[method(name = "subspace_segmentHeaders")] async fn segment_headers( &self, @@ -645,73 +637,18 @@ where Ok(()) } - // TODO: Remove as unnecessary, `segment_headers` can be used instead - async fn segment_commitments( - &self, - segment_indexes: Vec, - ) -> RpcResult>> { - if segment_indexes.len() > MAX_SEGMENT_INDEXES_PER_REQUEST { - error!( - "segment_indexes length exceed the limit: {} ", - segment_indexes.len() - ); - - return Err(JsonRpseeError::Custom(format!( - "segment_indexes length exceed the limit {MAX_SEGMENT_INDEXES_PER_REQUEST}" - ))); - }; - - let runtime_api = self.client.runtime_api(); - let best_hash = self.client.info().best_hash; - let best_block_number = self.client.info().best_number; - - let segment_commitment_result: Result, JsonRpseeError> = segment_indexes - .into_iter() - .map(|segment_index| { - let api_result = runtime_api - .segment_commitment(best_hash, segment_index) - .map_err(|_| { - JsonRpseeError::Custom( - "Internal error during `segment_commitment` call".to_string(), - ) - }); - - api_result.map(|maybe_segment_commitment| { - // This is not a very nice hack due to the fact that at the time first block is - // produced extrinsics with segment headers are not yet in runtime. - if maybe_segment_commitment.is_none() && best_block_number.is_zero() { - self.segment_headers_store - .get_segment_header(segment_index) - .map(|segment_header| segment_header.segment_commitment()) - } else { - maybe_segment_commitment - } - }) - }) - .collect(); - - if let Err(ref err) = segment_commitment_result { - error!( - "Failed to get data from runtime API (segment_commitment): {}", - err - ); - } - - segment_commitment_result - } - async fn segment_headers( &self, segment_indexes: Vec, ) -> RpcResult>> { - if segment_indexes.len() > MAX_SEGMENT_INDEXES_PER_REQUEST { + if segment_indexes.len() > MAX_SEGMENT_HEADERS_PER_REQUEST { error!( "segment_indexes length exceed the limit: {} ", segment_indexes.len() ); return Err(JsonRpseeError::Custom(format!( - "segment_indexes length exceed the limit {MAX_SEGMENT_INDEXES_PER_REQUEST}" + "segment_indexes length exceed the limit {MAX_SEGMENT_HEADERS_PER_REQUEST}" ))); }; diff --git a/crates/subspace-farmer/src/node_client.rs b/crates/subspace-farmer/src/node_client.rs index fdda2d3920..00aa85ea42 100644 --- a/crates/subspace-farmer/src/node_client.rs +++ b/crates/subspace-farmer/src/node_client.rs @@ -3,7 +3,7 @@ pub(crate) mod node_rpc_client; use async_trait::async_trait; use futures::Stream; use std::pin::Pin; -use subspace_core_primitives::{Piece, PieceIndex, SegmentCommitment, SegmentHeader, SegmentIndex}; +use subspace_core_primitives::{Piece, PieceIndex, SegmentHeader, SegmentIndex}; use subspace_rpc_primitives::{ FarmerAppInfo, NodeSyncStatus, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, @@ -50,12 +50,6 @@ pub trait NodeClient: Clone + Send + Sync + 'static { &self, ) -> Result + Send + 'static>>, Error>; - /// Get segment commitments for the segments - async fn segment_commitments( - &self, - segment_indexes: Vec, - ) -> Result>, Error>; - /// Get segment headers for the segments async fn segment_headers( &self, diff --git a/crates/subspace-farmer/src/node_client/node_rpc_client.rs b/crates/subspace-farmer/src/node_client/node_rpc_client.rs index b74b36e2ca..a9db6e4e64 100644 --- a/crates/subspace-farmer/src/node_client/node_rpc_client.rs +++ b/crates/subspace-farmer/src/node_client/node_rpc_client.rs @@ -7,7 +7,7 @@ use jsonrpsee::rpc_params; use jsonrpsee::ws_client::{WsClient, WsClientBuilder}; use std::pin::Pin; use std::sync::Arc; -use subspace_core_primitives::{Piece, PieceIndex, SegmentCommitment, SegmentHeader, SegmentIndex}; +use subspace_core_primitives::{Piece, PieceIndex, SegmentHeader, SegmentIndex}; use subspace_rpc_primitives::{ FarmerAppInfo, NodeSyncStatus, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, @@ -141,16 +141,6 @@ impl NodeClient for NodeRpcClient { ))) } - async fn segment_commitments( - &self, - segment_indexes: Vec, - ) -> Result>, RpcError> { - Ok(self - .client - .request("subspace_segmentCommitments", rpc_params![&segment_indexes]) - .await?) - } - async fn segment_headers( &self, segment_indexes: Vec, diff --git a/crates/subspace-farmer/src/utils/piece_validator.rs b/crates/subspace-farmer/src/utils/piece_validator.rs index 0ed0c7ca4a..089ac16a18 100644 --- a/crates/subspace-farmer/src/utils/piece_validator.rs +++ b/crates/subspace-farmer/src/utils/piece_validator.rs @@ -55,25 +55,21 @@ where let segment_commitment = match maybe_segment_commitment { Some(segment_commitment) => segment_commitment, None => { - let segment_commitments = match self - .node_client - .segment_commitments(vec![segment_index]) - .await - { - Ok(segment_commitments) => segment_commitments, - Err(error) => { - error!( - %piece_index, - ?error, - "Failed tor retrieve segment commitment from node" - ); - return None; - } - }; + let segment_headers = + match self.node_client.segment_headers(vec![segment_index]).await { + Ok(segment_headers) => segment_headers, + Err(error) => { + error!( + %piece_index, + ?error, + "Failed tor retrieve segment headers from node" + ); + return None; + } + }; - let segment_commitment = match segment_commitments.into_iter().next().flatten() - { - Some(segment_commitment) => segment_commitment, + let segment_commitment = match segment_headers.into_iter().next().flatten() { + Some(segment_header) => segment_header.segment_commitment(), None => { error!( %piece_index, diff --git a/crates/subspace-rpc-primitives/src/lib.rs b/crates/subspace-rpc-primitives/src/lib.rs index 7abde7c711..8f63a71525 100644 --- a/crates/subspace-rpc-primitives/src/lib.rs +++ b/crates/subspace-rpc-primitives/src/lib.rs @@ -22,8 +22,8 @@ use subspace_core_primitives::{ use subspace_farmer_components::FarmerProtocolInfo; use subspace_networking::libp2p::Multiaddr; -/// Defines a limit for segment indexes array. It affects storage access on the runtime side. -pub const MAX_SEGMENT_INDEXES_PER_REQUEST: usize = 300; +/// Defines a limit for number of segments that can be requested over RPC +pub const MAX_SEGMENT_HEADERS_PER_REQUEST: usize = 300; /// Information necessary for farmer application #[derive(Debug, Clone, Serialize, Deserialize)]