@@ -22,11 +22,10 @@ use zcash_primitives::{transaction::TxId, zip32::AccountId};
2222use zcash_protocol:: consensus:: { self , BlockHeight } ;
2323
2424use crate :: {
25- MAX_BATCH_OUTPUTS ,
2625 client:: { self , FetchRequest } ,
2726 error:: { ScanError , ServerError , SyncError } ,
2827 keys:: transparent:: TransparentAddressId ,
29- sync,
28+ sync:: { self , PerformanceLevel } ,
3029 wallet:: {
3130 ScanTarget , WalletBlock ,
3231 traits:: { SyncBlocks , SyncNullifiers , SyncWallet } ,
8887 }
8988 }
9089
91- pub ( crate ) fn launch ( & mut self ) {
92- self . spawn_batcher ( ) ;
93- self . spawn_workers ( ) ;
90+ pub ( crate ) fn launch ( & mut self , performance_level : PerformanceLevel ) {
91+ let max_batch_outputs = match performance_level {
92+ PerformanceLevel :: Low => 2usize . pow ( 11 ) ,
93+ PerformanceLevel :: Medium => 2usize . pow ( 12 ) ,
94+ PerformanceLevel :: High => 2usize . pow ( 12 ) ,
95+ PerformanceLevel :: Maximum => 2usize . pow ( 13 ) ,
96+ } ;
97+
98+ self . spawn_batcher ( max_batch_outputs) ;
99+ self . spawn_workers ( max_batch_outputs) ;
94100 }
95101
96102 pub ( crate ) fn worker_poolsize ( & self ) -> usize {
@@ -100,13 +106,13 @@ where
100106 /// Spawns the batcher.
101107 ///
102108 /// When the batcher is running it will wait for a scan task.
103- pub ( crate ) fn spawn_batcher ( & mut self ) {
109+ pub ( crate ) fn spawn_batcher ( & mut self , max_batch_outputs : usize ) {
104110 tracing:: debug!( "Spawning batcher" ) ;
105111 let mut batcher = Batcher :: new (
106112 self . consensus_parameters . clone ( ) ,
107113 self . fetch_request_sender . clone ( ) ,
108114 ) ;
109- batcher. run ( ) ;
115+ batcher. run ( max_batch_outputs ) ;
110116 self . batcher = Some ( batcher) ;
111117 }
112118
@@ -132,7 +138,7 @@ where
132138 /// Spawns a worker.
133139 ///
134140 /// When the worker is running it will wait for a scan task.
135- pub ( crate ) fn spawn_worker ( & mut self ) {
141+ pub ( crate ) fn spawn_worker ( & mut self , max_batch_outputs : usize ) {
136142 tracing:: debug!( "Spawning worker {}" , self . unique_id) ;
137143 let mut worker = ScanWorker :: new (
138144 self . unique_id ,
@@ -141,17 +147,17 @@ where
141147 self . fetch_request_sender . clone ( ) ,
142148 self . ufvks . clone ( ) ,
143149 ) ;
144- worker. run ( ) ;
150+ worker. run ( max_batch_outputs ) ;
145151 self . workers . push ( worker) ;
146152 self . unique_id += 1 ;
147153 }
148154
149155 /// Spawns the initial pool of workers.
150156 ///
151157 /// Poolsize is set by [`self::MAX_WORKER_POOLSIZE`].
152- pub ( crate ) fn spawn_workers ( & mut self ) {
158+ pub ( crate ) fn spawn_workers ( & mut self , max_batch_outputs : usize ) {
153159 for _ in 0 ..MAX_WORKER_POOLSIZE {
154- self . spawn_worker ( ) ;
160+ self . spawn_worker ( max_batch_outputs ) ;
155161 }
156162 }
157163
@@ -192,6 +198,7 @@ where
192198 & mut self ,
193199 wallet : & mut W ,
194200 shutdown_mempool : Arc < AtomicBool > ,
201+ performance_level : PerformanceLevel ,
195202 ) -> Result < ( ) , SyncError < W :: Error > >
196203 where
197204 W : SyncWallet + SyncBlocks + SyncNullifiers ,
@@ -227,7 +234,7 @@ where
227234 }
228235
229236 // scan ranges with `Verify` priority
230- self . update_batcher ( wallet)
237+ self . update_batcher ( wallet, performance_level )
231238 . map_err ( SyncError :: WalletError ) ?;
232239 }
233240 ScannerState :: Scan => {
@@ -236,7 +243,7 @@ where
236243 . expect ( "batcher should be running" )
237244 . update_batch_store ( ) ;
238245 self . update_workers ( ) ;
239- self . update_batcher ( wallet)
246+ self . update_batcher ( wallet, performance_level )
240247 . map_err ( SyncError :: WalletError ) ?;
241248 }
242249 ScannerState :: Shutdown => {
@@ -268,15 +275,21 @@ where
268275 }
269276 }
270277
271- fn update_batcher < W > ( & mut self , wallet : & mut W ) -> Result < ( ) , W :: Error >
278+ fn update_batcher < W > (
279+ & mut self ,
280+ wallet : & mut W ,
281+ performance_level : PerformanceLevel ,
282+ ) -> Result < ( ) , W :: Error >
272283 where
273284 W : SyncWallet + SyncBlocks + SyncNullifiers ,
274285 {
275286 let batcher = self . batcher . as_ref ( ) . expect ( "batcher should be running" ) ;
276287 if !batcher. is_batching ( ) {
277- if let Some ( scan_task) =
278- sync:: state:: create_scan_task ( & self . consensus_parameters , wallet) ?
279- {
288+ if let Some ( scan_task) = sync:: state:: create_scan_task (
289+ & self . consensus_parameters ,
290+ wallet,
291+ performance_level,
292+ ) ? {
280293 batcher. add_scan_task ( scan_task) ;
281294 } else if wallet. get_sync_state ( ) ?. scan_complete ( ) {
282295 self . state . shutdown ( ) ;
@@ -320,7 +333,7 @@ where
320333 ///
321334 /// Waits for a scan task and then fetches compact blocks to form fixed output batches. The scan task is split if
322335 /// needed and the compact blocks are added to each scan task and sent to the scan workers for scanning.
323- fn run ( & mut self ) {
336+ fn run ( & mut self , max_batch_outputs : usize ) {
324337 let ( scan_task_sender, mut scan_task_receiver) = mpsc:: channel :: < ScanTask > ( 1 ) ;
325338 let ( batch_sender, batch_receiver) = mpsc:: channel :: < ScanTask > ( 1 ) ;
326339
@@ -405,7 +418,7 @@ where
405418 . vtx
406419 . iter ( )
407420 . fold ( 0 , |acc, transaction| acc + transaction. actions . len ( ) ) ;
408- if sapling_output_count + orchard_output_count > MAX_BATCH_OUTPUTS {
421+ if sapling_output_count + orchard_output_count > max_batch_outputs {
409422 let ( full_batch, new_batch) = scan_task
410423 . clone ( )
411424 . split (
@@ -535,7 +548,7 @@ where
535548 /// Runs the worker in a new tokio task.
536549 ///
537550 /// Waits for a scan task and then calls [`crate::scan::scan`] on the given range.
538- fn run ( & mut self ) {
551+ fn run ( & mut self , max_batch_outputs : usize ) {
539552 let ( scan_task_sender, mut scan_task_receiver) = mpsc:: channel :: < ScanTask > ( 1 ) ;
540553
541554 let is_scanning = self . is_scanning . clone ( ) ;
@@ -552,6 +565,7 @@ where
552565 & consensus_parameters,
553566 & ufvks,
554567 scan_task,
568+ max_batch_outputs,
555569 )
556570 . await ;
557571
0 commit comments