Skip to content

Commit

Permalink
wip: progress
Browse files Browse the repository at this point in the history
    WALLETS_COIN_SELECTION_06a - can redeem rewards from self [MIR] [?] (161379ms)
    WALLETS_COIN_SELECTION_06b - can redeem rewards from other [MIR] [?] (163575ms)
  SHELLEY_MIGRATIONS
    SHELLEY_CREATE_MIGRATION_PLAN_06 - Can create a migration plan for a wallet that has rewards. [MIR] [                                                                                                               SHELLEY_CREATE_MIGRATION_PLAN_06 - Can create a migration plan for a wallet that has rewards. [MIR] [?] (161335ms)
    SHELLEY_MIGRATE_09 - Can migrate a wallet that has rewards. [MIR] [?] (161334ms)
  SHELLEY_TRANSACTIONS
    TRANS_ESTIMATE_03b - we see result when we can't cover fee (with withdrawal) [MIR] [?] (108922ms)
      # PENDING: This now triggers a new error on the backend side which is harder to catch without much logic changes. Since we are about to do a complete revision of the way transaction are constructed, which will result in the removal of the fee estimation altogether, I won't bother fixing this particular test case which is pretty minor / edge-case.
    SHELLEY_TX_REDEEM_01 - Can redeem rewards from self [MIR] [?] (163027ms)
    SHELLEY_TX_REDEEM_02 - Can redeem rewards from other [MIR] [?] (163692ms)
    SHELLEY_TX_REDEEM_03 - Can't redeem rewards from other if none left [MIR] [?] (163970ms)
    SHELLEY_TX_REDEEM_06a - Can't redeem rewards if utxo = 0 from other [MIR] [?] (52868ms)
    SHELLEY_TX_REDEEM_06b - Can't redeem rewards if utxo = 0 from self [MIR] [?] (2ms)
      # PENDING: Migration endpoints temporarily disabled
    SHELLEY_TX_REDEEM_07a - Can't redeem rewards if cannot cover fee [MIR] [ ]certificateFromDelegationAction: not supported in Conway yet
CallStack (from HasCallStack):
  error, called at src/Cardano/Wallet/Transaction/Delegation.hs:88:5 in cardano-wallet-2023.12.18-inplace:Cardano.Wallet.Transaction.Delegation
certificateFromDelegationAction: not supported in Conway yet
CallStack (from HasCallStack):
  error, called at src/Cardano/Wallet/Transaction/Delegation.hs:88:5 in cardano-wallet-2023.12.18-inplace:Cardano.Wallet.Transaction.Delegation
certificateFromDelegationAction: not supported in Conway yet
CallStack (from HasCallStack):
  error, called at src/Cardano/Wallet/Transaction/Delegation.hs:88:5 in cardano-wallet-2023.12.18-inplace:Cardano.Wallet.Transaction.Delegation
certificateFromDelegationAction: not supported in Conway yet
CallStack (from HasCallStack):
  error, called at src/Cardano/Wallet/Transaction/Delegation.hs:88:5 in cardano-wallet-2023.12.18-inplace:Cardano.Wallet.Transaction.Delegation
    SHELLEY_TX_REDEEM_07a - Can't redeem rewards if cannot cover fee [MIR] [?] (39902ms)
  NEW_SHELLEY_TRANSACTIONS
    TRANS_NEW_CREATE_03a - Withdrawal from self [MIR] [?] (28740ms)
    TRANS_NEW_CREATE_04a - Single Output Transaction with decode transaction [MIR] [?] (14135ms)
    TRANS_NEW_SIGN_03 - Sign withdrawals [MIR] [?] (27966ms)
      # PENDING: CONWAY is not supported: wrong era
    TRANS_NEW_JOIN_01e - Can re-join and withdraw at once [MIR] [?] (26520ms)
    TRANS_NEW_QUIT_02a - Cannot quit with rewards without explicit withdrawal [MIR] [?] (25973ms)
    TRANS_NEW_QUIT_02b - Can quit with rewards with explicit withdrawal [MIR] [?] (25857ms)
  SHELLEY_STAKE_POOLS
    STAKE_POOLS_QUIT_03 - Can quit with rewards [MIR] [ ][cardano-wallet.integration:Critical:4725] [2024-02-12 21:22:29.25 UTC] AsyncCancelled
cardano-node: thread killed
cardano-node: thread killed
cardano-node: thread killed
cardano-node: thread killed
cardano-node: thread killed
    STAKE_POOLS_QUIT_03 - Can quit with rewards [MIR] [?] (25898ms)

wip
  • Loading branch information
Anviking committed Feb 19, 2024
1 parent a1a0ac2 commit 367d580
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 63 deletions.
11 changes: 8 additions & 3 deletions lib/faucet/lib/Cardano/Faucet/Addresses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Cardano.Address.Style.Icarus
)
import Cardano.Address.Style.Shelley
( Shelley
, deriveDelegationPrivateKey
)
import Cardano.Mnemonic
( Mnemonic
Expand Down Expand Up @@ -117,15 +118,19 @@ shelley netTag mnemonic = mkPaymentAddrForIx <$> paymentKeyIxs
let firstIx = minBound
in firstIx : unfoldr (fmap dupe . nextIndex) firstIx
mkPaymentAddrForIx paymentAddrIx =
Shelley.paymentAddress netTag credential
Shelley.delegationAddress
netTag
(Shelley.PaymentFromExtendedKey $ toXPub <$> paymentKey)
(Shelley.DelegationFromExtendedKey $ toXPub <$> stakeKey)
where
credential :: Shelley.Credential PaymentK =
Shelley.PaymentFromExtendedKey (toXPub <$> paymentKey)
paymentKey :: Shelley PaymentK XPrv =
deriveAddressPrivateKey
(deriveShelleyAccountKey mnemonic)
Shelley.UTxOExternal
paymentAddrIx
stakeKey :: Shelley DelegationK XPrv =
deriveDelegationPrivateKey
(deriveShelleyAccountKey mnemonic)

shelleyRewardAccount
:: KnownNat n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ generateGenesis initialFunds genesisMods = do
& ppNOptL
.~ 3
& ppRhoL
.~ unsafeUnitInterval 0.178_650_067
.~ unsafeUnitInterval 0.001
& ppTauL
.~ unsafeUnitInterval 0.1
& ppA0L
Expand All @@ -197,7 +197,7 @@ generateGenesis initialFunds genesisMods = do
, sgActiveSlotsCoeff = unsafePositiveUnitInterval 0.5
, sgSecurityParam = 10
, sgEpochLength = 120
, sgSlotLength = 0.12
, sgSlotLength = 0.2
, sgUpdateQuorum = 1
, sgNetworkMagic =
fromIntegral (testnetMagicToNatural cfgTestnetMagic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

module Cardano.Wallet.Launch.Cluster.InstantaneousRewards
( moveInstantaneousRewardsTo
, delegateForNonInstantaneousRewards
, Credential (..)
)
where
Expand Down Expand Up @@ -47,7 +48,8 @@ import Cardano.Wallet.Launch.Cluster.SinkAddress
( genSinkAddress
)
import Cardano.Wallet.Launch.Cluster.StakeCertificates
( issueStakeScriptCert
( issueDelegationCert
, issueStakeScriptCert
, issueStakeVkCert
)
import Cardano.Wallet.Launch.Cluster.Tx
Expand Down Expand Up @@ -88,6 +90,9 @@ import System.FilePath
)

import qualified Cardano.Codec.Cbor as CBOR
import Cardano.Wallet.Launch.Cluster.PoolRecipe
( PoolId
)
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy.Char8 as BL8
Expand Down Expand Up @@ -237,3 +242,131 @@ moveInstantaneousRewardsTo conn targets = unless (null targets) $ do
, mirCert
]
pure $ FileOf @"mir-cert" mirCert

-- Context: MIR certs were removed with Conway.
delegateForNonInstantaneousRewards
:: HasCallStack
=> CardanoNodeConn
-> [Credential]
-> PoolId
-> ClusterM ()
delegateForNonInstantaneousRewards conn targets pool = unless (null targets) $ do
Config{..} <- ask
let clusterDir = cfgClusterDir
let clusterConfigs = cfgClusterConfigs
certs <- mapM (mkDelegationCerts cfgTestnetMagic) targets
(faucetInput, faucetPrv) <- takeFaucet
let txFile = pathOf clusterDir </> "mir-tx.raw"

sink <- genSinkAddress Nothing -- stake pub
cli
$ [ clusterEraToString cfgLastHardFork
, "transaction"
, "build-raw"
, "--tx-in"
, untag faucetInput
, "--ttl"
, "999999999"
, "--fee"
, show (faucetAmt - 1_000_000)
, "--tx-out"
, sink <> "+" <> "1000000"
, "--out-file"
, txFile
]
++ concatMap (\x -> ["--certificate-file", pathOf x]) (mconcat certs)

{- There is a ledger rule that disallows submitting MIR certificates
"too late in Epoch" e.g. less that stability window slots before beginning
of a next epoch. See the MIRCertificateTooLateinEpochDELEG error.
This problem is worked around by retrying the transaction submission until
it succeeds. (This is not ideal as it pollutes logs with error messages)
-}
signAndSubmitTx
conn
(FileOf @"tx-body" txFile)
[ changeFileOf @"faucet-prv" @"signing-key" faucetPrv
, FileOf @"signing-key"
$ pathOf clusterConfigs
</> "delegate-keys/shelley.000.skey"
]
"MIR certificates"
where
mkDelegationCerts
:: TestnetMagic
-> Credential
-> ClusterM [FileOf "cert"]
mkDelegationCerts testnetMagic = \case
KeyCredential xpub -> do
(prefix, vkFile) <- mkVerificationKey xpub
--_stakeAddr <-
-- cliLine
-- [ "stake-address"
-- , "build"
-- , "--testnet-magic"
-- , show (testnetMagicToNatural testnetMagic)
-- , "--stake-verification-key-file"
-- , vkFile
-- ]
stakeCert <-
issueStakeVkCert prefix (FileOf @"stake-pub" vkFile)
delegCert <-
issueDelegationCert
prefix
(FileOf @"stake-pub" vkFile)
pool

pure [changeFileOf stakeCert, changeFileOf delegCert]
ScriptCredential script -> do
(prefix, scriptFile) <- mkScript script
--stakeAddr <-
-- cliLine
-- [ "stake-address"
-- , "build"
-- , "--testnet-magic"
-- , show (testnetMagicToNatural testnetMagic)
-- , "--stake-script-file"
-- , scriptFile
-- ]
stakeCert <- issueStakeScriptCert prefix scriptFile
delegCert <-
issueDelegationCert
prefix
(FileOf @"stake-pub" scriptFile)
pool
pure [changeFileOf stakeCert, changeFileOf delegCert]

mkVerificationKey :: XPub -> ClusterM (Tagged "prefix" String, FilePath)
mkVerificationKey xpub = do
Config{..} <- ask
let base16 =
T.unpack . T.decodeUtf8 . convertToBase Base16
$ xpubPublicKey xpub
let json =
Aeson.object
[ "type" .= Aeson.String "StakeVerificationKeyShelley_ed25519"
, "description" .= Aeson.String "Stake Verification Key"
, "cborHex" .= Aeson.String ("5820" <> T.pack base16)
]
let file = pathOf cfgClusterDir </> base16 <> ".vk"
liftIO $ BL8.writeFile file (Aeson.encode json)
pure (Tagged base16, file)

mkScript :: ByteString -> ClusterM (Tagged "prefix" String, FilePath)
mkScript bytes = do
Config{..} <- ask
let base16 =
T.decodeUtf8 . convertToBase Base16
$ CBOR.toStrictByteString
$ CBOR.encodeBytes bytes
let json =
Aeson.object
[ "type" .= Aeson.String "PlutusScriptV1"
, "description" .= Aeson.String ""
, "cborHex" .= Aeson.String base16
]
let prefix = take 100 (T.unpack base16)
let file = pathOf cfgClusterDir </> prefix <> ".plutus"
liftIO $ BL8.writeFile file (Aeson.encode json)
pure (Tagged prefix, file)
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defaultPoolConfigs =
$
-- This pool should never retire:
PoolRecipe
{ pledgeAmt = 100 * millionAda
{ pledgeAmt = 500 * millionAda
, retirementEpoch = Nothing
, poolMetadata =
Aeson.object
Expand Down Expand Up @@ -96,7 +96,7 @@ defaultPoolConfigs =
:|
-- This pool should retire almost immediately:
[ PoolRecipe
{ pledgeAmt = 100 * millionAda
{ pledgeAmt = 500 * millionAda
, retirementEpoch = Just 3
, poolMetadata =
Aeson.object
Expand Down Expand Up @@ -136,7 +136,7 @@ defaultPoolConfigs =
}
, -- This pool should retire, but not within the duration of a test run:
PoolRecipe
{ pledgeAmt = 100 * millionAda
{ pledgeAmt = 500 * millionAda
, retirementEpoch = Just 100_000
, poolMetadata =
Aeson.object
Expand Down Expand Up @@ -176,7 +176,7 @@ defaultPoolConfigs =
}
, -- This pool should retire, but not within the duration of a test run:
PoolRecipe
{ pledgeAmt = 100 * millionAda
{ pledgeAmt = 500 * millionAda
, retirementEpoch = Just 1_000_000
, poolMetadata =
Aeson.object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Cardano.Wallet.Launch.Cluster.StakeCertificates
( issueStakeVkCert
, issueStakeScriptCert
, issueDelegationCert
)
where

Expand All @@ -20,9 +21,15 @@ import Cardano.Wallet.Launch.Cluster.Config
import Cardano.Wallet.Launch.Cluster.FileOf
( FileOf (..)
)
import Cardano.Wallet.Launch.Cluster.PoolRecipe
( PoolId (..)
)
import Control.Monad.Reader
( asks
)
import Data.ByteArray.Encoding
( Base (..)
)
import Data.Generics.Labels
()
import Data.Tagged
Expand All @@ -33,6 +40,9 @@ import System.FilePath
( (</>)
)

import qualified Data.ByteArray.Encoding as BA
import qualified Data.ByteString.Char8 as B8

-- | Create a stake address registration certificate from a vk
issueStakeVkCert
:: Tagged "prefix" String
Expand Down Expand Up @@ -68,3 +78,23 @@ issueStakeScriptCert prefix stakeScript = do
, file
]
pure $ FileOf file

issueDelegationCert
:: Tagged "prefix" String
-> FileOf "stake-pub"
-> PoolId
-> ClusterM (FileOf "stake-vk-cert")
issueDelegationCert prefix stakePub poolId = do
outputDir <- asks cfgClusterDir
let file = pathOf outputDir </> untag prefix <> "-stake.cert"
cli
[ "stake-address"
, "delegation-certificate"
, "--staking-verification-key-file"
, pathOf stakePub
, "--stake-pool-id"
, B8.unpack $ BA.convertToBase Base16 $ getPoolId poolId
, "--out-file"
, file
]
pure $ FileOf file
3 changes: 3 additions & 0 deletions lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ library integration-framework
, bech32-th
, bytestring
, cardano-addresses
, cardano-data
, cardano-crypto-class
, cardano-ledger-shelley
, cardano-wallet-application-extras
, cardano-wallet-launcher
Expand Down Expand Up @@ -714,6 +716,7 @@ library integration-framework
, memory
, microstache
, monad-loops
, lens
, network-uri
, resourcet
, retry
Expand Down
Loading

0 comments on commit 367d580

Please sign in to comment.