Skip to content

Commit

Permalink
Revert to using deprecated Shelley.evaluateTransactionFee call (#4511)
Browse files Browse the repository at this point in the history
This reverts the switch made in the recent node bump out of precaution,
as the behaviour of `estimateMinFeeTx` is different from that of
`evaluateTransactionFee`.

Task for later to properly address this: [ADP-3334 (Stop using
deprecated ledger function
`Shelley.evaluateTransactionFee`)](https://cardanofoundation.atlassian.net/browse/ADP-3334)

### Issue Number

ADP-3302, follow-up to
#4503
  • Loading branch information
Anviking authored Mar 27, 2024
2 parents c5747c0 + 84db1dd commit 8851da9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 74 deletions.
29 changes: 8 additions & 21 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

{-# OPTIONS_GHC -Wno-warnings-deprecations #-}
-- For 'Shelley.evaluateTransactionFee', see ADP-3334
-- https://cardanofoundation.atlassian.net/browse/ADP-3334

-- |
-- Copyright: © 2022 IOHK
-- License: Apache-2.0
Expand Down Expand Up @@ -170,7 +174,6 @@ import Cardano.Ledger.Alonzo.UTxO
)
import Cardano.Ledger.Api
( coinTxOutL
, estimateMinFeeTx
, ppKeyDepositL
)
import Cardano.Ledger.Api.UTxO
Expand Down Expand Up @@ -219,9 +222,6 @@ import Cardano.Ledger.Val
import Control.Arrow
( (>>>)
)
import Data.Bits
( Bits
)
import Data.ByteString
( ByteString
)
Expand Down Expand Up @@ -281,6 +281,7 @@ import qualified Cardano.Ledger.Credential as Core
import qualified Cardano.Ledger.Keys as Ledger
import qualified Cardano.Ledger.Mary.Value as Value
import qualified Cardano.Ledger.Plutus.Data as Alonzo
import qualified Cardano.Ledger.Shelley.API.Wallet as Shelley
import qualified Cardano.Ledger.Shelley.UTxO as Shelley
import qualified Cardano.Ledger.TxIn as Ledger
import qualified Cardano.Wallet.Primitive.Ledger.Convert as Convert
Expand Down Expand Up @@ -838,18 +839,12 @@ evaluateMinimumFee pp tx kwc =
KeyWitnessCounts {nKeyWits, nBootstrapWits} = kwc

mainFee :: Coin
mainFee =
estimateMinFeeTx pp tx
(unsafeIntCast nKeyWits)
accountForBootWitsElsewhere
mainFee = Shelley.evaluateTransactionFee pp tx nKeyWits
-- TODO [ADP-3334] Stop using deprecated ledger function
-- https://cardanofoundation.atlassian.net/browse/ADP-3334

FeePerByte feePerByte = getFeePerByte pp

-- 'estimateMinFeeTx' appears to assume byron/bootstrap wits contain no
-- address attributes or payload. For now, let's keep using our own
-- estimation.
accountForBootWitsElsewhere = 0

bootWitnessFee :: Coin
bootWitnessFee = Coin $ intCast $ feePerByte * byteCount
where
Expand All @@ -862,14 +857,6 @@ evaluateMinimumFee pp tx kwc =
sizeOf_BootstrapWitnesses 0 = 0
sizeOf_BootstrapWitnesses n = 4 + 180 * n

unsafeIntCast
:: (HasCallStack, Integral a, Integral b, Bits a, Bits b, Show a)
=> a
-> b
unsafeIntCast x = fromMaybe err $ intCastMaybe x
where
err = error $ "unsafeIntCast failed for " <> show x

-- | Evaluate the /balance/ of a transaction using the ledger.
--
-- The balance is defined as:
Expand Down
8 changes: 4 additions & 4 deletions lib/balance-tx/test/data/balanceTx/1ada-payment/golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
0.850000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 850000) (MultiAsset (fromList [])), required = MaryValue (Coin 1000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 150000) (MultiAsset (fromList []))})
0.900000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 900000) (MultiAsset (fromList [])), required = MaryValue (Coin 1000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 100000) (MultiAsset (fromList []))})
0.950000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 950000) (MultiAsset (fromList [])), required = MaryValue (Coin 1000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 50000) (MultiAsset (fromList []))})
1.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 169021, shortfall = Coin 169021})
1.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 169021, shortfall = Coin 119021})
1.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 169021, shortfall = Coin 69021})
1.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 169021, shortfall = Coin 19021})
1.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 168845, shortfall = Coin 168845})
1.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 168845, shortfall = Coin 118845})
1.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 168845, shortfall = Coin 68845})
1.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 168845, shortfall = Coin 18845})
1.200000,0.200000,0.163741
1.250000,0.250000,0.163741
1.300000,0.300000,0.163741
Expand Down
8 changes: 4 additions & 4 deletions lib/balance-tx/test/data/balanceTx/delegate/golden
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
1.850000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1850000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 150000) (MultiAsset (fromList []))})
1.900000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1900000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 100000) (MultiAsset (fromList []))})
1.950000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1950000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 50000) (MultiAsset (fromList []))})
2.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176633, shortfall = Coin 176633})
2.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176633, shortfall = Coin 126633})
2.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176633, shortfall = Coin 76633})
2.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176633, shortfall = Coin 26633})
2.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176457, shortfall = Coin 176457})
2.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176457, shortfall = Coin 126457})
2.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176457, shortfall = Coin 76457})
2.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 176457, shortfall = Coin 26457})
2.200000,0.200000,0.170957
2.250000,0.250000,0.170957
2.300000,0.300000,0.170957
Expand Down
8 changes: 4 additions & 4 deletions lib/balance-tx/test/data/balanceTx/pingPong_1/golden
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
1.850000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1850000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 150000) (MultiAsset (fromList []))})
1.900000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1900000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 100000) (MultiAsset (fromList []))})
1.950000,ErrBalanceTxAssetsInsufficient (ErrBalanceTxAssetsInsufficientError {available = MaryValue (Coin 1950000) (MultiAsset (fromList [])), required = MaryValue (Coin 2000000) (MultiAsset (fromList [])), shortfall = MaryValue (Coin 50000) (MultiAsset (fromList []))})
2.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170737, shortfall = Coin 170737})
2.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170737, shortfall = Coin 120737})
2.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170737, shortfall = Coin 70737})
2.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170737, shortfall = Coin 20737})
2.000000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170561, shortfall = Coin 170561})
2.050000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170561, shortfall = Coin 120561})
2.100000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170561, shortfall = Coin 70561})
2.150000,ErrBalanceTxUnableToCreateChange (ErrBalanceTxUnableToCreateChangeError {requiredCost = Coin 170561, shortfall = Coin 20561})
2.200000,0.200000,0.166997
2.250000,0.250000,0.166997
2.300000,0.300000,0.166997
Expand Down
Loading

0 comments on commit 8851da9

Please sign in to comment.