feat(bench): maquinaria FRAME v2 de benchmarking para los 5 pallets custom (RV 8→9)

Los 19 extrinsics de provenance/fees/agent-identity/emission/governance pasan de
weights placeholder `from_parts(10_000, 0)` (proof_size=0, sin contar reads/writes
de DB — vector de DoS real) a weights INTERIM hand-derived DB-aware vía el trait
`WeightInfo`. Cierra el mispricing de DoS en TODOS los extrinsics del chain.

Cada pallet gana:
- weights.rs: trait WeightInfo + SubstrateWeight<T> (DB-aware vía T::DbWeight) + impl ()
- benchmarking.rs: benchmarks FRAME v2, VERIFICADOS por impl_benchmark_test_suite!
  (19 benchmarks ejecutan+pasan en los mocks — cargo test --features runtime-benchmarks)
- Config: `type WeightInfo` + swap de los `#[pallet::weight]`

Runtime:
- define_benchmarks! con los 5 pallets + runtime API Benchmark (inerte sin la feature)
- WeightInfo cableado a SubstrateWeight<Runtime> en cada Config
- RUNTIME_VERSION 8→9 (weights = consenso-relevante: fee + llenado de bloque;
  las firmas de los extrinsics NO cambian ⇒ TRANSACTION_VERSION intacto)

3 bugs latentes cerrados (territorio virgen — el runtime NUNCA se compiló con
runtime-benchmarks; las dimensiones nuevas cazan lo que no se había visto):
- pallet-grandpa/try-runtime mal ubicado en la feature runtime-benchmarks (copy-paste
  erróneo: features ortogonales; NUNCA activaba los benchmarks de grandpa)
- feature runtime-benchmarks incompleta → E0046 en OriginFeeAdapter (métodos
  benchmark-gated de OnChargeTransaction) + pallet-staking
  (StakingUnchecked::migrate_to_direct_staker); ahora lista TODOS los pallets como
  un runtime de producción Substrate
- pallet-revive/runtime-benchmarks omitido a propósito (fixtures RISC-V/PolkaVM
  indisponibles; ReviveApi deferred, no benchmarkeado)

emission: mock extraído del `mod tests` inline a `pub mod mock` (reuso del test-suite,
sin duplicar el scaffold; los 15 tests existentes + el benchmark verdes).

GATED (documentado en el §Estado de cada weights.rs): la generación de números
CANÓNICOS por CLI requiere el node sc-service o omni-bencher+WASM (ambos bloqueados
hace sesiones). Los weights interinos son DB-aware/DoS-safe y regenerables de forma
mecánica cuando aterrice el HW de referencia (Pi5/VPS) — benchmarking.rs es la fuente
de verdad de la FORMA.

Verificado: 5 test-suites de pallet verdes (con y sin runtime-benchmarks) + runtime
compila en ambos modos + workspace sin regresión + 40 tests de runtime (incl. v9).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
davidherranandClaude Opus 4.8 committed 2026-07-07 22:48:26 -05:00
1 parent 0d56e0bcbf
commit c7fc6a88fc
29 files changed
+1206 -121

No files matched your search

+19 -3
View File
@@ -63,6 +63,10 @@
pub use pallet::*;
/// Weights canonical (INTERIM hand-derived DB-aware — ver `weights.rs` §Estado).
pub mod weights;
pub use weights::WeightInfo;
/// Re-export canonical types desde origin-chain-types para consumers.
pub use origin_chain_types::{
AssetAttestation, AssetHash, OitIdentity, SeverityTier, ValidationAttestation,
@@ -107,6 +111,8 @@ pub mod pallet {
use origin_chain_types::{
attestation_signed_message, decode_signing_payload, AssetAttestation, AssetHash,
};
// Trait de weights en scope para resolver `T::WeightInfo::<method>()`.
use crate::weights::WeightInfo;
/// Cota DoS del `signing_payload` postcard recibido (el real ~115 bytes;
/// 512 es holgado para schema/identifier futuros sin permitir flooding).
@@ -121,6 +127,11 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Weight information canonical para los extrinsics de este pallet.
/// El runtime lo cablea a `weights::SubstrateWeight<Runtime>`; los mocks
/// usan `()`. Ver `weights.rs` + `benchmarking.rs`.
type WeightInfo: crate::weights::WeightInfo;
// Future canonical (post OCAFB ratify):
// type OitFeeSchedule: arkhe_amis_server::OitFeeSchedule;
}
@@ -281,7 +292,7 @@ pub mod pallet {
/// con el `genesis_hash` de ESTA cadena (cierra replay cross-chain).
/// 7. Insert `AssetAttestation` (creator = validador, block real) + evento.
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_parts(20_000, 0))]
#[pallet::weight(T::WeightInfo::attest_asset())]
pub fn attest_asset(
origin: OriginFor<T>,
signing_payload: BoundedVec<u8, MaxPayloadLen>,
@@ -353,7 +364,7 @@ pub mod pallet {
/// validadores que governance habilita pueden anclar. Sunset a
/// attestation-driven cuando el registro OIT de Mathi aterrice.
#[pallet::call_index(1)]
#[pallet::weight(Weight::from_parts(10_000, 0))]
#[pallet::weight(T::WeightInfo::register_validator())]
pub fn register_validator(
origin: OriginFor<T>,
public_key: [u8; 32],
@@ -367,7 +378,7 @@ pub mod pallet {
/// FIX-4: revoca un validador — ya no puede anclar. **Root-only.**
#[pallet::call_index(2)]
#[pallet::weight(Weight::from_parts(10_000, 0))]
#[pallet::weight(T::WeightInfo::revoke_validator())]
pub fn revoke_validator(
origin: OriginFor<T>,
public_key: [u8; 32],
@@ -382,6 +393,11 @@ pub mod pallet {
extern crate alloc;
/// Benchmarks canonical (FRAME v2) — solo bajo la feature `runtime-benchmarks`.
/// Verificados por `impl_benchmark_test_suite!` en el mock (ver `benchmarking.rs`).
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
// v0.0.18 — Mock runtime canonical + integration tests E2E PROV-3 flow.
// Per audit canonical sesión 3+ (`AUDIT_CHARON_SESION_3_STATE_V1.md`),
// own fixtures basados en vendor copy ValidationAttestation real existente