talaia-labs / rust-teos

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

Adds --forceupdate to teosd #216

Closed sr-gi closed 1 year ago

sr-gi commented 1 year ago

If a tower hasn't been running for a long time and the backend runs in pruned mode it could be the case that by the time the tower comes back online, the Last known block by the tower is not being known by the node anymore. In this situation, the tower cannot bootstrap normally, given the cache cannot be populated.

This commits adds a new argument to teosd (--forceupdate) that can be used to force a tower to update its last known block to the earliest known block by the backend under this situation. Notice that doing so may make the tower miss some of its state transitions (the ones triggered by missed blocks), so this must be done as a last resource.

Fixes #209 Supersedes #212

Testing

This can be tested easily in regtest by running bitcoind with the (hidden, undocumented) -fastprune modifier. That would make blocks smaller and easier to prune. After that, you can prune the chain using bitcoin-cli pruneblockchain x where x is your target prune height. The pruning is not likely to happen to the exact block you specified, given block files are pruned as a whole, so the chain would be pruned to the closest value that allows a bock file to be deleted.

So the flow of testing should be:

  1. Start teosd and mine a few blocks so there is a last_known_block known by the tower
  2. Shut down the tower
  3. Mine a few thousand more blocks
  4. Call bitcoin-cli pruneblockchain x and checked the returned y value
  5. If y - IRREVOCABLY_RESOLVED < last_known_block_height, continue, otherwise go back to 3.
  6. Run teosd again and test it with and without --forceupdate
sr-gi commented 1 year ago

I've tested this manually and it seems to run just fine.

In order to test this you'd need a tower that has a last known block at height n and a node with a chain that has pruned that same block. I haven't been able to test this on regtest given pruning is based on how much block data we are holding (not how many blocks) and regtest blocks are mainly empty, so the threshold is never met. However, I've been able to test this using mainnet and an old tower state.

I may add some E2E testing for this if I manage to create a test where full blocks are created, so eviction can be triggered.

sr-gi commented 1 year ago

I'm confused about what the chain_monitor would do given it's being passed an old/pruned tip. Is poll_best_tip() gonna just skip the pruned blocks between tip and the best tip?

Yeah, you're right. I've come up with a better solution than this, will force push asap

sr-gi commented 1 year ago

This should make more sense now

sr-gi commented 1 year ago

I fixed suggestions and updated some of the logs since I didn't like them much.

I've also updated the PR description with guidelines for how to test this in regtest.

sr-gi commented 1 year ago

Nits should be fixed. I'd be nice to get a tACK

mariocynicys commented 1 year ago

Nits should be fixed. I'd be nice to get a tACK

Yeah will work on that tonight.

sr-gi commented 1 year ago

Addressed comments