@@ -26,18 +26,11 @@ import Cardano.Logging
26
26
import Cardano.Prelude
27
27
import Data.Aeson
28
28
import Data.Time.Clock
29
+ import Data.Time.Clock.POSIX
29
30
30
- import Cardano.Api.Protocol.Types (BlockType (.. ), protocolInfo )
31
- import qualified Cardano.Ledger.Shelley.API as SL
32
31
import Cardano.Node.Protocol.Types (SomeConsensusProtocol (.. ))
33
32
import qualified Ouroboros.Consensus.Block.RealPoint as RP
34
- import Ouroboros.Consensus.Cardano.Block
35
- import Ouroboros.Consensus.Cardano.CanHardFork (shelleyLedgerConfig )
36
- import qualified Ouroboros.Consensus.Config as Consensus
37
- import Ouroboros.Consensus.HardFork.Combinator.Degenerate
38
33
import qualified Ouroboros.Consensus.Node.NetworkProtocolVersion as NPV
39
- import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (.. ))
40
- import Ouroboros.Consensus.Shelley.Ledger.Ledger
41
34
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
42
35
import Ouroboros.Consensus.Storage.ImmutableDB.Chunks.Internal
43
36
import qualified Ouroboros.Consensus.Storage.LedgerDB.OnDisk as LgrDb
@@ -165,7 +158,7 @@ traceNodeStateChainDB
165
158
-> Trace IO NodeState
166
159
-> ChainDB. TraceEvent blk
167
160
-> IO ()
168
- traceNodeStateChainDB scp tr ev =
161
+ traceNodeStateChainDB _scp tr ev =
169
162
case ev of
170
163
ChainDB. TraceOpenEvent ev' ->
171
164
case ev' of
@@ -201,12 +194,13 @@ traceNodeStateChainDB scp tr ev =
201
194
case ev' of
202
195
ChainDB. AddedToCurrentChain _ (ChainDB. NewTipInfo currentTip ntEpoch sInEpoch _) _ _ -> do
203
196
-- The slot of the latest block consumed (our progress).
204
- let RP. RealPoint slotSinceSystemStart _ = currentTip
197
+ let RP. RealPoint ourSlotSinceSystemStart _ = currentTip
205
198
-- The slot corresponding to the latest wall-clock time (our target).
206
- slotNow <- getSlotForNow scp slotSinceSystemStart
199
+ slotSinceSystemStart <- getSlotForNow
207
200
let syncProgressPct :: SyncPercentage
208
- syncProgressPct =
209
- (fromIntegral (unSlotNo slotSinceSystemStart) / fromIntegral (unSlotNo slotNow)) * 100.0
201
+ syncProgressPct = ( fromIntegral (unSlotNo ourSlotSinceSystemStart)
202
+ / fromIntegral (unSlotNo slotSinceSystemStart)
203
+ ) * 100.0
210
204
traceWith tr $ NodeAddBlock $
211
205
AddedToCurrentChain ntEpoch (SlotNo sInEpoch) syncProgressPct
212
206
_ -> return ()
@@ -242,32 +236,15 @@ traceNodeStateShutdown tr = traceWith tr . NodeShutdown
242
236
243
237
-- Misc.
244
238
245
- getSlotForNow
246
- :: SomeConsensusProtocol
247
- -> SlotNo
248
- -> IO SlotNo
249
- getSlotForNow (SomeConsensusProtocol whichP pInfo) s = do
250
- now <- getCurrentTime
251
- let cfg = pInfoConfig $ protocolInfo pInfo
252
- case whichP of
253
- ShelleyBlockType -> do
254
- let DegenLedgerConfig cfgShelley = Consensus. configLedger cfg
255
- nowSinceSystemStart = now `diffUTCTime` getSystemStartTime cfgShelley
256
- return . SlotNo $ floor nowSinceSystemStart
257
- CardanoBlockType -> do
258
- let CardanoLedgerConfig _ cfgShelley cfgAllegra cfgMary
259
- cfgAlonzo cfgBabbage =
260
- Consensus. configLedger cfg
261
- latestNowSinceSystemStart = minimum
262
- [ now `diffUTCTime` getSystemStartTime cfgShelley
263
- , now `diffUTCTime` getSystemStartTime cfgAllegra
264
- , now `diffUTCTime` getSystemStartTime cfgMary
265
- , now `diffUTCTime` getSystemStartTime cfgAlonzo
266
- , now `diffUTCTime` getSystemStartTime cfgBabbage
267
- ]
268
- return . SlotNo $ floor latestNowSinceSystemStart
269
- _ ->
270
- -- It is assumed that Byron isn't used already.
271
- return s
239
+ getSlotForNow :: IO SlotNo
240
+ getSlotForNow = do
241
+ posixNow <- utc2s <$> getCurrentTime
242
+ -- Since Shelley era the slot length is 1 second, so the number of seconds is the number of slots.
243
+ let numberOfSlotsFromShelleyTillNow = posixNow - posixStartOfShelleyEra
244
+ totalNumberOfSlotsTillNow = numberOfSlotsInByronEra + numberOfSlotsFromShelleyTillNow
245
+ return $ SlotNo totalNumberOfSlotsTillNow
272
246
where
273
- getSystemStartTime = SL. sgSystemStart . shelleyLedgerGenesis . shelleyLedgerConfig
247
+ -- These numbers are taken from 'First-Block-of-Each-Era' wiki page.
248
+ posixStartOfShelleyEra = 1596073491
249
+ numberOfSlotsInByronEra = 4492799
250
+ utc2s = fromInteger . round . utcTimeToPOSIXSeconds
0 commit comments