diff --git a/data_structures/src/chain/priority.rs b/data_structures/src/chain/priority.rs index a4984d8b7..90a565076 100644 --- a/data_structures/src/chain/priority.rs +++ b/data_structures/src/chain/priority.rs @@ -387,6 +387,14 @@ 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, + /// 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 { @@ -425,6 +433,42 @@ 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); + } + } + + /// 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 { @@ -459,6 +503,14 @@ 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)); + } + Transaction::Unstake(_) => { + self.0 + .digest_ut_priority(Priority::from_absolute_fee_weight(*fee, *weight)); + } _ => (), } } @@ -492,6 +544,16 @@ 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, + 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 { @@ -521,6 +583,27 @@ 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} ║ + +╠══════════════════════════════════════════════════════════╣ +║ 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. @@ -544,6 +627,26 @@ 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(), + 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(), ) } } @@ -642,36 +745,78 @@ 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(); + 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) = - priorities.clone().fold( - (f64::MAX, 0.0f64, f64::MAX, 0.0f64), - |(drt_lowest, drt_highest, vtt_lowest, vtt_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(); - - ( - drt_lowest.min(drt_min), - drt_highest.max(drt_min), - vtt_lowest.min(vtt_min), - vtt_highest.max(vtt_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; 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. @@ -680,6 +825,10 @@ pub mod strategies { drt_lowest, vtt_highest, vtt_lowest, + st_highest, + st_lowest, + ut_highest, + ut_lowest, } in priorities { // This calculates the buckets in which the lowest values should be inserted. @@ -689,6 +838,12 @@ 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; + 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 @@ -704,11 +859,20 @@ 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); + } + 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. let epochs = f64::from(minutes) * 60.0 / f64::from(seconds_per_epoch); @@ -718,6 +882,8 @@ 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); + 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. @@ -725,9 +891,15 @@ 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); + 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 { @@ -770,6 +942,46 @@ 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), + }; + 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, @@ -782,6 +994,16 @@ pub mod strategies { vtt_medium, vtt_high, vtt_opulent, + st_stinky, + st_low, + st_medium, + st_high, + st_opulent, + ut_stinky, + ut_low, + ut_medium, + ut_high, + ut_opulent, } } } @@ -916,6 +1138,51 @@ 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())); + } + + #[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`. @@ -928,6 +1195,10 @@ mod tests { drt_lowest: None, vtt_highest: Priority::from(i * 2), vtt_lowest: None, + st_highest: Priority::from(i * 3), + st_lowest: None, + ut_highest: Priority::from(i * 4), + ut_lowest: None, }) .collect_vec(); @@ -952,6 +1223,10 @@ mod tests { drt_lowest: None, vtt_highest: Priority::from(i * 2), vtt_lowest: None, + st_highest: Priority::from(i * 3), + st_lowest: None, + ut_highest: Priority::from(i * 4), + ut_lowest: None, }) .collect_vec(); @@ -991,43 +1266,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(147.6148469637572)), + time_to_block: TimeToBlock(21600), + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(498.5057734262123)), + time_to_block: TimeToBlock(3600), + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(589.0582705778136)), + time_to_block: TimeToBlock(900), + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(634.3345191536143)), + time_to_block: TimeToBlock(300), + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(668.2917055854648)), + time_to_block: TimeToBlock(60), + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(94.15754187923238)), + time_to_block: TimeToBlock(21600), + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(500.257601935986)), + time_to_block: TimeToBlock(3600), + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(589.0919900734009)), + time_to_block: TimeToBlock(900), + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(627.1638707037214)), + time_to_block: TimeToBlock(300), + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(690.6170050875892)), time_to_block: TimeToBlock(60), }, }; @@ -1044,6 +1359,10 @@ 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)), + ut_highest: Priority::from_absolute_fee_weight(1_000_000, 1), + ut_lowest: Some(Priority::from_absolute_fee_weight(1_000, 1)), }; 100 ]; @@ -1092,6 +1411,46 @@ 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), + }, + 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); @@ -1105,6 +1464,10 @@ 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)), + 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 ]; @@ -1117,6 +1480,10 @@ 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)), + 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(); @@ -1143,11 +1510,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 { @@ -1163,11 +1530,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 { @@ -1181,6 +1548,46 @@ mod tests { vtt_opulent: PriorityEstimate { priority: Priority(OrderedFloat(0.5)), time_to_block: TimeToBlock(60) + }, + st_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.29729848625684224)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.29729848625684224)), + 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) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.28632348839778504)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.28632348839778504)), + 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) } } ) @@ -1195,7 +1602,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 { @@ -1203,19 +1610,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 { @@ -1227,11 +1634,51 @@ 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.15748499378925293)), + 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.3541458525647886)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.47929367178558413)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5597458412846669)), + time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.1906048021048631)), + 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.4762393097434008)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5317793528953387)), time_to_block: TimeToBlock(60) } } @@ -1247,23 +1694,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 { @@ -1271,19 +1718,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.1440263044618641)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.43073047444064677)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5071849197683221)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5454121424321599)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.5836393650959976)), + time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.11341166631027368)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.42834810653370786)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5096220265913683)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.540099746612991)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.6010551866562364)), time_to_block: TimeToBlock(60) } } @@ -1299,43 +1786,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.42594491039416227)), + time_to_block: TimeToBlock(21600) + }, + st_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.5171826715544424)), + time_to_block: TimeToBlock(3600) + }, + st_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5577327876256781)), + time_to_block: TimeToBlock(900) + }, + st_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5881453746791048)), + time_to_block: TimeToBlock(300) + }, + st_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.6084204327147227)), + time_to_block: TimeToBlock(60) + }, + ut_stinky: PriorityEstimate { + priority: Priority(OrderedFloat(0.4347914213819278)), + time_to_block: TimeToBlock(21600) + }, + ut_low: PriorityEstimate { + priority: Priority(OrderedFloat(0.512825964594247)), + time_to_block: TimeToBlock(3600) + }, + ut_medium: PriorityEstimate { + priority: Priority(OrderedFloat(0.5574171321441437)), + time_to_block: TimeToBlock(900) + }, + ut_high: PriorityEstimate { + priority: Priority(OrderedFloat(0.5908605078065662)), + time_to_block: TimeToBlock(300) + }, + ut_opulent: PriorityEstimate { + priority: Priority(OrderedFloat(0.6243038834689887)), time_to_block: TimeToBlock(60) } } @@ -1361,7 +1888,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) = (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![]; @@ -1370,6 +1899,10 @@ 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); + let mut gb = normal.sample(&mut prng); + let mut hb = normal.sample(&mut prng); if ab < bb { (ab, bb) = (bb, ab) @@ -1377,12 +1910,22 @@ mod tests { if cb < db { (cb, db) = (db, cb) } + if eb < fb { + (eb, fb) = (fb, eb) + } + if gb < hb { + (gb, hb) = (hb, gb) + } - (a, b, c, d) = ( + (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 { @@ -1390,6 +1933,10 @@ 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)), + ut_highest: Priority::from(g), + ut_lowest: Some(Priority::from(h)), }) } 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. //