-
Notifications
You must be signed in to change notification settings - Fork 908
Custody backfill sync #7907
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
Open
eserilev
wants to merge
54
commits into
sigp:unstable
Choose a base branch
from
eserilev:custody-backfill-sync
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,137
−32
Open
Custody backfill sync #7907
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d91b688
Add historical data column storage functionality
eserilev f3b9f24
some progress on a manager -> sync service architecture
eserilev cbdb44d
Adding custody sync service
eserilev 8c1fafa
resolve merge conflicts
eserilev a5670c8
minor cleanup
eserilev e182af7
enable batch request/response handling
eserilev 3cff919
refactor
eserilev 2fcd512
update
eserilev 6ae8174
resolve merge conflicts
eserilev 8c074ec
Remove some TODOs
eserilev 725dabd
update
eserilev 82c9160
Adding a bunch of logs and fixing some edge cases
eserilev 83bba63
some progress
eserilev 27f4438
Merge unstable
eserilev 1bf46a7
fix logs
eserilev f415360
some cleanup
eserilev faf389c
more progress
eserilev fb83add
some comments
eserilev a05ce72
update
eserilev aae5dd9
linting fixes
eserilev f4f21c6
linting
eserilev 107b131
Linting
eserilev 7293cfe
some fixes
eserilev d4d5dba
Add KZG verification logic
eserilev 2c8f7f9
Handle skipped slots
eserilev 86beef5
Resume pending custody backfill when necessary
eserilev 2f5f7b4
Fix some TODOs
eserilev 0b1b2e6
Resolve some TODOs
eserilev d7323e0
Cleanup
eserilev b88f53c
Fix a bug where custody sync cant be restarted
eserilev acb8b30
remove TODOs
eserilev 103de67
Need to fix speedo
eserilev 890683e
update
eserilev f8ba916
resolve merge conflicts
eserilev 79748a1
fix test
eserilev 46a41d6
fix test
eserilev ecb1980
fmt
eserilev 370a5d4
fix test
eserilev a001eb0
fix test
eserilev 9205a91
merge conflicts
eserilev 0113b00
fmt
eserilev 9c67997
some cleanup
eserilev 9ac4a7d
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cu…
eserilev 9e4fd45
Fix some comments
eserilev 76b5f30
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cu…
eserilev 8579c03
Await finalization before triggering custody backfill sync
eserilev 3fceed3
fix finalization delay
eserilev 6705dd8
fix
eserilev 2644404
fix tests
eserilev 93d5786
Fix test
eserilev eb2b075
FMT
eserilev 316583a
fix test
eserilev 95e3e6d
Resolve conflicts
eserilev 8b757ad
Notifier fixes
eserilev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
beacon_node/beacon_chain/src/historical_data_columns.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
use crate::{ | ||
BeaconChain, BeaconChainError, BeaconChainTypes, | ||
data_column_verification::verify_kzg_for_data_column_list, | ||
}; | ||
use store::{Error as StoreError, KeyValueStore}; | ||
use types::{ColumnIndex, DataColumnSidecarList, Epoch, EthSpec, Hash256, Slot}; | ||
|
||
#[derive(Debug)] | ||
pub enum HistoricalDataColumnError { | ||
// The provided data column sidecar pertains to a block that doesn't exist in the database. | ||
NoBlockFound { | ||
data_column_block_root: Hash256, | ||
}, | ||
|
||
/// Logic error: should never occur. | ||
IndexOutOfBounds, | ||
|
||
/// The provided data column sidecar list doesn't contain columns for the full range of slots for the given epoch. | ||
MissingDataColumns { | ||
missing_slots_and_data_columns: Vec<(Slot, ColumnIndex)>, | ||
}, | ||
|
||
/// The provided data column sidecar list contains at least one column with an invalid kzg commitment. | ||
InvalidKzg, | ||
|
||
/// Internal store error | ||
StoreError(StoreError), | ||
|
||
/// Internal beacon chain error | ||
BeaconChainError(Box<BeaconChainError>), | ||
} | ||
|
||
impl From<StoreError> for HistoricalDataColumnError { | ||
fn from(e: StoreError) -> Self { | ||
Self::StoreError(e) | ||
} | ||
} | ||
|
||
impl<T: BeaconChainTypes> BeaconChain<T> { | ||
/// Store a batch of historical data columns in the database. | ||
/// | ||
/// The data columns block roots and proposer signatures are verified with the existing | ||
/// block stored in the DB. This function assumes that KZG proofs have already been verified. | ||
/// | ||
/// This function requires that the data column sidecar list contains columns for a full epoch. | ||
/// | ||
/// Return the number of `data_columns` successfully imported. | ||
pub fn import_historical_data_column_batch( | ||
&self, | ||
epoch: Epoch, | ||
historical_data_column_sidecar_list: DataColumnSidecarList<T::EthSpec>, | ||
) -> Result<usize, HistoricalDataColumnError> { | ||
let mut total_imported = 0; | ||
let mut ops = vec![]; | ||
|
||
let unique_column_indices = historical_data_column_sidecar_list | ||
.iter() | ||
.map(|item| item.index) | ||
.collect::<HashSet<_>>(); | ||
|
||
let mut slot_and_column_index_to_data_columns = historical_data_column_sidecar_list | ||
.iter() | ||
.map(|data_column| ((data_column.slot(), data_column.index), data_column)) | ||
.collect::<HashMap<_, _>>(); | ||
|
||
if historical_data_column_sidecar_list.is_empty() { | ||
return Ok(total_imported); | ||
} | ||
|
||
let forward_blocks_iter = self | ||
.forwards_iter_block_roots_until( | ||
epoch.start_slot(T::EthSpec::slots_per_epoch()), | ||
epoch.end_slot(T::EthSpec::slots_per_epoch()), | ||
) | ||
.map_err(|e| HistoricalDataColumnError::BeaconChainError(Box::new(e)))?; | ||
|
||
for block_iter_result in forward_blocks_iter { | ||
let (block_root, slot) = block_iter_result | ||
.map_err(|e| HistoricalDataColumnError::BeaconChainError(Box::new(e)))?; | ||
|
||
for column_index in unique_column_indices.clone() { | ||
if let Some(data_column) = | ||
slot_and_column_index_to_data_columns.remove(&(slot, column_index)) | ||
{ | ||
if self | ||
.store | ||
.get_data_column(&block_root, &data_column.index)? | ||
.is_none() | ||
{ | ||
tracing::debug!( | ||
block_root = ?block_root, | ||
column_index = data_column.index, | ||
"Skipping data column import as identical data column exists" | ||
); | ||
continue; | ||
} | ||
if block_root != data_column.block_root() { | ||
return Err(HistoricalDataColumnError::NoBlockFound { | ||
data_column_block_root: data_column.block_root(), | ||
}); | ||
} | ||
self.store.data_column_as_kv_store_ops( | ||
&block_root, | ||
data_column.clone(), | ||
&mut ops, | ||
); | ||
total_imported += 1; | ||
} | ||
} | ||
} | ||
|
||
verify_kzg_for_data_column_list(historical_data_column_sidecar_list.iter(), &self.kzg) | ||
.map_err(|_| HistoricalDataColumnError::InvalidKzg)?; | ||
|
||
self.store.blobs_db.do_atomically(ops)?; | ||
|
||
if slot_and_column_index_to_data_columns.is_empty() { | ||
self.store.put_data_column_custody_info(Some( | ||
epoch.start_slot(T::EthSpec::slots_per_epoch()), | ||
))?; | ||
} else { | ||
tracing::warn!( | ||
?epoch, | ||
missing_slots = ?slot_and_column_index_to_data_columns.keys().map(|(slot, _)| slot), | ||
"Some data columns are missing from the batch" | ||
); | ||
return Err(HistoricalDataColumnError::MissingDataColumns { | ||
missing_slots_and_data_columns: slot_and_column_index_to_data_columns | ||
.keys() | ||
.cloned() | ||
.collect::<Vec<_>>(), | ||
}); | ||
} | ||
|
||
self.data_availability_checker | ||
.custody_context() | ||
.backfill_custody_count_at_epoch(epoch); | ||
|
||
tracing::debug!(total_imported, "Imported historical data columns"); | ||
|
||
Ok(total_imported) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment