diff --git a/qa/rpc-tests/abc-cmdline.py b/qa/rpc-tests/abc-cmdline.py --- a/qa/rpc-tests/abc-cmdline.py +++ b/qa/rpc-tests/abc-cmdline.py @@ -18,8 +18,7 @@ from test_framework.outputchecker import OutputChecker MAX_GENERATED_BLOCK_SIZE_ERROR = ( - 'Max generated block size (blockmaxsize) cannot be lower than ' - '1MB or exceed the excessive block size (excessiveblocksize)') + 'Max generated block size (blockmaxsize) cannot exceed the excessive block size (excessiveblocksize)') class ABC_CmdLine_Test (BitcoinTestFramework): @@ -95,48 +94,9 @@ raise AssertionError('Must not accept excessiveblocksize' ' below blockmaxsize') - # Make sure that allowsmallgeneratedblocksize doesn't help here - outputchecker = OutputChecker() - try: - self.extra_args = [['-blockmaxsize=1500000', - '-excessiveblocksize=1300000', - '-allowsmallgeneratedblocksize']] - self.nodes[0] = start_node(0, self.options.tmpdir, - self.extra_args[0], - stderr_checker=outputchecker) - except Exception as e: - assert(outputchecker.contains( - 'Error: ' + MAX_GENERATED_BLOCK_SIZE_ERROR)) - assert_equal( - 'bitcoind exited with status 1 during initialization', str(e)) - else: - raise AssertionError('Must not accept excessiveblocksize' - ' below blockmaxsize') - - print(" Attempt to set blockmaxsize below 1MB") - outputchecker = OutputChecker() - try: - self.extra_args = [["-blockmaxsize=%d" % LEGACY_MAX_BLOCK_SIZE]] - self.nodes[0] = start_node(0, self.options.tmpdir, - self.extra_args[0], - stderr_checker=outputchecker) - except Exception as e: - assert(outputchecker.contains( - 'Error: ' + MAX_GENERATED_BLOCK_SIZE_ERROR)) - assert_equal( - 'bitcoind exited with status 1 during initialization', str(e)) - else: - raise AssertionError('Must not accept excessiveblocksize' - ' below blockmaxsize') - - outputchecker = OutputChecker() - self.extra_args = [["-blockmaxsize=%d" % LEGACY_MAX_BLOCK_SIZE, - "-allowsmallgeneratedblocksize"]] - self.nodes[0] = start_node(0, self.options.tmpdir, - self.extra_args[0], - stderr_checker=outputchecker) - assert(outputchecker.contains( - 'Warning: ' + MAX_GENERATED_BLOCK_SIZE_ERROR)) + # Make sure we leave the test with a node running as this is what thee + # framework expects. + self.nodes[0] = start_node(0, self.options.tmpdir, []) def run_test(self): # Run tests on -excessiveblocksize option diff --git a/qa/rpc-tests/pruning.py b/qa/rpc-tests/pruning.py --- a/qa/rpc-tests/pruning.py +++ b/qa/rpc-tests/pruning.py @@ -53,12 +53,14 @@ start_node(0, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", "-checkblocks=5", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900)) self.nodes.append( start_node(1, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", "-checkblocks=5", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900)) @@ -67,6 +69,7 @@ start_node(2, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", "-prune=550", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900)) self.prunedir = self.options.tmpdir + "/node2/regtest/blocks/" @@ -76,11 +79,13 @@ self.nodes.append( start_node(3, self.options.tmpdir, ["-debug=0", "-maxreceivebuffer=20000", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900)) self.nodes.append( start_node(4, self.options.tmpdir, ["-debug=0", "-maxreceivebuffer=20000", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900)) @@ -88,6 +93,7 @@ self.nodes.append( start_node(5, self.options.tmpdir, ["-debug=0", "-prune=550", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME])) # Determine default relay fee @@ -151,6 +157,7 @@ self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", "-checkblocks=5", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) # Mine 24 blocks in node 1 @@ -183,7 +190,6 @@ self.stop_node(1) self.nodes[1] = start_node(1, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", - "-allowsmallgeneratedblocksize", "-blockmaxsize=5000", "-checkblocks=5", "-disablesafemode", @@ -214,10 +220,10 @@ self.stop_node(1) self.nodes[1] = start_node(1, self.options.tmpdir, ["-debug", "-maxreceivebuffer=20000", - "-allowsmallgeneratedblocksize", "-blockmaxsize=5000", "-checkblocks=5", "-disablesafemode", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900, stderr_checker=OutputChecker()) @@ -305,7 +311,7 @@ # at this point, node has 995 blocks and has not yet run in prune mode node = self.nodes[node_number] = start_node( node_number, self.options.tmpdir, - ["-debug=0", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) + ["-debug=0", "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) assert_equal(node.getblockcount(), 995) assert_raises_message( JSONRPCException, "not in prune mode", node.pruneblockchain, 500) @@ -314,7 +320,7 @@ # now re-start in manual pruning mode node = self.nodes[node_number] = start_node( node_number, self.options.tmpdir, - ["-debug=0", "-prune=1", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) + ["-debug=0", "-prune=1", "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) assert_equal(node.getblockcount(), 995) def height(index): @@ -404,7 +410,7 @@ self.stop_node(node_number) self.nodes[node_number] = start_node( node_number, self.options.tmpdir, - ["-debug=0", "-prune=550", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) + ["-debug=0", "-prune=550", "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME], timewait=900) print("Success") @@ -415,6 +421,7 @@ self.stop_node(2) start_node(2, self.options.tmpdir, ["-debug=1", "-prune=550", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME]) print("Success") except Exception as detail: @@ -431,6 +438,7 @@ self.stop_node(5) # stop and start to trigger rescan start_node(5, self.options.tmpdir, ["-debug=1", "-prune=550", + "-blockmaxsize=1000000", "-uahfstarttime=%d" % UAHF_START_TIME]) print ("Success") except Exception as detail: diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py --- a/qa/rpc-tests/smartfees.py +++ b/qa/rpc-tests/smartfees.py @@ -212,8 +212,7 @@ # (17k is room enough for 110 or so transactions) self.nodes.append(start_node(1, self.options.tmpdir, ["-blockprioritysize=1500", "-blockmaxsize=17000", - "-maxorphantx=1000", "-debug=estimatefee", - "-allowsmallgeneratedblocksize"], + "-maxorphantx=1000", "-debug=estimatefee"], stderr_checker=OutputChecker())) connect_nodes(self.nodes[1], 0) @@ -221,8 +220,7 @@ # produces too small blocks (room for only 55 or so transactions) node2args = ["-blockprioritysize=0", "-blockmaxsize=8000", - "-maxorphantx=1000", - "-allowsmallgeneratedblocksize"] + "-maxorphantx=1000"] self.nodes.append( start_node(2, self.options.tmpdir, node2args, stderr_checker=OutputChecker())) diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1400,24 +1400,12 @@ } // Check blockmaxsize does not exceed maximum accepted block size. - // Also checks that it isn't smaller than 1MB, as to make sure we can - // satisfy the "must be big" UAHF rule. const uint64_t nProposedMaxGeneratedBlockSize = GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); - const bool maxGeneratedBlockSizeTooSmall = - nProposedMaxGeneratedBlockSize <= LEGACY_MAX_BLOCK_SIZE; - const bool maxGeneratedBlockSizeTooBig = - nProposedMaxGeneratedBlockSize > config.GetMaxBlockSize(); - if (maxGeneratedBlockSizeTooSmall || maxGeneratedBlockSizeTooBig) { - auto msg = - _("Max generated block size (blockmaxsize) cannot be lower than " - "1MB or exceed the excessive block size (excessiveblocksize)"); - if (maxGeneratedBlockSizeTooBig || - !IsArgSet("-allowsmallgeneratedblocksize")) { - return InitError(msg); - } - - InitWarning(msg); + if (nProposedMaxGeneratedBlockSize > config.GetMaxBlockSize()) { + auto msg = _("Max generated block size (blockmaxsize) cannot exceed " + "the excessive block size (excessiveblocksize)"); + return InitError(msg); } const int64_t nProposedUAHFStartTime = diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -96,26 +96,9 @@ std::max(uint64_t(1000), std::min(config.GetMaxBlockSize() - 1000, nMaxGeneratedBlockSize)); - // If UAHF is not activated yet, we also want to limit the max generated - // block size to LEGACY_MAX_BLOCK_SIZE - 1000 - if (!IsUAHFenabled(config, pindexPrev)) { - nMaxGeneratedBlockSize = - std::min(LEGACY_MAX_BLOCK_SIZE - 1000, nMaxGeneratedBlockSize); - } - return nMaxGeneratedBlockSize; } -static uint64_t ComputeMinGeneratedBlockSize(const Config &config, - const CBlockIndex *pindexPrev) { - if (IsUAHFenabled(config, pindexPrev) && - !IsUAHFenabled(config, pindexPrev->pprev)) { - return LEGACY_MAX_BLOCK_SIZE + 1; - } - - return 0; -} - BlockAssembler::BlockAssembler(const Config &_config, const CChainParams &_chainparams) : chainparams(_chainparams), config(&_config) { @@ -162,7 +145,6 @@ resetBlock(); pblocktemplate.reset(new CBlockTemplate()); - if (!pblocktemplate.get()) { return nullptr; } @@ -223,30 +205,6 @@ uint64_t nSerializeSize = GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); - // We need a "must be big" block, so we stuff the coinbase. - uint64_t nMinBlockSize = ComputeMinGeneratedBlockSize(*config, pindexPrev); - if (nSerializeSize < nMinBlockSize) { - static const std::string pad = - "A purely peer-to-peer version of electronic cash would allow " - "online payments to be sent directly from one party to another " - "without going through a financial institution."; - auto o = CTxOut( - 0, CScript() << OP_RETURN - << std::vector(pad.begin(), pad.end())); - auto commitmentSize = - GetSerializeSize(o, SER_NETWORK, PROTOCOL_VERSION); - auto missingCommitment = - 1 + ((nMinBlockSize - nSerializeSize - 1) / commitmentSize); - coinbaseTx.vout.reserve(missingCommitment + 1); - for (size_t i = 0; i < missingCommitment; ++i) { - coinbaseTx.vout.push_back(o); - } - - pblock->vtx[0] = MakeTransactionRef(coinbaseTx); - nSerializeSize = - GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); - } - LogPrintf("CreateNewBlock(): total size: %u txs: %u fees: %ld sigops %d\n", nSerializeSize, nBlockTx, nFees, nBlockSigOps); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -721,42 +721,9 @@ GlobalConfig config; const CChainParams &chainparams = Params(); - // The maximum block size to be generated before the UAHF - static const auto LEGACY_CAP = LEGACY_MAX_BLOCK_SIZE - 1000; - // We are working on a fake chain and need to protect ourselves. LOCK(cs_main); - // Check before UAHF activation. - BOOST_CHECK(!IsUAHFenabledForCurrentBlock(config)); - - // Test around the historical 1MB cap - config.SetMaxBlockSize(ONE_MEGABYTE); - CheckBlockMaxSize(chainparams, 0, 1000); - CheckBlockMaxSize(chainparams, 1000, 1000); - CheckBlockMaxSize(chainparams, 1001, 1001); - CheckBlockMaxSize(chainparams, 12345, 12345); - - CheckBlockMaxSize(chainparams, ONE_MEGABYTE - 1001, ONE_MEGABYTE - 1001); - CheckBlockMaxSize(chainparams, ONE_MEGABYTE - 1000, ONE_MEGABYTE - 1000); - CheckBlockMaxSize(chainparams, ONE_MEGABYTE - 999, LEGACY_CAP); - CheckBlockMaxSize(chainparams, ONE_MEGABYTE, LEGACY_CAP); - - // Test around higher limit, the block size should still cap at LEGACY_CAP. - static const auto EIGHT_MEGABYTES = 8 * ONE_MEGABYTE; - config.SetMaxBlockSize(EIGHT_MEGABYTES); - CheckBlockMaxSize(chainparams, EIGHT_MEGABYTES - 1001, LEGACY_CAP); - CheckBlockMaxSize(chainparams, EIGHT_MEGABYTES - 1000, LEGACY_CAP); - CheckBlockMaxSize(chainparams, EIGHT_MEGABYTES - 999, LEGACY_CAP); - CheckBlockMaxSize(chainparams, EIGHT_MEGABYTES, LEGACY_CAP); - - // Before the UAHF, the default generated block size is the LEGACY_CAP. - { - ClearArg("-blockmaxsize"); - BlockAssembler ba(config, chainparams); - BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), LEGACY_CAP); - } - // Activate UAHF const int64_t hfStartTime = config.GetUAHFStartTime(); auto pindex = chainActive.Tip(); @@ -780,6 +747,7 @@ CheckBlockMaxSize(chainparams, ONE_MEGABYTE, ONE_MEGABYTE - 999); // Test around higher limit such as 8MB + static const auto EIGHT_MEGABYTES = 8 * ONE_MEGABYTE; config.SetMaxBlockSize(EIGHT_MEGABYTES); CheckBlockMaxSize(chainparams, EIGHT_MEGABYTES - 1001, EIGHT_MEGABYTES - 1001); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2102,9 +2102,9 @@ /** * Update the on-disk chain state. - * The caches and indexes are flushed depending on the mode we're called with - * if they're too large, if it's been a while since the last write, - * or always and in all cases if we're in prune mode and are deleting files. + * The caches and indexes are flushed depending on the mode we're called with if + * they're too large, if it's been a while since the last write, or always and + * in all cases if we're in prune mode and are deleting files. */ static bool FlushStateToDisk(CValidationState &state, FlushStateMode mode, int nManualPruneHeight) { @@ -3761,14 +3761,18 @@ } } -/* Calculate the block/rev files to delete based on height specified by user - * with RPC command pruneblockchain */ +/** + * Calculate the block/rev files to delete based on height specified by user + * with RPC command pruneblockchain. + */ void FindFilesToPruneManual(std::set &setFilesToPrune, int nManualPruneHeight) { assert(fPruneMode && nManualPruneHeight > 0); LOCK2(cs_main, cs_LastBlockFile); - if (chainActive.Tip() == nullptr) return; + if (chainActive.Tip() == nullptr) { + return; + } // last block to prune is the lesser of (user-specified height, // MIN_BLOCKS_TO_KEEP from the tip) @@ -3778,8 +3782,9 @@ int count = 0; for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) { if (vinfoBlockFile[fileNumber].nSize == 0 || - vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) + vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { continue; + } PruneOneBlockFile(fileNumber); setFilesToPrune.insert(fileNumber); count++; @@ -3801,7 +3806,7 @@ if (chainActive.Tip() == nullptr || nPruneTarget == 0) { return; } - if ((uint64_t)chainActive.Tip()->nHeight <= nPruneAfterHeight) { + if (uint64_t(chainActive.Tip()->nHeight) <= nPruneAfterHeight) { return; } @@ -3820,16 +3825,20 @@ nBytesToPrune = vinfoBlockFile[fileNumber].nSize + vinfoBlockFile[fileNumber].nUndoSize; - if (vinfoBlockFile[fileNumber].nSize == 0) continue; + if (vinfoBlockFile[fileNumber].nSize == 0) { + continue; + } - if (nCurrentUsage + nBuffer < - nPruneTarget) // are we below our target? + // are we below our target? + if (nCurrentUsage + nBuffer < nPruneTarget) { break; + } // don't prune files that could have a block within // MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning - if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) + if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { continue; + } PruneOneBlockFile(fileNumber); // Queue up the files for removal