Skip to content

Commit

Permalink
Merge #4466 #4484 #4486
Browse files Browse the repository at this point in the history
4466: Added changelogs for releases between 1.34.0 and 1.35.3 r=Jimbo4350 a=LaurenceIO

Updated api, cli, node, and submit-api changelogs on master with changes in 1.34.0, 1.34.1, 1.35.0, 1.35.1, 1.35.2, and 1.35.3 releases.

Thanks to `@ltouro` for highlighting a typo.

4484: Update error message for incorrectly witnessed collateral inputs r=Jimbo4350 a=Jimbo4350

Resolves: #4479 

4486: tx-generator: Use distinct keys/addresses for benchmarking phases r=MarcFontaine a=MarcFontaine

This is useful for debugging the tx-generator.
Hard coded addresses:
`addr_test1vzj7zv9msmdasvy5nc9jhnn2gqvrvu33v5rlg332zdfrkugklxkau` : outputs of the splitting phase (value not Plutus).
`addr_test1vz4qz2ayucp7xvnthrx93uhha7e04gvxttpnuq4e6mx2n5gzfw23z` : final outputs of the benchmarking phase.



Co-authored-by: LaurenceIO <73659683+LaurenceIO@users.noreply.github.com>
Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
Co-authored-by: MarcFontaine <MarcFontaine@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 28, 2022
4 parents dbca757 + 69939e5 + d100008 + 7173847 commit c92564e
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 34 deletions.
104 changes: 89 additions & 15 deletions bench/tx-generator/src/Cardano/Benchmarking/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import Control.Applicative (liftA2)
import Control.Monad
import Control.Monad.Trans.Except
import Control.Monad.Trans.RWS.CPS

import Data.Aeson
import Data.ByteString.Lazy as BSL (ByteString)
import Data.Dependent.Sum ( (==>) )
import Data.DList (DList)
import qualified Data.DList as DL
import Data.Text (Text)
import qualified Data.Text as Text

import Cardano.Api

import Cardano.Benchmarking.NixOptions
import Cardano.Benchmarking.Script.Setters
import Cardano.Benchmarking.Script.Store (Name(..), WalletName)
import Cardano.Benchmarking.Script.Store (KeyName, Name(..), WalletName)
import Cardano.Benchmarking.Script.Types

data CompileError where
Expand Down Expand Up @@ -53,12 +55,17 @@ compileToScript = do
genesisWallet <- importGenesisFunds
collateralWallet <- addCollaterals genesisWallet
splitWallet <- splittingPhase genesisWallet
benchmarkingPhase splitWallet collateralWallet
void $ benchmarkingPhase splitWallet collateralWallet

initConstants :: Compiler ()
initConstants = do
setN TLocalSocket _nix_localNodeSocketPath
setConst TTTL 1000000
emit $ DefineSigningKey keyNameTxGenFunds keyTxGenFunds
emit $ DefineSigningKey keyNameCollaterals keyCollaterals
emit $ DefineSigningKey keyNameSplitPhase keySplitPhase
emit $ DefineSigningKey keyNameBenchmarkInputs keyBenchmarkInputs
emit $ DefineSigningKey keyNameBenchmarkDone keyBenchmarkDone
where
setConst :: Tag v -> v -> Compiler ()
setConst key val = emit $ Set $ key ==> val
Expand All @@ -72,8 +79,8 @@ importGenesisFunds = do
wallet <- newWallet "genesis_wallet"
era <- askNixOption _nix_era
fee <- askNixOption _nix_tx_fee
cmd1 (ReadSigningKey $ KeyName "pass-partout") _nix_sigKey
emit $ Submit era LocalSocket $ SecureGenesis fee wallet (KeyName "pass-partout") (KeyName "pass-partout")
cmd1 (ReadSigningKey keyNameGenesisInputFund) _nix_sigKey
emit $ Submit era LocalSocket $ SecureGenesis fee wallet keyNameGenesisInputFund keyNameTxGenFunds
delay
logMsg "Importing Genesis Fund. Done."
return wallet
Expand All @@ -89,8 +96,8 @@ addCollaterals src = do
collateralWallet <- newWallet "collateral_wallet"
fee <- askNixOption _nix_tx_fee
let generator = Split fee src
(PayToAddr (KeyName "pass-partout") collateralWallet)
(PayToAddr (KeyName "pass-partout") src)
(PayToAddr keyNameCollaterals collateralWallet)
(PayToAddr keyNameTxGenFunds src)
[ safeCollateral ]
emit $ Submit era LocalSocket generator
logMsg "Create collaterals. Done."
Expand All @@ -106,17 +113,18 @@ splittingPhase srcWallet = do
finalDest <- newWallet "final_split_wallet"
splitSteps <- splitSequenceWalletNames srcWallet finalDest $ unfoldSplitSequence tx_fee minValuePerInput (tx_count * inputs_per_tx)
isPlutus <- isAnyPlutusMode
forM_ (init splitSteps) $ createChange False era
createChange isPlutus era $ last splitSteps
forM_ (init splitSteps) $ createChange False False era
createChange True isPlutus era $ last splitSteps
return finalDest
where
createChange :: Bool -> AnyCardanoEra -> (SrcWallet, DstWallet, Split) -> Compiler ()
createChange isPlutus era (src, dst, split) = do
createChange :: Bool -> Bool -> AnyCardanoEra -> (SrcWallet, DstWallet, Split) -> Compiler ()
createChange isLastStep isPlutus era (src, dst, split) = do
logMsg $ Text.pack $ "Splitting step: " ++ show split
tx_fee <- askNixOption _nix_tx_fee
payMode <- if isPlutus then plutusPayMode dst else return $ PayToAddr (KeyName "pass-partout") dst
let valuePayMode = PayToAddr (if isLastStep then keyNameSplitPhase else keyNameBenchmarkInputs) dst
payMode <- if isPlutus then plutusPayMode dst else return valuePayMode
let generator = case split of
SplitWithChange lovelace count -> Split tx_fee src payMode (PayToAddr (KeyName "pass-partout") src) $ replicate count lovelace
SplitWithChange lovelace count -> Split tx_fee src payMode (PayToAddr keyNameTxGenFunds src) $ replicate count lovelace
FullSplits txCount -> Take txCount $ Cycle $ SplitN tx_fee src payMode maxOutputsPerTx
emit $ Submit era LocalSocket generator
delay
Expand Down Expand Up @@ -167,7 +175,7 @@ unfoldSplitSequence fee value outputs
(x, 0) -> x
(x, _rest) -> x+1

benchmarkingPhase :: WalletName -> Maybe WalletName -> Compiler ()
benchmarkingPhase :: WalletName -> Maybe WalletName -> Compiler WalletName
benchmarkingPhase wallet collateralWallet = do
debugMode <- askNixOption _nix_debugMode
targetNodes <- askNixOption _nix_targetNodes
Expand All @@ -178,15 +186,17 @@ benchmarkingPhase wallet collateralWallet = do
inputs <- askNixOption _nix_inputs_per_tx
outputs <- askNixOption _nix_outputs_per_tx
metadataSize <- askNixOption _nix_add_tx_size
doneWallet <- newWallet "done_wallet"
let
payMode = PayToAddr (KeyName "pass-partout") wallet --todo: used different wallet here !
payMode = PayToAddr keyNameBenchmarkDone doneWallet
submitMode = if debugMode
then LocalSocket
else Benchmark targetNodes (ThreadName "tx-submit-benchmark") tps txCount
generator = Take txCount $ Cycle $ NtoM fee wallet payMode inputs outputs (Just metadataSize) collateralWallet
emit $ Submit era submitMode generator
unless debugMode $ do
emit $ WaitBenchmark $ ThreadName "tx-submit-benchmark"
return doneWallet

data Fees = Fees {
_safeCollateral :: Lovelace
Expand Down Expand Up @@ -250,3 +260,67 @@ newWallet n = do
name <- WalletName <$> newIdentifier n
emit $ InitWallet name
return name

parseKey :: BSL.ByteString -> TextEnvelope
parseKey x = case decode x of
Nothing -> error $ "parsing of key failed : " ++ show x
Just k -> k

keyNameGenesisInputFund :: KeyName
keyNameGenesisInputFund = KeyName "GenesisInputFund"

keyNameTxGenFunds :: KeyName
keyNameTxGenFunds = KeyName "TxGenFunds"

{-|
The key that is used for the very first transaction, i.e. the secure Genesis transaction.
addr_test1vzd3muund27y5nw83vymqj3a83pcuzkkejej6s75e5lfjcc85nc3p is the actual address (in Testnet 42).
It is also used as change addresse in the first splitting-step.
-}
keyTxGenFunds :: TextEnvelope
keyTxGenFunds = parseKey "{\n \"type\": \"PaymentSigningKeyShelley_ed25519\",\n \"description\": \"Payment Signing Key\",\n \"cborHex\": \"5820617f846fc8b0e753bd51790de5f5a916de500175c6f5a0e27dde9da7879e1d35\"\n}\n"

keyNameSplitPhase :: KeyName
keyNameSplitPhase = KeyName "SplitPhase"

{-|
UTxOs that are generated in intermediate splitting steps use:
addr_test1vz45dtkyzk6s3245qw8hmaddaatcx8td3pvmntl8ty7q99c22eahm
-}

keySplitPhase :: TextEnvelope
keySplitPhase = parseKey "{\n \"type\": \"PaymentSigningKeyShelley_ed25519\",\n \"description\": \"Payment Signing Key\",\n \"cborHex\": \"5820cf0083c2a5d4c90ab255bc8e68f407d52eebd9408de60a0b9e4c468f9714f076\"\n}\n"

{-|
UTxOs of the final splitting steps, i.e. the inputs of the benchmarking phase, use:
addr_test1vzj7zv9msmdasvy5nc9jhnn2gqvrvu33v5rlg332zdfrkugklxkau
(Plutus script addresses are ofc different.)
-}
keyNameBenchmarkInputs :: KeyName
keyNameBenchmarkInputs = KeyName "BenchmarkInputs"

keyBenchmarkInputs :: TextEnvelope
keyBenchmarkInputs = parseKey "{\n \"type\": \"PaymentSigningKeyShelley_ed25519\",\n \"description\": \"Payment Signing Key\",\n \"cborHex\": \"58205b7f272602661d4ad3d9a4081f25fdcdcdf64fdc4892107de50e50937b77ea42\"\n}\n"

keyNameBenchmarkDone :: KeyName
keyNameBenchmarkDone = KeyName "BenchmarkingDone"

{-|
The output of the actual benchmarking transactions use:
addr_test1vz4qz2ayucp7xvnthrx93uhha7e04gvxttpnuq4e6mx2n5gzfw23z
Query the progress of the benchmarking phase:
`cardano-node query utxo --testnet-magic 42 --address addr_test1vz4qz2ayucp7xvnthrx93uhha7e04gvxttpnuq4e6mx2n5gzfw23z`
-}

keyBenchmarkDone :: TextEnvelope
keyBenchmarkDone = parseKey "{\n \"type\": \"PaymentSigningKeyShelley_ed25519\",\n \"description\": \"Payment Signing Key\",\n \"cborHex\": \"582016ca4f13fa17557e56a7d0dd3397d747db8e1e22fdb5b9df638abdb680650d50\"\n}\n"

keyNameCollaterals :: KeyName
keyNameCollaterals = KeyName "Collaterals"

{-|
Collateral inputs for Plutus transactions:
addr_test1vpckd9muw3l4f8ne4uzumy28p0k84rvx48q46kssjkta5ng4v6sfs
-}
keyCollaterals :: TextEnvelope
keyCollaterals = parseKey "{\n \"type\": \"PaymentSigningKeyShelley_ed25519\",\n \"description\": \"Payment Signing Key\",\n \"cborHex\": \"58204babdb63537ccdac393ea23d042af3b7c3587d7dc88ed3b66c959f198ad358fa\"\n}\n"
58 changes: 57 additions & 1 deletion cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,62 @@

- Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384))

## 1.35.3 -- August 2022

- Fix leadership schedule for current on babbage (#4106)
- Update build to allow all invalid scripts (again) (#4088)
- Fix building of Alonzo transaction in Babbage era. (#4166)
- Add `utxoCostPerByte` protocol parameter (#4141)

## 1.35.2 -- July 2022 (not released)

None

## 1.35.1 -- July 2022 (not released)

None

## 1.35.0 -- June 2022
- Add Vasil hardfork to cardano-api and cardano-cli (#3765)
- Reference script integration (#3953)
- Wire up remaining Plutusv2 reference script types (#4034)
- Add `IsString` (Hash BlockHeader) (#3619)
- Make `LedgerStateEvents` a type alias (#3692)
- Propagate protocol epoch state decode error (#3696)
- Expose the tx mempool monitoring mini protocol in cardano-api (#3706)
- Babbage functionality integration in cardano api Part 1 (#3803)
- Remove unused package (#3816)
- Add `IsCardanoEra` constraint to BlockInMode (#3665)
- Update cardano-api's TxOut with inline datum (#3773)
- Update cardano-api txout with reference scripts (#3779)
- Implement return and total collateral in cardano-api (#3787)
- Add reference transaction inputs to cardano-api (#3804)
- Fix datum in tx and ref scripts (#3882)
- Support the babbage era in the API function `cddlTypeToEra` (#3916)
- Fix typo for TxWitness BabbageEra (#3961)
- kes-period-info property test (#3718)
- Extend deserialiseFromRawBytesHex to produce error description (#3304)
- add genesis create-cardano command (#3832)
- Propagate protocol in block type (#3818)
- Create VRF signing key file with correct permissions (#1948)
- Update example-reference-script-usage.sh to also use inline datums (#4006)
- Restore deleted comment (#4044)
- Do not require decentralization parameter in protocol parameters (#4051)

## 1.34.0 -- February 2022

- Expose `lovelaceToTxOutValue`. (#3381)
- Implement two functions: `currentEpochEligibleLeadershipSlots` and
`nextEpochEligibleLeadershipSlots` to get the leadership slots for the
current/next epoch respectively. (#3464, #3494)
- Various small internal fixes. (#3466)
- Add a `capi` library to support using the cardano node as a C library in other
software. (#3501)
- `fromShelleyAddr` now takes an explicit `ShelleyBasedEra` parameter to
determine the era. The previous behaviour (with an implicit
`IsShelleyBasedEra` constraint) can be obtained with `fromShelleyAddrIsSbe`.
(#2253, #3606)

## 1.33.0 -- December 2021
## 1.32.1 -- November 2021

Expand Down Expand Up @@ -45,7 +101,7 @@

- Support for automated Tx building. (#2953)
- A few additional exports for API consumers. (#3001, #3055)
- Miscallaneous internal improvements. (#2948)
- Miscellaneous internal improvements. (#2948)
- Block folding interface now derives the network ID automatically from the
ledger config. (#2955, #2975)
- Improve the error generated when a Tx output does not meet the minimum UTxO
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ module Cardano.Api (
getIsCardanoEraConstraint,

-- ** Misc
NotScriptLockedTxInsError(..),
ScriptLockedTxInsError(..),
TxInsExistError(..),
renderNotScriptLockedTxInsError,
renderTxInsExistError,
Expand Down
15 changes: 8 additions & 7 deletions cardano-api/src/Cardano/Api/Convenience/Construction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Cardano.Api.Convenience.Construction (

-- * Misc
TxInsExistError(..),
NotScriptLockedTxInsError(..),
ScriptLockedTxInsError(..),
notScriptLockedTxIns,
renderNotScriptLockedTxInsError,
renderTxInsExistError,
Expand Down Expand Up @@ -84,19 +84,20 @@ txInsExistInUTxO ins (UTxO utxo)
then return ()
else Left . TxInsDoNotExist $ ins List.\\ occursInUtxo

newtype NotScriptLockedTxInsError = NotScriptLockedTxIns [TxIn]
newtype ScriptLockedTxInsError = ScriptLockedTxIns [TxIn]

renderNotScriptLockedTxInsError :: NotScriptLockedTxInsError -> Text
renderNotScriptLockedTxInsError (NotScriptLockedTxIns txins) =
"The followings tx inputs are not script locked: " <> textShow (map renderTxIn txins)
renderNotScriptLockedTxInsError :: ScriptLockedTxInsError -> Text
renderNotScriptLockedTxInsError (ScriptLockedTxIns txins) =
"The followings tx inputs were expected to be key witnessed but are actually script witnessed: " <>
textShow (map renderTxIn txins)

notScriptLockedTxIns :: [TxIn] -> UTxO era -> Either NotScriptLockedTxInsError ()
notScriptLockedTxIns :: [TxIn] -> UTxO era -> Either ScriptLockedTxInsError ()
notScriptLockedTxIns collTxIns (UTxO utxo) = do
let onlyCollateralUTxOs = Map.restrictKeys utxo $ Set.fromList collTxIns
scriptLockedTxIns =
filter (\(_, TxOut aInEra _ _ _) -> not $ isKeyAddress aInEra ) $ Map.assocs onlyCollateralUTxOs
if null scriptLockedTxIns
then return ()
else Left . NotScriptLockedTxIns $ map fst scriptLockedTxIns
else Left . ScriptLockedTxIns $ map fst scriptLockedTxIns


0 comments on commit c92564e

Please sign in to comment.