Cherry-pick vote and stake authority changes (#6127)

* add authorized parameters to vote api (#6072)

* add authorized parameters to vote api

* code review

* add authorities to stake init (#6104)

* add authorities to stake init

* fixups

* code review
This commit is contained in:
Tyera Eulberg
2019-09-26 17:18:31 -06:00
committed by GitHub
parent 232d2b3899
commit 61930c0dd3
14 changed files with 947 additions and 428 deletions

View File

@@ -228,7 +228,7 @@ mod tests {
let ancestors = vec![3, 4, 5, 7, 9, 11];
let mut confidence = HashMap::new();
let lamports = 5;
let mut vote_state = VoteState::new(&Pubkey::default(), &Pubkey::default(), 0);
let mut vote_state = VoteState::default();
let root = ancestors.last().unwrap();
vote_state.root_slot = Some(*root);
@@ -251,7 +251,7 @@ mod tests {
let ancestors = vec![3, 4, 5, 7, 9, 11];
let mut confidence = HashMap::new();
let lamports = 5;
let mut vote_state = VoteState::new(&Pubkey::default(), &Pubkey::default(), 0);
let mut vote_state = VoteState::default();
let root = ancestors[2];
vote_state.root_slot = Some(root);
@@ -281,7 +281,7 @@ mod tests {
let ancestors = vec![3, 4, 5, 7, 9, 10, 11];
let mut confidence = HashMap::new();
let lamports = 5;
let mut vote_state = VoteState::new(&Pubkey::default(), &Pubkey::default(), 0);
let mut vote_state = VoteState::default();
let root = ancestors[2];
vote_state.root_slot = Some(root);
@@ -319,18 +319,20 @@ mod tests {
mut genesis_block, ..
} = create_genesis_block(10_000);
let sk1 = Pubkey::new_rand();
let pk1 = Pubkey::new_rand();
let mut vote_account1 = vote_state::create_account(&pk1, &Pubkey::new_rand(), 0, 100);
let stake_account1 = stake_state::create_account(&pk1, &vote_account1, 100);
let stake_account1 = stake_state::create_account(&sk1, &pk1, &vote_account1, 100);
let sk2 = Pubkey::new_rand();
let pk2 = Pubkey::new_rand();
let mut vote_account2 = vote_state::create_account(&pk2, &Pubkey::new_rand(), 0, 50);
let stake_account2 = stake_state::create_account(&pk2, &vote_account2, 50);
let stake_account2 = stake_state::create_account(&sk2, &pk2, &vote_account2, 50);
genesis_block.accounts.extend(vec![
(pk1, vote_account1.clone()),
(Pubkey::new_rand(), stake_account1),
(sk1, stake_account1),
(pk2, vote_account2.clone()),
(Pubkey::new_rand(), stake_account2),
(sk2, stake_account2),
]);
// Create bank

View File

@@ -1,9 +1,7 @@
use solana_runtime::bank::Bank;
use solana_sdk::account::Account;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{account::Account, pubkey::Pubkey};
use solana_vote_api::vote_state::VoteState;
use std::borrow::Borrow;
use std::collections::HashMap;
use std::{borrow::Borrow, collections::HashMap};
/// Looks through vote accounts, and finds the latest slot that has achieved
/// supermajority lockout
@@ -99,14 +97,18 @@ where
pub(crate) mod tests {
use super::*;
use crate::genesis_utils::{create_genesis_block, GenesisBlockInfo, BOOTSTRAP_LEADER_LAMPORTS};
use solana_sdk::instruction::Instruction;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::sysvar::stake_history::{self, StakeHistory};
use solana_sdk::transaction::Transaction;
use solana_stake_api::stake_instruction;
use solana_stake_api::stake_state::Stake;
use solana_vote_api::vote_instruction;
use solana_sdk::{
instruction::Instruction,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
sysvar::stake_history::{self, StakeHistory},
transaction::Transaction,
};
use solana_stake_api::{
stake_instruction,
stake_state::{Authorized, Stake},
};
use solana_vote_api::{vote_instruction, vote_state::VoteInit};
use std::sync::Arc;
fn new_from_parent(parent: &Arc<Bank>, slot: u64) -> Bank {
@@ -140,8 +142,12 @@ pub(crate) mod tests {
vote_instruction::create_account(
&from_account.pubkey(),
vote_pubkey,
node_pubkey,
0,
&VoteInit {
node_pubkey: *node_pubkey,
authorized_voter: *vote_pubkey,
authorized_withdrawer: *vote_pubkey,
commission: 0,
},
amount,
),
);
@@ -157,6 +163,7 @@ pub(crate) mod tests {
&stake_account_pubkey,
vote_pubkey,
amount,
&Authorized::auto(&stake_account_pubkey),
),
);
}
@@ -288,15 +295,28 @@ pub(crate) mod tests {
fn test_to_staked_nodes() {
let mut stakes = Vec::new();
let node1 = Pubkey::new_rand();
let node2 = Pubkey::new_rand();
// Node 1 has stake of 3
for i in 0..3 {
stakes.push((i, VoteState::new(&Pubkey::new_rand(), &node1, 0)));
stakes.push((
i,
VoteState::new(&VoteInit {
node_pubkey: node1,
..VoteInit::default()
}),
));
}
// Node 1 has stake of 5
stakes.push((5, VoteState::new(&Pubkey::new_rand(), &node2, 0)));
let node2 = Pubkey::new_rand();
stakes.push((
5,
VoteState::new(&VoteInit {
node_pubkey: node2,
..VoteInit::default()
}),
));
let result = to_staked_nodes(stakes.into_iter());
assert_eq!(result.len(), 2);