@@ -28,7 +28,7 @@ use crate::{
2828 sim:: {
2929 MiniProtocol , NodeImpl , SimCpuTask , SimMessage ,
3030 linear_leios:: attackers:: { EBWithholdingEvent , EBWithholdingSender } ,
31- lottery,
31+ lottery:: { LotteryConfig , LotteryKind , MockLotteryResults , vrf_probabilities } ,
3232 } ,
3333} ;
3434
@@ -306,7 +306,7 @@ pub struct LinearLeiosNode {
306306 tracker : EventTracker ,
307307 rng : ChaChaRng ,
308308 clock : Clock ,
309- stake : u64 ,
309+ lottery : LotteryConfig ,
310310 consumers : Vec < NodeId > ,
311311 txs : HashMap < TransactionId , TransactionView > ,
312312 ledger_states : BTreeMap < BlockId , Arc < LedgerState > > ,
@@ -333,14 +333,19 @@ impl NodeImpl for LinearLeiosNode {
333333 rng : ChaChaRng ,
334334 clock : Clock ,
335335 ) -> Self {
336+ let lottery = LotteryConfig :: Random {
337+ stake : config. stake ,
338+ total_stake : sim_config. total_stake ,
339+ } ;
340+
336341 Self {
337342 id : config. id ,
338343 sim_config,
339344 queued : EventResult :: default ( ) ,
340345 tracker,
341346 rng,
342347 clock,
343- stake : config . stake ,
348+ lottery ,
344349 consumers : config. consumers . clone ( ) ,
345350 txs : HashMap :: new ( ) ,
346351 ledger_states : BTreeMap :: new ( ) ,
@@ -512,7 +517,10 @@ impl LinearLeiosNode {
512517// Ranking block propagation
513518impl LinearLeiosNode {
514519 fn try_generate_rb ( & mut self , slot : u64 ) {
515- let Some ( vrf) = self . run_vrf ( self . sim_config . block_generation_probability ) else {
520+ let Some ( vrf) = self . run_vrf (
521+ LotteryKind :: GenerateRB ,
522+ self . sim_config . block_generation_probability ,
523+ ) else {
516524 return ;
517525 } ;
518526
@@ -1204,8 +1212,8 @@ impl LinearLeiosNode {
12041212 }
12051213
12061214 fn try_vote_for_endorser_block ( & mut self , eb : & Arc < EndorserBlock > , seen : Timestamp ) -> bool {
1207- let vrf_wins = lottery :: vrf_probabilities ( self . sim_config . vote_probability )
1208- . filter_map ( |f| self . run_vrf ( f) )
1215+ let vrf_wins = vrf_probabilities ( self . sim_config . vote_probability )
1216+ . filter_map ( |f| self . run_vrf ( LotteryKind :: GenerateVote , f) )
12091217 . count ( ) ;
12101218 if vrf_wins == 0 {
12111219 return false ;
@@ -1487,18 +1495,12 @@ impl LinearLeiosNode {
14871495
14881496// Common utilities
14891497impl LinearLeiosNode {
1498+ #[ allow( unused) ]
1499+ pub fn mock_lottery ( & mut self , results : Arc < MockLotteryResults > ) {
1500+ self . lottery = LotteryConfig :: Mock { results } ;
1501+ }
14901502 // Simulates the output of a VRF using this node's stake (if any).
1491- fn run_vrf ( & mut self , success_rate : f64 ) -> Option < u64 > {
1492- let target_vrf_stake = lottery:: compute_target_vrf_stake (
1493- self . stake ,
1494- self . sim_config . total_stake ,
1495- success_rate,
1496- ) ;
1497- let result = self . rng . random_range ( 0 ..self . sim_config . total_stake ) ;
1498- if result < target_vrf_stake {
1499- Some ( result)
1500- } else {
1501- None
1502- }
1503+ fn run_vrf ( & mut self , kind : LotteryKind , success_rate : f64 ) -> Option < u64 > {
1504+ self . lottery . run ( kind, success_rate, & mut self . rng )
15031505 }
15041506}
0 commit comments