Bitcoin ABC 0.30.7
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
8#include <blockindex.h>
9#include <common/args.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 CTransactionRef 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}
ArgsManager gArgs
Definition: args.cpp:38
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: args.cpp:556
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
bool isAvalancheFinalized(const TxId &txid) const
Definition: txmempool.h:513
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:307
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:571
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:101
std::string ToString() const
Definition: uint256.h:80
@ POLICY_VIOLATION
A block policy rule was violated. This block should be parked.
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
#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)