Plumb BankForks into GossipService

This commit is contained in:
Michael Vines
2019-02-20 21:36:08 -08:00
committed by Grimes
parent 4d5e2c8a4d
commit 080db1c62d
3 changed files with 15 additions and 9 deletions

View File

@ -12,6 +12,7 @@
//! * layer 2 - Everyone else, if layer 1 is `2^10`, layer 2 should be able to fit `2^20` number of nodes. //! * layer 2 - Everyone else, if layer 1 is `2^10`, layer 2 should be able to fit `2^20` number of nodes.
//! //!
//! Bank needs to provide an interface for us to query the stake weight //! Bank needs to provide an interface for us to query the stake weight
use crate::bank_forks::BankForks;
use crate::blocktree::Blocktree; use crate::blocktree::Blocktree;
use crate::contact_info::ContactInfo; use crate::contact_info::ContactInfo;
use crate::crds_gossip::CrdsGossip; use crate::crds_gossip::CrdsGossip;
@ -31,7 +32,6 @@ use rayon::prelude::*;
use solana_metrics::counter::Counter; use solana_metrics::counter::Counter;
use solana_metrics::{influxdb, submit}; use solana_metrics::{influxdb, submit};
use solana_netutil::{bind_in_range, bind_to, find_available_port_in_range, multi_bind_in_range}; use solana_netutil::{bind_in_range, bind_to, find_available_port_in_range, multi_bind_in_range};
use solana_runtime::bank::Bank;
use solana_runtime::bloom::Bloom; use solana_runtime::bloom::Bloom;
use solana_sdk::hash::Hash; use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
@ -860,7 +860,7 @@ impl ClusterInfo {
/// randomly pick a node and ask them for updates asynchronously /// randomly pick a node and ask them for updates asynchronously
pub fn gossip( pub fn gossip(
obj: Arc<RwLock<Self>>, obj: Arc<RwLock<Self>>,
bank: Option<Arc<Bank>>, bank_forks: Option<Arc<RwLock<BankForks>>>,
blob_sender: BlobSender, blob_sender: BlobSender,
exit: Arc<AtomicBool>, exit: Arc<AtomicBool>,
) -> JoinHandle<()> { ) -> JoinHandle<()> {
@ -870,8 +870,10 @@ impl ClusterInfo {
let mut last_push = timestamp(); let mut last_push = timestamp();
loop { loop {
let start = timestamp(); let start = timestamp();
let stakes: HashMap<_, _> = match bank { let stakes: HashMap<_, _> = match bank_forks {
Some(ref bank) => bank.staked_nodes(), Some(ref bank_forks) => {
bank_forks.read().unwrap().working_bank().staked_nodes()
}
None => HashMap::new(), None => HashMap::new(),
}; };
let _ = Self::run_gossip(&obj, &stakes, &blob_sender); let _ = Self::run_gossip(&obj, &stakes, &blob_sender);

View File

@ -192,7 +192,7 @@ impl Fullnode {
let gossip_service = GossipService::new( let gossip_service = GossipService::new(
&cluster_info, &cluster_info,
Some(blocktree.clone()), Some(blocktree.clone()),
Some(bank.clone()), Some(bank_forks.clone()),
node.sockets.gossip, node.sockets.gossip,
exit.clone(), exit.clone(),
); );

View File

@ -1,10 +1,10 @@
//! The `gossip_service` module implements the network control plane. //! The `gossip_service` module implements the network control plane.
use crate::bank_forks::BankForks;
use crate::blocktree::Blocktree; use crate::blocktree::Blocktree;
use crate::cluster_info::{ClusterInfo, Node, NodeInfo}; use crate::cluster_info::{ClusterInfo, Node, NodeInfo};
use crate::service::Service; use crate::service::Service;
use crate::streamer; use crate::streamer;
use solana_runtime::bank::Bank;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::signature::{Keypair, KeypairUtil};
use std::net::UdpSocket; use std::net::UdpSocket;
@ -24,7 +24,7 @@ impl GossipService {
pub fn new( pub fn new(
cluster_info: &Arc<RwLock<ClusterInfo>>, cluster_info: &Arc<RwLock<ClusterInfo>>,
blocktree: Option<Arc<Blocktree>>, blocktree: Option<Arc<Blocktree>>,
bank: Option<Arc<Bank>>, bank_forks: Option<Arc<RwLock<BankForks>>>,
gossip_socket: UdpSocket, gossip_socket: UdpSocket,
exit: Arc<AtomicBool>, exit: Arc<AtomicBool>,
) -> Self { ) -> Self {
@ -46,8 +46,12 @@ impl GossipService {
response_sender.clone(), response_sender.clone(),
exit.clone(), exit.clone(),
); );
let t_gossip = let t_gossip = ClusterInfo::gossip(
ClusterInfo::gossip(cluster_info.clone(), bank, response_sender, exit.clone()); cluster_info.clone(),
bank_forks,
response_sender,
exit.clone(),
);
let thread_hdls = vec![t_receiver, t_responder, t_listen, t_gossip]; let thread_hdls = vec![t_receiver, t_responder, t_listen, t_gossip];
Self { exit, thread_hdls } Self { exit, thread_hdls }
} }