Skip to content

Commit

Permalink
Merge branch 'bitcoin' into auxpow
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Dec 24, 2024
2 parents 4ce366e + fc7b214 commit 69a8b4e
Show file tree
Hide file tree
Showing 75 changed files with 365 additions and 218 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ if(WIN32)
try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_interface)
try_append_linker_flag("-Wl,--minor-subsystem-version,2" TARGET core_interface)
endif()

# Workaround producing large object files, which cannot be handled by the assembler.
# More likely to happen with no, or lower levels of optimisation.
# See discussion in https://github.com/bitcoin/bitcoin/issues/28109.
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
try_append_cxx_flags("/bigobj" TARGET core_interface_debug SKIP_LINK)
else()
try_append_cxx_flags("-Wa,-mbig-obj" TARGET core_interface_debug SKIP_LINK)
endif()
endif()

# Use 64-bit off_t on 32-bit Linux.
Expand Down
1 change: 0 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"BUILD_GUI_TESTS": "ON",
"BUILD_KERNEL_LIB": "ON",
"BUILD_SHARED_LIBS": "ON",
"BUILD_TESTING": "ON",
"BUILD_TESTS": "ON",
"BUILD_TX": "ON",
"BUILD_UTIL": "ON",
Expand Down
6 changes: 4 additions & 2 deletions contrib/guix/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ inspecting signatures in Mach-O binaries.")
#t))))))))

(define-public glibc-2.31
(let ((commit "8e30f03744837a85e33d84ccd34ed3abe30d37c3"))
(let ((commit "7b27c450c34563a28e634cccb399cd415e71ebfe"))
(package
(inherit glibc) ;; 2.35
(version "2.31")
Expand All @@ -463,7 +463,7 @@ inspecting signatures in Mach-O binaries.")
(file-name (git-file-name "glibc" commit))
(sha256
(base32
"1zi0s9yy5zkisw823vivn7zlj8w6g9p3mm7lmlqiixcxdkz4dbn6"))
"017qdpr5id7ddb4lpkzj2li1abvw916m3fc6n7nw28z4h5qbv2n0"))
(patches (search-our-patches "glibc-guix-prefix.patch"))))
(arguments
(substitute-keyword-arguments (package-arguments glibc)
Expand All @@ -474,6 +474,8 @@ inspecting signatures in Mach-O binaries.")
"--enable-cet",
"--enable-bind-now",
"--disable-werror",
"--disable-timezone-tools",
"--disable-profile",
building-on)))
((#:phases phases)
`(modify-phases ,phases
Expand Down
1 change: 1 addition & 0 deletions depends/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ work/
built/
sources/
x86_64*
amd64*
i686*
mips*
arm*
Expand Down
2 changes: 0 additions & 2 deletions depends/hosts/netbsd.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ netbsd_NM = $(host_toolchain)gcc-nm
netbsd_RANLIB = $(host_toolchain)gcc-ranlib
endif

netbsd_CXXFLAGS=$(netbsd_CFLAGS)

netbsd_release_CFLAGS=-O2
netbsd_release_CXXFLAGS=$(netbsd_release_CFLAGS)

Expand Down
4 changes: 2 additions & 2 deletions doc/build-openbsd.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenBSD Build Guide

**Updated for OpenBSD [7.5](https://www.openbsd.org/75.html)**
**Updated for OpenBSD [7.6](https://www.openbsd.org/76.html)**

This guide describes how to build bitcoind, command-line utilities, and GUI on OpenBSD.

Expand Down Expand Up @@ -90,7 +90,7 @@ There is an included test suite that is useful for testing code changes when dev
To run the test suite (recommended), you will need to have Python 3 installed:

```bash
pkg_add python # Select the newest version of the package.
pkg_add python py3-zmq # Select the newest version of the python package if necessary.
```

## Building Bitcoin Core
Expand Down
13 changes: 9 additions & 4 deletions src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@
#include <memory>
#include <vector>

using node::BlockAssembler;

static void AssembleBlock(benchmark::Bench& bench)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

CScriptWitness witness;
witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);
BlockAssembler::Options options;
options.coinbase_output_script = P2WSH_OP_TRUE;

// Collect some loose transactions that spend the coinbases of our mined blocks
constexpr size_t NUM_BLOCKS{200};
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
CMutableTransaction tx;
tx.vin.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE));
tx.vin.emplace_back(MineBlock(test_setup->m_node, options));
tx.vin.back().scriptWitness = witness;
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
Expand All @@ -48,19 +52,20 @@ static void AssembleBlock(benchmark::Bench& bench)
}

bench.run([&] {
PrepareBlock(test_setup->m_node, P2WSH_OP_TRUE);
PrepareBlock(test_setup->m_node, options);
});
}
static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench)
{
FastRandomContext det_rand{true};
auto testing_setup{MakeNoLogFileContext<TestChain100Setup>()};
testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000, /*submit=*/true);
node::BlockAssembler::Options assembler_options;
BlockAssembler::Options assembler_options;
assembler_options.test_block_validity = false;
assembler_options.coinbase_output_script = P2WSH_OP_TRUE;

bench.run([&] {
PrepareBlock(testing_setup->m_node, P2WSH_OP_TRUE, assembler_options);
PrepareBlock(testing_setup->m_node, assembler_options);
});
}

Expand Down
31 changes: 17 additions & 14 deletions src/consensus/merkle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <consensus/merkle.h>
#include <hash.h>
#include <util/check.h>

/* WARNING! If you're reading this because you're learning about crypto
and/or designing a new system that will use merkle trees, keep in mind
Expand Down Expand Up @@ -84,8 +85,10 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
}

/* This implements a constant-space merkle root/path calculator, limited to 2^32 leaves. */
static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot, bool* pmutated, uint32_t branchpos, std::vector<uint256>* pbranch) {
if (pbranch) pbranch->clear();
static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot, bool* pmutated, uint32_t leaf_pos, std::vector<uint256>* path)
{
if (path) path->clear();
Assume(leaves.size() <= UINT32_MAX);
if (leaves.size() == 0) {
if (pmutated) *pmutated = false;
if (proot) *proot = uint256();
Expand All @@ -105,18 +108,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
// First process all leaves into 'inner' values.
while (count < leaves.size()) {
uint256 h = leaves[count];
bool matchh = count == branchpos;
bool matchh = count == leaf_pos;
count++;
int level;
// For each of the lower bits in count that are 0, do 1 step. Each
// corresponds to an inner value that existed before processing the
// current leaf, and each needs a hash to combine it.
for (level = 0; !(count & ((uint32_t{1}) << level)); level++) {
if (pbranch) {
if (path) {
if (matchh) {
pbranch->push_back(inner[level]);
path->push_back(inner[level]);
} else if (matchlevel == level) {
pbranch->push_back(h);
path->push_back(h);
matchh = true;
}
}
Expand Down Expand Up @@ -144,8 +147,8 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
// If we reach this point, h is an inner value that is not the top.
// We combine it with itself (Bitcoin's special rule for odd levels in
// the tree) to produce a higher level one.
if (pbranch && matchh) {
pbranch->push_back(h);
if (path && matchh) {
path->push_back(h);
}
h = Hash(h, h);
// Increment count to the value it would have if two entries at this
Expand All @@ -154,11 +157,11 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
level++;
// And propagate the result upwards accordingly.
while (!(count & ((uint32_t{1}) << level))) {
if (pbranch) {
if (path) {
if (matchh) {
pbranch->push_back(inner[level]);
path->push_back(inner[level]);
} else if (matchlevel == level) {
pbranch->push_back(h);
path->push_back(h);
matchh = true;
}
}
Expand All @@ -171,18 +174,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
if (proot) *proot = h;
}

static std::vector<uint256> ComputeMerkleBranch(const std::vector<uint256>& leaves, uint32_t position) {
static std::vector<uint256> ComputeMerklePath(const std::vector<uint256>& leaves, uint32_t position) {
std::vector<uint256> ret;
MerkleComputation(leaves, nullptr, nullptr, position, &ret);
return ret;
}

std::vector<uint256> BlockMerkleBranch(const CBlock& block, uint32_t position)
std::vector<uint256> TransactionMerklePath(const CBlock& block, uint32_t position)
{
std::vector<uint256> leaves;
leaves.resize(block.vtx.size());
for (size_t s = 0; s < block.vtx.size(); s++) {
leaves[s] = block.vtx[s]->GetHash();
}
return ComputeMerkleBranch(leaves, position);
return ComputeMerklePath(leaves, position);
}
4 changes: 2 additions & 2 deletions src/consensus/merkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated = nullptr);
* Compute merkle path to the specified transaction
*
* @param[in] block the block
* @param[in] position transaction for which to calculate the merkle path, defaults to coinbase
* @param[in] position transaction for which to calculate the merkle path (0 is the coinbase)
*
* @return merkle path ordered from the deepest
*/
std::vector<uint256> BlockMerkleBranch(const CBlock& block, uint32_t position = 0);
std::vector<uint256> TransactionMerklePath(const CBlock& block, uint32_t position);

#endif // BITCOIN_CONSENSUS_MERKLE_H
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
{
WAIT_LOCK(kernel_notifications.m_tip_block_mutex, lock);
kernel_notifications.m_tip_block_cv.wait(lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(kernel_notifications.m_tip_block_mutex) {
return !kernel_notifications.m_tip_block.IsNull() || ShutdownRequested(node);
return kernel_notifications.TipBlock() || ShutdownRequested(node);
});
}

Expand All @@ -1827,7 +1827,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
if (tip_info) {
tip_info->block_height = chain_active_height;
tip_info->block_time = best_block_time;
tip_info->verification_progress = GuessVerificationProgress(chainman.GetParams().TxData(), &tip);
tip_info->verification_progress = chainman.GuessVerificationProgress(&tip);
}
if (tip_info && chainman.m_best_header) {
tip_info->header_height = chainman.m_best_header->nHeight;
Expand Down
30 changes: 2 additions & 28 deletions src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BlockTemplate
*
* @returns if the block was processed, independent of block validity
*/
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CMutableTransaction coinbase) = 0;
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0;
};

//! Interface giving clients (RPC, Stratum v2 Template Provider in the future)
Expand Down Expand Up @@ -88,36 +88,10 @@ class Mining
/**
* Construct a new block template
*
* @param[in] script_pub_key the coinbase output
* @param[in] options options for creating the block
* @returns a block template
*/
virtual std::unique_ptr<BlockTemplate> createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options = {}) = 0;

/**
* Processes new block. A valid new block is automatically relayed to peers.
*
* @param[in] block The block we want to process.
* @param[out] new_block A boolean which is set to indicate if the block was first received via this call
* @returns If the block was processed, independently of block validity
*/
virtual bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) = 0;

//! Return the number of transaction updates in the mempool,
//! used to decide whether to make a new block template.
virtual unsigned int getTransactionsUpdated() = 0;

/**
* Check a block is completely valid from start to finish.
* Only works on top of our current best block.
* Does not check proof-of-work.
*
* @param[in] block the block to validate
* @param[in] check_merkle_root call CheckMerkleRoot()
* @param[out] state details of why a block failed to validate
* @returns false if it does not build on the current tip, or any of the checks fail
*/
virtual bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) = 0;
virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;

//! Get internal node context. Useful for RPC and testing,
//! but not accessible across processes.
Expand Down
5 changes: 1 addition & 4 deletions src/ipc/capnp/mining.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
isInitialBlockDownload @1 (context :Proxy.Context) -> (result: Bool);
getTip @2 (context :Proxy.Context) -> (result: Common.BlockRef, hasResult: Bool);
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef);
createNewBlock @4 (scriptPubKey: Data, options: BlockCreateOptions) -> (result: BlockTemplate);
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool);
createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate);
}

interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
Expand Down
Loading

0 comments on commit 69a8b4e

Please sign in to comment.