Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ serde_derive = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true, features = ["macros"] }
solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] }
solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] }
solana-pubkey = { workspace = true, features = ["serde"] }

[dev-dependencies]
solana-address = { workspace = true, features = ["atomic"] }
solana-packet = { path = ".", features = ["dev-context-only-utils"] }
static_assertions = { workspace = true }

Expand Down
29 changes: 29 additions & 0 deletions packet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
};
use {
bitflags::bitflags,
solana_pubkey::Pubkey,
std::{
fmt,
net::{IpAddr, Ipv4Addr, SocketAddr},
Expand Down Expand Up @@ -72,6 +73,7 @@ pub struct Meta {
pub addr: IpAddr,
pub port: u16,
pub flags: PacketFlags,
remote_pubkey: Pubkey,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagging that this is technically a breaking change for anyone who builds a Meta without using Default in some way, ie:

let m = Meta { size, addr, port, flags };

It's not a problem, but probably requires a breaking release

Copy link
Contributor Author

@lijunwangs lijunwangs Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they can still use struct Meta, by putting the new flag with default
Met {
size,
add,
port,
flags,
..Meta::default()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but that does still constitute a breaking change since old code will no longer compile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, whenever we introduce a field it will break as we lack a constructor.

}

#[cfg(feature = "frozen-abi")]
Expand Down Expand Up @@ -300,6 +302,20 @@ impl Meta {
pub fn is_from_staked_node(&self) -> bool {
self.flags.contains(PacketFlags::FROM_STAKED_NODE)
}

#[inline]
pub fn remote_pubkey(&self) -> Option<Pubkey> {
if self.remote_pubkey == Pubkey::default() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such cases it may be preferable to explicitly compare with array of zeros rather than relying on the Default impl staying stable. Unlikely to be a problem for us of course.

None
} else {
Some(self.remote_pubkey)
}
}

#[inline]
pub fn set_remote_pubkey(&mut self, pubkey: Pubkey) {
self.remote_pubkey = pubkey;
}
}

impl Default for Meta {
Expand All @@ -309,6 +325,7 @@ impl Default for Meta {
addr: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
port: 0,
flags: PacketFlags::empty(),
remote_pubkey: Pubkey::default(),
}
}
}
Expand Down Expand Up @@ -355,4 +372,16 @@ mod tests {
Err("the size limit has been reached".to_string()),
);
}

#[test]
fn test_remote_pubkey() {
let mut meta = Meta::default();
assert!(meta.remote_pubkey().is_none());
let pubkey = Pubkey::new_unique();
meta.set_remote_pubkey(pubkey);
assert_eq!(meta.remote_pubkey(), Some(pubkey));
let pubkey = Pubkey::default();
meta.set_remote_pubkey(pubkey);
assert!(meta.remote_pubkey().is_none());
}
}