rust-lightning
rust-lightning copied to clipboard
[Memory] Persist `counterparty_claimable_outpoints` out of channel_monitor
Problem:
After every commitment signed, counterparty_claimable_outpoints keeps on growing without bounds within a channel_monitor, with a new hashmap entry for each commitment_tx.
It poses two problems mainly:
- Increased memory footprint, since all the active channel_monitors are stored in-memory.
- Increased channel_monitor on-disk size, where these are currently stored.
We don't want to keep on storing outpoints which will only be used for revoked_tx / funding_spend, instead we would like to store them in cold storage and read them only when required.
Ideal outcome: After doing this, Ldk's memory footprint should be drastically decreased owing to removed in-memory hashmap entries of counterparty_claimable_outpoints
- [x] Outline approach [Doc]
- [x] Minimize current set of non-current/previous_commitment reads to
counterparty_claimable_outpointsby re-using existing get calls and refactors [#3057 ] - [x] Remove watched_outputs dependency on per_commitment_claimable_data. (because if they depend on claimable_data, we won't outputs untill user provides us with ClaimInfo, and they won't be returned from tx_confirmed) [#3081]
- [ ] Introduce new event variants:
PersistClaimInfoandRequestClaimInfo[#3067] - [ ] Add pub fn in chain-monitor that can be called after both of those events. [#3217]
- [ ] Start publishing 2 new events, one in provide_secret and other in check_spend [#3106]
- [ ] In case when no htlcs have been forwarded, counterparty_claimable_outpoints will not have ClaimInfo. We don't want to treat missing ClaimInfo as acceptable, hence we need to write empty ClaimInfo so that user can always provide us with Some() ClaimInfo after ClaimInfoRequest.
- [x] Refactor
check_spend_counterparty_transactionandcancel_prev_commitment_claimsto act after we receiveClaimInfo - [x] Once funding_spent_seen and we receive
ClaimInfo, Re-insertClaimInfoincounterparty_claimable_outpoints, so thatget_claimable_balancescan account for it. (Done as part of handle events functions.)
Outlined approach in https://github.com/orgs/lightningdevkit/discussions/3050
++
- [x] Remove watched_outputs dependency on per_commitment_claimable_data. (because if they depend on claimable_data, we won't outputs untill user provides us with ClaimInfo, and they won't be returned from tx_confirmed)
- [x] In case when no htlcs have been forwarded,
counterparty_claimable_outpointswill not haveClaimInfo. We don't want to treat missingClaimInfoas acceptable, hence we need to write emptyClaimInfoso that user can always provide us with Some()ClaimInfoafterClaimInfoRequest.