@@ -225,7 +225,7 @@ def seconds_to_hms(s):
225
225
out = "-" + out
226
226
return out
227
227
228
- def next_block_delta (last_nbits , last_hash , ultimate_target , do_poisson ):
228
+ def next_block_delta (last_nbits , last_hash , ultimate_target , do_poisson , max_interval ):
229
229
# strategy:
230
230
# 1) work out how far off our desired target we are
231
231
# 2) cap it to a factor of 4 since that's the best we can do in a single retarget period
@@ -248,7 +248,7 @@ def next_block_delta(last_nbits, last_hash, ultimate_target, do_poisson):
248
248
this_interval_variance = 1
249
249
250
250
this_interval = avg_interval * this_interval_variance
251
- this_interval = max (1 , min (this_interval , 3600 ))
251
+ this_interval = max (1 , min (this_interval , max_interval ))
252
252
253
253
return this_interval
254
254
@@ -308,6 +308,10 @@ def do_generate(args):
308
308
return 1
309
309
my_blocks = (start - 1 , stop , total )
310
310
311
+ if args .max_interval < 960 :
312
+ logging .error ("--max-interval must be at least 960 (16 minutes)" )
313
+ return 1
314
+
311
315
ultimate_target = nbits_to_target (int (args .nbits ,16 ))
312
316
313
317
mined_blocks = 0
@@ -324,7 +328,7 @@ def do_generate(args):
324
328
if lastheader is None :
325
329
lastheader = bestheader ["hash" ]
326
330
elif bestheader ["hash" ] != lastheader :
327
- next_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bestheader ["hash" ], ultimate_target , args .poisson )
331
+ next_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bestheader ["hash" ], ultimate_target , args .poisson , args . max_interval )
328
332
next_delta += bestheader ["time" ] - time .time ()
329
333
next_is_mine = next_block_is_mine (bestheader ["hash" ], my_blocks )
330
334
logging .info ("Received new block at height %d; next in %s (%s)" , bestheader ["height" ], seconds_to_hms (next_delta ), ("mine" if next_is_mine else "backup" ))
@@ -338,14 +342,14 @@ def do_generate(args):
338
342
action_time = now
339
343
is_mine = True
340
344
elif bestheader ["height" ] == 0 :
341
- time_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bci ["bestblockhash" ], ultimate_target , args .poisson )
345
+ time_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bci ["bestblockhash" ], ultimate_target , args .poisson , args . max_interval )
342
346
time_delta *= 100 # 100 blocks
343
347
logging .info ("Backdating time for first block to %d minutes ago" % (time_delta / 60 ))
344
348
mine_time = now - time_delta
345
349
action_time = now
346
350
is_mine = True
347
351
else :
348
- time_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bci ["bestblockhash" ], ultimate_target , args .poisson )
352
+ time_delta = next_block_delta (int (bestheader ["bits" ], 16 ), bci ["bestblockhash" ], ultimate_target , args .poisson , args . max_interval )
349
353
mine_time = bestheader ["time" ] + time_delta
350
354
351
355
is_mine = next_block_is_mine (bci ["bestblockhash" ], my_blocks )
@@ -419,7 +423,7 @@ def do_generate(args):
419
423
# report
420
424
bstr = "block" if is_mine else "backup block"
421
425
422
- next_delta = next_block_delta (block .nBits , block .hash , ultimate_target , args .poisson )
426
+ next_delta = next_block_delta (block .nBits , block .hash , ultimate_target , args .poisson , args . max_interval )
423
427
next_delta += block .nTime - time .time ()
424
428
next_is_mine = next_block_is_mine (block .hash , my_blocks )
425
429
@@ -497,6 +501,7 @@ def main():
497
501
generate .add_argument ("--multiminer" , default = None , type = str , help = "Specify which set of blocks to mine (eg: 1-40/100 for the first 40%%, 2/3 for the second 3rd)" )
498
502
generate .add_argument ("--backup-delay" , default = 300 , type = int , help = "Seconds to delay before mining blocks reserved for other miners (default=300)" )
499
503
generate .add_argument ("--standby-delay" , default = 0 , type = int , help = "Seconds to delay before mining blocks (default=0)" )
504
+ generate .add_argument ("--max-interval" , default = 1800 , type = int , help = "Maximum interblock interval (seconds)" )
500
505
501
506
calibrate = cmds .add_parser ("calibrate" , help = "Calibrate difficulty" )
502
507
calibrate .set_defaults (fn = do_calibrate )
0 commit comments