cdk: transaction method to change a mint quote's unit, so dissolve is one transaction #40
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
vnprc/hashpool#40
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Give the mint a way to change a mint quote's currency unit inside a database transaction, so that dissolving a provisional epoch (re-stamp its never-paid quotes onto the previous epoch, pay them, mark the epoch dissolved) is one transaction instead of a raw SQL update followed by a second transaction with crash-recovery ordering.
Primary goals:
QuotesTransactionmethod (for exampleupdate_mint_quote_unit(quote_id, unit)on the lockedAcquired<MintQuote>) implemented incdk-sql-commonfor sqlite and postgres, carried on the forgevnprc/cdkbranch hashpool pins and offered upstream.restamp_quotesinroles/mint/src/lib/epoch/mod.rs, which opens a second pool on the mint's sqlite file and runsUPDATE mint_quote SET unit = …, is deleted once the method is available.Current state and specifics
On the reward-trigger branch (vnprc/hashpool#37) every other hashpool state change is written in the same cdk transaction as the cdk change it pairs with, through the mint database's key-value store. Dissolve is the exception because cdk exposes no way to change a quote's unit:
update_mint_quotepersists only new payments and issuances. hashpool therefore re-stamps with a direct statement throughcdk_sql_common::pool::Poolon the same file, with an affected-row-count check against the quotes counted under the lock, and then opens a cdk transaction to pay and flip. The two steps are ordered so a crash between them is recovered by a retry (the retry re-stamps zero rows and pays), which is correct but is exactly the kind of discipline a transaction makes unnecessary.Constraints the method must respect: only quotes with
amount_paid = 0 AND amount_issued = 0may change unit (a paid or issued quote is denominated in its unit for good), and the amount column is unit-less in storage so no conversion is needed. A guard in the method for that condition keeps the invariant in cdk rather than in the caller.Scope
In scope: the trait method, its sqlite and postgres implementations, a cdk test, the forge branch and the upstream pull request alongside cashubtc/cdk#2686, then the hashpool change that uses it and deletes
restamp_quotes. Out of scope: anything else about dissolve. The hashpool half depends on vnprc/hashpool#37 landing and on the cdk pin moving to a revision that carries the method.Part of vnprc/hashpool#13.