Skip to content

Implement server-side transaction validation via LocalStateQuery#1228

Draft
palas wants to merge 6 commits into
masterfrom
tx-validation
Draft

Implement server-side transaction validation via LocalStateQuery#1228
palas wants to merge 6 commits into
masterfrom
tx-validation

Conversation

@palas
Copy link
Copy Markdown
Contributor

@palas palas commented May 27, 2026

Context

Implements the cardano-api portion of server-side transaction validation via the LocalStateQuery protocol.

Part of IntersectMBO/cardano-cli#1380.

Big picture: transaction validate currently applies applyTx client-side with an empty UTxO set, making it unable to properly validate transactions. This cross-repo change adds a new ValidateTx query to the LocalStateQuery protocol so the node validates transactions against its real ledger state and UTxO set.

transaction validate PR list:

What this PR does

  • Adds QueryValidateTx to QueryInShelleyBasedEra, wrapping a Tx era and wiring it to the consensus ValidateTx query via toConsensusQueryShelleyBased
  • Adds queryValidateTx (in Cardano.Api.Experimental.Tx.Internal.Validate) to issue the query through LocalStateQueryExpr
  • Adds a high-level validateTx function (in Cardano.Api.Experimental.Tx) that combines phase-1 validation (via the node query) with phase-2 script execution unit evaluation, filtering script failures from phase-1 results to avoid double-reporting
  • Moves SignedTx from Cardano.Api.Experimental.Tx to its own Internal.Type module
  • Exposes InAnyEra existential wrapper in Cardano.Api.Experimental.Era
  • Re-exports Conway/Alonzo ledger validation error types through Cardano.Api.Ledger.Internal.Reexport (e.g. ApplyTxError, ConwayLedgerPredFailure, Mismatch, IsValid, CollectError, etc.) for downstream error rendering
  • Exports querySbe from Cardano.Api.Query.Internal.Expr
  • Exports queryValidateTx, QueryValidateTxError, TxValidationResult, and validateTx through the public Cardano.Api.Query and Cardano.Api.Experimental modules

How to trust this PR

Integration tests in cardano-testnet (in the cardano-node PR) exercise the full round-trip: valid simple txs, valid Plutus txs, fee-too-low, value-not-conserved, missing witnesses, missing script witnesses, no collateral, max-tx-size exceeded, phase-2 failures, and multi-error scenarios.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

palas added 6 commits May 26, 2026 02:50
…tion

Adds a new local state query that runs applyTx against the current
ledger state and returns the raw result. The provisional implementation
queries the full EpochState and runs applyTx client-side; this will be
replaced by a dedicated node-side consensus query.

Exposed from Cardano.Api.Query alongside other queries.
…idation

Runs both applyTx (phase 1) and evaluateTransactionExecutionUnits (phase 2)
independently in a single LocalStateQueryExpr session, returning both results
via TxValidationResult.
Add re-exports for ApplyTxError(..), ConwayLedgerPredFailure(..),
ConwayUtxowPredFailure(..), ConwayUtxoPredFailure(..), Mismatch(..),
and hashToTextAsHex so downstream consumers (cardano-cli) can
pattern-match on ledger predicate failures for human-readable
error rendering.
Replace the provisional client-side applyTx implementation with a proper
server-side query through the LocalStateQuery protocol. This avoids
transferring the full ledger state to the client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant