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

Disambiguate 2-n flags in governance new-committee action #302

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Sep 21, 2023

Changelog

- description: |
    A number of flags appeared in the parameters of new-committee multiple times, with the same long flag, making the parser break. This PR disambiguates the repeated occurences.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way <- Clément: I believe right?
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Contributes to fixing #300

How to trust this PR

This PR is mostly boilerplate, but there is one thing to make sure of:

When a prefix argument is introduced in a parser, it is used in all branches of the parser. For example in this snippet:

asum [ AnyStakePoolKey <$> pStakePoolVerificationKeyOrHashOrFile prefix
       , AnyStakeKey <$> pStakeVerificationKeyOrHashOrFile prefix
       ]

It is important to pass prefix to every branch of the asum. Otherwise we could create inconsistent parsers. I have made sure this was correct.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • The change log section in the PR description has been filled in
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • round trip tests
    • integration tests
      See Running tests for more details
  • NA The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • The changelog section in the PR is updated to describe the change
  • Self-reviewed the diff

@smelc
Copy link
Contributor Author

smelc commented Sep 21, 2023

On the current state of this PR, the create-new-committee API is now as follows (cc @CarlosLopezDeLara):

Usage: cardano-cli conway governance action create-new-committee 
                                                                   ( --mainnet
                                                                   | --testnet
                                                                   )
                                                                   --governance-action-deposit NATURAL
                                                                   ( --stake-pool-verification-key STRING
                                                                   | --cold-verification-key-file FILE
                                                                   | --stake-pool-id STAKE_POOL_ID
                                                                   | --stake-verification-key STRING
                                                                   | --stake-verification-key-file FILE
                                                                   | --stake-key-hash HASH
                                                                   )
                                                                   --proposal-url TEXT
                                                                   ( --proposal-text TEXT
                                                                   | --proposal-file FILE
                                                                   | --proposal-hash HASH
                                                                   )
                                                                   [ --remove-cc-stake-pool-verification-key STRING
                                                                   | --remove-cc-cold-verification-key-file FILE
                                                                   | --remove-cc-stake-pool-id STAKE_POOL_ID
                                                                   | --remove-cc-stake-verification-key STRING
                                                                   | --remove-cc-stake-verification-key-file FILE
                                                                   | --remove-cc-stake-key-hash HASH
                                                                   ]
                                                                   [
                                                                     ( --add-cc-stake-pool-verification-key STRING
                                                                     | --add-cc-cold-verification-key-file FILE
                                                                     | --add-cc-stake-pool-id STAKE_POOL_ID
                                                                     | --add-cc-stake-verification-key STRING
                                                                     | --add-cc-stake-verification-key-file FILE
                                                                     | --add-cc-stake-key-hash HASH
                                                                     )
                                                                     --epoch NATURAL]
                                                                   --quorum RATIONAL
                                                                   [--governance-action-tx-id TXID
                                                                     --governance-action-index WORD32]
                                                                   --out-file FILE

@smelc
Copy link
Contributor Author

smelc commented Sep 21, 2023

@CarlosLopezDeLara> if I retry your earlier example from Slack, it now fails differently:

> cabal run cardano-cli -- conway governance action create-new-committee --testnet --governance-action-deposit 0 --stake-verification-key-file utxo-keys/stake1.vkey --proposal-url https://tinyurl.com/3wrwb2as --proposal-file proposal.txt --remove-cc-cold-verification-key-file cc/cc-cold.vkey --add-cc-cold-verification-key-file cc/cc-cold1.vkey --epoch 5 --quorum 
1/100 --out-file new-cc.action

cardano-cli: proposal.txt: withBinaryFile: does not exist (No such file or directory)

Whereas before this PR, I was reproducing your parsing failure. So I think we're good.

@smelc smelc force-pushed the smelc/fix-new-committee-parser branch from 52adb31 to c457776 Compare September 21, 2023 14:36
@smelc
Copy link
Contributor Author

smelc commented Sep 21, 2023

@CarlosLopezDeLara> while doing this PR, I realized we likely have the same kind of problem for create-treasury-withdrawal. This is visible here in this PR: https://github.com/input-output-hk/cardano-cli/blob/smelc/fix-new-committee-parser/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs#L328 In this position, we should likely pass a prefix, because the pAnyStakeIdentifier parser is used twice, and so is likely ambiguous.

@smelc smelc marked this pull request as ready for review September 21, 2023 14:41
@smelc smelc force-pushed the smelc/fix-new-committee-parser branch from c457776 to 46fb3fa Compare September 21, 2023 14:47
<*> pProposalUrl
<*> pProposalHashSource
<*> many pAnyStakeIdentifier
<*> many ((,) <$> pAnyStakeIdentifier <*> pEpochNo "Committee member expiry epoch")
<*> many (pAnyStakeIdentifier (Just "remove-cc"))
Copy link
Contributor

@carbolymer carbolymer Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use IsString here:

instance IsString a => IsString (Maybe a) where fromString = Just . fromString

this way we could just write "remove-cc" instead without Just

Copy link
Contributor Author

@smelc smelc Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, generally speaking, this instance looks surprising to me (in other words: I'd be surprised to have in my context 🙂).

Also the occurrences of Just "prefix" are actually quite rare, most of this PR is just passing the prefix in context around.

<*> pProposalUrl
<*> pProposalHashSource
<*> many ((,) <$> pAnyStakeIdentifier <*> pTransferAmt)
<*> many ((,) <$> pAnyStakeIdentifier Nothing <*> pTransferAmt) -- TODO we should likely pass a prefix here, becaus pAnyStakeIdentiefier is used twice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think this should be included in this pr.

Copy link
Contributor Author

@smelc smelc Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do a separate PR, because it's a different command. I can do this other PR soon after this one is merged.

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but get an approval from @CarlosLopezDeLara and @Jimbo4350 or @newhoggy too

@smelc smelc force-pushed the smelc/fix-new-committee-parser branch from 46fb3fa to 783fb14 Compare September 21, 2023 16:12
@CarlosLopezDeLara
Copy link
Contributor

I can confirm that this resolved the parsing issue.

@CarlosLopezDeLara
Copy link
Contributor

@CarlosLopezDeLara> while doing this PR, I realized we likely have the same kind of problem for create-treasury-withdrawal. This is visible here in this PR: https://github.com/input-output-hk/cardano-cli/blob/smelc/fix-new-committee-parser/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs#L328 In this position, we should likely pass a prefix, because the pAnyStakeIdentifier parser is used twice, and so is likely ambiguous.

Interestingly enough, it does not complain about this:

$CARDANO_CLI conway governance action create-treasury-withdrawal \
--testnet \
--governance-action-deposit 0 \
--stake-verification-key-file "${UTXO_DIR}/stake1.vkey" \
--proposal-url https://tinyurl.com/3wrwb2as \
--proposal-file  "${ROOT}/govActionJustification.txt" \
--stake-verification-key-file "${UTXO_DIR}/stake1.vkey" \
--transfer "${WITHDRAW_AMOUNT}" \
--out-file "${UTXO_DIR}/treasury.action" 

@CarlosLopezDeLara CarlosLopezDeLara added this pull request to the merge queue Sep 21, 2023
Merged via the queue into main with commit 093655e Sep 21, 2023
19 checks passed
@CarlosLopezDeLara CarlosLopezDeLara deleted the smelc/fix-new-committee-parser branch September 21, 2023 17:04
@smelc
Copy link
Contributor Author

smelc commented Sep 21, 2023

Interestingly enough, it does not complain about this

Weird 😵‍💫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants