@@ -27,6 +27,7 @@ pub struct JobsCreators {
2727 templte_to_job_id : HashMap < u64 , u32 , BuildNoHashHasher < u64 > > ,
2828 ids : Id ,
2929 last_target : mining_sv2:: Target ,
30+ last_ntime : Option < u32 > ,
3031 extranonce_len : u8 ,
3132}
3233
@@ -56,6 +57,7 @@ impl JobsCreators {
5657 templte_to_job_id : HashMap :: with_hasher ( BuildNoHashHasher :: default ( ) ) ,
5758 ids : Id :: new ( ) ,
5859 last_target : mining_sv2:: Target :: new ( 0 , 0 ) ,
60+ last_ntime : None ,
5961 extranonce_len,
6062 }
6163 }
@@ -91,6 +93,7 @@ impl JobsCreators {
9193 next_job_id,
9294 version_rolling_allowed,
9395 self . extranonce_len ,
96+ self . last_ntime ,
9497 )
9598 }
9699
@@ -106,6 +109,7 @@ impl JobsCreators {
106109 /// we clear all the saved templates.
107110 pub fn on_new_prev_hash ( & mut self , prev_hash : & SetNewPrevHash < ' static > ) -> Option < u32 > {
108111 self . last_target = prev_hash. target . clone ( ) . into ( ) ;
112+ self . last_ntime = prev_hash. header_timestamp . clone ( ) . into ( ) ; // set correct ntime
109113 let template: Vec < NewTemplate < ' static > > = self
110114 . lasts_new_template
111115 . clone ( )
@@ -162,6 +166,7 @@ pub fn extended_job_from_custom_job(
162166 0 ,
163167 true ,
164168 extranonce_len,
169+ Some ( referenced_job. min_ntime ) ,
165170 )
166171}
167172
@@ -181,6 +186,7 @@ fn new_extended_job(
181186 job_id : u32 ,
182187 version_rolling_allowed : bool ,
183188 extranonce_len : u8 ,
189+ ntime : Option < u32 > ,
184190) -> Result < NewExtendedMiningJob < ' static > , Error > {
185191 coinbase_outputs[ 0 ] . value = match new_template. coinbase_tx_value_remaining . checked_mul ( 1 ) {
186192 //check that value_remaining is updated by TP
@@ -208,11 +214,7 @@ fn new_extended_job(
208214 let min_ntime = match new_template. future_template {
209215 true => binary_sv2:: Sv2Option :: new ( None ) ,
210216 false => {
211- let now = std:: time:: SystemTime :: now ( )
212- . duration_since ( std:: time:: UNIX_EPOCH )
213- . unwrap ( )
214- . as_secs ( ) as u32 ;
215- binary_sv2:: Sv2Option :: new ( Some ( now) )
217+ binary_sv2:: Sv2Option :: new ( ntime)
216218 }
217219 } ;
218220
@@ -432,11 +434,11 @@ impl StrippedCoinbaseTx {
432434 let mut inputs = self . inputs . clone ( ) ;
433435 let last_input = inputs. last_mut ( ) . ok_or ( Error :: BadPayloadSize ) ?;
434436 let new_last_input_len =
435- 32 // outpoint
436- + 4 // vout
437- + 1 // script length byte -> TODO can be also 3 (based on TODO in `coinbase_tx_prefix()`)
438- + self . bip141_bytes_len // space for bip34 bytes
439- ;
437+ 32 // outpoint
438+ + 4 // vout
439+ + 1 // script length byte -> TODO can be also 3 (based on TODO in `coinbase_tx_prefix()`)
440+ + self . bip141_bytes_len // space for bip34 bytes
441+ ;
440442 last_input. truncate ( new_last_input_len) ;
441443 let mut prefix: Vec < u8 > = vec ! [ ] ;
442444 prefix. extend_from_slice ( & self . version . to_le_bytes ( ) ) ;
@@ -747,4 +749,4 @@ pub mod tests {
747749 // println!("SIZE: {:?}", i);
748750 Transaction :: deserialize ( & encoded_clone) . unwrap ( ) ;
749751 }
750- }
752+ }
0 commit comments