Skip to content

feat: expose more ledger error types#1449

Merged
gilescope merged 12 commits into
mainfrom
ozgb-ledger-error-types
May 1, 2026
Merged

feat: expose more ledger error types#1449
gilescope merged 12 commits into
mainfrom
ozgb-ledger-error-types

Conversation

@ozgb

@ozgb ozgb commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Overview

Exposes more detailed Ledger error enums that were previously discarded. Addresses comment: #1374 (comment)

Changes are backwards-compatible - existing error types evaluate to the same error code, unless a more precise variant can now be used.

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • All commits are signed off (git commit -s) for the DCO
  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🧪 Testing Evidence

Please describe any additional testing aside from CI:

  • Additional tests are provided (if possible)

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other:
  • N/A

Links

ozgb added 4 commits April 29, 2026 16:22
Variants like MalformedTransaction::EffectsCheckFailure(EffectsCheckError)
were previously collapsed to a single flat code, hiding the inner cause
from end-users. Flatten the inner enums (EffectsCheckError,
SequencingCheckError, DisjointCheckError, FeeCalculationError,
MalformedContractDeploy, TransactionApplicationError, zswap MalformedOffer
and TransactionInvalid) into granular variants in InvalidError,
MalformedError, and SystemTransactionError, with stable u8 codes in the
free 212-250 range.

Add version-specific error_ext modules (versions/error_ext/ledger_7.rs,
ledger_8.rs) wired through lib.rs in the same style as block_context. Each
version maps only the variants it knows about; unknown variants fall
through to UnknownError + log rather than being silently misclassified.
This replaces the prior '_ => Ste::MerkleTreeError' pattern, which would
have masked any future ledger 9+ additions as MerkleTreeError.

Adds InvalidError variants for ledger 8's MerkleTreeError (top-level and
zswap-nested) and DivideByZero (present in both versions).

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Covers both the node-side host conversion changes and the runtime-side
pallet error variants exposed to end-users. Runtime metadata rebuild is
required as a result of the new variants.

Fixes: #1374
Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Granular error codes don't resolve the underlying issue, just make it
easier to debug.

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
@ozgb ozgb requested a review from a team as a code owner April 30, 2026 11:01
ozgb added 2 commits April 30, 2026 12:17
Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
@ozgb

ozgb commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

/bot rebuild-metadata

@github-actions

Copy link
Copy Markdown
Contributor

✅ Metadata rebuild complete! Changes have been committed.

Replace flattened variant names like `EffectsCheckRealCallsSubsetCheckFailure`
with nested wrappers like `MalformedError::EffectsCheck(EffectsCheckErrorCode::RealCallsSubsetCheckFailure)`.
Variant names now mirror upstream `mn_ledger` types directly. Each sub-enum
gets its own 256-variant budget, and the compile-time `MAX_MODULE_ERROR_ENCODED_SIZE`
check enforces correctness.

Flatten `LedgerApiError` into `cnight-observation::Error<T>` and
`midnight-system::Error<T>` (mirroring the `midnight` pallet pattern).
The previous `Error::LedgerApiError(LedgerApiError)` wrapper added an extra
byte that, combined with the new nesting, exceeded the 4-byte module error
budget.

u8 codes via `From<LedgerApiError>` are preserved for all reachable variants.
Two fallback paths now produce more specific bytes: unmapped upstream
ZswapTransactionInvalid -> 103 (was 109) and unmapped MalformedOffer -> 127
(was 139), reusing what were previously vestigial flat catch-all bytes.

SCALE pallet error encoding for granular variants changes shape: e.g.
`Error::Transaction(Malformed(EffectsCheck(RealCallsSubsetCheckFailure)))`
is 4 bytes vs the previous 3-byte flat encoding.

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
@ozgb

ozgb commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

/bot rebuild-metadata

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>

# Conflicts:
#	metadata/static/midnight_metadata.scale
#	metadata/static/midnight_metadata_1.0.0.scale
@ozgb

ozgb commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

/bot rebuild-metadata

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

❌ Metadata rebuild failed. Check the workflow logs for details.

ozgb added 2 commits May 1, 2026 12:51
Codes 168, 182, 186, 187, 188, 193, 205 were assigned to flat catch-all
variants (`MalformedError::FeeCalculation` etc.) on `main` and were
observable to mempool clients via `InvalidTransaction::Custom`. They are
no longer produced by the nested encoding, but reusing them for new
variants would silently collide on the wire.

Document the reservation in `RETIRED_U8_ERROR_CODES` and assert at test
time that no `LedgerApiError` value encodes to one of them.

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Post-merge: `LedgerApiError::BeneficiaryNotFound` was added on `main`
(#1359). The flattened `From<LedgerApiError> for Error<T>` impls in
`cnight-observation` and `midnight-system` need a matching arm now that
they enumerate variants explicitly rather than wrapping the whole type.

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
@ozgb

ozgb commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

/bot rebuild-metadata

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

✅ Metadata rebuild complete! Changes have been committed.

@ozgb ozgb closed this May 1, 2026
@ozgb ozgb reopened this May 1, 2026

@gilescope gilescope left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@gilescope gilescope enabled auto-merge May 1, 2026 14:08
@gilescope gilescope added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit cf032e6 May 1, 2026
33 checks passed
@gilescope gilescope deleted the ozgb-ledger-error-types branch May 1, 2026 15:02
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.

2 participants