From 999890b4c8a98e32205e52973b250b339b0692ca Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 14 Jul 2022 03:13:39 +0000 Subject: [PATCH 1/5] Remove `partial-type-signatures` flag from `Shelley.Compatibility`. This appears to no longer be necessary, as the Cardano API now exports the `BabbageEra` identifier, and we no longer use any partial type signatures in this module. --- lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs index ff34e90bce0..d0c3c38e2a0 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs @@ -24,9 +24,6 @@ -- Jörmungandr dual support. {-# OPTIONS_GHC -fno-warn-orphans #-} --- We have to use it until 'BabbageEra' appears in 'Cardano.Api'. -{-# OPTIONS_GHC -Wno-partial-type-signatures #-} - -- | -- Copyright: © 2020 IOHK -- License: Apache-2.0 From f8d3217fbb3205671a7453971aa57b194cfb4ffc Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 14 Jul 2022 02:39:07 +0000 Subject: [PATCH 2/5] [FAIL] Re-enable Babbage-era minimum UTxO golden tests. Note that these tests currently fail, so we have marked this commit with the [FAIL] tag. Subsequent commits will also be marked with [FAIL] until the whole test suite passes. The first commit that causes the whole test suite to pass will be marked with [PASS]. Test failures are of the following form: ``` lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs:496:9: 1) computeMinimumCoinForUTxO, Golden Tests, goldenTests_computeMinimumCoinForUTxO Babbage, golden test #0 Falsified (after 1 test): resultExpected: Coin 995610 resultReturned: Coin 1077500 Condition violated: resultReturned == resultExpected To rerun use: --match "/computeMinimumCoinForUTxO/Golden Tests/goldenTests_computeMinimumCoinForUTxO Babbage/golden test #0/" ... ``` --- .../Cardano/Wallet/Shelley/MinimumUTxOSpec.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs index 5823949b8ef..6a2aa90c9a5 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs @@ -134,11 +134,9 @@ spec = do goldenTests_computeMinimumCoinForUTxO "Alonzo" goldenMinimumUTxO_Alonzo goldenMinimumCoins_Alonzo - - -- FIXME [ADP-1978] Re-enable - --goldenTests_computeMinimumCoinForUTxO "Babbage" - -- goldenMinimumUTxO_Babbage - -- goldenMinimumCoins_Babbage + goldenTests_computeMinimumCoinForUTxO "Babbage" + goldenMinimumUTxO_Babbage + goldenMinimumCoins_Babbage -- Check that it's possible to evaluate 'computeMinimumCoinForUTxO' without -- any run-time error. @@ -346,9 +344,8 @@ goldenMinimumUTxO_Alonzo = minimumUTxOForShelleyBasedEra ShelleyBasedEraAlonzo def {Alonzo._coinsPerUTxOWord = testParameter_coinsPerUTxOWord_Alonzo} --- FIXME [ADP-1978] Re-enable -_goldenMinimumUTxO_Babbage :: MinimumUTxO -_goldenMinimumUTxO_Babbage = +goldenMinimumUTxO_Babbage :: MinimumUTxO +goldenMinimumUTxO_Babbage = minimumUTxOForShelleyBasedEra ShelleyBasedEraBabbage def {Babbage._coinsPerUTxOByte = testParameter_coinsPerUTxOByte_Babbage} @@ -392,9 +389,8 @@ goldenMinimumCoins_Alonzo = , (goldenTokenMap_4, Coin 1_862_028) ] --- FIXME [ADP-1978] Re-enable -_goldenMinimumCoins_Babbage :: [(TokenMap, Coin)] -_goldenMinimumCoins_Babbage = +goldenMinimumCoins_Babbage :: [(TokenMap, Coin)] +goldenMinimumCoins_Babbage = [ (goldenTokenMap_0, Coin 995_610) , (goldenTokenMap_1, Coin 1_150_770) , (goldenTokenMap_2, Coin 1_323_170) From 7baf98b808300b17af1f7a793fc6c76c982d0b94 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 14 Jul 2022 02:46:25 +0000 Subject: [PATCH 3/5] [FAIL] Use Babbage-era minimum UTxO calculation in Babbage era. We re-introduce the Babbage-era minimum UTxO calculation in the Babbage era, and remove the workaround. This causes multiple integration tests to fail with `utxo_too_small`. For example: ```hs API Specifications, SHELLEY_TRANSACTIONS, TRANSMETA_ESTIMATE_01b - fee estimation includes no-schema metadata expected a successful response but got an error: ClientError (Object (fromList [("code",String "utxo_too_small"),("message",String "Some outputs have ada values that are too small. There's a minimum ada value specified by the protocol that each output must satisfy. I'll handle that minimum value myself when you do not explicitly specify an ada value for an output. Otherwise, you must specify enough ada. Here are the problematic outputs: - Expected min coin value: 1.077500 Address: 010d62b5...3a953592 Token bundle: coin: 0.999920 tokens: [] ")])) While verifying value: ( Status { statusCode = 403 , statusMessage = "Forbidden" } , Left ( ClientError ( Object ( fromList [ ( "code" , String "utxo_too_small" ) , ( "message" , String "Some outputs have ada values that are too small. There's a minimum ada value specified by the protocol that each output must satisfy. I'll handle that minimum value myself when you do not explicitly specify an ada value for an output. Otherwise, you must specify enough ada. Here are the problematic outputs: - Expected min coin value: 1.077500 Address: 010d62b5...3a953592 Token bundle: coin: 0.999920 tokens: [] " ) ] ) ) ) ) ``` --- .../Cardano/Wallet/Shelley/Compatibility.hs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs index d0c3c38e2a0..3afea0ccdf3 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs @@ -277,8 +277,6 @@ import Data.ByteString.Short ( fromShort, toShort ) import Data.Coerce ( coerce ) -import Data.Default - ( Default (..) ) import Data.Foldable ( toList ) import Data.Function @@ -915,19 +913,7 @@ fromBabbagePParams eraInfo currentNodeProtocolParameters pp = , desiredNumberOfStakePools = desiredNumberOfStakePoolsFromPParams pp , minimumUTxO = - -- FIXME [ADP-1978] need to fix for final Babbage support ⚠️ - -- - -- We unexpectedly needed to increase @maxLengthAddress@ causing - -- tests to break in Babbage. Using the Alonzo calculation even in - -- Babbage is correct enough to make the integration tests to pass - -- in Babbage, and for us to be able to merge the Babbage - -- integration cluster support to master. This is not waterproof - -- though, and we should definitely use the babbage-specific - -- calculation. - minimumUTxOForShelleyBasedEra ShelleyBasedEraAlonzo $ - def { Alonzo._coinsPerUTxOWord = - multiplyCoinBy 8 $ Babbage._coinsPerUTxOByte pp - } + minimumUTxOForShelleyBasedEra ShelleyBasedEraBabbage pp , stakeKeyDeposit = stakeKeyDepositFromPParams pp , eras = fromBoundToEpochNo <$> eraInfo , maximumCollateralInputCount = unsafeIntToWord $ @@ -938,8 +924,6 @@ fromBabbagePParams eraInfo currentNodeProtocolParameters pp = Just $ executionUnitPricesFromPParams pp , currentNodeProtocolParameters } - where - multiplyCoinBy a (SL.Coin c) = SL.Coin (a * c) -- | Extract the current network decentralization level from the given set of -- protocol parameters. From c285d77cd2575f1f9676815261e36b61317d0e06 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Thu, 14 Jul 2022 19:47:17 +0200 Subject: [PATCH 4/5] Use even longer maxLengthAddress --- .../src/Test/Integration/Framework/DSL.hs | 3 +- .../src/Cardano/Wallet/Shelley/MinimumUTxO.hs | 43 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Framework/DSL.hs b/lib/core-integration/src/Test/Integration/Framework/DSL.hs index 8f3d3f0e9f0..f71ea44a032 100644 --- a/lib/core-integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/core-integration/src/Test/Integration/Framework/DSL.hs @@ -674,7 +674,8 @@ walletId = -- | Min UTxO parameter for the test cluster. minUTxOValue :: ApiEra -> Natural minUTxOValue e - | e >= ApiBabbage = 999_920 + | e >= ApiBabbage = 1_107_670 -- needs to be overestimated for the sake of + -- long byron addresses | e >= ApiAlonzo = 999_978 -- From 34482 lovelace per word | otherwise = 1_000_000 diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/MinimumUTxO.hs b/lib/shelley/src/Cardano/Wallet/Shelley/MinimumUTxO.hs index d911f90a3da..1dfe981f197 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/MinimumUTxO.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/MinimumUTxO.hs @@ -18,10 +18,10 @@ module Cardano.Wallet.Shelley.MinimumUTxO import Prelude -import Cardano.Wallet.Api.Types - ( DecodeAddress (..) ) -import Cardano.Wallet.Primitive.AddressDerivation - ( NetworkDiscriminant (..) ) +import Cardano.Wallet.Primitive.Passphrase + ( Passphrase (..) ) +import Cardano.Wallet.Primitive.Types + ( ProtocolMagic (..) ) import Cardano.Wallet.Primitive.Types.Address ( Address (..) ) import Cardano.Wallet.Primitive.Types.Coin @@ -48,6 +48,11 @@ import Numeric.Natural ( Natural ) import qualified Cardano.Api.Shelley as Cardano +import qualified Cardano.Byron.Codec.Cbor as Byron +import qualified Cardano.Crypto.Wallet as CC +import qualified Codec.CBOR.Write as CBOR +import qualified Data.ByteArray as BA +import qualified Data.ByteString as BS -- | Computes a minimum 'Coin' value for a 'TokenMap' that is destined for -- inclusion in a transaction output. @@ -145,17 +150,29 @@ embedTokenMapWithinPaddedTxOut era m = -- for inclusion in a transaction output. -- maxLengthAddress :: Address -maxLengthAddress = largeByronAddress +maxLengthAddress = longestByronAddrGeneratedByWallet where - -- FIXME: It's imperative to return the largest possible address, which is a - -- byron address. The following is /a/ large one, but not necessarily /the - -- largest/: - largeByronAddress :: Address - largeByronAddress = unsafeDecodeAddr - "DdzFFzCqrht74rkP7eNhMp9iaQ79JQZzHX6QxjoFoie4qAn5D2MESx3Rzpqtc9zX6ASEdDT\ - \hwJyqjc2kjqHMFnoUnC79GmmNCB9Vfe6a" + -- This should be the longest possible address the wallet can generate, + -- with a length of 86 bytes. (We can look at the callsites to encodeAddress + -- to confirm) + -- + -- With 4310 lovelace/byte, the minimum utxo value for a pure-ada output is + -- now 1.107670 ada (according to /v2/network/information). The largest + -- possible overestimation should be (86-29) bytes, or 0.245670 ada. + longestByronAddrGeneratedByWallet = Address + $ CBOR.toStrictByteString + $ Byron.encodeAddress xpub + [ Byron.encodeDerivationPathAttr pwd maxBound maxBound + , Byron.encodeProtocolMagicAttr (ProtocolMagic maxBound) + ] where - unsafeDecodeAddr = either (error . show) id . decodeAddress @'Mainnet + -- Must apparently always be 32 bytes + pwd :: Passphrase "addr-derivation-payload" + pwd = Passphrase $ BA.convert $ BS.replicate 32 0 + + xpub = CC.toXPub $ CC.generate (BS.replicate 32 0) xprvPass + where + xprvPass = mempty :: BS.ByteString -- | A 'Coin' value that is maximal in length when serialized to bytes. -- From 48ba4c429971190d2e09553f3e8cdebbed4e573d Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Thu, 14 Jul 2022 19:47:43 +0200 Subject: [PATCH 5/5] Adjust failing TRANS_NEW_JOIN_02 --- .../Test/Integration/Scenario/API/Shelley/TransactionsNew.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs index 62da40a1868..e217baf18fa 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs @@ -2697,7 +2697,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do it "TRANS_NEW_JOIN_02 - Can join stakepool in case I have many UTxOs on 1 address" $ \ctx -> runResourceT $ do - let amt = 1_000_000 + let amt = minUTxOValue (_mainEra ctx) src <- emptyWallet ctx wa <- fixtureWallet ctx