mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge 372f1a3c25 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.
This commit is contained in:
commit
1278b31bc7
13 changed files with 81 additions and 63 deletions
13
.cirrus.yml
13
.cirrus.yml
|
|
@ -73,6 +73,19 @@ task:
|
|||
env:
|
||||
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
|
||||
|
||||
task:
|
||||
name: 'tidy [jammy]'
|
||||
<< : *GLOBAL_TASK_TEMPLATE
|
||||
container:
|
||||
image: ubuntu:jammy
|
||||
cpu: 2
|
||||
memory: 5G
|
||||
# For faster CI feedback, immediately schedule the linters
|
||||
<< : *CREDITS_TEMPLATE
|
||||
env:
|
||||
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
|
||||
FILE_ENV: "./ci/test/00_setup_env_native_tidy.sh"
|
||||
|
||||
task:
|
||||
name: "Win64 native [msvc]"
|
||||
<< : *FILTER_TEMPLATE
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ export USE_BUSY_BOX=${USE_BUSY_BOX:-false}
|
|||
|
||||
export RUN_UNIT_TESTS=${RUN_UNIT_TESTS:-true}
|
||||
export RUN_FUNCTIONAL_TESTS=${RUN_FUNCTIONAL_TESTS:-true}
|
||||
export RUN_TIDY=${RUN_TIDY:-false}
|
||||
export RUN_SECURITY_TESTS=${RUN_SECURITY_TESTS:-false}
|
||||
# By how much to scale the test_runner timeouts (option --timeout-factor).
|
||||
# This is needed because some ci machines have slow CPU or disk, so sanitizers
|
||||
|
|
|
|||
19
ci/test/00_setup_env_native_tidy.sh
Executable file
19
ci/test/00_setup_env_native_tidy.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# 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.
|
||||
|
||||
export LC_ALL=C.UTF-8
|
||||
|
||||
export DOCKER_NAME_TAG="ubuntu:22.04"
|
||||
export CONTAINER_NAME=ci_native_tidy
|
||||
export PACKAGES="clang llvm clang-tidy bear libevent-dev libboost-dev"
|
||||
export NO_DEPENDS=1
|
||||
export RUN_UNIT_TESTS=false
|
||||
export RUN_FUNCTIONAL_TESTS=false
|
||||
export RUN_FUZZ_TESTS=false
|
||||
export RUN_TIDY=true
|
||||
export GOAL="install"
|
||||
export BITCOIN_CONFIG="CC=clang CXX=clang++ --disable-hardening CFLAGS='-O0 -g0' CXXFLAGS='-O0 -g0'"
|
||||
export CCACHE_SIZE=200M
|
||||
|
|
@ -48,7 +48,12 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
|
|||
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'
|
||||
fi
|
||||
|
||||
CI_EXEC make "$MAKEJOBS" "$GOAL" || ( echo "Build failure. Verbose build follows." && CI_EXEC make "$GOAL" V=1 ; false )
|
||||
if [[ "${RUN_TIDY}" == "true" ]]; then
|
||||
MAYBE_BEAR="bear"
|
||||
MAYBE_TOKEN="--"
|
||||
fi
|
||||
|
||||
CI_EXEC "${MAYBE_BEAR}" "${MAYBE_TOKEN}" make "$MAKEJOBS" "$GOAL" || ( echo "Build failure. Verbose build follows." && CI_EXEC make "$GOAL" V=1 ; false )
|
||||
|
||||
CI_EXEC "ccache --version | head -n 1 && ccache --show-stats"
|
||||
CI_EXEC du -sh "${DEPENDS_DIR}"/*/
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
|
|||
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
|
||||
fi
|
||||
|
||||
if [ "${RUN_TIDY}" = "true" ]; then
|
||||
export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/src/"
|
||||
CI_EXEC run-clang-tidy "${MAKEJOBS}"
|
||||
fi
|
||||
|
||||
if [ "$RUN_SECURITY_TESTS" = "true" ]; then
|
||||
CI_EXEC make test-security-check
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1950,6 +1950,7 @@ AC_CONFIG_LINKS([contrib/devtools/test-security-check.py:contrib/devtools/test-s
|
|||
AC_CONFIG_LINKS([contrib/devtools/test-symbol-check.py:contrib/devtools/test-symbol-check.py])
|
||||
AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
|
||||
AC_CONFIG_LINKS([contrib/macdeploy/background.tiff:contrib/macdeploy/background.tiff])
|
||||
AC_CONFIG_LINKS([src/.clang-tidy:src/.clang-tidy])
|
||||
AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
|
||||
AC_CONFIG_LINKS([test/bitcoin_functional/functional/test_runner.py:test/bitcoin_functional/functional/test_runner.py])
|
||||
AC_CONFIG_LINKS([test/fuzz/test_runner.py:test/fuzz/test_runner.py])
|
||||
|
|
|
|||
|
|
@ -491,22 +491,4 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
|
|||
nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
|
||||
}
|
||||
}
|
||||
|
||||
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
||||
{
|
||||
// Update nExtraNonce
|
||||
static uint256 hashPrevBlock;
|
||||
if (hashPrevBlock != pblock->hashPrevBlock) {
|
||||
nExtraNonce = 0;
|
||||
hashPrevBlock = pblock->hashPrevBlock;
|
||||
}
|
||||
++nExtraNonce;
|
||||
unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
|
||||
CMutableTransaction txCoinbase(*pblock->vtx[0]);
|
||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
|
||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||
|
||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
|
||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
|
||||
}
|
||||
} // namespace node
|
||||
|
|
|
|||
|
|
@ -211,8 +211,6 @@ private:
|
|||
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set& mapModifiedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
|
||||
};
|
||||
|
||||
/** Modify the extranonce in a block */
|
||||
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
||||
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
|
||||
|
||||
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
|
||||
|
|
|
|||
44
src/rpc/mining.cpp
Normal file → Executable file
44
src/rpc/mining.cpp
Normal file → Executable file
|
|
@ -7,6 +7,7 @@
|
|||
#include <chainparams.h>
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <consensus/merkle.h>
|
||||
#include <consensus/params.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <core_io.h>
|
||||
|
|
@ -50,7 +51,6 @@
|
|||
|
||||
using node::BlockAssembler;
|
||||
using node::CBlockTemplate;
|
||||
using node::IncrementExtraNonce;
|
||||
using node::NodeContext;
|
||||
using node::RegenerateCommitments;
|
||||
using node::UpdateTime;
|
||||
|
|
@ -123,19 +123,14 @@ static RPCHelpMan getnetworkhashps()
|
|||
};
|
||||
}
|
||||
|
||||
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, unsigned int& extra_nonce, uint256& block_hash)
|
||||
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, uint256& block_hash)
|
||||
{
|
||||
block_hash.SetNull();
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce);
|
||||
}
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
|
||||
CChainParams chainparams(Params());
|
||||
|
||||
// Signed blocks have no PoW requirements, but merkle root computed above in
|
||||
// IncrementExtraNonce
|
||||
// Signed blocks have no PoW requirements, but merkle root computed above
|
||||
if (!g_signed_blocks) {
|
||||
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus()) && !ShutdownRequested()) {
|
||||
++block.nNonce;
|
||||
|
|
@ -169,30 +164,20 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
|
|||
|
||||
static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& mempool, const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
|
||||
{
|
||||
int nHeightEnd = 0;
|
||||
int nHeight = 0;
|
||||
|
||||
{ // Don't keep cs_main locked
|
||||
LOCK(cs_main);
|
||||
nHeight = chainman.ActiveChain().Height();
|
||||
nHeightEnd = nHeight+nGenerate;
|
||||
}
|
||||
unsigned int nExtraNonce = 0;
|
||||
UniValue blockHashes(UniValue::VARR);
|
||||
while (nHeight < nHeightEnd && !ShutdownRequested())
|
||||
{
|
||||
while (nGenerate > 0 && !ShutdownRequested()) {
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), mempool, Params()).CreateNewBlock(coinbase_script));
|
||||
if (!pblocktemplate.get())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
||||
CBlock *pblock = &pblocktemplate->block;
|
||||
|
||||
uint256 block_hash;
|
||||
if (!GenerateBlock(chainman, *pblock, nMaxTries, nExtraNonce, block_hash)) {
|
||||
if (!GenerateBlock(chainman, *pblock, nMaxTries, block_hash)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!block_hash.IsNull()) {
|
||||
++nHeight;
|
||||
--nGenerate;
|
||||
blockHashes.push_back(block_hash.GetHex());
|
||||
}
|
||||
}
|
||||
|
|
@ -417,9 +402,8 @@ static RPCHelpMan generateblock()
|
|||
|
||||
uint256 block_hash;
|
||||
uint64_t max_tries{DEFAULT_MAX_TRIES};
|
||||
unsigned int extra_nonce{0};
|
||||
|
||||
if (!GenerateBlock(chainman, block, max_tries, extra_nonce, block_hash) || block_hash.IsNull()) {
|
||||
if (!GenerateBlock(chainman, block, max_tries, block_hash) || block_hash.IsNull()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block.");
|
||||
}
|
||||
|
||||
|
|
@ -1398,10 +1382,18 @@ static RPCHelpMan getnewblockhex()
|
|||
}
|
||||
|
||||
{
|
||||
// IncrementExtraNonce sets coinbase flags and builds merkle tree
|
||||
// Set coinbase flags and builds merkle tree
|
||||
LOCK(cs_main);
|
||||
unsigned int nExtraNonce = 0;
|
||||
IncrementExtraNonce(&pblocktemplate->block, chainman.ActiveChain().Tip(), nExtraNonce);
|
||||
pblocktemplate->block.hashMerkleRoot = BlockMerkleRoot(pblocktemplate->block);
|
||||
|
||||
unsigned int nHeight = chainman.ActiveChain().Tip()->nHeight + 1; // Height first in coinbase required for block.version=2
|
||||
CMutableTransaction txCoinbase(*pblocktemplate->block.vtx[0]);
|
||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
|
||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||
|
||||
pblocktemplate->block.vtx[0] = MakeTransactionRef(std::move(txCoinbase));
|
||||
pblocktemplate->block.hashMerkleRoot = BlockMerkleRoot(pblocktemplate->block);
|
||||
}
|
||||
|
||||
// If WSH(OP_TRUE) block, fill in witness
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <blockfilter.h>
|
||||
#include <chainparams.h>
|
||||
#include <consensus/merkle.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <node/miner.h>
|
||||
|
|
@ -18,7 +19,6 @@
|
|||
|
||||
using node::BlockAssembler;
|
||||
using node::CBlockTemplate;
|
||||
using node::IncrementExtraNonce;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
|
||||
|
||||
|
|
@ -76,9 +76,12 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
|
|||
for (const CMutableTransaction& tx : txns) {
|
||||
block.vtx.push_back(MakeTransactionRef(tx));
|
||||
}
|
||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot
|
||||
unsigned int extraNonce = 0;
|
||||
IncrementExtraNonce(&block, prev, extraNonce);
|
||||
{
|
||||
CMutableTransaction tx_coinbase{*block.vtx.at(0)};
|
||||
tx_coinbase.vin.at(0).scriptSig = CScript{} << prev->nHeight + 1;
|
||||
block.vtx.at(0) = MakeTransactionRef(std::move(tx_coinbase));
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
}
|
||||
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
|||
pruneheight = self.nodes[0].pruneblockchain(400)
|
||||
# the prune heights used here and below are magic numbers that are determined by the
|
||||
# thresholds at which block files wrap, so they depend on disk serialization and default block file size.
|
||||
assert_equal(pruneheight, 394)
|
||||
assert_equal(pruneheight, 395)
|
||||
|
||||
self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
|
||||
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
|
||||
|
|
@ -40,19 +40,18 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
|||
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0)
|
||||
|
||||
# mine and sync index up to a height that will later be the pruneheight
|
||||
self.generate(self.nodes[0], 298)
|
||||
self.sync_index(height=998)
|
||||
self.generate(self.nodes[0], 51)
|
||||
self.sync_index(height=751)
|
||||
|
||||
self.log.info("start node without blockfilterindex")
|
||||
self.restart_node(0, extra_args=["-fastprune", "-prune=1"])
|
||||
|
||||
self.log.info("make sure accessing the blockfilters throws an error")
|
||||
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2))
|
||||
self.generate(self.nodes[0], 502)
|
||||
self.generate(self.nodes[0], 749)
|
||||
|
||||
self.log.info("prune exactly up to the blockfilterindexes best block while blockfilters are disabled")
|
||||
pruneheight_2 = self.nodes[0].pruneblockchain(1000)
|
||||
assert_equal(pruneheight_2, 976) # ELEMENTS FIXME: why not 998
|
||||
pruneheight_2 = self.nodes[0].pruneblockchain(700) # ELEMENTS FIXME: this shuld be 1000
|
||||
assert_equal(pruneheight_2, 590) # ELEMENTS FIXME: why this number?
|
||||
self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"])
|
||||
self.log.info("make sure that we can continue with the partially synced index after having pruned up to the index height")
|
||||
self.sync_index(height=1500)
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ class UTXOSetHashTest(BitcoinTestFramework):
|
|||
assert_equal(finalized[::-1].hex(), node_muhash)
|
||||
|
||||
self.log.info("Test deterministic UTXO set hash results")
|
||||
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "4f08452f289a6cb0f277db2cef735d6332532f917321d8d8650b811d5119ec7c")
|
||||
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "0352e9a14613eea9f00ed9f437444450bdd64ea998b88579fdd71811a2d0d7cf")
|
||||
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "a7bf4204e7f5e803e0b36a207fe235d0f09d69b924457cb13785cfb301990fee")
|
||||
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "9bfdc6f243759d929b8af3c80620e3059023ee2f5348123c677bd61a858ca3df")
|
||||
|
||||
def run_test(self):
|
||||
self.test_muhash_implementation()
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ class DumptxoutsetTest(BitcoinTestFramework):
|
|||
# Blockhash should be deterministic based on mocked time.
|
||||
assert_equal(
|
||||
out['base_hash'],
|
||||
'10fcffda455bd997db67f3316a02947fc879a49a2d072b83880770043ef61ee2')
|
||||
'35cbc78d34cd311c914459deb0720da7935548b1e1ba165571b1ab67c37b4dce')
|
||||
|
||||
with open(str(expected_path), 'rb') as f:
|
||||
digest = hashlib.sha256(f.read()).hexdigest()
|
||||
# UTXO snapshot hash should be deterministic based on mocked time.
|
||||
assert_equal(
|
||||
digest, '6b4493ee40766455f586d13dd5b1c451748d05a88c4cce24344afe77e4e7d5ce')
|
||||
digest, '027f1b9e1b77eb0d9f34491369844509ad4434b8cabb4a0805022b8f84f239fd')
|
||||
|
||||
assert_equal(
|
||||
out['txoutset_hash'], '65789aa60eda11bec0c987f9f49e7c20399a16f66a5de085b3b4b352fa7039ef')
|
||||
out['txoutset_hash'], 'd01f8e9fd78d25418c071d592b207d09dbdf462a11963850ae80d387a414b235')
|
||||
assert_equal(out['nchaintx'], 101)
|
||||
|
||||
# Specifying a path to an existing file will fail.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue