Skip to content
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

Fix handshake network mismatch #145

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions anchor/network/src/handshake/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl NodeInfo {
/// Serialize `NodeInfo` to JSON bytes.
fn marshal(&self) -> Result<Vec<u8>, Error> {
let mut entries = vec![
"".to_string(), // formerly forkVersion, now deprecated
self.network_id.clone(), // network id
"".to_string(), // formerly forkVersion, now deprecated
format!("0x{}", self.network_id.clone()), // network id
];

if let Some(meta) = &self.metadata {
Expand All @@ -78,7 +78,12 @@ impl NodeInfo {
return Err(Validation("node info must have at least 2 entries".into()));
}
// skip ser.entries[0]: old forkVersion
let network_id = ser.entries[1].clone();
let network_id = ser.entries[1]
.clone()
.strip_prefix("0x")
.ok_or_else(|| Validation("network id must be prefixed with 0x".into()))?
.to_string();

let metadata = if ser.entries.len() >= 3 {
let meta = serde_json::from_slice(ser.entries[2].as_bytes())?;
Some(meta)
Expand Down
Loading