@@ -37,17 +37,33 @@ const TRANSACTION_COUNT_INDEX: usize = 4;
3737#[ cfg_attr( feature = "datasize" , derive( DataSize ) ) ]
3838pub struct TransactionLaneDefinition {
3939 /// The lane identifier
40- id : u8 ,
40+ #[ deprecated(
41+ note = "Use TransactionLaneDefinition::id() or TransactionLaneDefinition::set_id() instead."
42+ ) ]
43+ pub id : u8 ,
4144 /// The maximum length of a transaction in bytes
42- max_transaction_length : u64 ,
45+ #[ deprecated(
46+ note = "Use TransactionLaneDefinition::max_transaction_length() or TransactionLaneDefinition::set_max_transaction_length() instead."
47+ ) ]
48+ pub max_transaction_length : u64 ,
4349 /// The max args length size in bytes
44- max_transaction_args_length : u64 ,
50+ #[ deprecated(
51+ note = "Use TransactionLaneDefinition::max_transaction_args_length() or TransactionLaneDefinition::set_max_transaction_args_length() instead."
52+ ) ]
53+ pub max_transaction_args_length : u64 ,
4554 /// The maximum gas limit
46- max_transaction_gas_limit : u64 ,
55+ #[ deprecated(
56+ note = "Use TransactionLaneDefinition::max_transaction_gas_limit() or TransactionLaneDefinition::set_max_transaction_gas_limit() instead."
57+ ) ]
58+ pub max_transaction_gas_limit : u64 ,
4759 /// The maximum number of transactions
48- max_transaction_count : u64 ,
60+ #[ deprecated(
61+ note = "Use TransactionLaneDefinition::max_transaction_count() or TransactionLaneDefinition::set_max_transaction_count() instead."
62+ ) ]
63+ pub max_transaction_count : u64 ,
4964}
5065
66+ #[ allow( deprecated) ]
5167impl TryFrom < Vec < u64 > > for TransactionLaneDefinition {
5268 type Error = TransactionConfigError ;
5369
@@ -65,6 +81,7 @@ impl TryFrom<Vec<u64>> for TransactionLaneDefinition {
6581 }
6682}
6783
84+ #[ allow( deprecated) ]
6885impl TransactionLaneDefinition {
6986 /// Creates a new instance of TransactionLimitsDefinition
7087 pub fn new (
@@ -118,17 +135,22 @@ impl TransactionLaneDefinition {
118135 self . id
119136 }
120137
121- #[ cfg( any( feature = "testing" , test) ) ]
138+ pub fn set_id ( & mut self , id : u8 ) {
139+ self . id = id;
140+ }
141+
122142 pub fn set_max_transaction_count ( & mut self , max_transaction_count : u64 ) {
123143 self . max_transaction_count = max_transaction_count;
124144 }
125145
126- #[ cfg( any( feature = "testing" , test) ) ]
127146 pub fn set_max_transaction_gas_limit ( & mut self , max_transaction_gas_limit : u64 ) {
128147 self . max_transaction_gas_limit = max_transaction_gas_limit;
129148 }
130149
131- #[ cfg( any( feature = "testing" , test) ) ]
150+ pub fn set_max_transaction_args_length ( & mut self , max_transaction_args_length : u64 ) {
151+ self . max_transaction_args_length = max_transaction_args_length;
152+ }
153+
132154 pub fn set_max_transaction_length ( & mut self , max_transaction_length : u64 ) {
133155 self . max_transaction_length = max_transaction_length;
134156 }
@@ -263,11 +285,11 @@ impl TransactionV1Config {
263285 /// Returns the max serialized length of a transaction for the given lane.
264286 pub fn get_max_serialized_length ( & self , lane_id : u8 ) -> u64 {
265287 match lane_id {
266- MINT_LANE_ID => self . native_mint_lane . max_transaction_length ,
267- AUCTION_LANE_ID => self . native_auction_lane . max_transaction_length ,
268- INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_length ,
269- _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id == lane_id) {
270- Some ( wasm_lane) => wasm_lane. max_transaction_length ,
288+ MINT_LANE_ID => self . native_mint_lane . max_transaction_length ( ) ,
289+ AUCTION_LANE_ID => self . native_auction_lane . max_transaction_length ( ) ,
290+ INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_length ( ) ,
291+ _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id ( ) == lane_id) {
292+ Some ( wasm_lane) => wasm_lane. max_transaction_length ( ) ,
271293 None => 0 ,
272294 } ,
273295 }
@@ -276,11 +298,11 @@ impl TransactionV1Config {
276298 /// Returns the max number of runtime args
277299 pub fn get_max_args_length ( & self , lane_id : u8 ) -> u64 {
278300 match lane_id {
279- MINT_LANE_ID => self . native_mint_lane . max_transaction_args_length ,
280- AUCTION_LANE_ID => self . native_auction_lane . max_transaction_args_length ,
281- INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_args_length ,
282- _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id == lane_id) {
283- Some ( wasm_lane) => wasm_lane. max_transaction_args_length ,
301+ MINT_LANE_ID => self . native_mint_lane . max_transaction_args_length ( ) ,
302+ AUCTION_LANE_ID => self . native_auction_lane . max_transaction_args_length ( ) ,
303+ INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_args_length ( ) ,
304+ _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id ( ) == lane_id) {
305+ Some ( wasm_lane) => wasm_lane. max_transaction_args_length ( ) ,
284306 None => 0 ,
285307 } ,
286308 }
@@ -289,11 +311,11 @@ impl TransactionV1Config {
289311 /// Returns the max gas limit of a transaction for the given lane.
290312 pub fn get_max_transaction_gas_limit ( & self , lane_id : u8 ) -> u64 {
291313 match lane_id {
292- MINT_LANE_ID => self . native_mint_lane . max_transaction_gas_limit ,
293- AUCTION_LANE_ID => self . native_auction_lane . max_transaction_gas_limit ,
294- INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_gas_limit ,
295- _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id == lane_id) {
296- Some ( wasm_lane) => wasm_lane. max_transaction_gas_limit ,
314+ MINT_LANE_ID => self . native_mint_lane . max_transaction_gas_limit ( ) ,
315+ AUCTION_LANE_ID => self . native_auction_lane . max_transaction_gas_limit ( ) ,
316+ INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_gas_limit ( ) ,
317+ _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id ( ) == lane_id) {
318+ Some ( wasm_lane) => wasm_lane. max_transaction_gas_limit ( ) ,
297319 None => 0 ,
298320 } ,
299321 }
@@ -302,11 +324,11 @@ impl TransactionV1Config {
302324 /// Returns the max transactions count for the given lane.
303325 pub fn get_max_transaction_count ( & self , lane_id : u8 ) -> u64 {
304326 match lane_id {
305- MINT_LANE_ID => self . native_mint_lane . max_transaction_count ,
306- AUCTION_LANE_ID => self . native_auction_lane . max_transaction_count ,
307- INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_count ,
308- _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id == lane_id) {
309- Some ( wasm_lane) => wasm_lane. max_transaction_count ,
327+ MINT_LANE_ID => self . native_mint_lane . max_transaction_count ( ) ,
328+ AUCTION_LANE_ID => self . native_auction_lane . max_transaction_count ( ) ,
329+ INSTALL_UPGRADE_LANE_ID => self . install_upgrade_lane . max_transaction_count ( ) ,
330+ _ => match self . wasm_lanes . iter ( ) . find ( |lane| lane. id ( ) == lane_id) {
331+ Some ( wasm_lane) => wasm_lane. max_transaction_count ( ) ,
310332 None => 0 ,
311333 } ,
312334 }
@@ -316,15 +338,15 @@ impl TransactionV1Config {
316338 pub fn get_max_wasm_transaction_count ( & self ) -> u64 {
317339 let mut ret = 0 ;
318340 for lane in self . wasm_lanes . iter ( ) {
319- ret += lane. max_transaction_count ;
341+ ret += lane. max_transaction_count ( ) ;
320342 }
321343 ret
322344 }
323345
324346 /// Are the given transaction parameters supported.
325347 pub fn is_supported ( & self , lane_id : u8 ) -> bool {
326348 if !self . is_predefined_lane ( lane_id) {
327- return self . wasm_lanes . iter ( ) . any ( |lane| lane. id == lane_id) ;
349+ return self . wasm_lanes . iter ( ) . any ( |lane| lane. id ( ) == lane_id) ;
328350 }
329351 true
330352 }
@@ -333,7 +355,7 @@ impl TransactionV1Config {
333355 pub fn get_supported_lanes ( & self ) -> Vec < u8 > {
334356 let mut ret = vec ! [ 0 , 1 , 2 ] ;
335357 for lane in self . wasm_lanes . iter ( ) {
336- ret. push ( lane. id ) ;
358+ ret. push ( lane. id ( ) ) ;
337359 }
338360 ret
339361 }
@@ -348,33 +370,37 @@ impl TransactionV1Config {
348370 large : Option < u64 > ,
349371 ) -> Self {
350372 if let Some ( mint_count) = mint {
351- self . native_mint_lane . max_transaction_count = mint_count;
373+ self . native_mint_lane . set_max_transaction_count ( mint_count) ;
352374 }
353375 if let Some ( auction_count) = auction {
354- self . native_auction_lane . max_transaction_count = auction_count;
376+ self . native_auction_lane
377+ . set_max_transaction_count ( auction_count) ;
355378 }
356379 if let Some ( install_upgrade) = install {
357- self . install_upgrade_lane . max_transaction_count = install_upgrade;
380+ self . install_upgrade_lane
381+ . set_max_transaction_count ( install_upgrade) ;
358382 }
359383 if let Some ( large_limit) = large {
360- for lane in self . wasm_lanes . iter_mut ( ) {
361- if lane. id == 3 {
362- lane. max_transaction_count = large_limit;
384+ let mut wasm_lanes = self . wasm_lanes . clone ( ) ;
385+ for lane in wasm_lanes. iter_mut ( ) {
386+ if lane. id ( ) == 3 {
387+ lane. set_max_transaction_count ( large_limit) ;
363388 }
364389 }
390+ self . set_wasm_lanes ( wasm_lanes) ;
365391 }
366392 self
367393 }
368394
369395 /// Returns the max total count for all transactions across all lanes allowed in a block.
370396 pub fn get_max_block_count ( & self ) -> u64 {
371- self . native_mint_lane . max_transaction_count
372- + self . native_auction_lane . max_transaction_count
373- + self . install_upgrade_lane . max_transaction_count
397+ self . native_mint_lane . max_transaction_count ( )
398+ + self . native_auction_lane . max_transaction_count ( )
399+ + self . install_upgrade_lane . max_transaction_count ( )
374400 + self
375401 . wasm_lanes
376402 . iter ( )
377- . map ( |lane| lane . max_transaction_count )
403+ . map ( TransactionLaneDefinition :: max_transaction_count)
378404 . sum :: < u64 > ( )
379405 }
380406
@@ -395,8 +421,8 @@ impl TransactionV1Config {
395421 let buckets = self . get_wasm_lanes_ordered_by_transaction_size ( ) ;
396422 let number_of_lanes = buckets. len ( ) ;
397423 for ( i, lane) in buckets. iter ( ) . enumerate ( ) {
398- let max_transaction_size = lane. max_transaction_length ;
399- let max_runtime_args_size = lane. max_transaction_args_length ;
424+ let max_transaction_size = lane. max_transaction_length ( ) ;
425+ let max_runtime_args_size = lane. max_transaction_args_length ( ) ;
400426 if max_transaction_size >= transaction_size
401427 && max_runtime_args_size >= runtime_args_size
402428 {
@@ -410,7 +436,7 @@ impl TransactionV1Config {
410436 number_of_lanes - 1 ,
411437 ) ) ;
412438 }
413- maybe_adequate_lane_index. map ( |index| buckets[ index] . id )
439+ maybe_adequate_lane_index. map ( |index| buckets[ index] . id ( ) )
414440 }
415441
416442 pub fn get_lane_by_id ( & self , lane_id : u8 ) -> Option < & TransactionLaneDefinition > {
@@ -423,7 +449,7 @@ impl TransactionV1Config {
423449 if lane_id == INSTALL_UPGRADE_LANE_ID {
424450 return Some ( & self . install_upgrade_lane ) ;
425451 }
426- self . wasm_lanes . iter ( ) . find ( |el| el. id == lane_id)
452+ self . wasm_lanes . iter ( ) . find ( |el| el. id ( ) == lane_id)
427453 }
428454
429455 pub fn get_wasm_lane_id_by_payment_limited (
@@ -435,9 +461,9 @@ impl TransactionV1Config {
435461 let mut maybe_adequate_lane_index = None ;
436462 let lanes = self . get_wasm_lanes_ordered ( ) ;
437463 for ( i, lane) in lanes. iter ( ) . enumerate ( ) {
438- let max_transaction_gas = lane. max_transaction_gas_limit ;
439- let max_transaction_size = lane. max_transaction_length ;
440- let max_runtime_args_size = lane. max_transaction_args_length ;
464+ let max_transaction_gas = lane. max_transaction_gas_limit ( ) ;
465+ let max_transaction_size = lane. max_transaction_length ( ) ;
466+ let max_runtime_args_size = lane. max_transaction_args_length ( ) ;
441467 if gas_limit <= max_transaction_gas
442468 && transaction_size <= max_transaction_size
443469 && runtime_args_size <= max_runtime_args_size
@@ -446,7 +472,7 @@ impl TransactionV1Config {
446472 break ;
447473 }
448474 }
449- maybe_adequate_lane_index. map ( |index| lanes[ index] . id )
475+ maybe_adequate_lane_index. map ( |index| lanes[ index] . id ( ) )
450476 }
451477
452478 #[ allow( unreachable_code) ]
@@ -483,10 +509,10 @@ impl TransactionV1Config {
483509 let mut ordered = wasm_lanes;
484510 ordered. sort_by_key ( |item| {
485511 (
486- item. max_transaction_gas_limit ,
487- item. max_transaction_length ,
488- item. max_transaction_args_length ,
489- item. id ,
512+ item. max_transaction_gas_limit ( ) ,
513+ item. max_transaction_length ( ) ,
514+ item. max_transaction_args_length ( ) ,
515+ item. id ( ) ,
490516 )
491517 } ) ;
492518 ordered
@@ -496,7 +522,7 @@ impl TransactionV1Config {
496522 wasm_lanes : Vec < TransactionLaneDefinition > ,
497523 ) -> Vec < TransactionLaneDefinition > {
498524 let mut ordered = wasm_lanes;
499- ordered. sort_by ( |a , b| a . max_transaction_length . cmp ( & b . max_transaction_length ) ) ;
525+ ordered. sort_by_key ( TransactionLaneDefinition :: max_transaction_length) ;
500526 ordered
501527 }
502528
@@ -524,10 +550,7 @@ impl TransactionV1Config {
524550 pub fn get_max_wasm_lane_by_gas_limit ( & self ) -> Option < TransactionLaneDefinition > {
525551 self . wasm_lanes
526552 . iter ( )
527- . max_by ( |a, b| {
528- a. max_transaction_gas_limit
529- . cmp ( & b. max_transaction_gas_limit )
530- } )
553+ . max_by_key ( |lane| lane. max_transaction_gas_limit ( ) )
531554 . cloned ( )
532555 }
533556}
0 commit comments