RPC API now assumes a drone running on the bootstrap leader
This commit is contained in:
parent
8b357dcb32
commit
b7dc9dbc76
|
@ -175,6 +175,10 @@ pub fn request_airdrop_transaction(
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Result<Transaction, Error> {
|
) -> Result<Transaction, Error> {
|
||||||
|
info!(
|
||||||
|
"request_airdrop_transaction: drone_addr={} id={} tokens={} last_id={}",
|
||||||
|
drone_addr, id, tokens, last_id
|
||||||
|
);
|
||||||
// TODO: make this async tokio client
|
// TODO: make this async tokio client
|
||||||
let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?;
|
let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?;
|
||||||
stream.set_read_timeout(Some(Duration::new(10, 0)))?;
|
stream.set_read_timeout(Some(Duration::new(10, 0)))?;
|
||||||
|
|
|
@ -106,6 +106,7 @@ pub struct Fullnode {
|
||||||
broadcast_socket: UdpSocket,
|
broadcast_socket: UdpSocket,
|
||||||
rpc_addr: SocketAddr,
|
rpc_addr: SocketAddr,
|
||||||
rpc_pubsub_addr: SocketAddr,
|
rpc_pubsub_addr: SocketAddr,
|
||||||
|
drone_addr: SocketAddr,
|
||||||
db_ledger: Arc<DbLedger>,
|
db_ledger: Arc<DbLedger>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +211,15 @@ impl Fullnode {
|
||||||
keypair.clone(),
|
keypair.clone(),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
// Assume there's a drone running on the bootstrap leader
|
||||||
|
let mut drone_addr = match bootstrap_leader_info_option {
|
||||||
|
Some(bootstrap_leader_info) => bootstrap_leader_info.rpc,
|
||||||
|
None => rpc_addr,
|
||||||
|
};
|
||||||
|
drone_addr.set_port(solana_drone::drone::DRONE_PORT);
|
||||||
|
|
||||||
let (rpc_service, rpc_pubsub_service) =
|
let (rpc_service, rpc_pubsub_service) =
|
||||||
Self::startup_rpc_services(rpc_addr, rpc_pubsub_addr, &bank, &cluster_info);
|
Self::startup_rpc_services(rpc_addr, rpc_pubsub_addr, drone_addr, &bank, &cluster_info);
|
||||||
|
|
||||||
let gossip_service = GossipService::new(
|
let gossip_service = GossipService::new(
|
||||||
&cluster_info,
|
&cluster_info,
|
||||||
|
@ -338,6 +346,7 @@ impl Fullnode {
|
||||||
broadcast_socket: node.sockets.broadcast,
|
broadcast_socket: node.sockets.broadcast,
|
||||||
rpc_addr,
|
rpc_addr,
|
||||||
rpc_pubsub_addr,
|
rpc_pubsub_addr,
|
||||||
|
drone_addr,
|
||||||
db_ledger,
|
db_ledger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,6 +396,7 @@ impl Fullnode {
|
||||||
let (rpc_service, rpc_pubsub_service) = Self::startup_rpc_services(
|
let (rpc_service, rpc_pubsub_service) = Self::startup_rpc_services(
|
||||||
self.rpc_addr,
|
self.rpc_addr,
|
||||||
self.rpc_pubsub_addr,
|
self.rpc_pubsub_addr,
|
||||||
|
self.drone_addr,
|
||||||
&new_bank,
|
&new_bank,
|
||||||
&self.cluster_info,
|
&self.cluster_info,
|
||||||
);
|
);
|
||||||
|
@ -570,6 +580,7 @@ impl Fullnode {
|
||||||
fn startup_rpc_services(
|
fn startup_rpc_services(
|
||||||
rpc_addr: SocketAddr,
|
rpc_addr: SocketAddr,
|
||||||
rpc_pubsub_addr: SocketAddr,
|
rpc_pubsub_addr: SocketAddr,
|
||||||
|
drone_addr: SocketAddr,
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
) -> (JsonRpcService, PubSubService) {
|
) -> (JsonRpcService, PubSubService) {
|
||||||
|
@ -582,6 +593,7 @@ impl Fullnode {
|
||||||
bank,
|
bank,
|
||||||
cluster_info,
|
cluster_info,
|
||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port),
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port),
|
||||||
|
drone_addr,
|
||||||
),
|
),
|
||||||
PubSubService::new(
|
PubSubService::new(
|
||||||
bank,
|
bank,
|
||||||
|
|
15
src/rpc.rs
15
src/rpc.rs
|
@ -9,7 +9,7 @@ use crate::service::Service;
|
||||||
use crate::status_deque::Status;
|
use crate::status_deque::Status;
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use bs58;
|
use bs58;
|
||||||
use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
use solana_drone::drone::request_airdrop_transaction;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
|
@ -35,6 +35,7 @@ impl JsonRpcService {
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
rpc_addr: SocketAddr,
|
rpc_addr: SocketAddr,
|
||||||
|
drone_addr: SocketAddr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let request_processor = JsonRpcRequestProcessor::new(bank.clone());
|
let request_processor = JsonRpcRequestProcessor::new(bank.clone());
|
||||||
|
@ -52,6 +53,7 @@ impl JsonRpcService {
|
||||||
ServerBuilder::with_meta_extractor(io, move |_req: &hyper::Request<hyper::Body>| Meta {
|
ServerBuilder::with_meta_extractor(io, move |_req: &hyper::Request<hyper::Body>| Meta {
|
||||||
request_processor: request_processor.clone(),
|
request_processor: request_processor.clone(),
|
||||||
cluster_info: info.clone(),
|
cluster_info: info.clone(),
|
||||||
|
drone_addr,
|
||||||
rpc_addr,
|
rpc_addr,
|
||||||
exit: exit_pubsub.clone(),
|
exit: exit_pubsub.clone(),
|
||||||
}).threads(4)
|
}).threads(4)
|
||||||
|
@ -95,6 +97,7 @@ pub struct Meta {
|
||||||
pub request_processor: JsonRpcRequestProcessor,
|
pub request_processor: JsonRpcRequestProcessor,
|
||||||
pub cluster_info: Arc<RwLock<ClusterInfo>>,
|
pub cluster_info: Arc<RwLock<ClusterInfo>>,
|
||||||
pub rpc_addr: SocketAddr,
|
pub rpc_addr: SocketAddr,
|
||||||
|
pub drone_addr: SocketAddr,
|
||||||
pub exit: Arc<AtomicBool>,
|
pub exit: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
impl Metadata for Meta {}
|
impl Metadata for Meta {}
|
||||||
|
@ -226,10 +229,8 @@ impl RpcSol for RpcSolImpl {
|
||||||
trace!("request_airdrop id={} tokens={}", id, tokens);
|
trace!("request_airdrop id={} tokens={}", id, tokens);
|
||||||
let pubkey = verify_pubkey(id)?;
|
let pubkey = verify_pubkey(id)?;
|
||||||
|
|
||||||
let mut drone_addr = get_leader_addr(&meta.cluster_info)?;
|
|
||||||
drone_addr.set_port(DRONE_PORT);
|
|
||||||
let last_id = meta.request_processor.bank.last_id();
|
let last_id = meta.request_processor.bank.last_id();
|
||||||
let transaction = request_airdrop_transaction(&drone_addr, &pubkey, tokens, last_id)
|
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, last_id)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
info!("request_airdrop_transaction failed: {:?}", err);
|
info!("request_airdrop_transaction failed: {:?}", err);
|
||||||
Error::internal_error()
|
Error::internal_error()
|
||||||
|
@ -435,6 +436,7 @@ mod tests {
|
||||||
cluster_info.write().unwrap().insert_info(leader.clone());
|
cluster_info.write().unwrap().insert_info(leader.clone());
|
||||||
cluster_info.write().unwrap().set_leader(leader.id);
|
cluster_info.write().unwrap().set_leader(leader.id);
|
||||||
let rpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
let rpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
||||||
|
let drone_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
|
@ -443,6 +445,7 @@ mod tests {
|
||||||
let meta = Meta {
|
let meta = Meta {
|
||||||
request_processor,
|
request_processor,
|
||||||
cluster_info,
|
cluster_info,
|
||||||
|
drone_addr,
|
||||||
rpc_addr,
|
rpc_addr,
|
||||||
exit,
|
exit,
|
||||||
};
|
};
|
||||||
|
@ -456,7 +459,8 @@ mod tests {
|
||||||
let bank = Bank::new(&alice);
|
let bank = Bank::new(&alice);
|
||||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new(NodeInfo::default())));
|
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new(NodeInfo::default())));
|
||||||
let rpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 24680);
|
let rpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 24680);
|
||||||
let rpc_service = JsonRpcService::new(&Arc::new(bank), &cluster_info, rpc_addr);
|
let drone_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 24681);
|
||||||
|
let rpc_service = JsonRpcService::new(&Arc::new(bank), &cluster_info, rpc_addr, drone_addr);
|
||||||
let thread = rpc_service.thread_hdl.thread();
|
let thread = rpc_service.thread_hdl.thread();
|
||||||
assert_eq!(thread.name().unwrap(), "solana-jsonrpc");
|
assert_eq!(thread.name().unwrap(), "solana-jsonrpc");
|
||||||
|
|
||||||
|
@ -751,6 +755,7 @@ mod tests {
|
||||||
let meta = Meta {
|
let meta = Meta {
|
||||||
request_processor: JsonRpcRequestProcessor::new(Arc::new(bank)),
|
request_processor: JsonRpcRequestProcessor::new(Arc::new(bank)),
|
||||||
cluster_info: Arc::new(RwLock::new(ClusterInfo::new(NodeInfo::default()))),
|
cluster_info: Arc::new(RwLock::new(ClusterInfo::new(NodeInfo::default()))),
|
||||||
|
drone_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
|
||||||
rpc_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
|
rpc_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
|
||||||
exit: Arc::new(AtomicBool::new(false)),
|
exit: Arc::new(AtomicBool::new(false)),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue