Skip to content

Commit 838a241

Browse files
committed
Add support to obtain start time from Byron genesis file
1 parent 8ef0d86 commit 838a241

12 files changed

+66
-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

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

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

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,14 @@ pMustExtendEraHistorySafeZone =
418418
)
419419
<|> pure DoNotExtendSafeZone
420420

421-
pSystemStart :: Parser SystemStart
422-
pSystemStart = systemStartUTC <|> systemStartPOSIX
421+
pSystemStart :: Parser SystemStartOrGenesisFile
422+
pSystemStart =
423+
(SystemStartLiteral <$> (systemStartUTC <|> systemStartPOSIX))
424+
<|> ( SystemStartFromGenesisFile . GenesisFile
425+
<$> parseFilePath
426+
"start-time-from-byron-genesis-file"
427+
"Path to the Byron genesis file from which to get the start time."
428+
)
423429

424430
systemStartPOSIX :: Parser SystemStart
425431
systemStartPOSIX =

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ runTransactionCalculatePlutusScriptCostCmd
16931693
& onLeft (left . TxCmdQueryConvenienceError)
16941694
TransactionContextInfo
16951695
( TransactionContext
1696-
{ systemStart
1696+
{ systemStartSource
16971697
, mustExtendSafeZone
16981698
, eraHistoryFile
16991699
, utxoFile
@@ -1702,7 +1702,7 @@ runTransactionCalculatePlutusScriptCostCmd
17021702
) -> do
17031703
buildTransactionContext
17041704
sbe
1705-
systemStart
1705+
systemStartSource
17061706
mustExtendSafeZone
17071707
eraHistoryFile
17081708
utxoFile
@@ -1775,7 +1775,7 @@ runTransactionCalculatePlutusScriptCostCmd
17751775

17761776
buildTransactionContext
17771777
:: ShelleyBasedEra era
1778-
-> SystemStart
1778+
-> SystemStartOrGenesisFile
17791779
-> MustExtendSafeZone
17801780
-> File EraHistory In
17811781
-> FilePath
@@ -1784,14 +1784,20 @@ buildTransactionContext
17841784
TxCmdError
17851785
IO
17861786
(AnyCardanoEra, SystemStart, EraHistory, UTxO era, LedgerProtocolParameters era)
1787-
buildTransactionContext sbe systemStart mustUnsafeExtendSafeZone eraHistoryFile utxoFile protocolParamsFile =
1787+
buildTransactionContext sbe systemStartOrGenesisFile mustUnsafeExtendSafeZone eraHistoryFile utxoFile protocolParamsFile =
17881788
shelleyBasedEraConstraints sbe $ do
17891789
ledgerPParams <-
17901790
firstExceptT TxCmdProtocolParamsError $ readProtocolParameters sbe protocolParamsFile
17911791
EraHistory interpreter <-
17921792
onLeft (left . TxCmdTextEnvError) $
17931793
liftIO $
17941794
readFileTextEnvelope (proxyToAsType (error "Proxy type for EraHistory evaluated")) eraHistoryFile
1795+
systemStart <- case systemStartOrGenesisFile of
1796+
SystemStartLiteral systemStart -> return systemStart
1797+
SystemStartFromGenesisFile (GenesisFile byronGenesisFile) -> do
1798+
(byronGenesisData, _) <- firstExceptT TxCmdGenesisDataError $ Byron.readGenesisData byronGenesisFile
1799+
let systemStartUTCTime = Byron.gdStartTime byronGenesisData
1800+
return $ SystemStart systemStartUTCTime
17951801
utxosBytes <- handleIOExceptT (TxCmdUTxOFileError . FileIOError utxoFile) $ BS.readFile utxoFile
17961802
utxos <- firstExceptT TxCmdUTxOJSONError $ ExceptT (return $ Aeson.eitherDecodeStrict' utxosBytes)
17971803
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,7 @@ Usage: cardano-cli shelley transaction calculate-min-required-utxo --protocol-pa
20422042
Usage: cardano-cli shelley transaction calculate-plutus-script-cost
20432043
( ( --start-time-utc UTC-TIME
20442044
| --start-time-posix POSIX-TIME
2045+
| --start-time-from-byron-genesis-file FILEPATH
20452046
)
20462047
[--unsafe-extend-safe-zone]
20472048
--era-history-file FILEPATH
@@ -3146,6 +3147,7 @@ Usage: cardano-cli allegra transaction calculate-min-required-utxo --protocol-pa
31463147
Usage: cardano-cli allegra transaction calculate-plutus-script-cost
31473148
( ( --start-time-utc UTC-TIME
31483149
| --start-time-posix POSIX-TIME
3150+
| --start-time-from-byron-genesis-file FILEPATH
31493151
)
31503152
[--unsafe-extend-safe-zone]
31513153
--era-history-file FILEPATH
@@ -4230,6 +4232,7 @@ Usage: cardano-cli mary transaction calculate-min-required-utxo --protocol-param
42304232
Usage: cardano-cli mary transaction calculate-plutus-script-cost
42314233
( ( --start-time-utc UTC-TIME
42324234
| --start-time-posix POSIX-TIME
4235+
| --start-time-from-byron-genesis-file FILEPATH
42334236
)
42344237
[--unsafe-extend-safe-zone]
42354238
--era-history-file FILEPATH
@@ -5339,6 +5342,7 @@ Usage: cardano-cli alonzo transaction calculate-min-required-utxo --protocol-par
53395342
Usage: cardano-cli alonzo transaction calculate-plutus-script-cost
53405343
( ( --start-time-utc UTC-TIME
53415344
| --start-time-posix POSIX-TIME
5345+
| --start-time-from-byron-genesis-file FILEPATH
53425346
)
53435347
[--unsafe-extend-safe-zone]
53445348
--era-history-file FILEPATH
@@ -6749,6 +6753,7 @@ Usage: cardano-cli babbage transaction calculate-min-required-utxo --protocol-pa
67496753
Usage: cardano-cli babbage transaction calculate-plutus-script-cost
67506754
( ( --start-time-utc UTC-TIME
67516755
| --start-time-posix POSIX-TIME
6756+
| --start-time-from-byron-genesis-file FILEPATH
67526757
)
67536758
[--unsafe-extend-safe-zone]
67546759
--era-history-file FILEPATH
@@ -8876,6 +8881,7 @@ Usage: cardano-cli conway transaction calculate-min-required-utxo --protocol-par
88768881
Usage: cardano-cli conway transaction calculate-plutus-script-cost
88778882
( ( --start-time-utc UTC-TIME
88788883
| --start-time-posix POSIX-TIME
8884+
| --start-time-from-byron-genesis-file FILEPATH
88798885
)
88808886
[--unsafe-extend-safe-zone]
88818887
--era-history-file FILEPATH
@@ -11003,6 +11009,7 @@ Usage: cardano-cli latest transaction calculate-min-required-utxo --protocol-par
1100311009
Usage: cardano-cli latest transaction calculate-plutus-script-cost
1100411010
( ( --start-time-utc UTC-TIME
1100511011
| --start-time-posix POSIX-TIME
11012+
| --start-time-from-byron-genesis-file FILEPATH
1100611013
)
1100711014
[--unsafe-extend-safe-zone]
1100811015
--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)