-
Notifications
You must be signed in to change notification settings - Fork 36.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contrib/signet/miner: increase miner search space #30130
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
5f9d4e1
to
67fbf37
Compare
Force pushed so that the commit message is the same as the PR title. |
A small caveat: I couldn't get rid of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK, one suggestion to explicitly check for the exhaustion case and a couple of nits
67fbf37
to
2a5bd91
Compare
Thanks for the review, @AngusP. Your suggestion did the trick, indeed. Log from mining two blocks. The first exhausted the grinder search space. The second didn't.2024-05-20 15:05:53 INFO Mined block at height 10142; next in -464h55m33s (mine)
2024-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']
2024-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']
2024-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"]}']
2024-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'}
2024-05-20 15:05:53 DEBUG Mining block delta=2m30s start=1714554619 mine=True
2024-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']
2024-05-20 15:05:53 DEBUG grinding headhex: 00000020608f0855a9503487e2882999c48216bf0129e0c924d94fa0028a5f130200000063a1ad7c6fb413991c25e793160cdd4a3c3ef5681252711fb984a822b07ed2c6fb063266ac77031d00000000
2024-05-20 15:10:36 DEBUG grinder exhausted the nonce search space, retrying with new block header
2024-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']
2024-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"]}']
2024-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'}
2024-05-20 15:10:36 DEBUG Mining block delta=2m31s start=1714554620 mine=True
2024-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']
2024-05-20 15:10:36 DEBUG grinding headhex: 00000020608f0855a9503487e2882999c48216bf0129e0c924d94fa0028a5f1302000000891fb5f93c91c9ffbe1cfcfd31f0c1cbce05ad41a9cd7c6f9da5cfa7efc36814fc063266ac77031d00000000
2024-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']
2024-05-20 15:11:42 DEBUG Block hash 00000000bd1904f056ab49c086438fdc779f8249219dd99ce92218dacc9045a3 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
2024-05-20 15:11:42 INFO Mined block at height 10143; next in -464h58m52s (mine)
2024-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']
2024-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']
2024-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"]}']
2024-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'}
2024-05-20 15:11:42 DEBUG Mining block delta=2m30s start=1714554770 mine=True
2024-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']
2024-05-20 15:11:42 DEBUG grinding headhex: 00000020a34590ccda1822e99cd99d2149829f77dc8f4386c049ab56f00419bd00000000868b1b8cf4e05c4691a2b8e09b7e8eacac344de1a5aa8b00cbd9ca4ebbb5fd1492073266ac77031d00000000
2024-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']
2024-05-20 15:15:10 DEBUG Block hash 000000010a8e7590525e9b727d118dfd07add9e7a6b1cc7e176449319a8b5c35 payout to tb1qylfujt900rjxzfxjj7sktpu7dpm2n9j60ch7jt
2024-05-20 15:15:10 INFO Mined block at height 10144; next in -464h59m50s (mine) Mining interrupted with SIGINT.2024-05-20 15:19:39 INFO Mined block at height 10156; next in -464h34m19s (mine)
2024-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']
2024-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']
2024-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"]}']
2024-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'}
2024-05-20 15:19:39 DEBUG Mining block delta=2m30s start=1714556720 mine=True
2024-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']
2024-05-20 15:19:39 DEBUG grinding headhex: 00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000
^C2024-05-20 15:19:50 DEBUG mining aborted by the user Killing bitcoin-util to simulate an unrecoverable failure❯ $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
2024-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']
2024-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']
2024-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"]}']
2024-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'}
2024-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']
2024-05-20 15:20:06 DEBUG Mining block delta=2m30s start=1714556720 mine=True
2024-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']
2024-05-20 15:20:06 DEBUG grinding headhex: 00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000
Traceback (most recent call last):
File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 567, in <module>
main()
File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 561, in main
return args.fn(args)
^^^^^^^^^^^^^
File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 433, in do_generate
raise e
File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 425, in do_generate
block = finish_block(block, signet_solution, args.grind_cmd)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/../contrib/signet/miner", line 108, in finish_block
newheadhex = subprocess.run(cmd, capture_output=True, input=b"", check=True).stdout.strip()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/jose.edil/2-development/bitcoin/bitcoin-core/src/bitcoin-util', 'grind', '00000020977d867c7de3682308149efc54a6fc7f0579c22adba2e2e3c6441d980100000027a2307dc3799e62088c8aec04cb69018572135edf9db5f3daee4ebfd6f79daf300f3266ac77031d00000000']' died with <Signals.SIGTERM: 15>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from style nit
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 bitcoin#30102
2a5bd91
to
1cf174a
Compare
Fair enough, committed the style suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 1cf174a
@@ -350,7 +352,7 @@ def do_generate(args): | |||
is_mine = True | |||
else: | |||
time_delta = next_block_delta(int(bestheader["bits"], 16), bci["bestblockhash"], ultimate_target, args.poisson, args.max_interval) | |||
mine_time = bestheader["time"] + time_delta | |||
mine_time = bestheader["time"] + time_delta + retries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you also would want to change:
if tmpl["mintime"] > mine_time:
logging.info("Updating block time from %d to %d", mine_time, tmpl["mintime"])
mine_time = tmpl["mintime"]
to be
mintime = tmpl["mintime"] + retries
if mine_time < mintime:
logging.info(...)
mine_time = mintime
Returned to draft so I can refactor this PR on top of #28417 recently merged. |
🐙 This pull request conflicts with the target branch and needs rebase. |
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 thecalibrate
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 aCould 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 time2024-05-17 12:56:01
). The session was interrupted with SIGINT (Ctrl-C) after mining block 10102 (during mining of block 10103).Debug messages from mining session
Chain info after the mining session