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

refactor: update Gossip to PutContent #1607

Merged
merged 2 commits 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
4 changes: 2 additions & 2 deletions book/src/developers/protocols/json_rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The specification for these endpoints can be found [here](https://playground.ope
- `discv5_routingTableInfo`
- `portal_historyFindContent`
- `portal_historyFindNodes`
- `portal_historyGossip`
- `portal_historyPutContent`
- `portal_historyLocalContent`
- `portal_historyPing`
- `portal_historyOffer`
Expand All @@ -21,7 +21,7 @@ The specification for these endpoints can be found [here](https://playground.ope
- `portal_stateFindContent`
- `portal_stateFindNodes`
- `portal_stateLocalContent`
- `portal_stateGossip`
- `portal_statePutContent`
- `portal_stateOffer`
- `portal_stateStore`
- `portal_statePing`
Expand Down
15 changes: 8 additions & 7 deletions ethportal-api/src/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::{
enr::Enr,
portal::{
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
TracePutContentInfo,
},
portal_wire::OfferTrace,
},
Expand Down Expand Up @@ -114,21 +115,21 @@ pub trait BeaconNetworkApi {

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return the number of peers that the content was gossiped to.
Copy link
Member

Choose a reason for hiding this comment

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

nit: We have changed the return format, and those doc strings should be updated here and in history and state files.

#[method(name = "beaconGossip")]
async fn gossip(
#[method(name = "beaconPutContent")]
async fn put_content(
&self,
content_key: BeaconContentKey,
content_value: RawContentValue,
) -> RpcResult<u32>;
) -> RpcResult<PutContentInfo>;

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return tracing info detailing the gossip propagation.
#[method(name = "beaconTraceGossip")]
async fn trace_gossip(
#[method(name = "beaconTracePutContent")]
async fn trace_put_content(
&self,
content_key: BeaconContentKey,
content_value: RawContentValue,
) -> RpcResult<TraceGossipInfo>;
) -> RpcResult<TracePutContentInfo>;

/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
/// response. Does not store the content locally.
Expand Down
15 changes: 8 additions & 7 deletions ethportal-api/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::{
enr::Enr,
portal::{
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
TracePutContentInfo,
},
portal_wire::OfferTrace,
},
Expand Down Expand Up @@ -85,21 +86,21 @@ pub trait HistoryNetworkApi {

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return the number of peers that the content was gossiped to.
#[method(name = "historyGossip")]
async fn gossip(
#[method(name = "historyPutContent")]
async fn put_content(
&self,
content_key: HistoryContentKey,
content_value: RawContentValue,
) -> RpcResult<u32>;
) -> RpcResult<PutContentInfo>;

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return tracing info detailing the gossip propagation.
#[method(name = "historyTraceGossip")]
async fn trace_gossip(
#[method(name = "historyTracePutContent")]
async fn trace_put_content(
&self,
content_key: HistoryContentKey,
content_value: RawContentValue,
) -> RpcResult<TraceGossipInfo>;
) -> RpcResult<TracePutContentInfo>;

/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
/// response. Does not store the content locally.
Expand Down
15 changes: 8 additions & 7 deletions ethportal-api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::{
enr::Enr,
portal::{
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
TracePutContentInfo,
},
portal_wire::OfferTrace,
},
Expand Down Expand Up @@ -82,21 +83,21 @@ pub trait StateNetworkApi {

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return the number of peers that the content was gossiped to.
#[method(name = "stateGossip")]
async fn gossip(
#[method(name = "statePutContent")]
async fn put_content(
&self,
content_key: StateContentKey,
content_value: RawContentValue,
) -> RpcResult<u32>;
) -> RpcResult<PutContentInfo>;

/// Send the provided content value to interested peers. Clients may choose to send to some or
/// all peers. Return tracing info detailing the gossip propagation.
#[method(name = "stateTraceGossip")]
async fn trace_gossip(
#[method(name = "stateTracePutContent")]
async fn trace_put_content(
&self,
content_key: StateContentKey,
content_value: RawContentValue,
) -> RpcResult<TraceGossipInfo>;
) -> RpcResult<TracePutContentInfo>;

/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
/// response. Does not store the content locally.
Expand Down
12 changes: 6 additions & 6 deletions ethportal-api/src/types/jsonrpc/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub enum StateEndpoint {
/// params: [enr, content_key, content_value]
TraceOffer(Enr, StateContentKey, StateContentValue),
/// params: [enr, content_key, content_value]
Gossip(StateContentKey, StateContentValue),
PutContent(StateContentKey, StateContentValue),
/// params: [content_key, content_value]
TraceGossip(StateContentKey, StateContentValue),
TracePutContent(StateContentKey, StateContentValue),
/// params: [offset, limit]
PaginateLocalContentKeys(u64, u64),
}
Expand All @@ -75,9 +75,9 @@ pub enum HistoryEndpoint {
/// params: [node_id]
LookupEnr(NodeId),
/// params: [content_key, content_value]
Gossip(HistoryContentKey, HistoryContentValue),
PutContent(HistoryContentKey, HistoryContentValue),
/// params: [content_key, content_value]
TraceGossip(HistoryContentKey, HistoryContentValue),
TracePutContent(HistoryContentKey, HistoryContentValue),
/// params: [enr, Vec<(content_key, content_value)>]
Offer(Enr, Vec<(HistoryContentKey, HistoryContentValue)>),
/// params: [enr, content_key, content_value]
Expand Down Expand Up @@ -131,9 +131,9 @@ pub enum BeaconEndpoint {
/// params: node_id
LookupEnr(NodeId),
/// params: [content_key, content_value]
Gossip(BeaconContentKey, BeaconContentValue),
PutContent(BeaconContentKey, BeaconContentValue),
/// params: [content_key, content_value]
TraceGossip(BeaconContentKey, BeaconContentValue),
TracePutContent(BeaconContentKey, BeaconContentValue),
/// params: [enr, Vec<(content_key, content_value>)]
Offer(Enr, Vec<(BeaconContentKey, BeaconContentValue)>),
/// params: [enr, content_key, content_value]
Expand Down
20 changes: 15 additions & 5 deletions ethportal-api/src/types/portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,25 @@ pub struct AcceptInfo {
pub content_keys: BitList<typenum::U64>,
}

/// Response for TraceGossip endpoint
/// Response for PutContent endpoint
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TraceGossipInfo {
// List of all ENRs that were offered the content
pub struct PutContentInfo {
/// Indicates how many peers the content was gossiped to
pub peer_count: u32,
/// Indicates whether the content was stored locally or not
pub stored_locally: bool,
}

/// Response for TracePutContent endpoint
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TracePutContentInfo {
/// List of all ENRs that were offered the content
pub offered: Vec<String>,
// List of all ENRs that accepted the offer
/// List of all ENRs that accepted the offer
pub accepted: Vec<String>,
// List of all ENRs to whom the content was successfully transferred
/// List of all ENRs to whom the content was successfully transferred
pub transferred: Vec<String>,
}

Expand Down
2 changes: 1 addition & 1 deletion ethportal-peertest/src/scenarios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod basic;
pub mod bridge;
pub mod eth_rpc;
pub mod find;
pub mod gossip;
pub mod offer_accept;
pub mod paginate;
pub mod put_content;
pub mod state;
pub mod utp;
pub mod validation;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn test_gossip_with_trace(peertest: &Peertest, target: &Client) {
let _ = target.ping(peertest.bootnode.enr.clone()).await.unwrap();
let (content_key, content_value) = fixture_header_by_hash();
let result = target
.trace_gossip(content_key.clone(), content_value.encode())
.trace_put_content(content_key.clone(), content_value.encode())
.await
.unwrap();

Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn test_gossip_with_trace(peertest: &Peertest, target: &Client) {

// send new trace gossip request
let result = target
.trace_gossip(content_key.clone(), content_value.encode())
.trace_put_content(content_key.clone(), content_value.encode())
.await
.unwrap();

Expand All @@ -67,7 +67,7 @@ pub async fn test_gossip_with_trace(peertest: &Peertest, target: &Client) {

// test trace gossip without any expected accepts
let result = target
.trace_gossip(content_key, content_value.encode())
.trace_put_content(content_key, content_value.encode())
.await
.unwrap();

Expand Down
14 changes: 7 additions & 7 deletions portal-bridge/src/bridge/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use trin_metrics::bridge::BridgeMetricsReporter;
use crate::{
api::consensus::ConsensusApi,
constants::BEACON_GENESIS_TIME,
gossip::gossip_beacon_content,
put_content::put_content_beacon_content,
stats::{BeaconSlotStats, StatsReporter},
types::mode::BridgeMode,
utils::{
Expand Down Expand Up @@ -127,7 +127,7 @@ impl BeaconBridge {
// test files have no slot number data, so report all gossiped content at height 0.
let slot_stats = Arc::new(StdMutex::new(BeaconSlotStats::new(0)));
for asset in assets.0.into_iter() {
gossip_beacon_content(
put_content_beacon_content(
self.portal_client.clone(),
asset.content_key.clone(),
asset.content_value().expect("Error getting content value"),
Expand Down Expand Up @@ -336,7 +336,7 @@ impl BeaconBridge {
});

// Return the latest finalized block root if we successfully gossiped the latest bootstrap.
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
finalized_bootstrap.lock().await.finalized_block_root = latest_finalized_block_root;
finalized_bootstrap.lock().await.in_progress = false;

Expand Down Expand Up @@ -402,7 +402,7 @@ impl BeaconBridge {
);

// Update the current known period if we successfully gossiped the latest data.
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
*current_period.lock().await = expected_current_period;

Ok(())
Expand All @@ -426,7 +426,7 @@ impl BeaconBridge {
LightClientOptimisticUpdateKey::new(update.signature_slot),
);
let content_value = BeaconContentValue::LightClientOptimisticUpdate(update.into());
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await
}

async fn serve_light_client_finality_update(
Expand Down Expand Up @@ -465,7 +465,7 @@ impl BeaconBridge {
);
let content_value = BeaconContentValue::LightClientFinalityUpdate(update.into());

gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
*finalized_slot.lock().await = new_finalized_slot;

Ok(())
Expand Down Expand Up @@ -532,7 +532,7 @@ impl BeaconBridge {
let content_value =
BeaconContentValue::HistoricalSummariesWithProof(historical_summaries_with_proof);

gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
finalized_state_root.lock().await.state_root = latest_finalized_state_root;
finalized_state_root.lock().await.in_progress = false;

Expand Down
2 changes: 1 addition & 1 deletion portal-bridge/src/bridge/era1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{
history::{HEADER_SATURATION_DELAY, SERVE_BLOCK_TIMEOUT},
utils::lookup_epoch_acc,
},
gossip::gossip_history_content,
put_content::gossip_history_content,
stats::{HistoryBlockStats, StatsReporter},
types::mode::{BridgeMode, FourFoursMode},
};
Expand Down
2 changes: 1 addition & 1 deletion portal-bridge/src/bridge/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use trin_validation::{
use crate::{
api::execution::ExecutionApi,
bridge::utils::lookup_epoch_acc,
gossip::gossip_history_content,
put_content::gossip_history_content,
stats::{HistoryBlockStats, StatsReporter},
types::{full_header::FullHeader, mode::BridgeMode},
utils::{read_test_assets_from_file, TestAssets},
Expand Down
2 changes: 1 addition & 1 deletion portal-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub mod bridge;
pub mod census;
pub mod cli;
pub mod constants;
pub mod gossip;
pub mod handle;
pub mod put_content;
pub mod stats;
pub mod types;
pub mod utils;
Expand Down
Loading
Loading