{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq
(
LedgerTablesHandle (..)
, LedgerSeq (..)
, LedgerSeq'
, StateRef (..)
, closeLedgerSeq
, empty
, empty'
, extend
, prune
, pruneToImmTipOnly
, reapplyBlock
, reapplyThenPush
, anchor
, anchorHandle
, current
, currentHandle
, getPastLedgerAt
, immutableTipSlot
, isSaturated
, maxRollback
, rollback
, rollbackN
, rollbackToAnchor
, rollbackToPoint
, snapshots
, tip
, volatileStatesBimap
) where
import Cardano.Ledger.BaseTypes
import Control.ResourceRegistry
import qualified Data.Bifunctor as B
import Data.Function (on)
import Data.Word
import GHC.Generics
import NoThunks.Class
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config.SecurityParam
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.Tables.Utils
import Ouroboros.Consensus.Storage.LedgerDB.API
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Network.AnchoredSeq hiding
( anchor
, last
, map
, rollback
)
import qualified Ouroboros.Network.AnchoredSeq as AS hiding (map)
import System.FS.CRC (CRC)
import Prelude hiding (read)
data LedgerTablesHandle m l = LedgerTablesHandle
{ forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m ()
close :: !(m ())
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m (LedgerTablesHandle m l)
duplicate :: !(m (LedgerTablesHandle m l))
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l
-> LedgerTables l KeysMK -> m (LedgerTables l ValuesMK)
read :: !(LedgerTables l KeysMK -> m (LedgerTables l ValuesMK))
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l
-> (Maybe (TxIn l), Int) -> m (LedgerTables l ValuesMK)
readRange :: !((Maybe (TxIn l), Int) -> m (LedgerTables l ValuesMK))
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m (LedgerTables l ValuesMK)
readAll :: !(m (LedgerTables l ValuesMK))
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l
-> forall (mk :: MapKind). l mk -> l DiffMK -> m ()
pushDiffs :: !(forall mk. l mk -> l DiffMK -> m ())
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> l EmptyMK -> String -> m CRC
takeHandleSnapshot :: !(l EmptyMK -> String -> m CRC)
, forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m (Maybe Int)
tablesSize :: !(m (Maybe Int))
}
deriving Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
Proxy (LedgerTablesHandle m l) -> String
(Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo))
-> (Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo))
-> (Proxy (LedgerTablesHandle m l) -> String)
-> NoThunks (LedgerTablesHandle m l)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall (m :: * -> *) (l :: LedgerStateKind).
Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
forall (m :: * -> *) (l :: LedgerStateKind).
Proxy (LedgerTablesHandle m l) -> String
$cnoThunks :: forall (m :: * -> *) (l :: LedgerStateKind).
Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
noThunks :: Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall (m :: * -> *) (l :: LedgerStateKind).
Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> LedgerTablesHandle m l -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall (m :: * -> *) (l :: LedgerStateKind).
Proxy (LedgerTablesHandle m l) -> String
showTypeOf :: Proxy (LedgerTablesHandle m l) -> String
NoThunks via OnlyCheckWhnfNamed "LedgerTablesHandle" (LedgerTablesHandle m l)
data StateRef m l = StateRef
{ forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state :: !(l EmptyMK)
, forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> LedgerTablesHandle m l
tables :: !(LedgerTablesHandle m l)
}
deriving (forall x. StateRef m l -> Rep (StateRef m l) x)
-> (forall x. Rep (StateRef m l) x -> StateRef m l)
-> Generic (StateRef m l)
forall x. Rep (StateRef m l) x -> StateRef m l
forall x. StateRef m l -> Rep (StateRef m l) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) (l :: LedgerStateKind) x.
Rep (StateRef m l) x -> StateRef m l
forall (m :: * -> *) (l :: LedgerStateKind) x.
StateRef m l -> Rep (StateRef m l) x
$cfrom :: forall (m :: * -> *) (l :: LedgerStateKind) x.
StateRef m l -> Rep (StateRef m l) x
from :: forall x. StateRef m l -> Rep (StateRef m l) x
$cto :: forall (m :: * -> *) (l :: LedgerStateKind) x.
Rep (StateRef m l) x -> StateRef m l
to :: forall x. Rep (StateRef m l) x -> StateRef m l
Generic
deriving instance (IOLike m, NoThunks (l EmptyMK)) => NoThunks (StateRef m l)
instance Eq (l EmptyMK) => Eq (StateRef m l) where
== :: StateRef m l -> StateRef m l -> Bool
(==) = l EmptyMK -> l EmptyMK -> Bool
forall a. Eq a => a -> a -> Bool
(==) (l EmptyMK -> l EmptyMK -> Bool)
-> (StateRef m l -> l EmptyMK)
-> StateRef m l
-> StateRef m l
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state
instance Show (l EmptyMK) => Show (StateRef m l) where
show :: StateRef m l -> String
show = l EmptyMK -> String
forall a. Show a => a -> String
show (l EmptyMK -> String)
-> (StateRef m l -> l EmptyMK) -> StateRef m l -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state
instance GetTip l => Anchorable (WithOrigin SlotNo) (StateRef m l) (StateRef m l) where
asAnchor :: StateRef m l -> StateRef m l
asAnchor = StateRef m l -> StateRef m l
forall a. a -> a
id
getAnchorMeasure :: Proxy (StateRef m l) -> StateRef m l -> WithOrigin SlotNo
getAnchorMeasure Proxy (StateRef m l)
_ = l EmptyMK -> WithOrigin SlotNo
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> WithOrigin SlotNo
getTipSlot (l EmptyMK -> WithOrigin SlotNo)
-> (StateRef m l -> l EmptyMK) -> StateRef m l -> WithOrigin SlotNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state
newtype LedgerSeq m l = LedgerSeq
{ forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq :: AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
}
deriving (forall x. LedgerSeq m l -> Rep (LedgerSeq m l) x)
-> (forall x. Rep (LedgerSeq m l) x -> LedgerSeq m l)
-> Generic (LedgerSeq m l)
forall x. Rep (LedgerSeq m l) x -> LedgerSeq m l
forall x. LedgerSeq m l -> Rep (LedgerSeq m l) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) (l :: LedgerStateKind) x.
Rep (LedgerSeq m l) x -> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind) x.
LedgerSeq m l -> Rep (LedgerSeq m l) x
$cfrom :: forall (m :: * -> *) (l :: LedgerStateKind) x.
LedgerSeq m l -> Rep (LedgerSeq m l) x
from :: forall x. LedgerSeq m l -> Rep (LedgerSeq m l) x
$cto :: forall (m :: * -> *) (l :: LedgerStateKind) x.
Rep (LedgerSeq m l) x -> LedgerSeq m l
to :: forall x. Rep (LedgerSeq m l) x -> LedgerSeq m l
Generic
deriving newtype instance (IOLike m, NoThunks (l EmptyMK)) => NoThunks (LedgerSeq m l)
deriving newtype instance Eq (l EmptyMK) => Eq (LedgerSeq m l)
deriving newtype instance Show (l EmptyMK) => Show (LedgerSeq m l)
type LedgerSeq' m blk = LedgerSeq m (ExtLedgerState blk)
empty ::
( GetTip l
, IOLike m
) =>
l EmptyMK ->
LedgerTables l ValuesMK ->
(LedgerTables l ValuesMK -> m (LedgerTablesHandle m l)) ->
m (LedgerSeq m l)
empty :: forall (l :: LedgerStateKind) (m :: * -> *).
(GetTip l, IOLike m) =>
l EmptyMK
-> LedgerTables l ValuesMK
-> (LedgerTables l ValuesMK -> m (LedgerTablesHandle m l))
-> m (LedgerSeq m l)
empty l EmptyMK
st LedgerTables l ValuesMK
tbs LedgerTables l ValuesMK -> m (LedgerTablesHandle m l)
new = AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (LedgerTablesHandle m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerTablesHandle m l
-> LedgerSeq m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b. Anchorable v a b => a -> AnchoredSeq v a b
AS.Empty (StateRef m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerTablesHandle m l -> StateRef m l)
-> LedgerTablesHandle m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l EmptyMK -> LedgerTablesHandle m l -> StateRef m l
forall (m :: * -> *) (l :: LedgerStateKind).
l EmptyMK -> LedgerTablesHandle m l -> StateRef m l
StateRef l EmptyMK
st (LedgerTablesHandle m l -> LedgerSeq m l)
-> m (LedgerTablesHandle m l) -> m (LedgerSeq m l)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LedgerTables l ValuesMK -> m (LedgerTablesHandle m l)
new LedgerTables l ValuesMK
tbs
empty' ::
( GetTip l
, IOLike m
, HasLedgerTables l
) =>
l ValuesMK ->
(LedgerTables l ValuesMK -> m (LedgerTablesHandle m l)) ->
m (LedgerSeq m l)
empty' :: forall (l :: LedgerStateKind) (m :: * -> *).
(GetTip l, IOLike m, HasLedgerTables l) =>
l ValuesMK
-> (LedgerTables l ValuesMK -> m (LedgerTablesHandle m l))
-> m (LedgerSeq m l)
empty' l ValuesMK
st = l EmptyMK
-> LedgerTables l ValuesMK
-> (LedgerTables l ValuesMK -> m (LedgerTablesHandle m l))
-> m (LedgerSeq m l)
forall (l :: LedgerStateKind) (m :: * -> *).
(GetTip l, IOLike m) =>
l EmptyMK
-> LedgerTables l ValuesMK
-> (LedgerTables l ValuesMK -> m (LedgerTablesHandle m l))
-> m (LedgerSeq m l)
empty (l ValuesMK -> l EmptyMK
forall (l :: LedgerStateKind) (mk :: MapKind).
HasLedgerTables l =>
l mk -> l EmptyMK
forgetLedgerTables l ValuesMK
st) (l ValuesMK -> LedgerTables l ValuesMK
forall (l :: LedgerStateKind) (l' :: LedgerStateKind)
(mk :: MapKind).
(HasLedgerTables l, SameUtxoTypes l l', CanMapMK mk,
CanMapKeysMK mk, ZeroableMK mk) =>
l mk -> LedgerTables l' mk
ltprj l ValuesMK
st)
closeLedgerSeq :: Monad m => LedgerSeq m l -> m ()
closeLedgerSeq :: forall (m :: * -> *) (l :: LedgerStateKind).
Monad m =>
LedgerSeq m l -> m ()
closeLedgerSeq = (StateRef m l -> m ()) -> [StateRef m l] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (LedgerTablesHandle m l -> m ()
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m ()
close (LedgerTablesHandle m l -> m ())
-> (StateRef m l -> LedgerTablesHandle m l) -> StateRef m l -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> LedgerTablesHandle m l
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> LedgerTablesHandle m l
tables) ([StateRef m l] -> m ())
-> (LedgerSeq m l -> [StateRef m l]) -> LedgerSeq m l -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> [StateRef m l]
forall v a b. AnchoredSeq v a b -> [b]
toOldestFirst (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> [StateRef m l])
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> [StateRef m l]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
reapplyThenPush ::
(IOLike m, ApplyBlock l blk) =>
ResourceRegistry m ->
LedgerDbCfg l ->
blk ->
LedgerSeq m l ->
m (LedgerSeq m l, LedgerSeq m l)
reapplyThenPush :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
(IOLike m, ApplyBlock l blk) =>
ResourceRegistry m
-> LedgerDbCfg l
-> blk
-> LedgerSeq m l
-> m (LedgerSeq m l, LedgerSeq m l)
reapplyThenPush ResourceRegistry m
rr LedgerDbCfg l
cfg blk
ap LedgerSeq m l
db =
(\StateRef m l
current' -> LedgerDbPrune -> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerDbPrune -> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
prune (SecurityParam -> LedgerDbPrune
LedgerDbPruneKeeping (LedgerDbCfg l -> HKD Identity SecurityParam
forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> HKD f SecurityParam
ledgerDbCfgSecParam LedgerDbCfg l
cfg)) (LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l))
-> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
forall a b. (a -> b) -> a -> b
$ StateRef m l -> LedgerSeq m l -> LedgerSeq m l
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
StateRef m l -> LedgerSeq m l -> LedgerSeq m l
extend StateRef m l
current' LedgerSeq m l
db)
(StateRef m l -> (LedgerSeq m l, LedgerSeq m l))
-> m (StateRef m l) -> m (LedgerSeq m l, LedgerSeq m l)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ComputeLedgerEvents
-> LedgerCfg l
-> blk
-> ResourceRegistry m
-> LedgerSeq m l
-> m (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
(ApplyBlock l blk, IOLike m) =>
ComputeLedgerEvents
-> LedgerCfg l
-> blk
-> ResourceRegistry m
-> LedgerSeq m l
-> m (StateRef m l)
reapplyBlock (LedgerDbCfg l -> ComputeLedgerEvents
forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> ComputeLedgerEvents
ledgerDbCfgComputeLedgerEvents LedgerDbCfg l
cfg) (LedgerDbCfg l -> HKD Identity (LedgerCfg l)
forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> HKD f (LedgerCfg l)
ledgerDbCfg LedgerDbCfg l
cfg) blk
ap ResourceRegistry m
rr LedgerSeq m l
db
reapplyBlock ::
forall m l blk.
(ApplyBlock l blk, IOLike m) =>
ComputeLedgerEvents ->
LedgerCfg l ->
blk ->
ResourceRegistry m ->
LedgerSeq m l ->
m (StateRef m l)
reapplyBlock :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
(ApplyBlock l blk, IOLike m) =>
ComputeLedgerEvents
-> LedgerCfg l
-> blk
-> ResourceRegistry m
-> LedgerSeq m l
-> m (StateRef m l)
reapplyBlock ComputeLedgerEvents
evs LedgerCfg l
cfg blk
b ResourceRegistry m
_rr LedgerSeq m l
db = do
let ks :: LedgerTables l KeysMK
ks = blk -> LedgerTables l KeysMK
forall (l :: LedgerStateKind) blk.
ApplyBlock l blk =>
blk -> LedgerTables l KeysMK
getBlockKeySets blk
b
StateRef l EmptyMK
st LedgerTablesHandle m l
tbs = LedgerSeq m l -> StateRef m l
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> StateRef m l
currentHandle LedgerSeq m l
db
newtbs <- LedgerTablesHandle m l -> m (LedgerTablesHandle m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerTablesHandle m l -> m (LedgerTablesHandle m l)
duplicate LedgerTablesHandle m l
tbs
vals <- read newtbs ks
let st' = ComputeLedgerEvents -> LedgerCfg l -> blk -> l ValuesMK -> l DiffMK
forall (l :: LedgerStateKind) blk.
ApplyBlock l blk =>
ComputeLedgerEvents -> LedgerCfg l -> blk -> l ValuesMK -> l DiffMK
tickThenReapply ComputeLedgerEvents
evs LedgerCfg l
cfg blk
b (l EmptyMK
st l EmptyMK -> LedgerTables l ValuesMK -> l ValuesMK
forall (mk :: MapKind) (any :: MapKind).
(CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) =>
l any -> LedgerTables l mk -> l mk
forall (l :: LedgerStateKind) (mk :: MapKind) (any :: MapKind).
(HasLedgerTables l, CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) =>
l any -> LedgerTables l mk -> l mk
`withLedgerTables` LedgerTables l ValuesMK
vals)
newst = l DiffMK -> l EmptyMK
forall (l :: LedgerStateKind) (mk :: MapKind).
HasLedgerTables l =>
l mk -> l EmptyMK
forgetLedgerTables l DiffMK
st'
pushDiffs newtbs st st'
pure (StateRef newst newtbs)
prune ::
GetTip l =>
LedgerDbPrune ->
LedgerSeq m l ->
(LedgerSeq m l, LedgerSeq m l)
prune :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerDbPrune -> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
prune (LedgerDbPruneKeeping (SecurityParam NonZero Word64
k)) (LedgerSeq AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb) =
if Int -> Word64
forall a. Enum a => Int -> a
toEnum Int
nvol Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= NonZero Word64 -> Word64
forall a. NonZero a -> a
unNonZero NonZero Word64
k
then (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall a b. (a -> b) -> a -> b
$ StateRef m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b. Anchorable v a b => a -> AnchoredSeq v a b
Empty (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
forall v a b. AnchoredSeq v a b -> a
AS.anchor AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb), AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb)
else
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: MapKind) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
B.bimap (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b.
Anchorable v a b =>
Int -> AnchoredSeq v a b -> AnchoredSeq v a b
dropNewest Int
1) AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq ((AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l))
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l)
forall a b. (a -> b) -> a -> b
$ Int
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
forall v a b.
Anchorable v a b =>
Int -> AnchoredSeq v a b -> (AnchoredSeq v a b, AnchoredSeq v a b)
AS.splitAt (Int
nvol Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word64 -> Int
forall a. Enum a => a -> Int
fromEnum (NonZero Word64 -> Word64
forall a. NonZero a -> a
unNonZero NonZero Word64
k)) AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb
where
nvol :: Int
nvol = AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> Int
forall v a b. Anchorable v a b => AnchoredSeq v a b -> Int
AS.length AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb
prune LedgerDbPrune
LedgerDbPruneAll (LedgerSeq AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb) =
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: MapKind) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
B.bimap (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b.
Anchorable v a b =>
Int -> AnchoredSeq v a b -> AnchoredSeq v a b
dropNewest Int
1) AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq ((AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l))
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l, LedgerSeq m l)
forall a b. (a -> b) -> a -> b
$ Int
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l),
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
forall v a b.
Anchorable v a b =>
Int -> AnchoredSeq v a b -> (AnchoredSeq v a b, AnchoredSeq v a b)
AS.splitAt Int
nvol AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb
where
nvol :: Int
nvol = AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> Int
forall v a b. Anchorable v a b => AnchoredSeq v a b -> Int
AS.length AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb
{-# INLINE prune #-}
extend ::
GetTip l =>
StateRef m l ->
LedgerSeq m l ->
LedgerSeq m l
extend :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
StateRef m l -> LedgerSeq m l -> LedgerSeq m l
extend StateRef m l
newState =
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> LedgerSeq m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b.
Anchorable v a b =>
AnchoredSeq v a b -> b -> AnchoredSeq v a b
:> StateRef m l
newState) (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
pruneToImmTipOnly ::
GetTip l =>
LedgerSeq m l ->
(LedgerSeq m l, LedgerSeq m l)
pruneToImmTipOnly :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
pruneToImmTipOnly = LedgerDbPrune -> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerDbPrune -> LedgerSeq m l -> (LedgerSeq m l, LedgerSeq m l)
prune LedgerDbPrune
LedgerDbPruneAll
rollbackN ::
GetTip l =>
Word64 ->
LedgerSeq m l ->
Maybe (LedgerSeq m l)
rollbackN :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
Word64 -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollbackN Word64
n LedgerSeq m l
ldb
| Word64
n Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= LedgerSeq m l -> Word64
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> Word64
maxRollback LedgerSeq m l
ldb =
LedgerSeq m l -> Maybe (LedgerSeq m l)
forall a. a -> Maybe a
Just (LedgerSeq m l -> Maybe (LedgerSeq m l))
-> LedgerSeq m l -> Maybe (LedgerSeq m l)
forall a b. (a -> b) -> a -> b
$ AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (Int
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b.
Anchorable v a b =>
Int -> AnchoredSeq v a b -> AnchoredSeq v a b
AS.dropNewest (Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n) (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall a b. (a -> b) -> a -> b
$ LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq LedgerSeq m l
ldb)
| Bool
otherwise =
Maybe (LedgerSeq m l)
forall a. Maybe a
Nothing
current :: GetTip l => LedgerSeq m l -> l EmptyMK
current :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> l EmptyMK
current = StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state (StateRef m l -> l EmptyMK)
-> (LedgerSeq m l -> StateRef m l) -> LedgerSeq m l -> l EmptyMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l -> StateRef m l
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> StateRef m l
currentHandle
currentHandle :: GetTip l => LedgerSeq m l -> StateRef m l
currentHandle :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> StateRef m l
currentHandle = AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
forall v a b. Anchorable v a b => AnchoredSeq v a b -> a
headAnchor (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> StateRef m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
anchor :: LedgerSeq m l -> l EmptyMK
anchor :: forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l -> l EmptyMK
anchor = StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state (StateRef m l -> l EmptyMK)
-> (LedgerSeq m l -> StateRef m l) -> LedgerSeq m l -> l EmptyMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l -> StateRef m l
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l -> StateRef m l
anchorHandle
anchorHandle :: LedgerSeq m l -> StateRef m l
anchorHandle :: forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l -> StateRef m l
anchorHandle = AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
forall v a b. AnchoredSeq v a b -> a
AS.anchor (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> StateRef m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
snapshots :: LedgerSeq m l -> [(Word64, l EmptyMK)]
snapshots :: forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l -> [(Word64, l EmptyMK)]
snapshots =
[Word64] -> [l EmptyMK] -> [(Word64, l EmptyMK)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word64
0 ..]
([l EmptyMK] -> [(Word64, l EmptyMK)])
-> (LedgerSeq m l -> [l EmptyMK])
-> LedgerSeq m l
-> [(Word64, l EmptyMK)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StateRef m l -> l EmptyMK) -> [StateRef m l] -> [l EmptyMK]
forall a b. (a -> b) -> [a] -> [b]
map StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state
([StateRef m l] -> [l EmptyMK])
-> (LedgerSeq m l -> [StateRef m l])
-> LedgerSeq m l
-> [l EmptyMK]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> [StateRef m l]
forall v a b. AnchoredSeq v a b -> [b]
AS.toNewestFirst
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> [StateRef m l])
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> [StateRef m l]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
maxRollback :: GetTip l => LedgerSeq m l -> Word64
maxRollback :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> Word64
maxRollback =
Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int -> Word64)
-> (LedgerSeq m l -> Int) -> LedgerSeq m l -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> Int
forall v a b. Anchorable v a b => AnchoredSeq v a b -> Int
AS.length
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> Int)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
tip :: GetTip l => LedgerSeq m l -> Point l
tip :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> Point l
tip = Point l -> Point l
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (Point l -> Point l)
-> (LedgerSeq m l -> Point l) -> LedgerSeq m l -> Point l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l EmptyMK -> Point l
forall (mk :: MapKind). l mk -> Point l
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> Point l
getTip (l EmptyMK -> Point l)
-> (LedgerSeq m l -> l EmptyMK) -> LedgerSeq m l -> Point l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l -> l EmptyMK
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> l EmptyMK
current
isSaturated :: GetTip l => SecurityParam -> LedgerSeq m l -> Bool
isSaturated :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
SecurityParam -> LedgerSeq m l -> Bool
isSaturated (SecurityParam NonZero Word64
k) LedgerSeq m l
db =
LedgerSeq m l -> Word64
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> Word64
maxRollback LedgerSeq m l
db Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= NonZero Word64 -> Word64
forall a. NonZero a -> a
unNonZero NonZero Word64
k
getPastLedgerAt ::
( HasHeader blk
, GetTip l
, HeaderHash l ~ HeaderHash blk
, StandardHash l
) =>
Point blk ->
LedgerSeq m l ->
Maybe (l EmptyMK)
getPastLedgerAt :: forall blk (l :: LedgerStateKind) (m :: * -> *).
(HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk,
StandardHash l) =>
Point blk -> LedgerSeq m l -> Maybe (l EmptyMK)
getPastLedgerAt Point blk
pt LedgerSeq m l
db = LedgerSeq m l -> l EmptyMK
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> l EmptyMK
current (LedgerSeq m l -> l EmptyMK)
-> Maybe (LedgerSeq m l) -> Maybe (l EmptyMK)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Point blk -> LedgerSeq m l -> Maybe (LedgerSeq m l)
forall blk (l :: LedgerStateKind) (m :: * -> *).
(HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk,
StandardHash l) =>
Point blk -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollback Point blk
pt LedgerSeq m l
db
rollbackToPoint ::
( StandardHash l
, GetTip l
) =>
Point l -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollbackToPoint :: forall (l :: LedgerStateKind) (m :: * -> *).
(StandardHash l, GetTip l) =>
Point l -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollbackToPoint Point l
pt (LedgerSeq AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb) = do
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l)
-> Maybe
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> Maybe (LedgerSeq m l)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WithOrigin SlotNo
-> (Either (StateRef m l) (StateRef m l) -> Bool)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> Maybe
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
forall v a b.
Anchorable v a b =>
v
-> (Either a b -> Bool)
-> AnchoredSeq v a b
-> Maybe (AnchoredSeq v a b)
AS.rollback
(Point l -> WithOrigin SlotNo
forall {k} (block :: k). Point block -> WithOrigin SlotNo
pointSlot Point l
pt)
((Point l -> Point l -> Bool
forall a. Eq a => a -> a -> Bool
== Point l
pt) (Point l -> Bool)
-> (Either (StateRef m l) (StateRef m l) -> Point l)
-> Either (StateRef m l) (StateRef m l)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l EmptyMK -> Point l
forall (mk :: MapKind). l mk -> Point l
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> Point l
getTip (l EmptyMK -> Point l)
-> (Either (StateRef m l) (StateRef m l) -> l EmptyMK)
-> Either (StateRef m l) (StateRef m l)
-> Point l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StateRef m l -> l EmptyMK)
-> (StateRef m l -> l EmptyMK)
-> Either (StateRef m l) (StateRef m l)
-> l EmptyMK
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state)
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
ldb
rollbackToAnchor ::
GetTip l =>
LedgerSeq m l -> LedgerSeq m l
rollbackToAnchor :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> LedgerSeq m l
rollbackToAnchor (LedgerSeq AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
vol) =
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
forall (m :: * -> *) (l :: LedgerStateKind).
AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> LedgerSeq m l
LedgerSeq (StateRef m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall v a b. Anchorable v a b => a -> AnchoredSeq v a b
AS.Empty (AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
forall v a b. AnchoredSeq v a b -> a
AS.anchor AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
vol))
rollback ::
( HasHeader blk
, GetTip l
, HeaderHash l ~ HeaderHash blk
, StandardHash l
) =>
Point blk ->
LedgerSeq m l ->
Maybe (LedgerSeq m l)
rollback :: forall blk (l :: LedgerStateKind) (m :: * -> *).
(HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk,
StandardHash l) =>
Point blk -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollback Point blk
pt LedgerSeq m l
db
| Point blk
pt Point blk -> Point blk -> Bool
forall a. Eq a => a -> a -> Bool
== Point l -> Point blk
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (l EmptyMK -> Point l
forall (mk :: MapKind). l mk -> Point l
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> Point l
getTip (LedgerSeq m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l -> l EmptyMK
anchor LedgerSeq m l
db)) =
LedgerSeq m l -> Maybe (LedgerSeq m l)
forall a. a -> Maybe a
Just (LedgerSeq m l -> Maybe (LedgerSeq m l))
-> LedgerSeq m l -> Maybe (LedgerSeq m l)
forall a b. (a -> b) -> a -> b
$ LedgerSeq m l -> LedgerSeq m l
forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> LedgerSeq m l
rollbackToAnchor LedgerSeq m l
db
| Bool
otherwise =
Point l -> LedgerSeq m l -> Maybe (LedgerSeq m l)
forall (l :: LedgerStateKind) (m :: * -> *).
(StandardHash l, GetTip l) =>
Point l -> LedgerSeq m l -> Maybe (LedgerSeq m l)
rollbackToPoint (Point blk -> Point l
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint Point blk
pt) LedgerSeq m l
db
immutableTipSlot ::
GetTip l =>
LedgerSeq m l -> WithOrigin SlotNo
immutableTipSlot :: forall (l :: LedgerStateKind) (m :: * -> *).
GetTip l =>
LedgerSeq m l -> WithOrigin SlotNo
immutableTipSlot =
l EmptyMK -> WithOrigin SlotNo
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> WithOrigin SlotNo
getTipSlot
(l EmptyMK -> WithOrigin SlotNo)
-> (LedgerSeq m l -> l EmptyMK)
-> LedgerSeq m l
-> WithOrigin SlotNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state
(StateRef m l -> l EmptyMK)
-> (LedgerSeq m l -> StateRef m l) -> LedgerSeq m l -> l EmptyMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l
forall v a b. AnchoredSeq v a b -> a
AS.anchor
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> StateRef m l)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> StateRef m l
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq
volatileStatesBimap ::
AS.Anchorable (WithOrigin SlotNo) a b =>
(l EmptyMK -> a) ->
(l EmptyMK -> b) ->
LedgerSeq m l ->
AS.AnchoredSeq (WithOrigin SlotNo) a b
volatileStatesBimap :: forall a b (l :: LedgerStateKind) (m :: * -> *).
Anchorable (WithOrigin SlotNo) a b =>
(l EmptyMK -> a)
-> (l EmptyMK -> b)
-> LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) a b
volatileStatesBimap l EmptyMK -> a
f l EmptyMK -> b
g =
(StateRef m l -> a)
-> (StateRef m l -> b)
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) a b
forall v2 a2 b2 a1 b1 v1.
Anchorable v2 a2 b2 =>
(a1 -> a2)
-> (b1 -> b2) -> AnchoredSeq v1 a1 b1 -> AnchoredSeq v2 a2 b2
AS.bimap (l EmptyMK -> a
f (l EmptyMK -> a)
-> (StateRef m l -> l EmptyMK) -> StateRef m l -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state) (l EmptyMK -> b
g (l EmptyMK -> b)
-> (StateRef m l -> l EmptyMK) -> StateRef m l -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateRef m l -> l EmptyMK
forall (m :: * -> *) (l :: LedgerStateKind).
StateRef m l -> l EmptyMK
state)
(AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
-> AnchoredSeq (WithOrigin SlotNo) a b)
-> (LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l))
-> LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
forall (m :: * -> *) (l :: LedgerStateKind).
LedgerSeq m l
-> AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
getLedgerSeq