moonbeam
moonbeam copied to clipboard
Hash of Moonriver finalized block is 0x000...000
At https://stakeglmr.com , as part of our backend indexing, we do:
api.rpc.chain.subscribeFinalizedHeads((header) => {
const finalizedBlockNum = +header.number.toString().replace(/,/g, '')
// DO STUFF
})
We have started deploying the same backend for Moonriver, and we noticed than when we initially subscribe, sometimes we get:
(await api.rpc.chain.getBlockHash(finalizedBlockNum)).toString() === '0x0000000000000000000000000000000000000000000000000000000000000000'
This is resolved if you wait a bit, but shouldn't it be the case that RPC should return the actual block hash for any finalized block number?
We have deployed a fix to both Moonriver and Moonbeam (just in case).
@ioannist thank you for reporting it. I wasn't able to reproduce it using:
import { ApiPromise, WsProvider } from "@polkadot/api";
const main = async () => {
const wsProvider = new WsProvider("wss://wss.moonriver.moonbeam.network");
const api = await ApiPromise.create({
provider: wsProvider,
});
await api.rpc.chain.subscribeFinalizedHeads(async (header) => {
console.log(
header.number.toString(),
(await api.rpc.chain.getBlockHash(header.number.toString())).toString()
);
});
};
main();
Is it happening all the time or only for some blocks ? If yes can you provide a block number ?
It is only happening (sometimes) for the first block when we subscribe to api.rpc.chain.subscribeFinalizedHeads
We keep requesting the block hash until we get a valid one, so we typically see it happening 2-3 times when we launch the program.
Your code looks identical, the only difference I see is that you connect remotely whereas we connect to a local node which I think is running 0.22 (will confirm). Since remote requests have a longer response time and this is a time-sensitive bug, it may be worth testing it with a local connection.
@ioannist is it still happening ? I haven't followed recent changed of finalization pipeline but I know there have been some changes in there