Skip to content

Commit c176f6c

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#7812: Tiny refactor of IsRBFOptIn, avoid exception
4f7c959 Refactor IsRBFOptIn, avoid exception (Jonas Schnelli)
1 parent f1f3fa3 commit c176f6c

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/policy/rbf.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,34 @@ bool SignalsOptInRBF(const CTransaction &tx)
1414
return false;
1515
}
1616

17-
bool IsRBFOptIn(const CTxMemPoolEntry &entry, CTxMemPool &pool)
17+
RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)
1818
{
1919
AssertLockHeld(pool.cs);
2020

2121
CTxMemPool::setEntries setAncestors;
2222

2323
// First check the transaction itself.
24-
if (SignalsOptInRBF(entry.GetTx())) {
25-
return true;
24+
if (SignalsOptInRBF(tx)) {
25+
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
2626
}
2727

2828
// If this transaction is not in our mempool, then we can't be sure
2929
// we will know about all its inputs.
30-
if (!pool.exists(entry.GetTx().GetHash())) {
31-
throw std::runtime_error("Cannot determine RBF opt-in signal for non-mempool transaction\n");
30+
if (!pool.exists(tx.GetHash())) {
31+
return RBF_TRANSACTIONSTATE_UNKNOWN;
3232
}
3333

3434
// If all the inputs have nSequence >= maxint-1, it still might be
3535
// signaled for RBF if any unconfirmed parents have signaled.
3636
uint64_t noLimit = std::numeric_limits<uint64_t>::max();
3737
std::string dummy;
38+
CTxMemPoolEntry entry = *pool.mapTx.find(tx.GetHash());
3839
pool.CalculateMemPoolAncestors(entry, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false);
3940

4041
BOOST_FOREACH(CTxMemPool::txiter it, setAncestors) {
4142
if (SignalsOptInRBF(it->GetTx())) {
42-
return true;
43+
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
4344
}
4445
}
45-
return false;
46+
return RBF_TRANSACTIONSTATE_FINAL;
4647
}

src/policy/rbf.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
#include "txmempool.h"
99

10+
enum RBFTransactionState {
11+
RBF_TRANSACTIONSTATE_UNKNOWN,
12+
RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125,
13+
RBF_TRANSACTIONSTATE_FINAL
14+
};
15+
1016
// Check whether the sequence numbers on this transaction are signaling
1117
// opt-in to replace-by-fee, according to BIP 125
1218
bool SignalsOptInRBF(const CTransaction &tx);
@@ -15,6 +21,6 @@ bool SignalsOptInRBF(const CTransaction &tx);
1521
// according to BIP 125
1622
// This involves checking sequence numbers of the transaction, as well
1723
// as the sequence numbers of all in-mempool ancestors.
18-
bool IsRBFOptIn(const CTxMemPoolEntry &entry, CTxMemPool &pool);
24+
RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool);
1925

2026
#endif // BITCOIN_POLICY_RBF_H

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
8686
std::string rbfStatus = "no";
8787
if (confirms <= 0) {
8888
LOCK(mempool.cs);
89-
if (!mempool.exists(hash)) {
90-
if (SignalsOptInRBF(wtx)) {
91-
rbfStatus = "yes";
92-
} else {
93-
rbfStatus = "unknown";
94-
}
95-
} else if (IsRBFOptIn(*mempool.mapTx.find(hash), mempool)) {
89+
RBFTransactionState rbfState = IsRBFOptIn(wtx, mempool);
90+
if (rbfState == RBF_TRANSACTIONSTATE_UNKNOWN)
91+
rbfStatus = "unknown";
92+
else if (rbfState == RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125)
9693
rbfStatus = "yes";
97-
}
9894
}
9995
entry.push_back(Pair("bip125-replaceable", rbfStatus));
10096

0 commit comments

Comments
 (0)