Skip to content

Commit adfa490

Browse files
authored
feat: subnetwork stores should use affected_by_radius (#1840)
1 parent 57ada36 commit adfa490

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

crates/storage/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ impl<TMetric: Metric> ContentStore for MemoryContentStore<TMetric> {
126126
&self,
127127
key: &Self::Key,
128128
) -> Result<ShouldWeStoreContent, ContentStoreError> {
129-
let distance = self.distance_to_key(key);
130-
if distance > self.radius {
129+
if key.affected_by_radius() && self.distance_to_key(key) > self.radius {
131130
return Ok(ShouldWeStoreContent::NotWithinRadius);
132131
}
133132
if self.contains_key(key) {

crates/storage/src/versioned/id_indexed_v1/store.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ pub struct PaginateResult<TContentKey> {
3838
/// Different SQL table is created for each `ContentType`, with content-id as a primary key.
3939
/// It has a configurable capacity and it will prune data that is farthest from the `NodeId` once
4040
/// it uses more than storage capacity.
41+
///
42+
/// Only content that is affected by radius should be stored in this store, otherwise it might be
43+
/// removed as the radius shrinks because of the pruning.
4144
#[derive(Debug)]
4245
pub struct IdIndexedV1Store<TContentKey: OverlayContentKey, TMetric: Metric> {
4346
/// The configuration.

crates/subnetworks/history/src/storage.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ impl ContentStore for HistoryStorage {
3939
key: &HistoryContentKey,
4040
) -> Result<ShouldWeStoreContent, ContentStoreError> {
4141
let content_id = ContentId::from(key.content_id());
42-
if self.store.distance_to_content_id(&content_id) > self.store.radius() {
42+
if key.affected_by_radius()
43+
&& self.store.distance_to_content_id(&content_id) > self.store.radius()
44+
{
4345
Ok(ShouldWeStoreContent::NotWithinRadius)
4446
} else if self.store.has_content(&content_id)? {
4547
Ok(ShouldWeStoreContent::AlreadyStored)

crates/subnetworks/state/src/storage.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ impl ContentStore for StateStorage {
5454
key: &StateContentKey,
5555
) -> Result<ShouldWeStoreContent, ContentStoreError> {
5656
let content_id = ContentId::from(key.content_id());
57-
if self.store.distance_to_content_id(&content_id) > self.store.radius() {
57+
if key.affected_by_radius()
58+
&& self.store.distance_to_content_id(&content_id) > self.store.radius()
59+
{
5860
Ok(ShouldWeStoreContent::NotWithinRadius)
5961
} else if self.store.has_content(&content_id)? {
6062
Ok(ShouldWeStoreContent::AlreadyStored)

0 commit comments

Comments
 (0)