1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "policy/rbf.h"
7 bool SignalsOptInRBF(const CTransaction
&tx
)
9 for (const CTxIn
&txin
: tx
.vin
) {
10 if (txin
.nSequence
< std::numeric_limits
<unsigned int>::max()-1) {
17 RBFTransactionState
IsRBFOptIn(const CTransaction
&tx
, CTxMemPool
&pool
)
19 AssertLockHeld(pool
.cs
);
21 CTxMemPool::setEntries setAncestors
;
23 // First check the transaction itself.
24 if (SignalsOptInRBF(tx
)) {
25 return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125
;
28 // If this transaction is not in our mempool, then we can't be sure
29 // we will know about all its inputs.
30 if (!pool
.exists(tx
.GetHash())) {
31 return RBF_TRANSACTIONSTATE_UNKNOWN
;
34 // If all the inputs have nSequence >= maxint-1, it still might be
35 // signaled for RBF if any unconfirmed parents have signaled.
36 uint64_t noLimit
= std::numeric_limits
<uint64_t>::max();
38 CTxMemPoolEntry entry
= *pool
.mapTx
.find(tx
.GetHash());
39 pool
.CalculateMemPoolAncestors(entry
, setAncestors
, noLimit
, noLimit
, noLimit
, noLimit
, dummy
, false);
41 for (CTxMemPool::txiter it
: setAncestors
) {
42 if (SignalsOptInRBF(it
->GetTx())) {
43 return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125
;
46 return RBF_TRANSACTIONSTATE_FINAL
;