Phase0 epoch processing is quadratic: get_base_reward rescans the registry for every validator

未關閉
#703 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 6 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
67/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust

研究方向

Start in crates/blockchain/state_transition/src/beacon/stf/epoch/rewards.rs, reading get_base_reward and the phase0 delta loops that call it. Compare how RewardContext in #632 passes precomputed balance for Altair and later; then run the phase0 fixtures and the era replay for mainnet era 290. Done means the epoch path avoids rescanning the registry per validator and those checks complete successfully.

由索引模型根據 Issue 內容生成。

描述

Found by the era replay battery (#680): mainnet phase0 era 290 did not get through a single epoch boundary in 30 minutes, so phase0 eras are excluded from its matrix.

Cause (crates/blockchain/state_transition/src/beacon/stf/epoch/rewards.rs)

  • get_base_reward (line 71) calls get_total_active_balance(state) — a full registry scan — on every call.
  • It is called per validator from the phase0 delta loops (lines 118, 121, 125, 212, 246, and through get_proposer_reward at 82), so a phase0 epoch transition does O(validators) scans of O(validators) each: quadratic in the registry size. With the registry now a persistent tree (state.validator(i) is a descent), each scan is also more expensive than an array walk.

Fix

  • Compute the total active balance (or the base reward per increment) once per epoch transition and pass it in, the way #632's RewardContext already does for altair and later, and #648 proposes for deneb/electra's get_base_reward_per_increment.
  • The spec-literal get_base_reward can stay as the reference the fixtures call, with the epoch path using the precomputed total.

Impact

  • No live chain is in phase0, so this doesn't affect following mainnet today; it blocks replaying phase0 history in #680 and makes phase0 fixtures slower than they need to be.
  • Once fixed, phase0 eras (e.g. mainnet 290) can be added back to the era replay matrix.
主要語言
Rust
星號
86
分支
34
平均合併
9 天 20 小時
30 天內合併 PR
77

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

lambdaclass/ethlambda 的其他 Issue

查看 lambdaclass/ethlambda 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。