moonbeam icon indicating copy to clipboard operation
moonbeam copied to clipboard

Hash of Moonriver finalized block is 0x000...000

Open ioannist opened this issue 3 years ago • 2 comments

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 avatar May 04 '22 05:05 ioannist

@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 ?

crystalin avatar May 04 '22 12:05 crystalin

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 avatar May 04 '22 14:05 ioannist

@ioannist is it still happening ? I haven't followed recent changed of finalization pipeline but I know there have been some changes in there

crystalin avatar Jan 04 '23 08:01 crystalin