Skip to content

feat: implement cmd/relay#224

Merged
emlautarom1 merged 35 commits into
mainfrom
emlautarom1/cmd-relay
Feb 27, 2026
Merged

feat: implement cmd/relay#224
emlautarom1 merged 35 commits into
mainfrom
emlautarom1/cmd-relay

Conversation

@emlautarom1
Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 commented Feb 13, 2026

Closes #182


There is an ignored test due to a missing feature in the Relay (/metrics endpoint). We'll revisit this later when we pick up this feature again.

@emlautarom1 emlautarom1 marked this pull request as ready for review February 20, 2026 02:03
Copilot AI review requested due to automatic review settings February 20, 2026 02:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the cmd/relay functionality by porting the relay command from the reference Go implementation. The relay server enables libp2p circuit relay functionality that allows Charon clients to discover and connect to their peers.

Changes:

  • Adds new relay command to CLI with comprehensive configuration options for P2P, logging, and monitoring
  • Implements relay server with QUIC support in addition to TCP
  • Adds graceful shutdown handling via Ctrl+C signal
  • Includes comprehensive test suite (one test ignored pending /metrics endpoint implementation)

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/relay-server/src/p2p.rs Updates to use new multiaddr methods from P2P config for TCP/UDP listening
crates/relay-server/src/error.rs Adds P2PConfigError variant for improved error handling
crates/relay-server/src/config.rs Changes data_dir from Option to PathBuf with default value ".charon"
crates/p2p/src/p2p.rs Adds QUIC support to relay server and removes unnecessary keypair clone
crates/cli/src/main.rs Implements top-level Ctrl+C handling and adds relay command route
crates/cli/src/error.rs Changes CliError visibility to public and adds error variants
crates/cli/src/commands/relay.rs New 558-line implementation of relay command with args, config conversion, and tests
crates/cli/src/commands/mod.rs Exports new relay module
crates/cli/src/cli.rs Adds Relay command variant to CLI structure
crates/cli/Cargo.toml Adds relay-server, tracing, libp2p, and backon dependencies
Cargo.toml Removes unused eth2_keystore optimization
Cargo.lock Updates dependencies including alloy, futures, and other transitive deps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/commands/relay.rs
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
Copy link
Copy Markdown
Collaborator

@varex83 varex83 left a comment

Choose a reason for hiding this comment

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

Small non-blocking comments, everything else looks great! LGTM!

Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/cli/src/commands/relay.rs Outdated
@varex83
Copy link
Copy Markdown
Collaborator

varex83 commented Feb 25, 2026

Also one note - while testing it locally I had to run cargo update to fix the dependecy problems with alloy

Comment thread crates/cli/src/commands/relay.rs Outdated
Comment thread crates/relay-server/src/p2p.rs
Comment thread crates/cli/src/commands/relay.rs Outdated
@emlautarom1
Copy link
Copy Markdown
Collaborator Author

Also one note - while testing it locally I had to run cargo update to fix the dependecy problems with alloy

What problem did you find? CI did not show any issues on either platform.

@varex83
Copy link
Copy Markdown
Collaborator

varex83 commented Feb 26, 2026

What problem did you find? CI did not show any issues on either platform.

It was related that the latest alloy version is not supported by the rust version we use (1.89) and it required something like 1.91/1.92

Comment thread crates/p2p/src/config.rs
Comment on lines -184 to -187
// Go version checks if IP is nil (unspecified)
if socket_addr.ip().is_unspecified() {
return Err(P2PConfigError::UnspecifiedIP("TCP".to_string()));
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This check was incorrect:

Go considers :1234 a valid TCP address with a nil IP, thus it was rejected with an error: https://github.com/ObolNetwork/charon/blob/749d2d7ab0b8ace34f2e686a5af5910c8adb4dc0/p2p/config.go#L103-L114

In Rust this string results in a parse error. Our check for is_unspecified() then was incorrect since it would reject 0.0.0.0 as address while the Go code does not.

To verify, I've ran the following test in Go and added its equivalent in Rust:

func TestResolveListenAddrAllInterfaces(t *testing.T) {
	c := Config{
		TCPAddrs: []string{
			"0.0.0.0:0",
		},
		UDPAddrs: []string{
			"0.0.0.0:0",
		},
	}
	_, err := c.TCPMultiaddrs()
	require.NoError(t, err)

	_, err = c.UDPMultiaddrs()
	require.NoError(t, err)
}

@emlautarom1 emlautarom1 merged commit 63d5abe into main Feb 27, 2026
6 checks passed
@emlautarom1 emlautarom1 deleted the emlautarom1/cmd-relay branch February 27, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement cmd/relay

4 participants