Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 5 additions & 34 deletions simulators/portal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions simulators/portal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ authors = ["Kolby ML (Moroz Liebl) <[email protected]>"]
edition = "2021"

[dependencies]
alloy-rlp = "0.3.8"
alloy-primitives = "0.7.7"
# todo: remove this when we update discv5. Added this because enr 10.1 is a breaking change
enr = { version = "=0.10.0", features = ["k256", "ed25519"] }
ethportal-api = { git = "https://github.com/ethereum/trin", rev = "688847c64c1ef15df20828aa44ef871d3345fc98" }
portal-spec-test-utils-rs = { git = "https://github.com/ethereum/portal-spec-tests", rev = "954f7d0eb2950a2131048404a1a4ce476bb64657" }
hivesim = { git = "https://github.com/ethereum/hive", rev = "62b3362bae655754b5f624c36720ba8c44a2f375" }
futures = "0.3.25"
hivesim = { git = "https://github.com/ethereum/hive", rev = "81fc9a350d7f7ca8bcbe5f54886483d405d4daa8" }
itertools = "0.10.5"
portal-spec-test-utils-rs = { git = "https://github.com/ethereum/portal-spec-tests", rev = "954f7d0eb2950a2131048404a1a4ce476bb64657" }
serde_json = "1.0.87"
serde_yaml = "0.9"
tokio = { version = "1", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
tokio = { version = "1", features = ["full"] }

# todo: remove this when we update discv5. Added this because enr 10.1 is a breaking change
enr = { version = "=0.10.0", features = ["k256", "ed25519"] }
zstd = "=0.13.0"
zstd-safe = "=7.0.0"
zstd-sys = "=2.0.9+zstd.1.5.5"
66 changes: 19 additions & 47 deletions simulators/portal/src/suites/beacon/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use ethportal_api::types::beacon::ContentInfo;
use ethportal_api::utils::bytes::hex_encode;
use ethportal_api::{
BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, ContentValue, Discv5ApiClient,
OverlayContentKey,
};
use hivesim::types::ClientDefinition;
use hivesim::types::ContentKeyValue;
use hivesim::types::TestData;
use hivesim::{dyn_async, Client, NClientTestSpec, Test};
use itertools::Itertools;
use serde_json::json;
Expand All @@ -20,21 +17,13 @@ use std::collections::HashMap;
const MAX_PORTAL_CONTENT_PAYLOAD_SIZE: usize = 1165;
const BOOTSTRAP_KEY: &str = "0x10bd9f42d9a42d972bdaf4dee84e5b419dd432b52867258acb7bcc7f567b6e3af1";

fn content_pair_to_string_pair(
content_pair: (BeaconContentKey, BeaconContentValue),
) -> ContentKeyValue {
let (content_key, content_value) = content_pair;
ContentKeyValue {
key: content_key.to_hex(),
value: hex_encode(content_value.encode()),
}
}
type TestData = (BeaconContentKey, BeaconContentValue);

/// Processed content data for beacon tests
struct ProcessedContent {
content_type: String,
identifier: String,
test_data: Vec<ContentKeyValue>,
test_data: TestData,
}

fn process_content(content: Vec<(BeaconContentKey, BeaconContentValue)>) -> Vec<ProcessedContent> {
Expand All @@ -44,30 +33,30 @@ fn process_content(content: Vec<(BeaconContentKey, BeaconContentValue)>) -> Vec<
BeaconContentKey::LightClientBootstrap(bootstrap) => (
"Bootstrap".to_string(),
hex_encode(bootstrap.block_hash),
vec![content_pair_to_string_pair(beacon_content)],
beacon_content,
),
BeaconContentKey::LightClientUpdatesByRange(updates_by_range) => (
"Updates by Range".to_string(),
format!(
"start period: {} count: {}",
updates_by_range.start_period, updates_by_range.count
),
vec![content_pair_to_string_pair(beacon_content)],
beacon_content,
),
BeaconContentKey::LightClientFinalityUpdate(finality_update) => (
"Finality Update".to_string(),
format!("finalized slot: {}", finality_update.finalized_slot),
vec![content_pair_to_string_pair(beacon_content)],
beacon_content,
),
BeaconContentKey::LightClientOptimisticUpdate(optimistic_update) => (
"Optimistic Update".to_string(),
format!("optimistic slot: {}", optimistic_update.signature_slot),
vec![content_pair_to_string_pair(beacon_content)],
beacon_content,
),
BeaconContentKey::HistoricalSummariesWithProof(historical_summaries) => (
"Historical Summaries".to_string(),
format!("historical summaries epoch: {}", historical_summaries.epoch),
vec![content_pair_to_string_pair(beacon_content)],
beacon_content,
),
};
result.push(ProcessedContent {
Expand Down Expand Up @@ -107,7 +96,7 @@ dyn_async! {
always_run: false,
run: test_recursive_find_content,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: Some(TestData::ContentList(test_data.clone())),
test_data: test_data.clone(),
clients: vec![client_a.clone(), client_b.clone()],
}
).await;
Expand All @@ -119,7 +108,7 @@ dyn_async! {
always_run: false,
run: test_find_content,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: Some(TestData::ContentList(test_data)),
test_data,
clients: vec![client_a.clone(), client_b.clone()],
}
).await;
Expand All @@ -132,7 +121,7 @@ dyn_async! {
always_run: false,
run: test_ping,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone()],
}
).await;
Expand All @@ -144,7 +133,7 @@ dyn_async! {
always_run: false,
run: test_find_content_non_present,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone()],
}
).await;
Expand All @@ -156,7 +145,7 @@ dyn_async! {
always_run: false,
run: test_find_nodes_zero_distance,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone()],
}
).await;
Expand All @@ -166,7 +155,7 @@ dyn_async! {

dyn_async! {
// test that a node will not return content via FINDCONTENT.
async fn test_find_content_non_present<'a>(clients: Vec<Client>, _: Option<TestData>) {
async fn test_find_content_non_present<'a>(clients: Vec<Client>, _: ()) {
let (client_a, client_b) = match clients.iter().collect_tuple() {
Some((client_a, client_b)) => (client_a, client_b),
None => {
Expand Down Expand Up @@ -208,7 +197,7 @@ dyn_async! {
}

dyn_async! {
async fn test_ping<'a>(clients: Vec<Client>, _: Option<TestData>) {
async fn test_ping<'a>(clients: Vec<Client>, _: ()) {
let (client_a, client_b) = match clients.iter().collect_tuple() {
Some((client_a, client_b)) => (client_a, client_b),
None => {
Expand Down Expand Up @@ -249,7 +238,7 @@ dyn_async! {
}

dyn_async! {
async fn test_find_nodes_zero_distance<'a>(clients: Vec<Client>, _: Option<TestData>) {
async fn test_find_nodes_zero_distance<'a>(clients: Vec<Client>, _: ()) {
let (client_a, client_b) = match clients.iter().collect_tuple() {
Some((client_a, client_b)) => (client_a, client_b),
None => {
Expand Down Expand Up @@ -285,23 +274,14 @@ dyn_async! {

dyn_async! {
// test that a node will return a content via RECURSIVEFINDCONTENT template that it has stored locally
async fn test_recursive_find_content<'a>(clients: Vec<Client>, test_data: Option<TestData>) {
async fn test_recursive_find_content<'a>(clients: Vec<Client>, test_data: TestData) {
let (client_a, client_b) = match clients.iter().collect_tuple() {
Some((client_a, client_b)) => (client_a, client_b),
None => {
panic!("Unable to get expected amount of clients from NClientTestSpec");
}
};
let test_data = match test_data.map(|data| data.content_list()) {
Some(test_data) => test_data,
None => panic!("Expected test data non was provided"),
};

let ContentKeyValue { key: target_key, value: target_value } = test_data.first().expect("Target content is required for this test");
let target_key: BeaconContentKey =
serde_json::from_value(json!(target_key)).unwrap();
let target_value: BeaconContentValue =
serde_json::from_value(json!(target_value)).unwrap();
let (target_key, target_value) = test_data;
match client_b.rpc.store(target_key.clone(), target_value.clone()).await {
Ok(result) => if !result {
panic!("Error storing target content for recursive find content");
Expand Down Expand Up @@ -356,22 +336,14 @@ dyn_async! {

dyn_async! {
// test that a node will return a x content via FINDCONTENT that it has stored locally
async fn test_find_content<'a> (clients: Vec<Client>, test_data: Option<TestData>) {
async fn test_find_content<'a> (clients: Vec<Client>, test_data: TestData) {
let (client_a, client_b) = match clients.iter().collect_tuple() {
Some((client_a, client_b)) => (client_a, client_b),
None => {
panic!("Unable to get expected amount of clients from NClientTestSpec");
}
};
let test_data = match test_data.map(|data| data.content_list()) {
Some(test_data) => test_data,
None => panic!("Expected test data none was provided"),
};
let ContentKeyValue { key: target_key, value: target_value } = test_data.first().expect("Target content is required for this test");
let target_key: BeaconContentKey =
serde_json::from_value(json!(target_key)).unwrap();
let target_value: BeaconContentValue =
serde_json::from_value(json!(target_value)).unwrap();
let (target_key, target_value) = test_data;
match client_b.rpc.store(target_key.clone(), target_value.clone()).await {
Ok(result) => if !result {
panic!("Error storing target content for find content");
Expand Down
11 changes: 5 additions & 6 deletions simulators/portal/src/suites/beacon/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ethportal_api::{
BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, Discv5ApiClient,
};
use hivesim::types::ClientDefinition;
use hivesim::types::TestData;
use hivesim::{dyn_async, Client, NClientTestSpec, Test};
use itertools::Itertools;
use serde_json::json;
Expand All @@ -34,7 +33,7 @@ dyn_async! {
always_run: false,
run: test_find_content_two_jumps,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(PRIVATE_KEY_ENVIRONMENT_VARIABLE.to_string(), private_key_2.clone()), (HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(PRIVATE_KEY_ENVIRONMENT_VARIABLE.to_string(), private_key_1.clone()), (HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
}
).await;
Expand All @@ -47,7 +46,7 @@ dyn_async! {
always_run: false,
run: test_find_content_two_jumps,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(PRIVATE_KEY_ENVIRONMENT_VARIABLE.to_string(), private_key_1.clone()), (HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(PRIVATE_KEY_ENVIRONMENT_VARIABLE.to_string(), private_key_2.clone()), (HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
}
).await;
Expand All @@ -59,7 +58,7 @@ dyn_async! {
always_run: false,
run: test_find_nodes_distance_of_client_c,
environments: Some(vec![Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())])), Some(HashMap::from([(HIVE_PORTAL_NETWORKS_SELECTED.to_string(), BEACON_STRING.to_string())]))]),
test_data: None,
test_data: (),
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
}
).await;
Expand All @@ -68,7 +67,7 @@ dyn_async! {
}

dyn_async! {
async fn test_find_content_two_jumps<'a> (clients: Vec<Client>, _: Option<TestData>) {
async fn test_find_content_two_jumps<'a> (clients: Vec<Client>, _: ()) {
let (client_a, client_b, client_c) = match clients.iter().collect_tuple() {
Some((client_a, client_b, client_c)) => (client_a, client_b, client_c),
None => {
Expand Down Expand Up @@ -163,7 +162,7 @@ dyn_async! {
}

dyn_async! {
async fn test_find_nodes_distance_of_client_c<'a>(clients: Vec<Client>, _: Option<TestData>) {
async fn test_find_nodes_distance_of_client_c<'a>(clients: Vec<Client>, _: ()) {
let (client_a, client_b, client_c) = match clients.iter().collect_tuple() {
Some((client_a, client_b, client_c)) => (client_a, client_b, client_c),
None => {
Expand Down
Loading