Skip to content

Commit 0cc002a

Browse files
committed
Add support to obtain start time from Byron genesis file
1 parent 5ec3b1a commit 0cc002a

12 files changed

+61
-7
lines changed

cardano-cli/src/Cardano/CLI/EraBased/Transaction/Command.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Cardano.CLI.EraBased.Transaction.Command
2323
, NodeContextInfo (..)
2424
, TransactionContext (..)
2525
, MustExtendSafeZone (..)
26+
, SystemStartOrGenesisFile (..)
2627
)
2728
where
2829

@@ -263,13 +264,18 @@ data NodeContextInfo
263264
-- | Transaction context, requried to evaluate the execution
264265
-- costs of the plutus scripts in the transaction.
265266
data TransactionContext = TransactionContext
266-
{ systemStart :: SystemStart
267+
{ systemStartSource :: SystemStartOrGenesisFile
267268
, mustExtendSafeZone :: MustExtendSafeZone
268269
, eraHistoryFile :: File EraHistory In
269270
, utxoFile :: FilePath
270271
, protocolParamsFile :: ProtocolParamsFile
271272
}
272273

274+
-- | The system start time or a means to get it (the genesis file)
275+
data SystemStartOrGenesisFile
276+
= SystemStartLiteral !SystemStart
277+
| SystemStartFromGenesisFile !GenesisFile
278+
273279
-- | Whether the safe zone for the era history must be respected
274280
-- when evaluating the execution costs of the plutus scripts in the transaction.
275281
--

cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,14 @@ pMustExtendEraHistorySafeZone =
432432
)
433433
<|> pure DoNotExtendSafeZone
434434

435-
pSystemStart :: Parser SystemStart
436-
pSystemStart = systemStartUTC <|> systemStartPOSIX
435+
pSystemStart :: Parser SystemStartOrGenesisFile
436+
pSystemStart =
437+
(SystemStartLiteral <$> (systemStartUTC <|> systemStartPOSIX))
438+
<|> ( SystemStartFromGenesisFile . GenesisFile
439+
<$> parseFilePath
440+
"start-time-from-byron-genesis-file"
441+
"Path to the Byron genesis file from which to get the start time."
442+
)
437443

438444
systemStartPOSIX :: Parser SystemStart
439445
systemStartPOSIX =

cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ runTransactionCalculatePlutusScriptCostCmd
16971697
& onLeft (left . TxCmdQueryConvenienceError)
16981698
TransactionContextInfo
16991699
( TransactionContext
1700-
{ systemStart
1700+
{ systemStartSource
17011701
, mustExtendSafeZone
17021702
, eraHistoryFile
17031703
, utxoFile
@@ -1706,7 +1706,7 @@ runTransactionCalculatePlutusScriptCostCmd
17061706
) -> do
17071707
buildTransactionContext
17081708
sbe
1709-
systemStart
1709+
systemStartSource
17101710
mustExtendSafeZone
17111711
eraHistoryFile
17121712
utxoFile
@@ -1779,7 +1779,7 @@ runTransactionCalculatePlutusScriptCostCmd
17791779

17801780
buildTransactionContext
17811781
:: ShelleyBasedEra era
1782-
-> SystemStart
1782+
-> SystemStartOrGenesisFile
17831783
-> MustExtendSafeZone
17841784
-> File EraHistory In
17851785
-> FilePath
@@ -1788,14 +1788,20 @@ buildTransactionContext
17881788
TxCmdError
17891789
IO
17901790
(AnyCardanoEra, SystemStart, EraHistory, UTxO era, LedgerProtocolParameters era)
1791-
buildTransactionContext sbe systemStart mustUnsafeExtendSafeZone eraHistoryFile utxoFile protocolParamsFile =
1791+
buildTransactionContext sbe systemStartOrGenesisFile mustUnsafeExtendSafeZone eraHistoryFile utxoFile protocolParamsFile =
17921792
shelleyBasedEraConstraints sbe $ do
17931793
ledgerPParams <-
17941794
firstExceptT TxCmdProtocolParamsError $ readProtocolParameters sbe protocolParamsFile
17951795
EraHistory interpreter <-
17961796
onLeft (left . TxCmdTextEnvError) $
17971797
liftIO $
17981798
readFileTextEnvelope (proxyToAsType (error "Proxy type for EraHistory evaluated")) eraHistoryFile
1799+
systemStart <- case systemStartOrGenesisFile of
1800+
SystemStartLiteral systemStart -> return systemStart
1801+
SystemStartFromGenesisFile (GenesisFile byronGenesisFile) -> do
1802+
(byronGenesisData, _) <- firstExceptT TxCmdGenesisDataError $ Byron.readGenesisData byronGenesisFile
1803+
let systemStartUTCTime = Byron.gdStartTime byronGenesisData
1804+
return $ SystemStart systemStartUTCTime
17991805
utxosBytes <- handleIOExceptT (TxCmdUTxOFileError . FileIOError utxoFile) $ BS.readFile utxoFile
18001806
utxos <- firstExceptT TxCmdUTxOJSONError $ ExceptT (return $ Aeson.eitherDecodeStrict' utxosBytes)
18011807
let eraHistory = EraHistory $ case mustUnsafeExtendSafeZone of

cardano-cli/src/Cardano/CLI/Type/Error/TxCmdError.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Cardano.CLI.Type.Error.TxCmdError
1515
where
1616

1717
import Cardano.Api
18+
import Cardano.Api.Byron (GenesisDataError)
1819
import Cardano.Api.Consensus (EraMismatch (..))
1920
import Cardano.Api.Ledger qualified as L
2021
import Cardano.Api.Shelley
@@ -35,6 +36,8 @@ import Cardano.Prelude qualified as List
3536

3637
import Data.Set (Set)
3738
import Data.Text (Text)
39+
import Data.Text.Lazy.Builder (toLazyText)
40+
import Formatting.Buildable (Buildable (build))
3841

3942
{- HLINT ignore "Use let" -}
4043

@@ -96,6 +99,7 @@ data TxCmdError
9699
| forall era. TxCmdAlonzoEraOnwardsRequired !(CardanoEra era)
97100
| TxCmdUTxOFileError !(FileError JsonDecodeError)
98101
| TxCmdUTxOJSONError String
102+
| TxCmdGenesisDataError GenesisDataError
99103

100104
instance Show TxCmdError where
101105
show = show . renderTxCmdError
@@ -251,6 +255,8 @@ renderTxCmdError = \case
251255
"Error while reading UTxO set from JSON file: " <> prettyError e
252256
TxCmdUTxOJSONError e ->
253257
"Error while reading UTxO set from JSON file: " <> pretty e
258+
TxCmdGenesisDataError genesisDataError ->
259+
"Error while reading Byron genesis data: " <> pshow (toLazyText $ build genesisDataError)
254260

255261
prettyPolicyIdList :: [PolicyId] -> Doc ann
256262
prettyPolicyIdList =

cardano-cli/test/cardano-cli-golden/files/golden/help.cli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,7 @@ Usage: cardano-cli conway transaction calculate-min-required-utxo --protocol-par
31263126
Usage: cardano-cli conway transaction calculate-plutus-script-cost
31273127
( ( --start-time-utc UTC-TIME
31283128
| --start-time-posix POSIX-TIME
3129+
| --start-time-from-byron-genesis-file FILEPATH
31293130
)
31303131
[--unsafe-extend-safe-zone]
31313132
--era-history-file FILEPATH
@@ -5296,6 +5297,7 @@ Usage: cardano-cli latest transaction calculate-min-required-utxo --protocol-par
52965297
Usage: cardano-cli latest transaction calculate-plutus-script-cost
52975298
( ( --start-time-utc UTC-TIME
52985299
| --start-time-posix POSIX-TIME
5300+
| --start-time-from-byron-genesis-file FILEPATH
52995301
)
53005302
[--unsafe-extend-safe-zone]
53015303
--era-history-file FILEPATH

cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_calculate-plutus-script-cost.cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Usage: cardano-cli allegra transaction calculate-plutus-script-cost
22
( ( --start-time-utc UTC-TIME
33
| --start-time-posix POSIX-TIME
4+
| --start-time-from-byron-genesis-file FILEPATH
45
)
56
[--unsafe-extend-safe-zone]
67
--era-history-file FILEPATH
@@ -24,6 +25,9 @@ Available options:
2425
format.
2526
--start-time-posix POSIX-TIME
2627
The genesis start time as POSIX seconds.
28+
--start-time-from-byron-genesis-file FILEPATH
29+
Path to the Byron genesis file from which to get the
30+
start time.
2731
--unsafe-extend-safe-zone
2832
Allow extending the validity of the era history past
2933
the safe zone. The safe zone is a period of time

cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_calculate-plutus-script-cost.cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Usage: cardano-cli alonzo transaction calculate-plutus-script-cost
22
( ( --start-time-utc UTC-TIME
33
| --start-time-posix POSIX-TIME
4+
| --start-time-from-byron-genesis-file FILEPATH
45
)
56
[--unsafe-extend-safe-zone]
67
--era-history-file FILEPATH
@@ -24,6 +25,9 @@ Available options:
2425
format.
2526
--start-time-posix POSIX-TIME
2627
The genesis start time as POSIX seconds.
28+
--start-time-from-byron-genesis-file FILEPATH
29+
Path to the Byron genesis file from which to get the
30+
start time.
2731
--unsafe-extend-safe-zone
2832
Allow extending the validity of the era history past
2933
the safe zone. The safe zone is a period of time

cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_calculate-plutus-script-cost.cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Usage: cardano-cli babbage transaction calculate-plutus-script-cost
22
( ( --start-time-utc UTC-TIME
33
| --start-time-posix POSIX-TIME
4+
| --start-time-from-byron-genesis-file FILEPATH
45
)
56
[--unsafe-extend-safe-zone]
67
--era-history-file FILEPATH
@@ -24,6 +25,9 @@ Available options:
2425
format.
2526
--start-time-posix POSIX-TIME
2627
The genesis start time as POSIX seconds.
28+
--start-time-from-byron-genesis-file FILEPATH
29+
Path to the Byron genesis file from which to get the
30+
start time.
2731
--unsafe-extend-safe-zone
2832
Allow extending the validity of the era history past
2933
the safe zone. The safe zone is a period of time

cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_calculate-plutus-script-cost.cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Usage: cardano-cli conway transaction calculate-plutus-script-cost
22
( ( --start-time-utc UTC-TIME
33
| --start-time-posix POSIX-TIME
4+
| --start-time-from-byron-genesis-file FILEPATH
45
)
56
[--unsafe-extend-safe-zone]
67
--era-history-file FILEPATH
@@ -24,6 +25,9 @@ Available options:
2425
format.
2526
--start-time-posix POSIX-TIME
2627
The genesis start time as POSIX seconds.
28+
--start-time-from-byron-genesis-file FILEPATH
29+
Path to the Byron genesis file from which to get the
30+
start time.
2731
--unsafe-extend-safe-zone
2832
Allow extending the validity of the era history past
2933
the safe zone. The safe zone is a period of time

cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_calculate-plutus-script-cost.cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Usage: cardano-cli latest transaction calculate-plutus-script-cost
22
( ( --start-time-utc UTC-TIME
33
| --start-time-posix POSIX-TIME
4+
| --start-time-from-byron-genesis-file FILEPATH
45
)
56
[--unsafe-extend-safe-zone]
67
--era-history-file FILEPATH
@@ -24,6 +25,9 @@ Available options:
2425
format.
2526
--start-time-posix POSIX-TIME
2627
The genesis start time as POSIX seconds.
28+
--start-time-from-byron-genesis-file FILEPATH
29+
Path to the Byron genesis file from which to get the
30+
start time.
2731
--unsafe-extend-safe-zone
2832
Allow extending the validity of the era history past
2933
the safe zone. The safe zone is a period of time

0 commit comments

Comments
 (0)