mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
b0c3de6847
fb6d51eb25
signet/miner: Use argparse exclusive groups (Anthony Towns)338a266a9a
signet/miner: add support for a poolnum/poolid tag in mined blocks (Anthony Towns)409ab7d35b
signet/miner: add Generate.mine function (Anthony Towns)7b31332370
signet/miner: add Generate.gbt function (Anthony Towns)85c5c0bea9
signet/miner: add Generate.next_block_time function (Anthony Towns)5540e6ca49
signet/miner: move next_block_* functions into new Generator class (Anthony Towns)35f4631196
signet/miner: rename do_decode_psbt to decode_psbt (Anthony Towns)aac040b439
signet/miner: drop create_coinbase function (Anthony Towns)16951f549e
signet/miner: drop do_createpsbt function (Anthony Towns)3aed0a4284
signet/miner: drop get_reward_address function (Anthony Towns) Pull request description: Refactors the code a bunch, and adds `--poolnum` / `--poolid` options so that signers can tag their coinbases in a way that explorers can recognise (see also https://github.com/bitcoin-data/mining-pools/pull/82 and https://github.com/mempool/mempool/issues/2903). The refactoring in particular helps enable the "try using inquisition's getblocktemplate, and if that doesn't work fall back to core's getblocktemplate" logic, as described/implemented in https://github.com/bitcoin-inquisition/bitcoin/pull/7 ACKs for top commit: achow101: ACKfb6d51eb25
danielabrozzoni: Code review ACKfb6d51eb25
Tree-SHA512: d84095c4045ab196685b847e04ce2cdaedf387bc2527430ede918318dc5b70bf3d87b754264016f895f506fac70d4fdea5ef3cd8c3c375fd586afeae01e045e5
66 lines
2.2 KiB
Python
Executable file
66 lines
2.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# Copyright (c) 2022 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test signet miner tool"""
|
|
|
|
import os.path
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
from test_framework.key import ECKey
|
|
from test_framework.script_util import key_to_p2wpkh_script
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal
|
|
from test_framework.wallet_util import bytes_to_wif
|
|
|
|
|
|
CHALLENGE_PRIVATE_KEY = (42).to_bytes(32, 'big')
|
|
|
|
|
|
class SignetMinerTest(BitcoinTestFramework):
|
|
def add_options(self, parser):
|
|
self.add_wallet_options(parser)
|
|
|
|
def set_test_params(self):
|
|
self.chain = "signet"
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 1
|
|
|
|
# generate and specify signet challenge (simple p2wpkh script)
|
|
privkey = ECKey()
|
|
privkey.set(CHALLENGE_PRIVATE_KEY, True)
|
|
pubkey = privkey.get_pubkey().get_bytes()
|
|
challenge = key_to_p2wpkh_script(pubkey)
|
|
self.extra_args = [[f'-signetchallenge={challenge.hex()}']]
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_cli()
|
|
self.skip_if_no_wallet()
|
|
self.skip_if_no_bitcoin_util()
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0]
|
|
# import private key needed for signing block
|
|
node.importprivkey(bytes_to_wif(CHALLENGE_PRIVATE_KEY))
|
|
|
|
# generate block with signet miner tool
|
|
base_dir = self.config["environment"]["SRCDIR"]
|
|
signet_miner_path = os.path.join(base_dir, "contrib", "signet", "miner")
|
|
subprocess.run([
|
|
sys.executable,
|
|
signet_miner_path,
|
|
f'--cli={node.cli.binary} -datadir={node.cli.datadir}',
|
|
'generate',
|
|
f'--address={node.getnewaddress()}',
|
|
f'--grind-cmd={self.options.bitcoinutil} grind',
|
|
'--nbits=1d00ffff',
|
|
f'--set-block-time={int(time.time())}',
|
|
'--poolnum=99',
|
|
], check=True, stderr=subprocess.STDOUT)
|
|
assert_equal(node.getblockcount(), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
SignetMinerTest(__file__).main()
|