Skip to content
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

simulators/portal: update gossip to put content tests #1196

Merged
merged 1 commit into from
Jan 2, 2025
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
135 changes: 12 additions & 123 deletions simulators/portal/Cargo.lock

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

2 changes: 1 addition & 1 deletion simulators/portal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
alloy-rlp = "0.3.8"
alloy-primitives = "0.8.3"
ethportal-api = { git = "https://github.com/ethereum/trin", rev = "4b212d4f3e8afa7b3298eebd4b4b6e3ec04d680f" }
ethportal-api = { git = "https://github.com/ethereum/trin", rev = "5ae01c3ad2c69b4b003e0c206a961f2cf09f3be9" }
futures = "0.3.25"
hivesim = { git = "https://github.com/ethereum/hive", rev = "4408fc1de3fee3ac23acd25a812c117756af2f39" }
itertools = "0.10.5"
Expand Down
16 changes: 8 additions & 8 deletions simulators/portal/src/suites/history/interop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use alloy_primitives::Bytes;
use ethportal_api::types::portal::{FindContentInfo, GetContentInfo};
use ethportal_api::types::portal::{FindContentInfo, GetContentInfo, PutContentInfo};
use ethportal_api::types::portal_wire::MAX_PORTAL_CONTENT_PAYLOAD_SIZE;
use ethportal_api::{
ContentValue, Discv5ApiClient, HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient,
Expand Down Expand Up @@ -180,10 +180,10 @@ dyn_async! {
// Test gossiping a collection of blocks to node B (B will gossip back to A)
test.run(
NClientTestSpec {
name: format!("GOSSIP blocks from A:{} --> B:{}", client_a.name, client_b.name),
name: format!("PUT CONTENT blocks from A:{} --> B:{}", client_a.name, client_b.name),
description: "".to_string(),
always_run: false,
run: test_gossip_two_nodes,
run: test_put_content_two_nodes,
environments: None,
test_data: content.clone(),
clients: vec![client_a.clone(), client_b.clone()],
Expand Down Expand Up @@ -425,7 +425,7 @@ dyn_async! {
}

dyn_async! {
async fn test_gossip_two_nodes<'a> (clients: Vec<Client>, test_data: TestData) {
async fn test_put_content_two_nodes<'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"),
Expand All @@ -445,10 +445,10 @@ dyn_async! {

// With default node settings nodes should be storing all content
for (content_key, content_value) in test_data.clone() {
match client_a.rpc.gossip(content_key.clone(), content_value.encode()).await {
Ok(nodes_gossiped_to) => {
if nodes_gossiped_to != 1 {
panic!("We expected to gossip to 1 node instead we gossiped to: {nodes_gossiped_to}");
match client_a.rpc.put_content(content_key.clone(), content_value.encode()).await {
Ok(PutContentInfo { peer_count, .. }) => {
if peer_count != 1 {
panic!("We expected to gossip to 1 node instead we gossiped to: {peer_count}");
}
}
Err(err) => panic!("Unable to get received content: {err:?}"),
Expand Down
16 changes: 8 additions & 8 deletions simulators/portal/src/suites/state/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ethportal_api::jsonrpsee::http_client::HttpClient;
use ethportal_api::types::execution::header_with_proof::{
BlockHeaderProof, HeaderWithProof, SszNone,
};
use ethportal_api::types::portal::{FindContentInfo, GetContentInfo};
use ethportal_api::types::portal::{FindContentInfo, GetContentInfo, PutContentInfo};
use ethportal_api::types::portal_wire::MAX_PORTAL_CONTENT_PAYLOAD_SIZE;
use ethportal_api::utils::bytes::hex_encode;
use ethportal_api::{
Expand Down Expand Up @@ -196,10 +196,10 @@ dyn_async! {
// Test gossiping a collection of blocks to node B (B will gossip back to A)
test.run(
NClientTestSpec {
name: format!("GOSSIP blocks from A:{} --> B:{}", client_a.name, client_b.name),
name: format!("PUT CONTENT blocks from A:{} --> B:{}", client_a.name, client_b.name),
description: "".to_string(),
always_run: false,
run: test_gossip_two_nodes,
run: test_put_content_two_nodes,
environments: environments.clone(),
test_data: content.clone(),
clients: vec![client_a.clone(), client_b.clone()],
Expand Down Expand Up @@ -439,7 +439,7 @@ dyn_async! {
}

dyn_async! {
async fn test_gossip_two_nodes<'a> (clients: Vec<Client>, test_data: Vec<TestData>) {
async fn test_put_content_two_nodes<'a> (clients: Vec<Client>, test_data: Vec<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"),
Expand All @@ -461,10 +461,10 @@ dyn_async! {
for TestData { header, key: content_key, offer_value: content_offer_value, .. } in test_data.clone() {
store_header(header, &client_b.rpc).await;

match client_a.rpc.gossip(content_key.clone(), content_offer_value.encode()).await {
Ok(nodes_gossiped_to) => {
if nodes_gossiped_to != 1 {
panic!("We expected to gossip to 1 node instead we gossiped to: {nodes_gossiped_to}");
match client_a.rpc.put_content(content_key.clone(), content_offer_value.encode()).await {
Ok(PutContentInfo { peer_count, .. }) => {
Copy link
Contributor

@bhartnett bhartnett Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the test should check that the storedLocally flag is true in the response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes the radius is 100 percent, which I don't think we can assume

Copy link
Contributor

@bhartnett bhartnett Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes true. I guess it depends on how the nodes are setup in the tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the future we can standardize some startup params around this kind of thing

if peer_count != 1 {
panic!("We expected to gossip to 1 node instead we gossiped to: {peer_count}");
}
}
Err(err) => panic!("Unable to get received content: {err:?}"),
Expand Down