diff options
author | Karl-Johan Alm <karljohan-alm@garage.co.jp> | 2017-01-11 15:31:16 +0900 |
---|---|---|
committer | Karl-Johan Alm <karljohan-alm@garage.co.jp> | 2017-01-18 12:07:13 +0900 |
commit | ee5c1ce5a6155d502d8e779d3490d6cf66374c3f (patch) | |
tree | 8747ac02a8749c889f347b3f8fc2028e5b1fc385 | |
parent | 6696b4635ceb9b47aaa63244bff9032fa7b08354 (diff) | |
download | bitcoin-ee5c1ce5a6155d502d8e779d3490d6cf66374c3f.tar.xz |
Bug-fix: listsinceblock: use closest common ancestor when a block hash was provided for a chain that was not the main chain.
-rw-r--r-- | src/wallet/rpcwallet.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2428ef04e2..f99aed519a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1679,7 +1679,7 @@ UniValue listsinceblock(const JSONRPCRequest& request) LOCK2(cs_main, pwalletMain->cs_wallet); - CBlockIndex *pindex = NULL; + const CBlockIndex *pindex = NULL; int target_confirms = 1; isminefilter filter = ISMINE_SPENDABLE; @@ -1690,7 +1690,16 @@ UniValue listsinceblock(const JSONRPCRequest& request) blockId.SetHex(request.params[0].get_str()); BlockMap::iterator it = mapBlockIndex.find(blockId); if (it != mapBlockIndex.end()) + { pindex = it->second; + if (chainActive[pindex->nHeight] != pindex) + { + // the block being asked for is a part of a deactivated chain; + // we don't want to depend on its perceived height in the block + // chain, we want to instead use the last common ancestor + pindex = chainActive.FindFork(pindex); + } + } } if (request.params.size() > 1) @@ -1701,9 +1710,10 @@ UniValue listsinceblock(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); } - if(request.params.size() > 2) - if(request.params[2].get_bool()) - filter = filter | ISMINE_WATCH_ONLY; + if (request.params.size() > 2 && request.params[2].get_bool()) + { + filter = filter | ISMINE_WATCH_ONLY; + } int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; |