node icon indicating copy to clipboard operation
node copied to clipboard

Blockchain Reader Fast and Slow

Open lautarodragan opened this issue 7 years ago • 1 comments

Blockchain Reader polls Insight for blocks periodically, running every X seconds.

As long as X is less than the average time new blocks take to generate in the blockchain, Po.et Node will be always up to date.

This approach works well when Po.et Node is already up to date, but if it is started thousands of blocks behind the tip, it'll take forever to catch up.

In this special case, we need Blockchain Reader to poll for blocks much, much faster. We can do this by

  • highestBlock = (await GET https://test-insight.bitpay.com/api/status?q=getInfo).blocks
  • If (highestBlock - ourCurrentBlockHeight > N)
  • cron.stop
  • fastMethod.start

This "fastMethod" would run scanBlock(index) just like the cron, keeping track of the index and increasing it constantly, but instead of running every X amount of time, it'd run new requests as soon as the previous one is finished. It should also run several requests in parallel, since most of the function time is spent on awaits, running up to N requests in parallel.

lautarodragan avatar Dec 05 '17 20:12 lautarodragan

Update: we are no longer using insight api, but we can still get the block count with bitcoin-core using the getblockchaininfo command

kennylavender avatar Nov 28 '18 00:11 kennylavender