@@ -1599,54 +1599,13 @@ pub enum ApplyDecision {
15991599 Reject ,
16001600}
16011601
1602- #[ derive( Clone , Debug , Serialize , Deserialize ) ]
1603- struct Time {
1604- nanoseconds_since_unix_epoch : u64 ,
1605- }
1606-
1607- impl Time {
1608- #[ cfg( target_family = "wasm" ) ]
1609- fn now ( ) -> Self {
1610- // TODO:
1611- // https://github.com/janestreet/time_now/blob/d7e3801d2f120b6723c28429de0dd63b669d47b8/src/time_now_stubs.c#L16
1612- todo ! ( )
1613- }
1614-
1615- #[ cfg( not( target_family = "wasm" ) ) ]
1616- fn now ( ) -> Self {
1617- const NANOS_PER_SECOND : u64 = 1000000000 ;
1618-
1619- let mut tp = libc:: timeval {
1620- tv_sec : 0 ,
1621- tv_usec : 0 ,
1622- } ;
1623-
1624- let result = unsafe {
1625- // Use same syscall than OCaml:
1626- // https://github.com/janestreet/time_now/blob/d7e3801d2f120b6723c28429de0dd63b669d47b8/src/time_now_stubs.c#L30
1627- libc:: gettimeofday ( & mut tp, std:: ptr:: null_mut ( ) )
1628- } ;
1629- if result == -1 {
1630- return Self {
1631- nanoseconds_since_unix_epoch : 0 ,
1632- } ;
1633- }
1634-
1635- Self {
1636- nanoseconds_since_unix_epoch : NANOS_PER_SECOND
1637- . wrapping_mul ( tp. tv_sec as u64 )
1638- . wrapping_add ( ( tp. tv_usec as u64 ) . wrapping_mul ( 1000 ) ) ,
1639- }
1640- }
1641- }
1642-
16431602const MAX_PER_15_SECONDS : usize = 10 ;
16441603
16451604#[ derive( Clone , Debug , Serialize , Deserialize ) ]
16461605pub struct TransactionPool {
16471606 pub pool : IndexedPool ,
1648- locally_generated_uncommitted : HashMap < ValidCommandWithHash , ( Time , Batch ) > ,
1649- locally_generated_committed : HashMap < ValidCommandWithHash , ( Time , Batch ) > ,
1607+ locally_generated_uncommitted : HashMap < ValidCommandWithHash , ( redux :: Timestamp , Batch ) > ,
1608+ locally_generated_committed : HashMap < ValidCommandWithHash , ( redux :: Timestamp , Batch ) > ,
16501609 current_batch : usize ,
16511610 remaining_in_batch : usize ,
16521611 pub config : Config ,
@@ -1964,6 +1923,7 @@ impl TransactionPool {
19641923
19651924 fn apply (
19661925 & mut self ,
1926+ time : redux:: Timestamp ,
19671927 global_slot_since_genesis : Slot ,
19681928 current_global_slot : Slot ,
19691929 diff : & diff:: DiffVerified ,
@@ -2079,7 +2039,7 @@ impl TransactionPool {
20792039 continue ;
20802040 } ;
20812041 if !all_dropped_cmd_hashes. contains ( & cmd. hash ) {
2082- self . register_locally_generated ( cmd) ;
2042+ self . register_locally_generated ( time , cmd) ;
20832043 }
20842044 }
20852045 }
@@ -2117,6 +2077,7 @@ impl TransactionPool {
21172077
21182078 pub fn unsafe_apply (
21192079 & mut self ,
2080+ time : redux:: Timestamp ,
21202081 global_slot_since_genesis : Slot ,
21212082 current_global_slot : Slot ,
21222083 diff : & diff:: DiffVerified ,
@@ -2131,6 +2092,7 @@ impl TransactionPool {
21312092 String ,
21322093 > {
21332094 let ( decision, accepted, rejected) = self . apply (
2095+ time,
21342096 global_slot_since_genesis,
21352097 current_global_slot,
21362098 diff,
@@ -2140,11 +2102,11 @@ impl TransactionPool {
21402102 Ok ( ( decision, accepted, rejected) )
21412103 }
21422104
2143- fn register_locally_generated ( & mut self , cmd : & ValidCommandWithHash ) {
2105+ fn register_locally_generated ( & mut self , time : redux :: Timestamp , cmd : & ValidCommandWithHash ) {
21442106 match self . locally_generated_uncommitted . entry ( cmd. clone ( ) ) {
21452107 Entry :: Occupied ( mut entry) => {
2146- let ( time , _batch_num) = entry. get_mut ( ) ;
2147- * time = Time :: now ( ) ;
2108+ let ( entry_time , _batch_num) = entry. get_mut ( ) ;
2109+ * entry_time = redux :: Timestamp :: global_now ( ) ;
21482110 }
21492111 Entry :: Vacant ( entry) => {
21502112 let batch_num = if self . remaining_in_batch > 0 {
@@ -2155,7 +2117,7 @@ impl TransactionPool {
21552117 self . current_batch += 1 ;
21562118 self . current_batch
21572119 } ;
2158- entry. insert ( ( Time :: now ( ) , Batch :: Of ( batch_num) ) ) ;
2120+ entry. insert ( ( time , Batch :: Of ( batch_num) ) ) ;
21592121 }
21602122 }
21612123 }
@@ -2259,7 +2221,7 @@ impl TransactionPool {
22592221
22602222 fn get_rebroadcastable < F > ( & mut self , has_timed_out : F ) -> Vec < Vec < UserCommand > >
22612223 where
2262- F : Fn ( & Time ) -> bool ,
2224+ F : Fn ( & redux :: Timestamp ) -> bool ,
22632225 {
22642226 let log = |has_timed_out : bool , s : & str , cmd : & ValidCommandWithHash | -> bool {
22652227 if has_timed_out {
0 commit comments