Skip to content

Commit e3bf4fc

Browse files
TDemecoffarall
authored andcommitted
feat: 🔊 make the MSP use a retry strategy for its storage request responses (#558)
* feat: ✨ use the retry mechanism for MSP storage request responses * refactor: 🔊 make the peer ID not set log `debug` instead of `trace`
1 parent 74f8508 commit e3bf4fc

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

‎client/blockchain-service/src/handler_msp.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ where
604604
let managed_msp_peer_id = match self.config.peer_id.clone() {
605605
Some(peer_id) => peer_id,
606606
None => {
607-
trace!(target: LOG_TARGET, "MSP node peer ID is not set, meaning it is not meant to be a distributor. Skipping distribution of files.");
607+
debug!(target: LOG_TARGET, "MSP node peer ID is not set, meaning it is not meant to be a distributor. Skipping distribution of files.");
608608
return;
609609
}
610610
};

‎client/src/tasks/msp_upload_file.rs‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::{
77

88
use sc_network::PeerId;
99
use sc_tracing::tracing::*;
10-
use shc_blockchain_service::types::{MspRespondStorageRequest, RespondStorageRequest};
10+
use shc_blockchain_service::types::{
11+
MspRespondStorageRequest, RespondStorageRequest, RetryStrategy,
12+
};
1113
use shc_blockchain_service::{capacity_manager::CapacityRequestData, types::SendExtrinsicOptions};
1214
use sp_core::H256;
1315
use sp_runtime::traits::{SaturatedConversion, Zero};
@@ -16,7 +18,8 @@ use pallet_file_system::types::RejectedStorageRequest;
1618
use shc_actors_framework::event_bus::EventHandler;
1719
use shc_blockchain_service::events::ProcessMspRespondStoringRequest;
1820
use shc_blockchain_service::{
19-
commands::BlockchainServiceCommandInterface, events::NewStorageRequest,
21+
commands::{BlockchainServiceCommandInterface, BlockchainServiceCommandInterfaceExt},
22+
events::NewStorageRequest,
2023
};
2124
use shc_common::{
2225
traits::StorageEnableRuntime,
@@ -39,6 +42,24 @@ use crate::{
3942

4043
const LOG_TARGET: &str = "msp-upload-file-task";
4144

45+
/// Configuration for the MSP upload file task
46+
#[derive(Debug, Clone)]
47+
pub struct MspUploadFileConfig {
48+
/// Maximum number of times to retry submitting respond storage request extrinsic
49+
pub max_try_count: u32,
50+
/// Maximum tip amount to use when submitting respond storage request extrinsic
51+
pub max_tip: u128,
52+
}
53+
54+
impl Default for MspUploadFileConfig {
55+
fn default() -> Self {
56+
Self {
57+
max_try_count: 3,
58+
max_tip: 500,
59+
}
60+
}
61+
}
62+
4263
/// MSP Upload File Task: Handles the whole flow of a file being uploaded to a MSP, from
4364
/// the MSP's perspective.
4465
///
@@ -69,6 +90,7 @@ where
6990
{
7091
storage_hub_handler: StorageHubHandler<NT, Runtime>,
7192
file_key_cleanup: Option<H256>,
93+
config: MspUploadFileConfig,
7294
}
7395

7496
impl<NT, Runtime> Clone for MspUploadFileTask<NT, Runtime>
@@ -81,6 +103,7 @@ where
81103
Self {
82104
storage_hub_handler: self.storage_hub_handler.clone(),
83105
file_key_cleanup: self.file_key_cleanup,
106+
config: self.config.clone(),
84107
}
85108
}
86109
}
@@ -95,8 +118,14 @@ where
95118
Self {
96119
storage_hub_handler,
97120
file_key_cleanup: None,
121+
config: MspUploadFileConfig::default(),
98122
}
99123
}
124+
125+
pub fn with_config(mut self, config: MspUploadFileConfig) -> Self {
126+
self.config = config;
127+
self
128+
}
100129
}
101130

102131
/// Handles the [`NewStorageRequest`] event.
@@ -341,7 +370,7 @@ where
341370

342371
self.storage_hub_handler
343372
.blockchain
344-
.send_extrinsic(
373+
.submit_extrinsic_with_retry(
345374
call,
346375
SendExtrinsicOptions::new(
347376
Duration::from_secs(
@@ -353,9 +382,11 @@ where
353382
Some("fileSystem".to_string()),
354383
Some("mspRespondStorageRequestsMultipleBuckets".to_string()),
355384
),
385+
RetryStrategy::default()
386+
.with_max_retries(self.config.max_try_count)
387+
.with_max_tip(self.config.max_tip.saturated_into()),
388+
false,
356389
)
357-
.await?
358-
.watch_for_success(&self.storage_hub_handler.blockchain)
359390
.await?;
360391

361392
// Log accepted and rejected files, and remove rejected files from File Storage.

0 commit comments

Comments
 (0)