cculianu / Fulcrum

A fast & nimble SPV Server for BCH, BTC, and LTC
Other
325 stars 73 forks source link

Error message "Error loading address data. (Invalid scripthash)" when viewing P2PK address on self-hosted instance of Mempool. #212

Closed ghost closed 8 months ago

ghost commented 8 months ago

Hi,

I am self-hosting my own instance of Mempool and I got the error in the title when clicking on a P2PK address.

I am running Bitcoin Core 25.1 and Fulcrum 1.9.6 as backend and I thought I had misconfigured something so I asked in the Mempool support chat and one of the maintainers said that this is due to Fulcrum not indexing P2PK addresses.

Is this something worth considering to implement in a future release?

cculianu commented 8 months ago

The guy lied to you -- it is indexing p2pk addresses. It indexes any and all "locking scripts" irrespective of what they are.. including bare multisig, miner-created OP_TRUE, anything.

Not sure what's going on here but without more info I can't help...

I suspect there is just a bug in Mempool tbh, without further info, because Fulcrum indexes any and all locking scripts it sees. it doesn't even really parse them -- it just hashes them and indexes them.

ghost commented 8 months ago

Not sure what's going on here but without more info I can't help...

My bad, I should've provided more details.

Let's take this transaction as an example.

If I click on either the input or the output addresses, I am able to view the transaction history of those addresses.

mempool_space_P2PK

If I do the same on my self-hosted instance I get the "(Invalid scripthash)" message.

mempool_ch_P2PK

Mempool Space uses blockstream/electrs while I am using Fulcrum as backend.

cculianu commented 8 months ago

Do you know what RPC call it is looking for/failing on? Can you trace the RPC?

ghost commented 8 months ago

I have not been able to track it. I've enabled the debug option for [rpc] in bitcoin.conf but all I see is a lot of:

[rpc] ThreadRPCServer method=getmempoolinfo user=myuser [rpc] ThreadRPCServer method=getrawtransaction user=cookie [rpc] ThreadRPCServer method=getrawmempool user=myuser

No particular error pops up.

ghost commented 8 months ago

Also tried enabling debugging in fulcrum.conf with debug = true but I don't see anything wrong.

cculianu commented 8 months ago

You can enable network trace in Fulcrum.. you need to have "debug = true" appear twice in the conf file for that... it will be VERY verbose though so be prepared for your log to get raped.

I am very curious what call is being made. I suspect that what's happening is that blockstream's electrum supports some non-standard extensions to send a scripthash or a raw p2pk, which is outside the protocol spec for Electrum protocol. EDIT: See next comment -- I think it's a bug in Mempool. No extension.

This is the call for Electrum protocol 1.4 which ElectrumX and Fulcrum implement identically: https://electrum-cash-protocol.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-history .. it expects a scripthash.

I suspect the Mempool app is expecting this extension that blockstream offers that is unsupported and not part of the protocol. EDIT: No, I think it's a bug in Mempool app.

Let me know what the RPC is though .. I might be able to add "hidden" support for this extension...

If you can find out more let me know.

cculianu commented 8 months ago

I really think this is a bug in Mempool, in their Electrum backend. Have you reported this to them? I think they are just not encoding the request properly to the server for 1 particular call.

I think the bug is on this line, but I can't be sure since i don't know their codebase: https://github.com/mempool/mempool/blob/d4d17fa1672dc56ff82db886a82d08be1cd043d8/backend/src/api/bitcoin/electrum-api.ts#L170

This call should be made with encodeScriptHash wrapping the argument.. like the other similar calls.. but it is omitted.

I'm like 99% sure now this is a bug in the Mempool app.

Note that I realized after perusing their codebase that the Blockstream Esplora backend they use is completely different than the Electrum backend.. so this is not related to my previous hypothesis above that I need to add some "extension".

ghost commented 8 months ago

It looks like the fix for this has been implemented on Mempool's end. Still haven't tested it myself but I want to thank you for taking the time to look into this.

cculianu commented 8 months ago

My pleasure. I’m actually skeptical that this is the fix. I think also they forgot to convert a p2pk -> script hash for the gethistory call .. (the line of code I linked).

Do let me know if this doesn’t fix it and if not we can follow-up with them again.

Closing for now.

ghost commented 8 months ago

I have just rebuilt the backend after a git pull so I could test myself and I don't get any "Invalid scripthash" error message anymore.

mempool_FIX

cculianu commented 8 months ago

Oh that's great -- I guess maybe that fixed it? Keep clicking around see if everything works. Good to hear.

ghost commented 8 months ago

Been clicking around on multiple early blocks and no issue so far. Thank you very much.