Skip to content

Commit 7bec116

Browse files
authored
feat: add CLI options for BeaconNodeFallback configuration (#753)
Closes #248 - Add `--broadcast` flag to configure which API topics are sent to all beacon nodes - Add `--beacon-nodes-sync-tolerances` flag to configure sync distance thresholds Co-Authored-By: Soham Zemse <22412996+zemse@users.noreply.github.com>
1 parent 4ce4739 commit 7bec116

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

anchor/client/src/cli.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
path::PathBuf,
55
};
66

7+
use beacon_node_fallback::ApiTopic;
78
use clap::{
89
Parser,
910
builder::{ArgAction, ArgPredicate},
@@ -80,6 +81,38 @@ pub struct Node {
8081
)]
8182
pub beacon_nodes_tls_certs: Option<Vec<PathBuf>>,
8283

84+
#[clap(
85+
long,
86+
value_name = "API_TOPICS",
87+
value_delimiter = ',',
88+
help = "Comma-separated list of beacon API topics to broadcast to all beacon nodes. \
89+
Possible values are: none, attestations, blocks, subscriptions, sync-committee. \
90+
Default (when flag is omitted) is to broadcast subscriptions only.",
91+
display_order = 0
92+
)]
93+
pub broadcast: Option<Vec<ApiTopic>>,
94+
95+
#[clap(
96+
long,
97+
value_name = "SYNC_TOLERANCES",
98+
value_delimiter = ',',
99+
default_value = "8,8,48",
100+
help = "A comma-separated list of 3 values which sets the size of each sync distance range when \
101+
determining the health of each connected beacon node. \
102+
The first value determines the `Synced` range. If a connected beacon node is synced to within \
103+
this number of slots it is considered 'Synced'. \
104+
The second value determines the `Small` sync distance range. This range starts immediately after \
105+
the `Synced` range. \
106+
The third value determines the `Medium` sync distance range. This range starts immediately after \
107+
the `Small` range. \
108+
Any sync distance larger than the `Medium` range is considered `Large`. \
109+
For example, a value of '8,8,48' would mean: \
110+
Synced: 0..=8, Small: 9..=16, Medium: 17..=64, Large: 65..",
111+
display_order = 0,
112+
help_heading = FLAG_HEADER
113+
)]
114+
pub beacon_nodes_sync_tolerances: Vec<u64>,
115+
83116
#[clap(
84117
long,
85118
value_name = "CERTIFICATE-FILES",

anchor/client/src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::{net::IpAddr, path::PathBuf};
55

6+
use beacon_node_fallback::{ApiTopic, beacon_node_health::BeaconNodeSyncDistanceTiers};
67
use global_config::GlobalConfig;
78
use multiaddr::{Multiaddr, Protocol};
89
use network::{DEFAULT_DISC_PORT, DEFAULT_TCP_PORT, ListenAddr, ListenAddress};
@@ -56,6 +57,10 @@ pub struct Config {
5657
/// A list of custom certificates that the validator client will additionally use when
5758
/// connecting to an execution node over SSL/TLS.
5859
pub execution_nodes_tls_certs: Option<Vec<PathBuf>>,
60+
/// Configuration for beacon node fallback (sync tolerances).
61+
pub beacon_node_fallback: beacon_node_fallback::Config,
62+
/// Topics to broadcast to all beacon nodes.
63+
pub broadcast_topics: Vec<ApiTopic>,
5964
/// Configuration for the processor
6065
pub processor: processor::Config,
6166
/// If slashing protection is disabled
@@ -113,6 +118,8 @@ impl Config {
113118
network: network_config,
114119
beacon_nodes_tls_certs: None,
115120
execution_nodes_tls_certs: None,
121+
beacon_node_fallback: <_>::default(),
122+
broadcast_topics: vec![ApiTopic::Subscriptions],
116123
processor: <_>::default(),
117124
disable_slashing_protection: false,
118125
impostor: None,
@@ -201,6 +208,15 @@ pub fn from_cli(cli_args: &Node, global_config: GlobalConfig) -> Result<Config,
201208
config.beacon_nodes_tls_certs = cli_args.beacon_nodes_tls_certs.clone();
202209
config.execution_nodes_tls_certs = cli_args.execution_nodes_tls_certs.clone();
203210

211+
// Beacon node fallback configuration
212+
config.beacon_node_fallback.sync_tolerances =
213+
BeaconNodeSyncDistanceTiers::from_vec(&cli_args.beacon_nodes_sync_tolerances)?;
214+
215+
if let Some(mut broadcast_topics) = cli_args.broadcast.clone() {
216+
broadcast_topics.retain(|topic| *topic != ApiTopic::None);
217+
config.broadcast_topics = broadcast_topics;
218+
}
219+
204220
// MEV options
205221
config.builder_proposals = cli_args.builder_proposals;
206222
config.builder_boost_factor = cli_args.builder_boost_factor;

anchor/client/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use anchor_validator_store::{
1818
registration_service::RegistrationService,
1919
};
2020
use beacon_node_fallback::{
21-
ApiTopic, BeaconNodeFallback, CandidateBeaconNode, start_fallback_updater_service,
21+
BeaconNodeFallback, CandidateBeaconNode, start_fallback_updater_service,
2222
};
2323
pub use cli::Node;
2424
use config::Config;
@@ -318,19 +318,17 @@ impl Client {
318318
// Initialize the number of connected, available beacon nodes to 0.
319319
set_gauge(&validator_metrics::AVAILABLE_BEACON_NODES_COUNT, 0);
320320

321-
// TODO: make beacon_node_fallback::Config and broadcast_topics configurable
322-
// https://github.com/sigp/anchor/issues/248
323321
let mut beacon_nodes: BeaconNodeFallback<_> = BeaconNodeFallback::new(
324322
candidates,
325-
beacon_node_fallback::Config::default(),
326-
vec![ApiTopic::Subscriptions],
323+
config.beacon_node_fallback,
324+
config.broadcast_topics.clone(),
327325
spec.clone(),
328326
);
329327

330328
let mut proposer_nodes: BeaconNodeFallback<_> = BeaconNodeFallback::new(
331329
proposer_candidates,
332-
beacon_node_fallback::Config::default(),
333-
vec![ApiTopic::Subscriptions],
330+
config.beacon_node_fallback,
331+
config.broadcast_topics.clone(),
334332
spec.clone(),
335333
);
336334

0 commit comments

Comments
 (0)