-
Notifications
You must be signed in to change notification settings - Fork 75
feat: implement das-core #1094
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
Merged
Merged
feat: implement das-core #1094
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
afa5ca3
add constants
akronim26 deb34ac
compute matrix fn done
akronim26 9a9f53e
recover matrix fn done
akronim26 bd510c5
fix clippy
akronim26 855d98b
add custody group functions
akronim26 6cf820d
fix clippy
akronim26 2839ec5
fix function name
akronim26 b24bdfd
add get_data_column_sidecars
akronim26 a48c40f
fix fn name to match functioning
akronim26 2df3edf
fix error type
akronim26 bcd813d
fixes
akronim26 71778d7
requested changes done
akronim26 8b5705e
used ensure!
akronim26 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| use anyhow::{Ok, Result, anyhow}; | ||
| use discv5::enr::NodeId; | ||
| use ream_consensus_misc::constants::beacon::NUM_CUSTODY_GROUPS; | ||
| use sha2::{Digest, Sha256}; | ||
|
|
||
| use crate::data_column_sidecar::NUMBER_OF_COLUMNS; | ||
|
|
||
| pub fn get_custody_group_indices(node_id: NodeId, custody_group_count: u64) -> Result<Vec<u64>> { | ||
| if custody_group_count > NUM_CUSTODY_GROUPS { | ||
| return Err(anyhow!( | ||
| "Custody group count more than number of custody groups", | ||
| )); | ||
| } | ||
|
|
||
| if custody_group_count == NUM_CUSTODY_GROUPS { | ||
| return Ok((0..NUM_CUSTODY_GROUPS).collect()); | ||
| } | ||
|
|
||
| let mut custody_indices: Vec<u64> = Vec::new(); | ||
| let mut current_id = node_id.raw(); | ||
|
|
||
| while custody_indices.len() < custody_group_count as usize { | ||
| let hash = Sha256::digest(current_id); | ||
|
|
||
| let mut array = [0u8; 8]; | ||
| array.copy_from_slice(&hash[0..8]); | ||
| let index = u64::from_le_bytes(array) % NUM_CUSTODY_GROUPS; | ||
|
|
||
| if !custody_indices.contains(&index) { | ||
| custody_indices.push(index); | ||
| } | ||
|
|
||
| let mut carry = true; | ||
| for byte in current_id.iter_mut().rev() { | ||
| if carry { | ||
| let (new_byte, overflow) = byte.overflowing_add(1); | ||
| *byte = new_byte; | ||
| carry = overflow; | ||
| } | ||
| } | ||
| } | ||
| custody_indices.sort(); | ||
| Ok(custody_indices) | ||
| } | ||
|
|
||
| pub fn compute_columns_for_custody_group(custody_group_index: u64) -> Result<Vec<u64>> { | ||
| if custody_group_index >= NUM_CUSTODY_GROUPS { | ||
| return Err(anyhow!( | ||
| "Custody group index is greater than total custody groups" | ||
| )); | ||
| } | ||
akronim26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let mut column_indices = Vec::new(); | ||
| for col in 0..NUMBER_OF_COLUMNS { | ||
akronim26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if col % NUM_CUSTODY_GROUPS == custody_group_index { | ||
| column_indices.push(col); | ||
| } | ||
| } | ||
|
|
||
| Ok(column_indices) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.