Skip to content

Commit 386de78

Browse files
authored
Fix SelectCoinsMinConf to allow instant respends (#3061)
* Modify tests to check for instant respends This should fail atm... * Fix SelectCoinsMinConf to allow instant respends Now tests should pass again.
1 parent cbbeec6 commit 386de78

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,6 +2895,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
28952895
std::sort(vCoins.begin(), vCoins.end(), less_then_denom);
28962896
}
28972897

2898+
int nMaxChainLength = std::min(gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT), gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT));
2899+
28982900
// try to find nondenom first to prevent unneeded spending of mixed coins
28992901
for (unsigned int tryDenom = tryDenomStart; tryDenom < 2; tryDenom++)
29002902
{
@@ -2908,11 +2910,13 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
29082910

29092911
const CWalletTx *pcoin = output.tx;
29102912

2913+
bool fLockedByIS = pcoin->IsLockedByInstantSend();
2914+
29112915
// if (logCategories != BCLog::NONE) LogPrint(BCLog::SELECTCOINS, "value %s confirms %d\n", FormatMoney(pcoin->vout[output.i].nValue), output.nDepth);
2912-
if (output.nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs))
2916+
if (output.nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs) && !fLockedByIS)
29132917
continue;
29142918

2915-
if (!mempool.TransactionWithinChainLimit(pcoin->GetHash(), nMaxAncestors))
2919+
if (!mempool.TransactionWithinChainLimit(pcoin->GetHash(), fLockedByIS ? nMaxChainLength : nMaxAncestors))
29162920
continue;
29172921

29182922
int i = output.i;

test/functional/p2p-instantsend.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def test_block_doublespend(self):
7171
assert (res['hash'] != wrong_block)
7272
# wait for long time only for first node
7373
timeout = 1
74+
# send coins back to the controller node without waiting for confirmations
75+
receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
76+
assert_equal(receiver.getwalletinfo()["balance"], 0)
7477
# mine more blocks
7578
# TODO: mine these blocks on an isolated node
7679
self.bump_mocktime(1)
@@ -109,6 +112,9 @@ def test_mempool_doublespend(self):
109112
for node in self.nodes:
110113
self.wait_for_instantlock(is_id, node)
111114
assert_raises_jsonrpc(-5, "No such mempool or blockchain transaction", isolated.getrawtransaction, dblspnd_txid)
115+
# send coins back to the controller node without waiting for confirmations
116+
receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
117+
assert_equal(receiver.getwalletinfo()["balance"], 0)
112118

113119
if __name__ == '__main__':
114120
InstantSendTest().main()

0 commit comments

Comments
 (0)