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 摘要。