cardano-api:internal
Safe HaskellNone
LanguageHaskell2010

Cardano.Api.LedgerState

Synopsis

Initialization / Accumulation

initialLedgerState Source #

Arguments

:: 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.

applyBlock Source #

Arguments

:: Env

The environment returned by initialLedgerState

-> 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.

Constructors

FullValidation

Do all validation implied by the ledger layer's applyBlock.

QuickValidation

Only check that the previous hash from the block matches the head hash of the ledger state.

applyBlockWithEvents Source #

Arguments

:: Env 
-> LedgerState 
-> Bool

True to validate

-> CardanoBlock StandardCrypto 
-> Either LedgerStateError LedgerStateEvents 

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

foldBlocks Source #

Arguments

:: 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 --socket-path command line option when running the node.

-> ValidationMode 
-> a

The initial accumulator state.

-> (Env -> LedgerState -> [LedgerEvent] -> BlockInMode -> a -> IO (a, FoldStatus))

Accumulator function Takes:

  • Environment (this is a constant over the whole fold).
  • The Ledger state (with block i applied) at block i.
  • The Ledger events resulting from applying block i.
  • Block i.
  • The accumulator state at block i - 1.

And returns:

  • The accumulator state at block i
  • A type indicating whether to stop or continue folding.

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

Instances details
Show FoldStatus Source # 
Instance details

Defined in Cardano.Api.LedgerState

Eq FoldStatus Source # 
Instance details

Defined in Cardano.Api.LedgerState

chainSyncClientWithLedgerState Source #

Arguments

:: 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 LedgerState from applying the current block. If we trust the node, then we generally expect blocks to validate. Also note that after a block fails to validate we may still roll back to a validated block, in which case the valid LedgerState will be passed here again.

-> ChainSyncClient BlockInMode ChainPoint ChainTip m a

A client that acts just like the wrapped client but doesn't require the LedgerState annotation on the block type.

Wrap a ChainSyncClient with logic that tracks the ledger state.

Ledger state conditions

data ConditionResult Source #

Type isomorphic to bool, representing condition check result

Instances

Instances details
Bounded ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

Enum ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

Read ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

Show ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

Eq ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

Ord ConditionResult Source # 
Instance details

Defined in Cardano.Api.LedgerState

foldEpochState Source #

Arguments

:: 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 --socket-path command line option when running the node.

-> 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.

SlotNo - Current (not necessarily the tip) slot number

BlockNo - Current (not necessarily the tip) block number

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 #

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 (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.

Fields

  • SlotNo

    Oldest known slot number that we can roll back to.

  • ChainPoint

    Rollback was attempted to this point.

TerminationEpochReached EpochNo

The ledger state condition you were interested in was not met prior to the termination epoch.

UnexpectedLedgerState 

Fields

ByronEraUnsupported 
DebugError !String 

Leadership schedule

currentEpochEligibleLeadershipSlots Source #

Return the slots at which a particular stake pool operator is expected to mint a block.

nextEpochEligibleLeadershipSlots Source #

Arguments

:: 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

Network Config

Genesis Config

readCardanoGenesisConfig Source #

Arguments

:: 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 decodeAlonzGenesis for more details)

-> NodeConfig 
-> t m GenesisConfig 

Byron Genesis Config

Shelley Genesis Config

shelleyPraosNonce :: GenesisHashShelley -> Nonce Source #

Compute the Nonce from the hash of the Genesis file.

Alonzo Genesis Config

readAlonzoGenesisConfig Source #

Arguments

:: 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 decodeAlonzGenesis for more details)

-> NodeConfig 
-> t m AlonzoGenesis 

Conway Genesis Config

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.

Environment