romanz / electrs

An efficient re-implementation of Electrum Server in Rust
MIT License
1.1k stars 407 forks source link

Bug: failed to get block hash 0000000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0 #1101

Open redtigervn opened 4 weeks ago

redtigervn commented 4 weeks ago

Hi there,

I've installed bitcoin node and electrs server on VPS. I write nodejs script to listen new transaction from specific addrs and I get this error when I use Electrum protocol method blockchain.scripthash.subscribe to subscribe scripthash. Then I use electrumClient.subscribe.on event to listen new tx. But I always get this error

Failed to get block: 0000000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

This block hash has 66 characters instead of 64 characters. Anyone get this error?

I also delete electrs_db folder and sync data again but it doesn't help.

image

romanz commented 4 weeks ago

Which client library is being used? Would it be possible to share the requests' log?

romanz commented 4 weeks ago

IIUC, by removing the first zero byte, we get the following valid block hash: https://blockstream.info/block/00000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

redtigervn commented 3 weeks ago

Hi Romanz, Sorry for late reply, I use electrum-client lib (version ^0.0.6) I also use bitcoinjs-lib lib to convert address to electrum hash

const crypto = require('crypto');
const ecc = require('tiny-secp256k1');
const bitcoin = require('bitcoinjs-lib');
bitcoin.initEccLib(ecc);

const script = bitcoin.address.toOutputScript(address);
const hash = crypto.createHash('sha256').update(script).digest();
const reversedHash = Buffer.from(hash.reverse());
cosnt scripthash = reversedHash.toString('hex');

electrumClient.blockchainScripthash_subscribe(scripthash).then((scripthash) => {              
    console.log(`Subscribed to updates for scripthash: ${scriptHash}`);
});

electrumClient.subscribe.on('blockchain.scripthash.subscribe', async (data) => {
    const [scripthash, status] = data;
    //receive a notification when the status of the script hash changes.
    //do something here....
});
redtigervn commented 3 weeks ago

IIUC, by removing the first zero byte, we get the following valid block hash: https://blockstream.info/block/00000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

but I don't know where this block hash come from. I get this error when I'm listening new status of the script hash changes. This protocol method: blockchain.scripthash.subscribe

romanz commented 3 weeks ago

Unfortunately, I am not familiar with this client library.

You can run electrs with higher logging verbosity, to see all the JSON-RPC requests and responses:

export RUST_LOG=electrs::server=DEBUG

I would suggest also trying to see if your code works on other Electrum servers, and maybe opening an issue here.

redtigervn commented 3 weeks ago

Unfortunately, I am not familiar with this client library.

You can run electrs with higher logging verbosity, to see all the JSON-RPC requests and responses:

export RUST_LOG=electrs::server=DEBUG

I would suggest also trying to see if your code works on other Electrum servers, and maybe opening an issue here.

Thanks for your suggestion