Boot VoteTransaction
This commit is contained in:
@ -440,7 +440,7 @@ mod tests {
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
|
||||
fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||
@ -461,6 +461,12 @@ mod tests {
|
||||
Transaction::new_signed_instructions(&[keypair], vec![ix], hash, 0)
|
||||
}
|
||||
|
||||
fn create_sample_vote(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||
let pubkey = keypair.pubkey();
|
||||
let ix = VoteInstruction::new_vote(&pubkey, Vote::new(1));
|
||||
Transaction::new_signed_instructions(&[keypair], vec![ix], hash, 0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_entry_verify() {
|
||||
let zero = Hash::default();
|
||||
@ -564,7 +570,7 @@ mod tests {
|
||||
let one = hash(&zero.as_ref());
|
||||
let keypair = Keypair::new();
|
||||
let vote_account = Keypair::new();
|
||||
let tx0 = VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, one, 1);
|
||||
let tx0 = create_sample_vote(&vote_account, one);
|
||||
let tx1 = create_sample_timestamp(&keypair, one);
|
||||
//
|
||||
// TODO: this magic number and the mix of transaction types
|
||||
@ -623,8 +629,7 @@ mod tests {
|
||||
let next_hash = solana_sdk::hash::hash(&hash.as_ref());
|
||||
let keypair = Keypair::new();
|
||||
let vote_account = Keypair::new();
|
||||
let tx_small =
|
||||
VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, next_hash, 2);
|
||||
let tx_small = create_sample_vote(&vote_account, next_hash);
|
||||
let tx_large = create_sample_payment(&keypair, next_hash);
|
||||
|
||||
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
||||
|
@ -27,7 +27,8 @@ use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::timing::timestamp;
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::Receiver;
|
||||
@ -325,23 +326,23 @@ pub fn make_active_set_entries(
|
||||
let voting_keypair = Keypair::new();
|
||||
let vote_account_id = voting_keypair.pubkey();
|
||||
|
||||
let new_vote_account_tx = VoteTransaction::new_account(
|
||||
active_keypair,
|
||||
let new_vote_account_ixs = VoteInstruction::new_account(
|
||||
&active_keypair.pubkey(),
|
||||
&vote_account_id,
|
||||
*blockhash,
|
||||
stake.saturating_sub(2),
|
||||
);
|
||||
let new_vote_account_tx = Transaction::new_signed_instructions(
|
||||
&[active_keypair.as_ref()],
|
||||
new_vote_account_ixs,
|
||||
*blockhash,
|
||||
1,
|
||||
);
|
||||
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
||||
|
||||
// 3) Create vote entry
|
||||
let vote_tx = VoteTransaction::new_vote(
|
||||
&voting_keypair.pubkey(),
|
||||
&voting_keypair,
|
||||
slot_to_vote_on,
|
||||
*blockhash,
|
||||
0,
|
||||
);
|
||||
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(slot_to_vote_on));
|
||||
let vote_tx =
|
||||
Transaction::new_signed_instructions(&[&voting_keypair], vec![vote_ix], *blockhash, 0);
|
||||
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
||||
|
||||
// 4) Create `num_ending_ticks` empty ticks
|
||||
|
@ -119,7 +119,8 @@ mod tests {
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::timing::MAX_RECENT_BLOCKHASHES;
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
@ -177,13 +178,10 @@ mod tests {
|
||||
|
||||
// Get another validator to vote, so we now have 2/3 consensus
|
||||
let voting_keypair = &vote_accounts[7].0;
|
||||
let vote_tx = VoteTransaction::new_vote(
|
||||
&voting_keypair.pubkey(),
|
||||
voting_keypair,
|
||||
MAX_RECENT_BLOCKHASHES as u64,
|
||||
blockhash,
|
||||
0,
|
||||
);
|
||||
let vote = Vote::new(MAX_RECENT_BLOCKHASHES as u64);
|
||||
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), vote);
|
||||
let vote_tx =
|
||||
Transaction::new_signed_instructions(&[voting_keypair], vec![vote_ix], blockhash, 0);
|
||||
bank.process_transaction(&vote_tx).unwrap();
|
||||
|
||||
LeaderConfirmationService::compute_confirmation(&bank, &mut last_confirmation_time);
|
||||
|
@ -14,8 +14,9 @@ use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::timing::DEFAULT_SLOTS_PER_EPOCH;
|
||||
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_api::vote_instruction::VoteInstruction;
|
||||
use solana_vote_api::vote_state::VoteState;
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::io::{Error, ErrorKind, Result};
|
||||
@ -295,11 +296,12 @@ impl LocalCluster {
|
||||
// Create the vote account if necessary
|
||||
if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 {
|
||||
// 1) Create vote account
|
||||
let mut transaction = VoteTransaction::new_account(
|
||||
from_account,
|
||||
&vote_account_pubkey,
|
||||
let instructions =
|
||||
VoteInstruction::new_account(&from_account.pubkey(), &vote_account_pubkey, amount);
|
||||
let mut transaction = Transaction::new_signed_instructions(
|
||||
&[from_account.as_ref()],
|
||||
instructions,
|
||||
client.get_recent_blockhash().unwrap(),
|
||||
amount,
|
||||
1,
|
||||
);
|
||||
|
||||
@ -311,11 +313,14 @@ impl LocalCluster {
|
||||
.expect("get balance");
|
||||
|
||||
// 2) Set delegate for new vote account
|
||||
let mut transaction = VoteTransaction::delegate_vote_account(
|
||||
vote_account,
|
||||
let vote_instruction =
|
||||
VoteInstruction::new_delegate_stake(&vote_account_pubkey, &delegate_id);
|
||||
|
||||
let mut transaction = Transaction::new_signed_instructions(
|
||||
&[vote_account],
|
||||
vec![vote_instruction],
|
||||
client.get_recent_blockhash().unwrap(),
|
||||
&delegate_id,
|
||||
0,
|
||||
1,
|
||||
);
|
||||
|
||||
client
|
||||
|
@ -19,7 +19,8 @@ use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::KeypairUtil;
|
||||
use solana_sdk::timing::{self, duration_as_ms};
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
|
||||
@ -297,11 +298,10 @@ impl ReplayStage {
|
||||
T: 'static + KeypairUtil + Send + Sync,
|
||||
{
|
||||
if let Some(ref voting_keypair) = voting_keypair {
|
||||
let keypair = voting_keypair.as_ref();
|
||||
let vote = VoteTransaction::new_vote(
|
||||
&vote_account,
|
||||
keypair,
|
||||
bank.slot(),
|
||||
let vote_ix = VoteInstruction::new_vote(&vote_account, Vote::new(bank.slot()));
|
||||
let vote_tx = Transaction::new_signed_instructions(
|
||||
&[voting_keypair.as_ref()],
|
||||
vec![vote_ix],
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
);
|
||||
@ -310,7 +310,7 @@ impl ReplayStage {
|
||||
Self::handle_new_root(&bank_forks, progress);
|
||||
}
|
||||
locktower.update_epoch(&bank);
|
||||
cluster_info.write().unwrap().push_vote(vote);
|
||||
cluster_info.write().unwrap().push_vote(vote_tx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,10 +606,14 @@ mod test {
|
||||
&poh_recorder,
|
||||
);
|
||||
|
||||
let keypair = voting_keypair.as_ref();
|
||||
let vote =
|
||||
VoteTransaction::new_vote(&keypair.pubkey(), keypair, 0, bank.last_blockhash(), 0);
|
||||
cluster_info_me.write().unwrap().push_vote(vote);
|
||||
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(0));
|
||||
let vote_tx = Transaction::new_signed_instructions(
|
||||
&[voting_keypair.as_ref()],
|
||||
vec![vote_ix],
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
);
|
||||
cluster_info_me.write().unwrap().push_vote(vote_tx);
|
||||
|
||||
info!("Send ReplayStage an entry, should see it on the ledger writer receiver");
|
||||
let next_tick = create_ticks(1, bank.last_blockhash());
|
||||
|
@ -106,9 +106,17 @@ impl VotingKeypair {
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_sdk::instruction::Instruction;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
|
||||
fn process_instructions<T: KeypairUtil>(bank: &Bank, keypairs: &[&T], ixs: Vec<Instruction>) {
|
||||
let blockhash = bank.last_blockhash();
|
||||
let tx = Transaction::new_signed_instructions(keypairs, ixs, blockhash, 0);
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
}
|
||||
|
||||
pub fn new_vote_account(
|
||||
from_keypair: &Keypair,
|
||||
@ -116,9 +124,8 @@ pub mod tests {
|
||||
bank: &Bank,
|
||||
lamports: u64,
|
||||
) {
|
||||
let blockhash = bank.last_blockhash();
|
||||
let tx = VoteTransaction::new_account(from_keypair, voting_pubkey, blockhash, lamports, 0);
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
let ixs = VoteInstruction::new_account(&from_keypair.pubkey(), voting_pubkey, lamports);
|
||||
process_instructions(bank, &[from_keypair], ixs);
|
||||
}
|
||||
|
||||
pub fn new_vote_account_with_delegate(
|
||||
@ -128,33 +135,32 @@ pub mod tests {
|
||||
bank: &Bank,
|
||||
lamports: u64,
|
||||
) {
|
||||
let blockhash = bank.last_blockhash();
|
||||
let tx = VoteTransaction::new_account_with_delegate(
|
||||
from_keypair,
|
||||
voting_keypair,
|
||||
let voting_pubkey = voting_keypair.pubkey();
|
||||
let mut ixs =
|
||||
VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
||||
ixs.push(VoteInstruction::new_delegate_stake(
|
||||
&voting_pubkey,
|
||||
delegate,
|
||||
blockhash,
|
||||
lamports,
|
||||
0,
|
||||
);
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
));
|
||||
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
||||
}
|
||||
|
||||
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
|
||||
let blockhash = bank.last_blockhash();
|
||||
let tx =
|
||||
VoteTransaction::new_vote(&voting_keypair.pubkey(), voting_keypair, slot, blockhash, 0);
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
let ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(slot));
|
||||
process_instructions(bank, &[voting_keypair], vec![ix]);
|
||||
}
|
||||
|
||||
pub fn new_vote_account_with_vote<T: KeypairUtil>(
|
||||
from_keypair: &Keypair,
|
||||
from_keypair: &T,
|
||||
voting_keypair: &T,
|
||||
bank: &Bank,
|
||||
lamports: u64,
|
||||
slot: u64,
|
||||
) {
|
||||
new_vote_account(from_keypair, &voting_keypair.pubkey(), bank, lamports);
|
||||
push_vote(voting_keypair, bank, slot);
|
||||
let voting_pubkey = voting_keypair.pubkey();
|
||||
let mut ixs =
|
||||
VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
||||
ixs.push(VoteInstruction::new_vote(&voting_pubkey, Vote::new(slot)));
|
||||
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user