Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Api.LedgerState
Synopsis
- envSecurityParam :: Env -> Word64
- newtype LedgerState where
- LedgerState {
- clsState :: LedgerState (HardForkBlock (CardanoEras StandardCrypto))
- pattern LedgerStateByron :: LedgerState ByronBlock -> LedgerState
- pattern LedgerStateShelley :: LedgerState (ShelleyBlock protocol (ShelleyEra StandardCrypto)) -> LedgerState
- pattern LedgerStateAllegra :: LedgerState (ShelleyBlock protocol (AllegraEra StandardCrypto)) -> LedgerState
- pattern LedgerStateMary :: LedgerState (ShelleyBlock protocol (MaryEra StandardCrypto)) -> LedgerState
- pattern LedgerStateAlonzo :: LedgerState (ShelleyBlock protocol (AlonzoEra StandardCrypto)) -> LedgerState
- pattern LedgerStateBabbage :: LedgerState (ShelleyBlock protocol (BabbageEra StandardCrypto)) -> LedgerState
- pattern LedgerStateConway :: LedgerState (ShelleyBlock protocol (ConwayEra StandardCrypto)) -> LedgerState
- LedgerState {
- encodeLedgerState :: LedgerState -> Encoding
- decodeLedgerState :: forall s. Decoder s LedgerState
- initialLedgerState :: NodeConfigFile 'In -> ExceptT InitialLedgerStateError IO (Env, LedgerState)
- applyBlock :: Env -> LedgerState -> ValidationMode -> Block era -> Either LedgerStateError (LedgerState, [LedgerEvent])
- data ValidationMode
- applyBlockWithEvents :: Env -> LedgerState -> Bool -> HardForkBlock (CardanoEras StandardCrypto) -> Either LedgerStateError LedgerStateEvents
- foldBlocks :: forall a. Show a => NodeConfigFile 'In -> SocketPath -> ValidationMode -> a -> (Env -> LedgerState -> [LedgerEvent] -> BlockInMode -> a -> IO (a, FoldStatus)) -> ExceptT FoldBlocksError IO a
- data FoldStatus
- chainSyncClientWithLedgerState :: forall m 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 a. Monad m => Env -> LedgerState -> ValidationMode -> ChainSyncClientPipelined (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a -> ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
- data LedgerStateError
- = ApplyBlockHashMismatch Text
- | ApplyBlockError (HardForkLedgerError (CardanoEras StandardCrypto))
- | InvalidRollback SlotNo ChainPoint
- | DebugError !String
- data FoldBlocksError
- data GenesisConfigError
- = NEError !Text
- | NEByronConfig !FilePath !ConfigurationError
- | NEShelleyConfig !FilePath !Text
- | NEAlonzoConfig !FilePath !Text
- | NEConwayConfig !FilePath !Text
- | NECardanoConfig !Text
- data InitialLedgerStateError
- renderLedgerStateError :: LedgerStateError -> Text
- renderFoldBlocksError :: FoldBlocksError -> Text
- renderGenesisConfigError :: GenesisConfigError -> Text
- renderInitialLedgerStateError :: InitialLedgerStateError -> Text
- 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) -> ProtVer -> Globals
- currentEpochEligibleLeadershipSlots :: forall era. ShelleyBasedEra era -> ShelleyGenesis StandardCrypto -> EpochInfo (Either Text) -> PParams (ShelleyLedgerEra era) -> ProtocolState era -> PoolId -> SigningKey VrfKey -> SerialisedPoolDistribution era -> EpochNo -> Either LeadershipError (Set SlotNo)
- nextEpochEligibleLeadershipSlots :: forall era. 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 :: !(File ConwayGenesisConfig 'In)
- ncConwayGenesisHash :: !GenesisHashConway
- ncRequiresNetworkMagic :: !RequiresNetworkMagic
- ncByronProtocolVersion :: !ProtocolVersion
- ncHardForkTriggers :: !CardanoHardForkTriggers
- type NodeConfigFile = File NodeConfig
- readNodeConfig :: NodeConfigFile 'In -> ExceptT Text IO NodeConfig
- data GenesisConfig = GenesisCardano !NodeConfig !Config !GenesisHashShelley !(TransitionConfig (LatestKnownEra StandardCrypto))
- readCardanoGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO GenesisConfig
- mkProtocolInfoCardano :: GenesisConfig -> (ProtocolInfo (HardForkBlock (CardanoEras StandardCrypto)), IO [BlockForging IO (HardForkBlock (CardanoEras StandardCrypto))])
- readByronGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO Config
- data ShelleyConfig = ShelleyConfig {}
- newtype GenesisHashShelley = GenesisHashShelley {
- unGenesisHashShelley :: Hash Blake2b_256 ByteString
- readShelleyGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO ShelleyConfig
- shelleyPraosNonce :: GenesisHashShelley -> Nonce
- newtype GenesisHashAlonzo = GenesisHashAlonzo {
- unGenesisHashAlonzo :: Hash Blake2b_256 ByteString
- readAlonzoGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO AlonzoGenesis
- newtype GenesisHashConway = GenesisHashConway {
- unGenesisHashConway :: Hash Blake2b_256 ByteString
- readConwayGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO (ConwayGenesis StandardCrypto)
- data Env = Env {
- envLedgerConfig :: HardForkLedgerConfig (CardanoEras StandardCrypto)
- envProtocolConfig :: ConsensusConfig (HardForkProtocol (CardanoEras StandardCrypto))
- genesisConfigToEnv :: GenesisConfig -> Either GenesisConfigError Env
Initialization / Accumulation
envSecurityParam :: Env -> Word64 Source #
newtype LedgerState Source #
Constructors
LedgerState | |
Fields
|
Bundled Patterns
pattern LedgerStateByron :: LedgerState ByronBlock -> LedgerState | |
pattern LedgerStateShelley :: LedgerState (ShelleyBlock protocol (ShelleyEra StandardCrypto)) -> LedgerState | |
pattern LedgerStateAllegra :: LedgerState (ShelleyBlock protocol (AllegraEra StandardCrypto)) -> LedgerState | |
pattern LedgerStateMary :: LedgerState (ShelleyBlock protocol (MaryEra StandardCrypto)) -> LedgerState | |
pattern LedgerStateAlonzo :: LedgerState (ShelleyBlock protocol (AlonzoEra StandardCrypto)) -> LedgerState | |
pattern LedgerStateBabbage :: LedgerState (ShelleyBlock protocol (BabbageEra StandardCrypto)) -> LedgerState | |
pattern LedgerStateConway :: LedgerState (ShelleyBlock protocol (ConwayEra StandardCrypto)) -> LedgerState |
encodeLedgerState :: LedgerState -> Encoding Source #
decodeLedgerState :: forall s. Decoder s LedgerState Source #
Arguments
:: NodeConfigFile 'In | Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json) |
-> ExceptT InitialLedgerStateError IO (Env, LedgerState) | The environment and initial ledger state |
Get the environment and initial ledger state.
Arguments
:: Env | The environment returned by |
-> LedgerState | The current ledger state |
-> ValidationMode | |
-> Block era | 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.
Constructors
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. |
Arguments
:: Env | |
-> LedgerState | |
-> Bool | True to validate |
-> HardForkBlock (CardanoEras StandardCrypto) | |
-> Either LedgerStateError LedgerStateEvents |
Traversing the block chain
Arguments
:: forall a. Show a | |
=> 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. |
-> ExceptT FoldBlocksError IO 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.
Constructors
ContinueFold | |
StopFold | |
DebugFold |
Instances
Eq FoldStatus Source # | |
Defined in Cardano.Api.LedgerState Methods (==) :: FoldStatus -> FoldStatus -> Bool Source # (/=) :: FoldStatus -> FoldStatus -> Bool Source # | |
Show FoldStatus Source # | |
Defined in Cardano.Api.LedgerState |
chainSyncClientWithLedgerState Source #
Arguments
:: forall m 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 a. Monad m => Env -> LedgerState -> ValidationMode -> ChainSyncClientPipelined (BlockInMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a -> ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a Source #
Errors
data LedgerStateError Source #
Constructors
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 (HardForkLedgerError (CardanoEras 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. |
Fields
| |
DebugError !String |
Instances
Show LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState | |
Exception LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState Methods toException :: LedgerStateError -> SomeException Source # fromException :: SomeException -> Maybe LedgerStateError Source # |
data FoldBlocksError Source #
Constructors
FoldBlocksInitialLedgerStateError InitialLedgerStateError | |
FoldBlocksApplyBlockError LedgerStateError |
Instances
Show FoldBlocksError Source # | |
Defined in Cardano.Api.LedgerState |
data GenesisConfigError Source #
Constructors
NEError !Text | |
NEByronConfig !FilePath !ConfigurationError | |
NEShelleyConfig !FilePath !Text | |
NEAlonzoConfig !FilePath !Text | |
NEConwayConfig !FilePath !Text | |
NECardanoConfig !Text |
Instances
Show GenesisConfigError Source # | |
Defined in Cardano.Api.LedgerState | |
Exception GenesisConfigError Source # | |
Defined in Cardano.Api.LedgerState Methods toException :: GenesisConfigError -> SomeException Source # fromException :: SomeException -> Maybe GenesisConfigError Source # |
data InitialLedgerStateError Source #
Constructors
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
Show InitialLedgerStateError Source # | |
Defined in Cardano.Api.LedgerState | |
Exception InitialLedgerStateError Source # | |
Defined in Cardano.Api.LedgerState |
renderLedgerStateError :: LedgerStateError -> Text Source #
renderFoldBlocksError :: FoldBlocksError -> Text Source #
renderGenesisConfigError :: GenesisConfigError -> Text Source #
Leadership schedule
data LeadershipError Source #
Constructors
Instances
Show LeadershipError Source # | |
Defined in Cardano.Api.LedgerState | |
Error LeadershipError Source # | |
Defined in Cardano.Api.LedgerState Methods prettyError :: LeadershipError -> Doc ann Source # |
constructGlobals :: ShelleyGenesis StandardCrypto -> EpochInfo (Either Text) -> ProtVer -> Globals Source #
currentEpochEligibleLeadershipSlots Source #
Arguments
:: forall era. 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 #
Arguments
:: forall era. 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 #
Constructors
NodeConfig | |
Fields
|
Instances
FromJSON NodeConfig Source # | |
Defined in Cardano.Api.LedgerState |
Network Config
type NodeConfigFile = File NodeConfig Source #
readNodeConfig :: NodeConfigFile 'In -> ExceptT Text IO NodeConfig Source #
Genesis Config
data GenesisConfig Source #
Constructors
GenesisCardano !NodeConfig !Config !GenesisHashShelley !(TransitionConfig (LatestKnownEra StandardCrypto)) |
readCardanoGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO GenesisConfig Source #
mkProtocolInfoCardano :: GenesisConfig -> (ProtocolInfo (HardForkBlock (CardanoEras StandardCrypto)), IO [BlockForging IO (HardForkBlock (CardanoEras StandardCrypto))]) Source #
Byron Genesis Config
readByronGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO Config Source #
Shelley Genesis Config
data ShelleyConfig Source #
Constructors
ShelleyConfig | |
Fields |
newtype GenesisHashShelley Source #
Constructors
GenesisHashShelley | |
Fields
|
Instances
Eq GenesisHashShelley Source # | |
Defined in Cardano.Api.Genesis Methods (==) :: GenesisHashShelley -> GenesisHashShelley -> Bool Source # (/=) :: GenesisHashShelley -> GenesisHashShelley -> Bool Source # | |
Show GenesisHashShelley Source # | |
Defined in Cardano.Api.Genesis |
readShelleyGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO ShelleyConfig Source #
shelleyPraosNonce :: GenesisHashShelley -> Nonce Source #
Compute the Nonce from the hash of the Genesis file.
Alonzo Genesis Config
newtype GenesisHashAlonzo Source #
Constructors
GenesisHashAlonzo | |
Fields
|
Instances
Eq GenesisHashAlonzo Source # | |
Defined in Cardano.Api.Genesis Methods (==) :: GenesisHashAlonzo -> GenesisHashAlonzo -> Bool Source # (/=) :: GenesisHashAlonzo -> GenesisHashAlonzo -> Bool Source # | |
Show GenesisHashAlonzo Source # | |
Defined in Cardano.Api.Genesis |
readAlonzoGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO AlonzoGenesis Source #
Conway Genesis Config
newtype GenesisHashConway Source #
Constructors
GenesisHashConway | |
Fields
|
Instances
Eq GenesisHashConway Source # | |
Defined in Cardano.Api.Genesis Methods (==) :: GenesisHashConway -> GenesisHashConway -> Bool Source # (/=) :: GenesisHashConway -> GenesisHashConway -> Bool Source # | |
Show GenesisHashConway Source # | |
Defined in Cardano.Api.Genesis |
readConwayGenesisConfig :: NodeConfig -> ExceptT GenesisConfigError IO (ConwayGenesis StandardCrypto) Source #
Environment
Constructors
Env | |
Fields
|