-
Notifications
You must be signed in to change notification settings - Fork 58
fix(platform-wallet-storage): durably apply swept transactions in the SQLite store #4559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
romchornyi
wants to merge
2
commits into
split/4406-1-seam
Choose a base branch
from
split/4406-2-storage
base: split/4406-1-seam
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/rs-platform-wallet-storage/migrations/V007__utxo_sweep_winner_height.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Anchor sweep tombstones at their winner's mined height and pin the | ||
| //! chainlock finality boundary. | ||
| //! | ||
| //! `core_utxos.winner_mined_height` is the mined height of the | ||
| //! transaction that beat an unmaterialised sweep tombstone's outpoint — | ||
| //! the placeholder row `apply_sweep` writes for a held input whose | ||
| //! funding output has never classified (`height IS NULL AND spent = 1`; | ||
| //! no other writer leaves `height` NULL). The height is carried on the | ||
| //! sweep event itself (`TransactionsSwept::winner_mined_height`), and | ||
| //! `apply_sweep` writes the placeholder for EVERY non-released held | ||
| //! input in EVERY sweep context — only the stamp differs. A | ||
| //! block-context sweep (winner actually mined) stamps the winner's | ||
| //! height, and the collector in `core_state::apply` evicts the row | ||
| //! exactly when `min(chainlock_height, synced_height)` reaches that | ||
| //! height — `prune_finalized_observed_spends`' condition verbatim, with | ||
| //! no observation-age margin. An InstantSend-locked, unmined winner | ||
| //! writes the same row with the stamp NULL — under DIP-10 its lock | ||
| //! alone settles the input, but it carries no height to key a lifetime | ||
| //! on — and the collector never takes an unstamped row: it resolves | ||
| //! only through proof, when the funding upsert materialises it, a later | ||
| //! block-context sweep re-stamps it into the collectible set, or a | ||
| //! release deletes it. See `CORE_SWEEP_REMOVAL` and the `apply_sweep` | ||
| //! doc in `core_state.rs` for why an unstamped hold must survive (it is | ||
| //! the only durable carrier of upstream's in-memory `spent_outpoints` | ||
| //! hold across a restart) and what bounds the foreign-input residue. | ||
| //! | ||
| //! `core_sync_state.chainlock_height` is the monotonic-max height of | ||
| //! the last applied chainlock, mirrored from | ||
| //! `CoreChangeSet::last_applied_chain_lock` (previously dropped by | ||
| //! this store). It is one half of the collector's finality boundary; | ||
| //! rows are never collected before a chainlock has been persisted, | ||
| //! matching upstream's "no-op until a chainlock has been applied". | ||
| //! | ||
| //! The partial index covers exactly the unmaterialised rows — the | ||
| //! collector's scan set is the stamped subset of these — so the | ||
| //! per-round sweep touches tombstones only, not the wallet's full | ||
| //! spent history. | ||
| //! | ||
| //! Edited in place (formerly `V006__utxo_tombstone_stamp`, column | ||
| //! `held_since_height`) under the same pre-release policy V001's test | ||
| //! documents: nothing shipped has applied this migration, and a dev | ||
| //! database that did apply the old shape fails refinery's divergence | ||
| //! check and must be recreated. Renumbered `V006` → `V007` when the | ||
| //! mainline's `V006__tracked_masternodes` merged in ahead of this | ||
| //! unmerged branch: version numbers, like capability bits, are | ||
| //! append-only and the already-merged assignment keeps its slot. | ||
|
|
||
| pub fn migration() -> String { | ||
| "ALTER TABLE core_utxos ADD COLUMN winner_mined_height INTEGER; | ||
| ALTER TABLE core_sync_state ADD COLUMN chainlock_height INTEGER; | ||
| CREATE INDEX idx_core_utxos_unmaterialized | ||
| ON core_utxos(wallet_id, winner_mined_height) | ||
| WHERE height IS NULL;" | ||
| .to_string() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.