plumb staking_account and voting_keypair from multinode-demo to Vote (#3199)
* plumb staking_account and voting_keypair from bash to Vote
This commit is contained in:
committed by
Greg Fitzgerald
parent
c8c85ff93b
commit
0acdbc0d03
@ -39,9 +39,15 @@ impl<'a> RewardsBank<'a> {
|
||||
self.bank.process_transaction(&tx)
|
||||
}
|
||||
|
||||
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
||||
fn submit_vote(
|
||||
&self,
|
||||
staking_account: Pubkey,
|
||||
vote_keypair: &Keypair,
|
||||
tick_height: u64,
|
||||
) -> Result<VoteState> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, blockhash, 0);
|
||||
let tx =
|
||||
VoteTransaction::new_vote(staking_account, vote_keypair, tick_height, blockhash, 0);
|
||||
self.bank.process_transaction(&tx)?;
|
||||
self.bank.register_tick(&hash(blockhash.as_ref()));
|
||||
|
||||
@ -80,11 +86,17 @@ fn test_redeem_vote_credits_via_bank() {
|
||||
|
||||
// The validator submits votes to accumulate credits.
|
||||
for i in 0..vote_state::MAX_LOCKOUT_HISTORY {
|
||||
let vote_state = rewards_bank.submit_vote(&vote_keypair, i as u64).unwrap();
|
||||
let vote_state = rewards_bank
|
||||
.submit_vote(vote_id, &vote_keypair, i as u64)
|
||||
.unwrap();
|
||||
assert_eq!(vote_state.credits(), 0);
|
||||
}
|
||||
let vote_state = rewards_bank
|
||||
.submit_vote(&vote_keypair, vote_state::MAX_LOCKOUT_HISTORY as u64 + 1)
|
||||
.submit_vote(
|
||||
vote_id,
|
||||
&vote_keypair,
|
||||
vote_state::MAX_LOCKOUT_HISTORY as u64 + 1,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(vote_state.credits(), 1);
|
||||
|
||||
|
@ -51,9 +51,15 @@ impl<'a> VoteBank<'a> {
|
||||
self.bank.process_transaction(&tx)
|
||||
}
|
||||
|
||||
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
||||
fn submit_vote(
|
||||
&self,
|
||||
staking_account: Pubkey,
|
||||
vote_keypair: &Keypair,
|
||||
tick_height: u64,
|
||||
) -> Result<VoteState> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, blockhash, 0);
|
||||
let tx =
|
||||
VoteTransaction::new_vote(staking_account, vote_keypair, tick_height, blockhash, 0);
|
||||
self.bank.process_transaction(&tx)?;
|
||||
self.bank.register_tick(&hash(blockhash.as_ref()));
|
||||
|
||||
@ -74,7 +80,7 @@ fn test_vote_bank_basic() {
|
||||
.create_vote_account(&from_keypair, vote_id, 100)
|
||||
.unwrap();
|
||||
|
||||
let vote_state = vote_bank.submit_vote(&vote_keypair, 0).unwrap();
|
||||
let vote_state = vote_bank.submit_vote(vote_id, &vote_keypair, 0).unwrap();
|
||||
assert_eq!(vote_state.votes.len(), 1);
|
||||
}
|
||||
|
||||
|
@ -15,21 +15,22 @@ pub struct VoteTransaction {}
|
||||
|
||||
impl VoteTransaction {
|
||||
pub fn new_vote<T: KeypairUtil>(
|
||||
voting_keypair: &T,
|
||||
staking_account: Pubkey,
|
||||
authorized_voter_keypair: &T,
|
||||
slot: u64,
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let vote = Vote { slot };
|
||||
TransactionBuilder::new(fee)
|
||||
.push(VoteInstruction::new_vote(voting_keypair.pubkey(), vote))
|
||||
.sign(&[voting_keypair], recent_blockhash)
|
||||
.push(VoteInstruction::new_vote(staking_account, vote))
|
||||
.sign(&[authorized_voter_keypair], recent_blockhash)
|
||||
}
|
||||
|
||||
/// Fund or create the staking account with lamports
|
||||
pub fn new_account(
|
||||
from_keypair: &Keypair,
|
||||
voter_id: Pubkey,
|
||||
staker_id: Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
lamports: u64,
|
||||
fee: u64,
|
||||
@ -39,12 +40,12 @@ impl VoteTransaction {
|
||||
TransactionBuilder::new(fee)
|
||||
.push(SystemInstruction::new_program_account(
|
||||
from_id,
|
||||
voter_id,
|
||||
staker_id,
|
||||
lamports,
|
||||
space,
|
||||
id(),
|
||||
))
|
||||
.push(VoteInstruction::new_initialize_account(voter_id))
|
||||
.push(VoteInstruction::new_initialize_account(staker_id))
|
||||
.sign(&[from_keypair], recent_blockhash)
|
||||
}
|
||||
|
||||
@ -131,7 +132,8 @@ mod tests {
|
||||
let keypair = Keypair::new();
|
||||
let slot = 1;
|
||||
let recent_blockhash = Hash::default();
|
||||
let transaction = VoteTransaction::new_vote(&keypair, slot, recent_blockhash, 0);
|
||||
let transaction =
|
||||
VoteTransaction::new_vote(keypair.pubkey(), &keypair, slot, recent_blockhash, 0);
|
||||
assert_eq!(
|
||||
VoteTransaction::get_votes(&transaction),
|
||||
vec![(keypair.pubkey(), Vote::new(slot), recent_blockhash)]
|
||||
|
Reference in New Issue
Block a user