From 1a45cd2e51214f81442a5f9bf16612100adaf5b8 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 13 Jan 2021 11:55:52 +1000 Subject: contrib/signet: Fix typos Thanks to muxator, JeremyRubin, and gruve-p for spotting. --- contrib/signet/README.md | 4 ++-- contrib/signet/miner | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/signet/README.md b/contrib/signet/README.md index 71dc2f9638..f6e3924b18 100644 --- a/contrib/signet/README.md +++ b/contrib/signet/README.md @@ -25,7 +25,7 @@ To mine the first block in your custom chain, you can run: cd src/ CLI="./bitcoin-cli -conf=mysignet.conf" - MINER="..contrib/signet/miner" + MINER="../contrib/signet/miner" GRIND="./bitcoin-util grind" ADDR=$($CLI -signet getnewaddress) $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --set-block-time=-1 @@ -52,7 +52,7 @@ Instead of specifying --ongoing, you can specify --max-blocks=N to mine N blocks Instead of using a single address, a ranged descriptor may be provided instead (via the --descriptor parameter), with the reward for the block at height H being sent to the H'th address generated from the descriptor. -Instead of calculating a specific nbits value, --min-nbits can be specified instead, in which case the mininmum signet difficulty will be targeted. +Instead of calculating a specific nbits value, --min-nbits can be specified instead, in which case the minimum signet difficulty will be targeted. By default, the signet miner mines blocks at fixed intervals with minimal variation. If you want blocks to appear more randomly, as they do in mainnet, specify the --poisson option. diff --git a/contrib/signet/miner b/contrib/signet/miner index a3fba49d0e..ecfbd9d766 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -520,7 +520,7 @@ def do_calibrate(args): sys.stderr.write("Can only specify one of --nbits or --seconds\n") return 1 if args.nbits is not None and len(args.nbits) != 8: - sys.stderr.write("Must specify 8 hex digits for --nbits") + sys.stderr.write("Must specify 8 hex digits for --nbits\n") return 1 TRIALS = 600 # gets variance down pretty low -- cgit v1.2.3 From a383ce5b4add6cdf4e9974527b609a1147a0d972 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 13 Jan 2021 11:56:06 +1000 Subject: contrib/signet/miner: --grind-cmd is required for calibrate Thanks to muxator for spotting. --- contrib/signet/miner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/signet/miner b/contrib/signet/miner index ecfbd9d766..0c1a4ac12d 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -605,7 +605,7 @@ def main(): sp.add_argument("--descriptor", default=None, type=str, help="Descriptor for block reward payment") for sp in [solvepsbt, generate, calibrate]: - sp.add_argument("--grind-cmd", default=None, type=str, help="Command to grind a block header for proof-of-work") + sp.add_argument("--grind-cmd", default=None, type=str, required=(sp==calibrate), help="Command to grind a block header for proof-of-work") args = parser.parse_args(sys.argv[1:]) -- cgit v1.2.3 From e66543827cd4ae9b76ff4c5c6e414c1942c7d727 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 13 Jan 2021 11:56:19 +1000 Subject: contrib/signet/miner: Automatic timestamp for first block When mining the first block of a new signet chain, pick a timestamp for the first block so that after mining 100 blocks the timestamp will be back to the current time -- this prevents an unnecessary delay before any miner rewards have matured enough to be spent. This takes into account that the delta between blocks may be shorter than 10 minutes due to attempting to increase the difficulty to match --nbits, but does not take into account the time spent actually generating the 100 blocks. --- contrib/signet/miner | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/signet/miner b/contrib/signet/miner index 0c1a4ac12d..09eb07502f 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -428,10 +428,13 @@ def do_generate(args): action_time = now is_mine = True elif bestheader["height"] == 0: - logging.error("When mining first block in a new signet, must specify --set-block-time") - return 1 + time_delta = next_block_delta(int(bestheader["bits"], 16), bci["bestblockhash"], ultimate_target, args.poisson) + time_delta *= 100 # 100 blocks + logging.info("Backdating time for first block to %d minutes ago" % (time_delta/60)) + mine_time = now - time_delta + action_time = now + is_mine = True else: - time_delta = next_block_delta(int(bestheader["bits"], 16), bci["bestblockhash"], ultimate_target, args.poisson) mine_time = bestheader["time"] + time_delta -- cgit v1.2.3 From b6d493fd4d602a67d16d2566466e18091e272fa0 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 13 Jan 2021 13:11:42 +1000 Subject: contrib/signet/README.md: Update miner description --- contrib/signet/README.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'contrib') diff --git a/contrib/signet/README.md b/contrib/signet/README.md index f6e3924b18..706b296c54 100644 --- a/contrib/signet/README.md +++ b/contrib/signet/README.md @@ -21,27 +21,28 @@ accept one claim per day. See `--password` above. miner ===== -To mine the first block in your custom chain, you can run: +You will first need to pick a difficulty target. Since signet chains are primarily protected by a signature rather than proof of work, there is no need to spend as much energy as possible mining, however you may wish to choose to spend more time than the absolute minimum. The calibrate subcommand can be used to pick a target appropriate for your hardware, eg: cd src/ - CLI="./bitcoin-cli -conf=mysignet.conf" MINER="../contrib/signet/miner" GRIND="./bitcoin-util grind" - ADDR=$($CLI -signet getnewaddress) - $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --set-block-time=-1 - -This will mine a block with the current timestamp. If you want to backdate the chain, you can give a different timestamp to --set-block-time. - -You will then need to pick a difficulty target. Since signet chains are primarily protected by a signature rather than proof of work, there is no need to spend as much energy as possible mining, however you may wish to choose to spend more time than the absolute minimum. The calibrate subcommand can be used to pick a target, eg: - $MINER calibrate --grind-cmd="$GRIND" nbits=1e00f403 for 25s average mining time It defaults to estimating an nbits value resulting in 25s average time to find a block, but the --seconds parameter can be used to pick a different target, or the --nbits parameter can be used to estimate how long it will take for a given difficulty. -Using the --ongoing parameter will then cause the signet miner to create blocks indefinitely. It will pick the time between blocks so that difficulty is adjusted to match the provided --nbits value. +To mine the first block in your custom chain, you can run: - $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=1e00f403 --ongoing + CLI="./bitcoin-cli -conf=mysignet.conf" + ADDR=$($CLI -signet getnewaddress) + NBITS=1e00f403 + $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS + +This will mine a single block with a backdated timestamp designed to allow 100 blocks to be mined as quickly as possible, so that it is possible to do transactions. + +Adding the --ongoing parameter will then cause the signet miner to create blocks indefinitely. It will pick the time between blocks so that difficulty is adjusted to match the provided --nbits value. + + $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS --ongoing Other options ------------- @@ -50,9 +51,11 @@ The --debug and --quiet options are available to control how noisy the signet mi Instead of specifying --ongoing, you can specify --max-blocks=N to mine N blocks and stop. -Instead of using a single address, a ranged descriptor may be provided instead (via the --descriptor parameter), with the reward for the block at height H being sent to the H'th address generated from the descriptor. +The --set-block-time option is available to manually move timestamps forward or backward (subject to the rules that blocktime must be greater than mediantime, and dates can't be more than two hours in the future). It can only be used when mining a single block (ie, not when using --ongoing or --max-blocks greater than 1). + +Instead of using a single address, a ranged descriptor may be provided via the --descriptor parameter, with the reward for the block at height H being sent to the H'th address generated from the descriptor. -Instead of calculating a specific nbits value, --min-nbits can be specified instead, in which case the minimum signet difficulty will be targeted. +Instead of calculating a specific nbits value, --min-nbits can be specified instead, in which case the minimum signet difficulty will be targeted. Signet's minimum difficulty corresponds to --nbits=1e0377ae. By default, the signet miner mines blocks at fixed intervals with minimal variation. If you want blocks to appear more randomly, as they do in mainnet, specify the --poisson option. @@ -76,5 +79,5 @@ These steps can instead be done explicitly: $MINER --cli="$CLI" solvepsbt --grind-cmd="$GRIND" | $CLI -signet -stdin submitblock -This is intended to allow you to replace part of the pipeline for further experimentation, if desired. +This is intended to allow you to replace part of the pipeline for further experimentation (eg, to sign the block with a hardware wallet). -- cgit v1.2.3 From b3c712cb2871e0034898b37454fb6a4e1fc78f84 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 7 Feb 2021 06:52:42 +1000 Subject: contrib/signet/miner: remove debug code --- contrib/signet/miner | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'contrib') diff --git a/contrib/signet/miner b/contrib/signet/miner index 09eb07502f..f1360818ae 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -528,7 +528,6 @@ def do_calibrate(args): TRIALS = 600 # gets variance down pretty low TRIAL_BITS = 0x1e3ea75f # takes about 5m to do 600 trials - #TRIAL_BITS = 0x1e7ea75f # XXX header = CBlockHeader() header.nBits = TRIAL_BITS @@ -536,23 +535,14 @@ def do_calibrate(args): start = time.time() count = 0 - #CHECKS=[] for i in range(TRIALS): header.nTime = i header.nNonce = 0 headhex = header.serialize().hex() cmd = args.grind_cmd.split(" ") + [headhex] newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip() - #newhead = FromHex(CBlockHeader(), newheadhex.decode('utf8')) - #count += newhead.nNonce - #if (i+1) % 100 == 0: - # CHECKS.append((i+1, count, time.time()-start)) - - #print("checks =", [c*1.0 / (b*targ*2**-256) for _,b,c in CHECKS]) avg = (time.time() - start) * 1.0 / TRIALS - #exp_count = 2**256 / targ * TRIALS - #print("avg =", avg, "count =", count, "exp_count =", exp_count) if args.nbits is not None: want_targ = nbits_to_target(int(args.nbits,16)) @@ -593,7 +583,6 @@ def main(): generate.add_argument("--nbits", default=None, type=str, help="Target nBits (specify difficulty)") generate.add_argument("--min-nbits", action="store_true", help="Target minimum nBits (use min difficulty)") generate.add_argument("--poisson", action="store_true", help="Simulate randomised block times") - #generate.add_argument("--signcmd", default=None, type=str, help="Alternative signing command") 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)") 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)") -- cgit v1.2.3