Skip to content

Commit 1278b31

Browse files
committed
Merge 372f1a3 into merged_master (Bitcoin PR bitcoin/bitcoin#24753)
Please review this very very carefully. I don't think this is correct, but I wanted to move on with the merges. Let's fix this.
2 parents 18d0ebd + 372f1a3 commit 1278b31

13 files changed

+81
-63
lines changed

.cirrus.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ task:
7373
env:
7474
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
7575

76+
task:
77+
name: 'tidy [jammy]'
78+
<< : *GLOBAL_TASK_TEMPLATE
79+
container:
80+
image: ubuntu:jammy
81+
cpu: 2
82+
memory: 5G
83+
# For faster CI feedback, immediately schedule the linters
84+
<< : *CREDITS_TEMPLATE
85+
env:
86+
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
87+
FILE_ENV: "./ci/test/00_setup_env_native_tidy.sh"
88+
7689
task:
7790
name: "Win64 native [msvc]"
7891
<< : *FILTER_TEMPLATE

ci/test/00_setup_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export USE_BUSY_BOX=${USE_BUSY_BOX:-false}
3737

3838
export RUN_UNIT_TESTS=${RUN_UNIT_TESTS:-true}
3939
export RUN_FUNCTIONAL_TESTS=${RUN_FUNCTIONAL_TESTS:-true}
40+
export RUN_TIDY=${RUN_TIDY:-false}
4041
export RUN_SECURITY_TESTS=${RUN_SECURITY_TESTS:-false}
4142
# By how much to scale the test_runner timeouts (option --timeout-factor).
4243
# This is needed because some ci machines have slow CPU or disk, so sanitizers

ci/test/00_setup_env_native_tidy.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2022 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
export LC_ALL=C.UTF-8
8+
9+
export DOCKER_NAME_TAG="ubuntu:22.04"
10+
export CONTAINER_NAME=ci_native_tidy
11+
export PACKAGES="clang llvm clang-tidy bear libevent-dev libboost-dev"
12+
export NO_DEPENDS=1
13+
export RUN_UNIT_TESTS=false
14+
export RUN_FUNCTIONAL_TESTS=false
15+
export RUN_FUZZ_TESTS=false
16+
export RUN_TIDY=true
17+
export GOAL="install"
18+
export BITCOIN_CONFIG="CC=clang CXX=clang++ --disable-hardening CFLAGS='-O0 -g0' CXXFLAGS='-O0 -g0'"
19+
export CCACHE_SIZE=200M

ci/test/06_script_a.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
4848
CI_EXEC 'grep -v HAVE_SYS_GETRANDOM src/config/bitcoin-config.h > src/config/bitcoin-config.h.tmp && mv src/config/bitcoin-config.h.tmp src/config/bitcoin-config.h'
4949
fi
5050

51-
CI_EXEC make "$MAKEJOBS" "$GOAL" || ( echo "Build failure. Verbose build follows." && CI_EXEC make "$GOAL" V=1 ; false )
51+
if [[ "${RUN_TIDY}" == "true" ]]; then
52+
MAYBE_BEAR="bear"
53+
MAYBE_TOKEN="--"
54+
fi
55+
56+
CI_EXEC "${MAYBE_BEAR}" "${MAYBE_TOKEN}" make "$MAKEJOBS" "$GOAL" || ( echo "Build failure. Verbose build follows." && CI_EXEC make "$GOAL" V=1 ; false )
5257

5358
CI_EXEC "ccache --version | head -n 1 && ccache --show-stats"
5459
CI_EXEC du -sh "${DEPENDS_DIR}"/*/

ci/test/06_script_b.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
3434
CI_EXEC LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" "${TEST_RUNNER_ENV}" test/functional/test_runner.py --ci "$MAKEJOBS" --tmpdirprefix "${BASE_SCRATCH_DIR}/test_runner/" --ansi --combinedlogslen=4000 --timeout-factor="${TEST_RUNNER_TIMEOUT_FACTOR}" "${TEST_RUNNER_EXTRA}" --quiet --failfast
3535
fi
3636

37+
if [ "${RUN_TIDY}" = "true" ]; then
38+
export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/src/"
39+
CI_EXEC run-clang-tidy "${MAKEJOBS}"
40+
fi
41+
3742
if [ "$RUN_SECURITY_TESTS" = "true" ]; then
3843
CI_EXEC make test-security-check
3944
fi

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,7 @@ AC_CONFIG_LINKS([contrib/devtools/test-security-check.py:contrib/devtools/test-s
19501950
AC_CONFIG_LINKS([contrib/devtools/test-symbol-check.py:contrib/devtools/test-symbol-check.py])
19511951
AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
19521952
AC_CONFIG_LINKS([contrib/macdeploy/background.tiff:contrib/macdeploy/background.tiff])
1953+
AC_CONFIG_LINKS([src/.clang-tidy:src/.clang-tidy])
19531954
AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
19541955
AC_CONFIG_LINKS([test/bitcoin_functional/functional/test_runner.py:test/bitcoin_functional/functional/test_runner.py])
19551956
AC_CONFIG_LINKS([test/fuzz/test_runner.py:test/fuzz/test_runner.py])

src/node/miner.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -491,22 +491,4 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
491491
nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
492492
}
493493
}
494-
495-
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
496-
{
497-
// Update nExtraNonce
498-
static uint256 hashPrevBlock;
499-
if (hashPrevBlock != pblock->hashPrevBlock) {
500-
nExtraNonce = 0;
501-
hashPrevBlock = pblock->hashPrevBlock;
502-
}
503-
++nExtraNonce;
504-
unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
505-
CMutableTransaction txCoinbase(*pblock->vtx[0]);
506-
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
507-
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
508-
509-
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
510-
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
511-
}
512494
} // namespace node

src/node/miner.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ class BlockAssembler
211211
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set& mapModifiedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
212212
};
213213

214-
/** Modify the extranonce in a block */
215-
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
216214
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
217215

218216
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */

src/rpc/mining.cpp

100644100755
Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <chainparams.h>
88
#include <consensus/amount.h>
99
#include <consensus/consensus.h>
10+
#include <consensus/merkle.h>
1011
#include <consensus/params.h>
1112
#include <consensus/validation.h>
1213
#include <core_io.h>
@@ -50,7 +51,6 @@
5051

5152
using node::BlockAssembler;
5253
using node::CBlockTemplate;
53-
using node::IncrementExtraNonce;
5454
using node::NodeContext;
5555
using node::RegenerateCommitments;
5656
using node::UpdateTime;
@@ -123,19 +123,14 @@ static RPCHelpMan getnetworkhashps()
123123
};
124124
}
125125

126-
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, unsigned int& extra_nonce, uint256& block_hash)
126+
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, uint256& block_hash)
127127
{
128128
block_hash.SetNull();
129-
130-
{
131-
LOCK(cs_main);
132-
IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce);
133-
}
129+
block.hashMerkleRoot = BlockMerkleRoot(block);
134130

135131
CChainParams chainparams(Params());
136132

137-
// Signed blocks have no PoW requirements, but merkle root computed above in
138-
// IncrementExtraNonce
133+
// Signed blocks have no PoW requirements, but merkle root computed above
139134
if (!g_signed_blocks) {
140135
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus()) && !ShutdownRequested()) {
141136
++block.nNonce;
@@ -169,30 +164,20 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
169164

170165
static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& mempool, const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
171166
{
172-
int nHeightEnd = 0;
173-
int nHeight = 0;
174-
175-
{ // Don't keep cs_main locked
176-
LOCK(cs_main);
177-
nHeight = chainman.ActiveChain().Height();
178-
nHeightEnd = nHeight+nGenerate;
179-
}
180-
unsigned int nExtraNonce = 0;
181167
UniValue blockHashes(UniValue::VARR);
182-
while (nHeight < nHeightEnd && !ShutdownRequested())
183-
{
168+
while (nGenerate > 0 && !ShutdownRequested()) {
184169
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), mempool, Params()).CreateNewBlock(coinbase_script));
185170
if (!pblocktemplate.get())
186171
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
187172
CBlock *pblock = &pblocktemplate->block;
188173

189174
uint256 block_hash;
190-
if (!GenerateBlock(chainman, *pblock, nMaxTries, nExtraNonce, block_hash)) {
175+
if (!GenerateBlock(chainman, *pblock, nMaxTries, block_hash)) {
191176
break;
192177
}
193178

194179
if (!block_hash.IsNull()) {
195-
++nHeight;
180+
--nGenerate;
196181
blockHashes.push_back(block_hash.GetHex());
197182
}
198183
}
@@ -417,9 +402,8 @@ static RPCHelpMan generateblock()
417402

418403
uint256 block_hash;
419404
uint64_t max_tries{DEFAULT_MAX_TRIES};
420-
unsigned int extra_nonce{0};
421405

422-
if (!GenerateBlock(chainman, block, max_tries, extra_nonce, block_hash) || block_hash.IsNull()) {
406+
if (!GenerateBlock(chainman, block, max_tries, block_hash) || block_hash.IsNull()) {
423407
throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block.");
424408
}
425409

@@ -1398,10 +1382,18 @@ static RPCHelpMan getnewblockhex()
13981382
}
13991383

14001384
{
1401-
// IncrementExtraNonce sets coinbase flags and builds merkle tree
1385+
// Set coinbase flags and builds merkle tree
14021386
LOCK(cs_main);
14031387
unsigned int nExtraNonce = 0;
1404-
IncrementExtraNonce(&pblocktemplate->block, chainman.ActiveChain().Tip(), nExtraNonce);
1388+
pblocktemplate->block.hashMerkleRoot = BlockMerkleRoot(pblocktemplate->block);
1389+
1390+
unsigned int nHeight = chainman.ActiveChain().Tip()->nHeight + 1; // Height first in coinbase required for block.version=2
1391+
CMutableTransaction txCoinbase(*pblocktemplate->block.vtx[0]);
1392+
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
1393+
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
1394+
1395+
pblocktemplate->block.vtx[0] = MakeTransactionRef(std::move(txCoinbase));
1396+
pblocktemplate->block.hashMerkleRoot = BlockMerkleRoot(pblocktemplate->block);
14051397
}
14061398

14071399
// If WSH(OP_TRUE) block, fill in witness

src/test/blockfilter_index_tests.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <blockfilter.h>
66
#include <chainparams.h>
7+
#include <consensus/merkle.h>
78
#include <consensus/validation.h>
89
#include <index/blockfilterindex.h>
910
#include <node/miner.h>
@@ -18,7 +19,6 @@
1819

1920
using node::BlockAssembler;
2021
using node::CBlockTemplate;
21-
using node::IncrementExtraNonce;
2222

2323
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
2424

@@ -76,9 +76,12 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
7676
for (const CMutableTransaction& tx : txns) {
7777
block.vtx.push_back(MakeTransactionRef(tx));
7878
}
79-
// IncrementExtraNonce creates a valid coinbase and merkleRoot
80-
unsigned int extraNonce = 0;
81-
IncrementExtraNonce(&block, prev, extraNonce);
79+
{
80+
CMutableTransaction tx_coinbase{*block.vtx.at(0)};
81+
tx_coinbase.vin.at(0).scriptSig = CScript{} << prev->nHeight + 1;
82+
block.vtx.at(0) = MakeTransactionRef(std::move(tx_coinbase));
83+
block.hashMerkleRoot = BlockMerkleRoot(block);
84+
}
8285

8386
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
8487

0 commit comments

Comments
 (0)