@@ -225,7 +225,7 @@ def seconds_to_hms(s):
225225 out = "-" + out
226226 return out
227227
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 ):
229229 # strategy:
230230 # 1) work out how far off our desired target we are
231231 # 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):
248248 this_interval_variance = 1
249249
250250 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 ))
252252
253253 return this_interval
254254
@@ -308,6 +308,10 @@ def do_generate(args):
308308 return 1
309309 my_blocks = (start - 1 , stop , total )
310310
311+ if args .max_interval < 960 :
312+ logging .error ("--max-interval must be at least 960 (16 minutes)" )
313+ return 1
314+
311315 ultimate_target = nbits_to_target (int (args .nbits ,16 ))
312316
313317 mined_blocks = 0
@@ -324,7 +328,7 @@ def do_generate(args):
324328 if lastheader is None :
325329 lastheader = bestheader ["hash" ]
326330 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 )
328332 next_delta += bestheader ["time" ] - time .time ()
329333 next_is_mine = next_block_is_mine (bestheader ["hash" ], my_blocks )
330334 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):
338342 action_time = now
339343 is_mine = True
340344 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 )
342346 time_delta *= 100 # 100 blocks
343347 logging .info ("Backdating time for first block to %d minutes ago" % (time_delta / 60 ))
344348 mine_time = now - time_delta
345349 action_time = now
346350 is_mine = True
347351 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 )
349353 mine_time = bestheader ["time" ] + time_delta
350354
351355 is_mine = next_block_is_mine (bci ["bestblockhash" ], my_blocks )
@@ -419,7 +423,7 @@ def do_generate(args):
419423 # report
420424 bstr = "block" if is_mine else "backup block"
421425
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 )
423427 next_delta += block .nTime - time .time ()
424428 next_is_mine = next_block_is_mine (block .hash , my_blocks )
425429
@@ -497,6 +501,7 @@ def main():
497501 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)" )
498502 generate .add_argument ("--backup-delay" , default = 300 , type = int , help = "Seconds to delay before mining blocks reserved for other miners (default=300)" )
499503 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)" )
500505
501506 calibrate = cmds .add_parser ("calibrate" , help = "Calibrate difficulty" )
502507 calibrate .set_defaults (fn = do_calibrate )
0 commit comments