Skip to content

Commit

Permalink
Error when costmodel is empty in create-update-proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 14, 2023
1 parent 60529cc commit 59f6751
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- **Breaking change** - `deserialiseFromRawBytes` method of the `SerialiseAsRawBytes` type class to return `Either` instead of `Maybe`. Deprecate `eitherDeserialiseFromRawBytes`. Use `deserialiseFromRawBytes` instead.

- The `cardano-cli governance create-update-proposal` command to reject empty cost model.

### Bugs

- Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384))
Expand Down
14 changes: 10 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT
onLeft)
import Data.Aeson (eitherDecode)
import qualified Data.ByteString.Lazy as LB
import Data.Function ((&))
import qualified Data.List as List
import Data.Text (Text)
import qualified Data.Text as Text

Expand All @@ -21,9 +23,8 @@ import Cardano.CLI.Shelley.Key (VerificationKeyOrHashOrFile,
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Types

import Cardano.Ledger.Alonzo.Scripts (CostModels (..))
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
import Control.Monad.IO.Unlift (MonadIO (..))
import Data.Function ((&))


data ShelleyGovernanceCmdError
Expand All @@ -39,6 +40,7 @@ data ShelleyGovernanceCmdError
!Int
-- ^ Number of reward amounts
| ShelleyGovernanceCmdCostModelsJsonDecodeErr !FilePath !Text
| ShelleyGovernanceCmdEmptyCostModel !FilePath
deriving Show

renderShelleyGovernanceError :: ShelleyGovernanceCmdError -> Text
Expand All @@ -55,8 +57,10 @@ renderShelleyGovernanceError err =
<> " The number of staking keys: " <> textShow numVKeys
<> " and the number of reward amounts: " <> textShow numRwdAmts
<> " are not equivalent."
ShelleyGovernanceCmdCostModelsJsonDecodeErr err' fp ->
"Error decoding cost model: " <> Text.pack err' <> " at: " <> fp
ShelleyGovernanceCmdCostModelsJsonDecodeErr fp err' ->
"Error decoding cost model: " <> err' <> " at: " <> Text.pack fp
ShelleyGovernanceCmdEmptyCostModel fp ->
"The decoded cost model was empty at: " <> Text.pack fp
ShelleyGovernanceCmdCostModelReadError err' ->
"Error reading the cost model: " <> Text.pack (displayError err')

Expand Down Expand Up @@ -163,6 +167,8 @@ runGovernanceUpdateProposal (OutputFile upFile) eNo genVerKeyFiles upPprams mCos
cModels <- pure (eitherDecode costModelsBs)
& onLeft (left . ShelleyGovernanceCmdCostModelsJsonDecodeErr fp . Text.pack)

when (List.null (unCostModels cModels)) $ left (ShelleyGovernanceCmdEmptyCostModel fp)

return $ upPprams {protocolUpdateCostModels = fromAlonzoCostModels cModels}

when (finalUpPprams == mempty) $ left ShelleyGovernanceCmdEmptyUpdateProposalError
Expand Down
5 changes: 0 additions & 5 deletions update.proposal

This file was deleted.

0 comments on commit 59f6751

Please sign in to comment.