Skip to content
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

Signet nits #9

Open
wants to merge 23 commits into
base: signet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f7d9294
add witness commitment section support to primitive/block
kallewoof Jul 17, 2019
a5fa1a7
add simple signature support (checker/creator)
kallewoof Jul 17, 2019
88902e2
add signet basic support (signet.cpp)
kallewoof Jul 17, 2019
93dd0a1
add signet chain and accompanying parameters
kallewoof Aug 19, 2019
d691232
qt: update QT to support signet network
kallewoof Jul 17, 2019
7c3dec1
consensus: add signet validation
kallewoof Jul 17, 2019
934c0ac
i/o: make DecodeHexBlk able to read block hex from file
kallewoof Jul 18, 2019
264ceda
rpc: add getnewblockhex command for obtaining an unsigned block
kallewoof Jul 18, 2019
59e8952
rpc: add signblock command
kallewoof Jul 18, 2019
3f856b9
rpc: include signet commitment in blockToJSON dictionary results
kallewoof Jul 18, 2019
d15d65e
rpc: refactor out grindBlock part from generateBlocks
kallewoof Aug 19, 2019
4b46180
rpc: add grindblock command for generating POW on a signed signet block
kallewoof Aug 19, 2019
fc94419
test: added signet mining tests
kallewoof Aug 5, 2019
cac0e98
contrib: add signet scripts (issuer, etc)
kallewoof Jul 17, 2019
d3f63bd
signet: hard-coded parameters for Signet Global Network III (2019-08-19)
kallewoof Jun 28, 2019
2335feb
rpc/signet: show signet blockscript in 'getblockchaininfo'
kallewoof Aug 23, 2019
9f2e4b0
util_tests.cpp update hash for hard coded chain merge
kallewoof Sep 10, 2019
b4f922f
9102: Really don't validate genesis block
instagibbs Nov 7, 2016
8ffa06c
nit: consensus.signet_blocks = false in the other chains
jtimon Sep 7, 2019
a908c78
nit: moveonly: easier to make CreateSignetGenesisBlock static in the …
jtimon Sep 8, 2019
55a7ceb
nit: SigNetParams: set each default value independently
jtimon Sep 7, 2019
010cca0
nit: no need to grind genesis blocks
jtimon Sep 7, 2019
7623165
proposal: signet restart (hash chain name too)
jtimon Sep 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: added signet mining tests
Also adds a condition to test initialization code to not generate blocks for signet chains.
  • Loading branch information
kallewoof committed Sep 10, 2019
commit fc944197197bfdca80c35f2732af2bd20d88cebc
95 changes: 95 additions & 0 deletions test/functional/mining_signet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
# Copyright (c) 2019 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 mining RPCs

- getmininginfo
- getblocktemplate proposal mode
- submitblock"""

from decimal import Decimal

from test_framework.blocktools import (
create_coinbase,
)
from test_framework.messages import (
CBlock,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)

private_key = "ZFNp4W4HSatHDc4zsheMsDWgUg2uiB5PtnY2Y2hUCNCkQiF81KyV"
pubkey = "02c72b24ae2ee333f2da24aea66ce4338c01db8f26d0cc96f586d77edcb5238a4f"
address = "sb1qghzjzc0jvkjvvvymxnadmjjpu2tywmvagduwfj"
blockscript = "5121" + pubkey + "51ae" # 1-of-1 multisig
genesisnonce = 405557

def assert_template(node, block, expect, rehash=True):
if rehash:
block.hashMerkleRoot = block.calc_merkle_root()
rsp = node.getblocktemplate(template_request={'data': block.serialize().hex(), 'mode': 'proposal', 'rules': ['segwit']})
assert_equal(rsp, expect)


class SigMiningTest(BitcoinTestFramework):
def set_test_params(self):
self.chain = "signet"
self.num_nodes = 2
self.setup_clean_chain = True
shared_args = ["-signet_blockscript=" + blockscript, "-signet_genesisnonce=" + str(genesisnonce), "-signet_seednode=localhost:1234"]
self.extra_args = [shared_args, shared_args]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def generate(self, node, count):
for i in range(count):
addr = node.getnewaddress()
block = node.getnewblockhex(addr)
signed = node.signblock(block)
node.grindblock(signed)

def run_test(self):
node = self.nodes[0]

# give the privkey to node 1 so it can sign
node.importprivkey(private_key)
self.log.info('Imported network private key')
self.log.info('address: %s, privkey: %s' % (address, node.dumpprivkey(address)))

self.log.info('getmininginfo')
mining_info = node.getmininginfo()
assert_equal(mining_info['blocks'], 0)
assert_equal(mining_info['chain'], 'signet')
assert 'currentblocktx' not in mining_info
assert 'currentblockweight' not in mining_info
assert_equal(mining_info['networkhashps'], Decimal('0'))
assert_equal(mining_info['pooledtx'], 0)

# Mine a block to leave initial block download
# Actually we mine 20 cause there's a bug in the coinbase height serializers

self.generate(node, 20)
tmpl = node.getblocktemplate({'rules': ['segwit']})
self.log.info("getblocktemplate: Test capability advertised")
assert 'proposal' in tmpl['capabilities']
assert 'coinbasetxn' not in tmpl

coinbase_tx = create_coinbase(height=int(tmpl["height"]))
# sequence numbers must not be max for nLockTime to have effect
coinbase_tx.vin[0].nSequence = 2 ** 32 - 2
coinbase_tx.rehash()

block = CBlock()
block.nVersion = tmpl["version"]
block.hashPrevBlock = int(tmpl["previousblockhash"], 16)
block.nTime = tmpl["curtime"]
block.nBits = int(tmpl["bits"], 16)
block.nNonce = 0
block.vtx = [coinbase_tx]

if __name__ == '__main__':
SigMiningTest().main()
2 changes: 1 addition & 1 deletion test/functional/rpc_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_categories(self):
# command titles
titles = [line[3:-3] for line in node.help().splitlines() if line.startswith('==')]

components = ['Blockchain', 'Control', 'Generating', 'Mining', 'Network', 'Rawtransactions', 'Util']
components = ['Blockchain', 'Control', 'Generating', 'Mining', 'Network', 'Rawtransactions', 'Signet', 'Util']

if self.is_wallet_compiled():
components.append('Wallet')
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"mainnet": b"\xf9\xbe\xb4\xd9", # mainnet
"testnet3": b"\x0b\x11\x09\x07", # testnet3
"regtest": b"\xfa\xbf\xb5\xda", # regtest
"signet": b"\xf0\xc7\x70\x6a", # signet
}


Expand Down
30 changes: 16 additions & 14 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def setup_nodes(self):
extra_args = self.extra_args
self.add_nodes(self.num_nodes, extra_args)
self.start_nodes()
self.import_deterministic_coinbase_privkeys()
if self.chain != "signet":
self.import_deterministic_coinbase_privkeys()
if not self.setup_clean_chain:
for n in self.nodes:
assert_equal(n.getblockchaininfo()["blocks"], 199)
Expand Down Expand Up @@ -499,19 +500,20 @@ def _initialize_chain(self):
# Wait for RPC connections to be ready
self.nodes[CACHE_NODE_ID].wait_for_rpc_connection()

# Create a 199-block-long chain; each of the 4 first nodes
# gets 25 mature blocks and 25 immature.
# The 4th node gets only 24 immature blocks so that the very last
# block in the cache does not age too much (have an old tip age).
# This is needed so that we are out of IBD when the test starts,
# see the tip age check in IsInitialBlockDownload().
for i in range(8):
self.nodes[CACHE_NODE_ID].generatetoaddress(
nblocks=25 if i != 7 else 24,
address=TestNode.PRIV_KEYS[i % 4].address,
)

assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], 199)
if self.chain != "signet":
# Create a 199-block-long chain; each of the 4 first nodes
# gets 25 mature blocks and 25 immature.
# The 4th node gets only 24 immature blocks so that the very last
# block in the cache does not age too much (have an old tip age).
# This is needed so that we are out of IBD when the test starts,
# see the tip age check in IsInitialBlockDownload().
for i in range(8):
self.nodes[CACHE_NODE_ID].generatetoaddress(
nblocks=25 if i != 7 else 24,
address=TestNode.PRIV_KEYS[i % 4].address,
)

assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], 199)

# Shut it down, and clean up cache directories:
self.stop_nodes()
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
'rpc_bind.py --ipv6',
'rpc_bind.py --nonloopback',
'mining_basic.py',
'mining_signet.py',
'wallet_bumpfee.py',
'wallet_bumpfee_totalfee_deprecation.py',
'rpc_named_arguments.py',
Expand Down