Add --private-rpc flag
This commit is contained in:
parent
1671ece9df
commit
81ba18eea6
|
@ -45,21 +45,13 @@ fn new_response<T>(bank: &Bank, value: T) -> RpcResponse<T> {
|
||||||
Ok(Response { context, value })
|
Ok(Response { context, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct JsonRpcConfig {
|
pub struct JsonRpcConfig {
|
||||||
pub enable_validator_exit: bool, // Enable the 'validatorExit' command
|
pub rpc_ports: Option<(u16, u16)>, // (API, PubSub)
|
||||||
|
pub enable_validator_exit: bool, // Enable the 'validatorExit' command
|
||||||
pub faucet_addr: Option<SocketAddr>,
|
pub faucet_addr: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for JsonRpcConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
enable_validator_exit: false,
|
|
||||||
faucet_addr: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct JsonRpcRequestProcessor {
|
pub struct JsonRpcRequestProcessor {
|
||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
|
|
|
@ -116,8 +116,7 @@ impl ValidatorExit {
|
||||||
pub struct Validator {
|
pub struct Validator {
|
||||||
pub id: Pubkey,
|
pub id: Pubkey,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
||||||
rpc_service: Option<JsonRpcService>,
|
rpc_service: Option<(JsonRpcService, PubSubService)>,
|
||||||
rpc_pubsub_service: Option<PubSubService>,
|
|
||||||
transaction_status_service: Option<TransactionStatusService>,
|
transaction_status_service: Option<TransactionStatusService>,
|
||||||
gossip_service: GossipService,
|
gossip_service: GossipService,
|
||||||
poh_recorder: Arc<Mutex<PohRecorder>>,
|
poh_recorder: Arc<Mutex<PohRecorder>>,
|
||||||
|
@ -219,36 +218,32 @@ impl Validator {
|
||||||
|
|
||||||
let blockstore = Arc::new(blockstore);
|
let blockstore = Arc::new(blockstore);
|
||||||
|
|
||||||
let rpc_service = if node.info.rpc.port() == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(JsonRpcService::new(
|
|
||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), node.info.rpc.port()),
|
|
||||||
config.rpc_config.clone(),
|
|
||||||
bank_forks.clone(),
|
|
||||||
block_commitment_cache.clone(),
|
|
||||||
blockstore.clone(),
|
|
||||||
cluster_info.clone(),
|
|
||||||
genesis_hash,
|
|
||||||
ledger_path,
|
|
||||||
storage_state.clone(),
|
|
||||||
validator_exit.clone(),
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
let subscriptions = Arc::new(RpcSubscriptions::new(&exit));
|
let subscriptions = Arc::new(RpcSubscriptions::new(&exit));
|
||||||
let rpc_pubsub_service = if node.info.rpc_pubsub.port() == 0 {
|
|
||||||
None
|
let rpc_service = config
|
||||||
} else {
|
.rpc_config
|
||||||
Some(PubSubService::new(
|
.rpc_ports
|
||||||
&subscriptions,
|
.map(|(rpc_port, rpc_pubsub_port)| {
|
||||||
SocketAddr::new(
|
(
|
||||||
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
JsonRpcService::new(
|
||||||
node.info.rpc_pubsub.port(),
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port),
|
||||||
),
|
config.rpc_config.clone(),
|
||||||
&exit,
|
bank_forks.clone(),
|
||||||
))
|
block_commitment_cache.clone(),
|
||||||
};
|
blockstore.clone(),
|
||||||
|
cluster_info.clone(),
|
||||||
|
genesis_hash,
|
||||||
|
ledger_path,
|
||||||
|
storage_state.clone(),
|
||||||
|
validator_exit.clone(),
|
||||||
|
),
|
||||||
|
PubSubService::new(
|
||||||
|
&subscriptions,
|
||||||
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_pubsub_port),
|
||||||
|
&exit,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let (transaction_status_sender, transaction_status_service) =
|
let (transaction_status_sender, transaction_status_service) =
|
||||||
if rpc_service.is_some() && !config.transaction_status_service_disabled {
|
if rpc_service.is_some() && !config.transaction_status_service_disabled {
|
||||||
|
@ -420,7 +415,6 @@ impl Validator {
|
||||||
id,
|
id,
|
||||||
gossip_service,
|
gossip_service,
|
||||||
rpc_service,
|
rpc_service,
|
||||||
rpc_pubsub_service,
|
|
||||||
transaction_status_service,
|
transaction_status_service,
|
||||||
tpu,
|
tpu,
|
||||||
tvu,
|
tvu,
|
||||||
|
@ -471,10 +465,8 @@ impl Validator {
|
||||||
pub fn join(self) -> Result<()> {
|
pub fn join(self) -> Result<()> {
|
||||||
self.poh_service.join()?;
|
self.poh_service.join()?;
|
||||||
drop(self.poh_recorder);
|
drop(self.poh_recorder);
|
||||||
if let Some(rpc_service) = self.rpc_service {
|
if let Some((rpc_service, rpc_pubsub_service)) = self.rpc_service {
|
||||||
rpc_service.join()?;
|
rpc_service.join()?;
|
||||||
}
|
|
||||||
if let Some(rpc_pubsub_service) = self.rpc_pubsub_service {
|
|
||||||
rpc_pubsub_service.join()?;
|
rpc_pubsub_service.join()?;
|
||||||
}
|
}
|
||||||
if let Some(transaction_status_service) = self.transaction_status_service {
|
if let Some(transaction_status_service) = self.transaction_status_service {
|
||||||
|
|
|
@ -496,6 +496,12 @@ pub fn main() {
|
||||||
.validator(port_validator)
|
.validator(port_validator)
|
||||||
.help("RPC port to use for this node"),
|
.help("RPC port to use for this node"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("private_rpc")
|
||||||
|
.long("--private-rpc")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Do not publish the RPC port for use by other nodes")
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("enable_rpc_exit")
|
Arg::with_name("enable_rpc_exit")
|
||||||
.long("enable-rpc-exit")
|
.long("enable-rpc-exit")
|
||||||
|
@ -657,7 +663,7 @@ pub fn main() {
|
||||||
let cuda = matches.is_present("cuda");
|
let cuda = matches.is_present("cuda");
|
||||||
let no_genesis_fetch = matches.is_present("no_genesis_fetch");
|
let no_genesis_fetch = matches.is_present("no_genesis_fetch");
|
||||||
let no_snapshot_fetch = matches.is_present("no_snapshot_fetch");
|
let no_snapshot_fetch = matches.is_present("no_snapshot_fetch");
|
||||||
let rpc_port = value_t!(matches, "rpc_port", u16);
|
let private_rpc = matches.is_present("private_rpc");
|
||||||
|
|
||||||
// Canonicalize ledger path to avoid issues with symlink creation
|
// Canonicalize ledger path to avoid issues with symlink creation
|
||||||
let _ = fs::create_dir_all(&ledger_path);
|
let _ = fs::create_dir_all(&ledger_path);
|
||||||
|
@ -678,6 +684,9 @@ pub fn main() {
|
||||||
expected_shred_version: value_t!(matches, "expected_shred_version", u16).ok(),
|
expected_shred_version: value_t!(matches, "expected_shred_version", u16).ok(),
|
||||||
new_hard_forks: hardforks_of(&matches, "hard_forks"),
|
new_hard_forks: hardforks_of(&matches, "hard_forks"),
|
||||||
rpc_config: JsonRpcConfig {
|
rpc_config: JsonRpcConfig {
|
||||||
|
rpc_ports: value_t!(matches, "rpc_port", u16)
|
||||||
|
.ok()
|
||||||
|
.map(|rpc_port| (rpc_port, rpc_port + 1)),
|
||||||
enable_validator_exit: matches.is_present("enable_rpc_exit"),
|
enable_validator_exit: matches.is_present("enable_rpc_exit"),
|
||||||
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
|
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
|
||||||
solana_net_utils::parse_host_port(address).expect("failed to parse faucet address")
|
solana_net_utils::parse_host_port(address).expect("failed to parse faucet address")
|
||||||
|
@ -852,12 +861,14 @@ pub fn main() {
|
||||||
let mut tcp_ports = vec![];
|
let mut tcp_ports = vec![];
|
||||||
let mut node =
|
let mut node =
|
||||||
Node::new_with_external_ip(&identity_keypair.pubkey(), &gossip_addr, dynamic_port_range);
|
Node::new_with_external_ip(&identity_keypair.pubkey(), &gossip_addr, dynamic_port_range);
|
||||||
if let Ok(rpc_port) = rpc_port {
|
|
||||||
let rpc_pubsub_port = rpc_port + 1;
|
if !private_rpc {
|
||||||
node.info.rpc = SocketAddr::new(node.info.gossip.ip(), rpc_port);
|
if let Some((rpc_port, rpc_pubsub_port)) = validator_config.rpc_config.rpc_ports {
|
||||||
node.info.rpc_pubsub = SocketAddr::new(node.info.gossip.ip(), rpc_pubsub_port);
|
node.info.rpc = SocketAddr::new(node.info.gossip.ip(), rpc_port);
|
||||||
tcp_ports = vec![rpc_port, rpc_pubsub_port];
|
node.info.rpc_pubsub = SocketAddr::new(node.info.gossip.ip(), rpc_pubsub_port);
|
||||||
};
|
tcp_ports = vec![rpc_port, rpc_pubsub_port];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref cluster_entrypoint) = cluster_entrypoint {
|
if let Some(ref cluster_entrypoint) = cluster_entrypoint {
|
||||||
let udp_sockets = vec![&node.sockets.gossip, &node.sockets.repair];
|
let udp_sockets = vec![&node.sockets.gossip, &node.sockets.repair];
|
||||||
|
|
Loading…
Reference in New Issue