Inline VoteSigner::new_vote_account
So that we can stop using the validator keypair to fund the the voting account.
This commit is contained in:
@ -162,6 +162,7 @@ pub mod tests {
|
|||||||
use crate::vote_signer_proxy::VoteSignerProxy;
|
use crate::vote_signer_proxy::VoteSignerProxy;
|
||||||
|
|
||||||
use crate::genesis_block::GenesisBlock;
|
use crate::genesis_block::GenesisBlock;
|
||||||
|
use crate::leader_scheduler::tests::new_vote_account;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
@ -201,9 +202,7 @@ pub mod tests {
|
|||||||
// Give the validator some tokens
|
// Give the validator some tokens
|
||||||
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), last_id)
|
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
vote_signer
|
new_vote_account(&validator_keypair, &vote_signer, &bank, 1, last_id);
|
||||||
.new_vote_account(&bank, 1, last_id)
|
|
||||||
.expect("Expected successful creation of account");
|
|
||||||
|
|
||||||
if i < 6 {
|
if i < 6 {
|
||||||
let vote_tx = Transaction::vote_new(&vote_signer, (i + 1) as u64, last_id, 0);
|
let vote_tx = Transaction::vote_new(&vote_signer, (i + 1) as u64, last_id, 0);
|
||||||
|
@ -511,7 +511,7 @@ pub fn make_active_set_entries(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::bank::Bank;
|
use crate::bank::Bank;
|
||||||
use crate::genesis_block::GenesisBlock;
|
use crate::genesis_block::GenesisBlock;
|
||||||
@ -535,6 +535,23 @@ mod tests {
|
|||||||
HashSet::from_iter(slice.iter().cloned())
|
HashSet::from_iter(slice.iter().cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_vote_account(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
vote_signer: &VoteSignerProxy,
|
||||||
|
bank: &Bank,
|
||||||
|
num_tokens: u64,
|
||||||
|
last_id: Hash,
|
||||||
|
) {
|
||||||
|
let tx = Transaction::vote_account_new(
|
||||||
|
from_keypair,
|
||||||
|
vote_signer.pubkey(),
|
||||||
|
last_id,
|
||||||
|
num_tokens,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn push_vote(vote_signer: &VoteSignerProxy, bank: &Bank, height: u64, last_id: Hash) {
|
fn push_vote(vote_signer: &VoteSignerProxy, bank: &Bank, height: u64, last_id: Hash) {
|
||||||
let new_vote_tx = Transaction::vote_new(vote_signer, height, last_id, 0);
|
let new_vote_tx = Transaction::vote_new(vote_signer, height, last_id, 0);
|
||||||
bank.process_transaction(&new_vote_tx).unwrap();
|
bank.process_transaction(&new_vote_tx).unwrap();
|
||||||
@ -571,9 +588,9 @@ mod tests {
|
|||||||
let mut validators = vec![];
|
let mut validators = vec![];
|
||||||
let last_id = genesis_block.last_id();
|
let last_id = genesis_block.last_id();
|
||||||
for i in 0..num_validators {
|
for i in 0..num_validators {
|
||||||
let new_validator = Keypair::new();
|
let new_validator = Arc::new(Keypair::new());
|
||||||
let new_pubkey = new_validator.pubkey();
|
let new_pubkey = new_validator.pubkey();
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_validator));
|
let vote_signer = VoteSignerProxy::new_local(&new_validator);
|
||||||
validators.push(new_pubkey);
|
validators.push(new_pubkey);
|
||||||
// Give the validator some tokens
|
// Give the validator some tokens
|
||||||
bank.transfer(
|
bank.transfer(
|
||||||
@ -585,13 +602,14 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(
|
&new_validator,
|
||||||
&bank,
|
&vote_signer,
|
||||||
num_vote_account_tokens as u64,
|
&bank,
|
||||||
genesis_block.last_id(),
|
num_vote_account_tokens as u64,
|
||||||
)
|
genesis_block.last_id(),
|
||||||
.unwrap();
|
);
|
||||||
|
|
||||||
// Vote to make the validator part of the active set for the entire test
|
// Vote to make the validator part of the active set for the entire test
|
||||||
// (we made the active_window_length large enough at the beginning of the test)
|
// (we made the active_window_length large enough at the beginning of the test)
|
||||||
push_vote(&vote_signer, &bank, 1, genesis_block.last_id());
|
push_vote(&vote_signer, &bank, 1, genesis_block.last_id());
|
||||||
@ -691,7 +709,7 @@ mod tests {
|
|||||||
let num_old_ids = 20;
|
let num_old_ids = 20;
|
||||||
let mut old_ids = HashSet::new();
|
let mut old_ids = HashSet::new();
|
||||||
for _ in 0..num_old_ids {
|
for _ in 0..num_old_ids {
|
||||||
let new_keypair = Keypair::new();
|
let new_keypair = Arc::new(Keypair::new());
|
||||||
let pk = new_keypair.pubkey();
|
let pk = new_keypair.pubkey();
|
||||||
old_ids.insert(pk.clone());
|
old_ids.insert(pk.clone());
|
||||||
|
|
||||||
@ -700,10 +718,14 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&new_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&new_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
// Push a vote for the account
|
// Push a vote for the account
|
||||||
push_vote(&vote_signer, &bank, start_height, genesis_block.last_id());
|
push_vote(&vote_signer, &bank, start_height, genesis_block.last_id());
|
||||||
@ -713,7 +735,7 @@ mod tests {
|
|||||||
let num_new_ids = 10;
|
let num_new_ids = 10;
|
||||||
let mut new_ids = HashSet::new();
|
let mut new_ids = HashSet::new();
|
||||||
for _ in 0..num_new_ids {
|
for _ in 0..num_new_ids {
|
||||||
let new_keypair = Keypair::new();
|
let new_keypair = Arc::new(Keypair::new());
|
||||||
let pk = new_keypair.pubkey();
|
let pk = new_keypair.pubkey();
|
||||||
new_ids.insert(pk);
|
new_ids.insert(pk);
|
||||||
// Give the account some stake
|
// Give the account some stake
|
||||||
@ -721,10 +743,14 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&new_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&new_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
push_vote(
|
push_vote(
|
||||||
&vote_signer,
|
&vote_signer,
|
||||||
@ -981,9 +1007,9 @@ mod tests {
|
|||||||
let mut validators = vec![];
|
let mut validators = vec![];
|
||||||
let last_id = genesis_block.last_id();
|
let last_id = genesis_block.last_id();
|
||||||
for i in 0..num_validators {
|
for i in 0..num_validators {
|
||||||
let new_validator = Keypair::new();
|
let new_validator = Arc::new(Keypair::new());
|
||||||
let new_pubkey = new_validator.pubkey();
|
let new_pubkey = new_validator.pubkey();
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_validator));
|
let vote_signer = VoteSignerProxy::new_local(&new_validator);
|
||||||
validators.push(new_pubkey);
|
validators.push(new_pubkey);
|
||||||
// Give the validator some tokens
|
// Give the validator some tokens
|
||||||
bank.transfer(
|
bank.transfer(
|
||||||
@ -995,13 +1021,13 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(
|
&new_validator,
|
||||||
&bank,
|
&vote_signer,
|
||||||
num_vote_account_tokens as u64,
|
&bank,
|
||||||
genesis_block.last_id(),
|
num_vote_account_tokens as u64,
|
||||||
)
|
genesis_block.last_id(),
|
||||||
.unwrap();
|
);
|
||||||
|
|
||||||
// Vote at height i * active_window_length for validator i
|
// Vote at height i * active_window_length for validator i
|
||||||
push_vote(
|
push_vote(
|
||||||
@ -1030,7 +1056,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multiple_vote() {
|
fn test_multiple_vote() {
|
||||||
let leader_keypair = Keypair::new();
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
let leader_id = leader_keypair.pubkey();
|
let leader_id = leader_keypair.pubkey();
|
||||||
let active_window_length = 1000;
|
let active_window_length = 1000;
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10000, leader_id, 500);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10000, leader_id, 500);
|
||||||
@ -1046,11 +1072,15 @@ mod tests {
|
|||||||
// window
|
// window
|
||||||
let initial_vote_height = 1;
|
let initial_vote_height = 1;
|
||||||
|
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(leader_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&leader_keypair);
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&leader_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
// Vote twice
|
// Vote twice
|
||||||
push_vote(
|
push_vote(
|
||||||
@ -1162,7 +1192,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_consecutive_leader_test(num_slots_per_epoch: u64, add_validator: bool) {
|
fn run_consecutive_leader_test(num_slots_per_epoch: u64, add_validator: bool) {
|
||||||
let bootstrap_leader_keypair = Keypair::new();
|
let bootstrap_leader_keypair = Arc::new(Keypair::new());
|
||||||
let bootstrap_leader_id = bootstrap_leader_keypair.pubkey();
|
let bootstrap_leader_id = bootstrap_leader_keypair.pubkey();
|
||||||
let bootstrap_height = 500;
|
let bootstrap_height = 500;
|
||||||
let leader_rotation_interval = 100;
|
let leader_rotation_interval = 100;
|
||||||
@ -1187,16 +1217,20 @@ mod tests {
|
|||||||
let initial_vote_height = 1;
|
let initial_vote_height = 1;
|
||||||
|
|
||||||
// Create and add validator to the active set
|
// Create and add validator to the active set
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Arc::new(Keypair::new());
|
||||||
let validator_id = validator_keypair.pubkey();
|
let validator_id = validator_keypair.pubkey();
|
||||||
if add_validator {
|
if add_validator {
|
||||||
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(validator_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&validator_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&validator_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
push_vote(
|
push_vote(
|
||||||
&vote_signer,
|
&vote_signer,
|
||||||
@ -1224,10 +1258,14 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a vote account
|
// Create a vote account
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(bootstrap_leader_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&bootstrap_leader_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, vote_account_tokens as u64, genesis_block.last_id())
|
&bootstrap_leader_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
vote_account_tokens as u64,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
// Add leader to the active set
|
// Add leader to the active set
|
||||||
push_vote(
|
push_vote(
|
||||||
@ -1263,7 +1301,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_max_height_for_leader() {
|
fn test_max_height_for_leader() {
|
||||||
let bootstrap_leader_keypair = Keypair::new();
|
let bootstrap_leader_keypair = Arc::new(Keypair::new());
|
||||||
let bootstrap_leader_id = bootstrap_leader_keypair.pubkey();
|
let bootstrap_leader_id = bootstrap_leader_keypair.pubkey();
|
||||||
let bootstrap_height = 500;
|
let bootstrap_height = 500;
|
||||||
let leader_rotation_interval = 100;
|
let leader_rotation_interval = 100;
|
||||||
@ -1341,16 +1379,21 @@ mod tests {
|
|||||||
// Now test when the active set > 1 node
|
// Now test when the active set > 1 node
|
||||||
|
|
||||||
// Create and add validator to the active set
|
// Create and add validator to the active set
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Arc::new(Keypair::new());
|
||||||
let validator_id = validator_keypair.pubkey();
|
let validator_id = validator_keypair.pubkey();
|
||||||
|
|
||||||
// Create a vote account for the validator
|
// Create a vote account for the validator
|
||||||
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(validator_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&validator_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&validator_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
push_vote(
|
push_vote(
|
||||||
&vote_signer,
|
&vote_signer,
|
||||||
&bank,
|
&bank,
|
||||||
@ -1361,10 +1404,14 @@ mod tests {
|
|||||||
// Create a vote account for the leader
|
// Create a vote account for the leader
|
||||||
bank.transfer(5, &mint_keypair, bootstrap_leader_id, last_id)
|
bank.transfer(5, &mint_keypair, bootstrap_leader_id, last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(bootstrap_leader_keypair));
|
let vote_signer = VoteSignerProxy::new_local(&bootstrap_leader_keypair);
|
||||||
vote_signer
|
new_vote_account(
|
||||||
.new_vote_account(&bank, 1, genesis_block.last_id())
|
&bootstrap_leader_keypair,
|
||||||
.unwrap();
|
&vote_signer,
|
||||||
|
&bank,
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
);
|
||||||
|
|
||||||
// Add leader to the active set
|
// Add leader to the active set
|
||||||
push_vote(
|
push_vote(
|
||||||
|
@ -10,7 +10,6 @@ use crate::rpc_request::{RpcClient, RpcRequest};
|
|||||||
use crate::streamer::BlobSender;
|
use crate::streamer::BlobSender;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use log::Level;
|
use log::Level;
|
||||||
use solana_sdk::hash::Hash;
|
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
@ -119,14 +118,6 @@ impl VoteSignerProxy {
|
|||||||
Self::new_with_signer(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<()> {
|
|
||||||
// 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 send_validator_vote(
|
pub fn send_validator_vote(
|
||||||
&self,
|
&self,
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
|
Reference in New Issue
Block a user