Skip to content

Commit

Permalink
Integrate node changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kostas Dermentzis <kostas.dermentzis@iohk.io>
  • Loading branch information
kderme committed Sep 7, 2023
1 parent 31f9234 commit b44eb73
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 113 deletions.
1 change: 1 addition & 0 deletions cardano-db-sync/cardano-db-sync.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ library
, containers
, contra-tracer
, directory
, data-default-class
, either
, esqueleto
, extra
Expand Down
113 changes: 63 additions & 50 deletions cardano-db-sync/src/Cardano/DbSync/Config/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ import Cardano.DbSync.Types
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
import Cardano.Ledger.Binary.Version
import Cardano.Ledger.Conway.Genesis
import Cardano.Ledger.Keys
import Cardano.Ledger.Shelley.Translation (emptyFromByronTranslationContext)
import Control.Monad.Trans.Except (ExceptT)
import Data.Default.Class (Default (def))
import Data.Word (Word64)
import Ouroboros.Consensus.Block.Forging
import Ouroboros.Consensus.Cardano (Nonce (..), ProtVer (ProtVer))
import qualified Ouroboros.Consensus.Cardano as Consensus
import qualified Ouroboros.Consensus.Cardano.Node as Consensus
import Ouroboros.Consensus.Cardano.Node
import Ouroboros.Consensus.Config (TopLevelConfig (..))
import Ouroboros.Consensus.Ledger.Basics (LedgerConfig)
import qualified Ouroboros.Consensus.Mempool.Capacity as TxLimits
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo)
import qualified Ouroboros.Consensus.Node.ProtocolInfo as Consensus
import Ouroboros.Consensus.Shelley.Eras (StandardCrypto)
import Ouroboros.Consensus.Shelley.Node (ShelleyGenesis (..))
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Consensus

-- Usually only one constructor, but may have two when we are preparing for a HFC event.
data GenesisConfig
Expand Down Expand Up @@ -84,53 +83,67 @@ mkProtocolInfoCardano ::
GenesisConfig ->
[Consensus.ShelleyLeaderCredentials StandardCrypto] -> -- this is not empty only in tests
(ProtocolInfo CardanoBlock, IO [BlockForging IO CardanoBlock])
mkProtocolInfoCardano ge shelleyCred =
case ge of
GenesisCardano dnc byronGenesis shelleyGenesis alonzoGenesis ->
Consensus.protocolInfoCardano
Consensus.ProtocolParamsByron
{ Consensus.byronGenesis = byronGenesis
, Consensus.byronPbftSignatureThreshold = Consensus.PBftSignatureThreshold <$> dncPBftSignatureThreshold dnc
, Consensus.byronProtocolVersion = dncByronProtocolVersion dnc
, Consensus.byronSoftwareVersion = mkByronSoftwareVersion
, Consensus.byronLeaderCredentials = Nothing
, Consensus.byronMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsShelleyBased
{ Consensus.shelleyBasedGenesis = scConfig shelleyGenesis
, Consensus.shelleyBasedInitialNonce = shelleyPraosNonce shelleyGenesis
, Consensus.shelleyBasedLeaderCredentials = shelleyCred
}
Consensus.ProtocolParamsShelley
{ Consensus.shelleyProtVer = mkProtVer 3 0
, Consensus.shelleyMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsAllegra
{ Consensus.allegraProtVer = mkProtVer 4 0
, Consensus.allegraMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsMary
{ Consensus.maryProtVer = mkProtVer 5 0
, Consensus.maryMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsAlonzo
{ Consensus.alonzoProtVer = mkProtVer 7 0
, Consensus.alonzoMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsBabbage
{ Consensus.babbageProtVer = mkProtVer 9 0
, Consensus.babbageMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
Consensus.ProtocolParamsConway
{ Consensus.conwayProtVer = mkProtVer 10 0
, Consensus.conwayMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure -- TODO: Conway
}
(Consensus.ProtocolTransitionParamsShelleyBased emptyFromByronTranslationContext $ dncShelleyHardFork dnc) -- TODO: Conway Fix
(Consensus.ProtocolTransitionParamsShelleyBased () $ dncAllegraHardFork dnc)
(Consensus.ProtocolTransitionParamsShelleyBased () $ dncMaryHardFork dnc)
(Consensus.ProtocolTransitionParamsShelleyBased alonzoGenesis $ dncAlonzoHardFork dnc)
(Consensus.ProtocolTransitionParamsShelleyBased () $ dncBabbageHardFork dnc)
(Consensus.ProtocolTransitionParamsShelleyBased (ConwayGenesis (GenDelegs mempty)) $ dncConwayHardFork dnc) -- TODO: Conway Fix
mkProtocolInfoCardano (GenesisCardano dnc bGenesis shelleyGenesis alonzoGenesis) shelleyCred =
protocolInfoCardano $
CardanoProtocolParams
{ paramsByron =
Consensus.ProtocolParamsByron
{ Consensus.byronGenesis = bGenesis
, Consensus.byronPbftSignatureThreshold = Consensus.PBftSignatureThreshold <$> dncPBftSignatureThreshold dnc
, Consensus.byronProtocolVersion = dncByronProtocolVersion dnc
, Consensus.byronSoftwareVersion = mkByronSoftwareVersion
, Consensus.byronLeaderCredentials = Nothing
, Consensus.byronMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsShelleyBased =
Consensus.ProtocolParamsShelleyBased
{ Consensus.shelleyBasedGenesis = scConfig shelleyGenesis
, Consensus.shelleyBasedInitialNonce = shelleyPraosNonce shelleyGenesis
, Consensus.shelleyBasedLeaderCredentials = shelleyCred
}
, paramsShelley =
Consensus.ProtocolParamsShelley
{ Consensus.shelleyProtVer = mkProtVer 3 0
, Consensus.shelleyMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsAllegra =
Consensus.ProtocolParamsAllegra
{ Consensus.allegraProtVer = mkProtVer 4 0
, Consensus.allegraMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsMary =
Consensus.ProtocolParamsMary
{ Consensus.maryProtVer = mkProtVer 5 0
, Consensus.maryMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsAlonzo =
Consensus.ProtocolParamsAlonzo
{ Consensus.alonzoProtVer = mkProtVer 7 0
, Consensus.alonzoMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsBabbage =
Consensus.ProtocolParamsBabbage
{ Consensus.babbageProtVer = mkProtVer 9 0
, Consensus.babbageMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, paramsConway =
Consensus.ProtocolParamsConway
{ Consensus.conwayProtVer = mkProtVer 10 0
, Consensus.conwayMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure -- TODO: Conway
}
, transitionParamsByronToShelley =
Consensus.ProtocolTransitionParamsByronToShelley emptyFromByronTranslationContext (dncShelleyHardFork dnc) -- TODO: Conway Fix
, transitionParamsShelleyToAllegra =
Consensus.ProtocolTransitionParamsIntraShelley () (dncAllegraHardFork dnc)
, transitionParamsAllegraToMary =
Consensus.ProtocolTransitionParamsIntraShelley () (dncMaryHardFork dnc)
, transitionParamsMaryToAlonzo =
Consensus.ProtocolTransitionParamsIntraShelley alonzoGenesis (dncAlonzoHardFork dnc)
, transitionParamsAlonzoToBabbage =
Consensus.ProtocolTransitionParamsIntraShelley () (dncBabbageHardFork dnc)
, transitionParamsBabbageToConway =
Consensus.ProtocolTransitionParamsIntraShelley (ConwayGenesis def) (dncConwayHardFork dnc) -- TODO: Conway Fix
}

shelleyPraosNonce :: ShelleyConfig -> Nonce
shelleyPraosNonce sCfg = Nonce (Crypto.castHash . unGenesisHashShelley $ scGenesisHash sCfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ epochProtoParams lstate =
LedgerStateConway st -> Just $ fromConwayParams $ getProtoParams st

getProtoParams ::
EraGov era =>
LedgerState (ShelleyBlock p era) ->
PParams era
getProtoParams = Shelley.esPp . Shelley.nesEs . Consensus.shelleyLedgerState
getProtoParams st = Shelley.nesEs (Consensus.shelleyLedgerState st) ^. Shelley.curPParamsEpochStateL

-- -------------------------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Cardano.DbSync.Era.Shelley.Generic.Witness
import Cardano.DbSync.Types (DataHash)
import qualified Cardano.Ledger.Address as Ledger
import qualified Cardano.Ledger.Alonzo.Language as Alonzo
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), txscriptfee)
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), txscriptfee, unBinaryPlutus)
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import Cardano.Ledger.Alonzo.TxAuxData (AlonzoTxAuxData (..), getAlonzoTxAuxDataScripts)
Expand All @@ -64,6 +64,7 @@ import qualified Data.Set as Set
#if __GLASGOW_HASKELL__ >= 906
import Data.Type.Equality (type (~))
#endif
import Cardano.Ledger.Language (Plutus (..))
import Lens.Micro
import Ouroboros.Consensus.Cardano.Block (EraCrypto, StandardAlonzo, StandardCrypto)

Expand Down Expand Up @@ -295,9 +296,9 @@ mkTxScript (hsh, script) =
getScriptType =
case script of
Alonzo.TimelockScript {} -> Timelock
Alonzo.PlutusScript Alonzo.PlutusV1 _s -> PlutusV1
Alonzo.PlutusScript Alonzo.PlutusV2 _s -> PlutusV2
Alonzo.PlutusScript Alonzo.PlutusV3 _s -> PlutusV3
Alonzo.PlutusScript (Plutus Alonzo.PlutusV1 _s) -> PlutusV1
Alonzo.PlutusScript (Plutus Alonzo.PlutusV2 _s) -> PlutusV2
Alonzo.PlutusScript (Plutus Alonzo.PlutusV3 _s) -> PlutusV3

timelockJsonScript :: Maybe ByteString
timelockJsonScript =
Expand All @@ -310,7 +311,7 @@ mkTxScript (hsh, script) =
plutusCborScript =
case script of
Alonzo.TimelockScript {} -> Nothing
plutusScript -> Just $ Ledger.originalBytes plutusScript
plScript -> Just $ Ledger.originalBytes plScript

getPlutusSizes ::
forall era.
Expand All @@ -330,7 +331,7 @@ getPlutusScriptSize :: Alonzo.AlonzoScript era -> Maybe Word64
getPlutusScriptSize script =
case script of
Alonzo.TimelockScript {} -> Nothing
Alonzo.PlutusScript _lang sbs -> Just $ fromIntegral (SBS.length sbs)
Alonzo.PlutusScript (Plutus _lang sbs) -> Just $ fromIntegral (SBS.length $ unBinaryPlutus sbs)

txDataWitness ::
(Core.TxWits era ~ Alonzo.AlonzoTxWits era, Core.EraTx era, EraCrypto era ~ StandardCrypto) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import Cardano.Ledger.Babbage.Core as Core hiding (Tx, TxOut)
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.TxBody
import qualified Cardano.Ledger.Core as Core
import Cardano.Prelude
Expand Down Expand Up @@ -65,7 +66,7 @@ fromConwayTx ioExtraPlutus mprices (blkIndex, tx) =
, txScriptSizes = getPlutusSizes tx
, txScripts = getScripts tx
, txExtraKeyWitnesses = extraKeyWits txBody
, txVotingProcedure = toList $ ctbVotingProcedures txBody
, txVotingProcedure = Map.toList $ fmap Map.toList (unVotingProcedures $ ctbVotingProcedures txBody)
, txProposalProcedure = toList $ ctbProposalProcedures txBody
}
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ data Tx = Tx
, txScriptSizes :: [Word64] -- this contains only the sizes of plutus scripts in witnesses
, txScripts :: [TxScript]
, txExtraKeyWitnesses :: ![ByteString]
, txVotingProcedure :: ![VotingProcedure StandardConway]
, txVotingProcedure :: ![(Voter StandardCrypto, [(GovActionId StandardCrypto, VotingProcedure StandardConway)])]
, txProposalProcedure :: ![ProposalProcedure StandardConway]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import qualified Cardano.Ledger.Address as Ledger
import qualified Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Coin (Coin (..), DeltaCoin)
import Cardano.Ledger.Conway.Governance
import qualified Cardano.Ledger.Conway.Governance as Ledger
import qualified Cardano.Ledger.Credential as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import Cardano.Ledger.Mary.Value (AssetName (..))
Expand Down Expand Up @@ -157,10 +156,10 @@ unAssetName = SBS.fromShort . assetName
dataHashToBytes :: DataHash -> ByteString
dataHashToBytes = Crypto.hashToBytes . Ledger.extractHash

achorHashToBytes :: Ledger.SafeHash StandardCrypto Ledger.AnchorDataHash -> ByteString
achorHashToBytes :: Ledger.SafeHash StandardCrypto Ledger.AnchorData -> ByteString
achorHashToBytes = Crypto.hashToBytes . Ledger.extractHash

toGovAction :: GovernanceAction StandardConway -> Db.GovActionType
toGovAction :: GovAction StandardConway -> Db.GovActionType
toGovAction = \case
ParameterChange {} -> Db.ParameterChange
HardForkInitiation {} -> Db.HardForkInitiation
Expand Down
Loading

0 comments on commit b44eb73

Please sign in to comment.