remove set_leader from cluster_info (#4998)
This commit is contained in:
parent
aebd70ddce
commit
f537482c86
|
@ -107,12 +107,13 @@ impl BankForks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, bank: Bank) {
|
pub fn insert(&mut self, bank: Bank) -> Arc<Bank> {
|
||||||
let bank = Arc::new(bank);
|
let bank = Arc::new(bank);
|
||||||
let prev = self.banks.insert(bank.slot(), bank.clone());
|
let prev = self.banks.insert(bank.slot(), bank.clone());
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
|
|
||||||
self.working_bank = bank.clone();
|
self.working_bank = bank.clone();
|
||||||
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: really want to kill this...
|
// TODO: really want to kill this...
|
||||||
|
|
|
@ -78,9 +78,6 @@ pub struct ClusterInfo {
|
||||||
pub gossip: CrdsGossip,
|
pub gossip: CrdsGossip,
|
||||||
/// set the keypair that will be used to sign crds values generated. It is unset only in tests.
|
/// set the keypair that will be used to sign crds values generated. It is unset only in tests.
|
||||||
pub(crate) keypair: Arc<Keypair>,
|
pub(crate) keypair: Arc<Keypair>,
|
||||||
// TODO: remove gossip_leader_pubkey once all usage of `set_leader()` and `leader_data()` is
|
|
||||||
// purged
|
|
||||||
gossip_leader_pubkey: Pubkey,
|
|
||||||
/// The network entrypoint
|
/// The network entrypoint
|
||||||
entrypoint: Option<ContactInfo>,
|
entrypoint: Option<ContactInfo>,
|
||||||
}
|
}
|
||||||
|
@ -181,7 +178,6 @@ impl ClusterInfo {
|
||||||
let mut me = Self {
|
let mut me = Self {
|
||||||
gossip: CrdsGossip::default(),
|
gossip: CrdsGossip::default(),
|
||||||
keypair,
|
keypair,
|
||||||
gossip_leader_pubkey: Pubkey::default(),
|
|
||||||
entrypoint: None,
|
entrypoint: None,
|
||||||
};
|
};
|
||||||
let id = contact_info.id;
|
let id = contact_info.id;
|
||||||
|
@ -237,15 +233,6 @@ impl ClusterInfo {
|
||||||
self.lookup(&self.id()).cloned().unwrap()
|
self.lookup(&self.id()).cloned().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: don't use leader_data().
|
|
||||||
pub fn leader_data(&self) -> Option<&ContactInfo> {
|
|
||||||
let leader_pubkey = self.gossip_leader_pubkey;
|
|
||||||
if leader_pubkey == Pubkey::default() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
self.lookup(&leader_pubkey)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contact_info_trace(&self) -> String {
|
pub fn contact_info_trace(&self) -> String {
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
let mut spy_nodes = 0;
|
let mut spy_nodes = 0;
|
||||||
|
@ -302,17 +289,6 @@ impl ClusterInfo {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Record the id of the current leader for use by `leader_tpu_via_blobs()`
|
|
||||||
pub fn set_leader(&mut self, leader_pubkey: &Pubkey) {
|
|
||||||
if *leader_pubkey != self.gossip_leader_pubkey {
|
|
||||||
warn!(
|
|
||||||
"{}: LEADER_UPDATE TO {} from {}",
|
|
||||||
self.gossip.id, leader_pubkey, self.gossip_leader_pubkey,
|
|
||||||
);
|
|
||||||
self.gossip_leader_pubkey = *leader_pubkey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push_epoch_slots(&mut self, id: Pubkey, root: u64, slots: BTreeSet<u64>) {
|
pub fn push_epoch_slots(&mut self, id: Pubkey, root: u64, slots: BTreeSet<u64>) {
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
let mut entry = CrdsValue::EpochSlots(EpochSlots::new(id, root, slots, now));
|
let mut entry = CrdsValue::EpochSlots(EpochSlots::new(id, root, slots, now));
|
||||||
|
@ -1949,17 +1925,6 @@ mod tests {
|
||||||
Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
|
Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_default_leader() {
|
|
||||||
solana_logger::setup();
|
|
||||||
let contact_info = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
|
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
|
||||||
let network_entry_point =
|
|
||||||
ContactInfo::new_gossip_entry_point(&socketaddr!("127.0.0.1:1239"));
|
|
||||||
cluster_info.insert_info(network_entry_point);
|
|
||||||
assert!(cluster_info.leader_data().is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_in_range(x: u16, range: (u16, u16)) {
|
fn assert_in_range(x: u16, range: (u16, u16)) {
|
||||||
assert!(x >= range.0);
|
assert!(x >= range.0);
|
||||||
assert!(x < range.1);
|
assert!(x < range.1);
|
||||||
|
@ -2043,12 +2008,9 @@ mod tests {
|
||||||
//create new cluster info, leader, and peer
|
//create new cluster info, leader, and peer
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let peer_keypair = Keypair::new();
|
let peer_keypair = Keypair::new();
|
||||||
let leader_keypair = Keypair::new();
|
|
||||||
let contact_info = ContactInfo::new_localhost(&keypair.pubkey(), 0);
|
let contact_info = ContactInfo::new_localhost(&keypair.pubkey(), 0);
|
||||||
let leader = ContactInfo::new_localhost(&leader_keypair.pubkey(), 0);
|
|
||||||
let peer = ContactInfo::new_localhost(&peer_keypair.pubkey(), 0);
|
let peer = ContactInfo::new_localhost(&peer_keypair.pubkey(), 0);
|
||||||
let mut cluster_info = ClusterInfo::new(contact_info.clone(), Arc::new(keypair));
|
let mut cluster_info = ClusterInfo::new(contact_info.clone(), Arc::new(keypair));
|
||||||
cluster_info.set_leader(&leader.id);
|
|
||||||
cluster_info.insert_info(peer.clone());
|
cluster_info.insert_info(peer.clone());
|
||||||
cluster_info.gossip.refresh_push_active_set(&HashMap::new());
|
cluster_info.gossip.refresh_push_active_set(&HashMap::new());
|
||||||
//check that all types of gossip messages are signed correctly
|
//check that all types of gossip messages are signed correctly
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl ContactInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self {
|
pub(crate) fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self {
|
||||||
fn next_port(addr: &SocketAddr, nxt: u16) -> SocketAddr {
|
fn next_port(addr: &SocketAddr, nxt: u16) -> SocketAddr {
|
||||||
let mut nxt_addr = *addr;
|
let mut nxt_addr = *addr;
|
||||||
nxt_addr.set_port(addr.port() + nxt);
|
nxt_addr.set_port(addr.port() + nxt);
|
||||||
|
|
|
@ -163,7 +163,6 @@ impl ReplayStage {
|
||||||
&my_pubkey,
|
&my_pubkey,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&poh_recorder,
|
&poh_recorder,
|
||||||
&cluster_info,
|
|
||||||
&leader_schedule_cache,
|
&leader_schedule_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -189,10 +188,9 @@ impl ReplayStage {
|
||||||
my_pubkey: &Pubkey,
|
my_pubkey: &Pubkey,
|
||||||
bank_forks: &Arc<RwLock<BankForks>>,
|
bank_forks: &Arc<RwLock<BankForks>>,
|
||||||
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
|
||||||
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
||||||
) {
|
) {
|
||||||
let (reached_leader_tick, grace_ticks, poh_slot, parent_slot) = {
|
let (grace_ticks, poh_slot, parent_slot) = {
|
||||||
let poh_recorder = poh_recorder.lock().unwrap();
|
let poh_recorder = poh_recorder.lock().unwrap();
|
||||||
|
|
||||||
// we're done
|
// we're done
|
||||||
|
@ -201,19 +199,26 @@ impl ReplayStage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
poh_recorder.reached_leader_tick()
|
let (reached_leader_tick, grace_ticks, poh_slot, parent_slot) =
|
||||||
|
poh_recorder.reached_leader_tick();
|
||||||
|
|
||||||
|
if !reached_leader_tick {
|
||||||
|
trace!("{} poh_recorder hasn't reached_leader_tick", my_pubkey);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(grace_ticks, poh_slot, parent_slot)
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
"{} reached_leader_tick: {} poh_slot: {} parent_slot: {}",
|
"{} reached_leader_tick, poh_slot: {} parent_slot: {}",
|
||||||
my_pubkey,
|
my_pubkey,
|
||||||
reached_leader_tick,
|
|
||||||
poh_slot,
|
poh_slot,
|
||||||
parent_slot,
|
parent_slot,
|
||||||
);
|
);
|
||||||
|
|
||||||
if bank_forks.read().unwrap().get(poh_slot).is_some() {
|
if bank_forks.read().unwrap().get(poh_slot).is_some() {
|
||||||
trace!("{} already have bank in forks at {}", my_pubkey, poh_slot);
|
warn!("{} already have bank in forks at {}", my_pubkey, poh_slot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,33 +247,30 @@ impl ReplayStage {
|
||||||
next_leader,
|
next_leader,
|
||||||
poh_slot
|
poh_slot
|
||||||
);
|
);
|
||||||
// TODO: remove me?
|
|
||||||
cluster_info.write().unwrap().set_leader(&next_leader);
|
|
||||||
|
|
||||||
if next_leader == *my_pubkey && reached_leader_tick {
|
// I guess I missed my slot
|
||||||
trace!("{} starting tpu for slot {}", my_pubkey, poh_slot);
|
if next_leader != *my_pubkey {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
datapoint_warn!(
|
datapoint_warn!(
|
||||||
"replay_stage-new_leader",
|
"replay_stage-new_leader",
|
||||||
("count", poh_slot, i64),
|
("count", poh_slot, i64),
|
||||||
("grace", grace_ticks, i64)
|
("grace", grace_ticks, i64)
|
||||||
);
|
);
|
||||||
|
|
||||||
let tpu_bank = Bank::new_from_parent(&parent, my_pubkey, poh_slot);
|
let tpu_bank = bank_forks
|
||||||
bank_forks.write().unwrap().insert(tpu_bank);
|
.write()
|
||||||
if let Some(tpu_bank) = bank_forks.read().unwrap().get(poh_slot).cloned() {
|
.unwrap()
|
||||||
assert_eq!(
|
.insert(Bank::new_from_parent(&parent, my_pubkey, poh_slot));
|
||||||
bank_forks.read().unwrap().working_bank().slot(),
|
|
||||||
tpu_bank.slot()
|
info!(
|
||||||
);
|
|
||||||
debug!(
|
|
||||||
"poh_recorder new working bank: me: {} next_slot: {} next_leader: {}",
|
"poh_recorder new working bank: me: {} next_slot: {} next_leader: {}",
|
||||||
my_pubkey,
|
my_pubkey,
|
||||||
tpu_bank.slot(),
|
tpu_bank.slot(),
|
||||||
next_leader
|
next_leader
|
||||||
);
|
);
|
||||||
poh_recorder.lock().unwrap().set_bank(&tpu_bank);
|
poh_recorder.lock().unwrap().set_bank(&tpu_bank);
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
error!("{} No next leader found", my_pubkey);
|
error!("{} No next leader found", my_pubkey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,10 @@ impl JsonRpcRequestProcessor {
|
||||||
Ok(self.bank().slot())
|
Ok(self.bank().slot())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_slot_leader(&self) -> Result<String> {
|
||||||
|
Ok(self.bank().collector_id().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_transaction_count(&self) -> Result<u64> {
|
fn get_transaction_count(&self) -> Result<u64> {
|
||||||
Ok(self.bank().transaction_count() as u64)
|
Ok(self.bank().transaction_count() as u64)
|
||||||
}
|
}
|
||||||
|
@ -512,12 +516,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_slot_leader(&self, meta: Self::Metadata) -> Result<String> {
|
fn get_slot_leader(&self, meta: Self::Metadata) -> Result<String> {
|
||||||
let cluster_info = meta.cluster_info.read().unwrap();
|
meta.request_processor.read().unwrap().get_slot_leader()
|
||||||
let leader_data_option = cluster_info.leader_data();
|
|
||||||
Ok(leader_data_option
|
|
||||||
.and_then(|leader_data| Some(leader_data.id))
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_epoch_vote_accounts(&self, meta: Self::Metadata) -> Result<Vec<RpcVoteAccountInfo>> {
|
fn get_epoch_vote_accounts(&self, meta: Self::Metadata) -> Result<Vec<RpcVoteAccountInfo>> {
|
||||||
|
@ -577,6 +576,7 @@ mod tests {
|
||||||
) -> (MetaIoHandler<Meta>, Meta, Arc<Bank>, Hash, Keypair, Pubkey) {
|
) -> (MetaIoHandler<Meta>, Meta, Arc<Bank>, Hash, Keypair, Pubkey) {
|
||||||
let (bank_forks, alice) = new_bank_forks();
|
let (bank_forks, alice) = new_bank_forks();
|
||||||
let bank = bank_forks.read().unwrap().working_bank();
|
let bank = bank_forks.read().unwrap().working_bank();
|
||||||
|
let leader_pubkey = *bank.collector_id();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let blockhash = bank.confirmed_last_blockhash().0;
|
let blockhash = bank.confirmed_last_blockhash().0;
|
||||||
|
@ -595,9 +595,14 @@ mod tests {
|
||||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
|
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
|
||||||
ContactInfo::default(),
|
ContactInfo::default(),
|
||||||
)));
|
)));
|
||||||
let leader = ContactInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234"));
|
|
||||||
|
|
||||||
cluster_info.write().unwrap().insert_info(leader.clone());
|
cluster_info
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.insert_info(ContactInfo::new_with_pubkey_socketaddr(
|
||||||
|
&leader_pubkey,
|
||||||
|
&socketaddr!("127.0.0.1:1234"),
|
||||||
|
));
|
||||||
|
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
let rpc = RpcSolImpl;
|
let rpc = RpcSolImpl;
|
||||||
|
@ -606,7 +611,7 @@ mod tests {
|
||||||
request_processor,
|
request_processor,
|
||||||
cluster_info,
|
cluster_info,
|
||||||
};
|
};
|
||||||
(io, meta, bank, blockhash, alice, leader.id)
|
(io, meta, bank, blockhash, alice, leader_pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -674,13 +679,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_slot_leader() {
|
fn test_rpc_get_slot_leader() {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let (io, meta, _bank, _blockhash, _alice, _leader_pubkey) =
|
let (io, meta, _bank, _blockhash, _alice, leader_pubkey) =
|
||||||
start_rpc_handler_with_tx(&bob_pubkey);
|
start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getSlotLeader"}}"#);
|
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getSlotLeader"}}"#);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta);
|
||||||
let expected =
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, leader_pubkey);
|
||||||
format!(r#"{{"jsonrpc":"2.0","result":"11111111111111111111111111111111","id":1}}"#);
|
|
||||||
let expected: Response =
|
let expected: Response =
|
||||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::poh_recorder::{PohRecorder, WorkingBankEntries};
|
||||||
use crate::service::Service;
|
use crate::service::Service;
|
||||||
use crate::sigverify_stage::SigVerifyStage;
|
use crate::sigverify_stage::SigVerifyStage;
|
||||||
use crossbeam_channel::unbounded;
|
use crossbeam_channel::unbounded;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
|
@ -29,7 +28,6 @@ pub struct Tpu {
|
||||||
impl Tpu {
|
impl Tpu {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: &Pubkey,
|
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
||||||
entry_receiver: Receiver<WorkingBankEntries>,
|
entry_receiver: Receiver<WorkingBankEntries>,
|
||||||
|
@ -41,8 +39,6 @@ impl Tpu {
|
||||||
broadcast_type: &BroadcastStageType,
|
broadcast_type: &BroadcastStageType,
|
||||||
exit: &Arc<AtomicBool>,
|
exit: &Arc<AtomicBool>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
cluster_info.write().unwrap().set_leader(id);
|
|
||||||
|
|
||||||
let (packet_sender, packet_receiver) = channel();
|
let (packet_sender, packet_receiver) = channel();
|
||||||
let fetch_stage = FetchStage::new_with_sender(
|
let fetch_stage = FetchStage::new_with_sender(
|
||||||
transactions_sockets,
|
transactions_sockets,
|
||||||
|
|
|
@ -256,7 +256,6 @@ impl Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tpu = Tpu::new(
|
let tpu = Tpu::new(
|
||||||
&id,
|
|
||||||
&cluster_info,
|
&cluster_info,
|
||||||
&poh_recorder,
|
&poh_recorder,
|
||||||
entry_receiver,
|
entry_receiver,
|
||||||
|
|
Loading…
Reference in New Issue