Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Api.LedgerState
Synopsis
- data Env = Env {
- envLedgerConfig ∷ HardForkLedgerConfig (CardanoEras StandardCrypto)
- envProtocolConfig ∷ ConsensusConfig (HardForkProtocol (CardanoEras StandardCrypto))
- envSecurityParam ∷ Env → Word64
- newtype LedgerState where
- LedgerState {
- clsState ∷ LedgerState (HardForkBlock (CardanoEras StandardCrypto))
- pattern LedgerStateByron ∷ LedgerState ByronBlock → LedgerState
- pattern LedgerStateShelley ∷ LedgerState (ShelleyBlock (ShelleyEra StandardCrypto)) → LedgerState
- pattern LedgerStateAllegra ∷ LedgerState (ShelleyBlock (AllegraEra StandardCrypto)) → LedgerState
- pattern LedgerStateMary ∷ LedgerState (ShelleyBlock (MaryEra StandardCrypto)) → LedgerState
- pattern LedgerStateAlonzo ∷ LedgerState (ShelleyBlock (AlonzoEra StandardCrypto)) → LedgerState
- LedgerState {
- initialLedgerState ∷ FilePath → 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 ∷ ∀ a. FilePath → FilePath → ValidationMode → a → (Env → LedgerState → [LedgerEvent] → BlockInMode CardanoMode → a → IO a) → ExceptT FoldBlocksError IO a
- chainSyncClientWithLedgerState ∷ ∀ m a. Monad m ⇒ Env → LedgerState → ValidationMode → ChainSyncClient (BlockInMode CardanoMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a → ChainSyncClient (BlockInMode CardanoMode) ChainPoint ChainTip m a
- chainSyncClientPipelinedWithLedgerState ∷ ∀ m a. Monad m ⇒ Env → LedgerState → ValidationMode → ChainSyncClientPipelined (BlockInMode CardanoMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a → ChainSyncClientPipelined (BlockInMode CardanoMode) ChainPoint ChainTip m a
- data LedgerStateError
- = ApplyBlockHashMismatch Text
- | ApplyBlockError (HardForkLedgerError (CardanoEras StandardCrypto))
- | InvalidRollback SlotNo ChainPoint
- data FoldBlocksError
- data GenesisConfigError
- = NEError !Text
- | NEByronConfig !FilePath !ConfigurationError
- | NEShelleyConfig !FilePath !Text
- | NEAlonzoConfig !FilePath !Text
- | NECardanoConfig !Text
- data InitialLedgerStateError
- renderLedgerStateError ∷ LedgerStateError → Text
- renderFoldBlocksError ∷ FoldBlocksError → Text
- renderGenesisConfigError ∷ GenesisConfigError → Text
- renderInitialLedgerStateError ∷ InitialLedgerStateError → Text
- data LeadershipError
- = LeaderErrDecodeLedgerStateFailure
- | LeaderErrDecodeProtocolStateFailure
- | LeaderErrDecodeProtocolEpochStateFailure DecoderError
- | LeaderErrGenesisSlot
- | LeaderErrStakePoolHasNoStake PoolId
- | LeaderErrStakeDistribUnstable SlotNo SlotNo SlotNo SlotNo
- | LeaderErrSlotRangeCalculationFailure Text
- | LeaderErrCandidateNonceStillEvolving
- constructGlobals ∷ ShelleyGenesis StandardShelley → EpochInfo (Either Text) → ProtocolParameters → Globals
- currentEpochEligibleLeadershipSlots ∷ ShelleyLedgerEra era ~ ledgerera ⇒ Era ledgerera ⇒ HasField "_d" (PParams ledgerera) UnitInterval ⇒ Signable (VRF (Crypto ledgerera)) Seed ⇒ Share (TxOut (ShelleyLedgerEra era)) ~ Interns (Credential 'Staking (Crypto (ShelleyLedgerEra era))) ⇒ Crypto ledgerera ~ StandardCrypto ⇒ ShelleyBasedEra era → ShelleyGenesis StandardShelley → EpochInfo (Either Text) → ProtocolParameters → ProtocolState era → PoolId → SigningKey VrfKey → SerialisedCurrentEpochState era → EpochNo → Either LeadershipError (Set SlotNo)
- nextEpochEligibleLeadershipSlots ∷ HasField "_d" (PParams (ShelleyLedgerEra era)) UnitInterval ⇒ Era (ShelleyLedgerEra era) ⇒ Share (TxOut (ShelleyLedgerEra era)) ~ Interns (Credential 'Staking (Crypto (ShelleyLedgerEra era))) ⇒ ShelleyBasedEra era → ShelleyGenesis StandardShelley → SerialisedCurrentEpochState era → ProtocolState era → PoolId → SigningKey VrfKey → ProtocolParameters → EpochInfo (Either Text) → (ChainTip, EpochNo) → Either LeadershipError (Set SlotNo)
Initialization / Accumulation
Constructors
Env | |
Fields
|
envSecurityParam ∷ Env → Word64 Source #
newtype LedgerState Source #
Constructors
LedgerState | |
Fields
|
Bundled Patterns
pattern LedgerStateByron ∷ LedgerState ByronBlock → LedgerState | |
pattern LedgerStateShelley ∷ LedgerState (ShelleyBlock (ShelleyEra StandardCrypto)) → LedgerState | |
pattern LedgerStateAllegra ∷ LedgerState (ShelleyBlock (AllegraEra StandardCrypto)) → LedgerState | |
pattern LedgerStateMary ∷ LedgerState (ShelleyBlock (MaryEra StandardCrypto)) → LedgerState | |
pattern LedgerStateAlonzo ∷ LedgerState (ShelleyBlock (AlonzoEra StandardCrypto)) → LedgerState |
Arguments
∷ FilePath | 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
∷ ∀ a. FilePath | Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json) |
→ FilePath | Path to local cardano-node socket. This is the path specified by the |
→ ValidationMode | |
→ a | The initial accumulator state. |
→ (Env → LedgerState → [LedgerEvent] → BlockInMode CardanoMode → a → IO a) | 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.
chainSyncClientWithLedgerState Source #
Arguments
∷ ∀ m a. Monad m | |
⇒ Env | |
→ LedgerState | Initial ledger state |
→ ValidationMode | |
→ ChainSyncClient (BlockInMode CardanoMode, 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 CardanoMode) 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 ∷ ∀ m a. Monad m ⇒ Env → LedgerState → ValidationMode → ChainSyncClientPipelined (BlockInMode CardanoMode, Either LedgerStateError (LedgerState, [LedgerEvent])) ChainPoint ChainTip m a → ChainSyncClientPipelined (BlockInMode CardanoMode) 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
|
Instances
Show LedgerStateError Source # | |
Defined in Cardano.Api.LedgerState |
data FoldBlocksError Source #
data GenesisConfigError Source #
Constructors
NEError !Text | |
NEByronConfig !FilePath !ConfigurationError | |
NEShelleyConfig !FilePath !Text | |
NEAlonzoConfig !FilePath !Text | |
NECardanoConfig !Text |
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. |
Leadership schedule
data LeadershipError Source #
Constructors
Instances
Show LeadershipError Source # | |
Defined in Cardano.Api.LedgerState | |
Error LeadershipError Source # | |
Defined in Cardano.Api.LedgerState Methods |
constructGlobals ∷ ShelleyGenesis StandardShelley → EpochInfo (Either Text) → ProtocolParameters → Globals Source #
currentEpochEligibleLeadershipSlots Source #
Arguments
∷ ShelleyLedgerEra era ~ ledgerera | |
⇒ Era ledgerera | |
⇒ HasField "_d" (PParams ledgerera) UnitInterval | |
⇒ Signable (VRF (Crypto ledgerera)) Seed | |
⇒ Share (TxOut (ShelleyLedgerEra era)) ~ Interns (Credential 'Staking (Crypto (ShelleyLedgerEra era))) | |
⇒ Crypto ledgerera ~ StandardCrypto | |
⇒ ShelleyBasedEra era | |
→ ShelleyGenesis StandardShelley | |
→ EpochInfo (Either Text) | |
→ ProtocolParameters | |
→ ProtocolState era | |
→ PoolId | |
→ SigningKey VrfKey | |
→ SerialisedCurrentEpochState 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
∷ HasField "_d" (PParams (ShelleyLedgerEra era)) UnitInterval | |
⇒ Era (ShelleyLedgerEra era) | |
⇒ Share (TxOut (ShelleyLedgerEra era)) ~ Interns (Credential 'Staking (Crypto (ShelleyLedgerEra era))) | |
⇒ ShelleyBasedEra era | |
→ ShelleyGenesis StandardShelley | |
→ 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 |
→ ProtocolParameters | |
→ EpochInfo (Either Text) | |
→ (ChainTip, EpochNo) | |
→ Either LeadershipError (Set SlotNo) |