Bitcoin ABC 0.32.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
8#include <blockindex.h>
9#include <common/args.h>
10
12 if (!m_mempool || !m_blockIndex.pprev) {
13 return true;
14 }
16 return true;
17 }
18
20
21 // TODO Use a CoinViewCache
22 for (const auto &tx : m_block.vtx) {
23 for (const auto &txin : tx->vin) {
24 const CTransactionRef ptxConflicting =
25 m_mempool->GetConflictTx(txin.prevout);
26
27 // Only allow for the exact txid for each coin spent
28 if (ptxConflicting && ptxConflicting->GetId() != tx->GetId() &&
30 ptxConflicting->GetId())) {
31 return state.Invalid(
33 "finalized-tx-conflict",
34 strprintf("Block %s contains tx %s that conflicts with "
35 "finalized tx %s",
37 tx->GetId().ToString(),
38 ptxConflicting->GetId().ToString()));
39 }
40 }
41 }
42
43 return true;
44}
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
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:317
bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx, const Consensus::Params &params, const CBlockIndex &active_chain_tip, std::vector< TxId > &finalizedTxIds) EXCLUSIVE_LOCKS_REQUIRED(bool isAvalancheFinalizedPreConsensus(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:541
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:740
const CBlockIndex & m_blockIndex
Definition: preconsensus.h:25
const CTxMemPool * m_mempool
Definition: preconsensus.h:26
const CBlock & m_block
Definition: preconsensus.h:24
bool operator()(BlockPolicyValidationState &state) override EXCLUSIVE_LOCKS_REQUIRED(m_mempool -> cs)
const avalanche::Processor & m_avalanche
Definition: preconsensus.h:23
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
Definition: validation.h:101
bool isPreconsensusActivated(const CBlockIndex *pprev) const
Definition: processor.cpp:1514
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)