Skip to content

Commit

Permalink
more experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Mar 31, 2023
1 parent da893f4 commit cc867d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
14 changes: 12 additions & 2 deletions lib/wallet/integration/src/Test/Integration/Faucet.hs
Expand Up @@ -100,6 +100,10 @@ import Data.Text
( Text )
import GHC.TypeLits
( KnownNat, Nat, Symbol )
import System.Environment
( getEnv )
import System.IO.Unsafe
( unsafePerformIO )
import UnliftIO.MVar
( MVar, modifyMVar )

Expand Down Expand Up @@ -2372,11 +2376,17 @@ preregKeyWallet = unsafeMkMnemonic
, "bid", "raccoon", "spin", "reduce", "rival"
]

{-# NOINLINE addrsPerWallet #-}
-- Number of addresses per normal fixture wallet
addrsPerWallet :: Int
addrsPerWallet = unsafePerformIO $
read <$> getEnv "ADDRS_PER_WALLET"

shelleyIntegrationTestFunds :: [(Address, Coin)]
shelleyIntegrationTestFunds = mconcat
[ seqMnemonics >>= take 10 . map (, defaultAmt) . addresses . SomeMnemonic
[ seqMnemonics >>= take addrsPerWallet . map (, defaultAmt) . addresses . SomeMnemonic

, icaMnemonics >>= take 10 . map (, defaultAmt) . icaAddresses
, icaMnemonics >>= take addrsPerWallet . map (, defaultAmt) . icaAddresses

, zip
(addresses $ SomeMnemonic onlyDustWallet)
Expand Down
31 changes: 22 additions & 9 deletions lib/wallet/src/Cardano/Wallet.hs
Expand Up @@ -599,6 +599,10 @@ import GHC.TypeNats
( Nat )
import Statistics.Quantile
( medianUnbiased, quantiles )
import System.Environment
( getEnv )
import System.IO.Unsafe
( unsafePerformIO )
import System.Random.StdGenSeed
( StdGenSeed (..), stdGenFromSeed, stdGenSeed )
import Type.Reflection
Expand All @@ -612,6 +616,7 @@ import qualified Cardano.Address.Script as CA
import qualified Cardano.Address.Style.Shared as CA
import qualified Cardano.Address.Style.Shelley as CAShelley
import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Extra as Cardano
import qualified Cardano.Crypto.Wallet as CC
import qualified Cardano.Slotting.Slot as Slot
import qualified Cardano.Tx.Balance.Internal.CoinSelection as CS
Expand Down Expand Up @@ -2881,6 +2886,11 @@ delegationFee db@DBLayer{atomically, walletsDB} netLayer
case recentEra of {}
deposit <- liftIO $ calcMinimumDeposit db netLayer walletId
pure DelegationFee { feePercentiles, deposit }
{-# NOINLINE repeats #-}
repeats :: Int
repeats = unsafePerformIO $
read <$> getEnv "FEE_ITERATIONS"


-- | Repeatedly (100 times) runs given transaction fee estimation calculation
-- returning 1st and 9nth decile (10nth and 90nth percentile) values of a
Expand Down Expand Up @@ -2922,7 +2932,6 @@ calculateFeePercentiles
((e:_), []) -> Left e
(_, samples') -> Right samples'

repeats = 100 -- TODO: modify repeats based on data

-- | When estimating fee, it is rather cumbersome to return
-- "cannot cover fee" if clients are just asking for an estimation.
Expand Down Expand Up @@ -3799,15 +3808,19 @@ toBalanceTxPParams
:: forall era. WriteTx.IsRecentEra era
=> ProtocolParameters
-> (ProtocolParameters, Cardano.BundledProtocolParameters era)
toBalanceTxPParams pp =
toBalanceTxPParams pp = bundledPParams `seq` ledgerPParams `seq`
( pp
, maybe
(error $ unwords
, bundledPParams
)
where
nodePParams = fromMaybe (error $ unwords
[ "toBalanceTxPParams: no nodePParams."
, "should only be possible in Byron, where"
, "withRecentEra should prevent this to be reached."
])
(Cardano.bundleProtocolParams
(WriteTx.fromRecentEra (WriteTx.recentEra @era)))
$ currentNodeProtocolParameters pp
)
]) $ currentNodeProtocolParameters pp
bundledPParams = Cardano.bundleProtocolParams
(WriteTx.fromRecentEra (WriteTx.recentEra @era))
nodePParams
ledgerPParams = Cardano.unbundleLedgerShelleyBasedProtocolParams
(WriteTx.shelleyBasedEraFromRecentEra $ WriteTx.recentEra @era)
bundledPParams

0 comments on commit cc867d1

Please sign in to comment.