Skip to content

Commit 6682a37

Browse files
committed
raptorcast: wireauth integration
1 parent eb59a07 commit 6682a37

File tree

22 files changed

+2685
-292
lines changed

22 files changed

+2685
-292
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

monad-node-config/src/network.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use serde::Deserialize;
2222
pub struct NodeNetworkConfig {
2323
pub bind_address_host: Ipv4Addr,
2424
pub bind_address_port: u16,
25+
pub authenticated_bind_address_port: Option<u16>,
2526

2627
pub max_rtt_ms: u64,
2728
pub max_mbps: u16,

monad-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ monad-updaters = { workspace = true, features = ["monad-triedb", "tokio"] }
3939
monad-validator = { workspace = true }
4040
monad-version = { workspace = true }
4141
monad-wal = { workspace = true }
42+
monad-wireauth = { workspace = true }
4243

4344
agent = { workspace = true }
4445
alloy-rlp = { workspace = true }

monad-node/src/main.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use monad_consensus_state::ConsensusConfig;
3131
use monad_consensus_types::{metrics::Metrics, validator_data::ValidatorSetDataWithEpoch};
3232
use monad_control_panel::ipc::ControlPanelIpcReceiver;
3333
use monad_crypto::certificate_signature::{
34-
CertificateKeyPair, CertificateSignaturePubKey, CertificateSignatureRecoverable, PubKey,
34+
CertificateSignaturePubKey, CertificateSignatureRecoverable, PubKey,
3535
};
3636
use monad_dataplane::DataplaneBuilder;
3737
use monad_eth_block_policy::EthBlockPolicy;
@@ -51,7 +51,7 @@ use monad_peer_discovery::{
5151
use monad_pprof::start_pprof_server;
5252
use monad_raptorcast::{
5353
config::{RaptorCastConfig, RaptorCastConfigPrimary},
54-
RAPTORCAST_SOCKET,
54+
AUTHENTICATED_RAPTORCAST_SOCKET, RAPTORCAST_SOCKET,
5555
};
5656
use monad_router_multi::MultiRouter;
5757
use monad_state::{MonadMessage, MonadStateBuilder, VerifiedMonadMessage};
@@ -507,9 +507,16 @@ fn build_raptorcast_router<ST, SCT, M, OM>(
507507
locked_epoch_validators: Vec<ValidatorSetDataWithEpoch<SCT>>,
508508
current_epoch: Epoch,
509509
current_round: Round,
510-
) -> MultiRouter<ST, M, OM, MonadEvent<ST, SCT, ExecutionProtocolType>, PeerDiscovery<ST>>
510+
) -> MultiRouter<
511+
ST,
512+
M,
513+
OM,
514+
MonadEvent<ST, SCT, ExecutionProtocolType>,
515+
PeerDiscovery<ST>,
516+
monad_raptorcast::auth::WireAuthProtocol,
517+
>
511518
where
512-
ST: CertificateSignatureRecoverable,
519+
ST: CertificateSignatureRecoverable<KeyPairType = monad_secp::KeyPair>,
513520
SCT: SignatureCollection<NodeIdPubKey = CertificateSignaturePubKey<ST>>,
514521
M: Message<NodeIdPubKey = CertificateSignaturePubKey<ST>>
515522
+ Decodable
@@ -523,6 +530,10 @@ where
523530
IpAddr::V4(node_config.network.bind_address_host),
524531
node_config.network.bind_address_port,
525532
);
533+
let authenticated_bind_address = node_config
534+
.network
535+
.authenticated_bind_address_port
536+
.map(|port| SocketAddr::new(IpAddr::V4(node_config.network.bind_address_host), port));
526537
let Some(SocketAddr::V4(name_record_address)) = resolve_domain_v4(
527538
&NodeId::new(identity.pubkey()),
528539
&peer_discovery_config.self_address,
@@ -535,6 +546,7 @@ where
535546

536547
tracing::debug!(
537548
?bind_address,
549+
?authenticated_bind_address,
538550
?name_record_address,
539551
"Monad-node starting, pid: {}",
540552
process::id()
@@ -554,18 +566,35 @@ where
554566
.with_tcp_rps_burst(
555567
network_config.tcp_rate_limit_rps,
556568
network_config.tcp_rate_limit_burst,
557-
)
558-
.extend_udp_sockets(vec![monad_dataplane::UdpSocketConfig {
559-
socket_addr: bind_address,
560-
label: RAPTORCAST_SOCKET.to_string(),
561-
}]);
569+
);
570+
571+
let mut udp_sockets = vec![monad_dataplane::UdpSocketConfig {
572+
socket_addr: bind_address,
573+
label: RAPTORCAST_SOCKET.to_string(),
574+
}];
575+
if let Some(auth_addr) = authenticated_bind_address {
576+
udp_sockets.push(monad_dataplane::UdpSocketConfig {
577+
socket_addr: auth_addr,
578+
label: AUTHENTICATED_RAPTORCAST_SOCKET.to_string(),
579+
});
580+
}
581+
dp_builder = dp_builder.extend_udp_sockets(udp_sockets);
562582

563583
let self_id = NodeId::new(identity.pubkey());
564-
let self_record = NameRecord::new(
565-
*name_record_address.ip(),
566-
name_record_address.port(),
567-
peer_discovery_config.self_record_seq_num,
568-
);
584+
let self_record = match network_config.authenticated_bind_address_port {
585+
Some(auth_port) => NameRecord::new_with_authentication(
586+
*name_record_address.ip(),
587+
name_record_address.port(),
588+
network_config.bind_address_port,
589+
auth_port,
590+
peer_discovery_config.self_record_seq_num,
591+
),
592+
None => NameRecord::new(
593+
*name_record_address.ip(),
594+
network_config.bind_address_port,
595+
peer_discovery_config.self_record_seq_num,
596+
),
597+
};
569598
let self_record = MonadNameRecord::new(self_record, &identity);
570599
assert!(
571600
self_record.signature == peer_discovery_config.self_name_record_sig,
@@ -658,10 +687,14 @@ where
658687
rng: ChaCha8Rng::from_entropy(),
659688
};
660689

690+
let shared_key = Arc::new(identity);
691+
let wireauth_config = monad_wireauth::Config::default();
692+
let auth_protocol = monad_raptorcast::auth::WireAuthProtocol::new(wireauth_config, &shared_key);
693+
661694
MultiRouter::new(
662695
self_id,
663696
RaptorCastConfig {
664-
shared_key: Arc::new(identity),
697+
shared_key,
665698
mtu: network_config.mtu,
666699
udp_message_max_age_ms: network_config.udp_message_max_age_ms,
667700
primary_instance: RaptorCastConfigPrimary {
@@ -677,6 +710,7 @@ where
677710
peer_discovery_builder,
678711
current_epoch,
679712
epoch_validators,
713+
auth_protocol,
680714
)
681715
}
682716

monad-peer-discovery/examples/sign-name-record.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ struct Args {
3030
#[arg(long)]
3131
address: SocketAddrV4,
3232

33+
#[arg(
34+
long,
35+
help = "Optional authenticated UDP port. If provided, will create name record with authenticated UDP port"
36+
)]
37+
authenticated_udp_port: Option<u16>,
38+
3339
/// Sequence number for the name record
3440
#[arg(long)]
3541
self_record_seq_num: Option<u64>,
@@ -69,12 +75,25 @@ fn main() {
6975
.unwrap_or_else(|| panic!("Either node_config or self_record_seq_num must be provided"))
7076
};
7177
let self_address = args.address;
72-
let name_record = NameRecord::new(*self_address.ip(), self_address.port(), self_record_seq_num);
78+
let name_record = if let Some(authenticated_udp_port) = args.authenticated_udp_port {
79+
NameRecord::new_with_authentication(
80+
*self_address.ip(),
81+
self_address.port(),
82+
self_address.port(),
83+
authenticated_udp_port,
84+
self_record_seq_num,
85+
)
86+
} else {
87+
NameRecord::new(*self_address.ip(), self_address.port(), self_record_seq_num)
88+
};
7389
let signed_name_record: MonadNameRecord<SecpSignature> =
7490
MonadNameRecord::new(name_record, &keypair);
7591

7692
println!("self_address = {:?}", self_address.to_string());
7793
println!("self_record_seq_num = {}", self_record_seq_num);
94+
if let Some(authenticated_udp_port) = args.authenticated_udp_port {
95+
println!("authenticated_udp_port = {}", authenticated_udp_port);
96+
}
7897
println!(
7998
"self_name_record_sig = {:?}",
8099
hex::encode(signed_name_record.signature.serialize())

monad-raptorcast/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ monad-raptor = { workspace = true }
2121
monad-secp = { workspace = true }
2222
monad-types = { workspace = true }
2323
monad-validator = { workspace = true }
24+
monad-wireauth = { workspace = true }
2425

2526
alloy-rlp = { workspace = true }
2627
bitvec = { workspace = true }
@@ -36,7 +37,8 @@ rand = { workspace = true }
3637
rand_chacha = { workspace = true }
3738
thiserror = { workspace = true }
3839
tracing = { workspace = true }
39-
tokio = { workspace = true }
40+
tokio = { workspace = true, features = ["macros"] }
41+
zerocopy = { workspace = true }
4042

4143
[dev-dependencies]
4244
monad-testutil = { workspace = true }
@@ -49,11 +51,15 @@ eyre = { workspace = true }
4951
futures-util = { workspace = true }
5052
humantime = { workspace = true }
5153
insta = { workspace = true }
54+
opentelemetry = { workspace = true }
55+
opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] }
56+
opentelemetry-otlp = { workspace = true, features = ["metrics", "grpc-tonic"] }
57+
opentelemetry-semantic-conventions = { workspace = true }
5258
rand_distr = { workspace = true }
5359
rstest = { workspace = true }
5460
serde = { workspace = true, features = ["derive"] }
5561
tikv-jemallocator = { workspace = true }
56-
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "sync"] }
62+
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "sync", "test-util"] }
5763
toml = { workspace = true }
5864
tracing-subscriber = { workspace = true, features = ["env-filter"] }
5965

0 commit comments

Comments
 (0)