monosux/ethereum-block-by-date

Calls to resolve blocks at hourly granularity return incorrect values.

Closed this issue · 4 comments

Just putting this out there so that people are aware of the issue.

If you use this library to fetch block numbers discretely (i.e. not in batch mode) starting right now and going back, say 10 hours, the returned results are incorrect. For example:

image

However, if you do that same experiment at day-level granularity, the results seem to be correct (or at least vary as you might expect):
image

Here's the snippet that generated these results:

  const DAYS = 90
  const HOUR_INTERVALS = 10 // DAYS * 24
  const ethDater = new EthDater(web3)

  for(let hourIdx = 1; hourIdx < HOUR_INTERVALS; hourIdx++) {
    // now is a Luxon DateTime instance:
    const date = now.minus({ days: hourIdx }).toISO()
    const ethDaterObj = await ethDater.getDate(new Date(date))
    hourlyBlocks.push({
      date: ethDaterObj.date,
      block: ethDaterObj.block
    })
  }

This problem also seems to happen when you call the library in batch mode:

image

From this snippet:

const HOUR_INTERVALS = 10 // DAYS * 24
const ethDater = new EthDater(web3)

const endDate = new Date(now.toISO())
const startDate = new Date(now.minus({ hours: HOUR_INTERVALS }).toISO())
const hourlyBlocks = await ethDater.getEvery('hours', startDate, endDate, 1)

 for (const hourlyBlock of hourlyBlocks) {
   log.debug(`date: ${hourlyBlock.date}, block: ${hourlyBlock.block}`)
  }

I suspected I might be passing in the incorrect date format, but my previous comments daily results seem to indicate that's not the problem.

Hi,

thank you for sharing it. I will take a look, and let you know.

Hi,

thank you for sharing it. I will take a look, and let you know.

Thanks for writing this btw--if you need more info let me know. I was using infura as my provider, here's the salient libraries:

"esm": "^3.2.25",
"ethereum-block-by-date": "^1.2.5",
"luxon": "^1.26.0",
"moment": "^2.29.1",
"web3": "^1.3.4"
"typescript": "^3.9.3"

node 10.16.0

Hi,

Thank you for your detailed report. I found and fixed the issue. I published a new version 1.2.6, please update your package.

Let me know if something keeps going wrong.