aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/transaction.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/transaction.h')
-rw-r--r--src/wallet/transaction.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h
index ddeb931112..9c27574103 100644
--- a/src/wallet/transaction.h
+++ b/src/wallet/transaction.h
@@ -43,12 +43,12 @@ struct TxStateInMempool {
};
//! State of rejected transaction that conflicts with a confirmed block.
-struct TxStateConflicted {
+struct TxStateBlockConflicted {
uint256 conflicting_block_hash;
int conflicting_block_height;
- explicit TxStateConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {}
- std::string toString() const { return strprintf("Conflicted (block=%s, height=%i)", conflicting_block_hash.ToString(), conflicting_block_height); }
+ explicit TxStateBlockConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {}
+ std::string toString() const { return strprintf("BlockConflicted (block=%s, height=%i)", conflicting_block_hash.ToString(), conflicting_block_height); }
};
//! State of transaction not confirmed or conflicting with a known block and
@@ -75,7 +75,7 @@ struct TxStateUnrecognized {
};
//! All possible CWalletTx states
-using TxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateConflicted, TxStateInactive, TxStateUnrecognized>;
+using TxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized>;
//! Subset of states transaction sync logic is implemented to handle.
using SyncTxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateInactive>;
@@ -90,7 +90,7 @@ static inline TxState TxStateInterpretSerialized(TxStateUnrecognized data)
} else if (data.index >= 0) {
return TxStateConfirmed{data.block_hash, /*height=*/-1, data.index};
} else if (data.index == -1) {
- return TxStateConflicted{data.block_hash, /*height=*/-1};
+ return TxStateBlockConflicted{data.block_hash, /*height=*/-1};
}
return data;
}
@@ -102,7 +102,7 @@ static inline uint256 TxStateSerializedBlockHash(const TxState& state)
[](const TxStateInactive& inactive) { return inactive.abandoned ? uint256::ONE : uint256::ZERO; },
[](const TxStateInMempool& in_mempool) { return uint256::ZERO; },
[](const TxStateConfirmed& confirmed) { return confirmed.confirmed_block_hash; },
- [](const TxStateConflicted& conflicted) { return conflicted.conflicting_block_hash; },
+ [](const TxStateBlockConflicted& conflicted) { return conflicted.conflicting_block_hash; },
[](const TxStateUnrecognized& unrecognized) { return unrecognized.block_hash; }
}, state);
}
@@ -114,7 +114,7 @@ static inline int TxStateSerializedIndex(const TxState& state)
[](const TxStateInactive& inactive) { return inactive.abandoned ? -1 : 0; },
[](const TxStateInMempool& in_mempool) { return 0; },
[](const TxStateConfirmed& confirmed) { return confirmed.position_in_block; },
- [](const TxStateConflicted& conflicted) { return -1; },
+ [](const TxStateBlockConflicted& conflicted) { return -1; },
[](const TxStateUnrecognized& unrecognized) { return unrecognized.index; }
}, state);
}
@@ -258,6 +258,14 @@ public:
CTransactionRef tx;
TxState m_state;
+ // Set of mempool transactions that conflict
+ // directly with the transaction, or that conflict
+ // with an ancestor transaction. This set will be
+ // empty if state is InMempool or Confirmed, but
+ // can be nonempty if state is Inactive or
+ // BlockConflicted.
+ std::set<Txid> mempool_conflicts;
+
template<typename Stream>
void Serialize(Stream& s) const
{
@@ -335,9 +343,10 @@ public:
void updateState(interfaces::Chain& chain);
bool isAbandoned() const { return state<TxStateInactive>() && state<TxStateInactive>()->abandoned; }
- bool isConflicted() const { return state<TxStateConflicted>(); }
+ bool isMempoolConflicted() const { return !mempool_conflicts.empty(); }
+ bool isBlockConflicted() const { return state<TxStateBlockConflicted>(); }
bool isInactive() const { return state<TxStateInactive>(); }
- bool isUnconfirmed() const { return !isAbandoned() && !isConflicted() && !isConfirmed(); }
+ bool isUnconfirmed() const { return !isAbandoned() && !isBlockConflicted() && !isMempoolConflicted() && !isConfirmed(); }
bool isConfirmed() const { return state<TxStateConfirmed>(); }
const Txid& GetHash() const LIFETIMEBOUND { return tx->GetHash(); }
const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return tx->GetWitnessHash(); }