Skip to content

Commit efee594

Browse files
committed
simulators/portal: update portal simulators to newest version of hivesim
1 parent 81fc9a3 commit efee594

File tree

11 files changed

+196
-385
lines changed

11 files changed

+196
-385
lines changed

simulators/portal/Cargo.lock

Lines changed: 5 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simulators/portal/Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ authors = ["Kolby ML (Moroz Liebl) <[email protected]>"]
55
edition = "2021"
66

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

19-
# todo: remove this when we update discv5. Added this because enr 10.1 is a breaking change
20-
enr = { version = "=0.10.0", features = ["k256", "ed25519"] }
21-
zstd = "=0.13.0"
22-
zstd-safe = "=7.0.0"
23-
zstd-sys = "=2.0.9+zstd.1.5.5"

simulators/portal/src/suites/beacon/interop.rs

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use ethportal_api::types::beacon::ContentInfo;
55
use ethportal_api::utils::bytes::hex_encode;
66
use ethportal_api::{
77
BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, ContentValue, Discv5ApiClient,
8-
OverlayContentKey,
98
};
109
use hivesim::types::ClientDefinition;
11-
use hivesim::types::ContentKeyValue;
12-
use hivesim::types::TestData;
1310
use hivesim::{dyn_async, Client, NClientTestSpec, Test};
1411
use itertools::Itertools;
1512
use serde_json::json;
@@ -20,21 +17,13 @@ use std::collections::HashMap;
2017
const MAX_PORTAL_CONTENT_PAYLOAD_SIZE: usize = 1165;
2118
const BOOTSTRAP_KEY: &str = "0x10bd9f42d9a42d972bdaf4dee84e5b419dd432b52867258acb7bcc7f567b6e3af1";
2219

23-
fn content_pair_to_string_pair(
24-
content_pair: (BeaconContentKey, BeaconContentValue),
25-
) -> ContentKeyValue {
26-
let (content_key, content_value) = content_pair;
27-
ContentKeyValue {
28-
key: content_key.to_hex(),
29-
value: hex_encode(content_value.encode()),
30-
}
31-
}
20+
type TestData = (BeaconContentKey, BeaconContentValue);
3221

3322
/// Processed content data for beacon tests
3423
struct ProcessedContent {
3524
content_type: String,
3625
identifier: String,
37-
test_data: Vec<ContentKeyValue>,
26+
test_data: TestData,
3827
}
3928

4029
fn process_content(content: Vec<(BeaconContentKey, BeaconContentValue)>) -> Vec<ProcessedContent> {
@@ -44,30 +33,30 @@ fn process_content(content: Vec<(BeaconContentKey, BeaconContentValue)>) -> Vec<
4433
BeaconContentKey::LightClientBootstrap(bootstrap) => (
4534
"Bootstrap".to_string(),
4635
hex_encode(bootstrap.block_hash),
47-
vec![content_pair_to_string_pair(beacon_content)],
36+
beacon_content,
4837
),
4938
BeaconContentKey::LightClientUpdatesByRange(updates_by_range) => (
5039
"Updates by Range".to_string(),
5140
format!(
5241
"start period: {} count: {}",
5342
updates_by_range.start_period, updates_by_range.count
5443
),
55-
vec![content_pair_to_string_pair(beacon_content)],
44+
beacon_content,
5645
),
5746
BeaconContentKey::LightClientFinalityUpdate(finality_update) => (
5847
"Finality Update".to_string(),
5948
format!("finalized slot: {}", finality_update.finalized_slot),
60-
vec![content_pair_to_string_pair(beacon_content)],
49+
beacon_content,
6150
),
6251
BeaconContentKey::LightClientOptimisticUpdate(optimistic_update) => (
6352
"Optimistic Update".to_string(),
6453
format!("optimistic slot: {}", optimistic_update.signature_slot),
65-
vec![content_pair_to_string_pair(beacon_content)],
54+
beacon_content,
6655
),
6756
BeaconContentKey::HistoricalSummariesWithProof(historical_summaries) => (
6857
"Historical Summaries".to_string(),
6958
format!("historical summaries epoch: {}", historical_summaries.epoch),
70-
vec![content_pair_to_string_pair(beacon_content)],
59+
beacon_content,
7160
),
7261
};
7362
result.push(ProcessedContent {
@@ -107,7 +96,7 @@ dyn_async! {
10796
always_run: false,
10897
run: test_recursive_find_content,
10998
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())]))]),
110-
test_data: Some(TestData::ContentList(test_data.clone())),
99+
test_data: test_data.clone(),
111100
clients: vec![client_a.clone(), client_b.clone()],
112101
}
113102
).await;
@@ -119,7 +108,7 @@ dyn_async! {
119108
always_run: false,
120109
run: test_find_content,
121110
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())]))]),
122-
test_data: Some(TestData::ContentList(test_data)),
111+
test_data,
123112
clients: vec![client_a.clone(), client_b.clone()],
124113
}
125114
).await;
@@ -132,7 +121,7 @@ dyn_async! {
132121
always_run: false,
133122
run: test_ping,
134123
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())]))]),
135-
test_data: None,
124+
test_data: (),
136125
clients: vec![client_a.clone(), client_b.clone()],
137126
}
138127
).await;
@@ -144,7 +133,7 @@ dyn_async! {
144133
always_run: false,
145134
run: test_find_content_non_present,
146135
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())]))]),
147-
test_data: None,
136+
test_data: (),
148137
clients: vec![client_a.clone(), client_b.clone()],
149138
}
150139
).await;
@@ -156,7 +145,7 @@ dyn_async! {
156145
always_run: false,
157146
run: test_find_nodes_zero_distance,
158147
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())]))]),
159-
test_data: None,
148+
test_data: (),
160149
clients: vec![client_a.clone(), client_b.clone()],
161150
}
162151
).await;
@@ -166,7 +155,7 @@ dyn_async! {
166155

167156
dyn_async! {
168157
// test that a node will not return content via FINDCONTENT.
169-
async fn test_find_content_non_present<'a>(clients: Vec<Client>, _: Option<TestData>) {
158+
async fn test_find_content_non_present<'a>(clients: Vec<Client>, _: ()) {
170159
let (client_a, client_b) = match clients.iter().collect_tuple() {
171160
Some((client_a, client_b)) => (client_a, client_b),
172161
None => {
@@ -208,7 +197,7 @@ dyn_async! {
208197
}
209198

210199
dyn_async! {
211-
async fn test_ping<'a>(clients: Vec<Client>, _: Option<TestData>) {
200+
async fn test_ping<'a>(clients: Vec<Client>, _: ()) {
212201
let (client_a, client_b) = match clients.iter().collect_tuple() {
213202
Some((client_a, client_b)) => (client_a, client_b),
214203
None => {
@@ -249,7 +238,7 @@ dyn_async! {
249238
}
250239

251240
dyn_async! {
252-
async fn test_find_nodes_zero_distance<'a>(clients: Vec<Client>, _: Option<TestData>) {
241+
async fn test_find_nodes_zero_distance<'a>(clients: Vec<Client>, _: ()) {
253242
let (client_a, client_b) = match clients.iter().collect_tuple() {
254243
Some((client_a, client_b)) => (client_a, client_b),
255244
None => {
@@ -285,23 +274,14 @@ dyn_async! {
285274

286275
dyn_async! {
287276
// test that a node will return a content via RECURSIVEFINDCONTENT template that it has stored locally
288-
async fn test_recursive_find_content<'a>(clients: Vec<Client>, test_data: Option<TestData>) {
277+
async fn test_recursive_find_content<'a>(clients: Vec<Client>, test_data: TestData) {
289278
let (client_a, client_b) = match clients.iter().collect_tuple() {
290279
Some((client_a, client_b)) => (client_a, client_b),
291280
None => {
292281
panic!("Unable to get expected amount of clients from NClientTestSpec");
293282
}
294283
};
295-
let test_data = match test_data.map(|data| data.content_list()) {
296-
Some(test_data) => test_data,
297-
None => panic!("Expected test data non was provided"),
298-
};
299-
300-
let ContentKeyValue { key: target_key, value: target_value } = test_data.first().expect("Target content is required for this test");
301-
let target_key: BeaconContentKey =
302-
serde_json::from_value(json!(target_key)).unwrap();
303-
let target_value: BeaconContentValue =
304-
serde_json::from_value(json!(target_value)).unwrap();
284+
let (target_key, target_value) = test_data;
305285
match client_b.rpc.store(target_key.clone(), target_value.clone()).await {
306286
Ok(result) => if !result {
307287
panic!("Error storing target content for recursive find content");
@@ -356,22 +336,14 @@ dyn_async! {
356336

357337
dyn_async! {
358338
// test that a node will return a x content via FINDCONTENT that it has stored locally
359-
async fn test_find_content<'a> (clients: Vec<Client>, test_data: Option<TestData>) {
339+
async fn test_find_content<'a> (clients: Vec<Client>, test_data: TestData) {
360340
let (client_a, client_b) = match clients.iter().collect_tuple() {
361341
Some((client_a, client_b)) => (client_a, client_b),
362342
None => {
363343
panic!("Unable to get expected amount of clients from NClientTestSpec");
364344
}
365345
};
366-
let test_data = match test_data.map(|data| data.content_list()) {
367-
Some(test_data) => test_data,
368-
None => panic!("Expected test data none was provided"),
369-
};
370-
let ContentKeyValue { key: target_key, value: target_value } = test_data.first().expect("Target content is required for this test");
371-
let target_key: BeaconContentKey =
372-
serde_json::from_value(json!(target_key)).unwrap();
373-
let target_value: BeaconContentValue =
374-
serde_json::from_value(json!(target_value)).unwrap();
346+
let (target_key, target_value) = test_data;
375347
match client_b.rpc.store(target_key.clone(), target_value.clone()).await {
376348
Ok(result) => if !result {
377349
panic!("Error storing target content for find content");

simulators/portal/src/suites/beacon/mesh.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use ethportal_api::{
99
BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, Discv5ApiClient,
1010
};
1111
use hivesim::types::ClientDefinition;
12-
use hivesim::types::TestData;
1312
use hivesim::{dyn_async, Client, NClientTestSpec, Test};
1413
use itertools::Itertools;
1514
use serde_json::json;
@@ -34,7 +33,7 @@ dyn_async! {
3433
always_run: false,
3534
run: test_find_content_two_jumps,
3635
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())]))]),
37-
test_data: None,
36+
test_data: (),
3837
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
3938
}
4039
).await;
@@ -47,7 +46,7 @@ dyn_async! {
4746
always_run: false,
4847
run: test_find_content_two_jumps,
4948
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())]))]),
50-
test_data: None,
49+
test_data: (),
5150
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
5251
}
5352
).await;
@@ -59,7 +58,7 @@ dyn_async! {
5958
always_run: false,
6059
run: test_find_nodes_distance_of_client_c,
6160
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())]))]),
62-
test_data: None,
61+
test_data: (),
6362
clients: vec![client_a.clone(), client_b.clone(), client_c.clone()],
6463
}
6564
).await;
@@ -68,7 +67,7 @@ dyn_async! {
6867
}
6968

7069
dyn_async! {
71-
async fn test_find_content_two_jumps<'a> (clients: Vec<Client>, _: Option<TestData>) {
70+
async fn test_find_content_two_jumps<'a> (clients: Vec<Client>, _: ()) {
7271
let (client_a, client_b, client_c) = match clients.iter().collect_tuple() {
7372
Some((client_a, client_b, client_c)) => (client_a, client_b, client_c),
7473
None => {
@@ -163,7 +162,7 @@ dyn_async! {
163162
}
164163

165164
dyn_async! {
166-
async fn test_find_nodes_distance_of_client_c<'a>(clients: Vec<Client>, _: Option<TestData>) {
165+
async fn test_find_nodes_distance_of_client_c<'a>(clients: Vec<Client>, _: ()) {
167166
let (client_a, client_b, client_c) = match clients.iter().collect_tuple() {
168167
Some((client_a, client_b, client_c)) => (client_a, client_b, client_c),
169168
None => {

0 commit comments

Comments
 (0)