Skip to content

Commit

Permalink
Merge #4912 #4915 #4922
Browse files Browse the repository at this point in the history
4912: Add slotsInEpoch and slotsToEpochEnd to query tip command r=newhoggy a=newhoggy

Example output:

```
CARDANO_NODE_SOCKET_PATH=example/node-pool1/node.sock cardano-cli query tip --testnet-magic 42
{
    "block": 768,
    "epoch": 33,
    "era": "Alonzo",
    "hash": "4ca7fd3a9827e74f98e779a8ae333dc6fa3b69832cb11fdbab7af215eb68b1ee",
    "slot": 16814,
    "slotsInEpoch": 314,
    "slotsToEpochEnd": 186,
    "syncProgress": "100.00"
}
```

Resolves #3878


4915: Tip hash metrics r=newhoggy a=newhoggy

Salvaging this PR #2006

Related to #801


4922: Deploy Haddock for merge to master only r=newhoggy a=newhoggy

To merge changes from this PR #3012

Co-authored-by: John Ky <[email protected]>
Co-authored-by: Luke Nadur <[email protected]>
Co-authored-by: James Browning <[email protected]>
  • Loading branch information
4 people authored Mar 1, 2023
4 parents 3b21b2d + fbb1f0d + 57612b7 + 44216e6 commit 8461bf8
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/github-page.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: "Haddock documentation"

on: [push]
on:
push:
branches:
- master

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Allow assembling transactions with no witnesses ([PR 4408](https://github.com/input-output-hk/cardano-node/pull/4408))

- Add `slotsInEpoch` and `slotsToEpochEnd` to output of `query tip` command ([PR 4912](https://github.com/input-output-hk/cardano-node/pull/4912))

### Bugs

- Allow reading signing keys from a pipe ([PR 4342](https://github.com/input-output-hk/cardano-node/pull/4342))
Expand Down
16 changes: 16 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ data QueryTipLocalStateOutput = QueryTipLocalStateOutput
{ localStateChainTip :: ChainTip
, mEra :: Maybe AnyCardanoEra
, mEpoch :: Maybe EpochNo
, mSlotsInEpoch :: Maybe Word64
, mSlotsToEpochEnd :: Maybe Word64
, mSyncProgress :: Maybe Text
} deriving Show

Expand All @@ -169,6 +171,8 @@ instance ToJSON QueryTipLocalStateOutput where
object $
( ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotsInEpoch" ..=? mSlotsInEpoch a)
. ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a)
. ("syncProgress" ..=? mSyncProgress a)
) []
ChainTip slotNo blockHeader blockNo ->
Expand All @@ -178,13 +182,17 @@ instance ToJSON QueryTipLocalStateOutput where
. ("block" ..= blockNo)
. ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotsInEpoch" ..=? mSlotsInEpoch a)
. ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a)
. ("syncProgress" ..=? mSyncProgress a)
) []
toEncoding a = case localStateChainTip a of
ChainTipAtGenesis ->
pairs $ mconcat $
( ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotsInEpoch" ..=? mSlotsInEpoch a)
. ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a)
. ("syncProgress" ..=? mSyncProgress a)
) []
ChainTip slotNo blockHeader blockNo ->
Expand All @@ -194,6 +202,8 @@ instance ToJSON QueryTipLocalStateOutput where
. ("block" ..= blockNo)
. ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotsInEpoch" ..=? mSlotsInEpoch a)
. ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a)
. ("syncProgress" ..=? mSyncProgress a)
) []

Expand All @@ -206,18 +216,24 @@ instance FromJSON QueryTipLocalStateOutput where
mSlot <- o .:? "slot"
mHash <- o .:? "hash"
mBlock <- o .:? "block"
mSlotsInEpoch' <- o .:? "slotsInEpoch"
mSlotsToEpochEnd' <- o .:? "slotsToEpochEnd"
case (mSlot, mHash, mBlock) of
(Nothing, Nothing, Nothing) ->
pure $ QueryTipLocalStateOutput
ChainTipAtGenesis
mEra'
mEpoch'
mSlotsInEpoch'
mSlotsToEpochEnd'
mSyncProgress'
(Just slot, Just hash, Just block) ->
pure $ QueryTipLocalStateOutput
(ChainTip slot hash block)
mEra'
mEpoch'
mSlotsInEpoch'
mSlotsToEpochEnd'
mSyncProgress'
(_,_,_) ->
fail $ mconcat
Expand Down
6 changes: 5 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,11 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do
, O.mEra = Nothing
, O.mEpoch = Nothing
, O.mSyncProgress = Nothing
, O.mSlotsInEpoch = Nothing
, O.mSlotsToEpochEnd = Nothing
}

Right (epochNo, _, _) -> do
Right (epochNo, SlotsInEpoch slotsInEpoch, SlotsToEpochEnd slotsToEpochEnd) -> do
syncProgressResult <- runExceptT $ do
systemStart <- fmap getSystemStart (O.mSystemStart localState) & hoistMaybe ShelleyQueryCmdSystemStartUnavailable
nowSeconds <- toRelativeTime (SystemStart systemStart) <$> liftIO getCurrentTime
Expand All @@ -359,6 +361,8 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do
{ O.localStateChainTip = chainTip
, O.mEra = Just (O.era localState)
, O.mEpoch = Just epochNo
, O.mSlotsInEpoch = Just slotsInEpoch
, O.mSlotsToEpochEnd = Just slotsToEpochEnd
, O.mSyncProgress = mSyncProgress
}

Expand Down
46 changes: 24 additions & 22 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,61 +70,62 @@ library
Cardano.Node.Handlers.Shutdown
Cardano.Node.Handlers.TopLevel
Cardano.Node.Orphans
Cardano.Node.Parsers
Cardano.Node.Protocol
Cardano.Node.Protocol.Alonzo
Cardano.Node.Protocol.Byron
Cardano.Node.Protocol.Cardano
Cardano.Node.Protocol.Shelley
Cardano.Node.Protocol.Types
Cardano.Node.Parsers
Cardano.Node.Queries
Cardano.Node.Run
Cardano.Node.STM
Cardano.Node.Startup
Cardano.Node.STM
Cardano.Node.TraceConstraints
Cardano.Node.Tracing
Cardano.Node.Types
Cardano.Node.Tracing.API
Cardano.Node.Tracing.Compat
Cardano.Node.Tracing.DefaultTraceConfig
Cardano.Node.Tracing.Documentation
Cardano.Node.Tracing.Era.Byron
Cardano.Node.Tracing.Era.HardFork
Cardano.Node.Tracing.Era.Shelley
Cardano.Node.Tracing.Formatting
Cardano.Node.Tracing.Peers
Cardano.Node.Tracing.Render
Cardano.Node.Tracing.StateRep
Cardano.Node.Tracing.Tracers
Cardano.Node.Tracing.Tracers.BlockReplayProgress
Cardano.Node.Tracing.Tracers.ChainDB
Cardano.Node.Tracing.Tracers.Consensus
Cardano.Node.Tracing.Tracers.ConsensusStartupException
Cardano.Node.Tracing.Tracers.Diffusion
Cardano.Node.Tracing.Tracers.KESInfo
Cardano.Node.Tracing.Tracers.StartLeadershipCheck
Cardano.Node.Tracing.Tracers.ForgingThreadStats
Cardano.Node.Tracing.Tracers.Resources
Cardano.Node.Tracing.Tracers.Peer
Cardano.Node.Tracing.Tracers.Startup
Cardano.Node.Tracing.Tracers.Shutdown
Cardano.Node.Tracing.Tracers.P2P
Cardano.Node.Tracing.Tracers.NonP2P
Cardano.Node.Tracing.Tracers.KESInfo
Cardano.Node.Tracing.Tracers.NodeToClient
Cardano.Node.Tracing.Tracers.NodeToNode
Cardano.Node.Tracing.Formatting
Cardano.Node.Tracing.Render
Cardano.Node.Tracing.Tracers.NonP2P
Cardano.Node.Tracing.Tracers.P2P
Cardano.Node.Tracing.Tracers.Peer
Cardano.Node.Tracing.Tracers.Resources
Cardano.Node.Tracing.Tracers.Shutdown
Cardano.Node.Tracing.Tracers.StartLeadershipCheck
Cardano.Node.Tracing.Tracers.Startup
Cardano.Node.Types
Cardano.Tracing.Config
Cardano.Tracing.HasIssuer
Cardano.Tracing.Metrics
Cardano.Tracing.Peer
Cardano.Tracing.Render
Cardano.Tracing.Startup
Cardano.Tracing.Shutdown
Cardano.Tracing.Tracers
Cardano.Tracing.OrphanInstances.Byron
Cardano.Tracing.OrphanInstances.Common
Cardano.Tracing.OrphanInstances.Consensus
Cardano.Tracing.OrphanInstances.HardFork
Cardano.Tracing.OrphanInstances.Network
Cardano.Tracing.OrphanInstances.Shelley
Cardano.Tracing.Peer
Cardano.Tracing.Render
Cardano.Tracing.Shutdown
Cardano.Tracing.Startup
Cardano.Tracing.Tracers

other-modules: Paths_cardano_node
autogen-modules: Paths_cardano_node
Expand All @@ -139,18 +140,19 @@ library
, cardano-git-rev
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger-core
, cardano-ledger-alonzo
, cardano-ledger-babbage
, cardano-ledger-byron
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-ledger-shelley-ma
, cardano-ledger-alonzo
, cardano-ledger-babbage
, cardano-prelude
, cardano-protocol-tpraos ^>= 0.1
, cardano-slotting ^>= 0.1
, cborg ^>= 0.2.4
, contra-tracer
, containers
, contra-tracer
, deepseq
, directory
, dns
Expand All @@ -159,9 +161,9 @@ library
, filepath
, generic-data
, hostname
, iproute
, io-classes ^>= 0.3
, iohk-monitoring
, iproute
, lobemo-backend-aggregation
, lobemo-backend-ekg
, lobemo-backend-monitoring
Expand Down
4 changes: 4 additions & 0 deletions cardano-node/src/Cardano/Node/TraceConstraints.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}

module Cardano.Node.TraceConstraints (TraceConstraints) where


Expand All @@ -10,6 +11,7 @@ import Cardano.BM.Tracing (ToObject)
import Cardano.Logging (LogFormatting)
import Cardano.Node.Queries (ConvertTxId, GetKESInfo (..), HasKESInfo (..),
HasKESMetricsData (..), LedgerQueries)
import Cardano.Tracing.HasIssuer (HasIssuer)

import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateUpdateError,
Header)
Expand All @@ -25,6 +27,8 @@ import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId)
-- | Tracing-related constraints for monitoring purposes.
type TraceConstraints blk =
( ConvertTxId blk
, HasIssuer blk
, HasKESMetricsData blk
, HasTxs blk
, HasTxId (GenTx blk)
, LedgerQueries blk
Expand Down
83 changes: 83 additions & 0 deletions cardano-node/src/Cardano/Tracing/HasIssuer.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}

module Cardano.Tracing.HasIssuer
( BlockIssuerVerificationKeyHash (..)
, HasIssuer (..)
) where

import Data.ByteString (ByteString)
import Data.SOP.Strict

import Cardano.Api (serialiseToRawBytes, verificationKeyHash)
import Cardano.Api.Byron (VerificationKey (ByronVerificationKey))
import Cardano.Api.Shelley (VerificationKey (StakePoolVerificationKey))
import qualified Cardano.Chain.Block as Byron
import Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.Shelley.API as Shelley

import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock, Header (..))
import Ouroboros.Consensus.HardFork.Combinator (HardForkBlock, Header (..),
OneEraHeader (..))
import Ouroboros.Consensus.Shelley.Ledger.Block (Header (..), ShelleyBlock)

import Ouroboros.Consensus.Shelley.Protocol.Abstract

-- | Block issuer verification key hash.
data BlockIssuerVerificationKeyHash
= BlockIssuerVerificationKeyHash !ByteString
-- ^ Serialized block issuer verification key hash.
| NoBlockIssuer
-- ^ There is no block issuer.
--
-- For example, this could be relevant for epoch boundary blocks (EBBs),
-- genesis blocks, etc.
deriving (Eq, Show)

-- | Get the block issuer verification key hash from a block header.
class HasIssuer blk where
-- | Given a block header, return the serialized block issuer verification
-- key hash.
getIssuerVerificationKeyHash :: Header blk -> BlockIssuerVerificationKeyHash

instance HasIssuer ByronBlock where
getIssuerVerificationKeyHash byronBlkHdr =
case byronHeaderRaw byronBlkHdr of
Byron.ABOBBlockHdr hdr ->
BlockIssuerVerificationKeyHash
. serialiseToRawBytes
. verificationKeyHash
. ByronVerificationKey
$ Byron.headerIssuer hdr
Byron.ABOBBoundaryHdr _ -> NoBlockIssuer

instance
( ProtoCrypto protocol ~ StandardCrypto
, ProtocolHeaderSupportsProtocol protocol
) => HasIssuer (ShelleyBlock protocol era) where
getIssuerVerificationKeyHash shelleyBlkHdr =
BlockIssuerVerificationKeyHash
. serialiseToRawBytes
. verificationKeyHash
. StakePoolVerificationKey
$ toStakePoolKey issuer
where
-- We don't support a "block issuer" key role in @cardano-api@, so we'll
-- just convert it to a stake pool key.
toStakePoolKey
:: Shelley.VKey 'Shelley.BlockIssuer era
-> Shelley.VKey 'Shelley.StakePool era
toStakePoolKey vk = Shelley.VKey (Shelley.unVKey vk)

issuer = pHeaderIssuer (shelleyHeaderRaw shelleyBlkHdr)

instance All HasIssuer xs => HasIssuer (HardForkBlock xs) where
getIssuerVerificationKeyHash =
hcollapse
. hcmap (Proxy @HasIssuer) (K . getIssuerVerificationKeyHash)
. getOneEraHeader
. getHardForkHeader
Loading

0 comments on commit 8461bf8

Please sign in to comment.