Skip to content

Commit

Permalink
ledger-state has crpyot removed
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Dec 11, 2024
1 parent bdf8f3c commit 008df29
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 131 deletions.
19 changes: 9 additions & 10 deletions libs/ledger-state/bench/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Cardano.Ledger.Address
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Binary
import Cardano.Ledger.Credential
import Cardano.Ledger.Crypto
import Cardano.Ledger.Keys
import Control.DeepSeq (NFData, deepseq)
import Criterion.Main
Expand All @@ -28,11 +27,11 @@ import Test.Cardano.Ledger.Core.Address (decompactAddrOldLazy)

main :: IO ()
main = do
let mkPayment :: Int -> Credential 'Payment StandardCrypto
let mkPayment :: Int -> Credential 'Payment
mkPayment = KeyHashObj . payAddr28
stakeRefBase :: Int -> StakeReference StandardCrypto
stakeRefBase :: Int -> StakeReference
stakeRefBase = StakeRefBase . KeyHashObj . stakeAddr28
mkAddr :: (Int -> StakeReference StandardCrypto) -> Int -> Addr StandardCrypto
mkAddr :: (Int -> StakeReference) -> Int -> Addr
mkAddr mkStake n = Addr Mainnet (mkPayment n) (mkStake n)
mkPtr n =
let ni = toInteger n
Expand All @@ -41,17 +40,17 @@ main = do
count = 10000
seqUnit :: a -> StrictUnit
seqUnit x = x `seq` mempty
forcePaymentCred :: Addr StandardCrypto -> StrictUnit
forcePaymentCred :: Addr -> StrictUnit
forcePaymentCred = \case
Addr _ p _ -> p `seq` mempty
_ -> mempty
forceStakingCred :: Addr StandardCrypto -> StrictUnit
forceStakingCred :: Addr -> StrictUnit
forceStakingCred = \case
Addr _ _ s -> s `deepseq` mempty
_ -> mempty
addrs :: (Int -> StakeReference StandardCrypto) -> [Addr StandardCrypto]
addrs :: (Int -> StakeReference) -> [Addr]
addrs mkStake = mkAddr mkStake <$> [1 .. count]
partialDeserializeAddr :: ByteString -> Addr StandardCrypto
partialDeserializeAddr :: ByteString -> Addr
partialDeserializeAddr =
either (error . show) id . decodeFullDecoder' version "Addr" fromCborAddr
version = maxBound :: Version
Expand Down Expand Up @@ -184,14 +183,14 @@ deepseqUnit x = x `deepseq` mempty
textDigits :: Int -> T.Text
textDigits n = let i = n `mod` 10 in T.pack (take 6 (cycle (show i)))

payAddr28 :: Int -> KeyHash 'Payment StandardCrypto
payAddr28 :: Int -> KeyHash 'Payment
payAddr28 n =
KeyHash $
fromMaybe "Unexpected PayAddr28" $
hashFromTextAsHex $
textDigits n <> "0405060708090a0b0c0d0e0f12131415161718191a1b1c1d1e"

stakeAddr28 :: Int -> KeyHash 'Staking StandardCrypto
stakeAddr28 :: Int -> KeyHash 'Staking
stakeAddr28 n =
KeyHash $
fromMaybe "Unexpected StakeAddr28" $
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-state/bench/Performance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ validatedTx3 =
\7120c2d3482751b14f06dd41d7ff023eeae6e63933b097c023c1ed19df6a061173c45aa\
\54cceb568ff1886e2716e84e6260df5f6"

mkGlobals :: ShelleyGenesis StandardCrypto -> Globals
mkGlobals :: ShelleyGenesis -> Globals
mkGlobals genesis =
mkShelleyGlobals genesis epochInfoE
where
Expand All @@ -250,7 +250,7 @@ mkGlobals genesis =
getFilteredOldUTxO ::
EraTxOut era =>
NewEpochState era ->
Set (Addr (EraCrypto era)) ->
Set Addr ->
UTxO era
getFilteredOldUTxO ss addrs =
UTxO $
Expand Down
26 changes: 13 additions & 13 deletions libs/ledger-state/src/Cardano/Ledger/State/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ instance PersistField ShortByteString where
instance PersistFieldSql ShortByteString where
sqlType _ = SqlBlob

instance PersistField (TxId C) where
instance PersistField TxId where
toPersistValue = PersistByteString . hashToBytes . extractHash . unTxId
fromPersistValue (PersistByteString bs) =
case hashFromBytes bs of
Nothing -> Left "Invalid number of bytes for the hash"
Just h -> Right $ TxId $ unsafeMakeSafeHash h
fromPersistValue _ = Left "Unexpected type"

instance PersistFieldSql (TxId C) where
instance PersistFieldSql TxId where
sqlType _ = SqlBlob

deriving instance PersistField (CompactForm Coin)
Expand Down Expand Up @@ -102,13 +102,13 @@ decodePersistValue (PersistByteString bs) =
Right v -> Right v
decodePersistValue _ = Left "Unexpected type"

deriving via Enc (KeyHash r C) instance Typeable r => PersistField (KeyHash r C)
deriving via Enc (KeyHash r) instance Typeable r => PersistField (KeyHash r)

deriving via Enc (KeyHash r C) instance Typeable r => PersistFieldSql (KeyHash r C)
deriving via Enc (KeyHash r) instance Typeable r => PersistFieldSql (KeyHash r)

deriving via Enc (Credential r C) instance Typeable r => PersistField (Credential r C)
deriving via Enc (Credential r) instance Typeable r => PersistField (Credential r)

deriving via Enc (Credential r C) instance Typeable r => PersistFieldSql (Credential r C)
deriving via Enc (Credential r) instance Typeable r => PersistFieldSql (Credential r)

deriving via Enc Ptr instance PersistField Ptr

Expand Down Expand Up @@ -137,20 +137,20 @@ deriving via Enc (PState CurrentEra) instance PersistField (PState CurrentEra)

deriving via Enc (PState CurrentEra) instance PersistFieldSql (PState CurrentEra)

deriving via Enc (GenDelegs C) instance PersistField (GenDelegs C)
deriving via Enc GenDelegs instance PersistField GenDelegs

deriving via Enc (GenDelegs C) instance PersistFieldSql (GenDelegs C)
deriving via Enc GenDelegs instance PersistFieldSql GenDelegs

deriving via Enc (PoolParams C) instance PersistField (PoolParams C)
deriving via Enc PoolParams instance PersistField PoolParams

deriving via Enc (PoolParams C) instance PersistFieldSql (PoolParams C)
deriving via Enc PoolParams instance PersistFieldSql PoolParams

instance DecCBOR (NonMyopic C) where
instance DecCBOR NonMyopic where
decCBOR = decNoShareCBOR

deriving via Enc (NonMyopic C) instance PersistField (NonMyopic C)
deriving via Enc NonMyopic instance PersistField NonMyopic

deriving via Enc (NonMyopic C) instance PersistFieldSql (NonMyopic C)
deriving via Enc NonMyopic instance PersistFieldSql NonMyopic

deriving via Enc (PParams CurrentEra) instance PersistField (PParams CurrentEra)

Expand Down
42 changes: 21 additions & 21 deletions libs/ledger-state/src/Cardano/Ledger/State/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ insertSnapShot ::
MonadIO m =>
Key EpochState ->
SnapShotType ->
EpochBoundary.SnapShot C ->
EpochBoundary.SnapShot ->
ReaderT SqlBackend m ()
insertSnapShot snapShotEpochStateId snapShotType EpochBoundary.SnapShot {..} = do
snapShotId <- insert $ SnapShot {snapShotType, snapShotEpochStateId}
Expand All @@ -154,7 +154,7 @@ insertSnapShot snapShotEpochStateId snapShotType EpochBoundary.SnapShot {..} = d
insertSnapShots ::
MonadIO m =>
Key EpochState ->
EpochBoundary.SnapShots C ->
EpochBoundary.SnapShots ->
ReaderT SqlBackend m ()
insertSnapShots epochStateKey EpochBoundary.SnapShots {..} = do
mapM_
Expand Down Expand Up @@ -208,7 +208,7 @@ getSnapShotNoSharingM ::
MonadResource m =>
Key EpochState ->
SnapShotType ->
ReaderT SqlBackend m (SnapShotM C)
ReaderT SqlBackend m SnapShotM
getSnapShotNoSharingM epochStateId snapShotType = do
snapShotId <-
selectFirst
Expand Down Expand Up @@ -241,10 +241,10 @@ getSnapShotNoSharingM epochStateId snapShotType = do

getSnapShotWithSharingM ::
MonadResource m =>
[SnapShotM C] ->
[SnapShotM] ->
Key EpochState ->
SnapShotType ->
ReaderT SqlBackend m (SnapShotM C)
ReaderT SqlBackend m SnapShotM
getSnapShotWithSharingM otherSnapShots epochStateId snapShotType = do
let internOtherStakes =
interns
Expand Down Expand Up @@ -288,7 +288,7 @@ getSnapShotWithSharingM otherSnapShots epochStateId snapShotType = do
getSnapShotsWithSharingM ::
MonadResource m =>
Entity EpochState ->
ReaderT SqlBackend m (SnapShotsM C)
ReaderT SqlBackend m SnapShotsM
getSnapShotsWithSharingM (Entity epochStateId EpochState {epochStateSnapShotsFee}) = do
mark <- getSnapShotWithSharingM [] epochStateId SnapShotMark
set <- getSnapShotWithSharingM [mark] epochStateId SnapShotSet
Expand Down Expand Up @@ -324,7 +324,7 @@ getSnapShotNoSharing ::
MonadResource m =>
Key EpochState ->
SnapShotType ->
ReaderT SqlBackend m (EpochBoundary.SnapShot C)
ReaderT SqlBackend m EpochBoundary.SnapShot
getSnapShotNoSharing epochStateId snapShotType = do
snapShotId <-
selectFirst
Expand Down Expand Up @@ -358,7 +358,7 @@ getSnapShotNoSharing epochStateId snapShotType = do
getSnapShotsNoSharing ::
MonadResource m =>
Entity EpochState ->
ReaderT SqlBackend m (EpochBoundary.SnapShots C)
ReaderT SqlBackend m EpochBoundary.SnapShots
getSnapShotsNoSharing (Entity epochStateId EpochState {epochStateSnapShotsFee}) = do
mark <- getSnapShotNoSharing epochStateId SnapShotMark
set <- getSnapShotNoSharing epochStateId SnapShotSet
Expand All @@ -376,7 +376,7 @@ getSnapShotsNoSharing (Entity epochStateId EpochState {epochStateSnapShotsFee})
getSnapShotsNoSharingM ::
MonadResource m =>
Entity EpochState ->
ReaderT SqlBackend m (SnapShotsM C)
ReaderT SqlBackend m SnapShotsM
getSnapShotsNoSharingM (Entity epochStateId EpochState {epochStateSnapShotsFee}) = do
mark <- getSnapShotNoSharingM epochStateId SnapShotMark
set <- getSnapShotNoSharingM epochStateId SnapShotSet
Expand All @@ -392,10 +392,10 @@ getSnapShotsNoSharingM (Entity epochStateId EpochState {epochStateSnapShotsFee})

getSnapShotWithSharing ::
MonadResource m =>
[EpochBoundary.SnapShot C] ->
[EpochBoundary.SnapShot] ->
Key EpochState ->
SnapShotType ->
ReaderT SqlBackend m (EpochBoundary.SnapShot C)
ReaderT SqlBackend m EpochBoundary.SnapShot
getSnapShotWithSharing otherSnapShots epochStateId snapShotType = do
let internOtherStakes =
interns
Expand Down Expand Up @@ -439,7 +439,7 @@ getSnapShotWithSharing otherSnapShots epochStateId snapShotType = do
getSnapShotsWithSharing ::
MonadResource m =>
Entity EpochState ->
ReaderT SqlBackend m (EpochBoundary.SnapShots C)
ReaderT SqlBackend m EpochBoundary.SnapShots
getSnapShotsWithSharing (Entity epochStateId EpochState {epochStateSnapShotsFee}) = do
mark <- getSnapShotWithSharing [] epochStateId SnapShotMark
set <- getSnapShotWithSharing [mark] epochStateId SnapShotSet
Expand All @@ -456,22 +456,22 @@ getSnapShotsWithSharing (Entity epochStateId EpochState {epochStateSnapShotsFee}

sourceUTxO ::
MonadResource m =>
ConduitM () (TxIn.TxIn C, TxOut CurrentEra) (ReaderT SqlBackend m) ()
ConduitM () (TxIn.TxIn, TxOut CurrentEra) (ReaderT SqlBackend m) ()
sourceUTxO =
selectSource [] []
.| mapC (\(Entity _ Tx {..}) -> (TxIn.TxIn txInId txInIx, txOut))

sourceWithSharingUTxO ::
MonadResource m =>
Map.Map (Credential.StakeCredential C) a ->
ConduitM () (TxIn.TxIn C, TxOut CurrentEra) (ReaderT SqlBackend m) ()
Map.Map Credential.StakeCredential a ->
ConduitM () (TxIn.TxIn, TxOut CurrentEra) (ReaderT SqlBackend m) ()
sourceWithSharingUTxO stakeCredentials =
sourceUTxO .| mapC (fmap (internBabbageTxOut (`intern` stakeCredentials)))

foldDbUTxO ::
MonadUnliftIO m =>
-- | Folding function
(a -> (TxIn.TxIn C, TxOut CurrentEra) -> a) ->
(a -> (TxIn.TxIn, TxOut CurrentEra) -> a) ->
-- | Empty acc
a ->
-- | Path to Sqlite db
Expand Down Expand Up @@ -679,7 +679,7 @@ loadLedgerStateDStateTxIxSharing ::
T.Text ->
m
( Shelley.LedgerState CurrentEra
, IntMap.IntMap (Map.Map (TxIn.TxId C) (TxOut CurrentEra))
, IntMap.IntMap (Map.Map TxIn.TxId (TxOut CurrentEra))
)
loadLedgerStateDStateTxIxSharing fp =
runSqlite fp $ do
Expand Down Expand Up @@ -768,19 +768,19 @@ loadEpochStateWithSharing fp = runSqlite fp $ do
& curPParamsEpochStateL .~ epochStatePp

loadSnapShotsNoSharing ::
MonadUnliftIO m => T.Text -> Entity EpochState -> m (EpochBoundary.SnapShots C)
MonadUnliftIO m => T.Text -> Entity EpochState -> m EpochBoundary.SnapShots
loadSnapShotsNoSharing fp = runSqlite fp . getSnapShotsNoSharing
{-# INLINEABLE loadSnapShotsNoSharing #-}

loadSnapShotsWithSharing ::
MonadUnliftIO m => T.Text -> Entity EpochState -> m (EpochBoundary.SnapShots C)
MonadUnliftIO m => T.Text -> Entity EpochState -> m EpochBoundary.SnapShots
loadSnapShotsWithSharing fp = runSqlite fp . getSnapShotsWithSharing
{-# INLINEABLE loadSnapShotsWithSharing #-}

loadSnapShotsNoSharingM :: T.Text -> Entity EpochState -> IO (SnapShotsM C)
loadSnapShotsNoSharingM :: T.Text -> Entity EpochState -> IO SnapShotsM
loadSnapShotsNoSharingM fp = runSqlite fp . getSnapShotsNoSharingM
{-# INLINEABLE loadSnapShotsNoSharingM #-}

loadSnapShotsWithSharingM :: T.Text -> Entity EpochState -> IO (SnapShotsM C)
loadSnapShotsWithSharingM :: T.Text -> Entity EpochState -> IO SnapShotsM
loadSnapShotsWithSharingM fp = runSqlite fp . getSnapShotsWithSharingM
{-# INLINEABLE loadSnapShotsWithSharingM #-}
16 changes: 8 additions & 8 deletions libs/ledger-state/src/Cardano/Ledger/State/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import qualified Data.Map.Strict as Map
import Database.Persist.Sqlite
import Database.Persist.TH

type FGenDelegs = (Enc (Map.Map (Shelley.FutureGenDeleg C) (Keys.GenDelegPair C)))
type FGenDelegs = (Enc (Map.Map Shelley.FutureGenDeleg Keys.GenDelegPair))

type CredentialWitness = Credential.Credential 'Keys.Witness C
type CredentialWitness = Credential.Credential 'Keys.Witness

type KeyHashWitness = Keys.KeyHash 'Keys.Witness C
type KeyHashWitness = Keys.KeyHash 'Keys.Witness

share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
Expand All @@ -44,7 +44,7 @@ EpochState
reserves Coin
prevPp (PParams CurrentEra)
pp (PParams CurrentEra)
nonMyopic (Shelley.NonMyopic C)
nonMyopic Shelley.NonMyopic
snapShotsFee Coin

SnapShot
Expand All @@ -64,7 +64,7 @@ SnapShotDelegation
SnapShotPool
snapShotId SnapShotId
keyHashId KeyHashId
params (Shelley.PoolParams C)
params Shelley.PoolParams
UniqueSnapShotPool snapShotId keyHashId

LedgerState
Expand All @@ -82,7 +82,7 @@ UtxoState
donation Coin
DState
fGenDelegs FGenDelegs
genDelegs (Keys.GenDelegs C)
genDelegs Keys.GenDelegs
irDeltaReserves DeltaCoin
irDeltaTreasury DeltaCoin

Expand All @@ -94,12 +94,12 @@ KeyHash
UniqueKeyHash witness
Tx
inIx TxIx
inId (TxIn.TxId C)
inId TxIn.TxId
out (BabbageTxOut CurrentEra)
UniqueTx inIx inId
Txs
inIx TxIx
inId (TxIn.TxId C)
inId TxIn.TxId
out (BabbageTxOut CurrentEra)
stakeCredential CredentialId Maybe
UniqueTxs inIx inId
Expand Down
Loading

0 comments on commit 008df29

Please sign in to comment.