task(nto): PM-19778 CNGD extrinsic dispatch class#798
Merged
Conversation
Contributor
Contributor
Author
|
/bot rebuild-metadata |
Contributor
|
✅ Metadata rebuild complete! Changes have been committed. |
…me-benchmarks feature Add frame-benchmarking as an optional dependency and configure the runtime-benchmarks feature flag to enable benchmark compilation for the cnight-observation pallet. Follows the pattern established by pallet-federated-authority-observation. Ticket: PM-19778 Co-authored-by: Cursor <cursoragent@cursor.com>
Define the WeightInfo trait with fn process_tokens(n: u32) -> Weight for the cnight-observation pallet. Includes SubstrateWeight<T> placeholder impl with conservative estimates (to be replaced by benchmark output) and impl WeightInfo for () returning zero weight for tests and mocks. Refs: PM-19778
- Add pallet constants UTXO_PER_TX_OVERESTIMATE (64) and
MAX_UTXO_COUNT (12,800) matching mainchain follower buffer bounds
- Add WeightInfo associated type to Config trait
- Add TooManyUtxos error variant with dynamic UTXO count guard
- Change weight annotation from (0, Mandatory) to
(T::WeightInfo::process_tokens(MAX_UTXO_COUNT), Mandatory)
- Change return type to DispatchResultWithPostInfo with actual-weight
correction via PostDispatchInfo { pays_fee: Pays::No }
- Wire weights and benchmarking modules
Refs: PM-19778
Add `type WeightInfo = ();` to both mock runtime Config impls (mock.rs and mock_with_capture.rs), satisfying the new associated type added to the pallet's Config trait. Refs: PM-19778
…tration Add `type WeightInfo = ();` to the runtime's pallet_cnight_observation Config impl and register the pallet in `define_benchmarks!` so the benchmark CLI discovers its extrinsics. Refs: PM-19778
FRAME v2 benchmark for process_tokens using Registration UTXOs as the benchmark input type. Registration handlers exercise the storage-dominant path (2R + 1W + events per UTXO) without requiring LedgerApi, making them suitable for deterministic benchmarking. - Linear<0, MAX_UTXO_COUNT> parameter (0..12,800 UTXOs) - RawOrigin::None for inherent dispatch - Synthetic UTXOs with unique CardanoRewardAddressBytes - impl_benchmark_test_suite with mock_with_capture runtime Refs: PM-19778
- Mark shell command in weights.rs doc comment as ```text to prevent doctest from parsing it as Rust code - Remove impl_benchmark_test_suite! from benchmarking.rs — the external mock crate cannot propagate runtime-benchmarks feature without a circular dependency; benchmark smoke tests run via the runtime crate instead Refs: PM-19778
…ion tests Add validation_tests.rs covering PM-19778 code review findings M1/M2: - TC-01: TooManyUtxos rejection when UTXO count exceeds capacity bound - TC-02: Exact boundary acceptance at capacity limit - TC-06b: PostDispatchInfo returns actual_weight and Pays::No
Use capacity=2 instead of 1 to avoid `1u32 * UTXO_PER_TX_OVERESTIMATE` which clippy flags as identity_op (no-op multiplication by 1). Made-with: Cursor
6806d29 to
0cf6397
Compare
Contributor
Author
|
/bot rebuild-metadata |
Contributor
|
✅ Metadata rebuild complete! Changes have been committed. |
Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
gilescope
approved these changes
Feb 28, 2026
Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
gilescope
pushed a commit
that referenced
this pull request
Apr 8, 2026
m2ux
added a commit
that referenced
this pull request
Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
m2ux
added a commit
that referenced
this pull request
Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Summary
Add benchmarked weight infrastructure, UTXO count validation, and actual-weight correction to the
process_tokensinherent extrinsic, enabling accurate block weight accounting for the cnight-observation pallet.🎫 Ticket 📐 Engineering
Motivation
The
process_tokensinherent extrinsic previously declared zero weight withDispatchClass::Mandatory, bypassing block weight accounting entirely. Least Authority audit finding Issue H flagged this: without benchmarked weights, the runtime cannot accurately track block capacity consumed by UTXO processing, and there is no upper bound on UTXO batch size.This implementation adds the FRAME benchmarking infrastructure needed to derive accurate weights, a runtime safety guard on input size, and actual-weight correction via
PostDispatchInfoso that block capacity reflects the true processing cost.Changes
weights.rs) — NewWeightInfotrait withfn process_tokens(n: u32) -> Weight, placeholderSubstrateWeight<T>implementation with conservative estimates, and zero-weight()impl for testslib.rs) —process_tokensweight changed from(0, DispatchClass::Mandatory)to(T::WeightInfo::process_tokens(MAX_UTXO_COUNT), DispatchClass::Mandatory)declaring worst-case weight up frontlib.rs) — NewTooManyUtxoserror variant;ensure!guard rejects batches exceedingCardanoTxCapacityPerBlock * UTXO_PER_TX_OVERESTIMATE(default 200 × 64 = 12,800)lib.rs) — Return type changed fromDispatchResulttoDispatchResultWithPostInfo; returnsPostDispatchInfo { actual_weight: Some(T::WeightInfo::process_tokens(utxo_count)), pays_fee: Pays::No }lib.rs) —UTXO_PER_TX_OVERESTIMATE = 64,MAX_UTXO_COUNT = 12,800benchmarking.rs) — FRAME v2 parameterized benchmark using Registration UTXOs withLinear<0, MAX_UTXO_COUNT>type WeightInfo: WeightInfoadded to palletConfigtrait; wired as()in mock runtimes and runtimedefine_benchmarks!macrovalidation_tests.rs) — 3 tests using lightweight mock: UTXO guard rejection (TC-01), exact boundary acceptance (TC-02), PostDispatchInfo actual-weight verification (TC-06b)📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging