@@ -919,7 +919,11 @@ impl WalrusNodeClient<SuiContractClient> {
919919 let walrus_store_blobs =
920920 WalrusStoreBlob :: < String > :: default_unencoded_blobs_from_slice ( blobs, attributes) ;
921921 let start = Instant :: now ( ) ;
922- let encoded_blobs = self . encode_blobs ( walrus_store_blobs, store_args. encoding_type ) ?;
922+ let encoded_blobs = self . encode_blobs_with_chunk_size (
923+ walrus_store_blobs,
924+ store_args. encoding_type ,
925+ store_args. chunk_size ,
926+ ) ?;
923927 store_args. maybe_observe_encoding_latency ( start. elapsed ( ) ) ;
924928
925929 let ( failed_blobs, encoded_blobs) : ( Vec < _ > , Vec < _ > ) =
@@ -965,7 +969,11 @@ impl WalrusNodeClient<SuiContractClient> {
965969 let walrus_store_blobs =
966970 WalrusStoreBlob :: < String > :: default_unencoded_blobs_from_slice ( & blobs, & [ ] ) ;
967971
968- let encoded_blobs = self . encode_blobs ( walrus_store_blobs, store_args. encoding_type ) ?;
972+ let encoded_blobs = self . encode_blobs_with_chunk_size (
973+ walrus_store_blobs,
974+ store_args. encoding_type ,
975+ store_args. chunk_size ,
976+ ) ?;
969977 let ( failed_blobs, encoded_blobs) : ( Vec < _ > , Vec < _ > ) =
970978 encoded_blobs. into_iter ( ) . partition ( |blob| blob. is_failed ( ) ) ;
971979
@@ -1011,7 +1019,11 @@ impl WalrusNodeClient<SuiContractClient> {
10111019 let walrus_store_blobs =
10121020 WalrusStoreBlob :: < String > :: default_unencoded_blobs_from_slice ( blobs, & [ ] ) ;
10131021
1014- let encoded_blobs = self . encode_blobs ( walrus_store_blobs, store_args. encoding_type ) ?;
1022+ let encoded_blobs = self . encode_blobs_with_chunk_size (
1023+ walrus_store_blobs,
1024+ store_args. encoding_type ,
1025+ store_args. chunk_size ,
1026+ ) ?;
10151027 let ( failed_blobs, encoded_blobs) : ( Vec < _ > , Vec < _ > ) =
10161028 encoded_blobs. into_iter ( ) . partition ( |blob| blob. is_failed ( ) ) ;
10171029
@@ -1041,6 +1053,17 @@ impl WalrusNodeClient<SuiContractClient> {
10411053 & self ,
10421054 walrus_store_blobs : Vec < WalrusStoreBlob < ' a , T > > ,
10431055 encoding_type : EncodingType ,
1056+ ) -> ClientResult < Vec < WalrusStoreBlob < ' a , T > > > {
1057+ self . encode_blobs_with_chunk_size ( walrus_store_blobs, encoding_type, None )
1058+ }
1059+
1060+ /// Encodes multiple blobs with optional chunk size override.
1061+ #[ tracing:: instrument( skip_all, fields( count = walrus_store_blobs. len( ) ) ) ]
1062+ pub fn encode_blobs_with_chunk_size < ' a , T : Debug + Clone + Send + Sync > (
1063+ & self ,
1064+ walrus_store_blobs : Vec < WalrusStoreBlob < ' a , T > > ,
1065+ encoding_type : EncodingType ,
1066+ chunk_size : Option < u64 > ,
10441067 ) -> ClientResult < Vec < WalrusStoreBlob < ' a , T > > > {
10451068 if walrus_store_blobs. is_empty ( ) {
10461069 return Ok ( Vec :: new ( ) ) ;
@@ -1075,10 +1098,11 @@ impl WalrusNodeClient<SuiContractClient> {
10751098
10761099 let multi_pb_clone = multi_pb. clone ( ) ;
10771100 let unencoded_blob = blob. get_blob ( ) ;
1078- let encode_result = self . encode_pairs_and_metadata (
1101+ let encode_result = self . encode_pairs_and_metadata_with_chunk_size (
10791102 unencoded_blob,
10801103 encoding_type,
10811104 multi_pb_clone. as_ref ( ) ,
1105+ chunk_size,
10821106 ) ;
10831107 blob. with_encode_result ( encode_result)
10841108 } )
@@ -1100,6 +1124,18 @@ impl WalrusNodeClient<SuiContractClient> {
11001124 blob : & [ u8 ] ,
11011125 encoding_type : EncodingType ,
11021126 multi_pb : & MultiProgress ,
1127+ ) -> ClientResult < ( Vec < SliverPair > , VerifiedBlobMetadataWithId ) > {
1128+ self . encode_pairs_and_metadata_with_chunk_size ( blob, encoding_type, multi_pb, None )
1129+ }
1130+
1131+ /// Encodes a blob into sliver pairs and metadata with optional chunk size override.
1132+ #[ tracing:: instrument( skip_all) ]
1133+ pub fn encode_pairs_and_metadata_with_chunk_size (
1134+ & self ,
1135+ blob : & [ u8 ] ,
1136+ encoding_type : EncodingType ,
1137+ multi_pb : & MultiProgress ,
1138+ chunk_size_override : Option < u64 > ,
11031139 ) -> ClientResult < ( Vec < SliverPair > , VerifiedBlobMetadataWithId ) > {
11041140 use walrus_core:: encoding:: {
11051141 ChunkedBlobEncoder ,
@@ -1116,10 +1152,23 @@ impl WalrusNodeClient<SuiContractClient> {
11161152 let n_shards = self . encoding_config . n_shards ( ) ;
11171153 let max_single_chunk_size = max_blob_size_for_n_shards ( n_shards, encoding_type) ;
11181154
1119- let ( pairs, metadata) = if blob_size > max_single_chunk_size {
1120- // Use chunked encoding for large blobs
1121- let ( num_chunks, chunk_size) =
1122- compute_chunk_parameters ( blob_size, n_shards, encoding_type) ;
1155+ // If chunk_size_override is provided or blob is too large, use chunked encoding
1156+ let use_chunked = chunk_size_override. is_some ( ) || blob_size > max_single_chunk_size;
1157+
1158+ let ( pairs, metadata) = if use_chunked {
1159+ // Use chunked encoding for large blobs or when explicitly requested
1160+ let ( num_chunks, chunk_size) = if let Some ( override_size) = chunk_size_override {
1161+ // Validate that the override chunk size is reasonable
1162+ if override_size == 0 {
1163+ return Err ( ClientError :: store_blob_internal (
1164+ "chunk size must be greater than 0" . to_string ( )
1165+ ) ) ;
1166+ }
1167+ let num_chunks = ( blob_size + override_size - 1 ) / override_size;
1168+ ( num_chunks as u32 , override_size)
1169+ } else {
1170+ compute_chunk_parameters ( blob_size, n_shards, encoding_type)
1171+ } ;
11231172
11241173 spinner. set_message ( format ! ( "encoding large blob ({} chunks)" , num_chunks) ) ;
11251174 tracing:: info!(
0 commit comments