-
Notifications
You must be signed in to change notification settings - Fork 886
Manual finalization endpoint #7059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
2cb71e2
bd093d9
b03c18d
9057a88
d43553c
b567cc4
f397b87
9f4e757
c1b2c41
92c8633
fa6232c
404e48d
de60333
508ff71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,14 +124,22 @@ pub enum Notification { | |
Finalization(FinalizationNotification), | ||
Reconstruction, | ||
PruneBlobs(Epoch), | ||
ManualFinalization(ManualFinalizationNotification), | ||
} | ||
|
||
pub struct ManualFinalizationNotification { | ||
pub state_root: BeaconStateHash, | ||
pub checkpoint: Checkpoint, | ||
pub head_tracker: Arc<HeadTracker>, | ||
pub genesis_block_root: Hash256, | ||
} | ||
|
||
pub struct FinalizationNotification { | ||
finalized_state_root: BeaconStateHash, | ||
finalized_checkpoint: Checkpoint, | ||
head_tracker: Arc<HeadTracker>, | ||
prev_migration: Arc<Mutex<PrevMigration>>, | ||
genesis_block_root: Hash256, | ||
pub finalized_state_root: BeaconStateHash, | ||
pub finalized_checkpoint: Checkpoint, | ||
pub head_tracker: Arc<HeadTracker>, | ||
pub prev_migration: Arc<Mutex<PrevMigration>>, | ||
pub genesis_block_root: Hash256, | ||
} | ||
|
||
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Hot, Cold> { | ||
|
@@ -190,6 +198,10 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho | |
Ok(()) | ||
} | ||
|
||
pub fn process_manual_finalization(&self, notif: ManualFinalizationNotification) { | ||
let _ = self.send_background_notification(Notification::ManualFinalization(notif)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we ever run store migrator in the foreground other than testing, but probably should support it given we do it for all 3 other notifications, and if we want to test this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. We should do this for the clean version of this PR |
||
} | ||
|
||
pub fn process_reconstruction(&self) { | ||
if let Some(Notification::Reconstruction) = | ||
self.send_background_notification(Notification::Reconstruction) | ||
|
@@ -289,6 +301,26 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho | |
} | ||
} | ||
|
||
fn run_manual_migration( | ||
db: Arc<HotColdDB<E, Hot, Cold>>, | ||
notif: ManualFinalizationNotification, | ||
log: &Logger, | ||
) { | ||
// We create a "dummy" prev migration | ||
let prev_migration = PrevMigration { | ||
epoch: Epoch::new(1), | ||
epochs_per_migration: 2, | ||
}; | ||
let notif = FinalizationNotification { | ||
finalized_state_root: notif.state_root, | ||
finalized_checkpoint: notif.checkpoint, | ||
head_tracker: notif.head_tracker, | ||
prev_migration: Arc::new(prev_migration.into()), | ||
genesis_block_root: notif.genesis_block_root, | ||
}; | ||
Self::run_migration(db, notif, log); | ||
} | ||
|
||
/// Perform the actual work of `process_finalization`. | ||
fn run_migration( | ||
db: Arc<HotColdDB<E, Hot, Cold>>, | ||
|
@@ -422,16 +454,27 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho | |
while let Ok(notif) = rx.recv() { | ||
let mut reconstruction_notif = None; | ||
let mut finalization_notif = None; | ||
let mut manual_finalization_notif = None; | ||
let mut prune_blobs_notif = None; | ||
match notif { | ||
Notification::Reconstruction => reconstruction_notif = Some(notif), | ||
Notification::Finalization(fin) => finalization_notif = Some(fin), | ||
Notification::ManualFinalization(fin) => manual_finalization_notif = Some(fin), | ||
Notification::PruneBlobs(dab) => prune_blobs_notif = Some(dab), | ||
} | ||
// Read the rest of the messages in the channel, taking the best of each type. | ||
for notif in rx.try_iter() { | ||
match notif { | ||
Notification::Reconstruction => reconstruction_notif = Some(notif), | ||
Notification::ManualFinalization(fin) => { | ||
if let Some(current) = manual_finalization_notif.as_mut() { | ||
if fin.checkpoint.epoch > current.checkpoint.epoch { | ||
*current = fin; | ||
} | ||
} else { | ||
manual_finalization_notif = Some(fin); | ||
} | ||
} | ||
Notification::Finalization(fin) => { | ||
if let Some(current) = finalization_notif.as_mut() { | ||
if fin.finalized_checkpoint.epoch | ||
|
@@ -454,6 +497,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho | |
if let Some(fin) = finalization_notif { | ||
Self::run_migration(db.clone(), fin, &log); | ||
} | ||
if let Some(fin) = manual_finalization_notif { | ||
Self::run_manual_migration(db.clone(), fin, &log); | ||
} | ||
if let Some(dab) = prune_blobs_notif { | ||
Self::run_prune_blobs(db.clone(), dab, &log); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.