Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - CLI is not allowing process substitution on certain commands #4235

Closed
Tracked by #4144 ...
gitmachtl opened this issue Jul 26, 2022 · 4 comments · Fixed by #4384 or #4625
Closed
Tracked by #4144 ...

[BUG] - CLI is not allowing process substitution on certain commands #4235

gitmachtl opened this issue Jul 26, 2022 · 4 comments · Fixed by #4384 or #4625
Assignees
Labels

Comments

@gitmachtl
Copy link
Contributor

gitmachtl commented Jul 26, 2022

Cardano-CLI 1.34.1

In the past it was no problem to use a common practice in linux to not write out files directly (if you only need them in ram) and use a process substitution -> file handler instead.

For some commands in the CLI this is still working like (example):

Setting up the variables

protocolParametersJSON=

{
    "collateralPercentage": 150,
    "costModels": {
        "PlutusScriptV1": {
            "addInteger-cpu-arguments-intercept": 205665,
            "addInteger-cpu-arguments-slope": 812,
            "addInteger-memory-arguments-intercept": 1,
            "addInteger-memory-arguments-slope": 1,
    "....etc....etc.......",
    "stakePoolTargetNum": 500,
    "treasuryCut": 0.2,
    "txFeeFixed": 155381,
    "txFeePerByte": 44,
    "utxoCostPerWord": 34480
}
txBodyFile="/home/user/mytransaction.txbody"; txcnt=1; rxcnt=2; magicparam="--mainnet"; etc ...

Executing the command

cardano-cli transaction calculate-min-fee \
                    --tx-body-file ${txBodyFile} \
                    --protocol-params-file <(echo "${protocolParametersJSON}") \
                    --tx-in-count ${txcnt} \
                    --tx-out-count ${rxcnt} \
                    ${magicparam} ...

The part i am talking about is <(echo "${protocolParametersJSON}"), this is working fine for the command above. 👍


But in other commands for example for the tx-file content, this is not working anymore:

Setting up a variable

txFileJSON=

{
    "type": "Witnessed Tx AlonzoEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a5008282582055c90e5f39ee7e638da909.....64732c204d617274696e203a2d29"
}

Executing the command

cardano-cli transaction txid --tx-file <(echo "${txFileJSON}")
cardano-cli transaction submit --tx-file <(echo "${txFileJSON}") --mainnet

Results into the following error 😢

Command failed: transaction txid  Error: Failed to decode neither the cli's serialisation format nor the ledger's CDDL serialisation format. TextEnvelope error: /dev/fd/63: TextEnvelope type error:  Expected one of: TxSignedByron, TxSignedShelley, Tx AllegraEra, Tx MaryEra, Tx AlonzoEra, Tx BabbageEra Actual: Witnessed Tx AlonzoEra
TextEnvelopeCddl error: /dev/fd/63: Could not JSON decode TextEnvelopeCddl file at: /dev/fd/63 Error: Error in $: not enough input

So this is not working anymore. If you write out the content to a file and use the filename it works.

But why/how was this changed? It worked in previous versions of the CLI.


As a simple demo that it is not an OS issue we create a simple script that is showing the content of a file:
showfile.sh:

#!/bin/bash
whatever_file="${1}"
cat "${whatever_file}"

Execute the script with the process substitution like above:

./showfile.sh <(echo "${txFileJSON}")
{
    "type": "Witnessed Tx AlonzoEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a5008282582055c90e5f39ee7e638da909.....64732c204d617274696e203a2d29"
}

All good. So, something changed in the CLI and it would be good to fix it so it can be used like any other linux program together with process substitution on all parameters.

@gitmachtl
Copy link
Contributor Author

gitmachtl commented Aug 8, 2022

The output redirection to the stdout is not working for the VRF-Key creation!

$ cardano-cli node key-gen-VRF --verification-key-file "test.vrf.vkey" --signing-key-file /dev/stdout

cardano-cli-1.35.3-rc1: /dev/: openTempFile: permission denied (Permission denied)

Why the heck on earth wants cardano-cli to write a TempFile in the path given for the output signing key!?
Writing to /dev/stdout works for all other commands, but not for the VRF keys. We need this to do secure key handling without the need to write them out to a file on the HDD.

Issue is most likely caused by libsodium.

@LudvikGalois
Copy link
Contributor

Issue is most likely caused by libsodium.

It's actually caused by writeFileWithOwnerPermissions from Cardano.API.SerialiseTextEnvelope. Which makes a new file and then renames it to the target to clobber any existing file. This seems like a hack.

@CarlosLopezDeLara CarlosLopezDeLara moved this from 📋 Backlog to 🏗 In progress in Node CLI/API 2022 Aug 23, 2022
@LudvikGalois LudvikGalois self-assigned this Aug 23, 2022
@iohk-bors iohk-bors bot closed this as completed in d1d80d9 Aug 30, 2022
@CarlosLopezDeLara CarlosLopezDeLara moved this from 🏗 In progress to ✅ Done in Node CLI/API 2022 Aug 31, 2022
@saratomaz
Copy link

Issue unsolved

Setting up a variable

txFileJSON=$(cat <<-EOF
{
  "type": "Unwitnessed Tx BabbageEra",
  "description": "Ledger Cddl Format",
  "cborHex": "84a300818258208a5a31ae52cdc140b1c532c47d5cb3c8dbc6c9b7a4aa537ed9e3543ea94cfad1000183a200581d60768d2bcd29a84ae015d96118e3285bc0cbd399ae16039ad471c8a806011a001e8480a200581d60768d2bcd29a84ae015d96118e3285bc0cbd399ae16039ad471c8a806011a002625a0a200581d600ac4d3db1163e7884959c0317aa19263a236db113fa0fbefbd49b335011a00958d31021a0003094fa0f5f6"
}
EOF
)

Tested on tag 1.35.4-rc1

cardano-cli transaction txid --tx-file <(echo "${txFileJSON}")

Command failed: transaction txid  Error: Failed to decode neither the cli's serialisation format nor the ledger's CDDL serialisation format. TextEnvelope error: /dev/fd/63: TextEnvelope aeson decode error: Error in $: not enough input
TextEnvelopeCddl error: /dev/fd/63: Could not JSON decode TextEnvelopeCddl file at: /dev/fd/63 Error: Error in $: not enough input

If you write out the content to a file and use the filename it works.
cardano-cli transaction txid --tx-file <same_content_in_file>

a2e58d1b59d8c06535a1134f0022b1c77b5dc679248f635197546b6855830730

Tested on latest master

cardano-cli transaction txid --tx-file <(echo "${txFileJSON}")

cardano-cli: TODO
CallStack (from HasCallStack):
  error, called at src/Cardano/CLI/Shelley/Run/Transaction.hs:212:32 in cardano-cli-1.36.0-LXoqbxN0MejLJIylH9D3mJ:Cardano.CLI.Shelley.Run.Transaction(.env) 

If you write out the content to a file and use the filename it works.
cardano-cli transaction txid --tx-file <same_content_in_file>

a2e58d1b59d8c06535a1134f0022b1c77b5dc679248f635197546b6855830730

@saratomaz saratomaz reopened this Nov 3, 2022
@CarlosLopezDeLara CarlosLopezDeLara moved this from 🟣 DONE Merged/Closed to 👀Code review in Node CLI/API 2022 Nov 3, 2022
LudvikGalois pushed a commit that referenced this issue Nov 8, 2022
LudvikGalois pushed a commit that referenced this issue Nov 15, 2022
LudvikGalois pushed a commit that referenced this issue Nov 22, 2022
Jimbo4350 pushed a commit that referenced this issue Feb 8, 2023
Jimbo4350 pushed a commit that referenced this issue Feb 8, 2023
Jimbo4350 pushed a commit that referenced this issue Feb 9, 2023
newhoggy pushed a commit that referenced this issue Feb 10, 2023
Jimbo4350 pushed a commit that referenced this issue Feb 10, 2023
Jimbo4350 pushed a commit that referenced this issue Feb 10, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 11, 2023
Fixes #4235

Make prop_readFromPipe assertion more strict
newhoggy pushed a commit that referenced this issue Feb 11, 2023
Fixes #4235

Make prop_readFromPipe assertion more strict
newhoggy added a commit that referenced this issue Feb 11, 2023
Fixes #4235

Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 11, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 12, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 13, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 13, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
iohk-bors bot added a commit that referenced this issue Feb 13, 2023
4625: Handle pipes r=newhoggy a=LudvikGalois

Fixes #4235

Co-authored-by: Robert 'Probie' Offner <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 14, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
iohk-bors bot added a commit that referenced this issue Feb 14, 2023
4625: Handle pipes r=newhoggy a=LudvikGalois

Fixes #4235

Co-authored-by: Robert 'Probie' Offner <[email protected]>
newhoggy pushed a commit that referenced this issue Feb 20, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
iohk-bors bot added a commit that referenced this issue Feb 20, 2023
4625: Handle pipes r=newhoggy a=LudvikGalois

Fixes #4235

Co-authored-by: Robert 'Probie' Offner <[email protected]>
Jimbo4350 pushed a commit that referenced this issue Feb 28, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
iohk-bors bot added a commit that referenced this issue Feb 28, 2023
4625: Handle pipes r=Jimbo4350 a=LudvikGalois

Fixes #4235

4682: Export `fromShelleyBasedScript` from Cardano.Api r=Jimbo4350 a=eyeinsky

New PR based off of a branch in this repo. Old PR here #4386

Co-authored-by: Robert 'Probie' Offner <[email protected]>
Co-authored-by: Markus Läll <[email protected]>
iohk-bors bot added a commit that referenced this issue Feb 28, 2023
4625: Handle pipes r=Jimbo4350 a=LudvikGalois

Fixes #4235

4908: Added features to tracing r=jutaro a=jutaro

* Generated docu shows tracers, tracers with metrics, silent tracers according to current configuration
* Trace message shows tracers with metrics and silent tracers

Co-authored-by: Robert 'Probie' Offner <[email protected]>
Co-authored-by: Yupanqui <[email protected]>
newhoggy pushed a commit that referenced this issue Mar 1, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
iohk-bors bot added a commit that referenced this issue Mar 1, 2023
4625: Handle pipes r=newhoggy a=LudvikGalois

Fixes #4235

4908: Added features to tracing r=jutaro a=jutaro

* Generated docu shows tracers, tracers with metrics, silent tracers according to current configuration
* Trace message shows tracers with metrics and silent tracers

Co-authored-by: Robert 'Probie' Offner <[email protected]>
Co-authored-by: Yupanqui <[email protected]>
@iohk-bors iohk-bors bot closed this as completed in 71b5318 Mar 1, 2023
newhoggy pushed a commit that referenced this issue Mar 10, 2023
Fixes #4235
Co-authored-by: John Ky <[email protected]>
newhoggy pushed a commit to IntersectMBO/cardano-api that referenced this issue May 23, 2023
newhoggy pushed a commit to IntersectMBO/cardano-cli that referenced this issue May 24, 2023
newhoggy pushed a commit to IntersectMBO/cardano-cli that referenced this issue May 24, 2023
4625: Handle pipes r=newhoggy a=LudvikGalois

Fixes IntersectMBO/cardano-node#4235

4908: Added features to tracing r=jutaro a=jutaro

* Generated docu shows tracers, tracers with metrics, silent tracers according to current configuration
* Trace message shows tracers with metrics and silent tracers

Co-authored-by: Robert 'Probie' Offner <[email protected]>
Co-authored-by: Yupanqui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants
@LudvikGalois @dorin100 @gitmachtl @CarlosLopezDeLara @saratomaz and others