Skip to content

Commit

Permalink
Forward transactions to the expected leader instead of your own TPU p…
Browse files Browse the repository at this point in the history
…ort (solana-labs#12004)

* Use PoHRecorder to send to the right leader

* cleanup

* fmt

* clippy

* Cleanup, fix bug

Co-authored-by: Carl <carl@solana.com>
  • Loading branch information
aeyakovenko and carllin authored Sep 8, 2020
1 parent 9eebaa2 commit c67f8bd
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 65 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions banks-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ edition = "2018"
[dependencies]
bincode = "1.3.1"
futures = "0.3"
log = "0.4.8"
solana-banks-interface = { path = "../banks-interface", version = "1.4.0" }
solana-runtime = { path = "../runtime", version = "1.4.0" }
solana-sdk = { path = "../sdk", version = "1.4.0" }
solana-metrics = { path = "../metrics", version = "1.4.0" }
tarpc = { version = "0.21.0", features = ["full"] }
tokio = "0.2"
tokio-serde = { version = "0.6", features = ["bincode"] }
Expand Down
2 changes: 1 addition & 1 deletion banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::send_transaction_service::{SendTransactionService, TransactionInfo};
use bincode::{deserialize, serialize};
use futures::{
future,
Expand All @@ -8,7 +9,6 @@ use solana_runtime::{
bank::Bank,
bank_forks::BankForks,
commitment::{BlockCommitmentCache, CommitmentSlots},
send_transaction_service::{SendTransactionService, TransactionInfo},
};
use solana_sdk::{
account::Account,
Expand Down
4 changes: 4 additions & 0 deletions banks-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
pub mod banks_server;
pub mod rpc_banks_service;
pub mod send_transaction_service;

#[macro_use]
extern crate solana_metrics;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{bank::Bank, bank_forks::BankForks};
use log::*;
use solana_metrics::{datapoint_warn, inc_new_counter_info};
use solana_runtime::{bank::Bank, bank_forks::BankForks};
use solana_sdk::{clock::Slot, signature::Signature};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -205,8 +205,6 @@ mod test {

#[test]
fn process_transactions() {
solana_logger::setup();

let (genesis_config, mint_keypair) = create_genesis_config(4);
let bank = Bank::new(&genesis_config);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod rpc_pubsub;
pub mod rpc_pubsub_service;
pub mod rpc_service;
pub mod rpc_subscriptions;
pub mod send_transaction_service;
pub mod serve_repair;
pub mod serve_repair_service;
pub mod sigverify;
Expand Down
25 changes: 14 additions & 11 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//! The `rpc` module implements the Solana RPC interface.
use crate::{
cluster_info::ClusterInfo, contact_info::ContactInfo,
non_circulating_supply::calculate_non_circulating_supply, rpc_error::RpcCustomError,
rpc_health::*, validator::ValidatorExit,
cluster_info::ClusterInfo,
contact_info::ContactInfo,
non_circulating_supply::calculate_non_circulating_supply,
rpc_error::RpcCustomError,
rpc_health::*,
send_transaction_service::{SendTransactionService, TransactionInfo},
validator::ValidatorExit,
};
use bincode::{config::Options, serialize};
use jsonrpc_core::{types::error, Error, Metadata, Result};
Expand Down Expand Up @@ -36,7 +40,6 @@ use solana_runtime::{
bank::Bank,
bank_forks::BankForks,
commitment::{BlockCommitmentArray, BlockCommitmentCache, CommitmentSlots},
send_transaction_service::{SendTransactionService, TransactionInfo},
};
use solana_sdk::{
account::Account,
Expand Down Expand Up @@ -213,7 +216,7 @@ impl JsonRpcRequestProcessor {
let cluster_info = Arc::new(ClusterInfo::default());
let tpu_address = cluster_info.my_contact_info().tpu;
let (sender, receiver) = channel();
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);

Self {
config: JsonRpcConfig::default(),
Expand Down Expand Up @@ -2692,7 +2695,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);

cluster_info.insert_info(ContactInfo::new_with_pubkey_socketaddr(
&leader_pubkey,
Expand Down Expand Up @@ -4004,7 +4007,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);

let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
let res = io.handle_request_sync(req, meta);
Expand Down Expand Up @@ -4045,7 +4048,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);

let mut bad_transaction =
system_transaction::transfer(&mint_keypair, &Pubkey::new_rand(), 42, Hash::default());
Expand Down Expand Up @@ -4227,7 +4230,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);
assert_eq!(request_processor.validator_exit(), false);
assert_eq!(exit.load(Ordering::Relaxed), false);
}
Expand Down Expand Up @@ -4256,7 +4259,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);
assert_eq!(request_processor.validator_exit(), true);
assert_eq!(exit.load(Ordering::Relaxed), true);
}
Expand Down Expand Up @@ -4342,7 +4345,7 @@ pub mod tests {
&runtime::Runtime::new().unwrap(),
None,
);
SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver);
SendTransactionService::new(tpu_address, &bank_forks, None, &exit, receiver);
assert_eq!(
request_processor.get_block_commitment(0),
RpcBlockCommitment {
Expand Down
19 changes: 14 additions & 5 deletions core/src/rpc_service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//! The `rpc_service` module implements the Solana JSON RPC service.
use crate::{
bigtable_upload_service::BigTableUploadService, cluster_info::ClusterInfo, rpc::*,
rpc_health::*, validator::ValidatorExit,
bigtable_upload_service::BigTableUploadService,
cluster_info::ClusterInfo,
poh_recorder::PohRecorder,
rpc::*,
rpc_health::*,
send_transaction_service::{LeaderInfo, SendTransactionService},
validator::ValidatorExit,
};
use jsonrpc_core::MetaIoHandler;
use jsonrpc_http_server::{
Expand All @@ -14,7 +19,6 @@ use solana_ledger::blockstore::Blockstore;
use solana_runtime::{
bank_forks::{BankForks, SnapshotConfig},
commitment::BlockCommitmentCache,
send_transaction_service::SendTransactionService,
snapshot_utils,
};
use solana_sdk::{hash::Hash, native_token::lamports_to_sol, pubkey::Pubkey};
Expand All @@ -23,7 +27,7 @@ use std::{
net::SocketAddr,
path::{Path, PathBuf},
sync::atomic::{AtomicBool, Ordering},
sync::{mpsc::channel, Arc, RwLock},
sync::{mpsc::channel, Arc, Mutex, RwLock},
thread::{self, Builder, JoinHandle},
};
use tokio::runtime;
Expand Down Expand Up @@ -239,6 +243,7 @@ impl JsonRpcService {
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
blockstore: Arc<Blockstore>,
cluster_info: Arc<ClusterInfo>,
poh_recorder: Option<Arc<Mutex<PohRecorder>>>,
genesis_hash: Hash,
ledger_path: &Path,
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
Expand Down Expand Up @@ -302,16 +307,19 @@ impl JsonRpcService {
blockstore,
validator_exit.clone(),
health.clone(),
cluster_info,
cluster_info.clone(),
genesis_hash,
&runtime,
bigtable_ledger_storage,
);

let exit_send_transaction_service = Arc::new(AtomicBool::new(false));
let leader_info =
poh_recorder.map(|recorder| LeaderInfo::new(cluster_info.clone(), recorder));
let _send_transaction_service = Arc::new(SendTransactionService::new(
tpu_address,
&bank_forks,
leader_info,
&exit_send_transaction_service,
receiver,
));
Expand Down Expand Up @@ -438,6 +446,7 @@ mod tests {
block_commitment_cache,
blockstore,
cluster_info,
None,
Hash::default(),
&PathBuf::from("farf"),
validator_exit,
Expand Down
Loading

0 comments on commit c67f8bd

Please sign in to comment.