Author

Topic: cannot getrawtransaction on a txindex=0 node although block hash provided (Read 92 times)

hero member
Activity: 630
Merit: 731
Bitcoin g33k
Hello nc50lc,

thanks for the time and effort you took to test it. Unfortunately, I cannot reproduce this without unnecessary additional work. Nevertheless, I cannot (yet) make sense of it. If I stumble across it again at a later date (on another full node), I will dig further and try to find out what caused it. As far as I know at the moment, it looks like it only happened to me and therefore the error is probably 50cm behind the screen  Grin The main thing is that everything is fine with Bitcoin Core and everything is working as expected.

Thanks again for testing and feedback.
citb0in
legendary
Activity: 2534
Merit: 6080
Self-proclaimed Genius
Maybe you or anyone else can test this on his own full-node, preferably one without txindex enabled to compare apples by apples. I have no clue why I didn't work on my side, that's why I posted this question here.
As requested, I tested this on my full node Bitcoin Core v26.0.0 and it works if I included the blockhash.
The test node doesn't have txidex=1 in the config and has pruned blockchain.

The errors also work as intended.
  • If I provide a non-existing block hash:
    Block hash not found (code -5)
  • If I provide the hash of a pruned block:
    Block not available (code -1)
  • If I provide a TXID from another block:
    No such transaction found in the provided block. Use gettransaction for wallet transactions. (code -5)
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Either you got the wrong block hash, or your node was missing the block, possibly because it pruned it. Do you know if pruning was enabled? You should be able to discover this by looking at your debug.log.

That node is not pruned, it's an archived full-node. However I am still puzzled cause I'm pretty sure the block hash was correct. If you enter an invalid length of a block hash you will get a warning stating that. The user gets an information how many bytes the used block hash had. Nevertheless, since I've updated to txindex it seems to work. Thanks for your kind feedback and assistance, wish you a nice day.

citb0in
staff
Activity: 3458
Merit: 6793
Just writing some code
There are tests, and those are passing, so it does work. Either you got the wrong block hash, or your node was missing the block, possibly because it pruned it. Do you know if pruning was enabled? You should be able to discover this by looking at your debug.log. Note that txindex=1 doesn't work with pruning, so your node is no longer pruned if it was in the past.
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Hi Achow,

cannot tell you for sure cause meanwhile I enabled txindex and afterwards it worked. Maybe you or anyone else can test this on his own full-node, preferably one without txindex enabled to compare apples by apples. I have no clue why I didn't work on my side, that's why I posted this question here.

Cheers
citb0in
staff
Activity: 3458
Merit: 6793
Just writing some code
Does Bitcoin Core have the block whose hash you provide? Can you getblock it?
hero member
Activity: 630
Merit: 731
Bitcoin g33k
Hey everybody,

when I read the help of bitcoin-core command
Code:
getrawtransaction
I get this ...
Quote
getrawtransaction "txid" ( verbosity "blockhash" )

By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
If a blockhash argument is passed, it will return the transaction if
the specified block is available and the transaction is in that block.

Hint: Use gettransaction for wallet transactions.

If verbosity is 0 or omitted, returns the serialized transaction as a hex-encoded string.
If verbosity is 1, returns a JSON Object with information about the transaction.
If verbosity is 2, returns a JSON Object with information about the transaction, including fee and prevout information.

Arguments:
1. txid         (string, required) The transaction id
2. verbosity    (numeric, optional, default=0) 0 for hex-encoded data, 1 for a JSON object, and 2 for JSON object with fee and prevout
3. blockhash    (string, optional) The block in which to look for the transaction

I tried, and the result was not as expected. I used
Code:
getrawtransaction "abc123...TX...ID..." 0

and the error was:
Quote
No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions. (code -5)

In my understanding, it should return the requested data when I provide the blockhash even my full-node does not utilize txindex=1
The error message that Bitcoin Core outputted says the same: Either -txindex enabled or block hash provided.

But it doesn't. I am running latest version, why does this not work? Is the help page outdated somehow? Of course, when I enable txindex I get the result but this is contrary to what the documentations and help page of that command shows.

citb0in
Jump to: