Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAD-3723] Add progress to initial chain selection #3518

Merged
merged 7 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ import qualified Ouroboros.Network.AnchoredSeq as AS
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Storage.LedgerDB.Types
(UpdateLedgerDbTraceEvent (..))
import Ouroboros.Consensus.Storage.LedgerDB.Types (PushGoal (..),
Pushing (..), UpdateLedgerDbTraceEvent (..))
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util
import Ouroboros.Consensus.Util.CBOR (decodeWithOrigin)
Expand Down Expand Up @@ -437,16 +437,22 @@ ledgerDbPush cfg ap db =
applyBlock (ledgerDbCfg cfg) ap db

-- | Push a bunch of blocks (oldest first)
ledgerDbPushMany :: (ApplyBlock l blk, Monad m, c)
=> (UpdateLedgerDbTraceEvent blk -> m ())
-> LedgerDbCfg l
-> [Ap m l blk c] -> LedgerDB l -> m (LedgerDB l)
ledgerDbPushMany trace = repeatedlyM . pushAndTrace
ledgerDbPushMany ::
forall m c l blk . (ApplyBlock l blk, Monad m, c)
=> (UpdateLedgerDbTraceEvent blk -> m ())
-> LedgerDbCfg l
-> [Ap m l blk c] -> LedgerDB l -> m (LedgerDB l)
ledgerDbPushMany trace cfg aps initDb = (repeatedlyM pushAndTrace) aps initDb
EncodePanda marked this conversation as resolved.
Show resolved Hide resolved
where
pushAndTrace cfg ap db = do
trace $ StartedPushingBlockToTheLedgerDb $ toRealPoint ap
res <- ledgerDbPush cfg ap db
return res
pushAndTrace ap db = do
traceStep $ StartedPushingBlockToTheLedgerDb (Pushing $ toRealPoint ap)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something more direct (with the use of auxiliary mk functions)?

trace $ tartedPushingBlockToTheLedgerDb $ (mkPushing ap ) (mkPushGoal aps)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

ledgerDbPush cfg ap db

traceStep :: (PushGoal blk -> UpdateLedgerDbTraceEvent blk) -> m ()
traceStep step =
let goal = PushGoal . toRealPoint . last $ aps
event = step goal
in trace event

-- | Switch to a fork
ledgerDbSwitch :: (ApplyBlock l blk, Monad m, c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{-# LANGUAGE DeriveGeneric #-}
module Ouroboros.Consensus.Storage.LedgerDB.Types (UpdateLedgerDbTraceEvent (..)) where
module Ouroboros.Consensus.Storage.LedgerDB.Types (
PushGoal (..)
, Pushing (..)
, UpdateLedgerDbTraceEvent (..)
) where


import GHC.Generics (Generic)
Expand All @@ -8,7 +12,19 @@ import Ouroboros.Consensus.Block.RealPoint (RealPoint)
{-------------------------------------------------------------------------------
Trace events
-------------------------------------------------------------------------------}
newtype PushGoal blk = PushGoal { unPushGoal :: RealPoint blk }
deriving (Show, Eq)

newtype Pushing blk = Pushing { unPushing :: RealPoint blk }
deriving (Show, Eq)

data UpdateLedgerDbTraceEvent blk =
-- | Event fired when we are about to push a block to the LedgerDB
StartedPushingBlockToTheLedgerDb !(RealPoint blk)
StartedPushingBlockToTheLedgerDb
!(Pushing blk)
-- ^ point which block we are about to push
EncodePanda marked this conversation as resolved.
Show resolved Hide resolved
(PushGoal blk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a ! missing here?

-- ^ point to which we are updating the ledger, the last event
-- StartedPushingBlockToTheLedgerDb will have Pushing and PushGoal
-- wrapping over the same RealPoint
deriving (Show, Eq, Generic)