-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
159 additions
and
6 deletions.
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 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 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,20 @@ | ||
[package] | ||
name = 'eip_7594' | ||
edition = { workspace = true } | ||
authors = ["Grandine <info@grandine.io>"] | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
num-traits = { workspace = true } | ||
ssz = { workspace = true} | ||
sha2 = { workspace = true } | ||
typenum = { workspace = true } | ||
types = { workspace = true } | ||
|
||
[dev-dependencies] | ||
duplicate = { workspace = true } | ||
serde = { workspace = true } | ||
spec_test_utils = { workspace = true } | ||
test-generator = { workspace = true } |
This file contains 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,101 @@ | ||
use num_traits::One as _; | ||
use sha2::{Digest as _, Sha256}; | ||
use ssz::Uint256; | ||
use typenum::Unsigned as _; | ||
use types::{ | ||
eip7594::{ColumnIndex, NumberOfColumns, DATA_COLUMN_SIDECAR_SUBNET_COUNT}, | ||
phase0::primitives::NodeId, | ||
}; | ||
|
||
pub fn get_custody_columns(node_id: NodeId, custody_subnet_count: u64) -> Vec<ColumnIndex> { | ||
assert!(custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT); | ||
|
||
let mut subnet_ids = vec![]; | ||
let mut current_id = node_id; | ||
|
||
while (subnet_ids.len() as u64) < custody_subnet_count { | ||
let mut hasher = Sha256::new(); | ||
let mut bytes: [u8; 32] = [0; 32]; | ||
|
||
current_id.into_raw().to_little_endian(&mut bytes); | ||
|
||
hasher.update(&bytes); | ||
bytes = hasher.finalize().into(); | ||
|
||
let output_prefix = [ | ||
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], | ||
]; | ||
|
||
let output_prefix_u64 = u64::from_le_bytes(output_prefix); | ||
let subnet_id = output_prefix_u64 % DATA_COLUMN_SIDECAR_SUBNET_COUNT; | ||
|
||
if !subnet_ids.contains(&subnet_id) { | ||
subnet_ids.push(subnet_id); | ||
} | ||
|
||
if current_id == Uint256::MAX { | ||
current_id = Uint256::ZERO; | ||
} | ||
|
||
current_id = current_id + Uint256::one(); | ||
} | ||
|
||
let columns_per_subnet = NumberOfColumns::U64 / DATA_COLUMN_SIDECAR_SUBNET_COUNT; | ||
let mut result = Vec::new(); | ||
for i in 0..columns_per_subnet { | ||
for &subnet_id in &subnet_ids { | ||
result.push( | ||
(DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnet_id) | ||
.try_into() | ||
.unwrap(), | ||
); | ||
} | ||
} | ||
|
||
result.sort(); | ||
result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use duplicate::duplicate_item; | ||
use serde::Deserialize; | ||
use spec_test_utils::Case; | ||
use test_generator::test_resources; | ||
use types::{ | ||
phase0::primitives::NodeId, | ||
preset::{Mainnet, Minimal, Preset}, | ||
}; | ||
|
||
use crate::{get_custody_columns, ColumnIndex}; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
struct Meta { | ||
description: Option<String>, | ||
node_id: NodeId, | ||
custody_subnet_count: u64, | ||
result: Vec<ColumnIndex>, | ||
} | ||
|
||
#[duplicate_item( | ||
glob function_name preset; | ||
["consensus-spec-tests/tests/mainnet/eip7594/networking/get_custody_columns/*/*"] [get_custody_columns_mainnet] [Mainnet]; | ||
["consensus-spec-tests/tests/minimal/eip7594/networking/get_custody_columns/*/*"] [get_custody_columns_minimal] [Minimal]; | ||
)] | ||
#[test_resources(glob)] | ||
fn function_name(case: Case) { | ||
run_case::<preset>(case); | ||
} | ||
|
||
fn run_case<P: Preset>(case: Case) { | ||
let Meta { | ||
description: _description, | ||
node_id, | ||
custody_subnet_count, | ||
result, | ||
} = case.yaml::<Meta>("meta"); | ||
|
||
assert_eq!(get_custody_columns(node_id, custody_subnet_count), result); | ||
} | ||
} |
Submodule eth2_libp2p
updated
22 files
+1 −1 | Cargo.toml | |
+1 −0 | gossipsub/Cargo.toml | |
+8 −8 | gossipsub/src/lib.rs | |
+5 −1 | src/config.rs | |
+107 −4 | src/discovery/enr.rs | |
+30 −5 | src/discovery/mod.rs | |
+20 −2 | src/discovery/subnet_predicate.rs | |
+0 −1 | src/lib.rs | |
+167 −110 | src/metrics.rs | |
+21 −7 | src/peer_manager/mod.rs | |
+9 −0 | src/peer_manager/peerdb/peer_info.rs | |
+2 −4 | src/peer_manager/peerdb/score.rs | |
+3 −3 | src/rpc/codec/base.rs | |
+12 −12 | src/rpc/codec/ssz_snappy.rs | |
+7 −0 | src/service/gossip_cache.rs | |
+26 −25 | src/service/mod.rs | |
+11 −3 | src/types/fork_context.rs | |
+44 −0 | src/types/pubsub.rs | |
+2 −0 | src/types/subnet.rs | |
+13 −0 | src/types/topics.rs | |
+4 −4 | tests/common.rs | |
+12 −12 | tests/rpc_tests.rs |
This file contains 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 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 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 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