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

Aberta
#703 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 6 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
67/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
rust
Domínio
backend, performance

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
Linguagem predominante
Rust
Estrelas
86
Forks
34
Merge médio
9d 20h
PRs com merge (30d)
77

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de lambdaclass/ethlambda

Todas as issues de lambdaclass/ethlambda

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.