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:
1 parent
0d56e0bcbf
commit
c7fc6a88fc
29 files changed
+1206
-121
No files matched your search
@@ -258,7 +258,15 @@ pub const IMPL_NAME: &str = "origin-chain-charon";
|
||||
/// 5/7 de emergencia real: nueva dispatchable `endorse_emergency_proposal`
|
||||
/// (call_index 12) + gate real (antes tautológico). Nuevas storage/errors/evento
|
||||
/// + 1 call aditiva ⇒ spec bump; TRANSACTION_VERSION intacto (call_index nuevo).
|
||||
pub const RUNTIME_VERSION: u32 = 8;
|
||||
///
|
||||
/// **v9 (benchmarking real machinery)**: los 19 extrinsics de los 5 pallets custom
|
||||
/// pasan de weights placeholder `from_parts(10_000, 0)` (proof_size=0, sin contar
|
||||
/// DB — DoS) a weights INTERIM hand-derived DB-aware vía `WeightInfo`. Los weights
|
||||
/// son consenso-relevantes (afectan fee y llenado de bloque) ⇒ spec bump obligatorio.
|
||||
/// Las FIRMAS de los extrinsics NO cambian ⇒ TRANSACTION_VERSION intacto. La feature
|
||||
/// `runtime-benchmarks` gana `define_benchmarks!` + runtime API `Benchmark` (inerte
|
||||
/// sin la feature) + fix del bug `pallet-grandpa/try-runtime` en la feature.
|
||||
pub const RUNTIME_VERSION: u32 = 9;
|
||||
|
||||
/// Canonical authoring version per Substrate semver canonical.
|
||||
pub const AUTHORING_VERSION: u32 = 1;
|
||||
@@ -763,6 +771,52 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// frame_benchmarking::Benchmark — runtime API para `benchmark pallet`
|
||||
// ============================================================
|
||||
//
|
||||
// Solo bajo la feature `runtime-benchmarks`. Expone la maquinaria FRAME v2 de
|
||||
// los pallets custom (ver `benches` mod + `define_benchmarks!`). La GENERACIÓN
|
||||
// de números canónicos por CLI está gated por el node sc-service o
|
||||
// omni-bencher+WASM (ambos bloqueados hace sesiones, ver `main.rs` §BLOQUEO y
|
||||
// el §Estado de cada `weights.rs`); mientras tanto los `SubstrateWeight` llevan
|
||||
// números conservadores DB-aware. Este impl compila y queda listo para que el
|
||||
// loop de medición sea mecánico cuando la infra aterrice.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl frame_benchmarking::Benchmark<Block> for Runtime {
|
||||
fn benchmark_metadata(
|
||||
extra: bool,
|
||||
) -> (
|
||||
alloc::vec::Vec<frame_benchmarking::BenchmarkList>,
|
||||
alloc::vec::Vec<frame_support::traits::StorageInfo>,
|
||||
) {
|
||||
use frame_support::traits::StorageInfoTrait;
|
||||
|
||||
let mut list = alloc::vec::Vec::<frame_benchmarking::BenchmarkList>::new();
|
||||
list_benchmarks!(list, extra);
|
||||
|
||||
let storage_info = AllPalletsWithSystem::storage_info();
|
||||
(list, storage_info)
|
||||
}
|
||||
|
||||
fn dispatch_benchmark(
|
||||
config: frame_benchmarking::BenchmarkConfig,
|
||||
) -> Result<alloc::vec::Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String>
|
||||
{
|
||||
use frame_support::traits::TrackedStorageKey;
|
||||
|
||||
// Whitelist vacía: cada benchmark siembra su propio estado (validador
|
||||
// golden, etc.) y no depende de claves pre-existentes.
|
||||
let whitelist: alloc::vec::Vec<TrackedStorageKey> = alloc::vec::Vec::new();
|
||||
|
||||
let mut batches = alloc::vec::Vec::<frame_benchmarking::BenchmarkBatch>::new();
|
||||
let params = (&config, &whitelist);
|
||||
add_benchmarks!(params, batches);
|
||||
|
||||
Ok(batches)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Phase 3 Slice 3.1 SCAFFOLD — ReviveApi exposure DEFERRED
|
||||
// ============================================================
|
||||
@@ -818,6 +872,26 @@ impl_runtime_apis! {
|
||||
*/
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Registro de benchmarks canonical (frame_benchmarking::define_benchmarks!)
|
||||
// ============================================================
|
||||
//
|
||||
// Lista los pallets custom cuya maquinaria FRAME v2 se expone vía el runtime API
|
||||
// `Benchmark`. Genera los macros `list_benchmarks!` + `add_benchmarks!` (ambos
|
||||
// `#[macro_export]` → crate-global). Cada `[crate_path, PalletAlias]` mapea al
|
||||
// alias del `#[runtime]` de arriba. Los pallets upstream (balances/timestamp/…)
|
||||
// se benchmarkean con sus propios weights ya generados; aquí solo van los míos.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benches {
|
||||
frame_benchmarking::define_benchmarks!(
|
||||
[origin_chain_provenance, Provenance]
|
||||
[origin_chain_fees, Fees]
|
||||
[origin_chain_agent_identity, AgentIdentity]
|
||||
[origin_chain_emission, Emission]
|
||||
[origin_chain_governance, Governance]
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Runtime metadata canonical (RuntimeVersion + Executive)
|
||||
// ============================================================
|
||||
@@ -851,13 +925,13 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn runtime_version_v8_governance_hardening() {
|
||||
// v8 = hardening de governance (audit ultra 2026-07-04 + decisiones A/B):
|
||||
// correctitud (override/treasury/veto) + bond de propuesta (A) + flujo 5/7
|
||||
// de emergencia real con endorse_emergency_proposal (B, call_index 12).
|
||||
// Call aditiva + storage/metadata nuevos ⇒ spec bump; los extrinsics
|
||||
// EXISTENTES no cambian formato ⇒ TRANSACTION_VERSION intacto.
|
||||
assert_eq!(RUNTIME_VERSION, 8);
|
||||
fn runtime_version_v9_benchmarking_weights() {
|
||||
// v9 = benchmarking real machinery: los 19 extrinsics de los 5 pallets
|
||||
// custom pasan de weights placeholder (proof_size=0, DoS) a weights INTERIM
|
||||
// hand-derived DB-aware vía WeightInfo. Los weights son consenso-relevantes
|
||||
// (fee + llenado de bloque) ⇒ spec bump. Las FIRMAS de los extrinsics NO
|
||||
// cambian ⇒ TRANSACTION_VERSION intacto.
|
||||
assert_eq!(RUNTIME_VERSION, 9);
|
||||
assert_eq!(TRANSACTION_VERSION, 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user