RGB-WG / rgb-core

RGB Core Library: consensus validation for private & scalable client-validated smart contracts on Bitcoin & Lightning
https://spec.rgb.tech
Apache License 2.0
207 stars 52 forks source link

Preserve historic state for reorgs and unmined witness txes #166

Closed dr-orlovsky closed 1 year ago

dr-orlovsky commented 1 year ago

Fixes https://github.com/RGB-WG/rgb-wallet/pull/81#issuecomment-1625377294

In simple terms, we were removing previous state from the contract state data once we add a new state transition. However, this new state transition may not be yet final (its witness transaction is not mined), or may become invalid due to a blockchain re-org. Thus, I suggest to keep the historic state here (wallets do filter it anyway, so if it is assigned to a tx output which is already spent it will not be shown to the user).

Since the historic data will accumulate over the time, I plan to add an API to prune them with the wallet deciding which witness transactions are deep enough to safely remove the state.