@@ -16,11 +16,11 @@ use tower::Service;
16
16
use tracing:: { Instrument , Span } ;
17
17
18
18
use zebra_chain:: {
19
- block:: { self , Block } ,
19
+ block:: { self , Block , Height } ,
20
20
chain_sync_status:: ChainSyncStatus ,
21
21
chain_tip:: ChainTip ,
22
22
diagnostic:: task:: WaitForPanics ,
23
- parameters:: NetworkUpgrade ,
23
+ parameters:: { Network , NetworkUpgrade } ,
24
24
serialization:: { AtLeastOne , ZcashSerialize } ,
25
25
shutdown:: is_shutting_down,
26
26
work:: equihash:: { Solution , SolverCancelled } ,
@@ -61,6 +61,7 @@ pub const BLOCK_MINING_WAIT_TIME: Duration = Duration::from_secs(3);
61
61
///
62
62
/// See [`run_mining_solver()`] for more details.
63
63
pub fn spawn_init < Mempool , State , Tip , BlockVerifierRouter , SyncStatus , AddressBook > (
64
+ network : & Network ,
64
65
config : & Config ,
65
66
rpc : GetBlockTemplateRpcImpl < Mempool , State , Tip , BlockVerifierRouter , SyncStatus , AddressBook > ,
66
67
) -> JoinHandle < Result < ( ) , Report > >
@@ -94,10 +95,11 @@ where
94
95
SyncStatus : ChainSyncStatus + Clone + Send + Sync + ' static ,
95
96
AddressBook : AddressBookPeers + Clone + Send + Sync + ' static ,
96
97
{
98
+ let network = network. clone ( ) ;
97
99
let config = config. clone ( ) ;
98
100
99
101
// TODO: spawn an entirely new executor here, so mining is isolated from higher priority tasks.
100
- tokio:: spawn ( init ( config, rpc) . in_current_span ( ) )
102
+ tokio:: spawn ( init ( network , config, rpc) . in_current_span ( ) )
101
103
}
102
104
103
105
/// Initialize the miner based on its config.
@@ -107,6 +109,7 @@ where
107
109
///
108
110
/// See [`run_mining_solver()`] for more details.
109
111
pub async fn init < Mempool , State , Tip , BlockVerifierRouter , SyncStatus , AddressBook > (
112
+ network : Network ,
110
113
_config : Config ,
111
114
rpc : GetBlockTemplateRpcImpl < Mempool , State , Tip , BlockVerifierRouter , SyncStatus , AddressBook > ,
112
115
) -> Result < ( ) , Report >
@@ -163,7 +166,7 @@ where
163
166
let mut abort_handles = Vec :: new ( ) ;
164
167
165
168
let template_generator = tokio:: task:: spawn (
166
- generate_block_templates ( rpc. clone ( ) , template_sender) . in_current_span ( ) ,
169
+ generate_block_templates ( network , rpc. clone ( ) , template_sender) . in_current_span ( ) ,
167
170
) ;
168
171
abort_handles. push ( template_generator. abort_handle ( ) ) ;
169
172
let template_generator = template_generator. wait_for_panics ( ) ;
@@ -217,6 +220,7 @@ pub async fn generate_block_templates<
217
220
SyncStatus ,
218
221
AddressBook ,
219
222
> (
223
+ network : Network ,
220
224
rpc : GetBlockTemplateRpcImpl < Mempool , State , Tip , BlockVerifierRouter , SyncStatus , AddressBook > ,
221
225
template_sender : watch:: Sender < Option < Arc < Block > > > ,
222
226
) -> Result < ( ) , Report >
@@ -260,11 +264,11 @@ where
260
264
261
265
// Shut down the task when all the template receivers are dropped, or Zebra shuts down.
262
266
while !template_sender. is_closed ( ) && !is_shutting_down ( ) {
263
- let template = rpc. get_block_template ( Some ( parameters. clone ( ) ) ) . await ;
267
+ let template: Result < _ , _ > = rpc. get_block_template ( Some ( parameters. clone ( ) ) ) . await ;
264
268
265
269
// Wait for the chain to sync so we get a valid template.
266
270
let Ok ( template) = template else {
267
- debug ! (
271
+ info ! (
268
272
?BLOCK_TEMPLATE_WAIT_TIME ,
269
273
"waiting for a valid block template" ,
270
274
) ;
@@ -291,9 +295,12 @@ where
291
295
// Tell the next get_block_template() call to wait until the template has changed.
292
296
parameters. long_poll_id = Some ( template. long_poll_id ) ;
293
297
294
- let block =
295
- proposal_block_from_template ( & template, TimeSource :: CurTime , NetworkUpgrade :: Nu5 )
296
- . expect ( "unexpected invalid block template" ) ;
298
+ let block = proposal_block_from_template (
299
+ & template,
300
+ TimeSource :: CurTime ,
301
+ NetworkUpgrade :: current ( & network, Height ( template. height ) ) ,
302
+ )
303
+ . expect ( "unexpected invalid block template" ) ;
297
304
298
305
// If the template has actually changed, send an updated template.
299
306
template_sender. send_if_modified ( |old_block| {
0 commit comments