talaia-labs / python-teos

The Eye of Satoshi - Lightning Watchtower
https://talaia.watch
MIT License
100 stars 15 forks source link

Handle reorgs while offline #32

Open sr-gi opened 5 years ago

sr-gi commented 5 years ago

Bootstrapping from backed up state may end up in the watcher/responder having to deal with reorgs that happened when they were offline.

In order to deal with this, we will store a list of last known blocks (e.g: 30-40 hashes) so we can find what's the last common block, backtrack, and get the new information.

The watcher should be able to run with no much trouble, if a reorg happens finding the last common and build from there should be enough to catch all the possible triggers, and invalid appointments (those that may have been included in an orphan branch) will eventually expire.

The responder is more complicated though. Some jobs may have a different confirmation counter (easy to deal with) whereas other may be valid no more. For the later case, we may need to add those back to the watcher so they are handled.

sr-gi commented 5 years ago

Comments on this would be appreciated @stonecoldpat @yahgwai @bigspider

sr-gi commented 5 years ago

For the record, the current approach to deal with bootstrapping from backed up data consist in simply find what blocks have the watcher and responder missed whilst offline, instantiate them with their old state, and hand them all the blocks so they can run as if they had just received all that info.

sr-gi commented 5 years ago

The main idea is to call find_last_common_block, rewind_states and get_missed_blocks and feed the rewinded_states and missed blocks to both the watcher and responder (load_prev_state)

https://github.com/sr-gi/pisa_btc/blob/0b43fdcfc157d070ad0970ca89d0ff7d1dbdad2e/pisa/tools.py#L61-L113

https://github.com/sr-gi/pisa_btc/blob/226cb61da86fd700d240dda8fe0b4b45aa53a504/pisa/watcher.py#L26-L52

sr-gi commented 5 years ago

I may separate this from 9-add-data-persistency and add it to a later release. Focusing on data persistency without forks for now.