poetapp / node

The core of Po.et
https://docs.poetnetwork.net/
MIT License
193 stars 27 forks source link

Blockchain Reader Fast and Slow #30

Open lautarodragan opened 6 years ago

lautarodragan commented 6 years ago

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

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.

kennylavender commented 5 years ago

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