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

Fix ledger-state tool building #2535

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test-show-details: streaming
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 7de552c29e8c6fb421a4df48281f145feb6c7d2c
tag: 41545ba3ac6b3095966316a99883d678b5ab8da8
--sha256: 0icq9y3nnl42fz536da84414av36g37894qnyw4rk3qkalksqwir
subdir:
base-deriving-via
Expand Down
24 changes: 8 additions & 16 deletions libs/ledger-state/src/Cardano/Ledger/State/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,24 @@ import Cardano.Ledger.Credential
import Cardano.Ledger.Crypto
import Cardano.Ledger.Mary.Value
import qualified Cardano.Ledger.Mary.Value as Mary
import Cardano.Ledger.PoolDistr (individualPoolStakeVrf)
import Cardano.Ledger.Shelley.API
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.Rewards
import Cardano.Protocol.TPraos (individualPoolStakeVrf)
import Codec.CBOR.Read (deserialiseFromBytes)
import Conduit
import Control.Exception (throwIO)
import Control.Foldl (Fold (..))
import Control.Iterate.SetAlgebra (range)
import Control.Monad
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Compact.HashMap (toKey)
import Data.Compact.KeyMap as KeyMap hiding (Stat)
import qualified Data.Conduit.List as C
import Data.Foldable as F
import Data.Functor
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Map.Strict as Map
import Data.Proxy
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Read as T
import Data.Typeable
import Numeric.Natural
import Prettyprinter
Expand Down Expand Up @@ -125,14 +120,13 @@ txIxNestedInsertKeyMap ::
IntMap.IntMap (KeyMap.KeyMap a) ->
(TxIn C, a) ->
IntMap.IntMap (KeyMap.KeyMap a)
txIxNestedInsertKeyMap !m (TxInCompact32 x1 x2 x3 x4 txIx, !v) =
let !key = KeyMap.Key x1 x2 x3 x4
txIxNestedInsertKeyMap !m (TxInCompact txId txIx, !v) =
let !key = toKey txId
f =
\case
Nothing -> Just $! KeyMap.Leaf key v
Just hm -> Just $! KeyMap.insert key v hm
in IntMap.alter f (fromIntegral txIx) m
txIxNestedInsertKeyMap _ _ = error "Impossible"

txIdSharingKeyMap :: Fold (TxIn C, a) (KeyMap.KeyMap (IntMap.IntMap a))
txIdSharingKeyMap = Fold txIdNestedInsertKeyMap KeyMap.Empty id
Expand All @@ -144,11 +138,10 @@ txIdNestedInsertKeyMap ::
KeyMap.KeyMap (IntMap.IntMap a) ->
(TxIn C, a) ->
KeyMap.KeyMap (IntMap.IntMap a)
txIdNestedInsertKeyMap !m (TxInCompact32 x1 x2 x3 x4 txIx, !a) =
let !key = KeyMap.Key x1 x2 x3 x4
txIdNestedInsertKeyMap !m (TxInCompact txId txIx, !a) =
let !key = toKey txId
!v = IntMap.singleton (fromIntegral txIx) a
in KeyMap.insertWith (<>) key v m
txIdNestedInsertKeyMap _ _ = error "Impossible"

testKeyMap ::
KeyMap.KeyMap (IntMap.IntMap (Alonzo.TxOut CurrentEra)) ->
Expand All @@ -164,8 +157,8 @@ testKeyMap km m =
TxIn C ->
Alonzo.TxOut CurrentEra ->
KeyMap.KeyMap (IntMap.IntMap (Alonzo.TxOut CurrentEra))
test acc txIn@(TxInCompact32 x1 x2 x3 x4 txIx) txOut =
let !key = KeyMap.Key x1 x2 x3 x4
test acc txIn@(TxInCompact txId txIx) txOut =
let !key = toKey txId
in case KeyMap.lookupHM key acc of
Nothing -> error $ "Can't find txId: " <> show txIn
Just im ->
Expand All @@ -178,7 +171,6 @@ testKeyMap km m =
error $ "Found mismatching TxOuts for " <> show txIn
| IntMap.null im' -> KeyMap.delete key acc
| otherwise -> KeyMap.insert key im' acc
test _ _ _ = error "Impossible"

totalADA :: Map.Map (TxIn C) (Alonzo.TxOut CurrentEra) -> Mary.Value C
totalADA = foldMap (\(Alonzo.TxOut _ v _) -> v)
Expand Down