Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

add extra guard to fail if trying to submit a too big transaction #4131

Merged
merged 2 commits into from
May 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions wallet/src/Cardano/Wallet/Kernel/Transactions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Control.Retry (RetryPolicyM, RetryStatus, applyPolicy,
import Crypto.Random (MonadRandom (..))
import qualified Data.ByteArray as ByteArray
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import Data.Default (def)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -67,6 +68,7 @@ import Cardano.Wallet.Kernel.Types (AccountId (..),
RawResolvedTx (..), WalletId (..))
import Cardano.Wallet.Kernel.Util.Core
import Cardano.Wallet.WalletLayer.Kernel.Conv (exceptT)
import Pos.Binary (serialize)
import Pos.Chain.Txp (Tx (..), TxAttributes, TxAux (..), TxId,
TxIn (..), TxInWitness (..), TxOut (..), TxOutAux (..),
TxSigData (..), Utxo)
Expand Down Expand Up @@ -173,19 +175,30 @@ pay activeWallet spendingPassword opts accountId payees = do
case res of
Left e -> return (Left $ PaymentNewTransactionError e)
Right (txAux, partialMeta, _utxo) -> do
succeeded <- newPending activeWallet accountId txAux partialMeta
case succeeded of
Left e -> do
-- If the next retry would bring us to the
-- end of our allowed retries, we fail with
-- a proper error
retriesLeft <- applyPolicy retryPolicy rs
return . Left $ case retriesLeft of
Nothing ->
PaymentSubmissionMaxAttemptsReached
Just _ ->
PaymentNewPendingError e
Right meta -> return $ Right (taTx $ txAux, meta)
let sz = fromIntegral $ BL.length $ serialize txAux
maxSz <- Node.getMaxTxSize (walletPassive activeWallet ^. walletNode)
if sz >= maxSz then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘Œ

return
. Left
. PaymentNewTransactionError
. NewTransactionErrorCoinSelectionFailed
. CoinSelHardErrMaxInputsReached
$ "Too many inputs were picked, resulting in a too big transaction.\
\ Transactions should be smaller than " <> show maxSz <> " bytes)."
else do
succeeded <- newPending activeWallet accountId txAux partialMeta
case succeeded of
Left e -> do
-- If the next retry would bring us to the
-- end of our allowed retries, we fail with
-- a proper error
retriesLeft <- applyPolicy retryPolicy rs
return . Left $ case retriesLeft of
Nothing ->
PaymentSubmissionMaxAttemptsReached
Just _ ->
PaymentNewPendingError e
Right meta -> return $ Right (taTx $ txAux, meta)

-- See <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter>
retryPolicy :: RetryPolicyM IO
Expand Down