EmulatorState

scalus.cardano.node.EmulatorState
See theEmulatorState companion object
case class EmulatorState

The entire mutable state of an EmulatorBase, as one immutable value: a chain of real blocks, a mempool, and the config, spec section 6.

Aggregating it is what lets one state machine serve both platforms, and it is also what makes a transaction land atomically: the ledger state and the bookkeeping that describes it are swapped together, so no reader — and on the JVM no other submitting thread — can observe a UTxO set that has moved on while the applied-transaction log has not caught up. Every transition is a pure function from one state to the next, spec [ST-9].

The readers ledger, context and binaryDatums return the tip snapshot, spec [ST-8], ticked to the current slot, as the node's ticked ledger state, spec [NL-2]. The stored snapshots stay at the slot their ledger state was produced at, so a block forged on an older block, or after a rollback, sees the treasury and the donations of its own slot. The current slot is its own field: withSlot moves it, and it can be ahead of the tip block's slot.

appliedTxLog, appliedTxIndex and appliedTxs are derived, kept for O(1) lookup: the log is the imported log, then the txs of the selected-chain blocks above the log start, spec [TS-5]. The constructor is private, so EmulatorState.initial and the transitions below are the only way to build one, and no caller can hand back a state whose log and caches disagree (EmulatorStateInvariantTest pins it).

The log records one entry per application, while the two derived views are keyed by hash, so they are not always the same size. Applying one transaction twice needs the direct ledger edits (EmulatorBase.addUtxo) to put its inputs back — the ledger rules reject the second submission otherwise — but it is reachable, and then the log holds both applications while the index holds the later one and appliedTxs holds the hash once.

Value parameters

appliedTxIndex

derived: appliedTxLog keyed by transaction hash, holding the latest application of each

appliedTxLog

derived: the imported log, then the txs of the selected chain above logStart

appliedTxs

derived: the distinct hashes in appliedTxLog

blocks

the block tree, by block id

chain

the ids of the selected chain, oldest first. Genesis is not in it.

config

how this emulator behaves as a chain

currentSlot

the current slot, spec [VW-9]

genesisSnapshot

the snapshot of genesis, until it is deeper than k, spec [ST-4]

importedLog

the applied-tx log the state was built with, spec [TS-5]

logStart

the height above which the txs of the selected chain join the log, spec [DE-4]

mempool

the pending txs, oldest first

statuses

the status of each tx that left the mempool or the selected chain: Dropped by revalidation, spec [RV-3], or RolledBack under the Drop policy, spec [OR-4]. Kept, since the entry or the block is gone.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

The treasury and the reserves of the tip snapshot, ledger-rules spec [ES-9]. The treasury is context.env.treasury, spec [DM-13].

The treasury and the reserves of the tip snapshot, ledger-rules spec [ES-9]. The treasury is context.env.treasury, spec [DM-13].

Attributes

The datum store of the tip snapshot, spec [ST-8], spec [SC-13k].

The datum store of the tip snapshot, spec [ST-8], spec [SC-13k].

Attributes

The validation context of the tip snapshot, spec [ST-8].

The validation context of the tip snapshot, spec [ST-8].

Attributes

def ledger: State

The ledger state of the tip snapshot, spec [ST-8].

The ledger state of the tip snapshot, spec [ST-8].

Attributes

The whole ledger state of the tip snapshot in the shape of the node's NewEpochState, ledger-rules spec D122.

The whole ledger state of the tip snapshot in the shape of the node's NewEpochState, ledger-rules spec D122.

Attributes

The ratify result the last boundary of the tip snapshot computed and the next one enacts, ledger-rules spec [ES-9b], [EB-20]. At genesis it enacts nothing, spec [DM-9c].

The ratify result the last boundary of the tip snapshot computed and the next one enacts, ledger-rules spec [ES-9b], [EB-20]. At genesis it enacts nothing, spec [DM-9c].

Attributes

The reward update the last boundary of the tip snapshot computed and the next one pays, or None before the first boundary, ledger-rules spec [ES-9a], [RW-21].

The reward update the last boundary of the tip snapshot computed and the next one pays, or None before the first boundary, ledger-rules spec [ES-9a], [RW-21].

Attributes

The stake snapshots mark, set, go and the fee snapshot of the tip snapshot, ledger-rules spec [ES-9a].

The stake snapshots mark, set, go and the fee snapshot of the tip snapshot, ledger-rules spec [ES-9a].

Attributes

def withApplied(newLedger: State, applied: AppliedTx): EmulatorState

The state after applied moved the ledger to newLedger, as after a submit that passed validation: the tx joins the mempool, and in the Instant preset it is forged into a block at once, spec [MP-6], [MP-8]. newLedger must follow the snapshot a submit validates on, which in Instant is the tip snapshot.

The state after applied moved the ledger to newLedger, as after a submit that passed validation: the tx joins the mempool, and in the Instant preset it is forged into a block at once, spec [MP-6], [MP-8]. newLedger must follow the snapshot a submit validates on, which in Instant is the tip snapshot.

Attributes

The state with an empty applied-tx log: the imported log is dropped and the log starts above the tip, spec [DE-4]. No block is removed, and the ledger, the context and the datum store are kept: see EmulatorBase.clearAppliedTxs.

The state with an empty applied-tx log: the imported log is dropped and the log starts above the tip, spec [DE-4]. No block is removed, and the ledger, the context and the datum store are kept: see EmulatorBase.clearAppliedTxs.

Attributes

def withRewards(credential: Credential, amount: Coin): EmulatorState

The state with amount added to the reward balance of the account of credential.

The state with amount added to the reward balance of the account of credential.

Attributes

The state at a different slot, spec [NL-2]: only the current slot moves. The tip snapshot readers see is the stored one ticked to it, so crossing epoch boundaries forwards runs their epoch transitions, ledger-rules spec [EB-1]. Moving back before a boundary undoes it only when the tip block is before that boundary too: the tick never runs a boundary the stored tip ran already, ledger-rules spec D66. A tx submitted there is validated at the epoch of the current slot, which can be below the boundaries the tip ran, ledger-rules spec D67: for example a pool retirement for such a boundary is accepted and never reaped.

The state at a different slot, spec [NL-2]: only the current slot moves. The tip snapshot readers see is the stored one ticked to it, so crossing epoch boundaries forwards runs their epoch transitions, ledger-rules spec [EB-1]. Moving back before a boundary undoes it only when the tip block is before that boundary too: the tick never runs a boundary the stored tip ran already, ledger-rules spec D66. A tx submitted there is validated at the epoch of the current slot, which can be below the boundaries the tip ran, ledger-rules spec D67: for example a pool retirement for such a boundary is accepted and never reaped.

Attributes

Throws
IllegalArgumentException

in the Manual preset, for a slot below the slot of the tip block, spec [RV-8]

The state with one UTxO added, or replaced if one already sits at input, for the direct ledger edits that bypass validation.

The state with one UTxO added, or replaced if one already sits at input, for the direct ledger edits that bypass validation.

An inline datum on output joins the datum store, which is how a script UTxO seeded with EmulatorBase.addUtxo answers EmulatorBase.getDatum — a real node and Blockfrost both index the datums held in the UTxO set, not only those a transaction carried in its witness set. Only output is indexed, never the whole set: every other UTxO was indexed when it arrived, so seeding N UTxOs costs O(N) rather than O(N²). Nothing is removed: the store is everything the emulator has seen.

Attributes

The state with the UTxO at input dropped, for the direct ledger edits that bypass validation. A no-op if none sits there.

The state with the UTxO at input dropped, for the direct ledger edits that bypass validation. A no-op if none sits there.

The datum store is deliberately left alone: a node keeps answering for a datum it has seen after the output holding it is spent, and so does this.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product