Skip to content

Commit 57ada36

Browse files
authored
feat: add affected_by_radius to content key (#1839)
1 parent 44a974d commit 57ada36

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

crates/ethportal-api/src/types/content_key/beacon.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ impl fmt::Display for BeaconContentKey {
113113
}
114114

115115
impl OverlayContentKey for BeaconContentKey {
116+
fn affected_by_radius(&self) -> bool {
117+
false
118+
}
119+
116120
fn to_bytes(&self) -> RawContentKey {
117121
let mut bytes;
118122

crates/ethportal-api/src/types/content_key/history.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ impl fmt::Display for HistoryContentKey {
216216
}
217217

218218
impl OverlayContentKey for HistoryContentKey {
219+
fn affected_by_radius(&self) -> bool {
220+
match self {
221+
Self::BlockHeaderByHash(_) => true,
222+
Self::BlockHeaderByNumber(_) => true,
223+
Self::BlockBody(_) => true,
224+
Self::BlockReceipts(_) => true,
225+
Self::EphemeralHeadersFindContent(_) => false,
226+
Self::EphemeralHeaderOffer(_) => false,
227+
}
228+
}
229+
219230
fn to_bytes(&self) -> RawContentKey {
220231
let mut bytes;
221232

crates/ethportal-api/src/types/content_key/overlay.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ pub trait OverlayContentKey:
2121
Sha256::digest(self.to_bytes()).into()
2222
}
2323

24+
/// Returns whether this content key is affected by radius.
25+
///
26+
/// Most of the content is supposted to be stored if it falls within node's radius, but some
27+
/// content is not dependant on the radius and uses different logic instead.
28+
fn affected_by_radius(&self) -> bool;
29+
2430
/// Returns the bytes of the content key.
2531
///
2632
/// The [RawContentKey] is better suited than `Vec<u8>` for representing content key bytes.
@@ -96,6 +102,10 @@ impl Deref for IdentityContentKey {
96102
}
97103

98104
impl OverlayContentKey for IdentityContentKey {
105+
fn affected_by_radius(&self) -> bool {
106+
true
107+
}
108+
99109
fn content_id(&self) -> [u8; 32] {
100110
self.value
101111
}

crates/ethportal-api/src/types/content_key/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ pub struct ContractBytecodeKey {
6565
}
6666

6767
impl OverlayContentKey for StateContentKey {
68+
fn affected_by_radius(&self) -> bool {
69+
true
70+
}
71+
6872
fn to_bytes(&self) -> RawContentKey {
6973
let mut bytes;
7074

0 commit comments

Comments
 (0)