diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1805,11 +1805,12 @@ }}, {RPCResult::Type::STR_HEX, "lastblock", "The hash of the block (target_confirmations-1) from the best " - "block on the main chain. This is typically used to feed back " - "into listsinceblock the next time you call it. So you would " - "generally use a target_confirmations of say 6, so you will " - "be continually re-notified of transactions until they've " - "reached 6 confirmations plus any new ones"}, + "block on the main chain, or the genesis hash if the " + "referenced block does not exist yet. This is typically used " + "to feed back into listsinceblock the next time you call it. " + "So you would generally use a target_confirmations of say 6, " + "so you will be continually re-notified of transactions until " + "they've reached 6 confirmations plus any new ones"}, }}, RPCExamples{HelpExampleCli("listsinceblock", "") + HelpExampleCli("listsinceblock", @@ -1910,6 +1911,8 @@ } BlockHash lastblock; + target_confirms = + std::min(target_confirms, wallet.GetLastBlockHeight() + 1); CHECK_NONFATAL(wallet.chain().findAncestorByHeight( wallet.GetLastBlockHash(), wallet.GetLastBlockHeight() + 1 - target_confirms, diff --git a/test/functional/wallet_listsinceblock.py b/test/functional/wallet_listsinceblock.py --- a/test/functional/wallet_listsinceblock.py +++ b/test/functional/wallet_listsinceblock.py @@ -34,6 +34,7 @@ self.test_reorg() self.test_double_spend() self.test_double_send() + self.test_targetconfirmations() def test_no_blockhash(self): self.log.info("Test no blockhash") @@ -73,6 +74,27 @@ assert_raises_rpc_error(-8, "blockhash must be hexadecimal string (not 'Z000000000000000000000000000000000000000000000000000000000000000')", self.nodes[0].listsinceblock, "Z000000000000000000000000000000000000000000000000000000000000000") + def test_targetconfirmations(self): + ''' + This tests when the value of target_confirmations exceeds the number of + blocks in the main chain. In this case, the genesis block hash should be + given for the `lastblock` property. If target_confirmations is < 1, then + a -8 invalid parameter error is thrown. + ''' + self.log.info("Test target_confirmations") + blockhash, = self.nodes[2].generate(1) + blockheight = self.nodes[2].getblockheader(blockhash)['height'] + self.sync_all() + + assert_equal( + self.nodes[0].getblockhash(0), + self.nodes[0].listsinceblock(blockhash, blockheight + 1)['lastblock']) + assert_equal( + self.nodes[0].getblockhash(0), + self.nodes[0].listsinceblock(blockhash, blockheight + 1000)['lastblock']) + assert_raises_rpc_error(-8, "Invalid parameter", + self.nodes[0].listsinceblock, blockhash, 0) + def test_reorg(self): ''' `listsinceblock` did not behave correctly when handed a block that was