From 059ea913df73e5a6a12b9a464622f07da045f714 Mon Sep 17 00:00:00 2001 From: Mark Mackey Date: Tue, 22 Mar 2022 11:25:25 -0500 Subject: [PATCH] Add Proposer Cache Pruning & POS Activated Banner --- .../beacon_chain/src/block_verification.rs | 44 +++++++++++++++++-- beacon_node/client/src/builder.rs | 7 ++- beacon_node/execution_layer/src/lib.rs | 17 ++++--- beacon_node/http_api/src/lib.rs | 1 - 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 866e1e33831..0071e79013a 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -59,7 +59,7 @@ use fork_choice::{ForkChoice, ForkChoiceStore, PayloadVerificationStatus}; use parking_lot::RwLockReadGuard; use proto_array::Block as ProtoBlock; use safe_arith::ArithError; -use slog::{debug, error, Logger}; +use slog::{debug, error, info, Logger}; use slot_clock::SlotClock; use ssz::Encode; use state_processing::per_block_processing::is_merge_transition_block; @@ -81,6 +81,30 @@ use types::{ SignedBeaconBlock, SignedBeaconBlockHeader, Slot, }; +const POS_PANDA_BANNER: &str = r#" + ,,, ,,, ,,, ,,, + ;" ^; ;' ", ;" ^; ;' ", + ; s$$$$$$$s ; ; s$$$$$$$s ; + , ss$$$$$$$$$$s ,' ooooooooo. .oooooo. .oooooo..o , ss$$$$$$$$$$s ,' + ;s$$$$$$$$$$$$$$$ `888 `Y88. d8P' `Y8b d8P' `Y8 ;s$$$$$$$$$$$$$$$ + $$$$$$$$$$$$$$$$$$ 888 .d88'888 888Y88bo. $$$$$$$$$$$$$$$$$$ + $$$$P""Y$$$Y""W$$$$$ 888ooo88P' 888 888 `"Y8888o. $$$$P""Y$$$Y""W$$$$$ + $$$$ p"$$$"q $$$$$ 888 888 888 `"Y88b $$$$ p"$$$"q $$$$$ + $$$$ .$$$$$. $$$$ 888 `88b d88'oo .d8P $$$$ .$$$$$. $$$$ + $$DcaU$$$$$$$$$$ o888o `Y8bood8P' 8""88888P' $$DcaU$$$$$$$$$$ + "Y$$$"*"$$$Y" "Y$$$"*"$$$Y" + "$b.$$" "$b.$$" + + .o. . o8o . .o8 + .888. .o8 `"' .o8 "888 + .8"888. .ooooo. .o888oooooo oooo ooo .oooo. .o888oo .ooooo. .oooo888 + .8' `888. d88' `"Y8 888 `888 `88. .8' `P )88b 888 d88' `88bd88' `888 + .88ooo8888. 888 888 888 `88..8' .oP"888 888 888ooo888888 888 + .8' `888. 888 .o8 888 . 888 `888' d8( 888 888 .888 .o888 888 + o88o o8888o`Y8bod8P' "888"o888o `8' `Y888""8o "888"`Y8bod8P'`Y8bod88P" + +"#; + /// Maximum block slot number. Block with slots bigger than this constant will NOT be processed. const MAXIMUM_BLOCK_SLOT_NUMBER: u64 = 4_294_967_296; // 2^32 @@ -1118,9 +1142,13 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> { // early. // - Doing the check here means we can keep our fork-choice implementation "pure". I.e., no // calls to remote servers. - if is_merge_transition_block(&state, block.message().body()) { - validate_merge_block(chain, block.message())? - } + let valid_merge_transition_block = + if is_merge_transition_block(&state, block.message().body()) { + validate_merge_block(chain, block.message())?; + true + } else { + false + }; // The specification declares that this should be run *inside* `per_block_processing`, // however we run it here to keep `per_block_processing` pure (i.e., no calls to external @@ -1264,6 +1292,14 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> { }); } + if valid_merge_transition_block { + info!(chain.log, "{}", POS_PANDA_BANNER); + info!(chain.log, "Proof of Stake Activated"; "slot" => block.slot()); + info!(chain.log, ""; "Terminal POW Block Hash" => ?block.message().execution_payload()?.parent_hash.into_root()); + info!(chain.log, ""; "Merge Transition Block Root" => ?block.message().tree_hash_root()); + info!(chain.log, ""; "Merge Transition Execution Hash" => ?block.message().execution_payload()?.block_hash.into_root()); + } + Ok(Self { block, block_root, diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 89fbe2310f0..353b174a02b 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -704,10 +704,9 @@ where execution_layer.spawn_watchdog_routine(beacon_chain.slot_clock.clone()); // Spawn a routine that removes expired proposer preparations. - execution_layer - .spawn_clean_proposer_preparation_routine::( - beacon_chain.slot_clock.clone(), - ); + execution_layer.spawn_clean_proposer_caches_routine::( + beacon_chain.slot_clock.clone(), + ); // Spawns a routine that polls the `exchange_transition_configuration` endpoint. execution_layer.spawn_transition_configuration_poll(beacon_chain.spec.clone()); diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index c46549e4e51..ba4208d88a9 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -374,8 +374,8 @@ impl ExecutionLayer { self.engines().upcheck_not_synced(Logging::Disabled).await; } - /// Spawns a routine which cleans the cached proposer preparations periodically. - pub fn spawn_clean_proposer_preparation_routine( + /// Spawns a routine which cleans the cached proposer data periodically. + pub fn spawn_clean_proposer_caches_routine( &self, slot_clock: S, ) { @@ -393,7 +393,7 @@ impl ExecutionLayer { .map(|slot| slot.epoch(T::slots_per_epoch())) { Some(current_epoch) => el - .clean_proposer_preparation(current_epoch) + .clean_proposer_caches::(current_epoch) .await .map_err(|e| { error!( @@ -473,8 +473,8 @@ impl ExecutionLayer { } } - /// Removes expired entries from cached proposer preparations - async fn clean_proposer_preparation(&self, current_epoch: Epoch) -> Result<(), Error> { + /// Removes expired entries from proposer_preparation_data and proposers caches + async fn clean_proposer_caches(&self, current_epoch: Epoch) -> Result<(), Error> { let mut proposer_preparation_data = self.proposer_preparation_data().await; // Keep all entries that have been updated in the last 2 epochs @@ -482,6 +482,13 @@ impl ExecutionLayer { proposer_preparation_data.retain(|_validator_index, preparation_entry| { preparation_entry.update_epoch >= retain_epoch }); + drop(proposer_preparation_data); + + let retain_slot = retain_epoch.start_slot(T::slots_per_epoch()); + self.proposers() + .write() + .await + .retain(|proposer_key, _proposer| proposer_key.slot >= retain_slot); Ok(()) } diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 44c2c36bd80..c179696647d 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -954,7 +954,6 @@ pub fn serve( delay, ); - match chain.process_block(block.clone()) { Ok(root) => { info!(