monosux/ethereum-block-by-date

InternalError: too much recursion

Closed this issue · 11 comments

Hi, I'm running into an InternalError: too much recursion error.

DeepinScreenshot_select-area_20210819154327

Code:

const blockDater = new BlockDater(provider)
const currentTimestamp = (Date.now() / 1000) | 0
const date = DateTime.fromSeconds(currentTimestamp)
      .minus({ days: 1 })
      .toJSDate()
const info = await blockDater.getDate(date)

Any help is appreciated. Thanks!

Hi @miguelmota,

What is the "DateTime" object in your example? Is it "luxon" package?
Do you use Web3.js or Ethers.js?

@miguelmota sorry yes it's from luxon

import { DateTime } from 'luxon'

and it's ethers provider, with rpc url https://mainnet.optimism.io

I think it would be best to use a while loop instead of recursion

Also, what is the "ethereum-block-by-date" version you use?

@monosux latest 1.4.0

DeepinScreenshot_select-area_20210820094703

Thank you, I was able to reproduce the error. I am investigating it now. I let you know about the results soon.

Hi,

I am not familiar with the "optimism" solution, but for some reason, it has unusual block time. A lot of blocks have the same timestamp. For example, 67 blocks from 788016 till 788083 have 1629392348 as a timestamp.

For example:

let giveMeBlock = await provider.getBlock(788016);

Will return

{
  ...
  number: 788016,
  timestamp: 1629392348,
  ...
}

And

let giveMeBlock = await provider.getBlock(788083);

Will return

{
  ...
  number: 788083,
  timestamp: 1629392348,
  ...
}

The same time in blocks, in some moment drives block time difference to 0, and after division by zero, the package has infinity as an argument and infinity recursion as a result.

I can add checking for division by zero (actually I have to add this 😀), and it will solve the infinity recursion problem. But the plugin may not work correctly anyway, because of the same block time in the "optimism" blockchain.

Here is more information about Block Numbers and Timestamps in Optimism blockchain:

https://community.optimism.io/docs/developers/l2/block-time.html

Hi,

I published version 1.4.1 of the plugin with a fix for the division by zero error. Please update your dependencies.

But, as I said, because of the "optimism" block time feature, my plugin may not work correctly with this blockchain.

I am closing the issue for now, please let me know if you need any help.

Hi @miguelmota,

Just published version 1.4.2 with a better solution. It should work better for your case. Please update and let me know if it works for you.

@monosux works great!! thanks for the quick fix! 🎉

Great! You are welcome!