From 9a4abe96c72ea78b91117c802598798eb5e29d2d Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 31 Jan 2019 20:53:48 -0700 Subject: [PATCH] Reduce VoteSignerProxy to KeypairUtil --- src/replay_stage.rs | 14 ++++++++++---- src/result.rs | 7 ------- src/vote_signer_proxy.rs | 34 ++-------------------------------- 3 files changed, 12 insertions(+), 43 deletions(-) diff --git a/src/replay_stage.rs b/src/replay_stage.rs index 065b1c8fbe..592e816bfa 100644 --- a/src/replay_stage.rs +++ b/src/replay_stage.rs @@ -21,6 +21,8 @@ use solana_metrics::{influxdb, submit}; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::timing::duration_as_ms; +use solana_sdk::transaction::Transaction; +use solana_sdk::vote_transaction::VoteTransaction; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::mpsc::channel; use std::sync::mpsc::RecvTimeoutError; @@ -142,8 +144,10 @@ impl ReplayStage { } if 0 == num_ticks_to_next_vote { - if let Some(signer) = vote_signer_proxy { - let vote = signer.validator_vote(bank); + if let Some(vote_signer_proxy) = vote_signer_proxy { + let keypair = vote_signer_proxy.as_ref(); + let vote = + Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0); cluster_info.write().unwrap().push_vote(vote); } } @@ -473,7 +477,8 @@ mod test { None, ); - let vote = vote_signer_proxy.validator_vote(&bank); + let keypair = vote_signer_proxy.as_ref(); + let vote = Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0); cluster_info_me.write().unwrap().push_vote(vote); // Send ReplayStage an entry, should see it on the ledger writer receiver @@ -579,7 +584,8 @@ mod test { None, ); - let vote = vote_signer_proxy.validator_vote(&bank); + let keypair = vote_signer_proxy.as_ref(); + let vote = Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0); cluster_info_me.write().unwrap().push_vote(vote); // Send enough ticks to trigger leader rotation diff --git a/src/result.rs b/src/result.rs index e93a41c80f..b08f4942c9 100644 --- a/src/result.rs +++ b/src/result.rs @@ -7,7 +7,6 @@ use crate::db_ledger; use crate::erasure; use crate::packet; use crate::poh_recorder; -use crate::vote_signer_proxy; use bincode; use serde_json; use std; @@ -29,7 +28,6 @@ pub enum Error { ErasureError(erasure::ErasureError), SendError, PohRecorderError(poh_recorder::PohRecorderError), - VoteError(vote_signer_proxy::VoteError), DbLedgerError(db_ledger::DbLedgerError), } @@ -104,11 +102,6 @@ impl std::convert::From for Error { Error::PohRecorderError(e) } } -impl std::convert::From for Error { - fn from(e: vote_signer_proxy::VoteError) -> Error { - Error::VoteError(e) - } -} impl std::convert::From for Error { fn from(e: db_ledger::DbLedgerError) -> Error { Error::DbLedgerError(e) diff --git a/src/vote_signer_proxy.rs b/src/vote_signer_proxy.rs index 53709a5876..7fb0513ebf 100644 --- a/src/vote_signer_proxy.rs +++ b/src/vote_signer_proxy.rs @@ -1,35 +1,22 @@ //! The `vote_signer_proxy` votes on the `last_id` of the bank at a regular cadence -use crate::bank::Bank; use crate::jsonrpc_core; -use crate::result::Result; use crate::rpc_request::{RpcClient, RpcRequest}; -use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil, Signature}; -use solana_sdk::transaction::Transaction; -use solana_sdk::vote_transaction::VoteTransaction; use solana_vote_signer::rpc::LocalVoteSigner; use solana_vote_signer::rpc::VoteSigner; use std::net::SocketAddr; use std::sync::Arc; -#[derive(Debug, PartialEq, Eq)] -pub enum VoteError { - NoValidSupermajority, - NoLeader, - LeaderInfoNotFound, -} - pub struct RemoteVoteSigner { rpc_client: RpcClient, } impl RemoteVoteSigner { pub fn new(signer: SocketAddr) -> Self { - Self { - rpc_client: RpcClient::new_from_socket(signer), - } + let rpc_client = RpcClient::new_from_socket(signer); + Self { rpc_client } } } @@ -107,21 +94,4 @@ impl VoteSignerProxy { pub fn new_local(keypair: &Arc) -> Self { Self::new_with_signer(keypair, Box::new(LocalVoteSigner::default())) } - - pub fn new_vote_account(&self, bank: &Bank, num_tokens: u64, last_id: Hash) -> Result<()> { - // Create and register the new vote account - let tx = - Transaction::vote_account_new(&self.keypair, self.vote_account, last_id, num_tokens, 0); - bank.process_transaction(&tx)?; - Ok(()) - } - - pub fn validator_vote(&self, bank: &Arc) -> Transaction { - Transaction::vote_new(self, bank.tick_height(), bank.last_id(), 0) - } -} - -#[cfg(test)] -mod test { - //TODO simple tests that cover the signing }