Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
undercover-cactus committed Jan 22, 2025
1 parent eeedc3e commit 3757114
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
24 changes: 21 additions & 3 deletions client/blockchain-service/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ use shc_actors_framework::actor::{Actor, ActorEventLoop};
use shc_common::{
blockchain_utils::{convert_raw_multiaddresses_to_multiaddr, get_events_at_block},
types::{
BlockNumber, EitherBucketOrBspId, Fingerprint, ParachainClient, StorageProviderId,
TickNumber, BCSV_KEY_TYPE,
BlockNumber, EitherBucketOrBspId, Fingerprint, ParachainClient, StorageProviderId, StorageRequestMetadata, TickNumber, BCSV_KEY_TYPE
},
};
use shp_file_metadata::FileKey;
Expand Down Expand Up @@ -1156,9 +1155,28 @@ where
// TODO: Send events to check that this node has a Forest Storage for the BSP that it manages.
// TODO: Catch up to Forest root writes in the BSP Forest.
}
Some(StorageProviderId::MainStorageProvider(_msp_id)) => {
Some(StorageProviderId::MainStorageProvider(msp_id)) => {
// TODO: Send events to check that this node has a Forest Storage for each Bucket this MSP manages.
// TODO: Catch up to Forest root writes in the Bucket's Forests.

// TODO: Call runtime here
let storage_requests: Vec<StorageRequestMetadata> = self
.client
.runtime_api()
.storage_requests_by_msp(block_hash, msp_id).unwrap();

for sr in storage_requests {
self.emit(NewStorageRequest {
who: sr.owner,
file_key: ,
bucket_id: sr.bucket_id,
location: sr.location,
fingerprint: sr.fingerprint.into(),
size: sr.size,
user_peer_ids: ,
expires_at: ,
})
}
}
None => {
warn!(target: LOG_TARGET, "No Provider ID found. This node is not managing a Provider.");
Expand Down
1 change: 1 addition & 0 deletions client/common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub type Balance = pallet_storage_providers::types::BalanceOf<Runtime>;
pub type OpaqueBlock = storage_hub_runtime::opaque::Block;
pub type BlockHash = <OpaqueBlock as BlockT>::Hash;
pub type PeerId = pallet_file_system::types::PeerId<Runtime>;
pub type StorageRequestMetadata = pallet_file_system::types::StorageRequestMetadata<Runtime>;

/// Type alias for the events vector.
///
Expand Down
5 changes: 3 additions & 2 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use shc_common::{
types::{
BackupStorageProviderId, BlockNumber, ChunkId, CustomChallenge, FileMetadata, ForestLeaf,
HashT, KeyProof, KeyProofs, MainStorageProviderId, ProofsDealerProviderId, Proven,
RandomnessOutput, StorageProof, StorageProofsMerkleTrieLayout, BCSV_KEY_TYPE,
FILE_CHUNK_SIZE,
RandomnessOutput, StorageProof, StorageProofsMerkleTrieLayout, StorageRequestMetadata,
BCSV_KEY_TYPE, FILE_CHUNK_SIZE,
},
};
use shc_file_manager::traits::{ExcludeType, FileDataTrie, FileStorage, FileStorageError};
Expand Down Expand Up @@ -251,6 +251,7 @@ where
H256,
BlockNumber,
ChunkId,
StorageRequestMetadata,
>,
FL: FileStorage<StorageProofsMerkleTrieLayout> + Send + Sync,
FSH: ForestStorageHandler + Send + Sync + 'static,
Expand Down
3 changes: 2 additions & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sc_consensus_manual_seal::{
use sc_transaction_pool_api::TransactionPool;
use shc_common::types::{
BackupStorageProviderId, BlockNumber, ChunkId, CustomChallenge, ForestLeaf,
MainStorageProviderId, ProofsDealerProviderId, RandomnessOutput,
MainStorageProviderId, ProofsDealerProviderId, RandomnessOutput, StorageRequestMetadata,
};
use shc_forest_manager::traits::ForestStorageHandler;
use shc_rpc::{StorageHubClientApiServer, StorageHubClientRpc, StorageHubClientRpcConfig};
Expand Down Expand Up @@ -71,6 +71,7 @@ where
H256,
BlockNumber,
ChunkId,
StorageRequestMetadata,
>,
P: TransactionPool + Send + Sync + 'static,
FL: FileStorageT,
Expand Down
10 changes: 9 additions & 1 deletion pallets/file-system/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,27 @@ pub enum QueryConfirmChunksToProveForFileError {
ChallengedChunkToChunkIdError,
}

/// Error type for the `storage_requests_by_msp`.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum StorageRequestsByMSPError {
FailedToRetrieveStorageRequests,
}

sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait FileSystemApi<BackupStorageProviderId, MainStorageProviderId, FileKey, TickNumber, ChunkId>
pub trait FileSystemApi<BackupStorageProviderId, MainStorageProviderId, FileKey, TickNumber, ChunkId, StorageRequestMetadata>
where
BackupStorageProviderId: Codec,
MainStorageProviderId: Codec,
FileKey: Codec,
TickNumber: Codec,
ChunkId: Codec,
StorageRequestMetadata: Codec,
{
fn is_storage_request_open_to_volunteers(file_key: FileKey) -> Result<bool, IsStorageRequestOpenToVolunteersError>;
fn query_earliest_file_volunteer_tick(bsp_id: BackupStorageProviderId, file_key: FileKey) -> Result<TickNumber, QueryFileEarliestVolunteerTickError>;
fn query_bsp_confirm_chunks_to_prove_for_file(bsp_id: BackupStorageProviderId, file_key: FileKey) -> Result<Vec<ChunkId>, QueryBspConfirmChunksToProveForFileError>;
fn query_msp_confirm_chunks_to_prove_for_file(msp_id: MainStorageProviderId, file_key: FileKey) -> Result<Vec<ChunkId>, QueryMspConfirmChunksToProveForFileError>;
fn storage_requests_by_msp(msp_id: MainStorageProviderId) -> Vec<StorageRequestMetadata>;
}
}
17 changes: 17 additions & 0 deletions pallets/file-system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use frame_support::{
};
use frame_system::pallet_prelude::BlockNumberFor;
use num_bigint::BigUint;

Check warning on line 13 in pallets/file-system/src/utils.rs

View workflow job for this annotation

GitHub Actions / Check lint with clippy

unused import: `sp_core::H256`

Check failure on line 13 in pallets/file-system/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build node image

unused import: `sp_core::H256`
use sp_core::H256;

Check failure on line 14 in pallets/file-system/src/utils.rs

View workflow job for this annotation

GitHub Actions / Prepare artifacts

unused import: `sp_core::H256`
use sp_runtime::{
traits::{
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Convert, ConvertBack, Hash, One,
Expand Down Expand Up @@ -2404,6 +2405,22 @@ where

Ok((to_succeed, threshold_slope))
}

pub fn storage_requests_by_msp(
msp_id: ProviderIdFor<T>,
) -> Vec<(MerkleHash<T>, StorageRequestMetadata<T>)> {
// Get the storeage requests for a specific MSP
StorageRequests::<T>::iter()
.filter(|(_, metadata)| {
if let Some(msp) = metadata.msp {
msp.0 == msp_id
} else {
false
}
})
.map(|(file_key, storage)| (file_key, storage))
.collect()
}
}

mod hooks {
Expand Down
7 changes: 6 additions & 1 deletion runtime/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use frame_support::{
weights::Weight,
};
use pallet_aura::Authorities;
use pallet_file_system::types::StorageRequestMetadata;
use pallet_file_system_runtime_api::*;
use pallet_payment_streams_runtime_api::*;
use pallet_proofs_dealer::types::{
Expand Down Expand Up @@ -328,7 +329,7 @@ impl_runtime_apis! {
}
}

impl pallet_file_system_runtime_api::FileSystemApi<Block, BackupStorageProviderId<Runtime>, MainStorageProviderId<Runtime>, H256, BlockNumber, ChunkId> for Runtime {
impl pallet_file_system_runtime_api::FileSystemApi<Block, BackupStorageProviderId<Runtime>, MainStorageProviderId<Runtime>, H256, BlockNumber, ChunkId, StorageRequestMetadata<Runtime>> for Runtime {
fn is_storage_request_open_to_volunteers(file_key: H256) -> Result<bool, IsStorageRequestOpenToVolunteersError> {
FileSystem::is_storage_request_open_to_volunteers(file_key)
}
Expand All @@ -344,6 +345,10 @@ impl_runtime_apis! {
fn query_msp_confirm_chunks_to_prove_for_file(msp_id: MainStorageProviderId<Runtime>, file_key: H256) -> Result<Vec<ChunkId>, QueryMspConfirmChunksToProveForFileError> {
FileSystem::query_msp_confirm_chunks_to_prove_for_file(msp_id, file_key)
}

fn storage_requests_by_msp(msp_id: MainStorageProviderId<Runtime>) -> Vec<StorageRequestMetadata<Runtime>> {
FileSystem::storage_requests_by_msp(msp_id)

Check failure on line 350 in runtime/src/apis.rs

View workflow job for this annotation

GitHub Actions / Check lint with clippy

mismatched types
}
}

impl pallet_payment_streams_runtime_api::PaymentStreamsApi<Block, ProviderIdFor<Runtime>, Balance, AccountId> for Runtime {
Expand Down
7 changes: 6 additions & 1 deletion xcm-simulator/src/storagehub/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use frame_support::{
weights::Weight,
};
use pallet_aura::Authorities;
use pallet_file_system::types::StorageRequestMetadata;
use pallet_file_system_runtime_api::*;
use pallet_payment_streams_runtime_api::*;
use pallet_proofs_dealer::types::{
Expand Down Expand Up @@ -326,7 +327,7 @@ impl_runtime_apis! {
}
}

impl pallet_file_system_runtime_api::FileSystemApi<Block, BackupStorageProviderId<Runtime>, MainStorageProviderId<Runtime>, H256, BlockNumber, ChunkId> for Runtime {
impl pallet_file_system_runtime_api::FileSystemApi<Block, BackupStorageProviderId<Runtime>, MainStorageProviderId<Runtime>, H256, BlockNumber, ChunkId, StorageRequestMetadata<Runtime>> for Runtime {
fn is_storage_request_open_to_volunteers(file_key: H256) -> Result<bool, IsStorageRequestOpenToVolunteersError> {
FileSystem::is_storage_request_open_to_volunteers(file_key)
}
Expand All @@ -342,6 +343,10 @@ impl_runtime_apis! {
fn query_msp_confirm_chunks_to_prove_for_file(msp_id: MainStorageProviderId<Runtime>, file_key: H256) -> Result<Vec<ChunkId>, QueryMspConfirmChunksToProveForFileError> {
FileSystem::query_msp_confirm_chunks_to_prove_for_file(msp_id, file_key)
}

fn storage_requests_by_msp(msp_id: MainStorageProviderId<Runtime>) -> Vec<StorageRequestMetadata<Runtime>> {
FileSystem::storage_requests_by_msp(msp_id)

Check failure on line 348 in xcm-simulator/src/storagehub/apis.rs

View workflow job for this annotation

GitHub Actions / Check lint with clippy

mismatched types
}
}

impl pallet_payment_streams_runtime_api::PaymentStreamsApi<Block, ProviderIdFor<Runtime>, Balance, AccountId> for Runtime {
Expand Down

0 comments on commit 3757114

Please sign in to comment.