storage: a short delta frame or an undecodable block header still panics a state rebuild

オープン
#816 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend, databases

調査の方向性

Start with beacon_state_delta.rs at unframe and state_writer.rs at reconstruct_beacon_state_bytes and fold_beacon_state_deltas; then trace block slot decoding through store.rs at try_block_slot_in and peek_beacon_block_slot. Check the additional BlockHeader::from_ssz_bytes(..).expect("valid header") reads in store.rs to decide the fix's scope. Done means truncated StateDiffs and BlockHeaders rows read through get_state return errors instead of panicking, with tests covering both cases.

索引モデルが issue の本文から書いたものです。

説明

lambdaclass/ethlambda#788 changed get_state's rebuild to return Error::CorruptState, rather than panic, when a stored state, delta or diff does not decode. A few decodes of disk-sourced bytes on the same path still panic. Line numbers are at #788's head (4fe2f243):

  • Delta frame header. beacon_state_delta::unframe (crates/storage/src/beacon_state_delta.rs:111) slices bytes[0..32], [32..40] and [40..48] without checking the length. A StateDiffs row shorter than its 48-byte header therefore panics instead of reading back as CorruptState. On the rebuild path it is called by reconstruct_beacon_state_bytes (crates/storage/src/state_writer.rs:548) and fold_beacon_state_deltas (state_writer.rs:601). The writer's nearest_snapshot_root (state_writer.rs:580) calls it too.
  • Block slot lookup. Every hop of a rebuild reads its slot through try_block_slot_in (crates/storage/src/store.rs:1121). Its beacon arm, peek_beacon_block_slot (store.rs:1073), indexes the row by its SSZ offset with no bounds check. Its lean arm .expect("valid header")s (store.rs:1132). reconstruct_state's final header read (state_writer.rs:679) does the same.

This was out of #788's scope because these panics already exist on main and that PR's docs name them. The header decode is also not specific to the rebuild:

  • block_slot, beacon_block_slot and nearest_snapshot_root share it.
  • Four more BlockHeader::from_ssz_bytes(..).expect("valid header") reads sit elsewhere in store.rs (2702, 3026, 3074, 3138).

Making only the rebuild tolerate a corrupt header row would leave the next header read panicking. #306 is related but covers backend Results swallowed by .expect(), not bytes that read back fine and then fail to decode.

A fix:

  • Add a try_unframe (split_at_checked(48)) whose error the rebuild maps to CorruptState, and keep unframe as the panicking wrapper for frames the writer just built.
  • Add a fallible beacon slot peek and lean header decode, so that try_block_slot_in returns the crate's Error with a decode failure as CorruptState (or a new CorruptBlockHeader { root }).
  • Decide whether the other header reads follow.
  • Tests: a truncated StateDiffs row and a truncated BlockHeaders row each read back from get_state as an error, not a panic.
主要言語
Rust
スター
86
フォーク
34
平均マージ
9日 20時間
マージ済み PR(30日)
77

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lambdaclass/ethlambda のほかの issue

lambdaclass/ethlambda の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。