mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Merge #11565: Make listsinceblock refuse unknown block hash
659b206
Make listsinceblock refuse unknown block hash (Russell Yanofsky)
Pull request description:
Change suggested by @theuni who noticed listsinceblock would ignore invalid block hashes causing it to return a completely unfiltered list of transactions.
Tree-SHA512: 3c8fb160265780d1334e856e853ab48e2e18372b8f1fc71ae480c3f45317048cc1fee0055d5c58031981a91b9c2bdbeb8e49a889d04ecba61729ce8109f2ce3f
This commit is contained in:
commit
e1f6a2a801
@ -76,6 +76,9 @@ will only create hierarchical deterministic (HD) wallets.
|
|||||||
|
|
||||||
Low-level RPC changes
|
Low-level RPC changes
|
||||||
----------------------
|
----------------------
|
||||||
|
- `listsinceblock` will now throw an error if an unknown `blockhash` argument
|
||||||
|
value is passed, instead of returning a list of all wallet transactions since
|
||||||
|
the genesis block.
|
||||||
- The "currentblocksize" value in getmininginfo has been removed.
|
- The "currentblocksize" value in getmininginfo has been removed.
|
||||||
- The deprecated RPC `getinfo` was removed. It is recommended that the more specific RPCs are used:
|
- The deprecated RPC `getinfo` was removed. It is recommended that the more specific RPCs are used:
|
||||||
* `getblockchaininfo`
|
* `getblockchaininfo`
|
||||||
|
@ -1893,19 +1893,20 @@ UniValue listsinceblock(const JSONRPCRequest& request)
|
|||||||
int target_confirms = 1;
|
int target_confirms = 1;
|
||||||
isminefilter filter = ISMINE_SPENDABLE;
|
isminefilter filter = ISMINE_SPENDABLE;
|
||||||
|
|
||||||
if (!request.params[0].isNull()) {
|
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
|
||||||
uint256 blockId;
|
uint256 blockId;
|
||||||
|
|
||||||
blockId.SetHex(request.params[0].get_str());
|
blockId.SetHex(request.params[0].get_str());
|
||||||
BlockMap::iterator it = mapBlockIndex.find(blockId);
|
BlockMap::iterator it = mapBlockIndex.find(blockId);
|
||||||
if (it != mapBlockIndex.end()) {
|
if (it == mapBlockIndex.end()) {
|
||||||
paltindex = pindex = it->second;
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
if (chainActive[pindex->nHeight] != pindex) {
|
}
|
||||||
// the block being asked for is a part of a deactivated chain;
|
paltindex = pindex = it->second;
|
||||||
// we don't want to depend on its perceived height in the block
|
if (chainActive[pindex->nHeight] != pindex) {
|
||||||
// chain, we want to instead use the last common ancestor
|
// the block being asked for is a part of a deactivated chain;
|
||||||
pindex = chainActive.FindFork(pindex);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"""Test the listsincelast RPC."""
|
"""Test the listsincelast RPC."""
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal, assert_array_result, assert_raises_rpc_error
|
||||||
|
|
||||||
class ListSinceBlockTest (BitcoinTestFramework):
|
class ListSinceBlockTest (BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
@ -16,10 +16,43 @@ class ListSinceBlockTest (BitcoinTestFramework):
|
|||||||
self.nodes[2].generate(101)
|
self.nodes[2].generate(101)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
self.test_no_blockhash()
|
||||||
|
self.test_invalid_blockhash()
|
||||||
self.test_reorg()
|
self.test_reorg()
|
||||||
self.test_double_spend()
|
self.test_double_spend()
|
||||||
self.test_double_send()
|
self.test_double_send()
|
||||||
|
|
||||||
|
def test_no_blockhash(self):
|
||||||
|
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
|
||||||
|
blockhash, = self.nodes[2].generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
|
txs = self.nodes[0].listtransactions()
|
||||||
|
assert_array_result(txs, {"txid": txid}, {
|
||||||
|
"category": "receive",
|
||||||
|
"amount": 1,
|
||||||
|
"blockhash": blockhash,
|
||||||
|
"confirmations": 1,
|
||||||
|
})
|
||||||
|
assert_equal(
|
||||||
|
self.nodes[0].listsinceblock(),
|
||||||
|
{"lastblock": blockhash,
|
||||||
|
"removed": [],
|
||||||
|
"transactions": txs})
|
||||||
|
assert_equal(
|
||||||
|
self.nodes[0].listsinceblock(""),
|
||||||
|
{"lastblock": blockhash,
|
||||||
|
"removed": [],
|
||||||
|
"transactions": txs})
|
||||||
|
|
||||||
|
def test_invalid_blockhash(self):
|
||||||
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
||||||
|
"42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4")
|
||||||
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
||||||
|
"0000000000000000000000000000000000000000000000000000000000000000")
|
||||||
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
||||||
|
"invalid-hex")
|
||||||
|
|
||||||
def test_reorg(self):
|
def test_reorg(self):
|
||||||
'''
|
'''
|
||||||
`listsinceblock` did not behave correctly when handed a block that was
|
`listsinceblock` did not behave correctly when handed a block that was
|
||||||
|
Loading…
Reference in New Issue
Block a user