babylonlabs-io / babylon-contract

CosmWasm smart contracts for Babylon integration
Other
10 stars 6 forks source link

optimisation: trim fork headers in BTC light client #2

Open maurolacy opened 3 months ago

maurolacy commented 3 months ago

@SebastianElvis cloned issue babylonchain/babylon-contract#14 on 2023-04-12:

          Given that we want this contract to be deployed on consumer zones we should try to be as optimized as possible.

_Originally posted by @vitsalis in https://www.github.com/babylonchain/babylon-contract/pull/13#discussion_r1163712316_

maurolacy commented 3 months ago

@KonradStaniec commented on 2023-04-12:

just one note here, the easiest way to trim forks is for our light client to store only main chain and remove headers when doing reorg, this way main schema does not need to change at all.

Algorithm becomes:

  1. receive newfork

  2. travel from current tip to common ancestor of newfork and current fork. While traveling to common ancestor register hashes and height of seen headers

  3. Check that newfork have better total difficulty than current fork

  4. if newfork is indeed better:

a. remove all seen headers and heights

b. store headers and heights of newfork

  1. if not, reject newfork.
maurolacy commented 3 months ago

@SebastianElvis commented on 2023-04-12:

That's a smart idea! This way we can trim forks while handling new headers in the IBC packet. Will implement.