Skip to content

Commit

Permalink
contrib: make block interval configurable in signet miner
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad committed Sep 29, 2024
1 parent c25d1db commit 800f20b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions contrib/signet/miner
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ def seconds_to_hms(s):
return out

class Generate:
INTERVAL = 600.0*2016/2015 # 10 minutes, adjusted for the off-by-one bug


def __init__(self, multiminer=None, ultimate_target=None, poisson=False, max_interval=1800,
standby_delay=0, backup_delay=0, set_block_time=None,
standby_delay=0, backup_delay=0, set_block_time=None,
# 10 minutes, adjusted for the off-by-one bug
block_interval=600.0*2016/2015,
poolid=None):
if multiminer is None:
multiminer = (0, 1, 1)
Expand All @@ -239,6 +240,7 @@ class Generate:
self.backup_delay = backup_delay
self.set_block_time = set_block_time
self.poolid = poolid
self.block_interval = block_interval

def next_block_delta(self, last_nbits, last_hash):
# strategy:
Expand All @@ -252,7 +254,7 @@ class Generate:
retarget_factor = self.ultimate_target / current_target
retarget_factor = max(0.25, min(retarget_factor, 4.0))

avg_interval = self.INTERVAL * retarget_factor
avg_interval = self.block_interval * retarget_factor

if self.poisson:
det_rand = int(last_hash[-8:], 16) * 2**-32
Expand All @@ -276,7 +278,7 @@ class Generate:
self.action_time = now
self.is_mine = True
elif bestheader["height"] == 0:
time_delta = self.INTERVAL * 100 # plenty of time to mine 100 blocks
time_delta = self.block_interval * 100 # plenty of time to mine 100 blocks
logging.info("Backdating time for first block to %d minutes ago" % (time_delta/60))
self.mine_time = now - time_delta
self.action_time = now
Expand Down Expand Up @@ -345,6 +347,9 @@ def do_generate(args):
else:
max_blocks = 1

if args.block_interval is not None:
logging.info("Using block interval %s", seconds_to_hms(args.block_interval))

if args.set_block_time is not None and args.set_block_time < 0:
args.set_block_time = time.time()
logging.info("Treating negative block time as current time (%d)" % (args.set_block_time))
Expand Down Expand Up @@ -386,7 +391,8 @@ def do_generate(args):
ultimate_target = nbits_to_target(int(args.nbits,16))

gen = Generate(multiminer=my_blocks, ultimate_target=ultimate_target, poisson=args.poisson, max_interval=args.max_interval,
standby_delay=args.standby_delay, backup_delay=args.backup_delay, set_block_time=args.set_block_time, poolid=poolid)
standby_delay=args.standby_delay, backup_delay=args.backup_delay, set_block_time=args.set_block_time, poolid=poolid,
block_interval=args.block_interval)

mined_blocks = 0
bestheader = {"hash": None}
Expand Down Expand Up @@ -529,6 +535,7 @@ def main():
generate.add_argument("--backup-delay", default=300, type=int, help="Seconds to delay before mining blocks reserved for other miners (default=300)")
generate.add_argument("--standby-delay", default=0, type=int, help="Seconds to delay before mining blocks (default=0)")
generate.add_argument("--max-interval", default=1800, type=int, help="Maximum interblock interval (seconds)")
generate.add_argument("--block-interval", default=60*10, type=int, help="Consensus blocktime interval (seconds)")

calibrate = cmds.add_parser("calibrate", help="Calibrate difficulty")
calibrate.set_defaults(fn=do_calibrate)
Expand Down

0 comments on commit 800f20b

Please sign in to comment.