Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- envSecurityParam :: Env -> Word64
- newtype LedgerState where
- LedgerState { }
- pattern LedgerStateByron :: LedgerState ByronBlock -> LedgerState
- pattern LedgerStateShelley :: LedgerState StandardShelleyBlock -> LedgerState
- pattern LedgerStateAllegra :: LedgerState StandardAllegraBlock -> LedgerState
- pattern LedgerStateMary :: LedgerState StandardMaryBlock -> LedgerState
- pattern LedgerStateAlonzo :: LedgerState StandardAlonzoBlock -> LedgerState
- pattern LedgerStateBabbage :: LedgerState StandardBabbageBlock -> LedgerState
- pattern LedgerStateConway :: LedgerState StandardConwayBlock -> LedgerState
- encodeLedgerState :: CardanoCodecConfig StandardCrypto -> LedgerState -> Encoding
- decodeLedgerState :: CardanoCodecConfig StandardCrypto -> forall s. Decoder s LedgerState
- initialLedgerState :: forall t (m :: Type -> Type). MonadIOTransError InitialLedgerStateError t m => NodeConfigFile 'In -> t m (Env, LedgerState)
- applyBlock :: Env -> LedgerState -> ValidationMode -> BlockInMode -> Either LedgerStateError (LedgerState, [LedgerEvent])
- data ValidationMode
- applyBlockWithEvents :: Env -> LedgerState -> Bool -> CardanoBlock StandardCrypto -> Either LedgerStateError LedgerStateEvents
- data AnyNewEpochState where
- AnyNewEpochState :: forall era. ShelleyBasedEra era -> NewEpochState (ShelleyLedgerEra era) -> AnyNewEpochState
- getAnyNewEpochState :: ShelleyBasedEra era -> LedgerState -> Either LedgerStateError AnyNewEpochState
- foldBlocks :: forall a t (m :: Type -> Type). (Show a, MonadIOTransError FoldBlocksError t m) => NodeConfigFile 'In -> SocketPath -> ValidationMode -> a -> (Env -> LedgerState -> [LedgerEvent] -> BlockInMode -> a -> IO (a, FoldStatus)) -> t m a
- data FoldStatus
- chainSyncClientWithLedgerState :: forall (m :: Type -> Type) a. Monad m => Env -> LedgerState -> ValidationMode -> ChainSyncClient (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a -> ChainSyncClient BlockInMode ChainPoint ChainTip m a
- chainSyncClientPipelinedWithLedgerState :: forall (m :: Type -> Type) a. Monad m => Env -> LedgerState -> ValidationMode -> ChainSyncClientPipelined (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a -> ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
- data ConditionResult
- fromConditionResult :: ConditionResult -> Bool
- toConditionResult :: Bool -> ConditionResult
- foldEpochState :: forall t (m :: Type -> Type) s. MonadIOTransError FoldBlocksError t m => NodeConfigFile 'In -> SocketPath -> ValidationMode -> EpochNo -> s -> (AnyNewEpochState -> SlotNo -> BlockNo -> StateT s IO ConditionResult) -> t m (ConditionResult, s)
- data LedgerStateError
- data FoldBlocksError
- data GenesisConfigError
- data InitialLedgerStateError
- data LeadershipError
- = LeaderErrDecodeLedgerStateFailure
- | LeaderErrDecodeProtocolStateFailure (ByteString, DecoderError)
- | LeaderErrDecodeProtocolEpochStateFailure DecoderError
- | LeaderErrGenesisSlot
- | LeaderErrStakePoolHasNoStake PoolId
- | LeaderErrStakeDistribUnstable SlotNo SlotNo SlotNo SlotNo
- | LeaderErrSlotRangeCalculationFailure Text
- | LeaderErrCandidateNonceStillEvolving
- constructGlobals :: ShelleyGenesis StandardCrypto -> EpochInfo (Either Text) -> Globals
- currentEpochEligibleLeadershipSlots :: ShelleyBasedEra era -> ShelleyGenesis StandardCrypto -> EpochInfo (Either Text) -> PParams (ShelleyLedgerEra era) -> ProtocolState era -> PoolId -> SigningKey VrfKey -> SerialisedPoolDistribution era -> EpochNo -> Either LeadershipError (Set SlotNo)
- nextEpochEligibleLeadershipSlots :: ShelleyBasedEra era -> ShelleyGenesis StandardCrypto -> SerialisedCurrentEpochState era -> ProtocolState era -> PoolId -> SigningKey VrfKey -> PParams (ShelleyLedgerEra era) -> EpochInfo (Either Text) -> (ChainTip, EpochNo) -> Either LeadershipError (Set SlotNo)
- data NodeConfig = NodeConfig {
- ncPBftSignatureThreshold :: !(Maybe Double)
- ncByronGenesisFile :: !(File ByronGenesisConfig 'In)
- ncByronGenesisHash :: !GenesisHashByron
- ncShelleyGenesisFile :: !(File ShelleyGenesisConfig 'In)
- ncShelleyGenesisHash :: !GenesisHashShelley
- ncAlonzoGenesisFile :: !(File AlonzoGenesis 'In)
- ncAlonzoGenesisHash :: !GenesisHashAlonzo
- ncConwayGenesisFile :: !(Maybe (File ConwayGenesisConfig 'In))
- ncConwayGenesisHash :: !(Maybe GenesisHashConway)
- ncRequiresNetworkMagic :: !RequiresNetworkMagic
- ncByronProtocolVersion :: !ProtocolVersion
- ncHardForkTriggers :: !CardanoHardForkTriggers
- type NodeConfigFile = File NodeConfig
- readNodeConfig :: (MonadError Text m, MonadIO m) => NodeConfigFile 'In -> m NodeConfig
- data GenesisConfig = GenesisCardano !NodeConfig !Config !GenesisHashShelley !(TransitionConfig (LatestKnownEra StandardCrypto))
- readCardanoGenesisConfig :: forall t (m :: Type -> Type) era. MonadIOTransError GenesisConfigError t m => Maybe (CardanoEra era) -> NodeConfig -> t m GenesisConfig
- mkProtocolInfoCardano :: GenesisConfig -> (ProtocolInfo (CardanoBlock StandardCrypto), IO [BlockForging IO (CardanoBlock StandardCrypto)])
- readByronGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m Config
- data ShelleyConfig = ShelleyConfig {}
- newtype GenesisHashShelley = GenesisHashShelley {}
- readShelleyGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m ShelleyConfig
- shelleyPraosNonce :: GenesisHashShelley -> Nonce
- newtype GenesisHashAlonzo = GenesisHashAlonzo {}
- readAlonzoGenesisConfig :: forall t (m :: Type -> Type) era. MonadIOTransError GenesisConfigError t m => Maybe (CardanoEra era) -> NodeConfig -> t m AlonzoGenesis
- newtype GenesisHashConway = GenesisHashConway {}
- readConwayGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m (ConwayGenesis StandardCrypto)
- data Env = Env {}
- genesisConfigToEnv :: GenesisConfig -> Either GenesisConfigError Env
Initialization / Accumulation
envSecurityParam :: Env -> Word64 Source #
newtype LedgerState Source #
pattern LedgerStateByron :: LedgerState ByronBlock -> LedgerState | |
pattern LedgerStateShelley :: LedgerState StandardShelleyBlock -> LedgerState | |
pattern LedgerStateAllegra :: LedgerState StandardAllegraBlock -> LedgerState | |
pattern LedgerStateMary :: LedgerState StandardMaryBlock -> LedgerState | |
pattern LedgerStateAlonzo :: LedgerState StandardAlonzoBlock -> LedgerState | |
pattern LedgerStateBabbage :: LedgerState StandardBabbageBlock -> LedgerState | |
pattern LedgerStateConway :: LedgerState StandardConwayBlock -> LedgerState |
Instances
Show LedgerState Source # | |
Defined in Cardano.Api.LedgerState |
decodeLedgerState :: CardanoCodecConfig StandardCrypto -> forall s. Decoder s LedgerState Source #
:: forall t (m :: Type -> Type). MonadIOTransError InitialLedgerStateError t m | |
=> NodeConfigFile 'In | Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json) |
-> t m (Env, LedgerState) | The environment and initial ledger state |
Get the environment and initial ledger state.
:: Env | The environment returned by |
-> LedgerState | The current ledger state |
-> ValidationMode | |
-> BlockInMode | Some block to apply |
-> Either LedgerStateError (LedgerState, [LedgerEvent]) | The new ledger state (or an error). |
Apply a single block to the current ledger state.
data ValidationMode Source #
How to do validation when applying a block to a ledger state.
FullValidation | Do all validation implied by the ledger layer's |
QuickValidation | Only check that the previous hash from the block matches the head hash of the ledger state. |
:: Env | |
-> LedgerState | |
-> Bool | True to validate |
-> CardanoBlock StandardCrypto | |
-> Either LedgerStateError LedgerStateEvents |
data AnyNewEpochState where Source #
AnyNewEpochState :: forall era. ShelleyBasedEra era -> NewEpochState (ShelleyLedgerEra era) -> AnyNewEpochState |
Instances
Show AnyNewEpochState Source # | |
Defined in Cardano.Api.LedgerState |
getAnyNewEpochState :: ShelleyBasedEra era -> LedgerState -> Either LedgerStateError AnyNewEpochState Source #
Retrieve new epoch state from the ledger state, or an error on failure
Traversing the block chain
:: forall a t (m :: Type -> Type). (Show a, MonadIOTransError FoldBlocksError t m) | |
=> NodeConfigFile 'In | Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json) |
-> SocketPath | Path to local cardano-node socket. This is the path specified by the |
-> ValidationMode | |
-> a | The initial accumulator state. |
-> (Env -> LedgerState -> [LedgerEvent] -> BlockInMode -> a -> IO (a, FoldStatus)) | Accumulator function Takes:
And returns:
Note: This function can safely assume no rollback will occur even though internally this is implemented with a client protocol that may require rollback. This is achieved by only calling the accumulator on states/blocks that are older than the security parameter, k. This has the side effect of truncating the last k blocks before the node's tip. |
-> t m a | The final state |
Monadic fold over all blocks and ledger states. Stopping k
blocks before
the node's tip where k
is the security parameter.
data FoldStatus Source #
Type that lets us decide whether to continue or stop the fold from within our accumulation function.
Instances
Show FoldStatus Source # | |
Defined in Cardano.Api.LedgerState | |
Eq FoldStatus Source # | |
Defined in Cardano.Api.LedgerState (==) :: FoldStatus -> FoldStatus -> Bool Source # (/=) :: FoldStatus -> FoldStatus -> Bool Source # |
chainSyncClientWithLedgerState Source #
:: forall (m :: Type -> Type) a. Monad m | |
=> Env | |
-> LedgerState | Initial ledger state |
-> ValidationMode | |
-> ChainSyncClient (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a | A client to wrap. The block is annotated with a 'Either LedgerStateError
LedgerState'. This is either an error from validating a block or
the current |
-> ChainSyncClient BlockInMode ChainPoint ChainTip m a | A client that acts just like the wrapped client but doesn't require the
|
Wrap a ChainSyncClient
with logic that tracks the ledger state.
chainSyncClientPipelinedWithLedgerState :: forall (m :: Type -> Type) a. Monad m => Env -> LedgerState -> ValidationMode -> ChainSyncClientPipelined (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a -> ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a Source #
Ledger state conditions
data ConditionResult Source #
Type isomorphic to bool, representing condition check result
Instances
:: forall t (m :: Type -> Type) s. MonadIOTransError FoldBlocksError t m | |
=> NodeConfigFile 'In | Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json) |
-> SocketPath | Path to local cardano-node socket. This is the path specified by the |
-> ValidationMode | |
-> EpochNo | Termination epoch |
-> s | an initial value for the condition state |
-> (AnyNewEpochState -> SlotNo -> BlockNo -> StateT s IO ConditionResult) | Condition you want to check against the new epoch state.
Note: This function can safely assume no rollback will occur even though internally this is implemented with a client protocol that may require rollback. This is achieved by only calling the accumulator on states/blocks that are older than the security parameter, k. This has the side effect of truncating the last k blocks before the node's tip. |
-> t m (ConditionResult, s) | The final state |
Reconstructs the ledger's new epoch state and applies a supplied condition to it for every block. This function only terminates if the condition is met or we have reached the termination epoch. We need to provide a termination epoch otherwise blocks would be applied indefinitely.
Errors
data LedgerStateError Source #
ApplyBlockHashMismatch Text | When using QuickValidation, the block hash did not match the expected block hash after applying a new block to the current ledger state. |
ApplyBlockError (CardanoLedgerError StandardCrypto) | When using FullValidation, an error occurred when applying a new block to the current ledger state. |
InvalidRollback | Encountered a rollback larger than the security parameter. |
| |
TerminationEpochReached EpochNo | The ledger state condition you were interested in was not met prior to the termination epoch. |
UnexpectedLedgerState | |
| |
ByronEraUnsupported | |
DebugError !String |
Instances
Exception LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState | |
Show LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState | |
Error LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState prettyError :: LedgerStateError -> Doc ann Source # |
data FoldBlocksError Source #
FoldBlocksInitialLedgerStateError !InitialLedgerStateError | |
FoldBlocksApplyBlockError !LedgerStateError | |
FoldBlocksIOException !IOException | |
FoldBlocksMuxError !MuxError |
Instances
Show FoldBlocksError Source # | |
Defined in Cardano.Api.LedgerState | |
Error FoldBlocksError Source # | |
Defined in Cardano.Api.LedgerState prettyError :: FoldBlocksError -> Doc ann Source # |
data GenesisConfigError Source #
NEError !Text | |
NEByronConfig !FilePath !ConfigurationError | |
NEShelleyConfig !FilePath !Text | |
NEAlonzoConfig !FilePath !Text | |
NEConwayConfig !FilePath !Text | |
NECardanoConfig !Text |
Instances
Exception GenesisConfigError Source # | |
Show GenesisConfigError Source # | |
Defined in Cardano.Api.LedgerState | |
Error GenesisConfigError Source # | |
Defined in Cardano.Api.LedgerState prettyError :: GenesisConfigError -> Doc ann Source # |
data InitialLedgerStateError Source #
ILSEConfigFile Text | Failed to read or parse the network config file. |
ILSEGenesisFile GenesisConfigError | Failed to read or parse a genesis file linked from the network config file. |
ILSELedgerConsensusConfig GenesisConfigError | Failed to derive the Ledger or Consensus config. |
Instances
Exception InitialLedgerStateError Source # | |
Show InitialLedgerStateError Source # | |
Defined in Cardano.Api.LedgerState | |
Error InitialLedgerStateError Source # | |
Defined in Cardano.Api.LedgerState prettyError :: InitialLedgerStateError -> Doc ann Source # |
Leadership schedule
data LeadershipError Source #
Instances
Show LeadershipError Source # | |
Defined in Cardano.Api.LedgerState | |
Error LeadershipError Source # | |
Defined in Cardano.Api.LedgerState prettyError :: LeadershipError -> Doc ann Source # |
currentEpochEligibleLeadershipSlots Source #
:: ShelleyBasedEra era | |
-> ShelleyGenesis StandardCrypto | |
-> EpochInfo (Either Text) | |
-> PParams (ShelleyLedgerEra era) | |
-> ProtocolState era | |
-> PoolId | |
-> SigningKey VrfKey | |
-> SerialisedPoolDistribution era | |
-> EpochNo | Current EpochInfo |
-> Either LeadershipError (Set SlotNo) |
Return the slots at which a particular stake pool operator is expected to mint a block.
nextEpochEligibleLeadershipSlots Source #
:: ShelleyBasedEra era | |
-> ShelleyGenesis StandardCrypto | |
-> SerialisedCurrentEpochState era | We need the mark stake distribution in order to predict the following epoch's leadership schedule |
-> ProtocolState era | |
-> PoolId | Potential slot leading stake pool |
-> SigningKey VrfKey | VRF signing key of the stake pool |
-> PParams (ShelleyLedgerEra era) | |
-> EpochInfo (Either Text) | |
-> (ChainTip, EpochNo) | |
-> Either LeadershipError (Set SlotNo) |
Node Config
data NodeConfig Source #
Instances
FromJSON NodeConfig Source # | |
Defined in Cardano.Api.LedgerState parseJSON :: Value -> Parser NodeConfig # parseJSONList :: Value -> Parser [NodeConfig] # |
Network Config
type NodeConfigFile = File NodeConfig Source #
readNodeConfig :: (MonadError Text m, MonadIO m) => NodeConfigFile 'In -> m NodeConfig Source #
Genesis Config
data GenesisConfig Source #
readCardanoGenesisConfig Source #
:: forall t (m :: Type -> Type) era. MonadIOTransError GenesisConfigError t m | |
=> Maybe (CardanoEra era) | Provide era witness to read Alonzo Genesis in an era-sensitive manner (see
|
-> NodeConfig | |
-> t m GenesisConfig |
mkProtocolInfoCardano :: GenesisConfig -> (ProtocolInfo (CardanoBlock StandardCrypto), IO [BlockForging IO (CardanoBlock StandardCrypto)]) Source #
Byron Genesis Config
readByronGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m Config Source #
Shelley Genesis Config
data ShelleyConfig Source #
newtype GenesisHashShelley Source #
Instances
Show GenesisHashShelley Source # | |
Defined in Cardano.Api.Genesis | |
Eq GenesisHashShelley Source # | |
Defined in Cardano.Api.Genesis (==) :: GenesisHashShelley -> GenesisHashShelley -> Bool Source # (/=) :: GenesisHashShelley -> GenesisHashShelley -> Bool Source # |
readShelleyGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m ShelleyConfig Source #
shelleyPraosNonce :: GenesisHashShelley -> Nonce Source #
Compute the Nonce from the hash of the Genesis file.
Alonzo Genesis Config
newtype GenesisHashAlonzo Source #
Instances
Show GenesisHashAlonzo Source # | |
Defined in Cardano.Api.Genesis | |
Eq GenesisHashAlonzo Source # | |
Defined in Cardano.Api.Genesis (==) :: GenesisHashAlonzo -> GenesisHashAlonzo -> Bool Source # (/=) :: GenesisHashAlonzo -> GenesisHashAlonzo -> Bool Source # |
readAlonzoGenesisConfig Source #
:: forall t (m :: Type -> Type) era. MonadIOTransError GenesisConfigError t m | |
=> Maybe (CardanoEra era) | Provide era witness to read Alonzo Genesis in an era-sensitive manner (see
|
-> NodeConfig | |
-> t m AlonzoGenesis |
Conway Genesis Config
newtype GenesisHashConway Source #
Instances
Show GenesisHashConway Source # | |
Defined in Cardano.Api.Genesis | |
Eq GenesisHashConway Source # | |
Defined in Cardano.Api.Genesis (==) :: GenesisHashConway -> GenesisHashConway -> Bool Source # (/=) :: GenesisHashConway -> GenesisHashConway -> Bool Source # |
readConwayGenesisConfig :: forall t (m :: Type -> Type). MonadIOTransError GenesisConfigError t m => NodeConfig -> t m (ConwayGenesis StandardCrypto) Source #
If the conway genesis file does not exist we simply put in a default.