Implemented a trait for vote signer service (#2386)

* Implemented a trait for vote signer service

* removes need for RPC in unit tests for vote signing

* fix build errors

* address some review comments
This commit is contained in:
Pankaj Garg
2019-01-11 12:58:31 -08:00
committed by GitHub
parent d6b3991d49
commit d7594b19fc
16 changed files with 324 additions and 460 deletions

View File

@@ -159,12 +159,11 @@ pub mod tests {
use crate::compute_leader_confirmation_service::ComputeLeaderConfirmationService;
use crate::vote_signer_proxy::VoteSignerProxy;
use crate::local_vote_signer_service::LocalVoteSignerService;
use crate::mint::Mint;
use crate::service::Service;
use bincode::serialize;
use solana_sdk::hash::hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_vote_signer::rpc::LocalVoteSigner;
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
@@ -187,7 +186,6 @@ pub mod tests {
})
.collect();
let (signer_service, addr) = LocalVoteSignerService::new();
// Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to
// their vote account), for a total staking pool of 10 tokens.
let vote_accounts: Vec<_> = (0..10)
@@ -195,7 +193,8 @@ pub mod tests {
// Create new validator to vote
let validator_keypair = Arc::new(Keypair::new());
let last_id = ids[i];
let vote_signer = VoteSignerProxy::new(&validator_keypair, addr.clone());
let vote_signer =
VoteSignerProxy::new(&validator_keypair, Box::new(LocalVoteSigner::default()));
// Give the validator some tokens
bank.transfer(2, &mint.keypair(), validator_keypair.pubkey(), last_id)
@@ -233,6 +232,5 @@ pub mod tests {
);
assert!(bank.confirmation_time() != std::usize::MAX);
assert!(last_confirmation_time > 0);
signer_service.join().unwrap();
}
}

View File

@@ -13,10 +13,10 @@ use crate::service::Service;
use crate::tpu::{Tpu, TpuReturnType};
use crate::tpu_forwarder::TpuForwarder;
use crate::tvu::{Sockets, Tvu, TvuReturnType};
use crate::vote_signer_proxy::VoteSignerProxy;
use crate::window::{new_window, SharedWindow};
use log::Level;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::timestamp;
use std::net::UdpSocket;
@@ -91,7 +91,6 @@ pub enum FullnodeReturnType {
pub struct Fullnode {
pub node_role: Option<NodeRole>,
keypair: Arc<Keypair>,
vote_account_id: Pubkey,
exit: Arc<AtomicBool>,
rpc_service: Option<JsonRpcService>,
rpc_pubsub_service: Option<PubSubService>,
@@ -108,8 +107,8 @@ pub struct Fullnode {
rpc_addr: SocketAddr,
rpc_pubsub_addr: SocketAddr,
drone_addr: SocketAddr,
vote_signer_addr: SocketAddr,
db_ledger: Arc<DbLedger>,
vote_signer: Arc<VoteSignerProxy>,
}
impl Fullnode {
@@ -117,8 +116,7 @@ impl Fullnode {
node: Node,
ledger_path: &str,
keypair: Arc<Keypair>,
vote_account_id: &Pubkey,
vote_signer_addr: &SocketAddr,
vote_signer: Arc<VoteSignerProxy>,
leader_addr: Option<SocketAddr>,
sigverify_disabled: bool,
leader_scheduler: LeaderScheduler,
@@ -147,8 +145,7 @@ impl Fullnode {
let leader_info = leader_addr.map(|i| NodeInfo::new_entry_point(&i));
let server = Self::new_with_bank(
keypair,
vote_account_id,
vote_signer_addr,
vote_signer,
bank,
Some(db_ledger),
entry_height,
@@ -179,8 +176,7 @@ impl Fullnode {
#[allow(clippy::too_many_arguments)]
pub fn new_with_bank(
keypair: Arc<Keypair>,
vote_account_id: &Pubkey,
vote_signer_addr: &SocketAddr,
vote_signer: Arc<VoteSignerProxy>,
bank: Bank,
db_ledger: Option<Arc<DbLedger>>,
entry_height: u64,
@@ -271,8 +267,7 @@ impl Fullnode {
};
let tvu = Tvu::new(
vote_account_id,
vote_signer_addr,
&vote_signer,
&bank,
entry_height,
*last_entry_id,
@@ -335,7 +330,6 @@ impl Fullnode {
Fullnode {
keypair,
vote_account_id: *vote_account_id,
cluster_info,
shared_window,
bank,
@@ -353,8 +347,8 @@ impl Fullnode {
rpc_addr,
rpc_pubsub_addr,
drone_addr,
vote_signer_addr: *vote_signer_addr,
db_ledger,
vote_signer,
}
}
@@ -437,8 +431,7 @@ impl Fullnode {
};
let tvu = Tvu::new(
&self.vote_account_id,
&self.vote_signer_addr,
&self.vote_signer,
&self.bank,
entry_height,
last_entry_id,
@@ -658,15 +651,14 @@ mod tests {
use crate::leader_scheduler::{
make_active_set_entries, LeaderScheduler, LeaderSchedulerConfig,
};
use crate::local_vote_signer_service::LocalVoteSignerService;
use crate::service::Service;
use crate::streamer::responder;
use crate::vote_signer_proxy::VoteSignerProxy;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_vote_signer::rpc::LocalVoteSigner;
use std::cmp;
use std::fs::remove_dir_all;
use std::net::UdpSocket;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock};
@@ -687,10 +679,11 @@ mod tests {
bank.leader_scheduler = leader_scheduler;
let last_id = bank.last_id();
let keypair = Arc::new(keypair);
let signer = VoteSignerProxy::new(&keypair, Box::new(LocalVoteSigner::default()));
let v = Fullnode::new_with_bank(
Arc::new(keypair),
&Keypair::new().pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
keypair,
Arc::new(signer),
bank,
None,
entry_height,
@@ -729,10 +722,11 @@ mod tests {
let entry_height = mint.create_entries().len() as u64;
let last_id = bank.last_id();
let keypair = Arc::new(keypair);
let signer = VoteSignerProxy::new(&keypair, Box::new(LocalVoteSigner::default()));
Fullnode::new_with_bank(
Arc::new(keypair),
&Keypair::new().pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
keypair,
Arc::new(signer),
bank,
None,
entry_height,
@@ -801,13 +795,17 @@ mod tests {
Some(active_window_length),
);
let bootstrap_leader_keypair = Arc::new(bootstrap_leader_keypair);
let signer = VoteSignerProxy::new(
&bootstrap_leader_keypair,
Box::new(LocalVoteSigner::default()),
);
// Start up the leader
let mut bootstrap_leader = Fullnode::new(
bootstrap_leader_node,
&bootstrap_leader_ledger_path,
Arc::new(bootstrap_leader_keypair),
&Keypair::new().pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
bootstrap_leader_keypair,
Arc::new(signer),
Some(bootstrap_leader_info.gossip),
false,
LeaderScheduler::new(&leader_scheduler_config),
@@ -860,10 +858,9 @@ mod tests {
// Write the entries to the ledger that will cause leader rotation
// after the bootstrap height
let (signer_service, signer) = LocalVoteSignerService::new();
let validator_keypair = Arc::new(validator_keypair);
let (active_set_entries, validator_vote_account_id) = make_active_set_entries(
&validator_keypair,
signer,
&mint.keypair(),
&last_id,
&last_id,
@@ -912,14 +909,15 @@ mod tests {
{
// Test that a node knows to transition to a validator based on parsing the ledger
let vote_signer = VoteSignerProxy::new(&bootstrap_leader_keypair, signer);
let leader_vote_id = vote_signer.vote_account.clone();
let vote_signer = VoteSignerProxy::new(
&bootstrap_leader_keypair,
Box::new(LocalVoteSigner::default()),
);
let bootstrap_leader = Fullnode::new(
bootstrap_leader_node,
&bootstrap_leader_ledger_path,
bootstrap_leader_keypair,
&leader_vote_id,
&signer,
Arc::new(vote_signer),
Some(bootstrap_leader_info.gossip),
false,
LeaderScheduler::new(&leader_scheduler_config),
@@ -937,9 +935,8 @@ mod tests {
let validator = Fullnode::new(
validator_node,
&validator_ledger_path,
Arc::new(validator_keypair),
&validator_vote_account_id,
&signer,
validator_keypair,
Arc::new(validator_vote_account_id),
Some(bootstrap_leader_info.gossip),
false,
LeaderScheduler::new(&leader_scheduler_config),
@@ -962,7 +959,6 @@ mod tests {
DbLedger::destroy(&path).expect("Expected successful database destruction");
let _ignored = remove_dir_all(&path);
}
signer_service.join().unwrap();
}
#[test]
@@ -992,6 +988,7 @@ mod tests {
.expect("expected at least one genesis entry")
.id;
let validator_keypair = Arc::new(validator_keypair);
// Write two entries so that the validator is in the active set:
//
// 1) Give the validator a nonzero number of tokens
@@ -999,15 +996,8 @@ mod tests {
// after the bootstrap height
//
// 2) A vote from the validator
let (signer_service, signer) = LocalVoteSignerService::new();
let (active_set_entries, _validator_vote_account_id) = make_active_set_entries(
&validator_keypair,
signer,
&mint.keypair(),
&last_id,
&last_id,
0,
);
let (active_set_entries, _validator_vote_account_id) =
make_active_set_entries(&validator_keypair, &mint.keypair(), &last_id, &last_id, 0);
let initial_tick_height = genesis_entries
.iter()
.skip(2)
@@ -1041,16 +1031,14 @@ mod tests {
Some(bootstrap_height),
);
let validator_keypair = Arc::new(validator_keypair);
let vote_signer = VoteSignerProxy::new(&validator_keypair, signer);
let vote_id = vote_signer.vote_account.clone();
let vote_signer =
VoteSignerProxy::new(&validator_keypair, Box::new(LocalVoteSigner::default()));
// Start the validator
let mut validator = Fullnode::new(
validator_node,
&validator_ledger_path,
validator_keypair,
&vote_id,
&signer,
Arc::new(vote_signer),
Some(leader_gossip),
false,
LeaderScheduler::new(&leader_scheduler_config),
@@ -1119,7 +1107,6 @@ mod tests {
);
// Shut down
signer_service.join().unwrap();
t_responder.join().expect("responder thread join");
validator.close().unwrap();
DbLedger::destroy(&validator_ledger_path)

View File

@@ -4,7 +4,7 @@
use crate::bank::Bank;
use crate::entry::{create_ticks, Entry};
use crate::rpc_request::{RpcClient, RpcRequest};
use crate::vote_signer_proxy::VoteSignerProxy;
use bincode::serialize;
use byteorder::{LittleEndian, ReadBytesExt};
use hashbrown::HashSet;
@@ -15,8 +15,9 @@ use solana_sdk::system_transaction::SystemTransaction;
use solana_sdk::transaction::Transaction;
use solana_sdk::vote_program::{self, Vote, VoteProgram};
use solana_sdk::vote_transaction::VoteTransaction;
use solana_vote_signer::rpc::LocalVoteSigner;
use std::io::Cursor;
use std::net::SocketAddr;
use std::sync::Arc;
pub const DEFAULT_BOOTSTRAP_HEIGHT: u64 = 1000;
pub const DEFAULT_LEADER_ROTATION_INTERVAL: u64 = 100;
@@ -480,13 +481,12 @@ impl Default for LeaderScheduler {
// 1) Give the node a nonzero number of tokens,
// 2) A vote from the validator
pub fn make_active_set_entries(
active_keypair: &Keypair,
signer: SocketAddr,
active_keypair: &Arc<Keypair>,
token_source: &Keypair,
last_entry_id: &Hash,
last_tick_id: &Hash,
num_ending_ticks: usize,
) -> (Vec<Entry>, Pubkey) {
) -> (Vec<Entry>, VoteSignerProxy) {
// 1) Create transfer token entry
let transfer_tx =
Transaction::system_new(&token_source, active_keypair.pubkey(), 3, *last_tick_id);
@@ -494,16 +494,8 @@ pub fn make_active_set_entries(
let mut last_entry_id = transfer_entry.id;
// 2) Create and register the vote account
let rpc_client = RpcClient::new_from_socket(signer);
let msg = "Registering a new node";
let sig = Signature::new(&active_keypair.sign(msg.as_bytes()).as_ref());
let params = json!([active_keypair.pubkey(), sig, msg.as_bytes()]);
let resp = RpcRequest::RegisterNode
.retry_make_rpc_request(&rpc_client, 1, Some(params), 5)
.unwrap();
let vote_account_id: Pubkey = serde_json::from_value(resp).unwrap();
let vote_signer = VoteSignerProxy::new(active_keypair, Box::new(LocalVoteSigner::default()));
let vote_account_id: Pubkey = vote_signer.vote_account;
let new_vote_account_tx =
Transaction::vote_account_new(active_keypair, vote_account_id, *last_tick_id, 1, 1);
@@ -530,7 +522,7 @@ pub fn make_active_set_entries(
let mut txs = vec![transfer_entry, new_vote_account_entry, vote_entry];
let empty_ticks = create_ticks(num_ending_ticks, last_entry_id);
txs.extend(empty_ticks);
(txs, vote_account_id)
(txs, vote_signer)
}
#[cfg(test)]
@@ -540,14 +532,13 @@ mod tests {
LeaderScheduler, LeaderSchedulerConfig, DEFAULT_BOOTSTRAP_HEIGHT,
DEFAULT_LEADER_ROTATION_INTERVAL, DEFAULT_SEED_ROTATION_INTERVAL,
};
use crate::local_vote_signer_service::LocalVoteSignerService;
use crate::mint::Mint;
use crate::service::Service;
use crate::vote_signer_proxy::VoteSignerProxy;
use hashbrown::HashSet;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_vote_signer::rpc::LocalVoteSigner;
use std::hash::Hash as StdHash;
use std::iter::FromIterator;
use std::sync::Arc;
@@ -599,11 +590,13 @@ mod tests {
.last()
.expect("Mint should not create empty genesis entries")
.id;
let (signer_service, signer) = LocalVoteSignerService::new();
for i in 0..num_validators {
let new_validator = Keypair::new();
let new_pubkey = new_validator.pubkey();
let vote_signer = VoteSignerProxy::new(&Arc::new(new_validator), signer.clone());
let vote_signer = VoteSignerProxy::new(
&Arc::new(new_validator),
Box::new(LocalVoteSigner::default()),
);
validators.push(new_pubkey);
// Give the validator some tokens
bank.transfer(
@@ -697,7 +690,6 @@ mod tests {
Some((current_leader, slot))
);
}
signer_service.join().unwrap();
}
#[test]
@@ -717,7 +709,6 @@ mod tests {
let start_height = 3;
let num_old_ids = 20;
let mut old_ids = HashSet::new();
let (signer_service, signer) = LocalVoteSignerService::new();
for _ in 0..num_old_ids {
let new_keypair = Keypair::new();
let pk = new_keypair.pubkey();
@@ -728,7 +719,8 @@ mod tests {
.unwrap();
// Create a vote account
let vote_signer = VoteSignerProxy::new(&Arc::new(new_keypair), signer);
let vote_signer =
VoteSignerProxy::new(&Arc::new(new_keypair), Box::new(LocalVoteSigner::default()));
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
.unwrap();
@@ -749,7 +741,8 @@ mod tests {
.unwrap();
// Create a vote account
let vote_signer = VoteSignerProxy::new(&Arc::new(new_keypair), signer);
let vote_signer =
VoteSignerProxy::new(&Arc::new(new_keypair), Box::new(LocalVoteSigner::default()));
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
.unwrap();
@@ -777,7 +770,6 @@ mod tests {
let result =
leader_scheduler.get_active_set(2 * active_window_length + start_height, &bank);
assert!(result.is_empty());
signer_service.join().unwrap();
}
#[test]
@@ -1020,11 +1012,13 @@ mod tests {
.last()
.expect("Mint should not create empty genesis entries")
.id;
let (signer_service, signer) = LocalVoteSignerService::new();
for i in 0..num_validators {
let new_validator = Keypair::new();
let new_pubkey = new_validator.pubkey();
let vote_signer = VoteSignerProxy::new(&Arc::new(new_validator), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(new_validator),
Box::new(LocalVoteSigner::default()),
);
validators.push(new_pubkey);
// Give the validator some tokens
bank.transfer(
@@ -1063,7 +1057,6 @@ mod tests {
assert_eq!(vec![expected], *result);
}
signer_service.join().unwrap();
}
#[test]
@@ -1084,8 +1077,10 @@ mod tests {
// window
let initial_vote_height = 1;
let (signer_service, signer) = LocalVoteSignerService::new();
let vote_signer = VoteSignerProxy::new(&Arc::new(leader_keypair), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(leader_keypair),
Box::new(LocalVoteSigner::default()),
);
// Create a vote account
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
@@ -1101,7 +1096,6 @@ mod tests {
let result =
leader_scheduler.get_active_set(initial_vote_height + active_window_length + 1, &bank);
assert!(result.is_empty());
signer_service.join().unwrap();
}
#[test]
@@ -1222,12 +1216,14 @@ mod tests {
// Create and add validator to the active set
let validator_keypair = Keypair::new();
let validator_id = validator_keypair.pubkey();
let (signer_service, signer) = LocalVoteSignerService::new();
if add_validator {
bank.transfer(5, &mint.keypair(), validator_id, last_id)
.unwrap();
// Create a vote account
let vote_signer = VoteSignerProxy::new(&Arc::new(validator_keypair), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(validator_keypair),
Box::new(LocalVoteSigner::default()),
);
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
.unwrap();
@@ -1259,7 +1255,10 @@ mod tests {
.unwrap();
// Create a vote account
let vote_signer = VoteSignerProxy::new(&Arc::new(bootstrap_leader_keypair), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(bootstrap_leader_keypair),
Box::new(LocalVoteSigner::default()),
);
vote_signer
.new_vote_account(&bank, vote_account_tokens as u64, mint.last_id())
.unwrap();
@@ -1276,7 +1275,6 @@ mod tests {
} else {
assert!(leader_scheduler.leader_schedule[0] == bootstrap_leader_id);
}
signer_service.join().unwrap();
}
#[test]
@@ -1381,8 +1379,10 @@ mod tests {
// Create a vote account for the validator
bank.transfer(5, &mint.keypair(), validator_id, last_id)
.unwrap();
let (signer_service, signer) = LocalVoteSignerService::new();
let vote_signer = VoteSignerProxy::new(&Arc::new(validator_keypair), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(validator_keypair),
Box::new(LocalVoteSigner::default()),
);
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
.unwrap();
@@ -1391,7 +1391,10 @@ mod tests {
// Create a vote account for the leader
bank.transfer(5, &mint.keypair(), bootstrap_leader_id, last_id)
.unwrap();
let vote_signer = VoteSignerProxy::new(&Arc::new(bootstrap_leader_keypair), signer);
let vote_signer = VoteSignerProxy::new(
&Arc::new(bootstrap_leader_keypair),
Box::new(LocalVoteSigner::default()),
);
vote_signer
.new_vote_account(&bank, 1 as u64, mint.last_id())
.unwrap();
@@ -1455,6 +1458,5 @@ mod tests {
.max_height_for_leader(bootstrap_height + 2 * seed_rotation_interval + 1),
None
);
signer_service.join().unwrap();
}
}

View File

@@ -14,10 +14,9 @@ use crate::streamer::{responder, BlobSender};
use crate::vote_signer_proxy::VoteSignerProxy;
use log::Level;
use solana_metrics::{influxdb, submit};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::duration_as_ms;
use std::net::{SocketAddr, UdpSocket};
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::mpsc::channel;
use std::sync::mpsc::RecvTimeoutError;
@@ -65,8 +64,7 @@ impl ReplayStage {
cluster_info: &Arc<RwLock<ClusterInfo>>,
window_receiver: &EntryReceiver,
keypair: &Arc<Keypair>,
_vote_account_id: &Pubkey,
vote_signer: &VoteSignerProxy,
vote_signer: &Arc<VoteSignerProxy>,
vote_blob_sender: Option<&BlobSender>,
ledger_entry_sender: &EntrySender,
entry_height: &mut u64,
@@ -196,8 +194,7 @@ impl ReplayStage {
#[allow(clippy::new_ret_no_self)]
pub fn new(
keypair: Arc<Keypair>,
vote_account_id: &Pubkey,
vote_signer_addr: &SocketAddr,
vote_signer: Arc<VoteSignerProxy>,
bank: Arc<Bank>,
cluster_info: Arc<RwLock<ClusterInfo>>,
window_receiver: EntryReceiver,
@@ -211,15 +208,12 @@ impl ReplayStage {
let t_responder = responder("replay_stage", Arc::new(send), vote_blob_receiver);
let keypair = Arc::new(keypair);
let vote_account_id = *vote_account_id;
let vote_signer_addr = *vote_signer_addr;
let t_replay = Builder::new()
.name("solana-replay-stage".to_string())
.spawn(move || {
let _exit = Finalizer::new(exit);
let mut entry_height_ = entry_height;
let mut last_entry_id = last_entry_id;
let vote_signer = VoteSignerProxy::new(&keypair, vote_signer_addr);
loop {
let (leader_id, _) = bank
.get_current_leader()
@@ -242,7 +236,6 @@ impl ReplayStage {
&cluster_info,
&window_receiver,
&keypair,
&vote_account_id,
&vote_signer,
Some(&vote_blob_sender),
&ledger_entry_sender,
@@ -292,7 +285,6 @@ mod test {
make_active_set_entries, LeaderScheduler, LeaderSchedulerConfig,
};
use crate::local_vote_signer_service::LocalVoteSignerService;
use crate::packet::BlobError;
use crate::replay_stage::{ReplayStage, ReplayStageReturnType};
use crate::result::Error;
@@ -300,6 +292,7 @@ mod test {
use crate::vote_signer_proxy::VoteSignerProxy;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_vote_signer::rpc::LocalVoteSigner;
use std::fs::remove_dir_all;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
@@ -332,12 +325,12 @@ mod test {
.expect("expected at least one genesis entry")
.id;
let my_keypair = Arc::new(my_keypair);
// Write two entries to the ledger so that the validator is in the active set:
// 1) Give the validator a nonzero number of tokens 2) A vote from the validator .
// This will cause leader rotation after the bootstrap height
let (signer_service, signer) = LocalVoteSignerService::new();
let (active_set_entries, vote_account_id) =
make_active_set_entries(&my_keypair, signer, &mint.keypair(), &last_id, &last_id, 0);
make_active_set_entries(&my_keypair, &mint.keypair(), &last_id, &last_id, 0);
last_id = active_set_entries.last().unwrap().id;
let initial_tick_height = genesis_entries
.iter()
@@ -381,9 +374,8 @@ mod test {
let (entry_sender, entry_receiver) = channel();
let exit = Arc::new(AtomicBool::new(false));
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
Arc::new(my_keypair),
&vote_account_id,
&signer,
my_keypair,
Arc::new(vote_account_id),
Arc::new(bank),
Arc::new(RwLock::new(cluster_info_me)),
entry_receiver,
@@ -434,8 +426,6 @@ mod test {
&entries_to_send[..leader_rotation_index + 1]
);
signer_service.join().unwrap();
assert_eq!(exit.load(Ordering::Relaxed), true);
let _ignored = remove_dir_all(&my_ledger_path);
@@ -471,17 +461,17 @@ mod test {
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
// Set up the replay stage
let (signer_service, signer) = LocalVoteSignerService::new();
let bank = Arc::new(bank);
let (entry_sender, entry_receiver) = channel();
let exit = Arc::new(AtomicBool::new(false));
let my_keypair = Arc::new(my_keypair);
let vote_signer = VoteSignerProxy::new(&my_keypair, signer);
let vote_account_id = vote_signer.vote_account.clone();
let vote_signer = Arc::new(VoteSignerProxy::new(
&my_keypair,
Box::new(LocalVoteSigner::default()),
));
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
my_keypair.clone(),
&vote_account_id,
&signer,
vote_signer.clone(),
bank.clone(),
cluster_info_me.clone(),
entry_receiver,
@@ -512,7 +502,6 @@ mod test {
assert_eq!(next_tick, received_tick);
drop(entry_sender);
signer_service.join().unwrap();
replay_stage
.join()
.expect("Expect successful ReplayStage exit");
@@ -543,12 +532,12 @@ mod test {
.expect("expected at least one genesis entry")
.id;
let my_keypair = Arc::new(my_keypair);
// Write two entries to the ledger so that the validator is in the active set:
// 1) Give the validator a nonzero number of tokens 2) A vote from the validator.
// This will cause leader rotation after the bootstrap height
let (signer_service, signer) = LocalVoteSignerService::new();
let (active_set_entries, vote_account_id) =
make_active_set_entries(&my_keypair, signer, &mint.keypair(), &last_id, &last_id, 0);
make_active_set_entries(&my_keypair, &mint.keypair(), &last_id, &last_id, 0);
last_id = active_set_entries.last().unwrap().id;
let initial_tick_height = genesis_entries
.iter()
@@ -592,16 +581,13 @@ mod test {
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
// Set up the replay stage
let my_keypair = Arc::new(my_keypair);
let signer_proxy = VoteSignerProxy::new(&my_keypair, signer);
let vote_account_id = Arc::new(vote_account_id);
let signer_proxy = Arc::new(vote_account_id);
let bank = Arc::new(bank);
let (entry_sender, entry_receiver) = channel();
let exit = Arc::new(AtomicBool::new(false));
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
my_keypair.clone(),
&vote_account_id,
&signer,
signer_proxy.clone(),
bank.clone(),
cluster_info_me.clone(),
entry_receiver,
@@ -653,7 +639,6 @@ mod test {
)),
replay_stage.join().expect("replay stage join")
);
signer_service.join().unwrap();
assert_eq!(exit.load(Ordering::Relaxed), true);
let _ignored = remove_dir_all(&my_ledger_path);
}
@@ -663,7 +648,6 @@ mod test {
// Set up dummy node to host a ReplayStage
let my_keypair = Keypair::new();
let my_id = my_keypair.pubkey();
let vote_keypair = Keypair::new();
let my_node = Node::new_localhost_with_pubkey(my_id);
// Set up the cluster info
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
@@ -694,14 +678,15 @@ mod test {
.expect("Expected to err out");
let my_keypair = Arc::new(my_keypair);
let (signer_service, signer) = LocalVoteSignerService::new();
let vote_signer = VoteSignerProxy::new(&my_keypair, signer);
let vote_signer = Arc::new(VoteSignerProxy::new(
&my_keypair,
Box::new(LocalVoteSigner::default()),
));
let res = ReplayStage::process_entries(
&Arc::new(Bank::default()),
&cluster_info_me,
&entry_receiver,
&my_keypair,
&vote_keypair.pubkey(),
&vote_signer,
None,
&ledger_entry_sender,
@@ -728,7 +713,6 @@ mod test {
&cluster_info_me,
&entry_receiver,
&Arc::new(Keypair::new()),
&Keypair::new().pubkey(),
&vote_signer,
None,
&ledger_entry_sender,
@@ -745,7 +729,6 @@ mod test {
e
),
}
signer_service.join().unwrap();
let _ignored = remove_dir_all(&my_ledger_path);
}
}

View File

@@ -411,6 +411,7 @@ mod tests {
use crate::leader_scheduler::LeaderScheduler;
use crate::mint::Mint;
use crate::rpc_request::get_rpc_request_str;
use crate::vote_signer_proxy::VoteSignerProxy;
use bincode::serialize;
use reqwest;
use reqwest::header::CONTENT_TYPE;
@@ -418,6 +419,7 @@ mod tests {
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction::SystemTransaction;
use solana_sdk::transaction::Transaction;
use solana_vote_signer::rpc::LocalVoteSigner;
use std::fs::remove_dir_all;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
@@ -686,11 +688,12 @@ mod tests {
bank.leader_scheduler = leader_scheduler;
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let entry_height = alice.create_entries().len() as u64;
let server = Fullnode::new_with_bank(
leader_keypair,
&vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
entry_height,

View File

@@ -430,15 +430,15 @@ mod tests {
use crate::db_ledger::create_tmp_ledger_with_mint;
use crate::fullnode::Fullnode;
use crate::leader_scheduler::LeaderScheduler;
use crate::mint::Mint;
use crate::vote_signer_proxy::VoteSignerProxy;
use bincode::deserialize;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_instruction::SystemInstruction;
use solana_sdk::vote_program::VoteProgram;
use solana_sdk::vote_transaction::VoteTransaction;
use solana_vote_signer::rpc::LocalVoteSigner;
use std::fs::remove_dir_all;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
#[test]
fn test_thin_client() {
@@ -458,11 +458,12 @@ mod tests {
)));
bank.leader_scheduler = leader_scheduler;
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let last_id = bank.last_id();
let server = Fullnode::new_with_bank(
leader_keypair,
&vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
entry_height,
@@ -513,11 +514,12 @@ mod tests {
)));
bank.leader_scheduler = leader_scheduler;
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let last_id = bank.last_id();
let server = Fullnode::new_with_bank(
leader_keypair,
&vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
0,
@@ -572,12 +574,13 @@ mod tests {
)));
bank.leader_scheduler = leader_scheduler;
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let entry_height = alice.create_entries().len() as u64;
let last_id = bank.last_id();
let server = Fullnode::new_with_bank(
leader_keypair,
&vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
entry_height,
@@ -621,10 +624,13 @@ mod tests {
)));
bank.leader_scheduler = leader_scheduler;
let leader_vote_account_keypair = Arc::new(Keypair::new());
let vote_signer = VoteSignerProxy::new(
&leader_vote_account_keypair,
Box::new(LocalVoteSigner::default()),
);
let server = Fullnode::new_with_bank(
leader_keypair,
&leader_vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
entry_height,
@@ -714,12 +720,13 @@ mod tests {
)));
bank.leader_scheduler = leader_scheduler;
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let last_id = bank.last_id();
let entry_height = alice.create_entries().len() as u64;
let server = Fullnode::new_with_bank(
leader_keypair,
&vote_account_keypair.pubkey(),
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
Arc::new(vote_signer),
bank,
None,
entry_height,

View File

@@ -20,10 +20,10 @@ use crate::replay_stage::{ReplayStage, ReplayStageReturnType};
use crate::retransmit_stage::RetransmitStage;
use crate::service::Service;
use crate::storage_stage::StorageStage;
use crate::vote_signer_proxy::VoteSignerProxy;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
use std::net::{SocketAddr, UdpSocket};
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use std::thread;
@@ -51,7 +51,6 @@ impl Tvu {
/// This service receives messages from a leader in the network and processes the transactions
/// on the bank state.
/// # Arguments
/// * `vote_account_id` - Vote public key
/// * `bank` - The bank state.
/// * `entry_height` - Initial ledger height
/// * `last_entry_id` - Hash of the last entry
@@ -59,8 +58,7 @@ impl Tvu {
/// * `sockets` - My fetch, repair, and restransmit sockets
/// * `db_ledger` - the ledger itself
pub fn new(
vote_account_id: &Pubkey,
vote_signer_addr: &SocketAddr,
vote_signer: &Arc<VoteSignerProxy>,
bank: &Arc<Bank>,
entry_height: u64,
last_entry_id: Hash,
@@ -105,8 +103,7 @@ impl Tvu {
let (replay_stage, ledger_entry_receiver) = ReplayStage::new(
keypair.clone(),
vote_account_id,
vote_signer_addr,
vote_signer.clone(),
bank.clone(),
cluster_info.clone(),
blob_window_receiver,
@@ -184,14 +181,15 @@ pub mod tests {
use crate::service::Service;
use crate::streamer;
use crate::tvu::{Sockets, Tvu};
use crate::vote_signer_proxy::VoteSignerProxy;
use bincode::serialize;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction::SystemTransaction;
use solana_sdk::transaction::Transaction;
use solana_vote_signer::rpc::LocalVoteSigner;
use std::fs::remove_dir_all;
use std::net::UdpSocket;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock};
@@ -265,14 +263,15 @@ pub mod tests {
let cref1 = Arc::new(RwLock::new(cluster_info1));
let dr_1 = new_gossip(cref1.clone(), target1.sockets.gossip, exit.clone());
let vote_account_id = Keypair::new().pubkey();
let mut cur_hash = Hash::default();
let db_ledger_path = get_tmp_ledger_path("test_replay");
let db_ledger =
DbLedger::open(&db_ledger_path).expect("Expected to successfully open ledger");
let vote_account_keypair = Arc::new(Keypair::new());
let vote_signer =
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
let tvu = Tvu::new(
&vote_account_id,
&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
&Arc::new(vote_signer),
&bank,
0,
cur_hash,

View File

@@ -3,6 +3,7 @@
use crate::bank::Bank;
use crate::cluster_info::ClusterInfo;
use crate::counter::Counter;
use crate::jsonrpc_core;
use crate::packet::SharedBlob;
use crate::result::{Error, Result};
use crate::rpc_request::{RpcClient, RpcRequest};
@@ -15,6 +16,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::transaction::Transaction;
use solana_sdk::vote_program::Vote;
use solana_sdk::vote_transaction::VoteTransaction;
use solana_vote_signer::rpc::VoteSigner;
use std::net::SocketAddr;
use std::sync::atomic::AtomicUsize;
use std::sync::{Arc, RwLock};
@@ -26,27 +28,65 @@ pub enum VoteError {
LeaderInfoNotFound,
}
pub struct VoteSignerProxy {
pub struct RemoteVoteSigner {
rpc_client: RpcClient,
}
impl RemoteVoteSigner {
pub fn new(signer: SocketAddr) -> Self {
Self {
rpc_client: RpcClient::new_from_socket(signer),
}
}
}
impl VoteSigner for RemoteVoteSigner {
fn register(
&self,
pubkey: Pubkey,
sig: &Signature,
msg: &[u8],
) -> jsonrpc_core::Result<Pubkey> {
let params = json!([pubkey, sig, msg]);
let resp = RpcRequest::RegisterNode
.retry_make_rpc_request(&self.rpc_client, 1, Some(params), 5)
.unwrap();
let vote_account: Pubkey = serde_json::from_value(resp).unwrap();
Ok(vote_account)
}
fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<Signature> {
let params = json!([pubkey, sig, msg]);
let resp = RpcRequest::SignVote
.make_rpc_request(&self.rpc_client, 1, Some(params))
.unwrap();
let vote_signature: Signature = serde_json::from_value(resp).unwrap();
Ok(vote_signature)
}
fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<()> {
let params = json!([pubkey, sig, msg]);
let _resp = RpcRequest::DeregisterNode
.retry_make_rpc_request(&self.rpc_client, 1, Some(params), 5)
.unwrap();
Ok(())
}
}
pub struct VoteSignerProxy {
keypair: Arc<Keypair>,
signer: Box<VoteSigner + Send + Sync>,
pub vote_account: Pubkey,
}
impl VoteSignerProxy {
pub fn new(keypair: &Arc<Keypair>, signer: SocketAddr) -> Self {
let rpc_client = RpcClient::new_from_socket(signer);
pub fn new(keypair: &Arc<Keypair>, signer: Box<VoteSigner + Send + Sync>) -> Self {
let msg = "Registering a new node";
let sig = Signature::new(&keypair.sign(msg.as_bytes()).as_ref());
let params = json!([keypair.pubkey(), sig, msg.as_bytes()]);
let resp = RpcRequest::RegisterNode
.retry_make_rpc_request(&rpc_client, 1, Some(params), 5)
let vote_account = signer
.register(keypair.pubkey(), &sig, msg.as_bytes())
.unwrap();
let vote_account: Pubkey = serde_json::from_value(resp).unwrap();
Self {
rpc_client,
keypair: keypair.clone(),
signer,
vote_account,
}
}
@@ -83,12 +123,7 @@ impl VoteSignerProxy {
let sig = Signature::new(&self.keypair.sign(&msg).as_ref());
let keypair = self.keypair.clone();
let params = json!([keypair.pubkey(), sig, &msg]);
let resp = RpcRequest::SignVote
.make_rpc_request(&self.rpc_client, 1, Some(params))
.unwrap();
let vote_signature: Signature = serde_json::from_value(resp).unwrap();
let vote_signature = self.signer.sign(keypair.pubkey(), &sig, &msg).unwrap();
Transaction {
signatures: vec![vote_signature],
account_keys: tx.account_keys,