Skip to content

Commit

Permalink
Harden block handler (Versioning)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Jun 30, 2023
1 parent cb41742 commit f02d2d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions massa-protocol-exports/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ pub enum ProtocolError {
InvalidOperationError(String),
/// Listener error: {0}
ListenerError(String),
/// Incompatible newtork version: local current is {local} received is {received}
/// Incompatible network version: local current is {local} received is {received}
IncompatibleNetworkVersion {
/// local current version
local: u32,
/// received version from incoming header
/// received current network version from incoming header
received: u32,
},
/// Invalid announced network version
InvalidAnnouncedNetworkVersion {
/// local current version
local: u32,
/// received announced network version
announced_received: u32,
},
/// Versioned factory error: {0}
FactoryError(#[from] FactoryError),
/// PoS error: {0}
Expand Down
17 changes: 17 additions & 0 deletions massa-protocol-worker/src/handlers/block_handler/retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ impl RetrievalThread {
received: header.content.current_version,
})
} else {
// announced version == 0 -> No announce
if header.content.announced_version != 0 {
if header.content.announced_version <= version {
// Received block, announced an old version (already accepted)
return Err(ProtocolError::InvalidAnnouncedNetworkVersion {
local: version,
announced_received: header.content.announced_version,
});
}

let version_to_announce = self.mip_store.get_network_version_to_announce();
if header.content.announced_version != version_to_announce {
warn!("Please update your node if you want to support this update (network version: {})",
header.content.announced_version);
}
}

Ok(())
}
}
Expand Down

0 comments on commit f02d2d2

Please sign in to comment.