poetapp / node

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

EthereumRegistryWriter: onCidAdded restart resiliency #954

Open lautarodragan opened 5 years ago

lautarodragan commented 5 years ago

Currently if EthereumRegistryWriter is restarted after an addCid transaction has been sent to geth but before the associated cidAdded event is picked up, that event will never be picked up, since EthereumRegistryWriter always starts listening to cidAdded events from the latest block geth has seen.

This can be solved by indexing onCidAdded.blockNumber in the db, pick up the highest onCidAdded.blockNumber on startup and passing that to fromBlock.

const fromBlock = await db. // some aggregate `sum` function or sort by and findOne
const onCidAddedPromievent = await ethereumRegistryContract.onCidAdded({ fromBlock }, handleEventError)

The chances of this happening are probably slim so not the highest priority at the moment.