@@ -50,6 +50,12 @@ pub(crate) struct ProjectAsset {
5050 pub ( crate ) encodings : HashMap < String , ProjectAssetEncoding > ,
5151}
5252
53+ #[ derive( Debug , PartialEq ) ]
54+ pub enum Mode {
55+ ByProposal ,
56+ NormalDeploy ,
57+ }
58+
5359type IdMapping = BTreeMap < usize , Nat > ;
5460type UploadQueue = Vec < ( usize , Vec < u8 > ) > ;
5561pub ( crate ) struct ChunkUploader < ' agent > {
@@ -108,9 +114,17 @@ impl<'agent> ChunkUploader<'agent> {
108114 pub ( crate ) async fn finalize_upload (
109115 & self ,
110116 semaphores : & Semaphores ,
117+ mode : Mode ,
111118 ) -> 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
114128 }
115129
116130 pub ( crate ) fn bytes ( & self ) -> usize {
@@ -412,6 +426,7 @@ pub(crate) async fn make_project_assets(
412426 chunk_upload_target : Option < & ChunkUploader < ' _ > > ,
413427 asset_descriptors : Vec < AssetDescriptor > ,
414428 canister_assets : & HashMap < String , AssetDetails > ,
429+ mode : Mode ,
415430 logger : & Logger ,
416431) -> Result < HashMap < String , ProjectAsset > , CreateProjectAssetError > {
417432 let semaphores = Semaphores :: new ( ) ;
@@ -430,11 +445,14 @@ pub(crate) async fn make_project_assets(
430445 . collect ( ) ;
431446 let project_assets = try_join_all ( project_asset_futures) . await ?;
432447 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+ } ) ?;
438456 }
439457
440458 let mut hm = HashMap :: new ( ) ;
0 commit comments