From 0cb8fdf370bf966a1c10a439fadd9d451231b965 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 19 Oct 2023 14:59:29 +1100 Subject: [PATCH] Various small tree-states fixes (#4861) * Fix block backfill with genesis skip slots * Fix freezer upper limit * Fix: write post state in lcli skip-slots (#4843) * Added CARGO_USE_GIT_CLI to the Dockerfile (#4828) * chore: replace deprecated hub with gh for releases (#4839) * Put schema version back to 24 (ignore Deneb) * Minimise diff --------- Co-authored-by: Joe Clapis Co-authored-by: Dustin Brickwood --- .github/workflows/release.yml | 7 ++----- Dockerfile | 2 ++ .../beacon_chain/src/historical_blocks.rs | 18 +++++++++--------- beacon_node/beacon_chain/tests/store_tests.rs | 12 ++++++++++++ beacon_node/store/src/forwards_iter.rs | 9 ++++++++- beacon_node/store/src/metadata.rs | 2 +- book/src/api-lighthouse.md | 1 - database_manager/src/lib.rs | 2 -- lcli/src/skip_slots.rs | 6 ++++-- 9 files changed, 38 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 24ca09ec00e..26ef781b689 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -282,9 +282,6 @@ jobs: | | Docker | [${{ env.VERSION }}](https://hub.docker.com/r/${{ env.IMAGE_NAME }}/tags?page=1&ordering=last_updated&name=${{ env.VERSION }}) | [${{ env.IMAGE_NAME }}](https://hub.docker.com/r/${{ env.IMAGE_NAME }}) | ENDBODY ) - assets=() - for asset in ./lighthouse-*.tar.gz*; do - assets+=("-a" "$asset/$asset") - done + assets=(./lighthouse-*.tar.gz*) tag_name="${{ env.VERSION }}" - echo "$body" | hub release create --draft "${assets[@]}" -F "-" "$tag_name" + echo "$body" | gh release create --draft -F "-" "$tag_name" "${assets[@]}" diff --git a/Dockerfile b/Dockerfile index bcddef8a6f3..f52bb56f14f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,10 @@ RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-de COPY . lighthouse ARG FEATURES ARG PROFILE=release +ARG CARGO_USE_GIT_CLI=false ENV FEATURES $FEATURES ENV PROFILE $PROFILE +ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI RUN cd lighthouse && make FROM ubuntu:22.04 diff --git a/beacon_node/beacon_chain/src/historical_blocks.rs b/beacon_node/beacon_chain/src/historical_blocks.rs index 0989a2e8484..9a2f066164f 100644 --- a/beacon_node/beacon_chain/src/historical_blocks.rs +++ b/beacon_node/beacon_chain/src/historical_blocks.rs @@ -140,17 +140,17 @@ impl BeaconChain { prev_block_slot = block.slot(); expected_block_root = block.message().parent_root(); - // If we've reached genesis, add the genesis block root to the batch and set the - // anchor slot to 0 to indicate completion. + // If we've reached genesis, add the genesis block root to the batch for all slots + // between 0 and the first block slot, and set the anchor slot to 0 to indicate + // completion. if expected_block_root == self.genesis_block_root { let genesis_slot = self.spec.genesis_slot; - cold_batch.push(KeyValueStoreOp::PutKeyValue( - get_key_for_col( - DBColumn::BeaconBlockRoots.into(), - &genesis_slot.as_u64().to_be_bytes(), - ), - self.genesis_block_root.as_bytes().to_vec(), - )); + for slot in genesis_slot.as_u64()..block.slot().as_u64() { + cold_batch.push(KeyValueStoreOp::PutKeyValue( + get_key_for_col(DBColumn::BeaconBlockRoots.into(), &slot.to_be_bytes()), + self.genesis_block_root.as_bytes().to_vec(), + )); + } prev_block_slot = genesis_slot; expected_block_root = Hash256::zero(); break; diff --git a/beacon_node/beacon_chain/tests/store_tests.rs b/beacon_node/beacon_chain/tests/store_tests.rs index 80ebbe9761f..d35a310fb52 100644 --- a/beacon_node/beacon_chain/tests/store_tests.rs +++ b/beacon_node/beacon_chain/tests/store_tests.rs @@ -2103,6 +2103,18 @@ async fn weak_subjectivity_sync_unaligned_unadvanced_checkpoint() { weak_subjectivity_sync_test(slots, checkpoint_slot).await } +// Regression test for https://github.com/sigp/lighthouse/issues/4817 +// Skip 3 slots immediately after genesis, creating a gap between the genesis block and the first +// real block. +#[tokio::test] +async fn weak_subjectivity_sync_skips_at_genesis() { + let start_slot = 4; + let end_slot = E::slots_per_epoch() * 4; + let slots = (start_slot..end_slot).map(Slot::new).collect(); + let checkpoint_slot = Slot::new(E::slots_per_epoch() * 2); + weak_subjectivity_sync_test(slots, checkpoint_slot).await +} + async fn weak_subjectivity_sync_test(slots: Vec, checkpoint_slot: Slot) { // Build an initial chain on one harness, representing a synced node with full history. let num_final_blocks = E::slots_per_epoch() * 2; diff --git a/beacon_node/store/src/forwards_iter.rs b/beacon_node/store/src/forwards_iter.rs index 87996bdf1df..7b827ad9569 100644 --- a/beacon_node/store/src/forwards_iter.rs +++ b/beacon_node/store/src/forwards_iter.rs @@ -72,8 +72,15 @@ impl, Cold: ItemStore> HotColdDB let anchor_info = self.get_anchor_info(); // There are no historic states stored if the state upper limit lies in the hot // database. It hasn't been reached yet, and may never be. - if anchor_info.map_or(false, |a| a.state_upper_limit >= split_slot) { + if anchor_info.as_ref().map_or(false, |a| { + a.state_upper_limit >= split_slot && a.state_lower_limit == 0 + }) { None + } else if let Some(lower_limit) = anchor_info + .map(|a| a.state_lower_limit) + .filter(|limit| *limit > 0) + { + Some(lower_limit) } else { // Otherwise if the state upper limit lies in the freezer or all states are // reconstructed then state roots are available up to the split slot. diff --git a/beacon_node/store/src/metadata.rs b/beacon_node/store/src/metadata.rs index 5937c04a012..9c02dd111ce 100644 --- a/beacon_node/store/src/metadata.rs +++ b/beacon_node/store/src/metadata.rs @@ -4,7 +4,7 @@ use ssz::{Decode, Encode}; use ssz_derive::{Decode, Encode}; use types::{Checkpoint, Hash256, Slot}; -pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(25); +pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(24); // All the keys that get stored under the `BeaconMeta` column. // diff --git a/book/src/api-lighthouse.md b/book/src/api-lighthouse.md index 32c967c9e06..5bc13d39748 100644 --- a/book/src/api-lighthouse.md +++ b/book/src/api-lighthouse.md @@ -547,7 +547,6 @@ reconstruction has yet to be completed. For more information on the specific meanings of these fields see the docs on [Checkpoint Sync](./checkpoint-sync.md#reconstructing-states). - ### `/lighthouse/merge_readiness` Returns the current difficulty and terminal total difficulty of the network. Before [The Merge](https://ethereum.org/en/roadmap/merge/) on 15th September 2022, you will see that the current difficulty is less than the terminal total difficulty, An example is shown below: ```bash diff --git a/database_manager/src/lib.rs b/database_manager/src/lib.rs index 00ee73449a7..4beaf2babc0 100644 --- a/database_manager/src/lib.rs +++ b/database_manager/src/lib.rs @@ -365,8 +365,6 @@ pub fn inspect_db( } else { println!("Successfully saved values to file: {:?}", file_path); } - - total += value.len(); } } total += value.len(); diff --git a/lcli/src/skip_slots.rs b/lcli/src/skip_slots.rs index c6880f3c810..051666e70a3 100644 --- a/lcli/src/skip_slots.rs +++ b/lcli/src/skip_slots.rs @@ -110,6 +110,7 @@ pub fn run( } _ => return Err("must supply either --state-path or --beacon-url".into()), }; + let mut post_state = None; let initial_slot = state.slot(); let target_slot = initial_slot + slots; @@ -141,14 +142,15 @@ pub fn run( let duration = Instant::now().duration_since(start); info!("Run {}: {:?}", i, duration); + post_state = Some(state); } - if let Some(output_path) = output_path { + if let (Some(post_state), Some(output_path)) = (post_state, output_path) { let mut output_file = File::create(output_path) .map_err(|e| format!("Unable to create output file: {:?}", e))?; output_file - .write_all(&state.as_ssz_bytes()) + .write_all(&post_state.as_ssz_bytes()) .map_err(|e| format!("Unable to write to output file: {:?}", e))?; }