Skip to content

Commit 311a25a

Browse files
committed
squash
1 parent 6c90d56 commit 311a25a

File tree

6 files changed

+93
-22
lines changed

6 files changed

+93
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ tokio-util = "0.7"
675675
toml = "0.8.12"
676676
tonic = "0.9.2"
677677
tonic-build = "0.9.2"
678+
tower = "0.4.13"
678679
trees = "0.4.2"
679680
tungstenite = "0.20.1"
680681
uriparse = "0.6.4"

core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dashmap = { workspace = true, features = ["rayon", "raw-api"] }
2828
etcd-client = { workspace = true, features = ["tls"] }
2929
futures = { workspace = true }
3030
histogram = { workspace = true }
31+
hyper = { workspace = true }
3132
itertools = { workspace = true }
3233
jito-protos = { workspace = true }
3334
jito-tip-distribution = { workspace = true }
@@ -110,6 +111,7 @@ tempfile = { workspace = true }
110111
thiserror = { workspace = true }
111112
tokio = { workspace = true, features = ["full"] }
112113
tonic = { workspace = true }
114+
tower = { workspace = true }
113115
trees = { workspace = true }
114116

115117
[dev-dependencies]

core/src/proxy/block_engine_stage.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use {
2727
pubkey::Pubkey, saturating_add_assign, signature::Signer, signer::keypair::Keypair,
2828
},
2929
std::{
30+
net::{IpAddr, Ipv4Addr},
3031
str::FromStr,
3132
sync::{
3233
atomic::{AtomicBool, Ordering},
@@ -74,13 +75,27 @@ pub struct BlockBuilderFeeInfo {
7475
pub block_builder_commission: u64,
7576
}
7677

77-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
78+
#[derive(Clone, Debug, PartialEq, Eq)]
7879
pub struct BlockEngineConfig {
7980
/// Block Engine URL
8081
pub block_engine_url: String,
8182

8283
/// If set then it will be assumed the backend verified packets so signature verification will be bypassed in the validator.
8384
pub trust_packets: bool,
85+
86+
/// Address of local interface to bind socket. Set from cli arg in solana-validator.
87+
/// Needed for e.g. connecting over double zero.
88+
pub bind_address: IpAddr,
89+
}
90+
91+
impl Default for BlockEngineConfig {
92+
fn default() -> Self {
93+
Self {
94+
block_engine_url: String::default(),
95+
trust_packets: bool::default(),
96+
bind_address: IpAddr::from(Ipv4Addr::UNSPECIFIED),
97+
}
98+
}
8499
}
85100

86101
pub struct BlockEngineStage {
@@ -228,14 +243,24 @@ impl BlockEngineStage {
228243
})?;
229244
}
230245

246+
// Create connector for block-engine connection to respect cli bind-addr.
247+
let local_ip: IpAddr = local_block_engine_config.bind_address;
248+
let mut http = hyper::client::connect::HttpConnector::new();
249+
http.enforce_http(false);
250+
http.set_local_address(Some(local_ip));
251+
231252
debug!(
232253
"connecting to auth: {}",
233254
local_block_engine_config.block_engine_url
234255
);
235-
let auth_channel = timeout(*connection_timeout, backend_endpoint.connect())
236-
.await
237-
.map_err(|_| ProxyError::AuthenticationConnectionTimeout)?
238-
.map_err(|e| ProxyError::AuthenticationConnectionError(e.to_string()))?;
256+
257+
let auth_channel = timeout(
258+
*connection_timeout,
259+
backend_endpoint.connect_with_connector(http.clone()),
260+
)
261+
.await
262+
.map_err(|_| ProxyError::AuthenticationConnectionTimeout)?
263+
.map_err(|e| ProxyError::AuthenticationConnectionError(e.to_string()))?;
239264

240265
let mut auth_client = AuthServiceClient::new(auth_channel);
241266

@@ -257,10 +282,14 @@ impl BlockEngineStage {
257282
"connecting to block engine: {}",
258283
local_block_engine_config.block_engine_url
259284
);
260-
let block_engine_channel = timeout(*connection_timeout, backend_endpoint.connect())
261-
.await
262-
.map_err(|_| ProxyError::BlockEngineConnectionTimeout)?
263-
.map_err(|e| ProxyError::BlockEngineConnectionError(e.to_string()))?;
285+
286+
let block_engine_channel = timeout(
287+
*connection_timeout,
288+
backend_endpoint.connect_with_connector(http),
289+
)
290+
.await
291+
.map_err(|_| ProxyError::BlockEngineConnectionTimeout)?
292+
.map_err(|e| ProxyError::BlockEngineConnectionError(e.to_string()))?;
264293

265294
let access_token = Arc::new(Mutex::new(access_token));
266295
let block_engine_client = BlockEngineValidatorClient::with_interceptor(

core/src/proxy/relayer_stage.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl RelayerStageStats {
7070
}
7171
}
7272

73-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
73+
#[derive(Clone, Debug, PartialEq, Eq)]
7474
pub struct RelayerConfig {
7575
/// Relayer URL
7676
pub relayer_url: String,
@@ -83,6 +83,22 @@ pub struct RelayerConfig {
8383

8484
/// If set then it will be assumed the backend verified packets so signature verification will be bypassed in the validator.
8585
pub trust_packets: bool,
86+
87+
/// Address of local interface to bind socket. Set from cli arg in solana-validator.
88+
/// Needed for e.g. connecting over double zero.
89+
pub bind_address: IpAddr,
90+
}
91+
92+
impl Default for RelayerConfig {
93+
fn default() -> Self {
94+
Self {
95+
relayer_url: String::default(),
96+
expected_heartbeat_interval: Duration::default(),
97+
oldest_allowed_heartbeat: Duration::default(),
98+
trust_packets: bool::default(),
99+
bind_address: IpAddr::from(Ipv4Addr::UNSPECIFIED),
100+
}
101+
}
86102
}
87103

88104
pub struct RelayerStage {
@@ -221,11 +237,21 @@ impl RelayerStage {
221237
})?;
222238
}
223239

240+
// Create connector for relayer connection to respect cli bind-addr.
241+
let local_ip: IpAddr = local_relayer_config.bind_address;
242+
let mut http = hyper::client::connect::HttpConnector::new();
243+
http.enforce_http(false);
244+
http.set_local_address(Some(local_ip));
245+
224246
debug!("connecting to auth: {}", local_relayer_config.relayer_url);
225-
let auth_channel = timeout(*connection_timeout, backend_endpoint.connect())
226-
.await
227-
.map_err(|_| ProxyError::AuthenticationConnectionTimeout)?
228-
.map_err(|e| ProxyError::AuthenticationConnectionError(e.to_string()))?;
247+
248+
let auth_channel = timeout(
249+
*connection_timeout,
250+
backend_endpoint.connect_with_connector(http.clone()),
251+
)
252+
.await
253+
.map_err(|_| ProxyError::AuthenticationConnectionTimeout)?
254+
.map_err(|e| ProxyError::AuthenticationConnectionError(e.to_string()))?;
229255

230256
let mut auth_client = AuthServiceClient::new(auth_channel);
231257

@@ -247,10 +273,14 @@ impl RelayerStage {
247273
"connecting to relayer: {}",
248274
local_relayer_config.relayer_url
249275
);
250-
let relayer_channel = timeout(*connection_timeout, backend_endpoint.connect())
251-
.await
252-
.map_err(|_| ProxyError::RelayerConnectionTimeout)?
253-
.map_err(|e| ProxyError::RelayerConnectionError(e.to_string()))?;
276+
277+
let relayer_channel = timeout(
278+
*connection_timeout,
279+
backend_endpoint.connect_with_connector(http),
280+
)
281+
.await
282+
.map_err(|_| ProxyError::RelayerConnectionTimeout)?
283+
.map_err(|e| ProxyError::RelayerConnectionError(e.to_string()))?;
254284

255285
let access_token = Arc::new(Mutex::new(access_token));
256286
let relayer_client = RelayerClient::with_interceptor(

validator/src/admin_rpc_service.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use {
3232
collections::{HashMap, HashSet},
3333
env, error,
3434
fmt::{self, Display},
35-
net::SocketAddr,
35+
net::{IpAddr, SocketAddr},
3636
path::{Path, PathBuf},
3737
str::FromStr,
3838
sync::{Arc, RwLock},
@@ -255,6 +255,7 @@ pub trait AdminRpc {
255255
meta: Self::Metadata,
256256
block_engine_url: String,
257257
trust_packets: bool,
258+
bind_address: IpAddr,
258259
) -> Result<()>;
259260

260261
#[rpc(meta, name = "setRelayerConfig")]
@@ -265,6 +266,7 @@ pub trait AdminRpc {
265266
trust_packets: bool,
266267
expected_heartbeat_interval_ms: u64,
267268
max_failed_heartbeats: u64,
269+
bind_address: IpAddr,
268270
) -> Result<()>;
269271

270272
#[rpc(meta, name = "setShredReceiverAddress")]
@@ -484,11 +486,13 @@ impl AdminRpc for AdminRpcImpl {
484486
meta: Self::Metadata,
485487
block_engine_url: String,
486488
trust_packets: bool,
489+
bind_address: IpAddr,
487490
) -> Result<()> {
488491
debug!("set_block_engine_config request received");
489492
let config = BlockEngineConfig {
490493
block_engine_url,
491494
trust_packets,
495+
bind_address,
492496
};
493497
// Detailed log messages are printed inside validate function
494498
if BlockEngineStage::is_valid_block_engine_config(&config) {
@@ -544,6 +548,7 @@ impl AdminRpc for AdminRpcImpl {
544548
trust_packets: bool,
545549
expected_heartbeat_interval_ms: u64,
546550
max_failed_heartbeats: u64,
551+
bind_address: IpAddr,
547552
) -> Result<()> {
548553
debug!("set_relayer_config request received");
549554
let expected_heartbeat_interval = Duration::from_millis(expected_heartbeat_interval_ms);
@@ -554,6 +559,7 @@ impl AdminRpc for AdminRpcImpl {
554559
expected_heartbeat_interval,
555560
oldest_allowed_heartbeat,
556561
trust_packets,
562+
bind_address,
557563
};
558564
// Detailed log messages are printed inside validate function
559565
if RelayerStage::is_valid_relayer_config(&config) {

validator/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ pub fn main() {
466466

467467
let socket_addr_space = SocketAddrSpace::new(matches.is_present("allow_private_addr"));
468468
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
469+
let bind_address = solana_net_utils::parse_host(matches.value_of("bind_address").unwrap())
470+
.expect("invalid bind_address");
469471

470472
let operation = match matches.subcommand() {
471473
("", _) | ("run", _) => Operation::Run,
@@ -477,7 +479,7 @@ pub fn main() {
477479
.block_on(async move {
478480
admin_client
479481
.await?
480-
.set_block_engine_config(block_engine_url, trust_packets)
482+
.set_block_engine_config(block_engine_url, trust_packets, bind_address)
481483
.await
482484
})
483485
.unwrap_or_else(|err| {
@@ -503,6 +505,7 @@ pub fn main() {
503505
trust_packets,
504506
expected_heartbeat_interval_ms,
505507
max_failed_heartbeats,
508+
bind_address,
506509
)
507510
.await
508511
})
@@ -1274,8 +1277,6 @@ pub fn main() {
12741277
"--gossip-validator",
12751278
);
12761279

1277-
let bind_address = solana_net_utils::parse_host(matches.value_of("bind_address").unwrap())
1278-
.expect("invalid bind_address");
12791280
let rpc_bind_address = if matches.is_present("rpc_bind_address") {
12801281
solana_net_utils::parse_host(matches.value_of("rpc_bind_address").unwrap())
12811282
.expect("invalid rpc_bind_address")
@@ -1627,6 +1628,7 @@ pub fn main() {
16271628
"".to_string()
16281629
},
16291630
trust_packets: matches.is_present("trust_block_engine_packets"),
1631+
bind_address,
16301632
};
16311633

16321634
// Defaults are set in cli definition, safe to use unwrap() here
@@ -1653,6 +1655,7 @@ pub fn main() {
16531655
max_failed_heartbeats * expected_heartbeat_interval_ms,
16541656
),
16551657
trust_packets: matches.is_present("trust_relayer_packets"),
1658+
bind_address,
16561659
};
16571660

16581661
let mut validator_config = ValidatorConfig {

0 commit comments

Comments
 (0)