@@ -7,7 +7,9 @@ use std::{
77
88use sc_network:: PeerId ;
99use sc_tracing:: tracing:: * ;
10- use shc_blockchain_service:: types:: { MspRespondStorageRequest , RespondStorageRequest } ;
10+ use shc_blockchain_service:: types:: {
11+ MspRespondStorageRequest , RespondStorageRequest , RetryStrategy ,
12+ } ;
1113use shc_blockchain_service:: { capacity_manager:: CapacityRequestData , types:: SendExtrinsicOptions } ;
1214use sp_core:: H256 ;
1315use sp_runtime:: traits:: { SaturatedConversion , Zero } ;
@@ -16,7 +18,8 @@ use pallet_file_system::types::RejectedStorageRequest;
1618use shc_actors_framework:: event_bus:: EventHandler ;
1719use shc_blockchain_service:: events:: ProcessMspRespondStoringRequest ;
1820use shc_blockchain_service:: {
19- commands:: BlockchainServiceCommandInterface , events:: NewStorageRequest ,
21+ commands:: { BlockchainServiceCommandInterface , BlockchainServiceCommandInterfaceExt } ,
22+ events:: NewStorageRequest ,
2023} ;
2124use shc_common:: {
2225 traits:: StorageEnableRuntime ,
@@ -39,6 +42,24 @@ use crate::{
3942
4043const 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///
6990{
7091 storage_hub_handler : StorageHubHandler < NT , Runtime > ,
7192 file_key_cleanup : Option < H256 > ,
93+ config : MspUploadFileConfig ,
7294}
7395
7496impl < NT , Runtime > Clone for MspUploadFileTask < NT , Runtime >
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