Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add proximity-based update forwarding #2002

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

Draft
sanity wants to merge 5 commits into main
base: main
Choose a base branch
Loading
from feat/proximity-forwarding-v2
Draft
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
24 changes: 23 additions & 1 deletion crates/core/src/message.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use crate::{
client_events::{ClientId, HostResult},
node::PeerId,
node::{proximity_cache::ProximityCacheMessage, PeerId},
operations::{
connect::ConnectMsg, get::GetMsg, put::PutMsg, subscribe::SubscribeMsg, update::UpdateMsg,
},
Expand Down Expand Up @@ -255,6 +255,10 @@ pub(crate) enum NetMessageV1 {
},
Update(UpdateMsg),
Aborted(Transaction),
ProximityCache {
from: PeerId,
message: ProximityCacheMessage,
},
}

trait Versioned {
Expand All @@ -279,6 +283,7 @@ impl Versioned for NetMessageV1 {
NetMessageV1::Unsubscribed { .. } => semver::Version::new(1, 0, 0),
NetMessageV1::Update(_) => semver::Version::new(1, 0, 0),
NetMessageV1::Aborted(_) => semver::Version::new(1, 0, 0),
NetMessageV1::ProximityCache { .. } => semver::Version::new(1, 0, 0),
}
}
}
Expand Down Expand Up @@ -339,6 +344,11 @@ pub(crate) enum NodeEvent {
target: PeerId,
msg: Box<NetMessage>,
},
#[allow(dead_code)] // Reserved for future proximity cache broadcasting
BroadcastProximityCache {
from: PeerId,
message: crate::node::proximity_cache::ProximityCacheMessage,
},
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -418,6 +428,12 @@ impl Display for NodeEvent {
NodeEvent::SendMessage { target, msg } => {
write!(f, "SendMessage (to {target}, tx: {})", msg.id())
}
NodeEvent::BroadcastProximityCache { from, message } => {
write!(
f,
"BroadcastProximityCache (from {from}, message: {message:?})"
)
}
}
}
}
Expand Down Expand Up @@ -452,6 +468,7 @@ impl MessageStats for NetMessageV1 {
NetMessageV1::Update(op) => op.id(),
NetMessageV1::Aborted(tx) => tx,
NetMessageV1::Unsubscribed { transaction, .. } => transaction,
NetMessageV1::ProximityCache { .. } => Transaction::NULL,
}
}

Expand All @@ -464,6 +481,7 @@ impl MessageStats for NetMessageV1 {
NetMessageV1::Update(op) => op.target().as_ref().map(|b| b.borrow().clone()),
NetMessageV1::Aborted(_) => None,
NetMessageV1::Unsubscribed { .. } => None,
NetMessageV1::ProximityCache { .. } => None,
}
}

Expand All @@ -476,6 +494,7 @@ impl MessageStats for NetMessageV1 {
NetMessageV1::Update(op) => op.requested_location(),
NetMessageV1::Aborted(_) => None,
NetMessageV1::Unsubscribed { .. } => None,
NetMessageV1::ProximityCache { .. } => None,
}
}
}
Expand All @@ -495,6 +514,9 @@ impl Display for NetMessage {
Unsubscribed { key, from, .. } => {
write!(f, "Unsubscribed {{ key: {key}, from: {from} }}")?;
}
ProximityCache { from, message } => {
write!(f, "ProximityCache {{ from: {from}, message: {message:?} }}")?;
}
},
};
write!(f, "}}")
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/node/mod.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod message_processor;
mod network_bridge;
mod op_state_manager;
mod p2p_impl;
pub(crate) mod proximity_cache;
mod request_router;
pub(crate) mod testing_impl;

Expand Down
24 changes: 24 additions & 0 deletions crates/core/src/node/network_bridge/p2p_protoc.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,30 @@ impl P2pConnManager {
Err(e) => tracing::error!("Failed to send local subscribe response to result router: {}", e),
}
}
NodeEvent::BroadcastProximityCache { from, message } => {
// Broadcast ProximityCache message to all connected peers
tracing::debug!(
%from,
?message,
peer_count = ctx.connections.len(),
"Broadcasting ProximityCache message to connected peers"
);

use crate::message::{NetMessage, NetMessageV1};
let msg = NetMessage::V1(NetMessageV1::ProximityCache {
from: from.clone(),
message: message.clone(),
});

for peer in ctx.connections.keys() {
if peer != &from {
tracing::debug!(%peer, "Sending ProximityCache to peer");
if let Err(e) = ctx.bridge.send(peer, msg.clone()).await {
tracing::warn!(%peer, "Failed to send ProximityCache: {}", e);
}
}
}
}
NodeEvent::Disconnect { cause } => {
tracing::info!(
"Disconnecting from network{}",
Expand Down
10 changes: 9 additions & 1 deletion crates/core/src/node/op_state_manager.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ use crate::{
ring::{ConnectionManager, LiveTransactionTracker, Ring},
};

use super::{network_bridge::EventLoopNotificationsSender, NetEventRegister, NodeConfig};
use super::{
network_bridge::EventLoopNotificationsSender, proximity_cache::ProximityCacheManager,
NetEventRegister, NodeConfig,
};

#[cfg(debug_assertions)]
macro_rules! check_id_op {
Expand Down Expand Up @@ -77,6 +80,8 @@ pub(crate) struct OpManager {
pub peer_ready: Arc<AtomicBool>,
/// Whether this node is a gateway
pub is_gateway: bool,
/// Proximity cache manager for tracking which neighbors have which contracts
pub proximity_cache: Arc<ProximityCacheManager>,
}

impl OpManager {
Expand Down Expand Up @@ -126,6 +131,8 @@ impl OpManager {
tracing::debug!("Regular peer node: peer_ready will be set after first handshake");
}

let proximity_cache = Arc::new(ProximityCacheManager::new());

Ok(Self {
ring,
ops,
Expand All @@ -135,6 +142,7 @@ impl OpManager {
result_router_tx,
peer_ready,
is_gateway,
proximity_cache,
})
}

Expand Down
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /