Skip to content

Commit ee5c1ce

Browse files
committed
Bug-fix: listsinceblock: use closest common ancestor when a block hash was provided for a chain that was not the main chain.
1 parent 6696b46 commit ee5c1ce

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
16791679

16801680
LOCK2(cs_main, pwalletMain->cs_wallet);
16811681

1682-
CBlockIndex *pindex = NULL;
1682+
const CBlockIndex *pindex = NULL;
16831683
int target_confirms = 1;
16841684
isminefilter filter = ISMINE_SPENDABLE;
16851685

@@ -1690,7 +1690,16 @@ UniValue listsinceblock(const JSONRPCRequest& request)
16901690
blockId.SetHex(request.params[0].get_str());
16911691
BlockMap::iterator it = mapBlockIndex.find(blockId);
16921692
if (it != mapBlockIndex.end())
1693+
{
16931694
pindex = it->second;
1695+
if (chainActive[pindex->nHeight] != pindex)
1696+
{
1697+
// the block being asked for is a part of a deactivated chain;
1698+
// we don't want to depend on its perceived height in the block
1699+
// chain, we want to instead use the last common ancestor
1700+
pindex = chainActive.FindFork(pindex);
1701+
}
1702+
}
16941703
}
16951704

16961705
if (request.params.size() > 1)
@@ -1701,9 +1710,10 @@ UniValue listsinceblock(const JSONRPCRequest& request)
17011710
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
17021711
}
17031712

1704-
if(request.params.size() > 2)
1705-
if(request.params[2].get_bool())
1706-
filter = filter | ISMINE_WATCH_ONLY;
1713+
if (request.params.size() > 2 && request.params[2].get_bool())
1714+
{
1715+
filter = filter | ISMINE_WATCH_ONLY;
1716+
}
17071717

17081718
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
17091719

0 commit comments

Comments
 (0)