diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-01-02 17:50:48 -0500 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-01-02 17:50:56 -0500 |
commit | 17e14ac92fced92457945859463eda5d435bdd49 (patch) | |
tree | 0cab7274ff69d0444220fcd230851b24f2ba405c /src/test/util/mining.cpp | |
parent | 190a4051fde736faf99681d107f0b38dd385e90c (diff) | |
parent | faa92a2297b4a6aebdd58d1818c428f1c0346078 (diff) |
Merge #17781: rpc: Remove mempool global from miner
faa92a2297b4a6aebdd58d1818c428f1c0346078 rpc: Remove mempool global from miner (MarcoFalke)
6666ef13f167cfe880c2e94c09d003594d010cf3 test: Properly document blockinfo size in miner_tests (MarcoFalke)
Pull request description:
The miner needs read-only access to the mempool. Instead of using the mutable global `::mempool`, keep a immutable reference to a mempool that is passed to the miner. Apart from the obvious benefits of removing a global and making things immutable, this might also simplify testing with multiple mempools.
ACKs for top commit:
promag:
ACK faa92a2297b4a6aebdd58d1818c428f1c0346078.
fjahr:
ACK faa92a2297b4a6aebdd58d1818c428f1c0346078
jnewbery:
Code review ACK faa92a2297b4a6aebdd58d1818c428f1c0346078
Tree-SHA512: c44027b5d2217a724791166f3f3112c45110ac1dbb37bdae27148a0657e0d1a1d043b0d24e49fd45465ec014224d1b7eb15c92a33069ad883fa8ffeadc24735b
Diffstat (limited to 'src/test/util/mining.cpp')
-rw-r--r-- | src/test/util/mining.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp index 30f0f5d7e6..1df6844062 100644 --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -8,22 +8,23 @@ #include <consensus/merkle.h> #include <key_io.h> #include <miner.h> +#include <node/context.h> #include <pow.h> #include <script/standard.h> #include <validation.h> -CTxIn generatetoaddress(const std::string& address) +CTxIn generatetoaddress(const NodeContext& node, const std::string& address) { const auto dest = DecodeDestination(address); assert(IsValidDestination(dest)); const auto coinbase_script = GetScriptForDestination(dest); - return MineBlock(coinbase_script); + return MineBlock(node, coinbase_script); } -CTxIn MineBlock(const CScript& coinbase_scriptPubKey) +CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) { - auto block = PrepareBlock(coinbase_scriptPubKey); + auto block = PrepareBlock(node, coinbase_scriptPubKey); while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) { ++block->nNonce; @@ -36,10 +37,11 @@ CTxIn MineBlock(const CScript& coinbase_scriptPubKey) return CTxIn{block->vtx[0]->GetHash(), 0}; } -std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey) +std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) { + assert(node.mempool); auto block = std::make_shared<CBlock>( - BlockAssembler{Params()} + BlockAssembler{*node.mempool, Params()} .CreateNewBlock(coinbase_scriptPubKey) ->block); |