Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC now sends transactions at the local TPU #3193

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl ClusterInfo {
pub fn my_data(&self) -> NodeInfo {
self.lookup(self.id()).cloned().unwrap()
}
pub fn leader_id(&self) -> Pubkey {
fn leader_id(&self) -> Pubkey {
let entry = CrdsValueLabel::LeaderId(self.id());
self.gossip
.crds
Expand Down
34 changes: 8 additions & 26 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,9 @@ impl JsonRpcRequestProcessor {
}
}

fn get_leader_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
if let Some(leader_data) = cluster_info.read().unwrap().leader_data() {
Ok(leader_data.tpu)
} else {
Err(Error {
code: ErrorCode::InternalError,
message: "No leader detected".into(),
data: None,
})
}
fn get_tpu_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
let node_info = cluster_info.read().unwrap().my_data();
Ok(node_info.tpu)
}

fn verify_pubkey(input: String) -> Result<Pubkey> {
Expand Down Expand Up @@ -320,7 +313,7 @@ impl RpcSol for RpcSolImpl {
})?;

let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let transactions_addr = get_leader_addr(&meta.cluster_info)?;
let transactions_addr = get_tpu_addr(&meta.cluster_info)?;
transactions_socket
.send_to(&data, transactions_addr)
.map_err(|err| {
Expand Down Expand Up @@ -363,7 +356,7 @@ impl RpcSol for RpcSolImpl {
return Err(Error::invalid_request());
}
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let transactions_addr = get_leader_addr(&meta.cluster_info)?;
let transactions_addr = get_tpu_addr(&meta.cluster_info)?;
trace!("send_transaction: leader is {:?}", &transactions_addr);
transactions_socket
.send_to(&data, transactions_addr)
Expand Down Expand Up @@ -658,23 +651,12 @@ mod tests {
}

#[test]
fn test_rpc_get_leader_addr() {
fn test_rpc_get_tpu_addr() {
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
NodeInfo::default(),
NodeInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234")),
)));
assert_eq!(
get_leader_addr(&cluster_info),
Err(Error {
code: ErrorCode::InternalError,
message: "No leader detected".into(),
data: None,
})
);
let leader = NodeInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234"));
cluster_info.write().unwrap().insert_info(leader.clone());
cluster_info.write().unwrap().set_leader(leader.id);
assert_eq!(
get_leader_addr(&cluster_info),
get_tpu_addr(&cluster_info),
Ok(socketaddr!("127.0.0.1:1234"))
);
}
Expand Down