Skip to content

Commit

Permalink
node: Use existing NodeContext
Browse files Browse the repository at this point in the history
Summary:
This is a backport of [[bitcoin/bitcoin#21270 | core#21270]] [7/12] and [[bitcoin/bitcoin#21525 | core#21525]] [7/10]
bitcoin/bitcoin@4cde4a7
bitcoin/bitcoin@88aead2

Depends on D11422

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11423
  • Loading branch information
dongcarl authored and PiRK committed May 9, 2022
1 parent 9813976 commit a701d51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/node/coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

void FindCoins(const NodeContext &node, std::map<COutPoint, Coin> &coins) {
assert(node.mempool);
assert(node.chainman);
LOCK2(cs_main, node.mempool->cs);
CCoinsViewCache &chain_view = ::ChainstateActive().CoinsTip();
assert(std::addressof(::ChainstateActive()) ==
std::addressof(node.chainman->ActiveChainstate()));
CCoinsViewCache &chain_view = node.chainman->ActiveChainstate().CoinsTip();
CCoinsViewMemPool mempool_view(&chain_view, *node.mempool);
for (auto &coin : coins) {
if (!mempool_view.GetCoin(coin.first, coin.second)) {
Expand Down
14 changes: 9 additions & 5 deletions src/node/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ TransactionError BroadcastTransaction(NodeContext &node, const Config &config,
bool callback_set = false;

{ // cs_main scope
assert(node.chainman);
LOCK(cs_main);
assert(std::addressof(::ChainstateActive()) ==
std::addressof(node.chainman->ActiveChainstate()));
// If the transaction is already confirmed in the chain, don't do
// anything and return early.
CCoinsViewCache &view = ::ChainstateActive().CoinsTip();
CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
for (size_t o = 0; o < tx->vout.size(); o++) {
const Coin &existingCoin = view.AccessCoin(COutPoint(txid, o));
// IsSpent doesn't mean the coin is spent, it means the output
Expand All @@ -67,8 +70,8 @@ TransactionError BroadcastTransaction(NodeContext &node, const Config &config,
// First, call ATMP with test_accept and check the fee. If ATMP
// fails here, return error immediately.
Amount fee = Amount::zero();
if (!AcceptToMemoryPool(::ChainstateActive(), config,
*node.mempool, state, tx,
if (!AcceptToMemoryPool(node.chainman->ActiveChainstate(),
config, *node.mempool, state, tx,
false /* bypass_limits */,
/* test_accept */ true, &fee)) {
return HandleATMPError(state, err_string);
Expand All @@ -77,8 +80,9 @@ TransactionError BroadcastTransaction(NodeContext &node, const Config &config,
}
}
// Try to submit the transaction to the mempool.
if (!AcceptToMemoryPool(::ChainstateActive(), config, *node.mempool,
state, tx, false /* bypass_limits */)) {
if (!AcceptToMemoryPool(node.chainman->ActiveChainstate(), config,
*node.mempool, state, tx,
false /* bypass_limits */)) {
return HandleATMPError(state, err_string);
}

Expand Down

0 comments on commit a701d51

Please sign in to comment.