signet/miner: reduce default interblock interval limit to 30min #26208

pull ajtowns wants to merge 1 commits into bitcoin:master from ajtowns:202209-signetminercap changing 1 files +11 −6
  1. ajtowns commented at 7:23 PM on September 29, 2022: contributor

    Reduces the cap on the time between blocks from 60 minutes to 30 minutes, and makes it configurable.

  2. signet/miner: reduce default interblock interval limit to 30min
    Also allow the operator to change it, if desired, without having
    to edit the code.
    51a08f41ff
  3. ajtowns commented at 7:45 PM on September 29, 2022: contributor

    signet/miner --poisson attempts to simulate the distribution of times you'd see on mainnet. My original reasoning for the 60 minute cap is that you only expect 0.25% of blocks to take that long, so what does it matter. With a lower cap it seems worthwhile checking what that effects. I think you can work out the expected average with a cap as follows:

    def expected_times(tgt, N=100000):
        return [tgt*-math.log(1-i*1.0/N) for i in range(N)]
    
    def capped_average(seq, cap):
        sum, cnt = 0,0
        for v in seq:
            sum += min(v, cap)
            cnt += 1
        return sum/cnt
    
    def bisect(f, want, l=0, h=100000, prec=0.0005):
        while l + prec < h:
            m = (l + h)/2
            if f(m) < want:
                l = m
            else:
                h = m
        return h
    
    for cap in [11, 15, 16, 20, 25, 30, 45, 60]:
        tgt = bisect(lambda t: capped_average(expected_times(t), cap*60), 600)
        print("cap=%dmin, tgt=%.2fmin, average=%ds" % (cap, tgt/60, capped_average(expected_times(tgt), cap*60)))
    
    # results:
    # cap=11min, tgt=56.78min, average=600.0s
    # cap=15min, tgt=17.16min, average=600.0s
    # cap=16min, tgt=15.58min, average=600.0s
    # cap=20min, tgt=12.55min, average=600.0s
    # cap=25min, tgt=11.20min, average=600.0s
    # cap=30min, tgt=10.63min, average=600.0s
    # cap=45min, tgt=10.12min, average=600.0s
    # cap=60min, tgt=10.03min, average=600.0s
    

    That is, if you have a cap of 30 minutes, you need to be trying to have blocks every 10.63 minutes instead of every ten minutes because after applying the cap, you actual average will be reduced by that much. Effectively, this means the actual difficulty will generally be somewhat above the --nbits target, causing the signet miner to attempt to reduce the difficulty by mining more slowly, but that reduction will be offset in practice by the cap.

    It seems to me like 30 minutes is a nice round figure that doesn't cause anything to get too weird; and I've used 16minutes as a lower limit, since below that, you're targetting an average block interval that's higher than your maximum acceptable block interval, so it's probably better to just not use --poisson at all at that point, I think.

  4. fanquake requested review from kallewoof on Sep 29, 2022
  5. in contrib/signet/miner:228 in 51a08f41ff
     224 | @@ -225,7 +225,7 @@ def seconds_to_hms(s):
     225 |          out = "-" + out
     226 |      return out
     227 |  
     228 | -def next_block_delta(last_nbits, last_hash, ultimate_target, do_poisson):
     229 | +def next_block_delta(last_nbits, last_hash, ultimate_target, do_poisson, max_interval):
    


    a5an0 commented at 12:49 PM on October 1, 2022:

    have you thought about defaulting max_interval to 3600 so this change doesn't break any existing callers of next_block_delta? I see below that the arg parser has a default value, so maybe it's a moot point.


    ajtowns commented at 1:58 AM on October 2, 2022:

    You want each call site to use the same max_interval, so I thought it was less bug prone for missing the value to have an explicit "missing argument" error, rather than an implicit "cap is set to a different time".

    All existing callers in the script should already be updated by this patch; it's not really intended for this to provide a stable api that external callers could rely on.

  6. kallewoof approved
  7. kallewoof commented at 2:19 AM on October 3, 2022: member

    Looks good to me.

  8. fanquake merged this on Oct 3, 2022
  9. fanquake closed this on Oct 3, 2022

  10. sidhujag referenced this in commit 91723b9139 on Oct 4, 2022
  11. bitcoin locked this on Oct 3, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-26 09:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me