Skip to content

Commit 9010b83

Browse files
authored
refactor: ♻️ Separate MSP and BSP specific functionalities in Blockchain Service (Moonsong-Labs#386)
* feat: 🚧 Add new files `handler_msp` and `handler_bsp` * refactor: ♻️ Move BSP and MSP specific flow out of `handler.rs` * fix: 🚨 Move bsp/msp specific event handling away from handler.rs after merge * feat: 🚧 Separate `check_pending_forest_root_writes` into MSP and BSP specific functions * feat: 🚧 Make commands BSP/MSP specific fail if sent when managing the wrong provider * feat: 🚧 Move `forest_root_write_lock` and `forest_root_snapshots` out of handler and into MSP/BSP specific handlers * refactor: 🚧 Move events processing for forest root changing into MSP/BSP specific handlers * refactor: 🚧 Move common events handling into a separate function * refactor: ♻️ Finish separating MSP/BSP specific functionality in Blockchain Service * fix: 🚨 Compilation fixes after merge * fix: 🚨 Fix compilation and clippy issues * refactor: 🚚 Rename `get_provider_id` to `sync_provider_id`
1 parent dea0e2b commit 9010b83

File tree

10 files changed

+1694
-1211
lines changed

10 files changed

+1694
-1211
lines changed

client/blockchain-service/src/capacity_manager.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use pallet_storage_providers_runtime_api::{
66
QueryEarliestChangeCapacityBlockError, QueryStorageProviderCapacityError, StorageProvidersApi,
77
};
88
use sc_client_api::HeaderBackend;
9-
use shc_common::types::{BlockNumber, StorageData, StorageProviderId};
9+
use shc_common::types::{BlockNumber, StorageData};
1010
use shc_forest_manager::traits::ForestStorageHandler;
1111
use sp_api::ProvideRuntimeApi;
1212
use sp_core::H256;
1313

14-
use crate::{transaction::SubmittedTransaction, BlockchainService};
14+
use crate::{transaction::SubmittedTransaction, types::ManagedProvider, BlockchainService};
1515

1616
const LOG_TARGET: &str = "blockchain-service-capacity-manager";
1717

@@ -352,15 +352,15 @@ where
352352
};
353353

354354
// Get provider ID
355-
let Some(storage_provider_id) = &self.provider_id else {
355+
let Some(managed_provider) = &self.maybe_managed_provider else {
356356
return Err(anyhow!(
357357
"No provider ID set, cannot process capacity requests"
358358
));
359359
};
360360

361-
let inner_provider_id = match storage_provider_id {
362-
StorageProviderId::MainStorageProvider(id)
363-
| StorageProviderId::BackupStorageProvider(id) => id,
361+
let provider_id = match managed_provider {
362+
ManagedProvider::Msp(msp_handler) => msp_handler.msp_id,
363+
ManagedProvider::Bsp(bsp_handler) => bsp_handler.bsp_id,
364364
};
365365

366366
// Get current block hash
@@ -370,14 +370,14 @@ where
370370
let current_capacity = self
371371
.client
372372
.runtime_api()
373-
.query_storage_provider_capacity(current_block_hash, inner_provider_id)
373+
.query_storage_provider_capacity(current_block_hash, &provider_id)
374374
.unwrap_or_else(|_| Err(QueryStorageProviderCapacityError::InternalError))
375375
.map_err(|e| anyhow!("Failed to query current storage capacity: {:?}", e))?;
376376

377377
if current_capacity >= capacity_manager.max_capacity_allowed() {
378378
return Err(anyhow!("Provider already at maximum capacity"));
379379
}
380380

381-
Ok((current_block_hash, current_capacity, *inner_provider_id))
381+
Ok((current_block_hash, current_capacity, provider_id))
382382
}
383383
}

client/blockchain-service/src/handler.rs

+186-583
Large diffs are not rendered by default.

client/blockchain-service/src/handler_bsp.rs

+637
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)