Skip to content
Merged
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
1 change: 1 addition & 0 deletions bin/ethlambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ async fn run_node(options: Options) -> eyre::Result<()> {
// the loop has stopped asking for.
target_peers: common.discovery.target_peers,
wire: setup.wire,
agent_version: version::CLIENT_VERSION,
})
.wrap_err("failed to build swarm")?;

Expand Down
1 change: 1 addition & 0 deletions crates/net/p2p/src/beacon/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ mod tests {
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
bootnodes: mainnet_bootnodes,
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: crate::WireConfig::Beacon(Box::new(BeaconWireConfig {
fork_digest: [0x8c, 0x9f, 0x62, 0xfe],
fork: ForkName::Fulu,
Expand Down
66 changes: 66 additions & 0 deletions crates/net/p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ pub struct SwarmConfig {
/// the connection limits, and so decides the [`Wire`] the built swarm
/// carries.
pub wire: WireConfig,
/// The identify `agentVersion`, which crawlers read to name a peer's
/// client. Left unset, rust-libp2p reports its own crate version instead.
pub agent_version: &'static str,
}

/// The half of [`SwarmConfig`] the two networks disagree about.
Expand Down Expand Up @@ -788,6 +791,7 @@ pub fn build_swarm(config: SwarmConfig) -> Result<BuiltSwarm, SwarmBuildError> {
listening_socket,
target_peers,
wire,
agent_version,
} = config;

// The codec comes out of this match too, not from `Default`: the two beacon
Expand Down Expand Up @@ -829,6 +833,7 @@ pub fn build_swarm(config: SwarmConfig) -> Result<BuiltSwarm, SwarmBuildError> {
// peer reports into the address book, loopback included, and `req_resp` dials those.
let identify = libp2p::identify::Behaviour::new(
libp2p::identify::Config::new(identify_version.to_owned(), identity.public())
.with_agent_version(agent_version.to_owned())
.with_cache_size(0),
);

Expand Down Expand Up @@ -2446,6 +2451,7 @@ pub(crate) mod test_support {
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Beacon(Box::new(BeaconWireConfig {
fork_digest: [0u8; 4],
fork: config.fork_at_epoch(0),
Expand Down Expand Up @@ -2718,6 +2724,7 @@ mod tests {
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Lean(LeanWireConfig {
validator_ids: Vec::new(),
attestation_committee_count: 1,
Expand Down Expand Up @@ -2773,6 +2780,62 @@ mod tests {
.expect("both swarms must connect over TCP within the timeout");
}

/// The identify reply carries `SwarmConfig::agent_version`, not
/// rust-libp2p's default `rust-libp2p/<version>`.
#[tokio::test]
async fn identify_reports_the_configured_agent_version() {
fn build(node_key_byte: u8) -> BuiltSwarm {
build_swarm(SwarmConfig {
node_key: vec![node_key_byte; 32],
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Lean(LeanWireConfig {
validator_ids: Vec::new(),
attestation_committee_count: 1,
subscription_subnets: HashSet::new(),
milliseconds_per_slot: DEFAULT_MILLISECONDS_PER_SLOT,
}),
})
.expect("swarm builds")
}

let mut dialer = build(1);
let mut listener = build(2);

let listener_addr = loop {
if let SwarmEvent::NewListenAddr { address, .. } =
listener.swarm.select_next_some().await
{
break address
.with_p2p(listener.local_peer_id)
.expect("failed to add peer ID to multiaddr");
}
};
dialer.swarm.dial(listener_addr).expect("dial is accepted");

let received = async {
loop {
tokio::select! {
event = dialer.swarm.select_next_some() => {
if let SwarmEvent::Behaviour(BehaviourEvent::Identify(
libp2p::identify::Event::Received { info, .. },
)) = event
{
return info.agent_version;
}
}
_ = listener.swarm.select_next_some() => {}
}
}
};
let agent_version = tokio::time::timeout(Duration::from_secs(10), received)
.await
.expect("identify must complete within the timeout");
assert_eq!(agent_version, "ethlambda/test");
}

#[test]
fn gossip_is_held_for_a_verdict_only_when_asked() {
let ttl = Duration::from_secs(1);
Expand Down Expand Up @@ -2837,6 +2900,7 @@ mod tests {
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Beacon(Box::new(beacon::swarm::BeaconWireConfig {
fork_digest: [0x11, 0x22, 0x33, 0x44],
fork: ForkName::Fulu,
Expand Down Expand Up @@ -3125,6 +3189,7 @@ mod tests {
bootnodes,
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Lean(LeanWireConfig {
validator_ids: Vec::new(),
attestation_committee_count: 1,
Expand Down Expand Up @@ -3574,6 +3639,7 @@ mod tests {
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: WireConfig::Beacon(Box::new(beacon::swarm::BeaconWireConfig {
fork_digest: [0x11, 0x22, 0x33, 0x44],
fork: ForkName::Fulu,
Expand Down
1 change: 1 addition & 0 deletions crates/net/p2p/src/req_resp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,7 @@ mod tests {
bootnodes: Vec::new(),
listening_socket: "127.0.0.1:0".parse().expect("valid socket"),
target_peers: crate::discovery::DEFAULT_DISCOVERY_TARGET_PEERS,
agent_version: "ethlambda/test",
wire: crate::WireConfig::Lean(crate::LeanWireConfig {
validator_ids: Vec::new(),
attestation_committee_count: 1,
Expand Down
Loading