cardano-api-8.36.1.1: The cardano api
Safe HaskellNone
LanguageHaskell2010

Cardano.Api.LedgerState

Synopsis

Initialization / Accumulation

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 

decodeLedgerState :: forall s. Decoder s LedgerState Source #

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

applyBlock Source #

Arguments

:: Env

The environment returned by initialLedgerState

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

-> HardForkBlock (CardanoEras StandardCrypto) 
-> Either LedgerStateError LedgerStateEvents 

Traversing the block chain

foldBlocks Source #

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

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

Instances

Instances details
Eq FoldStatus Source # 
Instance details

Defined in Cardano.Api.LedgerState

Show FoldStatus Source # 
Instance details

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

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

  • SlotNo

    Oldest known slot number that we can roll back to.

  • ChainPoint

    Rollback was attempted to this point.

DebugError !String 

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

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

Network Config

Genesis Config

data GenesisConfig Source #

Constructors

GenesisCardano !NodeConfig !Config !GenesisHashShelley !(TransitionConfig (LatestKnownEra StandardCrypto)) 

mkProtocolInfoCardano :: GenesisConfig -> (ProtocolInfo (HardForkBlock (CardanoEras StandardCrypto)), IO [BlockForging IO (HardForkBlock (CardanoEras StandardCrypto))]) Source #

Byron Genesis Config

Shelley Genesis Config

shelleyPraosNonce :: GenesisHashShelley -> Nonce Source #

Compute the Nonce from the hash of the Genesis file.

Alonzo Genesis Config

Conway Genesis Config

Environment

data Env Source #

Constructors

Env 

Fields