@@ -50,6 +50,12 @@ pub(crate) struct ProjectAsset {
50
50
pub ( crate ) encodings : HashMap < String , ProjectAssetEncoding > ,
51
51
}
52
52
53
+ #[ derive( Debug , PartialEq ) ]
54
+ pub enum Mode {
55
+ ByProposal ,
56
+ NormalDeploy ,
57
+ }
58
+
53
59
type IdMapping = BTreeMap < usize , Nat > ;
54
60
type UploadQueue = Vec < ( usize , Vec < u8 > ) > ;
55
61
pub ( crate ) struct ChunkUploader < ' agent > {
@@ -108,9 +114,17 @@ impl<'agent> ChunkUploader<'agent> {
108
114
pub ( crate ) async fn finalize_upload (
109
115
& self ,
110
116
semaphores : & Semaphores ,
117
+ mode : Mode ,
111
118
) -> Result < ( ) , CreateChunkError > {
112
- // Crude estimate: If `MAX_CHUNK_SIZE / 2` bytes are added as data to the `commit_batch` args the message won't be above the message size limit.
113
- self . upload_chunks ( MAX_CHUNK_SIZE / 2 , semaphores) . await
119
+ let max_retained_bytes = if mode == Mode :: ByProposal {
120
+ // Never add data to the commit_batch args, because they have to fit in a single call.
121
+ 0
122
+ } else {
123
+ // Crude estimate: If `MAX_CHUNK_SIZE / 2` bytes are added as data to the `commit_batch` args the message won't be above the message size limit.
124
+ MAX_CHUNK_SIZE / 2
125
+ } ;
126
+
127
+ self . upload_chunks ( max_retained_bytes, semaphores) . await
114
128
}
115
129
116
130
pub ( crate ) fn bytes ( & self ) -> usize {
@@ -412,6 +426,7 @@ pub(crate) async fn make_project_assets(
412
426
chunk_upload_target : Option < & ChunkUploader < ' _ > > ,
413
427
asset_descriptors : Vec < AssetDescriptor > ,
414
428
canister_assets : & HashMap < String , AssetDetails > ,
429
+ mode : Mode ,
415
430
logger : & Logger ,
416
431
) -> Result < HashMap < String , ProjectAsset > , CreateProjectAssetError > {
417
432
let semaphores = Semaphores :: new ( ) ;
@@ -430,11 +445,14 @@ pub(crate) async fn make_project_assets(
430
445
. collect ( ) ;
431
446
let project_assets = try_join_all ( project_asset_futures) . await ?;
432
447
if let Some ( uploader) = chunk_upload_target {
433
- uploader. finalize_upload ( & semaphores) . await . map_err ( |err| {
434
- CreateProjectAssetError :: CreateEncodingError ( CreateEncodingError :: CreateChunkFailed (
435
- err,
436
- ) )
437
- } ) ?;
448
+ uploader
449
+ . finalize_upload ( & semaphores, mode)
450
+ . await
451
+ . map_err ( |err| {
452
+ CreateProjectAssetError :: CreateEncodingError (
453
+ CreateEncodingError :: CreateChunkFailed ( err) ,
454
+ )
455
+ } ) ?;
438
456
}
439
457
440
458
let mut hm = HashMap :: new ( ) ;
0 commit comments