Skip to content

Commit

Permalink
feat: check version of catchup response (#126)
Browse files Browse the repository at this point in the history
Description
---
Check the version of catchup response on receive and drop if the
response is too old
  • Loading branch information
SWvheerden authored Oct 31, 2024
1 parent 34b8655 commit 660dafc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/server/p2p/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ impl ShareChainSyncResponse {
}
}

pub fn version(&self) -> u64 {
self.version
}

pub fn peer_id(&self) -> &PeerId {
&self.peer_id
}
Expand Down
7 changes: 5 additions & 2 deletions src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ use libp2p::{
autonat::{self, NatStatus},
dcutr,
futures::StreamExt,
gossipsub::{self, IdentTopic, Message, MessageAcceptance, MessageId, PublishError},
gossipsub::{self, IdentTopic, Message, MessageAcceptance, PublishError},
identify::{self, Info},
identity::Keypair,
kad::{self, store::MemoryStore, Event},
mdns::{self, tokio::Tokio},
memory_connection_limits,
multiaddr::Protocol,
noise,
relay,
Expand Down Expand Up @@ -867,6 +866,10 @@ where S: ShareChain
debug!(target: MESSAGE_LOGGING_LOG_TARGET, "Share chain sync response: {response:?}");
let peer = response.peer_id().clone();

if response.version() != PROTOCOL_VERSION {
trace!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} has an outdated version, skipping", peer);
return;
}
let timer = Instant::now();
// if !self.sync_in_progress.load(Ordering::SeqCst) {
// return;
Expand Down
4 changes: 2 additions & 2 deletions src/sharechain/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,15 @@ impl ShareChain for InMemoryShareChain {

// Assume their blocks are in order highest first.
let mut split_height = 0;
let mut split_found = false;
// let mut split_found = false;

if let Some(last_block_received) = last_block_received {
if let Some(level) = p2_chain_read.level_at_height(last_block_received.0) {
if let Some(block) = level.blocks.get(&last_block_received.1) {
// Only split if the block is in the main chain
if level.chain_block == block.hash {
split_height = block.height;
split_found = true;
// split_found = true;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/sharechain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub const BLOCK_TARGET_TIME: u64 = 10;
pub const MIN_RANDOMX_SCALING_FACTOR: u64 = 1;
pub const MIN_SHA3X_SCALING_FACTOR: u64 = 1;

pub const MAX_BLOCKS_PER_INITIAL_SYNC: usize = 20;

pub mod error;
pub mod in_memory;
pub mod p2block;
Expand Down

0 comments on commit 660dafc

Please sign in to comment.