diff --git a/Cargo.lock b/Cargo.lock index f43a446a6c..ef5f624cbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3929,6 +3929,7 @@ dependencies = [ "solana-client", "solana-core", "solana-faucet", + "solana-gossip", "solana-local-cluster", "solana-logger 1.7.0", "solana-measure", @@ -3951,6 +3952,7 @@ dependencies = [ "rayon", "solana-clap-utils", "solana-core", + "solana-gossip", "solana-ledger", "solana-logger 1.7.0", "solana-measure", @@ -4028,6 +4030,7 @@ dependencies = [ "solana-exchange-program", "solana-faucet", "solana-genesis", + "solana-gossip", "solana-local-cluster", "solana-logger 1.7.0", "solana-metrics", @@ -4065,6 +4068,7 @@ dependencies = [ "solana-core", "solana-faucet", "solana-genesis", + "solana-gossip", "solana-local-cluster", "solana-logger 1.7.0", "solana-measure", @@ -4331,6 +4335,7 @@ dependencies = [ "solana-faucet", "solana-frozen-abi 1.7.0", "solana-frozen-abi-macro 1.7.0", + "solana-gossip", "solana-ledger", "solana-logger 1.7.0", "solana-measure", @@ -4396,6 +4401,7 @@ dependencies = [ "solana-clap-utils", "solana-client", "solana-core", + "solana-gossip", "solana-ledger", "solana-logger 1.7.0", "solana-net-utils", @@ -4562,13 +4568,42 @@ dependencies = [ name = "solana-gossip" version = "1.7.0" dependencies = [ + "bincode", + "bv", "clap", + "flate2", + "indexmap", + "itertools", + "log 0.4.11", + "lru", + "matches", + "num-traits", + "num_cpus", + "rand 0.7.3", + "rand_chacha 0.2.2", + "rayon", + "rustc_version", + "serde", + "serde_bytes", + "serde_derive", + "serial_test", "solana-clap-utils", - "solana-core", + "solana-client", + "solana-frozen-abi 1.7.0", + "solana-frozen-abi-macro 1.7.0", + "solana-ledger", "solana-logger 1.7.0", + "solana-measure", + "solana-metrics", "solana-net-utils", + "solana-perf", + "solana-rayon-threadlimit", + "solana-runtime", "solana-sdk", + "solana-streamer", "solana-version", + "solana-vote-program", + "thiserror", ] [[package]] @@ -4731,6 +4766,7 @@ dependencies = [ "solana-download-utils", "solana-exchange-program", "solana-faucet", + "solana-gossip", "solana-ledger", "solana-logger 1.7.0", "solana-rayon-threadlimit", @@ -5452,6 +5488,7 @@ dependencies = [ "solana-download-utils", "solana-faucet", "solana-genesis-utils", + "solana-gossip", "solana-ledger", "solana-logger 1.7.0", "solana-metrics", diff --git a/accounts-cluster-bench/Cargo.toml b/accounts-cluster-bench/Cargo.toml index 7fcce652ef..94d0dc0626 100644 --- a/accounts-cluster-bench/Cargo.toml +++ b/accounts-cluster-bench/Cargo.toml @@ -17,10 +17,11 @@ solana-account-decoder = { path = "../account-decoder", version = "=1.7.0" } solana-clap-utils = { path = "../clap-utils", version = "=1.7.0" } solana-client = { path = "../client", version = "=1.7.0" } solana-core = { path = "../core", version = "=1.7.0" } -solana-measure = { path = "../measure", version = "=1.7.0" } -solana-logger = { path = "../logger", version = "=1.7.0" } -solana-net-utils = { path = "../net-utils", version = "=1.7.0" } solana-faucet = { path = "../faucet", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } +solana-logger = { path = "../logger", version = "=1.7.0" } +solana-measure = { path = "../measure", version = "=1.7.0" } +solana-net-utils = { path = "../net-utils", version = "=1.7.0" } solana-runtime = { path = "../runtime", version = "=1.7.0" } solana-sdk = { path = "../sdk", version = "=1.7.0" } solana-transaction-status = { path = "../transaction-status", version = "=1.7.0" } diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 5896843f94..e8c8a8633c 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -6,8 +6,8 @@ use rayon::prelude::*; use solana_account_decoder::parse_token::spl_token_v2_0_pubkey; use solana_clap_utils::input_parsers::pubkey_of; use solana_client::rpc_client::RpcClient; -use solana_core::gossip_service::discover; use solana_faucet::faucet::{request_airdrop_transaction, FAUCET_PORT}; +use solana_gossip::gossip_service::discover; use solana_measure::measure::Measure; use solana_runtime::inline_spl_token_v2_0; use solana_sdk::{ diff --git a/banking-bench/Cargo.toml b/banking-bench/Cargo.toml index 2db03fe150..d3aff28a9c 100644 --- a/banking-bench/Cargo.toml +++ b/banking-bench/Cargo.toml @@ -16,12 +16,13 @@ rand = "0.7.0" rayon = "1.5.0" solana-core = { path = "../core", version = "=1.7.0" } solana-clap-utils = { path = "../clap-utils", version = "=1.7.0" } -solana-streamer = { path = "../streamer", version = "=1.7.0" } -solana-perf = { path = "../perf", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-ledger = { path = "../ledger", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } -solana-runtime = { path = "../runtime", version = "=1.7.0" } solana-measure = { path = "../measure", version = "=1.7.0" } +solana-perf = { path = "../perf", version = "=1.7.0" } +solana-runtime = { path = "../runtime", version = "=1.7.0" } +solana-streamer = { path = "../streamer", version = "=1.7.0" } solana-sdk = { path = "../sdk", version = "=1.7.0" } solana-version = { path = "../version", version = "=1.7.0" } diff --git a/banking-bench/src/main.rs b/banking-bench/src/main.rs index 8ff0f3d3ce..3c5527312b 100644 --- a/banking-bench/src/main.rs +++ b/banking-bench/src/main.rs @@ -6,11 +6,10 @@ use rand::{thread_rng, Rng}; use rayon::prelude::*; use solana_core::{ banking_stage::{create_test_recorder, BankingStage}, - cluster_info::ClusterInfo, - cluster_info::Node, poh_recorder::PohRecorder, poh_recorder::WorkingBankEntry, }; +use solana_gossip::{cluster_info::ClusterInfo, cluster_info::Node}; use solana_ledger::{ blockstore::Blockstore, genesis_utils::{create_genesis_config, GenesisConfigInfo}, diff --git a/bench-exchange/Cargo.toml b/bench-exchange/Cargo.toml index 0df2b2d074..9c0d8a89d5 100644 --- a/bench-exchange/Cargo.toml +++ b/bench-exchange/Cargo.toml @@ -22,8 +22,9 @@ solana-clap-utils = { path = "../clap-utils", version = "=1.7.0" } solana-core = { path = "../core", version = "=1.7.0" } solana-genesis = { path = "../genesis", version = "=1.7.0" } solana-client = { path = "../client", version = "=1.7.0" } -solana-faucet = { path = "../faucet", version = "=1.7.0" } solana-exchange-program = { path = "../programs/exchange", version = "=1.7.0" } +solana-faucet = { path = "../faucet", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } solana-metrics = { path = "../metrics", version = "=1.7.0" } solana-net-utils = { path = "../net-utils", version = "=1.7.0" } diff --git a/bench-exchange/src/main.rs b/bench-exchange/src/main.rs index 1ae55adf6c..8986a67e68 100644 --- a/bench-exchange/src/main.rs +++ b/bench-exchange/src/main.rs @@ -5,7 +5,7 @@ pub mod order_book; use crate::bench::{airdrop_lamports, create_client_accounts_file, do_bench_exchange, Config}; use log::*; -use solana_core::gossip_service::{discover_cluster, get_multi_client}; +use solana_gossip::gossip_service::{discover_cluster, get_multi_client}; use solana_sdk::signature::Signer; fn main() { diff --git a/bench-exchange/tests/bench_exchange.rs b/bench-exchange/tests/bench_exchange.rs index a41b644501..0cba65a7ff 100644 --- a/bench-exchange/tests/bench_exchange.rs +++ b/bench-exchange/tests/bench_exchange.rs @@ -1,13 +1,11 @@ use log::*; use solana_bench_exchange::bench::{airdrop_lamports, do_bench_exchange, Config}; -use solana_core::{ - gossip_service::{discover_cluster, get_multi_client}, - validator::ValidatorConfig, -}; +use solana_core::validator::ValidatorConfig; use solana_exchange_program::{ exchange_processor::process_instruction, id, solana_exchange_program, }; use solana_faucet::faucet::run_local_faucet_with_port; +use solana_gossip::gossip_service::{discover_cluster, get_multi_client}; use solana_local_cluster::{ local_cluster::{ClusterConfig, LocalCluster}, validator_configs::make_identical_validator_configs, diff --git a/bench-tps/Cargo.toml b/bench-tps/Cargo.toml index 659ca4e765..813ed90479 100644 --- a/bench-tps/Cargo.toml +++ b/bench-tps/Cargo.toml @@ -20,6 +20,7 @@ solana-core = { path = "../core", version = "=1.7.0" } solana-genesis = { path = "../genesis", version = "=1.7.0" } solana-client = { path = "../client", version = "=1.7.0" } solana-faucet = { path = "../faucet", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } solana-metrics = { path = "../metrics", version = "=1.7.0" } solana-measure = { path = "../measure", version = "=1.7.0" } diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index 17ee213d76..abb9b3a7eb 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -2,8 +2,8 @@ use log::*; use solana_bench_tps::bench::{do_bench_tps, generate_and_fund_keypairs, generate_keypairs}; use solana_bench_tps::cli; -use solana_core::gossip_service::{discover_cluster, get_client, get_multi_client}; use solana_genesis::Base64Account; +use solana_gossip::gossip_service::{discover_cluster, get_client, get_multi_client}; use solana_sdk::fee_calculator::FeeRateGovernor; use solana_sdk::signature::{Keypair, Signer}; use solana_sdk::system_program; diff --git a/bench-tps/tests/bench_tps.rs b/bench-tps/tests/bench_tps.rs index a49c68a7b4..2aab3983cc 100644 --- a/bench-tps/tests/bench_tps.rs +++ b/bench-tps/tests/bench_tps.rs @@ -5,8 +5,9 @@ use solana_bench_tps::{ cli::Config, }; use solana_client::thin_client::create_client; -use solana_core::{cluster_info::VALIDATOR_PORT_RANGE, validator::ValidatorConfig}; +use solana_core::validator::ValidatorConfig; use solana_faucet::faucet::run_local_faucet_with_port; +use solana_gossip::cluster_info::VALIDATOR_PORT_RANGE; use solana_local_cluster::{ local_cluster::{ClusterConfig, LocalCluster}, validator_configs::make_identical_validator_configs, diff --git a/ci/test-bench.sh b/ci/test-bench.sh index b4bbea9295..f2480f9882 100755 --- a/ci/test-bench.sh +++ b/ci/test-bench.sh @@ -27,7 +27,7 @@ BENCH_ARTIFACT=current_bench_results.log _ "$cargo" build --manifest-path=keygen/Cargo.toml export PATH="$PWD/target/debug":$PATH -# Clear the C dependency files, if dependeny moves these files are not regenerated +# Clear the C dependency files, if dependency moves these files are not regenerated test -d target/debug/bpf && find target/debug/bpf -name '*.d' -delete test -d target/release/bpf && find target/release/bpf -name '*.d' -delete @@ -45,6 +45,10 @@ _ "$cargo" nightly bench --manifest-path sdk/Cargo.toml ${V:+--verbose} \ _ "$cargo" nightly bench --manifest-path runtime/Cargo.toml ${V:+--verbose} \ -- -Z unstable-options --format=json | tee -a "$BENCH_FILE" +# Run gossip benches +_ "$cargo" nightly bench --manifest-path gossip/Cargo.toml ${V:+--verbose} \ + -- -Z unstable-options --format=json | tee -a "$BENCH_FILE" + # Run core benches _ "$cargo" nightly bench --manifest-path core/Cargo.toml ${V:+--verbose} \ -- -Z unstable-options --format=json | tee -a "$BENCH_FILE" diff --git a/core/Cargo.toml b/core/Cargo.toml index 310aa764ce..c75e7cf30b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -55,6 +55,7 @@ solana-banks-server = { path = "../banks-server", version = "=1.7.0" } solana-clap-utils = { path = "../clap-utils", version = "=1.7.0" } solana-client = { path = "../client", version = "=1.7.0" } solana-faucet = { path = "../faucet", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-ledger = { path = "../ledger", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } solana-merkle-tree = { path = "../merkle-tree", version = "=1.7.0" } @@ -102,13 +103,7 @@ name = "banking_stage" name = "blockstore" [[bench]] -name = "crds" - -[[bench]] -name = "crds_gossip_pull" - -[[bench]] -name = "crds_shards" +name = "cluster_info" [[bench]] name = "gen_keys" @@ -122,8 +117,5 @@ name = "poh" [[bench]] name = "retransmit_stage" -[[bench]] -name = "cluster_info" - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 1bfc27aef9..13e2d088c5 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -8,9 +8,9 @@ use log::*; use rand::{thread_rng, Rng}; use rayon::prelude::*; use solana_core::banking_stage::{create_test_recorder, BankingStage, BankingStageStats}; -use solana_core::cluster_info::ClusterInfo; -use solana_core::cluster_info::Node; use solana_core::poh_recorder::WorkingBankEntry; +use solana_gossip::cluster_info::ClusterInfo; +use solana_gossip::cluster_info::Node; use solana_ledger::blockstore_processor::process_entries; use solana_ledger::entry::{next_hash, Entry}; use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}; diff --git a/core/benches/cluster_info.rs b/core/benches/cluster_info.rs index e6b7694461..54750a2497 100644 --- a/core/benches/cluster_info.rs +++ b/core/benches/cluster_info.rs @@ -5,8 +5,8 @@ extern crate test; use rand::{thread_rng, Rng}; use solana_core::broadcast_stage::broadcast_metrics::TransmitShredsStats; use solana_core::broadcast_stage::{broadcast_shreds, get_broadcast_peers}; -use solana_core::cluster_info::{ClusterInfo, Node}; -use solana_core::contact_info::ContactInfo; +use solana_gossip::cluster_info::{ClusterInfo, Node}; +use solana_gossip::contact_info::ContactInfo; use solana_ledger::shred::Shred; use solana_sdk::pubkey; use solana_sdk::timing::timestamp; diff --git a/core/benches/retransmit_stage.rs b/core/benches/retransmit_stage.rs index cc4f46a865..5d22556071 100644 --- a/core/benches/retransmit_stage.rs +++ b/core/benches/retransmit_stage.rs @@ -4,9 +4,9 @@ extern crate solana_core; extern crate test; use log::*; -use solana_core::cluster_info::{ClusterInfo, Node}; -use solana_core::contact_info::ContactInfo; use solana_core::retransmit_stage::retransmitter; +use solana_gossip::cluster_info::{ClusterInfo, Node}; +use solana_gossip::contact_info::ContactInfo; use solana_ledger::entry::Entry; use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}; use solana_ledger::leader_schedule_cache::LeaderScheduleCache; diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index e057c0cab0..07f115ac30 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -4,11 +4,9 @@ // hash on gossip. Monitor gossip for messages from validators in the --trusted-validators // set and halt the node if a mismatch is detected. -use crate::{ - cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES}, - snapshot_packager_service::PendingSnapshotPackage, -}; +use crate::snapshot_packager_service::PendingSnapshotPackage; use rayon::ThreadPool; +use solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES}; use solana_runtime::{ accounts_db, snapshot_package::{AccountsPackage, AccountsPackagePre, AccountsPackageReceiver}, @@ -218,8 +216,7 @@ impl AccountsHashVerifier { #[cfg(test)] mod tests { use super::*; - use crate::cluster_info::make_accounts_hashes_message; - use crate::contact_info::ContactInfo; + use solana_gossip::{cluster_info::make_accounts_hashes_message, contact_info::ContactInfo}; use solana_runtime::bank_forks::ArchiveFormat; use solana_runtime::snapshot_utils::SnapshotVersion; use solana_sdk::{ diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 6ef1ea4f10..af59200f86 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -2,7 +2,6 @@ //! to contruct a software pipeline. The stage uses all available CPU cores and //! can do its processing in parallel with signature verification on the GPU. use crate::{ - cluster_info::ClusterInfo, packet_hasher::PacketHasher, poh_recorder::{PohRecorder, PohRecorderError, TransactionRecorder, WorkingBankEntry}, poh_service::{self, PohService}, @@ -11,6 +10,7 @@ use crossbeam_channel::{Receiver as CrossbeamReceiver, RecvTimeoutError}; use itertools::Itertools; use lru::LruCache; use retain_mut::RetainMut; +use solana_gossip::cluster_info::ClusterInfo; use solana_ledger::{ blockstore::Blockstore, blockstore_processor::TransactionStatusSender, entry::hash_transactions, leader_schedule_cache::LeaderScheduleCache, @@ -1435,11 +1435,12 @@ pub fn create_test_recorder( mod tests { use super::*; use crate::{ - cluster_info::Node, poh_recorder::Record, poh_recorder::WorkingBank, + poh_recorder::Record, poh_recorder::WorkingBank, transaction_status_service::TransactionStatusService, }; use crossbeam_channel::unbounded; use itertools::Itertools; + use solana_gossip::cluster_info::Node; use solana_ledger::{ blockstore::entries_to_test_shreds, entry::{next_entry, Entry, EntrySlice}, diff --git a/core/src/broadcast_stage.rs b/core/src/broadcast_stage.rs index f08ac8b826..d03b9dd65d 100644 --- a/core/src/broadcast_stage.rs +++ b/core/src/broadcast_stage.rs @@ -5,11 +5,7 @@ use self::{ fail_entry_verification_broadcast_run::FailEntryVerificationBroadcastRun, standard_broadcast_run::StandardBroadcastRun, }; -use crate::contact_info::ContactInfo; -use crate::crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS; -use crate::weighted_shuffle::weighted_best; use crate::{ - cluster_info::{ClusterInfo, ClusterInfoError}, poh_recorder::WorkingBankEntry, result::{Error, Result}, }; @@ -17,6 +13,12 @@ use crossbeam_channel::{ Receiver as CrossbeamReceiver, RecvTimeoutError as CrossbeamRecvTimeoutError, Sender as CrossbeamSender, }; +use solana_gossip::{ + cluster_info::{self, ClusterInfo, ClusterInfoError}, + contact_info::ContactInfo, + crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS, + weighted_shuffle::weighted_best, +}; use solana_ledger::{blockstore::Blockstore, shred::Shred}; use solana_measure::measure::Measure; use solana_metrics::{inc_new_counter_error, inc_new_counter_info}; @@ -363,7 +365,6 @@ pub fn get_broadcast_peers( cluster_info: &ClusterInfo, stakes: Option<&HashMap>, ) -> (Vec, Vec<(u64, usize)>) { - use crate::cluster_info; let mut peers = cluster_info.tvu_peers(); let peers_and_stakes = cluster_info::stake_weight_peers(&mut peers, stakes); (peers, peers_and_stakes) @@ -440,8 +441,8 @@ fn num_live_peers(peers: &[ContactInfo]) -> i64 { #[cfg(test)] pub mod test { use super::*; - use crate::cluster_info::{ClusterInfo, Node}; use crossbeam_channel::unbounded; + use solana_gossip::cluster_info::{ClusterInfo, Node}; use solana_ledger::{ blockstore::{make_slot_entries, Blockstore}, entry::create_ticks, diff --git a/core/src/broadcast_stage/broadcast_fake_shreds_run.rs b/core/src/broadcast_stage/broadcast_fake_shreds_run.rs index 9173be7ded..55983fd35e 100644 --- a/core/src/broadcast_stage/broadcast_fake_shreds_run.rs +++ b/core/src/broadcast_stage/broadcast_fake_shreds_run.rs @@ -138,7 +138,7 @@ impl BroadcastRun for BroadcastFakeShredsRun { #[cfg(test)] mod tests { use super::*; - use crate::contact_info::ContactInfo; + use solana_gossip::contact_info::ContactInfo; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; #[test] diff --git a/core/src/broadcast_stage/standard_broadcast_run.rs b/core/src/broadcast_stage/standard_broadcast_run.rs index 6c0bb12482..6908d5dd1b 100644 --- a/core/src/broadcast_stage/standard_broadcast_run.rs +++ b/core/src/broadcast_stage/standard_broadcast_run.rs @@ -494,7 +494,7 @@ impl BroadcastRun for StandardBroadcastRun { #[cfg(test)] mod test { use super::*; - use crate::cluster_info::{ClusterInfo, Node}; + use solana_gossip::cluster_info::{ClusterInfo, Node}; use solana_ledger::genesis_utils::create_genesis_config; use solana_ledger::{ blockstore::Blockstore, entry::create_ticks, get_tmp_ledger_path, diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index cd37901b6f..be3e410a62 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -1,7 +1,4 @@ use crate::{ - cluster_info::{ClusterInfo, GOSSIP_SLEEP_MILLIS}, - crds::Cursor, - crds_value::CrdsValueLabel, optimistic_confirmation_verifier::OptimisticConfirmationVerifier, poh_recorder::PohRecorder, replay_stage::DUPLICATE_THRESHOLD, @@ -15,6 +12,11 @@ use crossbeam_channel::{ }; use itertools::izip; use log::*; +use solana_gossip::{ + cluster_info::{ClusterInfo, GOSSIP_SLEEP_MILLIS}, + crds::Cursor, + crds_value::CrdsValueLabel, +}; use solana_ledger::blockstore::Blockstore; use solana_metrics::inc_new_counter_debug; use solana_perf::packet::{self, Packets}; diff --git a/core/src/cluster_slots.rs b/core/src/cluster_slots.rs index 82e940331f..7a9ca5fd3d 100644 --- a/core/src/cluster_slots.rs +++ b/core/src/cluster_slots.rs @@ -1,8 +1,8 @@ -use crate::{ - cluster_info::ClusterInfo, contact_info::ContactInfo, crds::Cursor, epoch_slots::EpochSlots, - serve_repair::RepairType, -}; +use crate::serve_repair::RepairType; use itertools::Itertools; +use solana_gossip::{ + cluster_info::ClusterInfo, contact_info::ContactInfo, crds::Cursor, epoch_slots::EpochSlots, +}; use solana_runtime::{bank_forks::BankForks, epoch_stakes::NodeIdToVoteAccounts}; use solana_sdk::{clock::Slot, pubkey::Pubkey}; use std::{ diff --git a/core/src/cluster_slots_service.rs b/core/src/cluster_slots_service.rs index ce362541c6..1f059521b6 100644 --- a/core/src/cluster_slots_service.rs +++ b/core/src/cluster_slots_service.rs @@ -1,4 +1,5 @@ -use crate::{cluster_info::ClusterInfo, cluster_slots::ClusterSlots}; +use crate::cluster_slots::ClusterSlots; +use solana_gossip::cluster_info::ClusterInfo; use solana_ledger::blockstore::{Blockstore, CompletedSlotsReceiver}; use solana_measure::measure::Measure; use solana_runtime::bank_forks::BankForks; @@ -185,7 +186,7 @@ impl ClusterSlotsService { #[cfg(test)] mod test { use super::*; - use crate::{cluster_info::Node, crds_value::CrdsValueLabel}; + use solana_gossip::{cluster_info::Node, crds_value::CrdsValueLabel}; #[test] pub fn test_update_lowest_slot() { diff --git a/core/src/lib.rs b/core/src/lib.rs index d418689864..363283000c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -13,40 +13,21 @@ pub mod bigtable_upload_service; pub mod broadcast_stage; pub mod cache_block_time_service; pub mod cluster_info_vote_listener; -pub mod commitment_service; -pub mod completed_data_sets_service; -mod deprecated; -pub mod sample_performance_service; -pub mod shred_fetch_stage; -#[macro_use] -pub mod contact_info; -pub mod cluster_info; -mod cluster_info_metrics; pub mod cluster_slot_state_verifier; pub mod cluster_slots; pub mod cluster_slots_service; +pub mod commitment_service; +pub mod completed_data_sets_service; pub mod consensus; -pub mod crds; -pub mod crds_gossip; -pub mod crds_gossip_error; -pub mod crds_gossip_pull; -pub mod crds_gossip_push; -pub mod crds_shards; -pub mod crds_value; -pub mod data_budget; -pub mod duplicate_shred; -pub mod epoch_slots; pub mod fetch_stage; pub mod fork_choice; pub mod gen_keys; -pub mod gossip_service; pub mod heaviest_subtree_fork_choice; pub mod latest_validator_votes_for_frozen_banks; pub mod ledger_cleanup_service; pub mod optimistic_confirmation_verifier; pub mod outstanding_requests; pub mod packet_hasher; -pub mod ping_pong; pub mod poh_recorder; pub mod poh_service; pub mod progress_map; @@ -62,9 +43,11 @@ pub mod rewards_recorder_service; pub mod rpc; pub mod rpc_health; pub mod rpc_service; +pub mod sample_performance_service; pub mod send_transaction_service; pub mod serve_repair; pub mod serve_repair_service; +pub mod shred_fetch_stage; pub mod sigverify; pub mod sigverify_shreds; pub mod sigverify_stage; @@ -78,7 +61,6 @@ pub mod unfrozen_gossip_verified_vote_hashes; pub mod validator; pub mod verified_vote_packets; pub mod vote_stake_tracker; -pub mod weighted_shuffle; pub mod window_service; #[macro_use] diff --git a/core/src/repair_service.rs b/core/src/repair_service.rs index 710e1bb97b..0bb96983bf 100644 --- a/core/src/repair_service.rs +++ b/core/src/repair_service.rs @@ -1,7 +1,6 @@ //! The `repair_service` module implements the tools necessary to generate a thread which //! regularly finds missing shreds in the ledger and sends repair requests for those shreds use crate::{ - cluster_info::ClusterInfo, cluster_info_vote_listener::VerifiedVoteReceiver, cluster_slots::ClusterSlots, outstanding_requests::OutstandingRequests, @@ -10,6 +9,7 @@ use crate::{ serve_repair::{RepairType, ServeRepair}, }; use crossbeam_channel::{Receiver as CrossbeamReceiver, Sender as CrossbeamSender}; +use solana_gossip::cluster_info::ClusterInfo; use solana_ledger::{ blockstore::{Blockstore, SlotMeta}, shred::Nonce, @@ -668,8 +668,8 @@ impl RepairService { #[cfg(test)] mod test { use super::*; - use crate::cluster_info::Node; use crossbeam_channel::unbounded; + use solana_gossip::cluster_info::Node; use solana_ledger::blockstore::{ make_chaining_slot_entries, make_many_slot_entries, make_slot_entries, }; diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 2bae193754..8a51879481 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -3,7 +3,6 @@ use crate::{ broadcast_stage::RetransmitSlotsSender, cache_block_time_service::CacheBlockTimeSender, - cluster_info::ClusterInfo, cluster_info_vote_listener::{ GossipDuplicateConfirmedSlotsReceiver, GossipVerifiedVoteHashReceiver, VoteTracker, }, @@ -25,6 +24,7 @@ use crate::{ window_service::DuplicateSlotReceiver, }; use solana_client::rpc_response::SlotUpdate; +use solana_gossip::cluster_info::ClusterInfo; use solana_ledger::{ block_error::BlockError, blockstore::Blockstore, @@ -2473,15 +2473,14 @@ impl ReplayStage { pub(crate) mod tests { use super::*; use crate::{ - cluster_info::Node, consensus::test::{initialize_state, VoteSimulator}, consensus::Tower, - crds::Cursor, progress_map::ValidatorStakeInfo, replay_stage::ReplayStage, transaction_status_service::TransactionStatusService, }; use crossbeam_channel::unbounded; + use solana_gossip::{cluster_info::Node, crds::Cursor}; use solana_ledger::{ blockstore::make_slot_entries, blockstore::{entries_to_test_shreds, BlockstoreError}, diff --git a/core/src/result.rs b/core/src/result.rs index ac9907bfbc..8dbce74de7 100644 --- a/core/src/result.rs +++ b/core/src/result.rs @@ -1,39 +1,23 @@ //! The `result` module exposes a Result type that propagates one of many different Error types. -use crate::poh_recorder; -use crate::{cluster_info, duplicate_shred}; -use solana_ledger::block_error; +use solana_gossip::{cluster_info, gossip_error::GossipError}; use solana_ledger::blockstore; -use solana_runtime::snapshot_utils; -use solana_sdk::transaction; -use std::any::Any; #[derive(Debug)] pub enum Error { Io(std::io::Error), - Json(serde_json::Error), - AddrParse(std::net::AddrParseError), - JoinError(Box), RecvError(std::sync::mpsc::RecvError), - TryCrossbeamRecvError(crossbeam_channel::TryRecvError), CrossbeamRecvTimeoutError(crossbeam_channel::RecvTimeoutError), ReadyTimeoutError, RecvTimeoutError(std::sync::mpsc::RecvTimeoutError), CrossbeamSendError, TryCrossbeamSendError, - TryRecvError(std::sync::mpsc::TryRecvError), Serialize(std::boxed::Box), - TransactionError(transaction::TransactionError), ClusterInfoError(cluster_info::ClusterInfoError), SendError, - PohRecorderError(poh_recorder::PohRecorderError), - BlockError(block_error::BlockError), BlockstoreError(blockstore::BlockstoreError), - FsExtra(fs_extra::error::Error), - SnapshotError(snapshot_utils::SnapshotError), WeightedIndexError(rand::distributions::weighted::WeightedError), - DuplicateNodeInstance, - DuplicateShredError(duplicate_shred::Error), + GossipError(GossipError), } pub type Result = std::result::Result; @@ -51,16 +35,6 @@ impl std::convert::From for Error { Error::RecvError(e) } } -impl std::convert::From for Error { - fn from(e: crossbeam_channel::TryRecvError) -> Error { - Error::TryCrossbeamRecvError(e) - } -} -impl std::convert::From for Error { - fn from(e: std::sync::mpsc::TryRecvError) -> Error { - Error::TryRecvError(e) - } -} impl std::convert::From for Error { fn from(e: crossbeam_channel::RecvTimeoutError) -> Error { Error::CrossbeamRecvTimeoutError(e) @@ -76,11 +50,6 @@ impl std::convert::From for Error { Error::RecvTimeoutError(e) } } -impl std::convert::From for Error { - fn from(e: transaction::TransactionError) -> Error { - Error::TransactionError(e) - } -} impl std::convert::From for Error { fn from(e: cluster_info::ClusterInfoError) -> Error { Error::ClusterInfoError(e) @@ -101,59 +70,29 @@ impl std::convert::From> for Error { Error::SendError } } -impl std::convert::From> for Error { - fn from(e: Box) -> Error { - Error::JoinError(e) - } -} impl std::convert::From for Error { fn from(e: std::io::Error) -> Error { Error::Io(e) } } -impl std::convert::From for Error { - fn from(e: fs_extra::error::Error) -> Error { - Error::FsExtra(e) - } -} -impl std::convert::From for Error { - fn from(e: serde_json::Error) -> Error { - Error::Json(e) - } -} -impl std::convert::From for Error { - fn from(e: std::net::AddrParseError) -> Error { - Error::AddrParse(e) - } -} impl std::convert::From> for Error { fn from(e: std::boxed::Box) -> Error { Error::Serialize(e) } } -impl std::convert::From for Error { - fn from(e: poh_recorder::PohRecorderError) -> Error { - Error::PohRecorderError(e) - } -} impl std::convert::From for Error { fn from(e: blockstore::BlockstoreError) -> Error { Error::BlockstoreError(e) } } -impl std::convert::From for Error { - fn from(e: snapshot_utils::SnapshotError) -> Error { - Error::SnapshotError(e) - } -} impl std::convert::From for Error { fn from(e: rand::distributions::weighted::WeightedError) -> Error { Error::WeightedIndexError(e) } } -impl std::convert::From for Error { - fn from(e: duplicate_shred::Error) -> Error { - Error::DuplicateShredError(e) +impl std::convert::From for Error { + fn from(e: GossipError) -> Error { + Error::GossipError(e) } } @@ -163,24 +102,11 @@ mod tests { use crate::result::Result; use std::io; use std::io::Write; - use std::net::SocketAddr; use std::panic; use std::sync::mpsc::channel; use std::sync::mpsc::RecvError; use std::sync::mpsc::RecvTimeoutError; - use std::thread; - fn addr_parse_error() -> Result { - Ok("12fdfasfsafsadfs".parse()?) - } - - fn join_error() -> Result<()> { - panic::set_hook(Box::new(|_info| {})); - Ok(thread::spawn(|| panic!("hi")).join()?) - } - fn json_error() -> Result<()> { - Ok(serde_json::from_slice(b"=342{;;;;:}")?) - } fn send_error() -> Result<()> { let (s, r) = channel(); drop(r); @@ -190,25 +116,20 @@ mod tests { #[test] fn from_test() { - assert_matches!(addr_parse_error(), Err(Error::AddrParse(_))); assert_matches!(Error::from(RecvError {}), Error::RecvError(_)); assert_matches!( Error::from(RecvTimeoutError::Timeout), Error::RecvTimeoutError(_) ); assert_matches!(send_error(), Err(Error::SendError)); - assert_matches!(join_error(), Err(Error::JoinError(_))); let ioe = io::Error::new(io::ErrorKind::NotFound, "hi"); assert_matches!(Error::from(ioe), Error::Io(_)); } #[test] fn fmt_test() { - write!(io::sink(), "{:?}", addr_parse_error()).unwrap(); write!(io::sink(), "{:?}", Error::from(RecvError {})).unwrap(); write!(io::sink(), "{:?}", Error::from(RecvTimeoutError::Timeout)).unwrap(); write!(io::sink(), "{:?}", send_error()).unwrap(); - write!(io::sink(), "{:?}", join_error()).unwrap(); - write!(io::sink(), "{:?}", json_error()).unwrap(); write!( io::sink(), "{:?}", diff --git a/core/src/retransmit_stage.rs b/core/src/retransmit_stage.rs index f513dba29b..3ebfaf56a1 100644 --- a/core/src/retransmit_stage.rs +++ b/core/src/retransmit_stage.rs @@ -2,12 +2,10 @@ #![allow(clippy::rc_buffer)] use crate::{ - cluster_info::{compute_retransmit_peers, ClusterInfo, DATA_PLANE_FANOUT}, cluster_info_vote_listener::VerifiedVoteReceiver, cluster_slots::ClusterSlots, cluster_slots_service::ClusterSlotsService, completed_data_sets_service::CompletedDataSetsSender, - contact_info::ContactInfo, repair_service::DuplicateSlotsResetSender, repair_service::RepairInfo, result::{Error, Result}, @@ -16,6 +14,10 @@ use crate::{ use crossbeam_channel::{Receiver, Sender}; use lru::LruCache; use solana_client::rpc_response::SlotUpdate; +use solana_gossip::{ + cluster_info::{compute_retransmit_peers, ClusterInfo, DATA_PLANE_FANOUT}, + contact_info::ContactInfo, +}; use solana_ledger::shred::{get_shred_slot_index_type, ShredFetchStats}; use solana_ledger::{ blockstore::{Blockstore, CompletedSlotsReceiver}, @@ -691,7 +693,7 @@ impl RetransmitStage { #[cfg(test)] mod tests { use super::*; - use crate::contact_info::ContactInfo; + use solana_gossip::contact_info::ContactInfo; use solana_ledger::blockstore_processor::{process_blockstore, ProcessOptions}; use solana_ledger::create_new_tmp_ledger; use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}; diff --git a/core/src/rpc.rs b/core/src/rpc.rs index c92d103f6e..425f8fb0ac 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -1,8 +1,6 @@ //! The `rpc` module implements the Solana RPC interface. use crate::{ - cluster_info::ClusterInfo, - contact_info::ContactInfo, rpc_health::*, send_transaction_service::{SendTransactionService, TransactionInfo}, validator::ValidatorExit, @@ -32,6 +30,7 @@ use solana_client::{ rpc_response::*, }; use solana_faucet::faucet::request_airdrop_transaction; +use solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo}; use solana_ledger::{ blockstore::Blockstore, blockstore_db::BlockstoreError, get_tmp_ledger_path, leader_schedule_cache::LeaderScheduleCache, @@ -3719,14 +3718,12 @@ pub(crate) fn create_validator_exit(exit: &Arc) -> Arc, /// set the keypair that will be used to sign crds values generated. It is unset only in tests. - pub(crate) keypair: Arc, + pub keypair: Arc, /// Network entrypoints entrypoints: RwLock>, outbound_budget: DataBudget, @@ -267,7 +270,7 @@ impl PruneData { } impl Sanitize for PruneData { - fn sanitize(&self) -> std::result::Result<(), SanitizeError> { + fn sanitize(&self) -> Result<(), SanitizeError> { if self.wallclock >= MAX_WALLCLOCK { return Err(SanitizeError::ValueOutOfBounds); } @@ -323,7 +326,7 @@ pub fn make_accounts_hashes_message( pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>; // TODO These messages should go through the gpu pipeline for spam filtering -#[frozen_abi(digest = "CH5BWuhAyvUiUQYgu2Lcwu7eoiW6bQitvtLS1yFsdmrE")] +#[frozen_abi(digest = "GANv3KVkTYF84kmg1bAuWEZd9MaiYzPquuu13hup3379")] #[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)] #[allow(clippy::large_enum_variant)] enum Protocol { @@ -408,7 +411,7 @@ impl Protocol { } impl Sanitize for Protocol { - fn sanitize(&self) -> std::result::Result<(), SanitizeError> { + fn sanitize(&self) -> Result<(), SanitizeError> { match self { Protocol::PullRequest(filter, val) => { filter.sanitize()?; @@ -894,7 +897,7 @@ impl ClusterInfo { } } - pub(crate) fn push_epoch_slots(&self, mut update: &[Slot]) { + pub fn push_epoch_slots(&self, mut update: &[Slot]) { let current_slots: Vec<_> = { let gossip = self.time_gossip_read_lock("lookup_epoch_slots", &self.stats.epoch_slots_lookup); @@ -968,7 +971,7 @@ impl ClusterInfo { GossipWriteLock::new(self.gossip.write().unwrap(), label, counter) } - pub(crate) fn push_message(&self, message: CrdsValue) { + pub fn push_message(&self, message: CrdsValue) { self.local_message_pending_push_queue .lock() .unwrap() @@ -1094,7 +1097,11 @@ impl ClusterInfo { } } - pub fn send_vote(&self, vote: &Transaction, tpu: Option) -> Result<()> { + pub fn send_vote( + &self, + vote: &Transaction, + tpu: Option, + ) -> Result<(), GossipError> { let tpu = tpu.unwrap_or_else(|| self.my_contact_info().tpu); let buf = serialize(vote)?; self.socket.send_to(&buf, &tpu)?; @@ -1119,7 +1126,11 @@ impl ClusterInfo { (labels, txs) } - pub(crate) fn push_duplicate_shred(&self, shred: &Shred, other_payload: &[u8]) -> Result<()> { + pub fn push_duplicate_shred( + &self, + shred: &Shred, + other_payload: &[u8], + ) -> Result<(), GossipError> { self.gossip.write().unwrap().push_duplicate_shred( &self.keypair, shred, @@ -1154,7 +1165,7 @@ impl ClusterInfo { .map(map) } - pub(crate) fn get_epoch_slots(&self, cursor: &mut Cursor) -> Vec { + pub fn get_epoch_slots(&self, cursor: &mut Cursor) -> Vec { let gossip = self.gossip.read().unwrap(); let entries = gossip.crds.get_epoch_slots(cursor); entries @@ -1203,7 +1214,7 @@ impl ClusterInfo { } // All nodes in gossip (including spy nodes) and the last time we heard about them - pub(crate) fn all_peers(&self) -> Vec<(ContactInfo, u64)> { + pub fn all_peers(&self) -> Vec<(ContactInfo, u64)> { self.gossip .read() .unwrap() @@ -1376,7 +1387,7 @@ impl ClusterInfo { packet: &Packet, s: &UdpSocket, forwarded: bool, - ) -> Result<()> { + ) -> Result<(), GossipError> { trace!("retransmit orders {}", peers.len()); let dests: Vec<_> = if forwarded { peers @@ -1398,7 +1409,7 @@ impl ClusterInfo { 1 ); error!("retransmit result {:?}", e); - return Err(Error::Io(e)); + return Err(GossipError::Io(e)); } } } @@ -1561,7 +1572,7 @@ impl ClusterInfo { let mut push_queue = self.local_message_pending_push_queue.lock().unwrap(); std::mem::take(&mut *push_queue) } - #[cfg(test)] + // Used in tests pub fn flush_push_queue(&self) { let pending_push_messages = self.drain_push_queue(); let mut gossip = self.gossip.write().unwrap(); @@ -1649,7 +1660,7 @@ impl ClusterInfo { sender: &PacketSender, generate_pull_requests: bool, require_stake_for_gossip: bool, - ) -> Result<()> { + ) -> Result<(), GossipError> { let reqs = self.generate_new_gossip_requests( thread_pool, gossip_validators, @@ -2491,7 +2502,7 @@ impl ClusterInfo { feature_set: Option<&FeatureSet>, epoch_duration: Duration, should_check_duplicate_instance: bool, - ) -> Result<()> { + ) -> Result<(), GossipError> { let _st = ScopedTimer::from(&self.stats.process_gossip_packets_time); self.stats .packets_received_count @@ -2517,7 +2528,7 @@ impl ClusterInfo { if should_check_duplicate_instance { for value in values { if self.instance.check_duplicate(value) { - return Err(Error::DuplicateNodeInstance); + return Err(GossipError::DuplicateNodeInstance); } } } @@ -2605,7 +2616,7 @@ impl ClusterInfo { thread_pool: &ThreadPool, last_print: &mut Instant, should_check_duplicate_instance: bool, - ) -> Result<()> { + ) -> Result<(), GossipError> { const RECV_TIMEOUT: Duration = Duration::from_secs(1); const SUBMIT_GOSSIP_STATS_INTERVAL: Duration = Duration::from_secs(2); let packets: Vec<_> = requests_receiver.recv_timeout(RECV_TIMEOUT)?.packets.into(); @@ -2678,7 +2689,7 @@ impl ClusterInfo { should_check_duplicate_instance, ) { match err { - Error::RecvTimeoutError(_) => { + GossipError::RecvTimeoutError(_) => { let table_size = self.gossip.read().unwrap().crds.len(); debug!( "{}: run_listen timeout, table size: {}", @@ -2686,7 +2697,7 @@ impl ClusterInfo { table_size, ); } - Error::DuplicateNodeInstance => { + GossipError::DuplicateNodeInstance => { error!( "duplicate running instances of the same validator node: {}", self.id() @@ -3013,7 +3024,7 @@ pub fn push_messages_to_peer( messages: Vec, self_id: Pubkey, peer_gossip: SocketAddr, -) -> Result<()> { +) -> Result<(), GossipError> { let reqs: Vec<_> = ClusterInfo::split_gossip_messages(PUSH_MESSAGE_MAX_PAYLOAD_SIZE, messages) .map(move |payload| (peer_gossip, Protocol::PushMessage(self_id, payload))) .collect(); @@ -3033,21 +3044,25 @@ pub fn stake_weight_peers( #[cfg(test)] mod tests { - use super::*; - use crate::{ - crds_gossip_pull::tests::MIN_NUM_BLOOM_FILTERS, - crds_value::{CrdsValue, CrdsValueLabel, Vote as CrdsVote}, - duplicate_shred::{self, tests::new_rand_shred, MAX_DUPLICATE_SHREDS}, + use { + super::*, + crate::{ + crds_gossip_pull::tests::MIN_NUM_BLOOM_FILTERS, + crds_value::{CrdsValue, CrdsValueLabel, Vote as CrdsVote}, + duplicate_shred::{self, tests::new_rand_shred, MAX_DUPLICATE_SHREDS}, + }, + itertools::izip, + rand::{seq::SliceRandom, SeedableRng}, + rand_chacha::ChaChaRng, + solana_ledger::shred::Shredder, + solana_sdk::signature::{Keypair, Signer}, + solana_vote_program::{vote_instruction, vote_state::Vote}, + std::{ + iter::repeat_with, + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4}, + sync::Arc, + }, }; - use itertools::izip; - use rand::{seq::SliceRandom, SeedableRng}; - use rand_chacha::ChaChaRng; - use solana_ledger::shred::Shredder; - use solana_sdk::signature::{Keypair, Signer}; - use solana_vote_program::{vote_instruction, vote_state::Vote}; - use std::iter::repeat_with; - use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4}; - use std::sync::Arc; #[test] fn test_gossip_node() { diff --git a/core/src/cluster_info_metrics.rs b/gossip/src/cluster_info_metrics.rs similarity index 97% rename from core/src/cluster_info_metrics.rs rename to gossip/src/cluster_info_metrics.rs index 832e335ea6..baac2f5438 100644 --- a/core/src/cluster_info_metrics.rs +++ b/gossip/src/cluster_info_metrics.rs @@ -1,13 +1,15 @@ -use crate::crds_gossip::CrdsGossip; -use solana_measure::measure::Measure; -use solana_sdk::pubkey::Pubkey; -use std::{ - collections::HashMap, - sync::{ - atomic::{AtomicU64, Ordering}, - RwLock, +use { + crate::crds_gossip::CrdsGossip, + solana_measure::measure::Measure, + solana_sdk::pubkey::Pubkey, + std::{ + collections::HashMap, + sync::{ + atomic::{AtomicU64, Ordering}, + RwLock, + }, + time::Instant, }, - time::Instant, }; #[derive(Default)] diff --git a/core/src/contact_info.rs b/gossip/src/contact_info.rs similarity index 95% rename from core/src/contact_info.rs rename to gossip/src/contact_info.rs index eafaf636ba..6471c30dac 100644 --- a/core/src/contact_info.rs +++ b/gossip/src/contact_info.rs @@ -1,12 +1,14 @@ -use crate::crds_value::MAX_WALLCLOCK; -use solana_sdk::pubkey::Pubkey; -#[cfg(test)] -use solana_sdk::rpc_port; -use solana_sdk::sanitize::{Sanitize, SanitizeError}; -#[cfg(test)] -use solana_sdk::signature::{Keypair, Signer}; -use solana_sdk::timing::timestamp; -use std::net::{IpAddr, SocketAddr}; +use { + crate::crds_value::MAX_WALLCLOCK, + solana_sdk::{ + pubkey::Pubkey, + rpc_port, + sanitize::{Sanitize, SanitizeError}, + signature::{Keypair, Signer}, + timing::timestamp, + }, + std::net::{IpAddr, SocketAddr}, +}; /// Structure representing a node on the network #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, AbiExample, Deserialize, Serialize)] @@ -132,8 +134,8 @@ impl ContactInfo { } } - #[cfg(test)] - pub(crate) fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self { + // Used in tests + pub fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self { fn next_port(addr: &SocketAddr, nxt: u16) -> SocketAddr { let mut nxt_addr = *addr; nxt_addr.set_port(addr.port() + nxt); @@ -166,8 +168,8 @@ impl ContactInfo { } } - #[cfg(test)] - pub(crate) fn new_with_socketaddr(bind_addr: &SocketAddr) -> Self { + // Used in tests + pub fn new_with_socketaddr(bind_addr: &SocketAddr) -> Self { let keypair = Keypair::new(); Self::new_with_pubkey_socketaddr(&keypair.pubkey(), bind_addr) } diff --git a/core/src/crds.rs b/gossip/src/crds.rs similarity index 98% rename from core/src/crds.rs rename to gossip/src/crds.rs index f03848bc18..bd197647aa 100644 --- a/core/src/crds.rs +++ b/gossip/src/crds.rs @@ -24,19 +24,27 @@ //! A value is updated to a new version if the labels match, and the value //! wallclock is later, or the value hash is greater. -use crate::contact_info::ContactInfo; -use crate::crds_shards::CrdsShards; -use crate::crds_value::{CrdsData, CrdsValue, CrdsValueLabel, LowestSlot}; -use bincode::serialize; -use indexmap::map::{rayon::ParValues, Entry, IndexMap}; -use indexmap::set::IndexSet; -use rayon::{prelude::*, ThreadPool}; -use solana_sdk::hash::{hash, Hash}; -use solana_sdk::pubkey::Pubkey; -use std::{ - cmp::Ordering, - collections::{hash_map, BTreeMap, HashMap, VecDeque}, - ops::{Bound, Index, IndexMut}, +use { + crate::{ + contact_info::ContactInfo, + crds_shards::CrdsShards, + crds_value::{CrdsData, CrdsValue, CrdsValueLabel, LowestSlot}, + }, + bincode::serialize, + indexmap::{ + map::{rayon::ParValues, Entry, IndexMap}, + set::IndexSet, + }, + rayon::{prelude::*, ThreadPool}, + solana_sdk::{ + hash::{hash, Hash}, + pubkey::Pubkey, + }, + std::{ + cmp::Ordering, + collections::{hash_map, BTreeMap, HashMap, VecDeque}, + ops::{Bound, Index, IndexMut}, + }, }; const CRDS_SHARDS_BITS: u32 = 8; @@ -539,16 +547,18 @@ impl Crds { #[cfg(test)] mod test { - use super::*; - use crate::{ - contact_info::ContactInfo, - crds_value::{new_rand_timestamp, NodeInstance}, + use { + super::*, + crate::{ + contact_info::ContactInfo, + crds_value::{new_rand_timestamp, NodeInstance}, + }, + rand::{thread_rng, Rng, SeedableRng}, + rand_chacha::ChaChaRng, + rayon::ThreadPoolBuilder, + solana_sdk::signature::{Keypair, Signer}, + std::{collections::HashSet, iter::repeat_with}, }; - use rand::{thread_rng, Rng, SeedableRng}; - use rand_chacha::ChaChaRng; - use rayon::ThreadPoolBuilder; - use solana_sdk::signature::{Keypair, Signer}; - use std::{collections::HashSet, iter::repeat_with}; #[test] fn test_insert() { diff --git a/core/src/crds_gossip.rs b/gossip/src/crds_gossip.rs similarity index 92% rename from core/src/crds_gossip.rs rename to gossip/src/crds_gossip.rs index 5a2d08a644..18c7991f3b 100644 --- a/core/src/crds_gossip.rs +++ b/gossip/src/crds_gossip.rs @@ -3,31 +3,33 @@ //! designed to run with a simulator or over a UDP network connection with messages up to a //! packet::PACKET_DATA_SIZE size. -use crate::{ - cluster_info::Ping, - contact_info::ContactInfo, - crds::Crds, - crds_gossip_error::CrdsGossipError, - crds_gossip_pull::{CrdsFilter, CrdsGossipPull, ProcessPullStats}, - crds_gossip_push::{CrdsGossipPush, CRDS_GOSSIP_NUM_ACTIVE}, - crds_value::{CrdsData, CrdsValue}, - duplicate_shred::{self, DuplicateShredIndex, LeaderScheduleFn, MAX_DUPLICATE_SHREDS}, - ping_pong::PingCache, -}; -use itertools::Itertools; -use rayon::ThreadPool; -use solana_ledger::shred::Shred; -use solana_sdk::{ - hash::Hash, - pubkey::Pubkey, - signature::{Keypair, Signer}, - timing::timestamp, -}; -use std::{ - collections::{HashMap, HashSet}, - net::SocketAddr, - sync::Mutex, - time::Duration, +use { + crate::{ + cluster_info::Ping, + contact_info::ContactInfo, + crds::Crds, + crds_gossip_error::CrdsGossipError, + crds_gossip_pull::{CrdsFilter, CrdsGossipPull, ProcessPullStats}, + crds_gossip_push::{CrdsGossipPush, CRDS_GOSSIP_NUM_ACTIVE}, + crds_value::{CrdsData, CrdsValue}, + duplicate_shred::{self, DuplicateShredIndex, LeaderScheduleFn, MAX_DUPLICATE_SHREDS}, + ping_pong::PingCache, + }, + itertools::Itertools, + rayon::ThreadPool, + solana_ledger::shred::Shred, + solana_sdk::{ + hash::Hash, + pubkey::Pubkey, + signature::{Keypair, Signer}, + timing::timestamp, + }, + std::{ + collections::{HashMap, HashSet}, + net::SocketAddr, + sync::Mutex, + time::Duration, + }, }; pub struct CrdsGossip { @@ -361,11 +363,11 @@ pub fn get_weight(max_weight: f32, time_since_last_selected: u32, stake: f32) -> #[cfg(test)] mod test { - use super::*; - use crate::contact_info::ContactInfo; - use crate::crds_value::CrdsData; - use solana_sdk::hash::hash; - use solana_sdk::timing::timestamp; + use { + super::*, + crate::{contact_info::ContactInfo, crds_value::CrdsData}, + solana_sdk::{hash::hash, timing::timestamp}, + }; #[test] fn test_prune_errors() { diff --git a/core/src/crds_gossip_error.rs b/gossip/src/crds_gossip_error.rs similarity index 100% rename from core/src/crds_gossip_error.rs rename to gossip/src/crds_gossip_error.rs diff --git a/core/src/crds_gossip_pull.rs b/gossip/src/crds_gossip_pull.rs similarity index 97% rename from core/src/crds_gossip_pull.rs rename to gossip/src/crds_gossip_pull.rs index 357a31d92e..d01e8887d2 100644 --- a/core/src/crds_gossip_pull.rs +++ b/gossip/src/crds_gossip_pull.rs @@ -9,32 +9,37 @@ //! with random hash functions. So each subsequent request will have a different distribution //! of false positives. -use crate::{ - cluster_info::{Ping, CRDS_UNIQUE_PUBKEY_CAPACITY}, - contact_info::ContactInfo, - crds::Crds, - crds_gossip::{get_stake, get_weight}, - crds_gossip_error::CrdsGossipError, - crds_value::CrdsValue, - ping_pong::PingCache, -}; -use itertools::Itertools; -use lru::LruCache; -use rand::distributions::{Distribution, WeightedIndex}; -use rand::Rng; -use rayon::{prelude::*, ThreadPool}; -use solana_runtime::bloom::{AtomicBloom, Bloom}; -use solana_sdk::{ - hash::{hash, Hash}, - pubkey::Pubkey, - signature::{Keypair, Signer}, -}; -use std::{ - collections::{HashMap, HashSet, VecDeque}, - convert::TryInto, - net::SocketAddr, - sync::Mutex, - time::{Duration, Instant}, +use { + crate::{ + cluster_info::{Ping, CRDS_UNIQUE_PUBKEY_CAPACITY}, + contact_info::ContactInfo, + crds::Crds, + crds_gossip::{get_stake, get_weight}, + crds_gossip_error::CrdsGossipError, + crds_value::CrdsValue, + ping_pong::PingCache, + }, + itertools::Itertools, + lru::LruCache, + rand::{ + distributions::{Distribution, WeightedIndex}, + Rng, + }, + rayon::{prelude::*, ThreadPool}, + solana_runtime::bloom::{AtomicBloom, Bloom}, + solana_sdk::{ + hash::{hash, Hash}, + pubkey::Pubkey, + signature::{Keypair, Signer}, + }, + std::{ + collections::{HashMap, HashSet, VecDeque}, + convert::TryInto, + iter::repeat_with, + net::SocketAddr, + sync::Mutex, + time::{Duration, Instant}, + }, }; pub const CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS: u64 = 15000; @@ -140,11 +145,10 @@ impl CrdsFilterSet { let max_bits = (max_bytes * 8) as f64; let max_items = CrdsFilter::max_items(max_bits, FALSE_RATE, KEYS); let mask_bits = CrdsFilter::mask_bits(num_items as f64, max_items as f64); - let filters = std::iter::repeat_with(|| { - Bloom::random(max_items as usize, FALSE_RATE, max_bits as usize).into() - }) - .take(1 << mask_bits) - .collect(); + let filters = + repeat_with(|| Bloom::random(max_items as usize, FALSE_RATE, max_bits as usize).into()) + .take(1 << mask_bits) + .collect(); Self { filters, mask_bits } } @@ -238,7 +242,7 @@ impl CrdsGossipPull { let num_samples = peers.len() * 2; let index = WeightedIndex::new(weights).unwrap(); let sample_peer = move || peers[index.sample(&mut rng)]; - std::iter::repeat_with(sample_peer).take(num_samples) + repeat_with(sample_peer).take(num_samples) }; let peer = { let mut rng = rand::thread_rng(); @@ -607,20 +611,23 @@ impl CrdsGossipPull { } #[cfg(test)] pub(crate) mod tests { - use super::*; - use crate::cluster_info::MAX_BLOOM_SIZE; - use crate::contact_info::ContactInfo; - use crate::crds_value::{CrdsData, Vote}; - use itertools::Itertools; - use rand::{seq::SliceRandom, thread_rng}; - use rayon::ThreadPoolBuilder; - use solana_perf::test_tx::test_tx; - use solana_sdk::{ - hash::{hash, HASH_BYTES}, - packet::PACKET_DATA_SIZE, - timing::timestamp, + use { + super::*, + crate::{ + cluster_info::MAX_BLOOM_SIZE, + contact_info::ContactInfo, + crds_value::{CrdsData, Vote}, + }, + itertools::Itertools, + rand::{seq::SliceRandom, thread_rng}, + rayon::ThreadPoolBuilder, + solana_perf::test_tx::test_tx, + solana_sdk::{ + hash::{hash, HASH_BYTES}, + packet::PACKET_DATA_SIZE, + timing::timestamp, + }, }; - use std::{iter::repeat_with, time::Duration}; #[cfg(debug_assertions)] pub(crate) const MIN_NUM_BLOOM_FILTERS: usize = 1; @@ -816,7 +823,7 @@ pub(crate) mod tests { let mut rng = thread_rng(); let crds_filter_set = CrdsFilterSet::new(/*num_items=*/ 9672788, /*max_bytes=*/ 8196); - let hash_values: Vec<_> = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) + let hash_values: Vec<_> = repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) .take(1024) .collect(); for hash_value in &hash_values { diff --git a/core/src/crds_gossip_push.rs b/gossip/src/crds_gossip_push.rs similarity index 97% rename from core/src/crds_gossip_push.rs rename to gossip/src/crds_gossip_push.rs index 595c97680b..8daa532d9b 100644 --- a/core/src/crds_gossip_push.rs +++ b/gossip/src/crds_gossip_push.rs @@ -8,25 +8,27 @@ //! the local nodes wallclock window they are dropped silently. //! 2. The prune set is stored in a Bloom filter. -use crate::{ - cluster_info::CRDS_UNIQUE_PUBKEY_CAPACITY, - contact_info::ContactInfo, - crds::{Crds, Cursor}, - crds_gossip::{get_stake, get_weight}, - crds_gossip_error::CrdsGossipError, - crds_value::CrdsValue, - weighted_shuffle::weighted_shuffle, -}; -use bincode::serialized_size; -use indexmap::map::IndexMap; -use lru::LruCache; -use rand::{seq::SliceRandom, Rng}; -use solana_runtime::bloom::{AtomicBloom, Bloom}; -use solana_sdk::{packet::PACKET_DATA_SIZE, pubkey::Pubkey, timing::timestamp}; -use std::{ - cmp, - collections::{HashMap, HashSet}, - ops::RangeBounds, +use { + crate::{ + cluster_info::CRDS_UNIQUE_PUBKEY_CAPACITY, + contact_info::ContactInfo, + crds::{Crds, Cursor}, + crds_gossip::{get_stake, get_weight}, + crds_gossip_error::CrdsGossipError, + crds_value::CrdsValue, + weighted_shuffle::weighted_shuffle, + }, + bincode::serialized_size, + indexmap::map::IndexMap, + lru::LruCache, + rand::{seq::SliceRandom, Rng}, + solana_runtime::bloom::{AtomicBloom, Bloom}, + solana_sdk::{packet::PACKET_DATA_SIZE, pubkey::Pubkey, timing::timestamp}, + std::{ + cmp, + collections::{HashMap, HashSet}, + ops::RangeBounds, + }, }; pub const CRDS_GOSSIP_NUM_ACTIVE: usize = 30; @@ -395,9 +397,10 @@ impl CrdsGossipPush { #[cfg(test)] mod test { - use super::*; - use crate::contact_info::ContactInfo; - use crate::crds_value::CrdsData; + use { + super::*, + crate::{contact_info::ContactInfo, crds_value::CrdsData}, + }; #[test] fn test_prune() { diff --git a/core/src/crds_shards.rs b/gossip/src/crds_shards.rs similarity index 94% rename from core/src/crds_shards.rs rename to gossip/src/crds_shards.rs index 74bef44b85..9412ac0a03 100644 --- a/core/src/crds_shards.rs +++ b/gossip/src/crds_shards.rs @@ -1,8 +1,11 @@ -use crate::crds::VersionedCrdsValue; -use crate::crds_gossip_pull::CrdsFilter; -use indexmap::map::IndexMap; -use std::cmp::Ordering; -use std::ops::{Index, IndexMut}; +use { + crate::{crds::VersionedCrdsValue, crds_gossip_pull::CrdsFilter}, + indexmap::map::IndexMap, + std::{ + cmp::Ordering, + ops::{Index, IndexMut}, + }, +}; #[derive(Clone)] pub struct CrdsShards { @@ -129,11 +132,13 @@ where #[cfg(test)] mod test { - use super::*; - use crate::{crds::Crds, crds_value::CrdsValue}; - use rand::{thread_rng, Rng}; - use solana_sdk::timing::timestamp; - use std::{collections::HashSet, iter::repeat_with, ops::Index}; + use { + super::*, + crate::{crds::Crds, crds_value::CrdsValue}, + rand::{thread_rng, Rng}, + solana_sdk::timing::timestamp, + std::{collections::HashSet, iter::repeat_with, ops::Index}, + }; fn new_test_crds_value(rng: &mut R) -> VersionedCrdsValue { let value = CrdsValue::new_rand(rng, None); diff --git a/core/src/crds_value.rs b/gossip/src/crds_value.rs similarity index 96% rename from core/src/crds_value.rs rename to gossip/src/crds_value.rs index 5fce1a2286..02c1b623b6 100644 --- a/core/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -1,28 +1,30 @@ -use crate::{ - cluster_info::MAX_SNAPSHOT_HASHES, - contact_info::ContactInfo, - deprecated, - duplicate_shred::{DuplicateShred, DuplicateShredIndex, MAX_DUPLICATE_SHREDS}, - epoch_slots::EpochSlots, -}; -use bincode::{serialize, serialized_size}; -use rand::{CryptoRng, Rng}; -use serde::de::{Deserialize, Deserializer}; -use solana_sdk::sanitize::{Sanitize, SanitizeError}; -use solana_sdk::timing::timestamp; -use solana_sdk::{ - clock::Slot, - hash::Hash, - pubkey::{self, Pubkey}, - signature::{Keypair, Signable, Signature, Signer}, - transaction::Transaction, -}; -use solana_vote_program::vote_transaction::parse_vote_transaction; -use std::{ - borrow::{Borrow, Cow}, - cmp::Ordering, - collections::{hash_map::Entry, BTreeSet, HashMap}, - fmt, +use { + crate::{ + cluster_info::MAX_SNAPSHOT_HASHES, + contact_info::ContactInfo, + deprecated, + duplicate_shred::{DuplicateShred, DuplicateShredIndex, MAX_DUPLICATE_SHREDS}, + epoch_slots::EpochSlots, + }, + bincode::{serialize, serialized_size}, + rand::{CryptoRng, Rng}, + serde::de::{Deserialize, Deserializer}, + solana_sdk::sanitize::{Sanitize, SanitizeError}, + solana_sdk::timing::timestamp, + solana_sdk::{ + clock::Slot, + hash::Hash, + pubkey::{self, Pubkey}, + signature::{Keypair, Signable, Signature, Signer}, + transaction::Transaction, + }, + solana_vote_program::vote_transaction::parse_vote_transaction, + std::{ + borrow::{Borrow, Cow}, + cmp::Ordering, + collections::{hash_map::Entry, BTreeSet, HashMap}, + fmt, + }, }; pub const MAX_WALLCLOCK: u64 = 1_000_000_000_000_000; @@ -684,17 +686,20 @@ pub(crate) fn sanitize_wallclock(wallclock: u64) -> Result<(), SanitizeError> { #[cfg(test)] mod test { - use super::*; - use crate::contact_info::ContactInfo; - use bincode::{deserialize, Options}; - use rand::SeedableRng; - use rand_chacha::ChaChaRng; - use solana_perf::test_tx::test_tx; - use solana_sdk::signature::{Keypair, Signer}; - use solana_sdk::timing::timestamp; - use solana_vote_program::{vote_instruction, vote_state}; - use std::cmp::Ordering; - use std::iter::repeat_with; + use { + super::*, + crate::contact_info::ContactInfo, + bincode::{deserialize, Options}, + rand::SeedableRng, + rand_chacha::ChaChaRng, + solana_perf::test_tx::test_tx, + solana_sdk::{ + signature::{Keypair, Signer}, + timing::timestamp, + }, + solana_vote_program::{vote_instruction, vote_state}, + std::{cmp::Ordering, iter::repeat_with}, + }; #[test] fn test_keys_and_values() { diff --git a/core/src/data_budget.rs b/gossip/src/data_budget.rs similarity index 98% rename from core/src/data_budget.rs rename to gossip/src/data_budget.rs index c73e981a55..cab20bd6fd 100644 --- a/core/src/data_budget.rs +++ b/gossip/src/data_budget.rs @@ -87,8 +87,7 @@ impl DataBudget { #[cfg(test)] mod tests { - use super::*; - use std::time::Duration; + use {super::*, std::time::Duration}; #[test] fn test_data_budget() { diff --git a/core/src/deprecated.rs b/gossip/src/deprecated.rs similarity index 100% rename from core/src/deprecated.rs rename to gossip/src/deprecated.rs diff --git a/core/src/duplicate_shred.rs b/gossip/src/duplicate_shred.rs similarity index 96% rename from core/src/duplicate_shred.rs rename to gossip/src/duplicate_shred.rs index db67f08f6f..ba7c330a59 100644 --- a/core/src/duplicate_shred.rs +++ b/gossip/src/duplicate_shred.rs @@ -1,20 +1,22 @@ -use crate::crds_value::sanitize_wallclock; -use itertools::Itertools; -use solana_ledger::{ - blockstore_meta::DuplicateSlotProof, - shred::{Shred, ShredError, ShredType}, +use { + crate::crds_value::sanitize_wallclock, + itertools::Itertools, + solana_ledger::{ + blockstore_meta::DuplicateSlotProof, + shred::{Shred, ShredError, ShredType}, + }, + solana_sdk::{ + clock::Slot, + pubkey::Pubkey, + sanitize::{Sanitize, SanitizeError}, + }, + std::{ + collections::{hash_map::Entry, HashMap}, + convert::TryFrom, + num::TryFromIntError, + }, + thiserror::Error, }; -use solana_sdk::{ - clock::Slot, - pubkey::Pubkey, - sanitize::{Sanitize, SanitizeError}, -}; -use std::{ - collections::{hash_map::Entry, HashMap}, - convert::TryFrom, - num::TryFromIntError, -}; -use thiserror::Error; const DUPLICATE_SHRED_HEADER_SIZE: usize = 63; diff --git a/core/src/epoch_slots.rs b/gossip/src/epoch_slots.rs similarity index 97% rename from core/src/epoch_slots.rs rename to gossip/src/epoch_slots.rs index e3061e5e90..423bb64c0e 100644 --- a/core/src/epoch_slots.rs +++ b/gossip/src/epoch_slots.rs @@ -1,11 +1,17 @@ -use crate::cluster_info::MAX_CRDS_OBJECT_SIZE; -use crate::crds_value::{self, MAX_SLOT, MAX_WALLCLOCK}; -use bincode::serialized_size; -use bv::BitVec; -use flate2::{Compress, Compression, Decompress, FlushCompress, FlushDecompress}; -use solana_sdk::clock::Slot; -use solana_sdk::pubkey::Pubkey; -use solana_sdk::sanitize::{Sanitize, SanitizeError}; +use { + crate::{ + cluster_info::MAX_CRDS_OBJECT_SIZE, + crds_value::{self, MAX_SLOT, MAX_WALLCLOCK}, + }, + bincode::serialized_size, + bv::BitVec, + flate2::{Compress, Compression, Decompress, FlushCompress, FlushDecompress}, + solana_sdk::{ + clock::Slot, + pubkey::Pubkey, + sanitize::{Sanitize, SanitizeError}, + }, +}; const MAX_SLOTS_PER_ENTRY: usize = 2048 * 8; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, AbiExample)] diff --git a/gossip/src/gossip_error.rs b/gossip/src/gossip_error.rs new file mode 100644 index 0000000000..df2be3a9c7 --- /dev/null +++ b/gossip/src/gossip_error.rs @@ -0,0 +1,27 @@ +use { + crate::duplicate_shred, + std::{io, sync}, + thiserror::Error, +}; + +#[derive(Error, Debug)] +pub enum GossipError { + #[error("duplicate node instance")] + DuplicateNodeInstance, + #[error(transparent)] + DuplicateShredError(#[from] duplicate_shred::Error), + #[error(transparent)] + Io(#[from] io::Error), + #[error(transparent)] + RecvTimeoutError(#[from] sync::mpsc::RecvTimeoutError), + #[error("send error")] + SendError, + #[error("serialization error")] + Serialize(#[from] Box), +} + +impl std::convert::From> for GossipError { + fn from(_e: sync::mpsc::SendError) -> GossipError { + GossipError::SendError + } +} diff --git a/core/src/gossip_service.rs b/gossip/src/gossip_service.rs similarity index 93% rename from core/src/gossip_service.rs rename to gossip/src/gossip_service.rs index e5b7bb7355..4dbc6a50c7 100644 --- a/core/src/gossip_service.rs +++ b/gossip/src/gossip_service.rs @@ -1,26 +1,30 @@ //! The `gossip_service` module implements the network control plane. -use crate::cluster_info::{ClusterInfo, VALIDATOR_PORT_RANGE}; -use crate::contact_info::ContactInfo; -use rand::{thread_rng, Rng}; -use solana_client::thin_client::{create_client, ThinClient}; -use solana_perf::recycler::Recycler; -use solana_runtime::bank_forks::BankForks; -use solana_sdk::{ - pubkey::Pubkey, - signature::{Keypair, Signer}, -}; -use solana_streamer::streamer; -use std::{ - collections::HashSet, - net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket}, - sync::{ - atomic::{AtomicBool, Ordering}, - mpsc::channel, - {Arc, RwLock}, +use { + crate::{ + cluster_info::{ClusterInfo, VALIDATOR_PORT_RANGE}, + contact_info::ContactInfo, + }, + rand::{thread_rng, Rng}, + solana_client::thin_client::{create_client, ThinClient}, + solana_perf::recycler::Recycler, + solana_runtime::bank_forks::BankForks, + solana_sdk::{ + pubkey::Pubkey, + signature::{Keypair, Signer}, + }, + solana_streamer::streamer, + std::{ + collections::HashSet, + net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket}, + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::channel, + {Arc, RwLock}, + }, + thread::{self, sleep, JoinHandle}, + time::{Duration, Instant}, }, - thread::{self, sleep, JoinHandle}, - time::{Duration, Instant}, }; pub struct GossipService { @@ -305,10 +309,11 @@ fn make_gossip_node( #[cfg(test)] mod tests { - use super::*; - use crate::cluster_info::{ClusterInfo, Node}; - use std::sync::atomic::AtomicBool; - use std::sync::Arc; + use { + super::*, + crate::cluster_info::{ClusterInfo, Node}, + std::sync::{atomic::AtomicBool, Arc}, + }; #[test] #[ignore] diff --git a/gossip/src/lib.rs b/gossip/src/lib.rs new file mode 100644 index 0000000000..7562674a0c --- /dev/null +++ b/gossip/src/lib.rs @@ -0,0 +1,38 @@ +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] +#![allow(clippy::integer_arithmetic)] + +pub mod cluster_info; +mod cluster_info_metrics; +#[macro_use] +pub mod contact_info; +pub mod crds; +pub mod crds_gossip; +pub mod crds_gossip_error; +pub mod crds_gossip_pull; +pub mod crds_gossip_push; +pub mod crds_shards; +pub mod crds_value; +pub mod data_budget; +mod deprecated; +pub mod duplicate_shred; +pub mod epoch_slots; +pub mod gossip_error; +pub mod gossip_service; +pub mod ping_pong; +pub mod weighted_shuffle; + +#[macro_use] +extern crate log; + +#[cfg(test)] +#[macro_use] +extern crate matches; + +#[macro_use] +extern crate serde_derive; + +#[macro_use] +extern crate solana_frozen_abi_macro; + +#[macro_use] +extern crate solana_metrics; diff --git a/gossip/src/main.rs b/gossip/src/main.rs index 7f98c475e9..20f667ef24 100644 --- a/gossip/src/main.rs +++ b/gossip/src/main.rs @@ -1,21 +1,23 @@ //! A command-line executable for monitoring a cluster's gossip plane. -use clap::{ - crate_description, crate_name, value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches, - SubCommand, -}; -use solana_clap_utils::{ - input_parsers::keypair_of, - input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey}, -}; -use solana_core::{contact_info::ContactInfo, gossip_service::discover}; -use solana_sdk::pubkey::Pubkey; -use std::{ - error, - net::{IpAddr, Ipv4Addr, SocketAddr}, - process::exit, - sync::Arc, - time::Duration, +use { + clap::{ + crate_description, crate_name, value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches, + SubCommand, + }, + solana_clap_utils::{ + input_parsers::keypair_of, + input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey}, + }, + solana_gossip::{contact_info::ContactInfo, gossip_service::discover}, + solana_sdk::pubkey::Pubkey, + std::{ + error, + net::{IpAddr, Ipv4Addr, SocketAddr}, + process::exit, + sync::Arc, + time::Duration, + }, }; fn parse_matches() -> ArgMatches<'static> { diff --git a/core/src/ping_pong.rs b/gossip/src/ping_pong.rs similarity index 95% rename from core/src/ping_pong.rs rename to gossip/src/ping_pong.rs index 254ced3e67..e115077b99 100644 --- a/core/src/ping_pong.rs +++ b/gossip/src/ping_pong.rs @@ -1,14 +1,20 @@ -use bincode::{serialize, Error}; -use lru::LruCache; -use rand::{AsByteSliceMut, CryptoRng, Rng}; -use serde::Serialize; -use solana_sdk::hash::{self, Hash}; -use solana_sdk::pubkey::Pubkey; -use solana_sdk::sanitize::{Sanitize, SanitizeError}; -use solana_sdk::signature::{Keypair, Signable, Signature, Signer}; -use std::borrow::Cow; -use std::net::SocketAddr; -use std::time::{Duration, Instant}; +use { + bincode::{serialize, Error}, + lru::LruCache, + rand::{AsByteSliceMut, CryptoRng, Rng}, + serde::Serialize, + solana_sdk::{ + hash::{self, Hash}, + pubkey::Pubkey, + sanitize::{Sanitize, SanitizeError}, + signature::{Keypair, Signable, Signature, Signer}, + }, + std::{ + borrow::Cow, + net::SocketAddr, + time::{Duration, Instant}, + }, +}; #[derive(AbiExample, Debug, Deserialize, Serialize)] pub struct Ping { @@ -252,10 +258,14 @@ impl PingCache { #[cfg(test)] mod tests { - use super::*; - use std::collections::HashSet; - use std::iter::repeat_with; - use std::net::{Ipv4Addr, SocketAddrV4}; + use { + super::*, + std::{ + collections::HashSet, + iter::repeat_with, + net::{Ipv4Addr, SocketAddrV4}, + }, + }; type Token = [u8; 32]; diff --git a/core/src/weighted_shuffle.rs b/gossip/src/weighted_shuffle.rs similarity index 96% rename from core/src/weighted_shuffle.rs rename to gossip/src/weighted_shuffle.rs index b7c3306011..62e2d18eb6 100644 --- a/core/src/weighted_shuffle.rs +++ b/gossip/src/weighted_shuffle.rs @@ -1,11 +1,12 @@ //! The `weighted_shuffle` module provides an iterator over shuffled weights. -use itertools::Itertools; -use num_traits::{FromPrimitive, ToPrimitive}; -use rand::{Rng, SeedableRng}; -use rand_chacha::ChaChaRng; -use std::iter; -use std::ops::Div; +use { + itertools::Itertools, + num_traits::{FromPrimitive, ToPrimitive}, + rand::{Rng, SeedableRng}, + rand_chacha::ChaChaRng, + std::{iter, ops::Div}, +}; /// Returns a list of indexes shuffled based on the input weights /// Note - The sum of all weights must not exceed `u64::MAX` diff --git a/core/tests/cluster_info.rs b/gossip/tests/cluster_info.rs similarity index 94% rename from core/tests/cluster_info.rs rename to gossip/tests/cluster_info.rs index 10df1bd8f3..921a842c32 100644 --- a/core/tests/cluster_info.rs +++ b/gossip/tests/cluster_info.rs @@ -1,17 +1,21 @@ #![allow(clippy::integer_arithmetic)] -use rayon::iter::ParallelIterator; -use rayon::prelude::*; -use serial_test::serial; -use solana_core::cluster_info::{compute_retransmit_peers, ClusterInfo}; -use solana_core::contact_info::ContactInfo; -use solana_sdk::pubkey::Pubkey; -use std::collections::{HashMap, HashSet}; -use std::sync::mpsc::channel; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::{Receiver, Sender}; -use std::sync::Arc; -use std::sync::Mutex; -use std::time::Instant; +use { + rayon::{iter::ParallelIterator, prelude::*}, + serial_test::serial, + solana_gossip::{ + cluster_info::{compute_retransmit_peers, ClusterInfo}, + contact_info::ContactInfo, + }, + solana_sdk::pubkey::Pubkey, + std::{ + collections::{HashMap, HashSet}, + sync::{ + mpsc::{channel, Receiver, Sender, TryRecvError}, + Arc, Mutex, + }, + time::Instant, + }, +}; type Nodes = HashMap, Receiver<(i32, bool)>)>; diff --git a/core/tests/crds_gossip.rs b/gossip/tests/crds_gossip.rs similarity index 96% rename from core/tests/crds_gossip.rs rename to gossip/tests/crds_gossip.rs index 04339db235..da4c30191b 100644 --- a/core/tests/crds_gossip.rs +++ b/gossip/tests/crds_gossip.rs @@ -1,31 +1,32 @@ #![allow(clippy::integer_arithmetic)] -use bincode::serialized_size; -use log::*; -use rayon::prelude::*; -use rayon::{ThreadPool, ThreadPoolBuilder}; -use serial_test::serial; -use solana_core::{ - cluster_info, - contact_info::ContactInfo, - crds_gossip::*, - crds_gossip_error::CrdsGossipError, - crds_gossip_pull::{ProcessPullStats, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS}, - crds_gossip_push::CRDS_GOSSIP_PUSH_MSG_TIMEOUT_MS, - crds_value::{CrdsData, CrdsValue, CrdsValueLabel}, - ping_pong::PingCache, -}; -use solana_rayon_threadlimit::get_thread_count; -use solana_sdk::{ - hash::hash, - pubkey::Pubkey, - signature::{Keypair, Signer}, - timing::timestamp, -}; -use std::{ - collections::{HashMap, HashSet}, - ops::Deref, - sync::{Arc, Mutex}, - time::{Duration, Instant}, +use { + bincode::serialized_size, + log::*, + rayon::{prelude::*, ThreadPool, ThreadPoolBuilder}, + serial_test::serial, + solana_gossip::{ + cluster_info, + contact_info::ContactInfo, + crds_gossip::*, + crds_gossip_error::CrdsGossipError, + crds_gossip_pull::{ProcessPullStats, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS}, + crds_gossip_push::CRDS_GOSSIP_PUSH_MSG_TIMEOUT_MS, + crds_value::{CrdsData, CrdsValue, CrdsValueLabel}, + ping_pong::PingCache, + }, + solana_rayon_threadlimit::get_thread_count, + solana_sdk::{ + hash::hash, + pubkey::Pubkey, + signature::{Keypair, Signer}, + timing::timestamp, + }, + std::{ + collections::{HashMap, HashSet}, + ops::Deref, + sync::{Arc, Mutex}, + time::{Duration, Instant}, + }, }; #[derive(Clone)] diff --git a/core/tests/gossip.rs b/gossip/tests/gossip.rs similarity index 94% rename from core/tests/gossip.rs rename to gossip/tests/gossip.rs index b66b034cb8..970a9c58b9 100644 --- a/core/tests/gossip.rs +++ b/gossip/tests/gossip.rs @@ -2,28 +2,33 @@ #[macro_use] extern crate log; -use rayon::iter::*; -use solana_core::{ - cluster_info::{ClusterInfo, Node}, - crds::Cursor, - gossip_service::GossipService, +use { + rayon::iter::*, + solana_gossip::{ + cluster_info::{ClusterInfo, Node}, + crds::Cursor, + gossip_service::GossipService, + }, + solana_perf::packet::Packet, + solana_runtime::bank_forks::BankForks, + solana_sdk::{ + hash::Hash, + pubkey::Pubkey, + signature::{Keypair, Signer}, + timing::timestamp, + transaction::Transaction, + }, + solana_vote_program::{vote_instruction, vote_state::Vote}, + std::{ + net::UdpSocket, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, RwLock, + }, + thread::sleep, + time::Duration, + }, }; -use solana_runtime::bank_forks::BankForks; - -use solana_perf::packet::Packet; -use solana_sdk::{ - hash::Hash, - pubkey::Pubkey, - signature::{Keypair, Signer}, - timing::timestamp, - transaction::Transaction, -}; -use solana_vote_program::{vote_instruction, vote_state::Vote}; -use std::net::UdpSocket; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, RwLock}; -use std::thread::sleep; -use std::time::Duration; fn test_node(exit: &Arc) -> (Arc, GossipService, UdpSocket) { let keypair = Arc::new(Keypair::new()); diff --git a/local-cluster/Cargo.toml b/local-cluster/Cargo.toml index 5c1e3f307b..c72fab22d1 100644 --- a/local-cluster/Cargo.toml +++ b/local-cluster/Cargo.toml @@ -21,8 +21,9 @@ solana-config-program = { path = "../programs/config", version = "=1.7.0" } solana-core = { path = "../core", version = "=1.7.0" } solana-client = { path = "../client", version = "=1.7.0" } solana-download-utils = { path = "../download-utils", version = "=1.7.0" } -solana-faucet = { path = "../faucet", version = "=1.7.0" } solana-exchange-program = { path = "../programs/exchange", version = "=1.7.0" } +solana-faucet = { path = "../faucet", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-ledger = { path = "../ledger", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } solana-runtime = { path = "../runtime", version = "=1.7.0" } diff --git a/local-cluster/src/cluster.rs b/local-cluster/src/cluster.rs index fe369212d7..fff7d1df90 100644 --- a/local-cluster/src/cluster.rs +++ b/local-cluster/src/cluster.rs @@ -1,7 +1,7 @@ use solana_client::thin_client::ThinClient; -use solana_core::contact_info::ContactInfo; use solana_core::validator::Validator; use solana_core::validator::ValidatorConfig; +use solana_gossip::{cluster_info::Node, contact_info::ContactInfo}; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::Keypair; use std::path::PathBuf; @@ -44,10 +44,10 @@ pub trait Cluster { &mut self, pubkey: &Pubkey, cluster_validator_info: &mut ClusterValidatorInfo, - ) -> (solana_core::cluster_info::Node, Option); + ) -> (Node, Option); fn restart_node_with_context( cluster_validator_info: ClusterValidatorInfo, - restart_context: (solana_core::cluster_info::Node, Option), + restart_context: (Node, Option), ) -> ClusterValidatorInfo; fn add_node(&mut self, pubkey: &Pubkey, cluster_validator_info: ClusterValidatorInfo); fn exit_restart_node(&mut self, pubkey: &Pubkey, config: ValidatorConfig); diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index 6a9b0fe01c..e174e4bd81 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -6,10 +6,10 @@ use log::*; use rand::{thread_rng, Rng}; use rayon::prelude::*; use solana_client::thin_client::create_client; +use solana_core::consensus::VOTE_THRESHOLD_DEPTH; use solana_core::validator::ValidatorExit; -use solana_core::{ - cluster_info::VALIDATOR_PORT_RANGE, consensus::VOTE_THRESHOLD_DEPTH, contact_info::ContactInfo, - gossip_service::discover_cluster, +use solana_gossip::{ + cluster_info::VALIDATOR_PORT_RANGE, contact_info::ContactInfo, gossip_service::discover_cluster, }; use solana_ledger::{ blockstore::Blockstore, diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index fa4c18b12f..080adae347 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -6,11 +6,11 @@ use crate::{ use itertools::izip; use log::*; use solana_client::thin_client::{create_client, ThinClient}; -use solana_core::{ +use solana_core::validator::{Validator, ValidatorConfig, ValidatorStartProgress}; +use solana_gossip::{ cluster_info::{Node, VALIDATOR_PORT_RANGE}, contact_info::ContactInfo, gossip_service::discover_cluster, - validator::{Validator, ValidatorConfig, ValidatorStartProgress}, }; use solana_ledger::create_new_tmp_ledger; use solana_runtime::genesis_utils::{ @@ -628,7 +628,7 @@ impl Cluster for LocalCluster { &mut self, pubkey: &Pubkey, cluster_validator_info: &mut ClusterValidatorInfo, - ) -> (solana_core::cluster_info::Node, Option) { + ) -> (Node, Option) { // Update the stored ContactInfo for this node let node = Node::new_localhost_with_pubkey(&pubkey); cluster_validator_info.info.contact_info = node.info.clone(); diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 2ef5fd4e6c..8ae01e6a13 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -13,14 +13,16 @@ use solana_client::{ }; use solana_core::{ broadcast_stage::BroadcastStageType, - cluster_info::{self, VALIDATOR_PORT_RANGE}, consensus::{Tower, SWITCH_FORK_THRESHOLD, VOTE_THRESHOLD_DEPTH}, - crds_value::{self, CrdsData, CrdsValue}, - gossip_service::discover_cluster, optimistic_confirmation_verifier::OptimisticConfirmationVerifier, validator::ValidatorConfig, }; use solana_download_utils::{download_snapshot, DownloadProgressRecord}; +use solana_gossip::{ + cluster_info::{self, VALIDATOR_PORT_RANGE}, + crds_value::{self, CrdsData, CrdsValue}, + gossip_service::discover_cluster, +}; use solana_ledger::{ ancestor_iterator::AncestorIterator, blockstore::{Blockstore, PurgeType}, @@ -1393,7 +1395,7 @@ fn test_mainnet_beta_cluster_type() { let client = create_client( cluster.entry_point_info.client_facing_addr(), - solana_core::cluster_info::VALIDATOR_PORT_RANGE, + VALIDATOR_PORT_RANGE, ); // Programs that are available at epoch 0 diff --git a/validator/Cargo.toml b/validator/Cargo.toml index 1d494ba33b..82f22488ac 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -35,6 +35,7 @@ solana-core = { path = "../core", version = "=1.7.0" } solana-download-utils = { path = "../download-utils", version = "=1.7.0" } solana-faucet = { path = "../faucet", version = "=1.7.0" } solana-genesis-utils = { path = "../genesis-utils", version = "=1.7.0" } +solana-gossip = { path = "../gossip", version = "=1.7.0" } solana-ledger = { path = "../ledger", version = "=1.7.0" } solana-logger = { path = "../logger", version = "=1.7.0" } solana-metrics = { path = "../metrics", version = "=1.7.0" } diff --git a/validator/src/lib.rs b/validator/src/lib.rs index 1bff0650fc..4ac27d8833 100644 --- a/validator/src/lib.rs +++ b/validator/src/lib.rs @@ -1,5 +1,6 @@ #![allow(clippy::integer_arithmetic)] -pub use solana_core::{cluster_info::MINIMUM_VALIDATOR_PORT_RANGE_WIDTH, test_validator}; +pub use solana_core::test_validator; +pub use solana_gossip::cluster_info::MINIMUM_VALIDATOR_PORT_RANGE_WIDTH; use { console::style, indicatif::{ProgressDrawTarget, ProgressStyle}, diff --git a/validator/src/main.rs b/validator/src/main.rs index 7f8231e851..f3e69f2e8e 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -20,13 +20,8 @@ use { rpc_client::RpcClient, rpc_config::RpcLeaderScheduleConfig, rpc_request::MAX_MULTIPLE_ACCOUNTS, }, - solana_core::ledger_cleanup_service::{ - DEFAULT_MAX_LEDGER_SHREDS, DEFAULT_MIN_MAX_LEDGER_SHREDS, - }, solana_core::{ - cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE}, - contact_info::ContactInfo, - gossip_service::GossipService, + ledger_cleanup_service::{DEFAULT_MAX_LEDGER_SHREDS, DEFAULT_MIN_MAX_LEDGER_SHREDS}, poh_service, rpc::JsonRpcConfig, tpu::DEFAULT_TPU_COALESCE_MS, @@ -36,6 +31,11 @@ use { }, solana_download_utils::{download_snapshot, DownloadProgressRecord}, solana_genesis_utils::download_then_check_genesis_hash, + solana_gossip::{ + cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE}, + contact_info::ContactInfo, + gossip_service::GossipService, + }, solana_ledger::blockstore_db::BlockstoreRecoveryMode, solana_perf::recycler::enable_recycler_warming, solana_rpc::rpc_pubsub_service::PubSubConfig,