From bffa3435cc4cf6fc1f4c3f42e6f929e851fa4e41 Mon Sep 17 00:00:00 2001 From: tommytrg Date: Tue, 29 Apr 2025 11:30:33 +0200 Subject: [PATCH 1/4] feat(priority): add support for stake transaction priorities --- data_structures/src/chain/priority.rs | 271 +++++++++++++++++++++++++- 1 file changed, 265 insertions(+), 6 deletions(-) diff --git a/data_structures/src/chain/priority.rs b/data_structures/src/chain/priority.rs index a4984d8b7..558d55160 100644 --- a/data_structures/src/chain/priority.rs +++ b/data_structures/src/chain/priority.rs @@ -387,6 +387,10 @@ pub struct Priorities { pub vtt_highest: Priority, /// The lowest priority used by data requests transactions in a block. pub vtt_lowest: Option, + /// The highest priority used by stake transactions in a block. + pub st_highest: Priority, + /// The lowest priority used by stake transactions in a block. + pub st_lowest: Option, } impl Priorities { @@ -425,6 +429,24 @@ impl Priorities { self.vtt_lowest = Some(priority); } } + + /// Process the priority of a stake transaction, and update the highest and lowest + /// values accordingly, if the provided value is higher or lower than the previously set values. + #[inline] + pub fn digest_st_priority(&mut self, priority: Priority) { + // Update highest + if priority > self.st_highest { + self.st_highest = priority; + } + // Update lowest + if let Some(st_lowest) = &self.st_lowest { + if &priority < st_lowest { + self.st_lowest = Some(priority); + } + } else if priority != 0 { + self.st_lowest = Some(priority); + } + } } impl fmt::Debug for Priorities { @@ -459,6 +481,10 @@ impl Visitor for PriorityVisitor { self.0 .digest_vtt_priority(Priority::from_absolute_fee_weight(*fee, *weight)); } + Transaction::Stake(_) => { + self.0 + .digest_st_priority(Priority::from_absolute_fee_weight(*fee, *weight)); + } _ => (), } } @@ -492,6 +518,11 @@ pub struct PrioritiesEstimate { pub vtt_medium: PriorityEstimate, pub vtt_high: PriorityEstimate, pub vtt_opulent: PriorityEstimate, + pub st_stinky: PriorityEstimate, + pub st_low: PriorityEstimate, + pub st_medium: PriorityEstimate, + pub st_high: PriorityEstimate, + pub st_opulent: PriorityEstimate, } impl fmt::Display for PrioritiesEstimate { @@ -521,6 +552,16 @@ impl fmt::Display for PrioritiesEstimate { ║ Medium │ {:>13} │ {:<28} ║ ║ High │ {:>13} │ {:<28} ║ ║ Opulent │ {:>13} │ {:<28} ║ +╠══════════════════════════════════════════════════════════╣ +║ Stake transactions ║ +╟──────────┬───────────────┬───────────────────────────────║ +║ Tier │ Time-to-block │ Priority ║ +╟──────────┼───────────────┼───────────────────────────────║ +║ Stinky │ {:>13} │ {:<28} ║ +║ Low │ {:>13} │ {:<28} ║ +║ Medium │ {:>13} │ {:<28} ║ +║ High │ {:>13} │ {:<28} ║ +║ Opulent │ {:>13} │ {:<28} ║ ╚══════════════════════════════════════════════════════════╝"#, // Believe it or not, these `to_string` are needed for proper formatting, hence the // clippy allow directive above. @@ -544,6 +585,16 @@ impl fmt::Display for PrioritiesEstimate { self.vtt_high.priority.to_string(), self.vtt_opulent.time_to_block.to_string(), self.vtt_opulent.priority.to_string(), + self.st_stinky.time_to_block.to_string(), + self.st_stinky.priority.to_string(), + self.st_low.time_to_block.to_string(), + self.st_low.priority.to_string(), + self.st_medium.time_to_block.to_string(), + self.st_medium.priority.to_string(), + self.st_high.time_to_block.to_string(), + self.st_high.priority.to_string(), + self.st_opulent.time_to_block.to_string(), + self.st_opulent.priority.to_string(), ) } } @@ -642,15 +693,16 @@ pub mod strategies { // Create counters for measuring frequency of priorities separately for DRTs and VTTs. let mut drt_counter = counter::Counter::::new(); let mut vtt_counter = counter::Counter::::new(); + let mut st_counter = counter::Counter::::new(); // This is a first pass over the priorities in the engine, just to find out the absolute // minimum and maximum among all the lowest priorities, i.e. what was the priority for the // less prioritized transaction in the blocks with the lowest and highest priority // requirements. - let (drt_lowest_absolute, drt_highest_absolute, vtt_lowest_absolute, vtt_highest_absolute) = + let (drt_lowest_absolute, drt_highest_absolute, vtt_lowest_absolute, vtt_highest_absolute, st_lowest_absolute, st_highest_absolute) = priorities.clone().fold( - (f64::MAX, 0.0f64, f64::MAX, 0.0f64), - |(drt_lowest, drt_highest, vtt_lowest, vtt_highest), priorities| { + (f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64), + |(drt_lowest, drt_highest, vtt_lowest, vtt_highest, st_lowest, st_highest), priorities| { let drt_min = priorities .drt_lowest .unwrap_or(priorities.drt_highest) @@ -659,12 +711,17 @@ pub mod strategies { .vtt_lowest .unwrap_or(priorities.vtt_highest) .as_f64(); - + let st_min = priorities + .st_lowest + .unwrap_or(priorities.st_highest) + .as_f64(); ( drt_lowest.min(drt_min), drt_highest.max(drt_min), vtt_lowest.min(vtt_min), vtt_highest.max(vtt_min), + st_lowest.min(st_min), + st_highest.max(st_min), ) }, ); @@ -672,6 +729,7 @@ pub mod strategies { // The size of each bucket in nWitWu (nano wits per weight unit) let drt_buckets_size = (drt_highest_absolute - drt_lowest_absolute) / buckets_count; let vtt_buckets_size = (vtt_highest_absolute - vtt_lowest_absolute) / buckets_count; + let st_buckets_size = (st_highest_absolute - st_lowest_absolute) / buckets_count; // Now we are ready to map priorities to buckets and insert the bucket numbers into the // lossy counter. @@ -680,6 +738,8 @@ pub mod strategies { drt_lowest, vtt_highest, vtt_lowest, + st_highest, + st_lowest, } in priorities { // This calculates the buckets in which the lowest values should be inserted. @@ -689,6 +749,9 @@ pub mod strategies { let vtt_bucket = ((vtt_lowest.unwrap_or(*vtt_highest).as_f64() - vtt_lowest_absolute) / vtt_buckets_size) .round() as u64; + let st_bucket = ((st_lowest.unwrap_or(*st_highest).as_f64() - st_lowest_absolute) + / st_buckets_size) + .round() as u64; // For a perfect calculation, all values lower than the lowest bucket index // (representing the lowest fee should be inserted. However, we can get a good enough @@ -704,11 +767,16 @@ pub mod strategies { for bucket in vtt_bucket * 90 / 100..=vtt_bucket { vtt_counter.add(bucket); } + for bucket in st_bucket * 90 / 100..=st_bucket { + st_counter.add(bucket); + } } // Make an estimation for each of the targeted time-to-blocks. let mut drt_priorities: Vec = vec![]; let mut vtt_priorities: Vec = vec![]; + let mut st_priorities: Vec = vec![]; + for minutes in target_minutes.into_iter() { // Derive the frequency threshold for this targeted time-to-block. let epochs = f64::from(minutes) * 60.0 / f64::from(seconds_per_epoch); @@ -718,6 +786,7 @@ pub mod strategies { // Run the frequency query on the lossy counters. let drt_elements = drt_counter.query(threshold); let vtt_elements = vtt_counter.query(threshold); + let st_elements = st_counter.query(threshold); // The priority is calculated by reverting the buckets mapping performed before, i.e. // mapping the bucket index back to a priority value. @@ -725,9 +794,12 @@ pub mod strategies { let drt_priority = Priority::from(drt_lowest_absolute + drt_bucket * drt_buckets_size); let vtt_bucket = vtt_elements.max().unwrap_or_default() as f64; let vtt_priority = Priority::from(vtt_lowest_absolute + vtt_bucket * vtt_buckets_size); + let st_bucket = st_elements.max().unwrap_or_default() as f64; + let st_priority = Priority::from(st_lowest_absolute + st_bucket * st_buckets_size); drt_priorities.push(drt_priority); vtt_priorities.push(vtt_priority); + st_priorities.push(st_priority); } let drt_stinky = PriorityEstimate { @@ -770,6 +842,26 @@ pub mod strategies { priority: cmp::max(vtt_priorities[4], Priority::default_opulent()), time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[4]) * 60), }; + let st_stinky = PriorityEstimate { + priority: cmp::max(st_priorities[0], Priority::default_stinky()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[0]) * 60), + }; + let st_low = PriorityEstimate { + priority: cmp::max(st_priorities[1], Priority::default_low()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[1]) * 60), + }; + let st_medium = PriorityEstimate { + priority: cmp::max(st_priorities[2], Priority::default_medium()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[2]) * 60), + }; + let st_high = PriorityEstimate { + priority: cmp::max(st_priorities[3], Priority::default_high()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[3]) * 60), + }; + let st_opulent = PriorityEstimate { + priority: cmp::max(st_priorities[4], Priority::default_opulent()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[4]) * 60), + }; PrioritiesEstimate { drt_stinky, @@ -782,6 +874,11 @@ pub mod strategies { vtt_medium, vtt_high, vtt_opulent, + st_stinky, + st_low, + st_medium, + st_high, + st_opulent, } } } @@ -916,6 +1013,28 @@ mod tests { assert_eq!(priorities.vtt_highest, 7); assert_eq!(priorities.vtt_lowest, Some(3.into())); } + #[test] + fn st_priorities_digestion() { + let mut priorities = Priorities::default(); + assert_eq!(priorities.st_highest, 0); + assert_eq!(priorities.st_lowest, None); + + priorities.digest_st_priority(0.into()); + assert_eq!(priorities.st_highest, 0); + assert_eq!(priorities.st_lowest, None); + + priorities.digest_st_priority(5.into()); + assert_eq!(priorities.st_highest, 5); + assert_eq!(priorities.st_lowest, Some(5.into())); + + priorities.digest_st_priority(7.into()); + assert_eq!(priorities.st_highest, 7); + assert_eq!(priorities.st_lowest, Some(5.into())); + + priorities.digest_st_priority(3.into()); + assert_eq!(priorities.st_highest, 7); + assert_eq!(priorities.st_lowest, Some(3.into())); + } // "Aligned" here means that the `PriorityEngine` capacity will match that of its inner // `VecDeque`, which only happens for capacities `c` satisfying `c = ℕ ^ 2 + 1`. @@ -928,6 +1047,8 @@ mod tests { drt_lowest: None, vtt_highest: Priority::from(i * 2), vtt_lowest: None, + st_highest: Priority::from(i * 3), + st_lowest: None, }) .collect_vec(); @@ -952,6 +1073,8 @@ mod tests { drt_lowest: None, vtt_highest: Priority::from(i * 2), vtt_lowest: None, + st_highest: Priority::from(i * 3), + st_lowest: None, }) .collect_vec(); @@ -1030,6 +1153,26 @@ mod tests { priority: Priority(OrderedFloat(683.3155683232975)), time_to_block: TimeToBlock(60), }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(99.58023815374057)), + time_to_block: TimeToBlock(21600), + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(504.6210794958821)), + time_to_block: TimeToBlock(3600), + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(588.011840948676)), + time_to_block: TimeToBlock(900), + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(635.6637046359867)), + time_to_block: TimeToBlock(300), + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(683.3155683232975)), + time_to_block: TimeToBlock(60), + }, }; assert_eq!(estimate, expected); @@ -1044,6 +1187,8 @@ mod tests { drt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), vtt_highest: Priority::from_absolute_fee_weight(1_000_000, 1), vtt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), + st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + st_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), }; 100 ]; @@ -1092,6 +1237,26 @@ mod tests { priority: Priority(OrderedFloat(1000.0)), time_to_block: TimeToBlock(60), }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(21600), + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(3600), + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(900), + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(300), + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(60), + }, }; assert_eq!(estimate, expected); @@ -1105,6 +1270,8 @@ mod tests { drt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), vtt_highest: Priority::from_absolute_fee_weight(1_000_000, 1), vtt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), + st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + st_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), }; DEFAULT_QUEUE_CAPACITY_EPOCHS ]; @@ -1117,6 +1284,8 @@ mod tests { drt_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), vtt_highest: Priority::from_absolute_fee_weight(1_000_000, 1), vtt_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), + st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + st_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), }); let estimate2 = engine.estimate_priority(Duration::from_secs(45)).unwrap(); @@ -1181,6 +1350,27 @@ mod tests { vtt_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5)), time_to_block: TimeToBlock(60) + }, + // fixme + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.17393312762758165)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.2)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.3)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.4)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5)), + time_to_block: TimeToBlock(60) } } ) @@ -1233,6 +1423,26 @@ mod tests { vtt_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5216648016084563)), time_to_block: TimeToBlock(60) + }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.17393312762758165)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.2)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.3)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.48854749932456354)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5216648016084563)), + time_to_block: TimeToBlock(60) } } ) @@ -1285,6 +1495,26 @@ mod tests { vtt_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5789020418264195)), time_to_block: TimeToBlock(60) + }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.1)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.4339473292851176)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5119998668073571)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5454509543168883)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5789020418264195)), + time_to_block: TimeToBlock(60) } } ) @@ -1337,6 +1567,26 @@ mod tests { vtt_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.6269231539367797)), time_to_block: TimeToBlock(60) + }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.4282576876167673)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.5217473188261849)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5568059305297165)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5801783383320709)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.6269231539367797)), + time_to_block: TimeToBlock(60) } } ) @@ -1361,7 +1611,7 @@ mod tests { let sigma = (max - min) / 5.0; let normal = Normal::new(middle, sigma).unwrap(); let mut prng = StdRng::seed_from_u64(0); - let (mut a, mut b, mut c, mut d) = (middle, middle, middle, middle); + let (mut a, mut b, mut c, mut d, mut e, mut f) = (middle, middle, middle, middle, middle, middle); let smoothing = smoothing.unwrap_or_default(); let mut output = vec![]; @@ -1370,6 +1620,8 @@ mod tests { let mut bb = normal.sample(&mut prng); let mut cb = normal.sample(&mut prng); let mut db = normal.sample(&mut prng); + let mut eb = normal.sample(&mut prng); + let mut fb = normal.sample(&mut prng); if ab < bb { (ab, bb) = (bb, ab) @@ -1377,12 +1629,17 @@ mod tests { if cb < db { (cb, db) = (db, cb) } + if eb < fb { + (eb, fb) = (fb, eb) + } - (a, b, c, d) = ( + (a, b, c, d, e, f) = ( (a * smoothing + ab) / (1.0 + smoothing), (b * smoothing + bb) / (1.0 + smoothing), (c * smoothing + cb) / (1.0 + smoothing), (d * smoothing + db) / (1.0 + smoothing), + (e * smoothing + eb) / (1.0 + smoothing), + (f * smoothing + fb) / (1.0 + smoothing), ); output.push(Priorities { @@ -1390,6 +1647,8 @@ mod tests { drt_lowest: Some(Priority::from(b)), vtt_highest: Priority::from(c), vtt_lowest: Some(Priority::from(d)), + st_highest: Priority::from(e), + st_lowest: Some(Priority::from(f)), }) } From fc87813880180eaeeffbba59595e8467f0af9ca0 Mon Sep 17 00:00:00 2001 From: tommytrg Date: Tue, 29 Apr 2025 11:54:09 +0200 Subject: [PATCH 2/4] feat(priority): add support for unstake transaction priorities --- data_structures/src/chain/priority.rs | 270 +++++++++++++++++++++++++- 1 file changed, 265 insertions(+), 5 deletions(-) diff --git a/data_structures/src/chain/priority.rs b/data_structures/src/chain/priority.rs index 558d55160..001ccedd7 100644 --- a/data_structures/src/chain/priority.rs +++ b/data_structures/src/chain/priority.rs @@ -391,6 +391,10 @@ pub struct Priorities { pub st_highest: Priority, /// The lowest priority used by stake transactions in a block. pub st_lowest: Option, + /// The highest priority used by unstake transactions in a block. + pub ut_highest: Priority, + /// The lowest priority used by unstake transactions in a block. + pub ut_lowest: Option, } impl Priorities { @@ -447,6 +451,24 @@ impl Priorities { self.st_lowest = Some(priority); } } + + /// Process the priority of a unstake transaction, and update the highest and lowest + /// values accordingly, if the provided value is higher or lower than the previously set values. + #[inline] + pub fn digest_ut_priority(&mut self, priority: Priority) { + // Update highest + if priority > self.ut_highest { + self.ut_highest = priority; + } + // Update lowest + if let Some(ut_lowest) = &self.ut_lowest { + if &priority < ut_lowest { + self.ut_lowest = Some(priority); + } + } else if priority != 0 { + self.ut_lowest = Some(priority); + } + } } impl fmt::Debug for Priorities { @@ -485,6 +507,10 @@ impl Visitor for PriorityVisitor { self.0 .digest_st_priority(Priority::from_absolute_fee_weight(*fee, *weight)); } + Transaction::Unstake(_) => { + self.0 + .digest_ut_priority(Priority::from_absolute_fee_weight(*fee, *weight)); + } _ => (), } } @@ -523,6 +549,11 @@ pub struct PrioritiesEstimate { pub st_medium: PriorityEstimate, pub st_high: PriorityEstimate, pub st_opulent: PriorityEstimate, + pub ut_stinky: PriorityEstimate, + pub ut_low: PriorityEstimate, + pub ut_medium: PriorityEstimate, + pub ut_high: PriorityEstimate, + pub ut_opulent: PriorityEstimate, } impl fmt::Display for PrioritiesEstimate { @@ -562,6 +593,17 @@ impl fmt::Display for PrioritiesEstimate { ║ Medium │ {:>13} │ {:<28} ║ ║ High │ {:>13} │ {:<28} ║ ║ Opulent │ {:>13} │ {:<28} ║ + +╠══════════════════════════════════════════════════════════╣ +║ Unstake transactions ║ +╟──────────┬───────────────┬───────────────────────────────║ +║ Tier │ Time-to-block │ Priority ║ +╟──────────┼───────────────┼───────────────────────────────║ +║ Stinky │ {:>13} │ {:<28} ║ +║ Low │ {:>13} │ {:<28} ║ +║ Medium │ {:>13} │ {:<28} ║ +║ High │ {:>13} │ {:<28} ║ +║ Opulent │ {:>13} │ {:<28} ║ ╚══════════════════════════════════════════════════════════╝"#, // Believe it or not, these `to_string` are needed for proper formatting, hence the // clippy allow directive above. @@ -595,6 +637,16 @@ impl fmt::Display for PrioritiesEstimate { self.st_high.priority.to_string(), self.st_opulent.time_to_block.to_string(), self.st_opulent.priority.to_string(), + self.ut_stinky.time_to_block.to_string(), + self.ut_stinky.priority.to_string(), + self.ut_low.time_to_block.to_string(), + self.ut_low.priority.to_string(), + self.ut_medium.time_to_block.to_string(), + self.ut_medium.priority.to_string(), + self.ut_high.time_to_block.to_string(), + self.ut_high.priority.to_string(), + self.ut_opulent.time_to_block.to_string(), + self.ut_opulent.priority.to_string(), ) } } @@ -694,15 +746,16 @@ pub mod strategies { let mut drt_counter = counter::Counter::::new(); let mut vtt_counter = counter::Counter::::new(); let mut st_counter = counter::Counter::::new(); + let mut ut_counter = counter::Counter::::new(); // This is a first pass over the priorities in the engine, just to find out the absolute // minimum and maximum among all the lowest priorities, i.e. what was the priority for the // less prioritized transaction in the blocks with the lowest and highest priority // requirements. - let (drt_lowest_absolute, drt_highest_absolute, vtt_lowest_absolute, vtt_highest_absolute, st_lowest_absolute, st_highest_absolute) = + let (drt_lowest_absolute, drt_highest_absolute, vtt_lowest_absolute, vtt_highest_absolute, st_lowest_absolute, st_highest_absolute, ut_lowest_absolute, ut_highest_absolute) = priorities.clone().fold( - (f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64), - |(drt_lowest, drt_highest, vtt_lowest, vtt_highest, st_lowest, st_highest), priorities| { + (f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64), + |(drt_lowest, drt_highest, vtt_lowest, vtt_highest, st_lowest, st_highest, ut_lowest, ut_highest), priorities| { let drt_min = priorities .drt_lowest .unwrap_or(priorities.drt_highest) @@ -715,6 +768,10 @@ pub mod strategies { .st_lowest .unwrap_or(priorities.st_highest) .as_f64(); + let ut_min = priorities + .ut_lowest + .unwrap_or(priorities.ut_highest) + .as_f64(); ( drt_lowest.min(drt_min), drt_highest.max(drt_min), @@ -722,6 +779,8 @@ pub mod strategies { vtt_highest.max(vtt_min), st_lowest.min(st_min), st_highest.max(st_min), + ut_lowest.min(ut_min), + ut_highest.max(ut_min), ) }, ); @@ -730,6 +789,7 @@ pub mod strategies { let drt_buckets_size = (drt_highest_absolute - drt_lowest_absolute) / buckets_count; let vtt_buckets_size = (vtt_highest_absolute - vtt_lowest_absolute) / buckets_count; let st_buckets_size = (st_highest_absolute - st_lowest_absolute) / buckets_count; + let ut_buckets_size = (ut_highest_absolute - ut_lowest_absolute) / buckets_count; // Now we are ready to map priorities to buckets and insert the bucket numbers into the // lossy counter. @@ -740,6 +800,8 @@ pub mod strategies { vtt_lowest, st_highest, st_lowest, + ut_highest, + ut_lowest, } in priorities { // This calculates the buckets in which the lowest values should be inserted. @@ -752,6 +814,9 @@ pub mod strategies { let st_bucket = ((st_lowest.unwrap_or(*st_highest).as_f64() - st_lowest_absolute) / st_buckets_size) .round() as u64; + let ut_bucket = ((ut_lowest.unwrap_or(*ut_highest).as_f64() - ut_lowest_absolute) + / ut_buckets_size) + .round() as u64; // For a perfect calculation, all values lower than the lowest bucket index // (representing the lowest fee should be inserted. However, we can get a good enough @@ -770,12 +835,16 @@ pub mod strategies { for bucket in st_bucket * 90 / 100..=st_bucket { st_counter.add(bucket); } + for bucket in ut_bucket * 90 / 100..=ut_bucket { + ut_counter.add(bucket); + } } // Make an estimation for each of the targeted time-to-blocks. let mut drt_priorities: Vec = vec![]; let mut vtt_priorities: Vec = vec![]; let mut st_priorities: Vec = vec![]; + let mut ut_priorities: Vec = vec![]; for minutes in target_minutes.into_iter() { // Derive the frequency threshold for this targeted time-to-block. @@ -787,6 +856,7 @@ pub mod strategies { let drt_elements = drt_counter.query(threshold); let vtt_elements = vtt_counter.query(threshold); let st_elements = st_counter.query(threshold); + let ut_elements = ut_counter.query(threshold); // The priority is calculated by reverting the buckets mapping performed before, i.e. // mapping the bucket index back to a priority value. @@ -796,10 +866,13 @@ pub mod strategies { let vtt_priority = Priority::from(vtt_lowest_absolute + vtt_bucket * vtt_buckets_size); let st_bucket = st_elements.max().unwrap_or_default() as f64; let st_priority = Priority::from(st_lowest_absolute + st_bucket * st_buckets_size); + let ut_bucket = ut_elements.max().unwrap_or_default() as f64; + let ut_priority = Priority::from(ut_lowest_absolute + ut_bucket * ut_buckets_size); drt_priorities.push(drt_priority); vtt_priorities.push(vtt_priority); st_priorities.push(st_priority); + ut_priorities.push(ut_priority); } let drt_stinky = PriorityEstimate { @@ -862,6 +935,26 @@ pub mod strategies { priority: cmp::max(st_priorities[4], Priority::default_opulent()), time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[4]) * 60), }; + let ut_stinky = PriorityEstimate { + priority: cmp::max(ut_priorities[0], Priority::default_stinky()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[0]) * 60), + }; + let ut_low = PriorityEstimate { + priority: cmp::max(ut_priorities[1], Priority::default_low()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[1]) * 60), + }; + let ut_medium = PriorityEstimate { + priority: cmp::max(ut_priorities[2], Priority::default_medium()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[2]) * 60), + }; + let ut_high = PriorityEstimate { + priority: cmp::max(ut_priorities[3], Priority::default_high()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[3]) * 60), + }; + let ut_opulent = PriorityEstimate { + priority: cmp::max(ut_priorities[4], Priority::default_opulent()), + time_to_block: TimeToBlock::from_secs(u64::from(target_minutes[4]) * 60), + }; PrioritiesEstimate { drt_stinky, @@ -879,6 +972,11 @@ pub mod strategies { st_medium, st_high, st_opulent, + ut_stinky, + ut_low, + ut_medium, + ut_high, + ut_opulent, } } } @@ -1036,6 +1134,29 @@ mod tests { assert_eq!(priorities.st_lowest, Some(3.into())); } + #[test] + fn ut_priorities_digestion() { + let mut priorities = Priorities::default(); + assert_eq!(priorities.ut_highest, 0); + assert_eq!(priorities.ut_lowest, None); + + priorities.digest_ut_priority(0.into()); + assert_eq!(priorities.ut_highest, 0); + assert_eq!(priorities.ut_lowest, None); + + priorities.digest_ut_priority(5.into()); + assert_eq!(priorities.ut_highest, 5); + assert_eq!(priorities.ut_lowest, Some(5.into())); + + priorities.digest_ut_priority(7.into()); + assert_eq!(priorities.ut_highest, 7); + assert_eq!(priorities.ut_lowest, Some(5.into())); + + priorities.digest_ut_priority(3.into()); + assert_eq!(priorities.ut_highest, 7); + assert_eq!(priorities.ut_lowest, Some(3.into())); + } + // "Aligned" here means that the `PriorityEngine` capacity will match that of its inner // `VecDeque`, which only happens for capacities `c` satisfying `c = ℕ ^ 2 + 1`. #[test] @@ -1049,6 +1170,8 @@ mod tests { vtt_lowest: None, st_highest: Priority::from(i * 3), st_lowest: None, + ut_highest: Priority::from(i * 4), + ut_lowest: None, }) .collect_vec(); @@ -1075,6 +1198,8 @@ mod tests { vtt_lowest: None, st_highest: Priority::from(i * 3), st_lowest: None, + ut_highest: Priority::from(i * 4), + ut_lowest: None, }) .collect_vec(); @@ -1173,6 +1298,26 @@ mod tests { priority: Priority(OrderedFloat(683.3155683232975)), time_to_block: TimeToBlock(60), }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(99.58023815374057)), + time_to_block: TimeToBlock(21600), + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(504.6210794958821)), + time_to_block: TimeToBlock(3600), + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(588.011840948676)), + time_to_block: TimeToBlock(900), + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(635.6637046359867)), + time_to_block: TimeToBlock(300), + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(683.3155683232975)), + time_to_block: TimeToBlock(60), + }, }; assert_eq!(estimate, expected); @@ -1189,6 +1334,8 @@ mod tests { vtt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), st_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), + ut_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + ut_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), }; 100 ]; @@ -1257,6 +1404,26 @@ mod tests { priority: Priority(OrderedFloat(1000.0)), time_to_block: TimeToBlock(60), }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(21600), + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(3600), + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(900), + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(300), + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(1000.0)), + time_to_block: TimeToBlock(60), + }, }; assert_eq!(estimate, expected); @@ -1272,6 +1439,8 @@ mod tests { vtt_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), st_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), + ut_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + ut_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), }; DEFAULT_QUEUE_CAPACITY_EPOCHS ]; @@ -1286,6 +1455,8 @@ mod tests { vtt_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), st_highest: Priority::from_absolute_fee_weight(1_000_000, 1), st_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), + ut_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + ut_lowest: Some(Priority::from_absolute_fee_weight(1, 1)), }); let estimate2 = engine.estimate_priority(Duration::from_secs(45)).unwrap(); @@ -1371,6 +1542,26 @@ mod tests { st_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5)), time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.17393312762758165)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.2)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.3)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.4)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5)), + time_to_block: TimeToBlock(60) } } ) @@ -1443,6 +1634,26 @@ mod tests { st_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5216648016084563)), time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.17393312762758165)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.2)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.3)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.48854749932456354)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5216648016084563)), + time_to_block: TimeToBlock(60) } } ) @@ -1515,6 +1726,26 @@ mod tests { st_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5789020418264195)), time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.1)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.4339473292851176)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5119998668073571)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5454509543168883)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5789020418264195)), + time_to_block: TimeToBlock(60) } } ) @@ -1587,6 +1818,26 @@ mod tests { st_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.6269231539367797)), time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.4282576876167673)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.5217473188261849)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5568059305297165)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5801783383320709)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.6269231539367797)), + time_to_block: TimeToBlock(60) } } ) @@ -1611,7 +1862,7 @@ mod tests { let sigma = (max - min) / 5.0; let normal = Normal::new(middle, sigma).unwrap(); let mut prng = StdRng::seed_from_u64(0); - let (mut a, mut b, mut c, mut d, mut e, mut f) = (middle, middle, middle, middle, middle, middle); + let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) = (middle, middle, middle, middle, middle, middle, middle, middle); let smoothing = smoothing.unwrap_or_default(); let mut output = vec![]; @@ -1622,6 +1873,8 @@ mod tests { let mut db = normal.sample(&mut prng); let mut eb = normal.sample(&mut prng); let mut fb = normal.sample(&mut prng); + let mut gb = normal.sample(&mut prng); + let mut hb = normal.sample(&mut prng); if ab < bb { (ab, bb) = (bb, ab) @@ -1632,14 +1885,19 @@ mod tests { if eb < fb { (eb, fb) = (fb, eb) } + if gb < hb { + (gb, hb) = (hb, gb) + } - (a, b, c, d, e, f) = ( + (a, b, c, d, e, f, g, h) = ( (a * smoothing + ab) / (1.0 + smoothing), (b * smoothing + bb) / (1.0 + smoothing), (c * smoothing + cb) / (1.0 + smoothing), (d * smoothing + db) / (1.0 + smoothing), (e * smoothing + eb) / (1.0 + smoothing), (f * smoothing + fb) / (1.0 + smoothing), + (g * smoothing + gb) / (1.0 + smoothing), + (h * smoothing + hb) / (1.0 + smoothing), ); output.push(Priorities { @@ -1649,6 +1907,8 @@ mod tests { vtt_lowest: Some(Priority::from(d)), st_highest: Priority::from(e), st_lowest: Some(Priority::from(f)), + ut_highest: Priority::from(g), + ut_lowest: Some(Priority::from(h)), }) } From 613c919f45bdc6803dec32a4d9e3d2f0238d6353 Mon Sep 17 00:00:00 2001 From: tommytrg Date: Fri, 9 May 2025 13:51:28 +0200 Subject: [PATCH 3/4] test(data_structures): update priority tests We need to update the tests that use priorities_factory because the inclusion of st (stake) and ut (unstake) priorities introduces additional random values into the priority generation process. This change affects the sequence of random numbers generated by the pseudorandom number generator (prng) and, consequently, the resulting Priorities objects. --- data_structures/src/chain/priority.rs | 167 +++++++++++++------------- 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/data_structures/src/chain/priority.rs b/data_structures/src/chain/priority.rs index 001ccedd7..c3bb260be 100644 --- a/data_structures/src/chain/priority.rs +++ b/data_structures/src/chain/priority.rs @@ -1239,83 +1239,83 @@ mod tests { let expected = PrioritiesEstimate { drt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(115.34829276116884)), + priority: Priority(OrderedFloat(179.58806455633322)), time_to_block: TimeToBlock(21600), }, drt_low: PriorityEstimate { - priority: Priority(OrderedFloat(509.5555102919566)), + priority: Priority(OrderedFloat(506.93216838191876)), time_to_block: TimeToBlock(3600), }, drt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(598.5700432827797)), + priority: Priority(OrderedFloat(588.7681943383152)), time_to_block: TimeToBlock(900), }, drt_high: PriorityEstimate { - priority: Priority(OrderedFloat(636.7191288502753)), + priority: Priority(OrderedFloat(635.5316377419701)), time_to_block: TimeToBlock(300), }, drt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(674.8682144177709)), + priority: Priority(OrderedFloat(682.2950811456253)), time_to_block: TimeToBlock(60), }, vtt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(99.58023815374057)), + priority: Priority(OrderedFloat(98.69972086291244)), time_to_block: TimeToBlock(21600), }, vtt_low: PriorityEstimate { - priority: Priority(OrderedFloat(504.6210794958821)), + priority: Priority(OrderedFloat(504.0641403072455)), time_to_block: TimeToBlock(3600), }, vtt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(588.011840948676)), + priority: Priority(OrderedFloat(590.0505323105889)), time_to_block: TimeToBlock(900), }, vtt_high: PriorityEstimate { - priority: Priority(OrderedFloat(635.6637046359867)), + priority: Priority(OrderedFloat(626.9018431691647)), time_to_block: TimeToBlock(300), }, vtt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(683.3155683232975)), + priority: Priority(OrderedFloat(663.7531540277403)), time_to_block: TimeToBlock(60), }, st_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(99.58023815374057)), + priority: Priority(OrderedFloat(147.6148469637572)), time_to_block: TimeToBlock(21600), }, st_low: PriorityEstimate { - priority: Priority(OrderedFloat(504.6210794958821)), + priority: Priority(OrderedFloat(498.5057734262123)), time_to_block: TimeToBlock(3600), }, st_medium: PriorityEstimate { - priority: Priority(OrderedFloat(588.011840948676)), + priority: Priority(OrderedFloat(589.0582705778136)), time_to_block: TimeToBlock(900), }, st_high: PriorityEstimate { - priority: Priority(OrderedFloat(635.6637046359867)), + priority: Priority(OrderedFloat(634.3345191536143)), time_to_block: TimeToBlock(300), }, st_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(683.3155683232975)), + priority: Priority(OrderedFloat(668.2917055854648)), time_to_block: TimeToBlock(60), }, ut_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(99.58023815374057)), + priority: Priority(OrderedFloat(94.15754187923238)), time_to_block: TimeToBlock(21600), }, ut_low: PriorityEstimate { - priority: Priority(OrderedFloat(504.6210794958821)), + priority: Priority(OrderedFloat(500.257601935986)), time_to_block: TimeToBlock(3600), }, ut_medium: PriorityEstimate { - priority: Priority(OrderedFloat(588.011840948676)), + priority: Priority(OrderedFloat(589.0919900734009)), time_to_block: TimeToBlock(900), }, ut_high: PriorityEstimate { - priority: Priority(OrderedFloat(635.6637046359867)), + priority: Priority(OrderedFloat(627.1638707037214)), time_to_block: TimeToBlock(300), }, ut_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(683.3155683232975)), + priority: Priority(OrderedFloat(690.6170050875892)), time_to_block: TimeToBlock(60), }, }; @@ -1483,11 +1483,11 @@ mod tests { estimate, PrioritiesEstimate { drt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.2891084568633235)), + priority: Priority(OrderedFloat(0.26012197586104785)), time_to_block: TimeToBlock(21600) }, drt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.2891084568633235)), + priority: Priority(OrderedFloat(0.26012197586104785)), time_to_block: TimeToBlock(3600) }, drt_medium: PriorityEstimate { @@ -1503,11 +1503,11 @@ mod tests { time_to_block: TimeToBlock(60) }, vtt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.20368096121383047)), time_to_block: TimeToBlock(21600) }, vtt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.2)), + priority: Priority(OrderedFloat(0.20368096121383047)), time_to_block: TimeToBlock(3600) }, vtt_medium: PriorityEstimate { @@ -1522,13 +1522,12 @@ mod tests { priority: Priority(OrderedFloat(0.5)), time_to_block: TimeToBlock(60) }, - // fixme st_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.29729848625684224)), time_to_block: TimeToBlock(21600) }, st_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.2)), + priority: Priority(OrderedFloat(0.29729848625684224)), time_to_block: TimeToBlock(3600) }, st_medium: PriorityEstimate { @@ -1544,11 +1543,11 @@ mod tests { time_to_block: TimeToBlock(60) }, ut_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.28632348839778504)), time_to_block: TimeToBlock(21600) }, ut_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.2)), + priority: Priority(OrderedFloat(0.28632348839778504)), time_to_block: TimeToBlock(3600) }, ut_medium: PriorityEstimate { @@ -1576,7 +1575,7 @@ mod tests { estimate, PrioritiesEstimate { drt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.18979375840681975)), + priority: Priority(OrderedFloat(0.15702925083789035)), time_to_block: TimeToBlock(21600) }, drt_low: PriorityEstimate { @@ -1584,19 +1583,19 @@ mod tests { time_to_block: TimeToBlock(3600) }, drt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.3)), + priority: Priority(OrderedFloat(0.3965049190709514)), time_to_block: TimeToBlock(900) }, drt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.49456907863619215)), + priority: Priority(OrderedFloat(0.5118080185905735)), time_to_block: TimeToBlock(300) }, drt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5357549327212425)), + priority: Priority(OrderedFloat(0.573894302947293)), time_to_block: TimeToBlock(60) }, vtt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.17218454876604591)), time_to_block: TimeToBlock(21600) }, vtt_low: PriorityEstimate { @@ -1608,15 +1607,15 @@ mod tests { time_to_block: TimeToBlock(900) }, vtt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.48854749932456354)), + priority: Priority(OrderedFloat(0.4950574537029726)), time_to_block: TimeToBlock(300) }, vtt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5216648016084563)), + priority: Priority(OrderedFloat(0.5561415167991479)), time_to_block: TimeToBlock(60) }, st_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.15748499378925293)), time_to_block: TimeToBlock(21600) }, st_low: PriorityEstimate { @@ -1624,19 +1623,19 @@ mod tests { time_to_block: TimeToBlock(3600) }, st_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.3)), + priority: Priority(OrderedFloat(0.3541458525647886)), time_to_block: TimeToBlock(900) }, st_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.48854749932456354)), + priority: Priority(OrderedFloat(0.47929367178558413)), time_to_block: TimeToBlock(300) }, st_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5216648016084563)), + priority: Priority(OrderedFloat(0.5597458412846669)), time_to_block: TimeToBlock(60) }, ut_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.17393312762758165)), + priority: Priority(OrderedFloat(0.1906048021048631)), time_to_block: TimeToBlock(21600) }, ut_low: PriorityEstimate { @@ -1648,11 +1647,11 @@ mod tests { time_to_block: TimeToBlock(900) }, ut_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.48854749932456354)), + priority: Priority(OrderedFloat(0.4762393097434008)), time_to_block: TimeToBlock(300) }, ut_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5216648016084563)), + priority: Priority(OrderedFloat(0.5317793528953387)), time_to_block: TimeToBlock(60) } } @@ -1668,23 +1667,23 @@ mod tests { estimate, PrioritiesEstimate { drt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.13668844087951934)), + priority: Priority(OrderedFloat(0.15702925083789035)), time_to_block: TimeToBlock(21600) }, drt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.43886803485024795)), + priority: Priority(OrderedFloat(0.44074006217140804)), time_to_block: TimeToBlock(3600) }, drt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5093766067767512)), + priority: Priority(OrderedFloat(0.509221982148464)), time_to_block: TimeToBlock(900) }, drt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5496672193061817)), + priority: Priority(OrderedFloat(0.5483545078496388)), time_to_block: TimeToBlock(300) }, drt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.6000304849679698)), + priority: Priority(OrderedFloat(0.5874870335508137)), time_to_block: TimeToBlock(60) }, vtt_stinky: PriorityEstimate { @@ -1692,59 +1691,59 @@ mod tests { time_to_block: TimeToBlock(21600) }, vtt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.4339473292851176)), + priority: Priority(OrderedFloat(0.423089514147716)), time_to_block: TimeToBlock(3600) }, vtt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5119998668073571)), + priority: Priority(OrderedFloat(0.5103411710981076)), time_to_block: TimeToBlock(900) }, vtt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5454509543168883)), + priority: Priority(OrderedFloat(0.5539669995733034)), time_to_block: TimeToBlock(300) }, vtt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5789020418264195)), + priority: Priority(OrderedFloat(0.5757799138109014)), time_to_block: TimeToBlock(60) }, st_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.1)), + priority: Priority(OrderedFloat(0.1440263044618641)), time_to_block: TimeToBlock(21600) }, st_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.4339473292851176)), + priority: Priority(OrderedFloat(0.43073047444064677)), time_to_block: TimeToBlock(3600) }, st_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5119998668073571)), + priority: Priority(OrderedFloat(0.5071849197683221)), time_to_block: TimeToBlock(900) }, st_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5454509543168883)), + priority: Priority(OrderedFloat(0.5454121424321599)), time_to_block: TimeToBlock(300) }, st_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5789020418264195)), + priority: Priority(OrderedFloat(0.5836393650959976)), time_to_block: TimeToBlock(60) }, ut_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.1)), + priority: Priority(OrderedFloat(0.11341166631027368)), time_to_block: TimeToBlock(21600) }, ut_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.4339473292851176)), + priority: Priority(OrderedFloat(0.42834810653370786)), time_to_block: TimeToBlock(3600) }, ut_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5119998668073571)), + priority: Priority(OrderedFloat(0.5096220265913683)), time_to_block: TimeToBlock(900) }, ut_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5454509543168883)), + priority: Priority(OrderedFloat(0.540099746612991)), time_to_block: TimeToBlock(300) }, ut_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.5789020418264195)), + priority: Priority(OrderedFloat(0.6010551866562364)), time_to_block: TimeToBlock(60) } } @@ -1760,83 +1759,83 @@ mod tests { estimate, PrioritiesEstimate { drt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.43338175330931106)), + priority: Priority(OrderedFloat(0.43619650230369633)), time_to_block: TimeToBlock(21600) }, drt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.5181512711463944)), + priority: Priority(OrderedFloat(0.5225426358242867)), time_to_block: TimeToBlock(3600) }, drt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.560536030064936)), + priority: Priority(OrderedFloat(0.5595481216188254)), time_to_block: TimeToBlock(900) }, drt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5923245992538423)), + priority: Priority(OrderedFloat(0.5965536074133642)), time_to_block: TimeToBlock(300) }, drt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.6241131684427486)), + priority: Priority(OrderedFloat(0.6335590932079028)), time_to_block: TimeToBlock(60) }, vtt_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.4282576876167673)), + priority: Priority(OrderedFloat(0.4277241336946116)), time_to_block: TimeToBlock(21600) }, vtt_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.5217473188261849)), + priority: Priority(OrderedFloat(0.5188610598114269)), time_to_block: TimeToBlock(3600) }, vtt_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5568059305297165)), + priority: Priority(OrderedFloat(0.5530374071052326)), time_to_block: TimeToBlock(900) }, vtt_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5801783383320709)), + priority: Priority(OrderedFloat(0.5872137543990384)), time_to_block: TimeToBlock(300) }, vtt_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.6269231539367797)), + priority: Priority(OrderedFloat(0.6099979859282423)), time_to_block: TimeToBlock(60) }, st_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.4282576876167673)), + priority: Priority(OrderedFloat(0.42594491039416227)), time_to_block: TimeToBlock(21600) }, st_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.5217473188261849)), + priority: Priority(OrderedFloat(0.5171826715544424)), time_to_block: TimeToBlock(3600) }, st_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5568059305297165)), + priority: Priority(OrderedFloat(0.5577327876256781)), time_to_block: TimeToBlock(900) }, st_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5801783383320709)), + priority: Priority(OrderedFloat(0.5881453746791048)), time_to_block: TimeToBlock(300) }, st_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.6269231539367797)), + priority: Priority(OrderedFloat(0.6084204327147227)), time_to_block: TimeToBlock(60) }, ut_stinky: PriorityEstimate { - priority: Priority(OrderedFloat(0.4282576876167673)), + priority: Priority(OrderedFloat(0.4347914213819278)), time_to_block: TimeToBlock(21600) }, ut_low: PriorityEstimate { - priority: Priority(OrderedFloat(0.5217473188261849)), + priority: Priority(OrderedFloat(0.512825964594247)), time_to_block: TimeToBlock(3600) }, ut_medium: PriorityEstimate { - priority: Priority(OrderedFloat(0.5568059305297165)), + priority: Priority(OrderedFloat(0.5574171321441437)), time_to_block: TimeToBlock(900) }, ut_high: PriorityEstimate { - priority: Priority(OrderedFloat(0.5801783383320709)), + priority: Priority(OrderedFloat(0.5908605078065662)), time_to_block: TimeToBlock(300) }, ut_opulent: PriorityEstimate { - priority: Priority(OrderedFloat(0.6269231539367797)), + priority: Priority(OrderedFloat(0.6243038834689887)), time_to_block: TimeToBlock(60) } } @@ -1862,7 +1861,9 @@ mod tests { let sigma = (max - min) / 5.0; let normal = Normal::new(middle, sigma).unwrap(); let mut prng = StdRng::seed_from_u64(0); - let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) = (middle, middle, middle, middle, middle, middle, middle, middle); + let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) = ( + middle, middle, middle, middle, middle, middle, middle, middle, + ); let smoothing = smoothing.unwrap_or_default(); let mut output = vec![]; From 51218ebf2c893185b0e227eca3a029c0e8dbb24a Mon Sep 17 00:00:00 2001 From: tommytrg Date: Fri, 9 May 2025 13:51:48 +0200 Subject: [PATCH 4/4] style: run linter --- data_structures/src/chain/priority.rs | 91 +++++++++++++++++---------- data_structures/src/superblock.rs | 2 +- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/data_structures/src/chain/priority.rs b/data_structures/src/chain/priority.rs index c3bb260be..90a565076 100644 --- a/data_structures/src/chain/priority.rs +++ b/data_structures/src/chain/priority.rs @@ -752,38 +752,65 @@ pub mod strategies { // minimum and maximum among all the lowest priorities, i.e. what was the priority for the // less prioritized transaction in the blocks with the lowest and highest priority // requirements. - let (drt_lowest_absolute, drt_highest_absolute, vtt_lowest_absolute, vtt_highest_absolute, st_lowest_absolute, st_highest_absolute, ut_lowest_absolute, ut_highest_absolute) = - priorities.clone().fold( - (f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64, f64::MAX, 0.0f64), - |(drt_lowest, drt_highest, vtt_lowest, vtt_highest, st_lowest, st_highest, ut_lowest, ut_highest), priorities| { - let drt_min = priorities - .drt_lowest - .unwrap_or(priorities.drt_highest) - .as_f64(); - let vtt_min = priorities - .vtt_lowest - .unwrap_or(priorities.vtt_highest) - .as_f64(); - let st_min = priorities - .st_lowest - .unwrap_or(priorities.st_highest) - .as_f64(); - let ut_min = priorities - .ut_lowest - .unwrap_or(priorities.ut_highest) - .as_f64(); - ( - drt_lowest.min(drt_min), - drt_highest.max(drt_min), - vtt_lowest.min(vtt_min), - vtt_highest.max(vtt_min), - st_lowest.min(st_min), - st_highest.max(st_min), - ut_lowest.min(ut_min), - ut_highest.max(ut_min), - ) - }, - ); + let ( + drt_lowest_absolute, + drt_highest_absolute, + vtt_lowest_absolute, + vtt_highest_absolute, + st_lowest_absolute, + st_highest_absolute, + ut_lowest_absolute, + ut_highest_absolute, + ) = priorities.clone().fold( + ( + f64::MAX, + 0.0f64, + f64::MAX, + 0.0f64, + f64::MAX, + 0.0f64, + f64::MAX, + 0.0f64, + ), + |( + drt_lowest, + drt_highest, + vtt_lowest, + vtt_highest, + st_lowest, + st_highest, + ut_lowest, + ut_highest, + ), + priorities| { + let drt_min = priorities + .drt_lowest + .unwrap_or(priorities.drt_highest) + .as_f64(); + let vtt_min = priorities + .vtt_lowest + .unwrap_or(priorities.vtt_highest) + .as_f64(); + let st_min = priorities + .st_lowest + .unwrap_or(priorities.st_highest) + .as_f64(); + let ut_min = priorities + .ut_lowest + .unwrap_or(priorities.ut_highest) + .as_f64(); + ( + drt_lowest.min(drt_min), + drt_highest.max(drt_min), + vtt_lowest.min(vtt_min), + vtt_highest.max(vtt_min), + st_lowest.min(st_min), + st_highest.max(st_min), + ut_lowest.min(ut_min), + ut_highest.max(ut_min), + ) + }, + ); // The size of each bucket in nWitWu (nano wits per weight unit) let drt_buckets_size = (drt_highest_absolute - drt_lowest_absolute) / buckets_count; diff --git a/data_structures/src/superblock.rs b/data_structures/src/superblock.rs index 2448ef0a7..3aeb54c13 100644 --- a/data_structures/src/superblock.rs +++ b/data_structures/src/superblock.rs @@ -490,7 +490,7 @@ impl SuperBlockState { // (assume this takes a week). // Add 7 x 1_920 epochs to take into account the activation delay for V2_0: // 3_048_960 + 7 x 1_920 + 7 x 1_920 = 3_075_840 - // + // // After that, wit/2.0 should be activated with a fixed superblock bootstrap // committee. //