Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b718bae
Add SomeTxSkelOutDatumHash datum variant
mmontin Aug 2, 2026
aa1a549
Add UserScriptHash owner for hash-only script allocation
mmontin Aug 2, 2026
673d6b7
fixing missing cases in User, simplying a few optics there
mmontin Aug 3, 2026
7f54ee0
first draft on an node interpreter for read effect
mmontin Aug 3, 2026
519770a
still processing Read ... and the riples
mmontin Aug 5, 2026
388a694
library compiles
mmontin Aug 5, 2026
d15aaac
updating tests, everything works
mmontin Aug 5, 2026
0518529
restructuring read effects into Conf and Chain
mmontin Aug 5, 2026
88cee21
extracting ValidateTxSkel from Write
mmontin Aug 5, 2026
0cd56ab
extracting automation pipeline
mmontin Aug 5, 2026
bf2f707
sketching interp validate node
mmontin Aug 5, 2026
0763dd1
splitting MockChainState into EmulatorState and ChainIndex
mmontin Aug 5, 2026
0085e8d
upgrading the interpretation of GetConstitution with the storing of t…
mmontin Aug 5, 2026
e086e9b
Utxos == Map TxOutRef TxSkelOut
mmontin Aug 6, 2026
c063def
move pipeline into umbrella automation module
mmontin Aug 6, 2026
e2898ff
no more dummy input + clean up forceOutputs
mmontin Aug 7, 2026
490aba7
fixing missing doc'
mmontin Aug 7, 2026
c6d00ab
WIP
mmontin Aug 9, 2026
e6db16c
interpretation of validation
mmontin Aug 11, 2026
abc80a7
TIME handling
mmontin Aug 11, 2026
3b5bac8
Rename effect interpreters by backend prefix instead of suffix
mmontin Aug 12, 2026
5e5df4a
interpreting mockchainmisc on IO
mmontin Aug 12, 2026
aa096d7
refactor(mockchain): lift MockChain submodules up into Cooked
mmontin Aug 12, 2026
fad641d
refactor(mockchain): rename Cooked.Common to Cooked.Aliases
mmontin Aug 12, 2026
e2cf199
refactor(mockchain): move Testing into the Run subtree
mmontin Aug 12, 2026
06d9fb9
refactor(mockchain): merge UtxoSearch into Effect.Read.Chain
mmontin Aug 12, 2026
07790f4
refactor(mockchain): rename the Run subtree to MockChain
mmontin Aug 12, 2026
412055b
refactor(mockchain): add BlockChain module skeletons
mmontin Aug 12, 2026
fd609ac
docs: use module-link syntax for the Cooked reference in Conf
mmontin Aug 12, 2026
35e14c6
Add Effect, MockChain, Runtime and BlockChain umbrella modules
mmontin Aug 12, 2026
bd4e2af
Add Utilities umbrella, move Ltl under MockChain, document umbrella c…
mmontin Aug 12, 2026
9387fb0
Flatten Effect modules and drop MockChain prefix from effect types
mmontin Aug 12, 2026
5d764c3
Drop MockChain prefix from Runtime error and journal types
mmontin Aug 12, 2026
b86edc4
some more refactoring and renaming, resolving circular dependencies a…
mmontin Aug 12, 2026
932940d
refactoring Cooked.BlockChain
mmontin Aug 12, 2026
e3aee07
blockchain intances and runs
mmontin Aug 13, 2026
601fa47
fixing missing imports + proper effect stacks names
mmontin Aug 13, 2026
76070c1
adding Fail in DirectBlockChainEffs
mmontin Aug 13, 2026
e453242
full refactoring of utxo searches. Finally the right one
mmontin Aug 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist-newstyle
*.swp
docs/
.pre-commit-config.yaml
.github/copilot-instructions.md
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,44 @@

### Added

- New `txSkelOptProceedAfterValidationFailures` boolean option in `TxSkelOpts`
(with its `txSkelOptProceedAfterValidationFailuresL` optic). When set to
`True`, transaction validation failures no longer abort the mockchain run.
Default is `False`.
- New `UserScriptHash` constructor for `User`, representing an allocation-mode
script owner known only by its `Api.ScriptHash` (no script body). It can be
used to pay to a bare script hash through `receives` (a new
`IsTxSkelOutAllowedOwner Api.ScriptHash` instance). Spending an output owned by
such a user requires providing the full script through a matching reference
input; otherwise a new `MCESpendingHashOnlyScript` error is raised. The
`userVScriptL` optic is now restricted to `User IsScript Redemption`, since an
allocation-mode script owner may no longer carry a script body.
- New `SomeTxSkelOutDatumHash` constructor for `TxSkelOutDatum`, representing an
output datum known only by its hash (no datum content). It is mirrored by a
new `UtxoPayloadDatumHash` constructor in the resulting `UtxoState`, and a new
`MCESpendingHashOnlyDatum` error is raised when attempting to build the
spending witness of a script output whose datum is only a hash.

### Changed

- Time-related primitives have been regrouped into a new dedicated
`Cooked.MockChain.Effect.Time.MockChainTime` effect. The time queries
(`currentSlot`, `currentMSRange`, `getEnclosingSlot`, `slotToMSRange`,
`slotRangeBefore`, `slotRangeAfter`) that used to live in `MockChainReadChain`
and the waiting primitives (`waitNSlots`, `awaitSlot`, `awaitEnclosingSlot`,
`waitNMSFromSlotLowerBound`, `waitNMSFromSlotUpperBound`) that used to live in
`MockChainWrite` are now all provided by `MockChainTime`, with `waitNSlots` as
its sole state-modifying primitive.
- The former `MockChainState` has been split into two independent records, each
backed by its own state monad: `EmulatorState` (the emulator `Params` and
`EmulatedLedgerState`, only relevant when running against the emulated ledger)
and `ChainIndex` (the map of known outputs and the constitution script, which
is backend-agnostic and also meaningful for the node backend). Accordingly,
`mcstToUtxoState` is now `chainIndexToUtxoState`, the `mcst*L` optics are
replaced by `emulatorState*L`/`chainIndex*L`, `MockChainConf` now carries
`mccInitialEmulatorState` and `mccInitialChainIndex`, and
`RunnableMockChain.runMockChain` takes an `EmulatorState` and a `ChainIndex`.

### Removed

### Fixed
Expand Down
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,52 @@ When you are creating an enhancement request, follow these guidelines:

- Document all your functions using [Haddock]'s syntax.

### Module organization (umbrella modules)

Cohesive-but-multi-concern parts of the library are split into focused,
per-concern submodules that live in a directory, and re-exported from an
_umbrella module_ bearing the name of that directory (e.g. `Cooked.Tweak`
re-exports `Cooked.Tweak.Guard`, `Cooked.Tweak.Insert`, ...). Follow these
conventions when adding or reorganizing modules:

- **One umbrella per directory.** When a directory groups several submodules
that form a coherent sub-system, add an umbrella module of the same name that
re-exports them all, typically as:

```haskell
-- | One-line description of the sub-system.
module Cooked.Foo (module X) where

import Cooked.Foo.Bar as X
import Cooked.Foo.Baz as X
```

- **Re-export instance-only submodules with `()`.** When a submodule only
provides instances (empty export list), import it in the umbrella as
`import Cooked.Foo.Bar ()` so its instances are brought in without polluting
the export list. If _all_ submodules are instance-only, the umbrella itself
has an empty export list (`module Cooked.Foo () where`).

- **Umbrellas are aggregators first.** An umbrella may additionally host the
central type or entry point of its sub-system (as `Cooked.Skeleton` hosts
`TxSkel` and `Cooked.Automation` hosts `runAutomationPipeline`), but should
not accumulate unrelated logic. Everything else belongs in a submodule.

- **Do not systematically nest umbrellas.** A sub-directory whose submodules are
a mere refinement of their parent sub-system may be flattened into the parent
umbrella rather than getting its own (e.g. `Cooked.Automation.GenerateTx.*`
and `Cooked.Effect.Read.*` are re-exported directly from `Cooked.Automation`
and `Cooked.Effect`). Add an intermediate umbrella only when the sub-directory
is itself an independently meaningful sub-system.

- **Transverse utilities** (type aliases, wallets, low-level helpers) live under
`Cooked.Utilities.*` and are re-exported from `Cooked.Utilities`, keeping the
top level of `Cooked.*` for the functional pillars of the library.

- The top-level `Cooked` module is the global umbrella: it re-exports the
per-directory umbrellas only, never individual submodules. Adding a new
sub-system therefore means adding a single import line there.

### Nix style guide

- All Nix code is formatted with [nixfmt].
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ handling fees or balancing.
6. Submit the transaction:
``` haskell
validateTxSkel_
txSkelTemplate
txSkelEmulatorTemplate
{ txSkelOuts = [bob `receives` Value (Script.ada 10)],
txSkelSignatories = txSkelSignatoriesFromList [wallet 1]
}
Expand Down
83 changes: 50 additions & 33 deletions cooked-validators.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,55 @@ library
Cooked.Attack.RedeemerTampering
Cooked.Attack.TokenDuplication
Cooked.Attack.ValidityTampering
Cooked.Families
Cooked.Ltl
Cooked.Automation
Cooked.Automation.AutoFilling.Constitution
Cooked.Automation.AutoFilling.MinAda
Cooked.Automation.AutoFilling.ReferenceScripts
Cooked.Automation.AutoFilling.Withdrawals
Cooked.Automation.Balancing
Cooked.Automation.GenerateTx.Anchor
Cooked.Automation.GenerateTx.Body
Cooked.Automation.GenerateTx.Certificate
Cooked.Automation.GenerateTx.Collateral
Cooked.Automation.GenerateTx.Credential
Cooked.Automation.GenerateTx.Input
Cooked.Automation.GenerateTx.Mint
Cooked.Automation.GenerateTx.Output
Cooked.Automation.GenerateTx.Proposal
Cooked.Automation.GenerateTx.ReferenceInputs
Cooked.Automation.GenerateTx.Withdrawals
Cooked.Automation.GenerateTx.Witness
Cooked.BlockChain
Cooked.BlockChain.Config
Cooked.BlockChain.Instances
Cooked.BlockChain.Run
Cooked.Effect
Cooked.Effect.Log
Cooked.Effect.Misc
Cooked.Effect.Override
Cooked.Effect.Params
Cooked.Effect.Query
Cooked.Effect.Submission
Cooked.Effect.Time
Cooked.Effect.Validation
Cooked.MockChain
Cooked.MockChain.Automation.AutoFilling.Constitution
Cooked.MockChain.Automation.AutoFilling.MinAda
Cooked.MockChain.Automation.AutoFilling.ReferenceScripts
Cooked.MockChain.Automation.AutoFilling.Withdrawals
Cooked.MockChain.Automation.Balancing
Cooked.MockChain.Automation.GenerateTx.Anchor
Cooked.MockChain.Automation.GenerateTx.Body
Cooked.MockChain.Automation.GenerateTx.Certificate
Cooked.MockChain.Automation.GenerateTx.Collateral
Cooked.MockChain.Automation.GenerateTx.Credential
Cooked.MockChain.Automation.GenerateTx.Input
Cooked.MockChain.Automation.GenerateTx.Mint
Cooked.MockChain.Automation.GenerateTx.Output
Cooked.MockChain.Automation.GenerateTx.Proposal
Cooked.MockChain.Automation.GenerateTx.ReferenceInputs
Cooked.MockChain.Automation.GenerateTx.Withdrawals
Cooked.MockChain.Automation.GenerateTx.Witness
Cooked.MockChain.Common
Cooked.MockChain.Effect.Log
Cooked.MockChain.Effect.Misc
Cooked.MockChain.Effect.Read
Cooked.MockChain.Effect.Write
Cooked.MockChain.Run.Instances
Cooked.MockChain.Run.Runnable
Cooked.MockChain.Run.Tweak
Cooked.MockChain.Runtime.Error
Cooked.MockChain.Runtime.Journal
Cooked.MockChain.Runtime.State
Cooked.MockChain.Config
Cooked.MockChain.Instances
Cooked.MockChain.Ltl
Cooked.MockChain.Run
Cooked.MockChain.Testing
Cooked.MockChain.UtxoSearch
Cooked.MockChain.Tweak
Cooked.Pretty
Cooked.Pretty.Class
Cooked.Pretty.Hashable
Cooked.Pretty.MockChain
Cooked.Pretty.Options
Cooked.Pretty.Plutus
Cooked.Pretty.Skeleton
Cooked.ShowBS
Cooked.Runtime
Cooked.Runtime.Error
Cooked.Runtime.Journal
Cooked.Runtime.State
Cooked.Skeleton
Cooked.Skeleton.Anchor
Cooked.Skeleton.Certificate
Expand All @@ -85,7 +93,11 @@ library
Cooked.Tweak.Query
Cooked.Tweak.Remove
Cooked.Tweak.Update
Cooked.Wallet
Cooked.Utilities
Cooked.Utilities.Aliases
Cooked.Utilities.Families
Cooked.Utilities.ShowBS
Cooked.Utilities.Wallet
other-modules:
Paths_cooked_validators
autogen-modules:
Expand Down Expand Up @@ -127,15 +139,18 @@ library
, bytestring
, cardano-api
, cardano-crypto
, cardano-ledger-alonzo
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-node-emulator
, cardano-slotting
, cardano-strict-containers
, containers
, data-default
, either
, exceptions
, extra
, http-conduit
, lens
, microlens
Expand All @@ -154,6 +169,8 @@ library
, tasty-hunit
, tasty-quickcheck
, text
, time
, witherable
default-language: Haskell2010

test-suite spec
Expand Down
8 changes: 4 additions & 4 deletions doc/BALANCING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ Our balancing function is signed as follows:

``` haskell
balanceTxSkel ::
(Members '[MockChainRead, MockChainLog, Error MockChainError, Error P.Ledger.ToCardanoError, Fail] effs) =>
(Members '[Query, Log, Error ChainError, Error P.Ledger.ToCardanoError, Fail] effs) =>
TxSkel ->
Sem effs ExtendedTxSkel
```

The library is built on [Polysemy] effects rather than a concrete monad, so the
balancing capabilities are expressed as the effect constraints
`Members '[MockChainRead, MockChainLog, Error MockChainError, Error
`Members '[Query, Log, Error ChainError, Error
P.Ledger.ToCardanoError, Fail] effs` and the result lives in `Sem effs`.

This function takes a skeleton and returns an `ExtendedTxSkel`, a record bundling
Expand Down Expand Up @@ -379,7 +379,7 @@ signature:

``` haskell
reachValue ::
(Members '[MockChainRead, Error P.Ledger.ToCardanoError] effs) =>
(Members '[Query, Error P.Ledger.ToCardanoError] effs) =>
Utxos -> -- candidate utxos, type Utxos = [(Api.TxOutRef, TxSkelOut)]
Api.Value -> -- the target value to reach
Integer -> -- the maximum number of utxos allowed in a subset
Expand Down Expand Up @@ -476,7 +476,7 @@ within this interval. The function that performs this computation is

``` haskell
computeFeeAndBalance ::
(Members '[MockChainRead, Error MockChainError, Error P.Ledger.ToCardanoError, Fail] effs) =>
(Members '[Query, Error ChainError, Error P.Ledger.ToCardanoError, Fail] effs) =>
Peer -> -- the balancing user
Fee -> -- lower bound of the search interval
Fee -> -- upper bound of the search interval
Expand Down
Loading