contrib/signet/miner: increase miner search space #30130

pull edilmedeiros wants to merge 1 commits into bitcoin:master from edilmedeiros:edilmedeiros-issue-30102 changing 1 files +28 −6
  1. edilmedeiros commented at 4:09 pm on May 17, 2024: contributor

    The miner script will call bitcoin-util grind to compute PoW which will try to exhaust the block’s nonce field and fail if it can’t find a valid hash. This behavior does not appear for low difficulty chains, but make the miner unusable for higher difficulty settings.

    We capture bitcoin-util grind failure, build a new block header by changing the block time and try to grind again.

    Fixes #30102.

    How this was tested

    This is a follow-up from #30091 and #30102.

    I’ve started a new signet chain with --nbits=1d008d28 (which accounts for 600 seconds difficulty per the calibrate command) and the first block’s date 30 days in the past and let the miner run as fast as it can. Starting from block 10080 (after 5 difficulty adjustment periods) the miner will occasionally fail with a Could not satisfy difficulty target message.

    There’s a functional test for the miner, but this fix requires a high difficulty chain to be observable (after block 10080 on my machine). A functional test would take many hours to run if there’s no mechanism of loading a pre-mined chain (with at least 10080 blocks), so I did not try to include one in this PR.

    Below is a mining session in which blocks 10097 to 10101 were mined in the first try of bitcoin-util grind and block 10102 required one retry (debug info at time 2024-05-17 12:56:01). The session was interrupted with SIGINT (Ctrl-C) after mining block 10102 (during mining of block 10103).

     0$BTC_PATH/../contrib/signet/miner --debug --cli "$BTC_PATH/bitcoin-cli -datadir=$DATADIR_PATH" generate --address $MINER_ADDR --grind-cmd "$BTC_PATH/bitcoin-util grind" --nbits $NBITS --ongoing
     12024-05-17 12:44:30 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
     22024-05-17 12:44:30 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000001403650dc3f806132c32ab17e8087e01a620ae685d1e3b469ed629ab9']
     32024-05-17 12:44:30 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
     42024-05-17 12:44:30 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000001403650dc3f806132c32ab17e8087e01a620ae685d1e3b469ed629ab9', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000001403650dc3f806132c32ab17e8087e01a620ae685d1e3b469ed629ab918', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714546817, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715960670, 'bits': '1d0377ac', 'height': 10097, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
     52024-05-17 12:44:30 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getaddressinfo', 'tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt']
     62024-05-17 12:44:30 DEBUG Mining block delta=2m30s start=1714547717 mine=True
     72024-05-17 12:44:30 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
     82024-05-17 12:44:30 DEBUG grinding headhex: 00000020b99a62ed69b4e3d185e60a621ae087807eb12ac33261803fdc503640010000003defccce7c49fc8e5d49e5fdfac5179424caa643d93dd2fce318737a73acbd3c05ec3166ac77031d00000000
     92024-05-17 12:44:59 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    102024-05-17 12:44:59 DEBUG Block hash 000000027f40f8a9ea5af6aecd5c3040365e5647c76c0a51bf3972f683d4921a payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    112024-05-17 12:44:59 INFO Mined block at height 10097; next in -392h27m12s (mine)
    122024-05-17 12:44:59 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    132024-05-17 12:44:59 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '000000027f40f8a9ea5af6aecd5c3040365e5647c76c0a51bf3972f683d4921a']
    142024-05-17 12:44:59 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    152024-05-17 12:44:59 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '000000027f40f8a9ea5af6aecd5c3040365e5647c76c0a51bf3972f683d4921a', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '000000027f40f8a9ea5af6aecd5c3040365e5647c76c0a51bf3972f683d4921a19', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714546967, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715960699, 'bits': '1d0377ac', 'height': 10098, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    162024-05-17 12:44:59 DEBUG Mining block delta=2m30s start=1714547867 mine=True
    172024-05-17 12:44:59 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    182024-05-17 12:44:59 DEBUG grinding headhex: 000000201a92d483f67239bf510a6cc747565e3640305ccdaef65aeaa9f8407f02000000fded29d2c7f696e68ab1412404ce7216faac9f9132d70d345fe055c2a4bd9fd39bec3166ac77031d00000000
    192024-05-17 12:45:04 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    202024-05-17 12:45:04 DEBUG Block hash 000000028b973069c60568f304b09095fe601ee1dd2b9c56ebd9846247f0cd90 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    212024-05-17 12:45:04 INFO Mined block at height 10098; next in -392h24m47s (mine)
    222024-05-17 12:45:04 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    232024-05-17 12:45:04 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '000000028b973069c60568f304b09095fe601ee1dd2b9c56ebd9846247f0cd90']
    242024-05-17 12:45:04 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    252024-05-17 12:45:04 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '000000028b973069c60568f304b09095fe601ee1dd2b9c56ebd9846247f0cd90', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '000000028b973069c60568f304b09095fe601ee1dd2b9c56ebd9846247f0cd9020', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547117, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715960704, 'bits': '1d0377ac', 'height': 10099, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    262024-05-17 12:45:04 DEBUG Mining block delta=2m30s start=1714548017 mine=True
    272024-05-17 12:45:04 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    282024-05-17 12:45:04 DEBUG grinding headhex: 0000002090cdf0476284d9eb569c2bdde11e60fe9590b004f36805c66930978b02000000e42cc72231e1dc1e9159b6e61f64ccd496b53e30b9f9a210016790a19c5b937331ed3166ac77031d00000000
    292024-05-17 12:48:29 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    302024-05-17 12:48:29 DEBUG Block hash 00000001b4e230b77edd93e706fb579aab0e8eefff0bc39f19bd671fb88d9e31 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    312024-05-17 12:48:29 INFO Mined block at height 10099; next in -392h25m42s (mine)
    322024-05-17 12:48:29 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    332024-05-17 12:48:29 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000001b4e230b77edd93e706fb579aab0e8eefff0bc39f19bd671fb88d9e31']
    342024-05-17 12:48:29 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    352024-05-17 12:48:29 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000001b4e230b77edd93e706fb579aab0e8eefff0bc39f19bd671fb88d9e31', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000001b4e230b77edd93e706fb579aab0e8eefff0bc39f19bd671fb88d9e3121', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547267, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715960909, 'bits': '1d0377ac', 'height': 10100, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    362024-05-17 12:48:29 DEBUG Mining block delta=2m30s start=1714548167 mine=True
    372024-05-17 12:48:29 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    382024-05-17 12:48:29 DEBUG grinding headhex: 00000020319e8db81f67bd199fc30bffef8e0eab9a57fb06e793dd7eb730e2b4010000000fcbbe2ca7f16269b8c7c348a2756b158312ad7745f496ef7de244e626e905fbc7ed3166ac77031d00000000
    392024-05-17 12:49:58 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    402024-05-17 12:49:58 DEBUG Block hash 00000002e3dd1d7dca6438c609a665362d45b2123cb5e86160492f91d2e711ea payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    412024-05-17 12:49:58 INFO Mined block at height 10100; next in -392h24m41s (mine)
    422024-05-17 12:49:58 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    432024-05-17 12:49:58 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000002e3dd1d7dca6438c609a665362d45b2123cb5e86160492f91d2e711ea']
    442024-05-17 12:49:58 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    452024-05-17 12:49:58 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000002e3dd1d7dca6438c609a665362d45b2123cb5e86160492f91d2e711ea', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000002e3dd1d7dca6438c609a665362d45b2123cb5e86160492f91d2e711ea22', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547417, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715960998, 'bits': '1d0377ac', 'height': 10101, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    462024-05-17 12:49:58 DEBUG Mining block delta=2m30s start=1714548317 mine=True
    472024-05-17 12:49:58 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    482024-05-17 12:49:58 DEBUG grinding headhex: 00000020ea11e7d2912f496061e8b53c12b2452d3665a609c63864ca7d1ddde3020000003f7bc2a2b69affa45d9b1999f07a13865daf3e3d60602cb9679f2dcd0414097d5dee3166ac77031d00000000
    492024-05-17 12:51:26 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    502024-05-17 12:51:26 DEBUG Block hash 00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f6 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    512024-05-17 12:51:26 INFO Mined block at height 10101; next in -392h23m39s (mine)
    522024-05-17 12:51:26 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    532024-05-17 12:51:26 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f6']
    542024-05-17 12:51:26 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    552024-05-17 12:51:26 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f6', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f623', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547568, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715961086, 'bits': '1d0377ac', 'height': 10102, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    562024-05-17 12:51:26 DEBUG Mining block delta=2m30s start=1714548467 mine=True
    572024-05-17 12:51:26 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    582024-05-17 12:51:26 DEBUG grinding headhex: 00000020f619ba9233e303f72c35bc807b95bb5aaf3999a7de35546fc7678918000000003e178dfed2d76249f0808057a88fcd97569670dbe0dfab79bd2da12840691dddf3ee3166ac77031d00000000
    59Could not satisfy difficulty target
    602024-05-17 12:56:01 DEBUG exception: Command '['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-util', 'grind', '00000020f619ba9233e303f72c35bc807b95bb5aaf3999a7de35546fc7678918000000003e178dfed2d76249f0808057a88fcd97569670dbe0dfab79bd2da12840691dddf3ee3166ac77031d00000000']' returned non-zero exit status 1.
    612024-05-17 12:56:01 DEBUG finish_block failed, retrying
    622024-05-17 12:56:01 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    632024-05-17 12:56:01 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    642024-05-17 12:56:01 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f6', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000000188967c76f5435dea79939af5abb957b80bc352cf703e33392ba19f623', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547568, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715961361, 'bits': '1d0377ac', 'height': 10102, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    652024-05-17 12:56:01 DEBUG Mining block delta=2m31s start=1714548468 mine=True
    662024-05-17 12:56:01 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    672024-05-17 12:56:01 DEBUG grinding headhex: 00000020f619ba9233e303f72c35bc807b95bb5aaf3999a7de35546fc76789180000000068c1d0b368ed7df6cc78fe0ad4f3312bdd396bf429e28d89b91ba82deea0645cf4ee3166ac77031d00000000
    682024-05-17 12:56:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    692024-05-17 12:56:39 DEBUG Block hash 00000000cadb825d6cd3009dc82144d64dd604dff072c524c31c5b8cad163eda payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    702024-05-17 12:56:39 INFO Mined block at height 10102; next in -392h26m21s (mine)
    712024-05-17 12:56:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    722024-05-17 12:56:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000000cadb825d6cd3009dc82144d64dd604dff072c524c31c5b8cad163eda']
    732024-05-17 12:56:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    742024-05-17 12:56:39 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000000cadb825d6cd3009dc82144d64dd604dff072c524c31c5b8cad163eda', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000000cadb825d6cd3009dc82144d64dd604dff072c524c31c5b8cad163eda24', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714547718, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1715961399, 'bits': '1d0377ac', 'height': 10103, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    752024-05-17 12:56:39 DEBUG Mining block delta=2m30s start=1714548618 mine=True
    762024-05-17 12:56:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    772024-05-17 12:56:39 DEBUG grinding headhex: 00000020da3e16ad8c5b1cc324c572f0df04d64dd64421c89d00d36c5d82dbca00000000a3780b24488f4cb399f58b76d28c8b5a90e68fef188f81fb91e83b2a894b2bca8aef3166ac77031d00000000
    78^C2024-05-17 12:56:47 DEBUG mining aborted by the user
    
     0$BTC_PATH/bitcoin-cli -datadir=$DATADIR_PATH -signet getblockchaininfo
     1{
     2  "chain": "signet",
     3  "blocks": 10102,
     4  "headers": 10102,
     5  "bestblockhash": "00000000cadb825d6cd3009dc82144d64dd604dff072c524c31c5b8cad163eda",
     6  "difficulty": 0.2883904525532027,
     7  "time": 1714548468,
     8  "mediantime": 1714547717,
     9  "verificationprogress": 1,
    10  "initialblockdownload": true,
    11  "chainwork": "000000000000000000000000000000000000000000000000000000c9f2cdeb92",
    12  "size_on_disk": 4162114,
    13  "pruned": false,
    14  "warnings": ""
    15}
    
  2. DrahtBot commented at 4:10 pm on May 17, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK AngusP

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29032 (signet: fixing mining for OP_TRUE challenge by Sjors)
    • #28417 (contrib/signet/miner updates by ajtowns)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. edilmedeiros renamed this:
    Increase contrib/signet/miner search space
    contrib/signet/miner: increase miner search space
    on May 17, 2024
  4. edilmedeiros force-pushed on May 17, 2024
  5. edilmedeiros commented at 4:11 pm on May 17, 2024: contributor
    Force pushed so that the commit message is the same as the PR title.
  6. edilmedeiros commented at 4:33 pm on May 17, 2024: contributor
    A small caveat: I couldn’t get rid of the Could not satisfy difficulty target message (see the debug log just before timestamp 2024-05-17 12:56:01). This is emitted by bitcoin-util itself before failing. I could not find a way to make the Python script intercept that to keep the terminal clean. I fear the complexity to achieve such an effect would not justify the benefit.
  7. laanwj added the label Scripts and tools on May 17, 2024
  8. in contrib/signet/miner:427 in 67fbf378ab outdated
    424+        # the subprocess will fail and thus the miner. In case of failure, increment the retries var,
    425+        # use it to create a new block header and try again.
    426+        try:
    427+            block = finish_block(block, signet_solution, args.grind_cmd)
    428+        except subprocess.CalledProcessError as e:
    429+            logging.debug('subprocess exception: {}'.format(e))
    


    AngusP commented at 7:48 pm on May 18, 2024:

    nit: given this is a debug log message and you’re “expecting” this exception, I’m not sure it makes sense to include the word exception? Implies something went wrong.

    0            logging.debug('grind subprocess: {}'.format(e))
    

    nit-ier: could use a shorter f string:

    0            logging.debug(f'grind subprocess: {e}')
    

    edilmedeiros commented at 5:21 pm on May 20, 2024:
    I’ll mark those as resolved since I simplified the strings in a reviewed commit. Turns out that the script is using this style all over: logging.debug("Mining block delta=%s start=%s mine=%s", seconds_to_hms(mine_time-bestheader["time"]), mine_time, is_mine)

    AngusP commented at 6:35 pm on May 20, 2024:
    Ah yes, I feel I should’ve remembered that 😆 it’s usually considered correct-est to use the % formatting in log messages because that formatted string is only actually created if the message will be logged based on log-level, vs f" or .format or " % ... which are always created. Others may consider that premature optimisation if string-formatting due to logging has negligible perf impact 😉
  9. in contrib/signet/miner:429 in 67fbf378ab outdated
    426+        try:
    427+            block = finish_block(block, signet_solution, args.grind_cmd)
    428+        except subprocess.CalledProcessError as e:
    429+            logging.debug('subprocess exception: {}'.format(e))
    430+            logging.debug('finish_block failed, retrying')
    431+            retries += 1
    


    AngusP commented at 8:04 pm on May 18, 2024:

    The subprocess.CalledProcessError could contain the stderr&out and the return code – given there are a couple of other cases where bitcoin-util grind can fail, it might be good to check we actually hit an exhaustion rather than the block header decode issue to prevent many retries when something else is wrong (even if in a rare/“should never happen” case)?

    0            if e.returncode == 1 and "Could not satisfy difficulty target" in e.stderr.decode("utf-8"):
    1                retries += 1
    2            else:
    3                raise
    

    (Maybe don’t need/want to check the return code)

    You’d also need to change stdout=subprocess.PIPE to capture_output=True for these to be set on the exception e:

     0diff --git a/contrib/signet/miner b/contrib/signet/miner
     1index 31035a5525..e50301639e 100755
     2--- a/contrib/signet/miner
     3+++ b/contrib/signet/miner
     4@@ -105,7 +105,7 @@ def finish_block(block, signet_solution, grind_cmd):
     5         headhex = CBlockHeader.serialize(block).hex()
     6         logging.debug('grinding headhex: {}'.format(headhex))
     7         cmd = grind_cmd.split(" ") + [headhex]
     8-        newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
     9+        newheadhex = subprocess.run(cmd, capture_output=True, input=b"", check=True).stdout.strip()
    10         newhead = from_hex(CBlockHeader(), newheadhex.decode('utf8'))
    11         block.nNonce = newhead.nNonce
    12         block.rehash()
    

    (untested with this script but I’ve checked a toy example so fairly sure this would work)


    edilmedeiros commented at 5:22 pm on May 20, 2024:
    Thanks, that did the job indeed.
  10. AngusP commented at 8:07 pm on May 18, 2024: contributor
    Approach ACK, one suggestion to explicitly check for the exhaustion case and a couple of nits
  11. edilmedeiros force-pushed on May 20, 2024
  12. edilmedeiros commented at 6:29 pm on May 20, 2024: contributor

    Thanks for the review, @AngusP. Your suggestion did the trick, indeed.

     02024-05-20 15:05:53 INFO Mined block at height 10142; next in -464h55m33s (mine)
     12024-05-20 15:05:53 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
     22024-05-20 15:05:53 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000002135f8a02a04fd924c9e02901bf1682c4992988e2873450a955088f60']
     32024-05-20 15:05:53 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
     42024-05-20 15:05:53 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000002135f8a02a04fd924c9e02901bf1682c4992988e2873450a955088f60', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000002135f8a02a04fd924c9e02901bf1682c4992988e2873450a955088f6064', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714553720, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1716228353, 'bits': '1d0377ac', 'height': 10143, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
     52024-05-20 15:05:53 DEBUG Mining block delta=2m30s start=1714554619 mine=True
     62024-05-20 15:05:53 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
     72024-05-20 15:05:53 DEBUG grinding headhex: 00000020608f0855a9503487e2882999c48216bf0129e0c924d94fa0028a5f130200000063a1ad7c6fb413991c25e793160cdd4a3c3ef5681252711fb984a822b07ed2c6fb063266ac77031d00000000
     82024-05-20 15:10:36 DEBUG grinder exhausted the nonce search space, retrying with new block header
     92024-05-20 15:10:36 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    102024-05-20 15:10:36 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    112024-05-20 15:10:36 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000002135f8a02a04fd924c9e02901bf1682c4992988e2873450a955088f60', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000002135f8a02a04fd924c9e02901bf1682c4992988e2873450a955088f6064', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714553720, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1716228636, 'bits': '1d0377ac', 'height': 10143, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    122024-05-20 15:10:36 DEBUG Mining block delta=2m31s start=1714554620 mine=True
    132024-05-20 15:10:36 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    142024-05-20 15:10:36 DEBUG grinding headhex: 00000020608f0855a9503487e2882999c48216bf0129e0c924d94fa0028a5f1302000000891fb5f93c91c9ffbe1cfcfd31f0c1cbce05ad41a9cd7c6f9da5cfa7efc36814fc063266ac77031d00000000
    152024-05-20 15:11:42 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    162024-05-20 15:11:42 DEBUG Block hash 00000000bd1904f056ab49c086438fdc779f8249219dd99ce92218dacc9045a3 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    172024-05-20 15:11:42 INFO Mined block at height 10143; next in -464h58m52s (mine)
    182024-05-20 15:11:42 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    192024-05-20 15:11:42 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000000bd1904f056ab49c086438fdc779f8249219dd99ce92218dacc9045a3']
    202024-05-20 15:11:42 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    212024-05-20 15:11:42 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000000bd1904f056ab49c086438fdc779f8249219dd99ce92218dacc9045a3', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000000bd1904f056ab49c086438fdc779f8249219dd99ce92218dacc9045a365', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714553870, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1716228702, 'bits': '1d0377ac', 'height': 10144, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    222024-05-20 15:11:42 DEBUG Mining block delta=2m30s start=1714554770 mine=True
    232024-05-20 15:11:42 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    242024-05-20 15:11:42 DEBUG grinding headhex: 00000020a34590ccda1822e99cd99d2149829f77dc8f4386c049ab56f00419bd00000000868b1b8cf4e05c4691a2b8e09b7e8eacac344de1a5aa8b00cbd9ca4ebbb5fd1492073266ac77031d00000000
    252024-05-20 15:15:10 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'submitblock']
    262024-05-20 15:15:10 DEBUG Block hash 000000010a8e7590525e9b727d118dfd07add9e7a6b1cc7e176449319a8b5c35 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
    272024-05-20 15:15:10 INFO Mined block at height 10144; next in -464h59m50s (mine)
    
    02024-05-20 15:19:39 INFO Mined block at height 10156; next in -464h34m19s (mine)
    12024-05-20 15:19:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
    22024-05-20 15:19:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d97']
    32024-05-20 15:19:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
    42024-05-20 15:19:39 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d97', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d9778', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714555821, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1716229179, 'bits': '1d0377ac', 'height': 10157, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
    52024-05-20 15:19:39 DEBUG Mining block delta=2m30s start=1714556720 mine=True
    62024-05-20 15:19:39 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
    72024-05-20 15:19:39 DEBUG grinding headhex: 00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000
    8^C2024-05-20 15:19:50 DEBUG mining aborted by the user
    
     0$BTC_PATH/../contrib/signet/miner --debug --cli "$BTC_PATH/bitcoin-cli -datadir=$DATADIR_PATH" generate --address $MINER_ADDR --grind-cmd "$BTC_PATH/bitcoin-util grind" --nbits $NBITS --ongoing
     12024-05-20 15:20:06 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockchaininfo']
     22024-05-20 15:20:06 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblockheader', '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d97']
     32024-05-20 15:20:06 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getblocktemplate', '{"rules":["signet","segwit"]}']
     42024-05-20 15:20:06 DEBUG GBT template: {'capabilities': ['proposal'], 'version': 536870912, 'rules': ['csv', '!segwit', '!signet', 'taproot'], 'vbavailable': {}, 'vbrequired': 0, 'previousblockhash': '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d97', 'transactions': [], 'coinbaseaux': {}, 'coinbasevalue': 5000000000, 'longpollid': '00000001981d44c6e3e2a2db2ac279057ffca654fc9e14082368e37d7c867d9778', 'target': '0000000377ac0000000000000000000000000000000000000000000000000000', 'mintime': 1714555821, 'mutable': ['time', 'transactions', 'prevblock'], 'noncerange': '00000000ffffffff', 'sigoplimit': 80000, 'sizelimit': 4000000, 'weightlimit': 4000000, 'curtime': 1716229206, 'bits': '1d0377ac', 'height': 10157, 'signet_challenge': '0014f64c3c86285a5a14521fc05fd7e599a13f953350', 'default_witness_commitment': '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9'}
     52024-05-20 15:20:06 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', 'getaddressinfo', 'tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt']
     62024-05-20 15:20:06 DEBUG Mining block delta=2m30s start=1714556720 mine=True
     72024-05-20 15:20:06 DEBUG Calling bitcoin-cli: ['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-cli', '-datadir=/Users/jose.edil/2-development/bitcoin/signet-mining-experiments/signet-fix-hashing', '-signet', '-stdin', 'walletprocesspsbt']
     82024-05-20 15:20:06 DEBUG grinding headhex: 00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000
     9Traceback (most recent call last):
    10  File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 567, in <module>
    11    main()
    12  File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 561, in main
    13    return args.fn(args)
    14           ^^^^^^^^^^^^^
    15  File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 433, in do_generate
    16    raise e
    17  File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 425, in do_generate
    18    block = finish_block(block, signet_solution, args.grind_cmd)
    19            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    20  File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 108, in finish_block
    21    newheadhex = subprocess.run(cmd, capture_output=True, input=b"", check=True).stdout.strip()
    22                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    23  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    24    raise CalledProcessError(retcode, process.args,
    25subprocess.CalledProcessError: Command '['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-util', 'grind', '00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000']' died with <Signals.SIGTERM: 15>.
    
  13. in contrib/signet/miner:106 in 2a5bd91c76 outdated
    102@@ -103,8 +103,9 @@ def finish_block(block, signet_solution, grind_cmd):
    103         block.solve()
    104     else:
    105         headhex = CBlockHeader.serialize(block).hex()
    106+        logging.debug('grinding headhex: {}'.format(headhex))
    


    AngusP commented at 8:55 pm on May 21, 2024:

    Sorry style nit here and later on, should use " not ' for strings (judging by the rest of the file) and % formatting for logging

    0        logging.debug("grinding headhex: %s", headhex)
    
  14. in contrib/signet/miner:429 in 2a5bd91c76 outdated
    426+        try:
    427+            block = finish_block(block, signet_solution, args.grind_cmd)
    428+        except subprocess.CalledProcessError as e:
    429+            # Look for the return code and output message raised by bitcoin-util
    430+            if e.returncode == 1 and "Could not satisfy difficulty target" in e.stderr.decode("utf-8"):
    431+                logging.debug('grinder exhausted the nonce search space, retrying with new block header')
    


    AngusP commented at 8:55 pm on May 21, 2024:
    0                logging.debug("grinder exhausted the nonce search space, retrying with new block header")
    
  15. in contrib/signet/miner:436 in 2a5bd91c76 outdated
    433+                continue
    434+            else: # bitcoin-util raised another error, pass it along and let the user know
    435+                raise e
    436+        # capture keyboard interrupt so one can stop the miner with SIGINT (Ctrl-C)
    437+        except KeyboardInterrupt:
    438+            logging.debug('mining aborted by the user')
    


    AngusP commented at 8:56 pm on May 21, 2024:
    0            logging.debug("mining aborted by the user")
    
  16. AngusP commented at 8:56 pm on May 21, 2024: contributor
    LGTM apart from style nit
  17. contrib/signet/miner: increase miner search space
    The miner script will call `bitcoin-util grind` to compute PoW which will try to
    exhaust the block's nonce field and fail if it can't find a valid hash. This
    behavior does not appear for low difficulty chains, but make the miner unusable
    for higher difficulty settings.
    
    We capture `bitcoin-util grind` exception, build a new block header with
    different time and try to grind again.
    
    Fixes #30102
    1cf174a295
  18. edilmedeiros force-pushed on May 22, 2024
  19. edilmedeiros commented at 2:12 am on May 22, 2024: contributor
    Fair enough, committed the style suggestions.
  20. AngusP approved
  21. AngusP commented at 1:37 pm on May 22, 2024: contributor
    utACK 1cf174a2954b434e9623afe86f3643be8eec2d70
  22. in contrib/signet/miner:355 in 1cf174a295
    351@@ -350,7 +352,7 @@ def do_generate(args):
    352             is_mine = True
    353         else:
    354             time_delta = next_block_delta(int(bestheader["bits"], 16), bci["bestblockhash"], ultimate_target, args.poisson, args.max_interval)
    355-            mine_time = bestheader["time"] + time_delta
    356+            mine_time = bestheader["time"] + time_delta + retries
    


    ajtowns commented at 0:59 am on May 24, 2024:

    I think you also would want to change:

    0        if tmpl["mintime"] > mine_time:
    1            logging.info("Updating block time from %d to %d", mine_time, tmpl["mintime"])
    2            mine_time = tmpl["mintime"]
    

    to be

    0    mintime = tmpl["mintime"] + retries
    1    if mine_time < mintime:
    2         logging.info(...)
    3         mine_time = mintime
    
  23. edilmedeiros marked this as a draft on Sep 4, 2024
  24. edilmedeiros commented at 6:41 pm on September 4, 2024: contributor
    Returned to draft so I can refactor this PR on top of #28417 recently merged.
  25. DrahtBot added the label Needs rebase on Sep 4, 2024
  26. DrahtBot commented at 7:23 pm on September 4, 2024: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.

  27. DrahtBot commented at 1:53 am on December 2, 2024: contributor

    ⌛ There hasn’t been much activity lately and the patch still needs rebase. What is the status here?

    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it ‘Up for grabs’ with the label, so that it can be picked up in the future.

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: 2024-12-21 15:12 UTC

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