Skip to content

Commit 5ae01c3

Browse files
authored
refactor: update Gossip to PutContent (#1607)
1 parent 29559d2 commit 5ae01c3

File tree

25 files changed

+232
-184
lines changed

25 files changed

+232
-184
lines changed

book/src/developers/protocols/json_rpc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The specification for these endpoints can be found [here](https://playground.ope
1212
- `discv5_routingTableInfo`
1313
- `portal_historyFindContent`
1414
- `portal_historyFindNodes`
15-
- `portal_historyGossip`
15+
- `portal_historyPutContent`
1616
- `portal_historyLocalContent`
1717
- `portal_historyPing`
1818
- `portal_historyOffer`
@@ -21,7 +21,7 @@ The specification for these endpoints can be found [here](https://playground.ope
2121
- `portal_stateFindContent`
2222
- `portal_stateFindNodes`
2323
- `portal_stateLocalContent`
24-
- `portal_stateGossip`
24+
- `portal_statePutContent`
2525
- `portal_stateOffer`
2626
- `portal_stateStore`
2727
- `portal_statePing`

ethportal-api/src/beacon.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::{
1414
enr::Enr,
1515
portal::{
1616
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
17-
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
17+
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
18+
TracePutContentInfo,
1819
},
1920
portal_wire::OfferTrace,
2021
},
@@ -114,21 +115,21 @@ pub trait BeaconNetworkApi {
114115

115116
/// Send the provided content value to interested peers. Clients may choose to send to some or
116117
/// all peers. Return the number of peers that the content was gossiped to.
117-
#[method(name = "beaconGossip")]
118-
async fn gossip(
118+
#[method(name = "beaconPutContent")]
119+
async fn put_content(
119120
&self,
120121
content_key: BeaconContentKey,
121122
content_value: RawContentValue,
122-
) -> RpcResult<u32>;
123+
) -> RpcResult<PutContentInfo>;
123124

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

133134
/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
134135
/// response. Does not store the content locally.

ethportal-api/src/history.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::{
77
enr::Enr,
88
portal::{
99
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
10-
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
10+
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
11+
TracePutContentInfo,
1112
},
1213
portal_wire::OfferTrace,
1314
},
@@ -85,21 +86,21 @@ pub trait HistoryNetworkApi {
8586

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

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

104105
/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
105106
/// response. Does not store the content locally.

ethportal-api/src/state.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::{
77
enr::Enr,
88
portal::{
99
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
10-
PaginateLocalContentInfo, PongInfo, TraceContentInfo, TraceGossipInfo,
10+
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
11+
TracePutContentInfo,
1112
},
1213
portal_wire::OfferTrace,
1314
},
@@ -82,21 +83,21 @@ pub trait StateNetworkApi {
8283

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

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

101102
/// Send an OFFER request with given ContentItems, to the designated peer and wait for a
102103
/// response. Does not store the content locally.

ethportal-api/src/types/jsonrpc/endpoints.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub enum StateEndpoint {
4848
/// params: [enr, content_key, content_value]
4949
TraceOffer(Enr, StateContentKey, StateContentValue),
5050
/// params: [enr, content_key, content_value]
51-
Gossip(StateContentKey, StateContentValue),
51+
PutContent(StateContentKey, StateContentValue),
5252
/// params: [content_key, content_value]
53-
TraceGossip(StateContentKey, StateContentValue),
53+
TracePutContent(StateContentKey, StateContentValue),
5454
/// params: [offset, limit]
5555
PaginateLocalContentKeys(u64, u64),
5656
}
@@ -75,9 +75,9 @@ pub enum HistoryEndpoint {
7575
/// params: [node_id]
7676
LookupEnr(NodeId),
7777
/// params: [content_key, content_value]
78-
Gossip(HistoryContentKey, HistoryContentValue),
78+
PutContent(HistoryContentKey, HistoryContentValue),
7979
/// params: [content_key, content_value]
80-
TraceGossip(HistoryContentKey, HistoryContentValue),
80+
TracePutContent(HistoryContentKey, HistoryContentValue),
8181
/// params: [enr, Vec<(content_key, content_value)>]
8282
Offer(Enr, Vec<(HistoryContentKey, HistoryContentValue)>),
8383
/// params: [enr, content_key, content_value]
@@ -131,9 +131,9 @@ pub enum BeaconEndpoint {
131131
/// params: node_id
132132
LookupEnr(NodeId),
133133
/// params: [content_key, content_value]
134-
Gossip(BeaconContentKey, BeaconContentValue),
134+
PutContent(BeaconContentKey, BeaconContentValue),
135135
/// params: [content_key, content_value]
136-
TraceGossip(BeaconContentKey, BeaconContentValue),
136+
TracePutContent(BeaconContentKey, BeaconContentValue),
137137
/// params: [enr, Vec<(content_key, content_value>)]
138138
Offer(Enr, Vec<(BeaconContentKey, BeaconContentValue)>),
139139
/// params: [enr, content_key, content_value]

ethportal-api/src/types/portal.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,25 @@ pub struct AcceptInfo {
6767
pub content_keys: BitList<typenum::U64>,
6868
}
6969

70-
/// Response for TraceGossip endpoint
70+
/// Response for PutContent endpoint
7171
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7272
#[serde(rename_all = "camelCase")]
73-
pub struct TraceGossipInfo {
74-
// List of all ENRs that were offered the content
73+
pub struct PutContentInfo {
74+
/// Indicates how many peers the content was gossiped to
75+
pub peer_count: u32,
76+
/// Indicates whether the content was stored locally or not
77+
pub stored_locally: bool,
78+
}
79+
80+
/// Response for TracePutContent endpoint
81+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
82+
#[serde(rename_all = "camelCase")]
83+
pub struct TracePutContentInfo {
84+
/// List of all ENRs that were offered the content
7585
pub offered: Vec<String>,
76-
// List of all ENRs that accepted the offer
86+
/// List of all ENRs that accepted the offer
7787
pub accepted: Vec<String>,
78-
// List of all ENRs to whom the content was successfully transferred
88+
/// List of all ENRs to whom the content was successfully transferred
7989
pub transferred: Vec<String>,
8090
}
8191

ethportal-peertest/src/scenarios/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ pub mod basic;
22
pub mod bridge;
33
pub mod eth_rpc;
44
pub mod find;
5-
pub mod gossip;
65
pub mod offer_accept;
76
pub mod paginate;
7+
pub mod put_content;
88
pub mod state;
99
pub mod utp;
1010
pub mod validation;

ethportal-peertest/src/scenarios/gossip.rs renamed to ethportal-peertest/src/scenarios/put_content.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn test_gossip_with_trace(peertest: &Peertest, target: &Client) {
2020
let _ = target.ping(peertest.bootnode.enr.clone()).await.unwrap();
2121
let (content_key, content_value) = fixture_header_by_hash();
2222
let result = target
23-
.trace_gossip(content_key.clone(), content_value.encode())
23+
.trace_put_content(content_key.clone(), content_value.encode())
2424
.await
2525
.unwrap();
2626

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

5151
// send new trace gossip request
5252
let result = target
53-
.trace_gossip(content_key.clone(), content_value.encode())
53+
.trace_put_content(content_key.clone(), content_value.encode())
5454
.await
5555
.unwrap();
5656

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

6868
// test trace gossip without any expected accepts
6969
let result = target
70-
.trace_gossip(content_key, content_value.encode())
70+
.trace_put_content(content_key, content_value.encode())
7171
.await
7272
.unwrap();
7373

portal-bridge/src/bridge/beacon.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use trin_metrics::bridge::BridgeMetricsReporter;
4444
use crate::{
4545
api::consensus::ConsensusApi,
4646
constants::BEACON_GENESIS_TIME,
47-
gossip::gossip_beacon_content,
47+
put_content::put_content_beacon_content,
4848
stats::{BeaconSlotStats, StatsReporter},
4949
types::mode::BridgeMode,
5050
utils::{
@@ -127,7 +127,7 @@ impl BeaconBridge {
127127
// test files have no slot number data, so report all gossiped content at height 0.
128128
let slot_stats = Arc::new(StdMutex::new(BeaconSlotStats::new(0)));
129129
for asset in assets.0.into_iter() {
130-
gossip_beacon_content(
130+
put_content_beacon_content(
131131
self.portal_client.clone(),
132132
asset.content_key.clone(),
133133
asset.content_value().expect("Error getting content value"),
@@ -336,7 +336,7 @@ impl BeaconBridge {
336336
});
337337

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

@@ -402,7 +402,7 @@ impl BeaconBridge {
402402
);
403403

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

408408
Ok(())
@@ -426,7 +426,7 @@ impl BeaconBridge {
426426
LightClientOptimisticUpdateKey::new(update.signature_slot),
427427
);
428428
let content_value = BeaconContentValue::LightClientOptimisticUpdate(update.into());
429-
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await
429+
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await
430430
}
431431

432432
async fn serve_light_client_finality_update(
@@ -465,7 +465,7 @@ impl BeaconBridge {
465465
);
466466
let content_value = BeaconContentValue::LightClientFinalityUpdate(update.into());
467467

468-
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
468+
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
469469
*finalized_slot.lock().await = new_finalized_slot;
470470

471471
Ok(())
@@ -532,7 +532,7 @@ impl BeaconBridge {
532532
let content_value =
533533
BeaconContentValue::HistoricalSummariesWithProof(historical_summaries_with_proof);
534534

535-
gossip_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
535+
put_content_beacon_content(portal_client, content_key, content_value, slot_stats).await?;
536536
finalized_state_root.lock().await.state_root = latest_finalized_state_root;
537537
finalized_state_root.lock().await.in_progress = false;
538538

portal-bridge/src/bridge/era1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
history::{HEADER_SATURATION_DELAY, SERVE_BLOCK_TIMEOUT},
3838
utils::lookup_epoch_acc,
3939
},
40-
gossip::gossip_history_content,
40+
put_content::gossip_history_content,
4141
stats::{HistoryBlockStats, StatsReporter},
4242
types::mode::{BridgeMode, FourFoursMode},
4343
};

0 commit comments

Comments
 (0)