Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Jul 3, 2024
1 parent 92092d3 commit a0d0f9f
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 33 deletions.
28 changes: 27 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ BITCOIN_CORE_H = \
policy/rbf.h \
policy/settings.h \
pow.h \
pos.h \
protocol.h \
psbt.h \
random.h \
Expand All @@ -275,6 +276,7 @@ BITCOIN_CORE_H = \
rpc/server.h \
rpc/server_util.h \
rpc/util.h \
rpc/contract_util.h \
scheduler.h \
script/descriptor.h \
script/keyorigin.h \
Expand Down Expand Up @@ -346,6 +348,8 @@ BITCOIN_CORE_H = \
util/vector.h \
util/convert.h \
util/signstr.h \
util/contractabi.h \
util/tokenstr.h \
validation.h \
validationinterface.h \
versionbits.h \
Expand All @@ -363,6 +367,9 @@ BITCOIN_CORE_H = \
wallet/receive.h \
wallet/rpc/util.h \
wallet/rpc/wallet.h \
wallet/rpc/addresses.h \
wallet/rpc/contract.h \
wallet/rpc/mining.h \
wallet/salvage.h \
wallet/scriptpubkeyman.h \
wallet/spend.h \
Expand All @@ -373,6 +380,7 @@ BITCOIN_CORE_H = \
wallet/walletdb.h \
wallet/wallettool.h \
wallet/walletutil.h \
wallet/stake.h \
walletinitinterface.h \
warnings.h \
zmq/zmqabstractnotifier.h \
Expand All @@ -381,7 +389,14 @@ BITCOIN_CORE_H = \
zmq/zmqrpc.h \
zmq/zmqutil.h \
qtum/posutils.h \
qtum/qtumstate.h \
qtum/qtumtransaction.h \
qtum/qtumDGP.h \
qtum/storageresults.h \
qtum/qtumutils.h \
qtum/qtumdelegation.h \
qtum/qtumtoken.h \
qtum/qtumledger.h \
qtum/delegationutils.h


Expand Down Expand Up @@ -485,10 +500,15 @@ libbitcoin_node_a_SOURCES = \
validation.cpp \
validationinterface.cpp \
versionbits.cpp \
qtum/qtumstate.cpp \
qtum/storageresults.cpp \
qtum/qtumledger.cpp \
$(BITCOIN_CORE_H)

if ENABLE_WALLET
libbitcoin_node_a_SOURCES += wallet/init.cpp
libbitcoin_node_a_SOURCES += wallet/init.cpp \
wallet/stake.cpp \
wallet/rpc/contract.cpp
libbitcoin_node_a_CPPFLAGS += $(BDB_CPPFLAGS)
endif
if !ENABLE_WALLET
Expand Down Expand Up @@ -717,6 +737,7 @@ libbitcoin_common_a_SOURCES = \
policy/policy.cpp \
protocol.cpp \
psbt.cpp \
pos.cpp \
rpc/external_signer.cpp \
rpc/rawtransaction_util.cpp \
rpc/request.cpp \
Expand All @@ -729,7 +750,11 @@ libbitcoin_common_a_SOURCES = \
script/solver.cpp \
warnings.cpp \
qtum/qtumutils.cpp \
qtum/qtumDGP.cpp \
qtum/qtumtoken.cpp \
qtum/qtumdelegation.cpp \
qtum/delegationutils.cpp \
util/contractabi.cpp \
libff/libff/algebra/curves/public_params.hpp \
libff/libff/algebra/curves/curve_utils.hpp \
evmone/include/evmone/evmone.h \
Expand Down Expand Up @@ -968,6 +993,7 @@ libqtum_util_a_SOURCES = \
util/string.cpp \
util/time.cpp \
util/tokenpipe.cpp \
util/tokenstr.cpp \
$(BITCOIN_CORE_H)
#

Expand Down
5 changes: 4 additions & 1 deletion src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <streams.h>
#include <util/chaintype.h>
#include <validation.h>
#include <test/util/setup_common.h>

// These are the two major time-sinks which happen after we have fully received
// a block off the wire, but before we can relay the block on to peers using
Expand Down Expand Up @@ -38,6 +39,8 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)

ArgsManager bench_args;
const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN);
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN);
Chainstate& chainstate = testing_setup->m_node.chainman->ActiveChainstate();

bench.unit("block").run([&] {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
Expand All @@ -46,7 +49,7 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)
assert(rewound);

BlockValidationState validationState;
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus(), chainstate);
assert(checked);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static void DuplicateInputs(benchmark::Bench& bench)
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
block.nNonce = 0;
auto nHeight = pindexPrev->nHeight + 1;
Chainstate& chainstate = testing_setup->m_node.chainman->ActiveChainstate();

// Make a coinbase TX
coinbaseTx.vin.resize(1);
Expand Down Expand Up @@ -58,7 +59,7 @@ static void DuplicateInputs(benchmark::Bench& bench)

bench.run([&] {
BlockValidationState cvstate{};
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false));
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), chainstate, false, false));
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/blockencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn) {
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
return READ_STATUS_INVALID;
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > dgpMaxBlockWeight / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)
return READ_STATUS_INVALID;

if (!header.IsNull() || !txn_available.empty()) return READ_STATUS_INVALID;
Expand Down Expand Up @@ -204,7 +204,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<

BlockValidationState state;
CheckBlockFn check_block = m_check_block_mock ? m_check_block_mock : CheckBlock;
if (!check_block(block, state, Params().GetConsensus(), /*fCheckPoW=*/true, /*fCheckMerkleRoot=*/true)) {
if (!check_block(block, state, Params().GetConsensus(), chainman->ActiveChainstate(), /*fCheckPoW=*/true, /*fCheckMerkleRoot=*/true, /*fCheckSig=*/true)) {
// TODO: We really want to just check merkle tree manually here,
// but that is expensive, and CheckBlock caches a block's
// "checked-status" (in the CBlock?). CBlock should be able to
Expand Down
2 changes: 1 addition & 1 deletion src/blockencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class PartiallyDownloadedBlock {
CBlockHeader header;

// Can be overridden for testing
using CheckBlockFn = std::function<bool(const CBlock&, BlockValidationState&, const Consensus::Params&, bool, bool)>;
using CheckBlockFn = std::function<bool(const CBlock&, BlockValidationState&, const Consensus::Params&, Chainstate& chainstate, bool, bool, bool)>;
CheckBlockFn m_check_block_mock{nullptr};

explicit PartiallyDownloadedBlock(CTxMemPool* poolIn, ChainstateManager* _chainman) : pool(poolIn), chainman(_chainman) {}
Expand Down
14 changes: 14 additions & 0 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <util/moneystr.h>
#include <util/time.h>
#include <validation.h>
#ifdef ENABLE_WALLET
#include <wallet/wallet.h>
#include <wallet/receive.h>
#include <wallet/stake.h>
#endif

#include <algorithm>
#include <utility>
Expand Down Expand Up @@ -428,4 +433,13 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
nDescendantsUpdated += UpdatePackagesForAdded(mempool, ancestors, mapModifiedTx);
}
}
#ifdef ENABLE_WALLET
void StakeQtums(bool fStake, wallet::CWallet *pwallet)
{
}

void RefreshDelegates(wallet::CWallet *pwallet, bool refreshMyDelegates, bool refreshStakerDelegates)
{
}
#endif
} // namespace node
6 changes: 6 additions & 0 deletions src/node/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ class BlockAssembler
void SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries);
};

#ifdef ENABLE_WALLET
/** Generate a new block, without valid proof-of-work */
void StakeQtums(bool fStake, wallet::CWallet *pwallet);
void RefreshDelegates(wallet::CWallet *pwallet, bool myDelegates, bool stakerDelegates);
#endif

int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);

/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
Expand Down
4 changes: 2 additions & 2 deletions src/pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ uint256 ComputeStakeModifier(const CBlockIndex* pindexPrev, const uint256& kerne
if (!pindexPrev)
return uint256(); // genesis block's modifier is 0

CHashWriter ss(0);
HashWriter ss;
ss << kernel << pindexPrev->nStakeModifier;
return ss.GetHash();
}
Expand Down Expand Up @@ -88,7 +88,7 @@ bool CheckStakeKernelHash(CBlockIndex* pindexPrev, unsigned int nBits, uint32_t
uint256 nStakeModifier = pindexPrev->nStakeModifier;

// Calculate hash
CHashWriter ss(0);
HashWriter ss;
ss << nStakeModifier;
ss << blockFromTime << prevout.hash << prevout.n << nTimeBlock;
hashProofOfStake = ss.GetHash();
Expand Down
4 changes: 2 additions & 2 deletions src/qtum/qtumstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ResultExecute QtumState::execute(EnvInfo const& _envInfo, SealEngineFace const&
//create a refund tx to send back any coins that were suppose to be sent to the contract
CMutableTransaction refund;
if(_t.value() > 0) {
refund.vin.push_back(CTxIn(h256Touint(_t.getHashWith()), _t.getNVout(), CScript() << OP_SPEND));
refund.vin.push_back(CTxIn(Txid::FromUint256(h256Touint(_t.getHashWith())), _t.getNVout(), CScript() << OP_SPEND));
//note, if sender was a non-standard tx, this will send the coins to pubkeyhash 0x00, effectively destroying the coins
CScript script(CScript() << OP_DUP << OP_HASH160 << _t.sender().asBytes() << OP_EQUALVERIFY << OP_CHECKSIG);
refund.vout.push_back(CTxOut(CAmount(_t.value().convert_to<uint64_t>()), script));
Expand Down Expand Up @@ -379,7 +379,7 @@ std::vector<CTxIn> CondensingTX::createVins(){
std::vector<CTxIn> ins;
for(auto& v : vins){
if((v.second.value > 0 && v.second.alive) || (v.second.value > 0 && !vins[v.first].alive && !checkDeleteAddress(v.first)))
ins.push_back(CTxIn(h256Touint(v.second.hash), v.second.nVout, CScript() << OP_SPEND));
ins.push_back(CTxIn(Txid::FromUint256(h256Touint(v.second.hash)), v.second.nVout, CScript() << OP_SPEND));
}
return ins;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/coinstatsindex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup)

LOCK(cs_main);
BlockValidationState state;
BOOST_CHECK(CheckBlock(block, state, params.GetConsensus()));
BOOST_CHECK(CheckBlock(block, state, params.GetConsensus(), chainstate));
BOOST_CHECK(m_node.chainman->AcceptBlock(new_block, state, &new_block_index, true, nullptr, nullptr, true));
CCoinsViewCache view(&chainstate.CoinsTip());
BOOST_CHECK(chainstate.ConnectBlock(block, state, new_block_index, view));
Expand Down
19 changes: 14 additions & 5 deletions src/test/fuzz/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <validation.h>
#include <test/util/setup_common.h>

#include <cassert>
#include <string>

namespace {
const TestingSetup* g_setup;

void initialize_block()
{
SelectParams(ChainType::REGTEST);
SelectParams(ChainType::UNITTEST);

static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
g_setup = testing_setup.get();
}

FUZZ_TARGET(block, .init = initialize_block)
Expand All @@ -33,17 +40,18 @@ FUZZ_TARGET(block, .init = initialize_block)
}
const Consensus::Params& consensus_params = Params().GetConsensus();
BlockValidationState validation_state_pow_and_merkle;
const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);
auto& chainstate = g_setup->m_node.chainman->ActiveChainstate();
const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, chainstate, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);
assert(validation_state_pow_and_merkle.IsValid() || validation_state_pow_and_merkle.IsInvalid() || validation_state_pow_and_merkle.IsError());
(void)validation_state_pow_and_merkle.Error("");
BlockValidationState validation_state_pow;
const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);
const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, chainstate, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);
assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || validation_state_pow.IsError());
BlockValidationState validation_state_merkle;
const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);
const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, chainstate, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);
assert(validation_state_merkle.IsValid() || validation_state_merkle.IsInvalid() || validation_state_merkle.IsError());
BlockValidationState validation_state_none;
const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);
const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, chainstate, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);
assert(validation_state_none.IsValid() || validation_state_none.IsInvalid() || validation_state_none.IsError());
if (valid_incl_pow_and_merkle) {
assert(valid_incl_pow && valid_incl_merkle && valid_incl_none);
Expand All @@ -66,3 +74,4 @@ FUZZ_TARGET(block, .init = initialize_block)
const bool is_null = block_copy.IsNull();
assert(is_null);
}
} // namespace
2 changes: 1 addition & 1 deletion src/test/fuzz/partially_downloaded_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void initialize_pdb()

PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional<BlockValidationResult> result)
{
return [result](const CBlock&, BlockValidationState& state, const Consensus::Params&, bool, bool) {
return [result](const CBlock&, BlockValidationState& state, const Consensus::Params&, Chainstate& chainstate, bool, bool, bool) {
if (result) {
return state.Invalid(*result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/validation_chainstate_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
// once it is changed to support multiple chainstates.
{
LOCK(::cs_main);
bool checked = CheckBlock(*pblockone, state, chainparams.GetConsensus());
bool checked = CheckBlock(*pblockone, state, chainparams.GetConsensus(), chainman.ActiveChainstate());
BOOST_CHECK(checked);
bool accepted = chainman.AcceptBlock(
pblockone, state, &pindex, true, nullptr, &newblock, true);
Expand Down
Loading

0 comments on commit a0d0f9f

Please sign in to comment.