Skip to content

Commit 4dcf3e8

Browse files
author
Braydon Fuller
committed
mempool: fix bug with mempool address index iteration
fixes a minor bug where iteration would not end when there are matching hashes for a p2sh and p2pkh address, and would return results for both addresses
1 parent 809a8ab commit 4dcf3e8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

qa/rpc-tests/addressindex.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ def run_test(self):
232232
address3 = "mw4ynwhS7MmrQ27hr82kgqu7zryNDK26JB"
233233
addressHash3 = "aa9872b5bbcdb511d89e0e11aa27da73fd2c3f50".decode("hex")
234234
scriptPubKey3 = CScript([OP_DUP, OP_HASH160, addressHash3, OP_EQUALVERIFY, OP_CHECKSIG])
235+
address4 = "2N8oFVB2vThAKury4vnLquW2zVjsYjjAkYQ"
236+
scriptPubKey4 = CScript([OP_HASH160, addressHash3, OP_EQUAL])
235237
unspent = self.nodes[2].listunspent()
236238

237239
tx = CTransaction()
@@ -246,7 +248,12 @@ def run_test(self):
246248
tx2 = CTransaction()
247249
tx2.vin = [CTxIn(COutPoint(int(unspent[1]["txid"], 16), unspent[1]["vout"]))]
248250
amount = unspent[1]["amount"] * 100000000
249-
tx2.vout = [CTxOut(amount / 2, scriptPubKey3), CTxOut(amount / 2, scriptPubKey3)]
251+
tx2.vout = [
252+
CTxOut(amount / 4, scriptPubKey3),
253+
CTxOut(amount / 4, scriptPubKey3),
254+
CTxOut(amount / 4, scriptPubKey4),
255+
CTxOut(amount / 4, scriptPubKey4)
256+
]
250257
tx2.rehash()
251258
signed_tx2 = self.nodes[2].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8"))
252259
memtxid2 = self.nodes[2].sendrawtransaction(signed_tx2["hex"], True)
@@ -268,8 +275,11 @@ def run_test(self):
268275
assert_equal(len(mempool2), 0)
269276

270277
tx = CTransaction()
271-
tx.vin = [CTxIn(COutPoint(int(memtxid2, 16), 0)), CTxIn(COutPoint(int(memtxid2, 16), 1))]
272-
tx.vout = [CTxOut(amount - 10000, scriptPubKey2)]
278+
tx.vin = [
279+
CTxIn(COutPoint(int(memtxid2, 16), 0)),
280+
CTxIn(COutPoint(int(memtxid2, 16), 1))
281+
]
282+
tx.vout = [CTxOut(amount / 2 - 10000, scriptPubKey2)]
273283
tx.rehash()
274284
self.nodes[2].importprivkey(privKey3)
275285
signed_tx3 = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ bool CTxMemPool::getAddressIndex(std::vector<std::pair<uint160, int> > &addresse
472472
LOCK(cs);
473473
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
474474
addressDeltaMap::iterator ait = mapAddress.lower_bound(CMempoolAddressDeltaKey((*it).second, (*it).first));
475-
while (ait != mapAddress.end() && (*ait).first.addressBytes == (*it).first) {
475+
while (ait != mapAddress.end() && (*ait).first.addressBytes == (*it).first && (*ait).first.type == (*it).second) {
476476
results.push_back(*ait);
477477
ait++;
478478
}

0 commit comments

Comments
 (0)