From d0beecca20803445b19a68993af210fc4d7fc99f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 2 Aug 2022 07:58:42 +0000 Subject: [PATCH] Make fork choice prune again (#3408) ## Issue Addressed NA ## Proposed Changes There was a regression in #3244 (released in v2.4.0) which stopped pruning fork choice (see [here](https://github.com/sigp/lighthouse/pull/3244#discussion_r935187485)). This would form a very slow memory leak, using ~100mb per month. The release has been out for ~11 days, so users should not be seeing a dangerous increase in memory, *yet*. Credits to @michaelsproul for noticing this :tada: ## Additional Info NA --- beacon_node/beacon_chain/src/canonical_head.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/beacon_node/beacon_chain/src/canonical_head.rs b/beacon_node/beacon_chain/src/canonical_head.rs index 709382f05b..6559487980 100644 --- a/beacon_node/beacon_chain/src/canonical_head.rs +++ b/beacon_node/beacon_chain/src/canonical_head.rs @@ -719,6 +719,9 @@ impl BeaconChain { drop(old_cached_head); // If the finalized checkpoint changed, perform some updates. + // + // The `after_finalization` function will take a write-lock on `fork_choice`, therefore it + // is a dead-lock risk to hold any other lock on fork choice at this point. if new_view.finalized_checkpoint != old_view.finalized_checkpoint { if let Err(e) = self.after_finalization(&new_cached_head, new_view, finalized_proto_block) @@ -878,6 +881,9 @@ impl BeaconChain { /// Perform updates to caches and other components after the finalized checkpoint has been /// changed. + /// + /// This function will take a write-lock on `canonical_head.fork_choice`, therefore it would be + /// unwise to hold any lock on fork choice while calling this function. fn after_finalization( self: &Arc, new_cached_head: &CachedHead, @@ -966,6 +972,9 @@ impl BeaconChain { self.head_tracker.clone(), )?; + // Take a write-lock on the canonical head and signal for it to prune. + self.canonical_head.fork_choice_write_lock().prune()?; + Ok(()) }