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,
|
||||
last_id: Hash,
|
||||
) -> 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
|
||||
let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?;
|
||||
stream.set_read_timeout(Some(Duration::new(10, 0)))?;
|
||||
|
|
|
@ -106,6 +106,7 @@ pub struct Fullnode {
|
|||
broadcast_socket: UdpSocket,
|
||||
rpc_addr: SocketAddr,
|
||||
rpc_pubsub_addr: SocketAddr,
|
||||
drone_addr: SocketAddr,
|
||||
db_ledger: Arc<DbLedger>,
|
||||
}
|
||||
|
||||
|
@ -210,8 +211,15 @@ impl Fullnode {
|
|||
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) =
|
||||
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(
|
||||
&cluster_info,
|
||||
|
@ -338,6 +346,7 @@ impl Fullnode {
|
|||
broadcast_socket: node.sockets.broadcast,
|
||||
rpc_addr,
|
||||
rpc_pubsub_addr,
|
||||
drone_addr,
|
||||
db_ledger,
|
||||
}
|
||||
}
|
||||
|
@ -387,6 +396,7 @@ impl Fullnode {
|
|||
let (rpc_service, rpc_pubsub_service) = Self::startup_rpc_services(
|
||||
self.rpc_addr,
|
||||
self.rpc_pubsub_addr,
|
||||
self.drone_addr,
|
||||
&new_bank,
|
||||
&self.cluster_info,
|
||||
);
|
||||
|
@ -570,6 +580,7 @@ impl Fullnode {
|
|||
fn startup_rpc_services(
|
||||
rpc_addr: SocketAddr,
|
||||
rpc_pubsub_addr: SocketAddr,
|
||||
drone_addr: SocketAddr,
|
||||
bank: &Arc<Bank>,
|
||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||
) -> (JsonRpcService, PubSubService) {
|
||||
|
@ -582,6 +593,7 @@ impl Fullnode {
|
|||
bank,
|
||||
cluster_info,
|
||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port),
|
||||
drone_addr,
|
||||
),
|
||||
PubSubService::new(
|
||||
bank,
|
||||
|
|
15
src/rpc.rs
15
src/rpc.rs
|
@ -9,7 +9,7 @@ use crate::service::Service;
|
|||
use crate::status_deque::Status;
|
||||
use bincode::{deserialize, serialize};
|
||||
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::pubkey::Pubkey;
|
||||
use solana_sdk::signature::Signature;
|
||||
|
@ -35,6 +35,7 @@ impl JsonRpcService {
|
|||
bank: &Arc<Bank>,
|
||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||
rpc_addr: SocketAddr,
|
||||
drone_addr: SocketAddr,
|
||||
) -> Self {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
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 {
|
||||
request_processor: request_processor.clone(),
|
||||
cluster_info: info.clone(),
|
||||
drone_addr,
|
||||
rpc_addr,
|
||||
exit: exit_pubsub.clone(),
|
||||
}).threads(4)
|
||||
|
@ -95,6 +97,7 @@ pub struct Meta {
|
|||
pub request_processor: JsonRpcRequestProcessor,
|
||||
pub cluster_info: Arc<RwLock<ClusterInfo>>,
|
||||
pub rpc_addr: SocketAddr,
|
||||
pub drone_addr: SocketAddr,
|
||||
pub exit: Arc<AtomicBool>,
|
||||
}
|
||||
impl Metadata for Meta {}
|
||||
|
@ -226,10 +229,8 @@ impl RpcSol for RpcSolImpl {
|
|||
trace!("request_airdrop id={} tokens={}", id, tokens);
|
||||
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 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| {
|
||||
info!("request_airdrop_transaction failed: {:?}", err);
|
||||
Error::internal_error()
|
||||
|
@ -435,6 +436,7 @@ mod tests {
|
|||
cluster_info.write().unwrap().insert_info(leader.clone());
|
||||
cluster_info.write().unwrap().set_leader(leader.id);
|
||||
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 mut io = MetaIoHandler::default();
|
||||
|
@ -443,6 +445,7 @@ mod tests {
|
|||
let meta = Meta {
|
||||
request_processor,
|
||||
cluster_info,
|
||||
drone_addr,
|
||||
rpc_addr,
|
||||
exit,
|
||||
};
|
||||
|
@ -456,7 +459,8 @@ mod tests {
|
|||
let bank = Bank::new(&alice);
|
||||
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_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();
|
||||
assert_eq!(thread.name().unwrap(), "solana-jsonrpc");
|
||||
|
||||
|
@ -751,6 +755,7 @@ mod tests {
|
|||
let meta = Meta {
|
||||
request_processor: JsonRpcRequestProcessor::new(Arc::new(bank)),
|
||||
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),
|
||||
exit: Arc::new(AtomicBool::new(false)),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue