Bitcoin ABC  0.29.4
P2P Digital Currency
preconsensus.cpp
Go to the documentation of this file.
1 // Copyright (c) 2024 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 
7 #include <avalanche/avalanche.h>
8 #include <blockindex.h>
9 #include <util/system.h>
10 
12  if (!m_mempool || !m_blockIndex.pprev ||
13  !gArgs.GetBoolArg("-avalanchepreconsensus",
15  return true;
16  }
17 
19 
20  // TODO Use a CoinViewCache
21  for (const auto &tx : m_block.vtx) {
22  for (const auto &txin : tx->vin) {
23  const CTransaction *ptxConflicting =
24  m_mempool->GetConflictTx(txin.prevout);
25 
26  // Only allow for the exact txid for each coin spent
27  if (ptxConflicting && ptxConflicting->GetId() != tx->GetId() &&
28  m_mempool->isAvalancheFinalized(ptxConflicting->GetId())) {
29  return state.Invalid(
31  "finalized-tx-conflict",
32  strprintf("Block %s contains tx %s that conflicts with "
33  "finalized tx %s",
35  tx->GetId().ToString(),
36  ptxConflicting->GetId().ToString()));
37  }
38  }
39  }
40 
41  return true;
42 }
static constexpr bool DEFAULT_AVALANCHE_PRECONSENSUS
Default for -avalanchepreconsensus.
Definition: avalanche.h:66
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:665
BlockHash GetHash() const
Definition: block.cpp:11
std::vector< CTransactionRef > vtx
Definition: block.h:63
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: blockindex.h:32
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
const TxId GetId() const
Definition: transaction.h:240
bool isAvalancheFinalized(const TxId &txid) const
Definition: txmempool.h:502
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:296
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:567
const CBlockIndex & m_blockIndex
Definition: preconsensus.h:18
const CTxMemPool * m_mempool
Definition: preconsensus.h:19
const CBlock & m_block
Definition: preconsensus.h:17
bool operator()(BlockPolicyValidationState &state) override EXCLUSIVE_LOCKS_REQUIRED(m_mempool -> cs)
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
Definition: validation.h:94
std::string ToString() const
Definition: uint256.h:80
@ POLICY_VIOLATION
A block policy rule was violated. This block should be parked.
ArgsManager gArgs
Definition: system.cpp:80
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
AssertLockHeld(pool.cs)