The goal here is to decouple unrelated tests from the details of block versions.
Currently, these tests are forcing specific versions of blocks for no real reason.
The goal here is to decouple unrelated tests from the details of block versions.
Currently, these tests are forcing specific versions of blocks for no real reason.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, 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.
54 | @@ -51,19 +55,29 @@ 55 | # From BIP141 56 | WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed" 57 | 58 | +NORMAL_GBT_REQUEST_PARAMS = {"rules": ["segwit"]} 59 | 60 | -def create_block(hashprev, coinbase, ntime=None, *, version=1): 61 | + 62 | +def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl={}, txlist=None):
Passing in a dictionary as a default parameter value is triggering the linter.
So how do we fix the linter?
Something like this?
def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl=None, txlist=None):
tmpl = {} if tmpl is None else tmpl
or use the suggestion from the linter
There isn't a problem with this PR. The problem is the linter being wrong.
Changing this to None here since it conceptually makes more sense anyway, but in other cases the linter should probably be fixed instead.
64 | block = CBlock() 65 | - block.nVersion = version 66 | - if ntime is None: 67 | - import time 68 | - block.nTime = int(time.time() + 600) 69 | + if tmpl is None: tmpl = {}
You'll have to make this multi-line or exclude E701 in the lint script
no opinion on linter thing but
utACK https://github.com/bitcoin/bitcoin/pull/19401/commits/dfe8110e411b5321b38e6658d4661d88e7ea421a
36 | @@ -37,14 +37,15 @@ def trueDummy(tx): 37 | class NULLDUMMYTest(BitcoinTestFramework): 38 | 39 | def set_test_params(self): 40 | - self.num_nodes = 1 41 | + # Need two nodes only so GBT doesn't complain that it's not connected 42 | + self.num_nodes = 2
Requiring connected nodes is inconvenient for generating the initial blocks for custom signets as well. How about:
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -652,11 +652,13 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
if(!node.connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
+ if (!Params().IsTestChain()) {
if (node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
if (::ChainstateActive().IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME " is in initial sync and waiting for blocks...");
+ }
static unsigned int nTransactionsUpdatedLast;
const CTxMemPool& mempool = EnsureMemPool(request.context);
instead?
Seems like an unnecessary special-casing for tests. Best to just make the tests work right.
80 | + if coinbase is None: 81 | + coinbase = create_coinbase(height=tmpl['height']) 82 | block.vtx.append(coinbase) 83 | + if txlist: 84 | + for tx in txlist: 85 | + if not hasattr(tx, 'calc_sha256'):
nit: seems like the better choice
if not isinstance(tx, CTransaction):
We don't really care what the class is, so long as it has calc_sha256
271 | @@ -272,6 +272,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock): 272 | 273 | # Advance the time on the node so that we can test timelocks 274 | self.nodes[0].setmocktime(cur_time+600) 275 | + tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
nit: for clarification
# Save block template now to use for the reorg later
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
tACK dfe8110e411b5321b38e6658d4661d88e7ea421a
Personally I wouldn't remove the linter rule but no strong feelings.
Restored linter rule against common sense due to widespread popularity. Added suggested comment.
re-ACK d438d609cd64fe532d94e45000495de93ef99aa6
ACK d438d60