From 45525cda01ef0d8f9aade88ce7ad910e6b6242d7 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 16 Oct 2018 22:38:56 +0000 Subject: [PATCH] Merge AuxPoW support from Namecore Changes are as below: Wrap CBlockHeader::nVersion into a new class (CBlockVersion). This allows to take care of interpreting the field into a base version, auxpow flag and the chain ID. Update getauxblock.py for new 'generate' RPC call. Add 'auxpow' to block JSON. Accept auxpow as PoW verification. Add unit tests for auxpow verification. Add check for memory-layout of CBlockVersion. Weaken auxpow chain ID checks for the testnet. Allow Params() to overrule when to check the auxpow chain ID and for legacy blocks. Use this to disable the checks on testnet. Introduce CPureBlockHeader. Split the block header part that is used by auxpow and the "real" block header (that uses auxpow) to resolve the cyclic dependency between the two. Differentiate between uint256 and arith_uint256. This change was done upstream, modify the auxpow code. Add missing lock in auxpow_tests. Fix REST header check for auxpow headers. Those can be longer, thus take that into account. Also perform the check actually on an auxpow header. Correctly set the coinbase for getauxblock results. Call IncrementExtraNonce in getauxblock so that the coinbase is actually initialised with the stuff it should be. (BIP30 block height and COINBASE_FLAGS.) Implement getauxblock plus regression test. Turn auxpow test into FIXTURE test. This allows using of the Params() calls. Move CMerkleTx code to auxpow.cpp. Otherwise we get linker errors when building without wallet. Fix rebase with BIP66. Update the code to handle BIP66's nVersion=3. Enforce that auxpow parent blocks have no auxpow block version. This is for compatibility with namecoind. See also https://github.com/namecoin/namecoin/pull/199. Move auxpow-related parameters to Consensus::Params. --- src/Makefile.am | 8 + src/Makefile.test.include | 1 + src/auxpow.cpp | 215 +++++++ src/auxpow.h | 158 +++++ src/chain.cpp | 28 + src/chain.h | 30 +- src/chainparams.cpp | 28 +- src/chainparams.h | 3 + src/consensus/params.h | 18 + src/dogecoin.cpp | 42 +- src/dogecoin.h | 8 + src/init.cpp | 3 +- src/miner.cpp | 6 +- src/miner.h | 3 + src/net_processing.cpp | 6 +- src/policy/policy.h | 4 +- src/pow.cpp | 1 + src/primitives/block.cpp | 19 +- src/primitives/block.h | 56 +- src/primitives/pureheader.cpp | 29 + src/primitives/pureheader.h | 146 +++++ src/qt/test/wallettests.cpp | 2 +- src/rest.cpp | 4 +- src/rpc/auxpow_miner.cpp | 197 ++++++ src/rpc/auxpow_miner.h | 107 +++ src/rpc/blockchain.cpp | 43 +- src/rpc/mining.cpp | 85 ++- src/rpc/rawtransaction.cpp | 3 +- src/rpc/rawtransaction.h | 15 + src/test/auxpow_tests.cpp | 609 ++++++++++++++++++ src/test/merkle_tests.cpp | 2 +- src/test/util/setup_common.cpp | 9 + src/test/util/setup_common.h | 5 + src/validation.cpp | 48 +- src/validation.h | 1 + src/wallet/rpcwallet.cpp | 186 ++++++ test/functional/auxpow_mining.py | 188 ++++++ test/functional/interface_rest.py | 19 +- test/functional/test_framework/auxpow.py | 104 +++ .../test_framework/auxpow_testing.py | 82 +++ 40 files changed, 2437 insertions(+), 84 deletions(-) create mode 100644 src/auxpow.cpp create mode 100644 src/auxpow.h create mode 100644 src/primitives/pureheader.cpp create mode 100644 src/primitives/pureheader.h create mode 100644 src/rpc/auxpow_miner.cpp create mode 100644 src/rpc/auxpow_miner.h create mode 100644 src/rpc/rawtransaction.h create mode 100644 src/test/auxpow_tests.cpp create mode 100755 test/functional/auxpow_mining.py create mode 100644 test/functional/test_framework/auxpow.py create mode 100644 test/functional/test_framework/auxpow_testing.py diff --git a/src/Makefile.am b/src/Makefile.am index 16f7b56272d..fd6b02d8dc3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -107,6 +107,7 @@ BITCOIN_CORE_H = \ addrdb.h \ addrman.h \ attributes.h \ + auxpow.h \ banman.h \ base58.h \ bech32.h \ @@ -185,6 +186,7 @@ BITCOIN_CORE_H = \ random.h \ randomenv.h \ reverse_iterator.h \ + rpc/auxpow_miner.h \ rpc/blockchain.h \ rpc/client.h \ rpc/mining.h \ @@ -317,6 +319,7 @@ libbitcoin_server_a_SOURCES = \ policy/settings.cpp \ pow.cpp \ rest.cpp \ + rpc/auxpow_miner.cpp \ rpc/blockchain.cpp \ rpc/mining.cpp \ rpc/misc.cpp \ @@ -463,6 +466,8 @@ libbitcoin_consensus_a_SOURCES = \ prevector.h \ primitives/block.cpp \ primitives/block.h \ + primitives/pureheader.cpp \ + primitives/pureheader.h \ primitives/transaction.cpp \ primitives/transaction.h \ pubkey.cpp \ @@ -487,6 +492,7 @@ libbitcoin_consensus_a_SOURCES = \ libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_common_a_SOURCES = \ + auxpow.cpp \ base58.cpp \ bech32.cpp \ bloom.cpp \ @@ -586,8 +592,10 @@ if TARGET_WINDOWS dogecoin_daemon_sources += bitcoind-res.rc endif +# FIXME: Remove SERVER once we have cleaned up getauxblock. dogecoin_bin_ldadd = \ $(LIBBITCOIN_WALLET) \ + $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_UTIL) \ $(LIBUNIVALUE) \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 4614179879b..1f5af956181 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -213,6 +213,7 @@ BITCOIN_TESTS =\ test/addrman_tests.cpp \ test/amount_tests.cpp \ test/allocator_tests.cpp \ + test/auxpow_tests.cpp \ test/base32_tests.cpp \ test/base58_tests.cpp \ test/base64_tests.cpp \ diff --git a/src/auxpow.cpp b/src/auxpow.cpp new file mode 100644 index 00000000000..24b13ad5579 --- /dev/null +++ b/src/auxpow.cpp @@ -0,0 +1,215 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 Vince Durham +// Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2014-2019 Daniel Kraft +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include +#include +#include