-
Notifications
You must be signed in to change notification settings - Fork 217
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
Database changes for resubmission of pending transactions #2570
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d47615c
swagger.yaml: Add note about external tx retrying
rvl 9980bcd
Add LocalTxSubmissionStatus type
rvl cf37cac
DBLayer for pending LocalTxSubmissions
rvl d14f87b
Rearrange specs in SqliteSpec
rvl 13d9dc0
Rework DBLayer - model DB functions
rvl 96a9d96
Sqlite: Add foreign key constraint from local_tx_submission to tx_meta
rvl 0e9623f
DBLayer: Handle case where PutLocalTxSubmission txId does not exist
rvl 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 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 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 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 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 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 |
---|---|---|
|
@@ -22,7 +22,9 @@ import Cardano.Address.Derivation | |
( XPrv ) | ||
import Cardano.Wallet.DB | ||
( DBLayer (..) | ||
, ErrNoSuchTransaction (..) | ||
, ErrNoSuchWallet (..) | ||
, ErrPutLocalTxSubmission (..) | ||
, ErrRemoveTx (..) | ||
, ErrWalletAlreadyExists (..) | ||
, PrimaryKey (..) | ||
|
@@ -40,12 +42,14 @@ import Cardano.Wallet.DB.Model | |
, mPutCheckpoint | ||
, mPutDelegationCertificate | ||
, mPutDelegationRewardBalance | ||
, mPutLocalTxSubmission | ||
, mPutPrivateKey | ||
, mPutTxHistory | ||
, mPutWalletMeta | ||
, mReadCheckpoint | ||
, mReadDelegationRewardBalance | ||
, mReadGenesisParameters | ||
, mReadLocalTxSubmissionPending | ||
, mReadPrivateKey | ||
, mReadTxHistory | ||
, mReadWalletMeta | ||
|
@@ -65,7 +69,7 @@ import Cardano.Wallet.Primitive.Types.Hash | |
import Cardano.Wallet.Primitive.Types.Tx | ||
( TransactionInfo (..) ) | ||
import Control.DeepSeq | ||
( NFData, deepseq ) | ||
( NFData, force ) | ||
import Control.Monad.Trans.Except | ||
( ExceptT (..) ) | ||
import Data.Functor.Identity | ||
|
@@ -90,9 +94,9 @@ newDBLayer timeInterpreter = do | |
Wallets | ||
-----------------------------------------------------------------------} | ||
|
||
{ initializeWallet = \pk cp meta txs gp -> ExceptT $ do | ||
cp `deepseq` meta `deepseq` | ||
alterDB errWalletAlreadyExists db (mInitializeWallet pk cp meta txs gp) | ||
{ initializeWallet = \pk cp meta txs gp -> ExceptT $ | ||
alterDB errWalletAlreadyExists db $ | ||
mInitializeWallet pk cp meta txs gp | ||
|
||
, removeWallet = ExceptT . alterDB errNoSuchWallet db . mRemoveWallet | ||
|
||
|
@@ -102,30 +106,33 @@ newDBLayer timeInterpreter = do | |
Checkpoints | ||
-----------------------------------------------------------------------} | ||
|
||
, putCheckpoint = \pk cp -> ExceptT $ do | ||
cp `deepseq` alterDB errNoSuchWallet db (mPutCheckpoint pk cp) | ||
, putCheckpoint = \pk cp -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mPutCheckpoint pk cp | ||
|
||
, readCheckpoint = readDB db . mReadCheckpoint | ||
|
||
, listCheckpoints = readDB db . mListCheckpoints | ||
|
||
, rollbackTo = \pk pt -> ExceptT $ | ||
alterDB errNoSuchWallet db (mRollbackTo pk pt) | ||
alterDB errNoSuchWallet db $ | ||
mRollbackTo pk pt | ||
|
||
, prune = \_ _ -> error "MVar.prune: not implemented" | ||
|
||
{----------------------------------------------------------------------- | ||
Wallet Metadata | ||
-----------------------------------------------------------------------} | ||
|
||
, putWalletMeta = \pk meta -> ExceptT $ do | ||
meta `deepseq` alterDB errNoSuchWallet db (mPutWalletMeta pk meta) | ||
, putWalletMeta = \pk meta -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mPutWalletMeta pk meta | ||
|
||
, readWalletMeta = readDB db . mReadWalletMeta timeInterpreter | ||
|
||
, putDelegationCertificate = \pk cert sl -> ExceptT $ do | ||
cert `deepseq` sl `deepseq` | ||
alterDB errNoSuchWallet db (mPutDelegationCertificate pk cert sl) | ||
, putDelegationCertificate = \pk cert sl -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mPutDelegationCertificate pk cert sl | ||
|
||
, isStakeKeyRegistered = | ||
ExceptT . alterDB errNoSuchWallet db . mIsStakeKeyRegistered | ||
|
@@ -134,8 +141,9 @@ newDBLayer timeInterpreter = do | |
Tx History | ||
-----------------------------------------------------------------------} | ||
|
||
, putTxHistory = \pk txh -> ExceptT $ do | ||
txh `deepseq` alterDB errNoSuchWallet db (mPutTxHistory pk txh) | ||
, putTxHistory = \pk txh -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mPutTxHistory pk txh | ||
|
||
, readTxHistory = \pk minWithdrawal order range mstatus -> | ||
readDB db $ | ||
|
@@ -147,6 +155,7 @@ newDBLayer timeInterpreter = do | |
range | ||
mstatus | ||
|
||
-- TODO: shift implementation to mGetTx | ||
, getTx = \pk tid -> ExceptT $ | ||
alterDB errNoSuchWallet db (mCheckWallet pk) >>= \case | ||
Left err -> pure $ Left err | ||
|
@@ -168,20 +177,30 @@ newDBLayer timeInterpreter = do | |
Keystore | ||
-----------------------------------------------------------------------} | ||
|
||
, putPrivateKey = \pk prv -> ExceptT $ do | ||
prv `deepseq` alterDB errNoSuchWallet db (mPutPrivateKey pk prv) | ||
, putPrivateKey = \pk prv -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mPutPrivateKey pk prv | ||
|
||
, readPrivateKey = readDB db . mReadPrivateKey | ||
|
||
{----------------------------------------------------------------------- | ||
Pending Tx | ||
-----------------------------------------------------------------------} | ||
|
||
, updatePendingTxForExpiry = \pk tip -> ExceptT $ do | ||
alterDB errNoSuchWallet db (mUpdatePendingTxForExpiry pk tip) | ||
, putLocalTxSubmission = \pk txid tx sl -> ExceptT $ | ||
alterDB (fmap ErrPutLocalTxSubmissionNoSuchWallet . errNoSuchWallet) db $ | ||
mPutLocalTxSubmission pk txid tx sl | ||
|
||
, removePendingOrExpiredTx = \pk tid -> ExceptT $ do | ||
alterDB errCannotRemovePendingTx db (mRemovePendingOrExpiredTx pk tid) | ||
, readLocalTxSubmissionPending = | ||
readDB db . mReadLocalTxSubmissionPending | ||
|
||
, updatePendingTxForExpiry = \pk tip -> ExceptT $ | ||
alterDB errNoSuchWallet db $ | ||
mUpdatePendingTxForExpiry pk tip | ||
|
||
, removePendingOrExpiredTx = \pk tid -> ExceptT $ | ||
alterDB errCannotRemovePendingTx db $ | ||
mRemovePendingOrExpiredTx pk tid | ||
|
||
{----------------------------------------------------------------------- | ||
Protocol Parameters | ||
|
@@ -208,7 +227,8 @@ newDBLayer timeInterpreter = do | |
|
||
-- | Apply an operation to the model database, then update the mutable variable. | ||
alterDB | ||
:: (Err (PrimaryKey WalletId) -> Maybe err) | ||
:: (NFData s, NFData xprv) | ||
=> (Err (PrimaryKey WalletId) -> Maybe err) | ||
-- ^ Error type converter | ||
-> MVar (Database (PrimaryKey WalletId) s xprv) | ||
-- ^ The database variable | ||
|
@@ -218,14 +238,15 @@ alterDB | |
alterDB convertErr db op = modifyMVar db (bubble . op) | ||
where | ||
bubble (Left e, db') = case convertErr e of | ||
Just e' -> pure (db', Left e') | ||
Just e' -> pure (force db', Left e') | ||
Nothing -> throwIO $ MVarDBError e | ||
bubble (Right a, db') = pure (db', Right a) | ||
bubble (Right a, db') = pure (force db', Right a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
-- | Run a query operation on the model database. Any error results are turned | ||
-- into a runtime exception. | ||
readDB | ||
:: MVar (Database (PrimaryKey WalletId) s xprv) | ||
:: (NFData s, NFData xprv) | ||
=> MVar (Database (PrimaryKey WalletId) s xprv) | ||
-- ^ The database variable | ||
-> ModelOp (PrimaryKey WalletId) s xprv a | ||
-- ^ Operation to run on the database | ||
|
@@ -239,8 +260,8 @@ errNoSuchWallet _ = Nothing | |
errCannotRemovePendingTx :: Err (PrimaryKey WalletId) -> Maybe ErrRemoveTx | ||
errCannotRemovePendingTx (NoSuchWallet (PrimaryKey wid)) = | ||
Just (ErrRemoveTxNoSuchWallet (ErrNoSuchWallet wid)) | ||
errCannotRemovePendingTx (NoSuchTx _ tid) = | ||
Just (ErrRemoveTxNoSuchTransaction tid) | ||
errCannotRemovePendingTx (NoSuchTx (PrimaryKey wid) tid) = | ||
Just (ErrRemoveTxNoSuchTransaction (ErrNoSuchTransaction wid tid)) | ||
errCannotRemovePendingTx (CantRemoveTxInLedger _ tid) = | ||
Just (ErrRemoveTxAlreadyInLedger tid) | ||
errCannotRemovePendingTx _ = Nothing | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side-note: I am not sure this
PrimaryKey
type is any useful nowadays. Not the point of this PR, but we could perhaps leave a TODO / FIXME note about removing this altogether, it just creates noise in many places.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes - that's what I thought too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll sort this in the next PR.