Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 13, 2021
1 parent fec2955 commit 6ac7b72
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Expand Up @@ -175,7 +175,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 13081b1cee1c3410e454c791a787f533d9fb7f92
tag: 789014bd5e613249fd0627fc5cf9d47aa3b0ce35
--sha256: 1vv40h3ljnyi67jy8mjj1bd97pjlb5lsc2praf92sdc132bqyzz7
subdir:
io-sim
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/src/Cardano/Api/IPC.hs
Expand Up @@ -391,7 +391,7 @@ convLocalNodeClientProtocols
localTxSubmissionClientForBlock = convLocalTxSubmissionClient mode <$>
localTxSubmissionClient,

localStateQueryClientForBlock = mapQueryOnLocalStateQueryClient Consensus.BlockQuery . convLocalStateQueryClient mode <$>
localStateQueryClientForBlock = mapQueryOnLocalStateQueryClient id . convLocalStateQueryClient mode <$>
localStateQueryClient
}

Expand Down Expand Up @@ -441,7 +441,7 @@ convLocalStateQueryClient
=> ConsensusMode mode
-> LocalStateQueryClient (BlockInMode mode) ChainPoint (QueryInMode mode) m a
-> LocalStateQueryClient block (Consensus.Point block)
(Consensus.BlockQuery block) m a
(Consensus.Query block) m a
convLocalStateQueryClient mode =
Net.Query.mapLocalStateQueryClient
(toConsensusPointInMode mode)
Expand Down
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/Query.hs
Expand Up @@ -453,6 +453,7 @@ fromConsensusQueryResult (QueryInEra ByronEraInByronMode
(Ledger.BlockQuery (Consensus.DegenQuery Consensus.GetUpdateInterfaceState),
Consensus.DegenQueryResult r'') ->
Right (ByronUpdateState r'')
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode
QueryByronUpdateState) q' r' =
Expand All @@ -470,6 +471,7 @@ fromConsensusQueryResult (QueryInEra ShelleyEraInShelleyMode
case (q', r') of
(Ledger.BlockQuery (Consensus.DegenQuery q''), Consensus.DegenQueryResult r'') ->
Right (fromConsensusQueryResultShelleyBased ShelleyBasedEraShelley q q'' r'')
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode
(QueryInShelleyBasedEra era _)) _ _ =
Expand Down
40 changes: 31 additions & 9 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Expand Up @@ -60,14 +60,31 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Type as LocalStateQu
(AcquireFailure (..))
import qualified Shelley.Spec.Ledger.API.Protocol as Ledger
import Cardano.Ledger.Coin
import Shelley.Spec.Ledger.EpochBoundary
import Shelley.Spec.Ledger.EpochBoundary
( SnapShot(SnapShot, _delegations, _stake),
SnapShots(SnapShots),
Stake(Stake, unStake),
poolStake )
import Shelley.Spec.Ledger.Keys (KeyHash (..), KeyRole (..))
import Shelley.Spec.Ledger.LedgerState hiding (_delegations)
import Shelley.Spec.Ledger.Scripts ()
import Text.Printf(printf)

import Data.SOP.Strict
import Cardano.Chain.Genesis
( Config(configGenesisData), GenesisData(gdStartTime) )
import Cardano.Slotting.Time
( SystemStart(getSystemStart))

import Ouroboros.Consensus.HardFork.Combinator.Basics
( HardForkLedgerConfig(..) )
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras
( PerEraLedgerConfig(getPerEraLedgerConfig) )
import Ouroboros.Consensus.HardFork.Combinator.PartialConfig
( WrapPartialLedgerConfig(unwrapPartialLedgerConfig) )
import Ouroboros.Consensus.Cardano.CanHardFork (ByronPartialLedgerConfig(..))

import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry
import qualified Ouroboros.Consensus.HardFork.Combinator.PartialConfig as PC

import qualified Data.Text.IO as T
import qualified System.IO as IO
Expand Down Expand Up @@ -223,6 +240,8 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do

systemStart <- mSystemStartQuery anyEra consensusMode localNodeConnInfo

systemStart2 <- mStartTime consensusMode localNodeConnInfo

nowSeconds <- toRelativeTime systemStart <$> liftIO getCurrentTime

let tolerance = RelativeTime (secondsToNominalDiffTime 600)
Expand All @@ -234,6 +253,8 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do
. toObject "tipTime" (Just jsonTipTime)
. toObject "now" (Just (relativeTimeSeconds nowSeconds))
. toObject "syncProgress" (Just jsonSyncProgress)
. toObject "systemStart1" (Just (getSystemStart systemStart))
. toObject "systemStart2" (Just systemStart2)
$ toJSON tip

case mOutFile of
Expand Down Expand Up @@ -261,19 +282,20 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do

mode -> left (ShelleyQueryCmdUnsupportedMode (AnyConsensusMode mode))

mPartialLedgerConfig
:: AnyCardanoEra
-> ConsensusMode mode
mStartTime
:: forall mode . ConsensusMode mode
-> LocalNodeConnectInfo mode
-> SlotNo
-> ExceptT ShelleyQueryCmdError IO (Either Qry.PastHorizonException (RelativeTime, SlotLength))
mPartialLedgerConfig _ cMode lNodeConnInfo slotNo = case cMode of
-> ExceptT ShelleyQueryCmdError IO UTCTime
mStartTime cMode lNodeConnInfo = case cMode of
CardanoMode -> do
let epochQuery = QueryPartialLedgerConfig CardanoModeIsMultiEra -- QueryInShelleyBasedEra sbe QueryEpoch
eResult <- liftIO $ queryNodeLocalState lNodeConnInfo Nothing epochQuery
case eResult of
Left acqFail -> left (ShelleyQueryCmdGeneric (show acqFail))
Right eraHistory -> return $ getProgress slotNo eraHistory
Right plc -> case getPerEraLedgerConfig (hardForkLedgerConfigPerEra (PC.unwrapPartialLedgerConfig plc)) of
perEraLedgerConfig -> case perEraLedgerConfig of
byronLC :* _ -> case byronLedgerConfig (unwrapPartialLedgerConfig byronLC) of
x -> return (gdStartTime (configGenesisData x))

mode -> left (ShelleyQueryCmdGeneric ("Not cardano mode: " <> show mode))

Expand Down

0 comments on commit 6ac7b72

Please sign in to comment.