Skip to content

Commit

Permalink
Cleanup stylish logs and dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed May 13, 2022
1 parent c81ef9e commit dc33deb
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 53 deletions.
5 changes: 3 additions & 2 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ import Ouroboros.Consensus.Block (BlockForging, BlockNo (..), BlockPro
ForgeStateInfo, ShouldForge (..), SlotNo (..), blockNo, blockSlot,
checkShouldForge)
import qualified Ouroboros.Consensus.Block as Block
import Ouroboros.Consensus.Cardano.Block (LedgerState (..), StandardAlonzo, StandardBabbage, StandardShelley)
import Ouroboros.Consensus.Cardano.Block (LedgerState (..), StandardAlonzo,
StandardBabbage, StandardShelley)
import Ouroboros.Consensus.Cardano.CanHardFork ()
import Ouroboros.Consensus.Config (TopLevelConfig, configConsensus, configLedger,
topLevelConfigLedger)
import Ouroboros.Consensus.Forecast (Forecast (..))
import Ouroboros.Consensus.HardFork.Combinator.Ledger ()
import qualified Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
import Ouroboros.Consensus.HardFork.Combinator.Ledger ()
import qualified Ouroboros.Consensus.HardFork.Combinator.Mempool as Consensus
import Ouroboros.Consensus.HeaderValidation (headerStateChainDep)
import Ouroboros.Consensus.Ledger.Abstract (TickedLedgerState, applyChainTick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Cardano.Ledger.Alonzo.Data
import Cardano.Ledger.Alonzo.Language
import Cardano.Ledger.Alonzo.Scripts
import Cardano.Ledger.BaseTypes
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Credential
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Era
Expand Down
8 changes: 4 additions & 4 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import Cardano.Crypto.VRF
import Cardano.Ledger.Address
import Cardano.Ledger.Alonzo.Data
import Cardano.Ledger.Alonzo.Scripts
import Cardano.Ledger.Alonzo.TxWitness
import Cardano.Ledger.Babbage.Tx
import Cardano.Ledger.Babbage.TxBody
import Cardano.Ledger.Alonzo.TxWitness
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Coin
import qualified Cardano.Ledger.Core as Core
Expand All @@ -41,18 +41,18 @@ import Cardano.Ledger.Shelley.Metadata
import Cardano.Ledger.Shelley.TxBody (DCert (..), PoolCert (..), PoolMetadata (..),
PoolParams (..), StakePoolRelay (..), Wdrl (..))
import Cardano.Ledger.ShelleyMA.Timelocks
import Cardano.Ledger.TxIn (TxIn (..), txid, TxId)
import Cardano.Ledger.TxIn (TxId, TxIn (..), txid)

import Ouroboros.Consensus.Cardano.Block (LedgerState)
import Ouroboros.Consensus.Shelley.Eras (StandardBabbage, StandardCrypto)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)

import Cardano.Ledger.Babbage.Collateral (collOuts)
import Cardano.Ledger.Shelley.UTxO
import Cardano.Mock.Forging.Crypto
import Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples
import Cardano.Mock.Forging.Tx.Generic
import Cardano.Mock.Forging.Types
import Cardano.Ledger.Babbage.Collateral (collOuts)
import Cardano.Ledger.Shelley.UTxO
-- import qualified Data.Maybe as Strict

type BabbageUTxOIndex = UTxOIndex StandardBabbage
Expand Down
4 changes: 2 additions & 2 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import Ouroboros.Consensus.Forecast
import Ouroboros.Consensus.Protocol.Praos (Praos)
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo, StandardBabbage,
StandardShelley, StandardCrypto)
import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo, StandardBabbage, StandardCrypto,
StandardShelley)

import Cardano.Ledger.Address
import qualified Cardano.Ledger.Core as Core
Expand Down
3 changes: 2 additions & 1 deletion cardano-chain-gen/test/Test/Cardano/Db/Mock/UnifiedApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import Cardano.Slotting.Slot (SlotNo (..))

import qualified Cardano.Ledger.Core as Core

import Ouroboros.Consensus.Cardano.Block (StandardAlonzo, StandardBabbage, StandardShelley)
import Ouroboros.Consensus.Cardano.Block (StandardAlonzo, StandardBabbage,
StandardShelley)
import Ouroboros.Consensus.Ledger.Basics (LedgerState)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)

Expand Down
2 changes: 1 addition & 1 deletion cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import Cardano.SMASH.Server.Types

import Cardano.Mock.ChainSync.Server
import Cardano.Mock.Forging.Interpreter
import Cardano.Mock.Forging.Tx.Alonzo.Scenarios
import qualified Cardano.Mock.Forging.Tx.Alonzo as Alonzo
import Cardano.Mock.Forging.Tx.Alonzo.Scenarios
import Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples
import Cardano.Mock.Forging.Tx.Generic
import Cardano.Mock.Forging.Types
Expand Down
4 changes: 2 additions & 2 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import Cardano.SMASH.Server.Types

import Cardano.Mock.ChainSync.Server
import Cardano.Mock.Forging.Interpreter
import Cardano.Mock.Forging.Tx.Babbage.Scenarios
import qualified Cardano.Mock.Forging.Tx.Babbage as Babbage
import Cardano.Mock.Forging.Tx.Alonzo.ScriptsExamples
import qualified Cardano.Mock.Forging.Tx.Babbage as Babbage
import Cardano.Mock.Forging.Tx.Babbage.Scenarios
import Cardano.Mock.Forging.Tx.Generic
import qualified Cardano.Mock.Forging.Tx.Shelley as Shelley
import Cardano.Mock.Forging.Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import qualified Cardano.Protocol.TPraos.OCert as TPraos
import Cardano.DbSync.Types
import Cardano.Slotting.Slot (SlotNo (..))

import Ouroboros.Consensus.Cardano.Block (StandardAllegra, StandardAlonzo, StandardBabbage,
StandardMary, StandardShelley)
import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Cardano.Block (StandardAllegra, StandardAlonzo,
StandardBabbage, StandardMary, StandardShelley)
import qualified Ouroboros.Consensus.Protocol.Praos.Header as Praos
import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBasedEra, ShelleyBlock)
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus
import Ouroboros.Consensus.Shelley.Protocol.Abstract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import Ouroboros.Consensus.Cardano.Block (HardForkState (..))
import Ouroboros.Consensus.Cardano.CanHardFork ()
import qualified Ouroboros.Consensus.HeaderValidation as Consensus
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus
import Ouroboros.Consensus.Protocol.Praos as Consensus
import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus

data NewEpoch = NewEpoch
{ neEpoch :: !EpochNo
Expand Down Expand Up @@ -63,4 +63,4 @@ extractEpochNonce extLedgerState =
Shelley.ticknStateEpochNonce . Shelley.csTickn . Consensus.tpraosStateChainDepState

extractNoncePraos :: Consensus.PraosState c -> Ledger.Nonce
extractNoncePraos = praosStateEpochNonce
extractNoncePraos = praosStateEpochNonce
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import qualified Cardano.Ledger.Alonzo as Alonzo
import Cardano.Ledger.Alonzo.Language (Language)
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import Cardano.Ledger.BaseTypes (UnitInterval, strictMaybeToMaybe)
import qualified Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Babbage (BabbageEra)
import qualified Cardano.Ledger.Babbage.PParams as Babbage
import Cardano.Ledger.BaseTypes (UnitInterval, strictMaybeToMaybe)
import qualified Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Coin (Coin)
import qualified Cardano.Ledger.Keys as Ledger
import Cardano.Ledger.Shelley (ShelleyEra)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ import Cardano.Db (ScriptType (..))

import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.ParamProposal
import Cardano.DbSync.Era.Shelley.Generic.Util
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (fromTxIn, getWithdrawalSum,
mkTxCertificate, mkTxWithdrawal)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Types
import Cardano.DbSync.Era.Shelley.Generic.Util
import Cardano.DbSync.Era.Shelley.Generic.Witness


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import Ouroboros.Consensus.Shelley.Eras (StandardBabbage, StandardCryp

import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.ParamProposal
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (getWithdrawalSum, fromTxIn)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (fromTxIn, getWithdrawalSum)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Types
import Cardano.DbSync.Era.Shelley.Generic.Witness

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import Ouroboros.Consensus.Cardano.Block (StandardCrypto, StandardMary
import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.ParamProposal
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval, mkTxScript)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (fromTxIn, getWithdrawalSum, mkTxCertificate, mkTxWithdrawal, txHashId)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley (fromTxIn, getWithdrawalSum,
mkTxCertificate, mkTxWithdrawal, txHashId)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Types
import Cardano.DbSync.Era.Shelley.Generic.Witness

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ mkTxCertificate ix dcert =
{ txcRedeemerIndex = Nothing
, txcIndex = ix
, txcCert = dcert
}
}
8 changes: 6 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ insertShelleyBlock
insertShelleyBlock env firstBlockOfEpoch blk lStateSnap details = do
runExceptT $ do
pbid <- case Generic.blkPreviousHash blk of
Nothing -> liftLookupFail (renderInsertName (Generic.blkEra blk)) DB.queryGenesis -- this is for networks that fork from Byron on epoch 0.
Just pHash -> queryPrevBlockWithCache (renderInsertName (Generic.blkEra blk)) cache pHash
Nothing -> liftLookupFail (renderErrorMessage (Generic.blkEra blk)) DB.queryGenesis -- this is for networks that fork from Byron on epoch 0.
Just pHash -> queryPrevBlockWithCache (renderErrorMessage (Generic.blkEra blk)) cache pHash
mPhid <- lift $ queryPoolKeyWithCache cache CacheNew (Generic.StakePoolKeyHash $ Generic.blkSlotLeader blk)

slid <- lift . DB.insertSlotLeader $ Generic.mkSlotLeader (Generic.blkSlotLeader blk) (eitherToMaybe mPhid)
Expand Down Expand Up @@ -158,6 +158,10 @@ insertShelleyBlock env firstBlockOfEpoch blk lStateSnap details = do

renderInsertName :: Generic.BlockEra -> Text
renderInsertName eraName =
mconcat ["Insert ", textShow eraName, " Block"]

renderErrorMessage :: Generic.BlockEra -> Text
renderErrorMessage eraName =
case eraName of
Generic.Shelley -> "insertShelleyBlock"
other -> mconcat [ "insertShelleyBlock(", textShow other, ")" ]
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ validateEpochRewards tracer earnedEpochNo rmap = do
else do
insertEpochRewardTotalReceived earnedEpochNo (Db.DbLovelace expectedw64)
liftIO . logInfo tracer $ mconcat
[ "validateEpochRewards: total rewards that become spendable in epoch "
[ "Validate Epoch Rewards: total rewards that become spendable in epoch "
, textShow (unEpochNo $ Generic.rwdEpoch rmap), " is ", textShow actual
, " ADA"
]
Expand Down
36 changes: 13 additions & 23 deletions cardano-db-sync/src/Cardano/DbSync/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

module Cardano.DbSync.LedgerState
( CardanoLedgerState (..)
, IndexCache (..)
, LedgerEnv (..)
, LedgerEvent (..)
, LedgerStateSnapshot (..)
Expand Down Expand Up @@ -40,8 +39,6 @@ import Cardano.BM.Trace (Trace, logInfo, logWarning)
import Cardano.Binary (Decoder, DecoderError, Encoding, FromCBOR (..), ToCBOR (..))
import qualified Cardano.Binary as Serialize

import qualified Cardano.Db as DB

import qualified Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Core (PParams)
import Cardano.Ledger.Era (Crypto)
Expand All @@ -54,8 +51,6 @@ import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
import Cardano.DbSync.Config.Types
import qualified Cardano.DbSync.Era.Cardano.Util as Cardano
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
import Cardano.DbSync.Era.Shelley.Generic.StakeCred
import Cardano.DbSync.Era.Shelley.Generic.StakePoolKeyHash
import Cardano.DbSync.LedgerEvent
import Cardano.DbSync.StateQuery
import Cardano.DbSync.Types
Expand All @@ -68,8 +63,8 @@ import Cardano.Slotting.EpochInfo (EpochInfo, epochInfoEpoch)
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..), WithOrigin (..), fromWithOrigin)

import qualified Control.Exception as Exception
import Control.Monad.Class.MonadSTM.Strict (StrictTMVar, StrictTVar, TBQueue, atomically,
newEmptyTMVarIO, newTBQueueIO, newTVarIO, readTVar, writeTVar)
import Control.Monad.Class.MonadSTM.Strict (StrictTVar, TBQueue, atomically, newTBQueueIO,
newTVarIO, readTVar, writeTVar)

import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BS
Expand Down Expand Up @@ -125,11 +120,6 @@ import System.Mem (performMajorGC)
{- HLINT ignore "Reduce duplication" -}
{- HLINT ignore "Use readTVarIO" -}

data IndexCache = IndexCache
{ icAddressCache :: !(Map StakeCred DB.StakeAddressId)
, icPoolCache :: !(Map StakePoolKeyHash DB.PoolHashId)
}

data LedgerEnv = LedgerEnv
{ leTrace :: Trace IO Text
, leProtocolInfo :: !(Consensus.ProtocolInfo IO CardanoBlock)
Expand All @@ -140,8 +130,6 @@ data LedgerEnv = LedgerEnv
, leInterpreter :: !(StrictTVar IO (Maybe CardanoInterpreter))
, leStateVar :: !(StrictTVar IO (Maybe LedgerDB))
, leEventState :: !(StrictTVar IO LedgerEventState)
, lePoolRewards :: !(StrictTMVar IO Generic.Rewards)
, leMirRewards :: !(StrictTMVar IO Generic.Rewards)
-- The following do not really have anything to do with maintaining ledger
-- state. They are here due to the ongoing headaches around the split between
-- `cardano-sync` and `cardano-db-sync`.
Expand Down Expand Up @@ -251,8 +239,6 @@ mkLedgerEnv trce protocolInfo dir nw stableEpochSlot systemStart aop = do
owq <- newTBQueueIO 100
orq <- newTBQueueIO 100
est <- newTVarIO =<< getCurrentTime
prvar <- newEmptyTMVarIO
mrvar <- newEmptyTMVarIO
pure LedgerEnv
{ leTrace = trce
, leProtocolInfo = protocolInfo
Expand All @@ -263,8 +249,6 @@ mkLedgerEnv trce protocolInfo dir nw stableEpochSlot systemStart aop = do
, leInterpreter = intervar
, leStateVar = svar
, leEventState = evar
, lePoolRewards = prvar
, leMirRewards = mrvar
, leOfflineWorkQueue = owq
, leOfflineResultQueue = orq
, leEpochSyncTime = est
Expand Down Expand Up @@ -494,9 +478,9 @@ cleanupLedgerStateFiles env slotNo = do
-- Remove invalid (ie SlotNo >= current) ledger state files (occurs on rollback).
deleteAndLogFiles env "invalid" invalid
-- Remove all but 6 most recent state files.
deleteAndLogStateFile env "valid" (List.drop 6 valid)
deleteAndLogStateFile env "old" (List.drop 6 valid)
-- Remove all but 6 most recent epoch boundary state files.
deleteAndLogStateFile env "epoch boundary" (List.drop 6 epochBoundary)
deleteAndLogStateFile env "old epoch boundary" (List.drop 6 epochBoundary)
where
groupFiles :: LedgerStateFile
-> ([LedgerStateFile], [LedgerStateFile], [FilePath])
Expand Down Expand Up @@ -557,9 +541,15 @@ deleteNewerFiles env point = do
deleteAndLogStateFile env "newer" newerFiles

deleteAndLogFiles :: LedgerEnv -> Text -> [FilePath] -> IO ()
deleteAndLogFiles env descr files = unless (null files) $ do
logInfo (leTrace env) $ mconcat ["Removing ", descr, " files ", textShow files]
mapM_ safeRemoveFile files
deleteAndLogFiles env descr files =
case files of
[] -> pure ()
[fl] -> do
logInfo (leTrace env) $ mconcat ["Removing ", descr, " file ", Text.pack fl]
safeRemoveFile fl
_ -> do
logInfo (leTrace env) $ mconcat ["Removing ", descr, " files ", textShow files]
mapM_ safeRemoveFile files

deleteAndLogStateFile :: LedgerEnv -> Text -> [LedgerStateFile] -> IO ()
deleteAndLogStateFile env descr lsfs = deleteAndLogFiles env descr (lsfFilePath <$> lsfs)
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import Data.ByteArray (ByteArrayAccess)
import qualified Data.ByteArray
import qualified Data.ByteString.Base16 as Base16
import qualified Data.List as List
import qualified Data.Strict.Maybe as Strict
import qualified Data.Map.Strict as Map
import qualified Data.Strict.Maybe as Strict
import qualified Data.Text as Text
import Data.Text.ANSI (red)
import qualified Data.Text.Encoding as Text
Expand Down
2 changes: 1 addition & 1 deletion cardano-db/src/Cardano/Db/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ queryBlocksAfterSlot slotNo = do

-- | Calculate the Epoch table entry for the specified epoch.
-- When syncing the chain or filling an empty table, this is called at each epoch boundary to
-- calculate the Epcoh entry for the last epoch.
-- calculate the Epoch entry for the last epoch.
-- When following the chain, this is called for each new block of the current epoch.
queryCalcEpochEntry :: MonadIO m => Word64 -> ReaderT SqlBackend m Epoch
queryCalcEpochEntry epochNum = do
Expand Down

0 comments on commit dc33deb

Please sign in to comment.