vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
86 stars 3.58k forks source link

Getting last block fails #100

Open silentlight opened 2 years ago

silentlight commented 2 years ago

Hi all,

When using:

const lastBlock = await this.connex.thor.block().get();

ocassionaly I get genesis block (height = 0).

Do you know what might be wrong.

qianbin commented 2 years ago
if (!this.connex.thor.status.head.number) {
    await this.connex.thor.ticker().next()
}
const lastBlock = await this.connex.thor.block().get()

add lines to check the head number should work

ehamery commented 2 years ago

Have you considered including that check in the block() function? this.connex.thor.status.head.number should never be null or undefined... await this.connex.thor.block().get() sometimes returns null. That is the same issue, isn't it?

qianbin commented 2 years ago

Have you considered including that check in the block() function? this.connex.thor.status.head.number should never be null or undefined... await this.connex.thor.block().get() sometimes returns null. That is the same issue, isn't it?

await this.connex.thor.block().get() returns null only if the block specified by the given arg revision does not exists.

ehamery commented 2 years ago

If you do not provide any argument to the block() function, await this.connex.thor.block().get() should return the head block, so it should never be null and it sometimes is. That looks like a bug to me. Same as this.connex.thor.status.head.number being null.

qianbin commented 2 years ago

If you do not provide any argument to the block() function, await this.connex.thor.block().get() should return the head block, so it should never be null and it sometimes is. That looks like a bug to me. Same as this.connex.thor.status.head.number being null.

You're right. I'll look into the code. Can you provides some context of your code piece?

ehamery commented 2 years ago

I am basically scanning blocks and once in a while await this.connex.thor.block().get() returns null.