-
Notifications
You must be signed in to change notification settings - Fork 86
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
Changes from 5 commits
b3902e5
8be9a23
eee455c
d2f234d
5c59ed7
68b9a6c
4a5633a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +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 (PushGoal (..), | ||
Pushing (..), UpdateLedgerDbTraceEvent (..)) | ||
import Ouroboros.Consensus.Ticked | ||
import Ouroboros.Consensus.Util | ||
import Ouroboros.Consensus.Util.CBOR (decodeWithOrigin) | ||
|
@@ -265,6 +267,13 @@ data Ap :: (Type -> Type) -> Type -> Type -> Constraint -> Type where | |
Internal utilities for 'Ap' | ||
-------------------------------------------------------------------------------} | ||
|
||
toRealPoint :: HasHeader blk => Ap m l blk c -> RealPoint blk | ||
toRealPoint (ReapplyVal blk) = blockRealPoint blk | ||
toRealPoint (ApplyVal blk) = blockRealPoint blk | ||
toRealPoint (ReapplyRef rp) = rp | ||
toRealPoint (ApplyRef rp) = rp | ||
toRealPoint (Weaken ap) = toRealPoint ap | ||
|
||
-- | Apply block to the current ledger state | ||
-- | ||
-- We take in the entire 'LedgerDB' because we record that as part of errors. | ||
|
@@ -428,27 +437,40 @@ ledgerDbPush cfg ap db = | |
applyBlock (ledgerDbCfg cfg) ap db | ||
|
||
-- | Push a bunch of blocks (oldest first) | ||
ledgerDbPushMany :: (ApplyBlock l blk, Monad m, c) | ||
=> LedgerDbCfg l | ||
-> [Ap m l blk c] -> LedgerDB l -> m (LedgerDB l) | ||
ledgerDbPushMany = repeatedlyM . ledgerDbPush | ||
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 ap db = do | ||
traceStep $ StartedPushingBlockToTheLedgerDb (Pushing $ toRealPoint ap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about something more direct (with the use of auxiliary trace $ tartedPushingBlockToTheLedgerDb $ (mkPushing ap ) (mkPushGoal aps) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
=> LedgerDbCfg l | ||
-> Word64 -- ^ How many blocks to roll back | ||
-> (UpdateLedgerDbTraceEvent blk -> m ()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In principle, this could be any action. I wonder if we want to be more specific and declare that this should actually be a tracer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, but at least debatable. Even though I follow your line of thought and you are right, in principle this could be any hook but: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nfrisby are you ok with doing this in separate PR so this one does not get polluted with too many concerns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for the the new field it should just be Edit: eg you could use |
||
-> [Ap m l blk c] -- ^ New blocks to apply | ||
-> LedgerDB l | ||
-> m (Either ExceededRollback (LedgerDB l)) | ||
ledgerDbSwitch cfg numRollbacks newBlocks db = | ||
ledgerDbSwitch cfg numRollbacks trace newBlocks db = | ||
case rollback numRollbacks db of | ||
Nothing -> | ||
return $ Left $ ExceededRollback { | ||
rollbackMaximum = ledgerDbMaxRollback db | ||
, rollbackRequested = numRollbacks | ||
} | ||
Just db' -> | ||
Right <$> ledgerDbPushMany cfg newBlocks db' | ||
Right <$> ledgerDbPushMany trace cfg newBlocks db' | ||
|
||
{------------------------------------------------------------------------------- | ||
The LedgerDB itself behaves like a ledger | ||
|
@@ -524,13 +546,14 @@ ledgerDbPush' cfg b = runIdentity . ledgerDbPush cfg (pureBlock b) | |
|
||
ledgerDbPushMany' :: ApplyBlock l blk | ||
=> LedgerDbCfg l -> [blk] -> LedgerDB l -> LedgerDB l | ||
ledgerDbPushMany' cfg bs = runIdentity . ledgerDbPushMany cfg (map pureBlock bs) | ||
ledgerDbPushMany' cfg bs = | ||
runIdentity . ledgerDbPushMany (const $ pure ()) cfg (map pureBlock bs) | ||
|
||
ledgerDbSwitch' :: forall l blk. ApplyBlock l blk | ||
=> LedgerDbCfg l | ||
-> Word64 -> [blk] -> LedgerDB l -> Maybe (LedgerDB l) | ||
ledgerDbSwitch' cfg n bs db = | ||
case runIdentity $ ledgerDbSwitch cfg n (map pureBlock bs) db of | ||
case runIdentity $ ledgerDbSwitch cfg n (const $ pure ()) (map pureBlock bs) db of | ||
Left ExceededRollback{} -> Nothing | ||
Right db' -> Just db' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,8 @@ import Ouroboros.Consensus.Ledger.Abstract | |
import Ouroboros.Consensus.Ledger.Extended | ||
import Ouroboros.Consensus.Ledger.Inspect | ||
import Ouroboros.Consensus.Ledger.SupportsProtocol | ||
import Ouroboros.Consensus.Storage.LedgerDB.Types | ||
(UpdateLedgerDbTraceEvent (..)) | ||
import Ouroboros.Consensus.Util.CBOR (ReadIncrementalErr, | ||
readIncremental) | ||
import Ouroboros.Consensus.Util.IOLike | ||
|
@@ -323,6 +325,7 @@ initStartingWith tracer cfg streamAPI initDb = do | |
(ledgerState (ledgerDbCurrent db)) | ||
(ledgerState (ledgerDbCurrent db')) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: undue newline |
||
traceWith tracer (ReplayedBlock (blockRealPoint blk) events ()) | ||
return (db', replayed') | ||
|
||
|
@@ -496,7 +499,6 @@ snapshotFromPath fileName = do | |
{------------------------------------------------------------------------------- | ||
Trace events | ||
-------------------------------------------------------------------------------} | ||
|
||
data TraceEvent blk | ||
= InvalidSnapshot DiskSnapshot (InitFailure blk) | ||
-- ^ An on disk snapshot was skipped because it was invalid. | ||
|
@@ -533,4 +535,5 @@ data TraceReplayEvent blk replayTo | |
-- The @blockInfo@ parameter corresponds replayed block and the @replayTo@ | ||
-- parameter corresponds to the block at the tip of the ImmutableDB, i.e., | ||
-- the last block to replay. | ||
| UpdateLedgerDbTraceEvent (UpdateLedgerDbTraceEvent blk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a Haddock comment on this one, describing the general meaning of the |
||
deriving (Generic, Eq, Show, Functor, Foldable, Traversable) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
module Ouroboros.Consensus.Storage.LedgerDB.Types ( | ||
PushGoal (..) | ||
, Pushing (..) | ||
, UpdateLedgerDbTraceEvent (..) | ||
) where | ||
|
||
|
||
import GHC.Generics (Generic) | ||
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 | ||
!(Pushing blk) | ||
-- ^ point which block we are about to push | ||
EncodePanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(PushGoal blk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a |
||
-- ^ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have other uses of
const $ pure ()
. Don't we want to replace these withnoopTrace
? Or just useconst $ pure ()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. good question, i think it's better if we replace with
noop
helper function, otherwise someone who will read the code will have to check each time to understand "wtf is const pure unit"