Implement KeypairUtil for VoteSignerProxy

This commit is contained in:
Greg Fitzgerald 2019-01-29 09:33:23 -07:00
parent a0bed5375d
commit 278effad49
3 changed files with 33 additions and 25 deletions

View File

@ -249,18 +249,18 @@ fn main() {
let mut leader_scheduler = LeaderScheduler::default();
leader_scheduler.use_only_bootstrap_leader = use_only_bootstrap_leader;
let vote_account;
let vote_signer_option = if !no_signer {
let vote_signer =
VoteSignerProxy::new(&keypair, Box::new(RemoteVoteSigner::new(signer_addr)));
vote_account = vote_signer.vote_account;
let vote_signer = VoteSignerProxy::new_with_signer(
&keypair,
Box::new(RemoteVoteSigner::new(signer_addr)),
);
info!("Signer service address: {:?}", signer_addr);
info!("New vote account ID is {:?}", vote_account);
info!("New vote account ID is {:?}", vote_signer.pubkey());
Some(Arc::new(vote_signer))
} else {
vote_account = Pubkey::default();
None
};
let vote_account_option = vote_signer_option.as_ref().map(|x| x.pubkey());
let gossip_addr = node.info.gossip;
let mut fullnode = Fullnode::new(
@ -275,7 +275,7 @@ fn main() {
fullnode_config,
);
if !no_signer {
if let Some(vote_account) = vote_account_option {
let leader_node_info = loop {
info!("Looking for leader...");
match poll_gossip_for_leader(gossip_addr, Some(10)) {

View File

@ -491,7 +491,7 @@ pub fn make_active_set_entries(
// 2) Create and register the vote account
let vote_signer = VoteSignerProxy::new_local(active_keypair);
let vote_account_id: Pubkey = vote_signer.vote_account;
let vote_account_id = vote_signer.pubkey();
let new_vote_account_tx =
Transaction::vote_account_new(active_keypair, vote_account_id, *last_tick_id, 1, 1);

View File

@ -75,16 +75,33 @@ impl VoteSigner for RemoteVoteSigner {
}
}
impl KeypairUtil for VoteSignerProxy {
/// Return a local VoteSignerProxy with a new keypair. Used for unit-tests.
fn new() -> Self {
Self::new_local(&Arc::new(Keypair::new()))
}
/// Return the public key of the keypair used to sign votes
fn pubkey(&self) -> Pubkey {
self.vote_account
}
fn sign_message(&self, msg: &[u8]) -> Signature {
let sig = self.keypair.sign_message(msg);
self.signer.sign(self.keypair.pubkey(), &sig, &msg).unwrap()
}
}
pub struct VoteSignerProxy {
keypair: Arc<Keypair>,
signer: Box<VoteSigner + Send + Sync>,
pub vote_account: Pubkey,
vote_account: Pubkey,
last_leader: RwLock<Pubkey>,
unsent_votes: RwLock<Vec<Transaction>>,
}
impl VoteSignerProxy {
pub fn new(keypair: &Arc<Keypair>, signer: Box<VoteSigner + Send + Sync>) -> Self {
pub fn new_with_signer(keypair: &Arc<Keypair>, signer: Box<VoteSigner + Send + Sync>) -> Self {
let msg = "Registering a new node";
let sig = keypair.sign_message(msg.as_bytes());
let vote_account = signer
@ -100,7 +117,7 @@ impl VoteSignerProxy {
}
pub fn new_local(keypair: &Arc<Keypair>) -> Self {
Self::new(keypair, Box::new(LocalVoteSigner::default()))
Self::new_with_signer(keypair, Box::new(LocalVoteSigner::default()))
}
pub fn new_vote_account(&self, bank: &Bank, num_tokens: u64, last_id: Hash) -> Result<()> {
@ -160,20 +177,11 @@ impl VoteSignerProxy {
pub fn new_signed_vote_transaction(&self, last_id: &Hash, tick_height: u64) -> Transaction {
let vote = Vote { tick_height };
let tx = Transaction::vote_new(&self.vote_account, vote, *last_id, 0);
let msg = tx.message();
let sig = self.keypair.sign_message(&msg);
let keypair = self.keypair.clone();
let vote_signature = self.signer.sign(keypair.pubkey(), &sig, &msg).unwrap();
Transaction {
signatures: vec![vote_signature],
account_keys: tx.account_keys,
last_id: tx.last_id,
fee: tx.fee,
program_ids: tx.program_ids,
instructions: tx.instructions,
}
let mut tx = Transaction::vote_new(&self.vote_account, vote, *last_id, 0);
assert!(tx.signatures.is_empty());
let sig = self.sign_message(&tx.message());
tx.signatures.push(sig);
tx
}
fn new_signed_vote_blob(&self, tx: &Transaction, leader_tpu: SocketAddr) -> Result<SharedBlob> {