lightningdevkit / rust-lightning

A highly modular Bitcoin Lightning library written in Rust. It's rust-lightning, not Rusty's Lightning!
Other
1.16k stars 364 forks source link

Support during-sync operation #800

Open TheBlueMatt opened 3 years ago

TheBlueMatt commented 3 years ago

We should have a mode where a ChannelManager will only take "safe" actions which can occur while the chain is being synchronized in the background (ie we are guaranteed that we are behind the current tip, but will be in sync soon). When we do this we should also support syncing only to common tip(s) in the block-sync crate, see https://github.com/rust-bitcoin/rust-lightning/pull/791#discussion_r576364349.

ariard commented 3 years ago

I think the following actions can be labeld as "safe":

Balance-increasing or closing are unsafe as a state less favorable to us might have been already committed onchain.

In theory we could make those "dangerous" operations valid if we lower our trust model by relying on some headers-verified at-tip assumevalid-UTXO, once those are available on the base layer. If you don't care about verifying gossips traffic and assuming you don't have channel close, you might bypass completely sync for mobile. The hard challenge is conserving privacy of your utxos towards semi-trusted assumevalid/BIP157 servers...

TheBlueMatt commented 3 years ago

Jeff notes in the above references in 808 that we should try to enforce this via an API refactor if possible, eg wrapping ChannelManager in a ChannelManagerSyncing object during deserialization and only allowing access to a subset of the API until the user informs us they're done.