_id => _pubkey variable renaming (#4419)

* wallet: rename *_account_id to *_account_pubkey

* s/from_id/from_pubkey/g

* s/node_id/node_pubkey/g

* s/stake_id/stake_pubkey/g

* s/voter_id/voter_pubkey/g

* s/vote_id/vote_pubkey/g

* s/delegate_id/delegate_pubkey/g

* s/account_id/account_pubkey/g

* s/to_id/to_pubkey/g

* s/my_id/my_pubkey/g

* cargo fmt

* s/staker_id/staker_pubkey/g

* s/mining_pool_id/mining_pool_pubkey/g

* s/leader_id/leader_pubkey/g

* cargo fmt

* s/funding_id/funding_pubkey/g
This commit is contained in:
Michael Vines
2019-05-23 23:20:04 -07:00
committed by GitHub
parent 94beb4b8c2
commit cfe5afd34c
42 changed files with 697 additions and 620 deletions

View File

@ -295,8 +295,8 @@ impl AccountsDB {
};
if candidates.is_empty() {
let mut stores = self.storage.write().unwrap();
let path_idx = thread_rng().gen_range(0, self.paths.len());
let storage = Arc::new(self.new_storage_entry(fork_id, &self.paths[path_idx]));
let path_index = thread_rng().gen_range(0, self.paths.len());
let storage = Arc::new(self.new_storage_entry(fork_id, &self.paths[path_index]));
stores.insert(storage.id, storage.clone());
candidates.push(storage);
}

View File

@ -268,7 +268,7 @@ impl Bank {
fn process_genesis_block(&mut self, genesis_block: &GenesisBlock) {
// Bootstrap leader collects fees until `new_from_parent` is called.
self.collector_id = genesis_block.bootstrap_leader_id;
self.collector_id = genesis_block.bootstrap_leader_pubkey;
self.fee_calculator = genesis_block.fee_calculator.clone();
for (pubkey, account) in genesis_block.accounts.iter() {
@ -1017,7 +1017,7 @@ mod tests {
#[test]
fn test_bank_new() {
let dummy_leader_id = Pubkey::new_rand();
let dummy_leader_pubkey = Pubkey::new_rand();
let dummy_leader_lamports = BOOTSTRAP_LEADER_LAMPORTS;
let mint_lamports = 10_000;
let GenesisBlockInfo {
@ -1027,7 +1027,7 @@ mod tests {
..
} = create_genesis_block_with_leader(
mint_lamports,
&dummy_leader_id,
&dummy_leader_pubkey,
dummy_leader_lamports,
);
let bank = Bank::new(&genesis_block);
@ -1599,10 +1599,10 @@ mod tests {
#[test]
fn test_bank_epoch_vote_accounts() {
let leader_id = Pubkey::new_rand();
let leader_pubkey = Pubkey::new_rand();
let leader_lamports = 3;
let mut genesis_block =
create_genesis_block_with_leader(5, &leader_id, leader_lamports).genesis_block;
create_genesis_block_with_leader(5, &leader_pubkey, leader_lamports).genesis_block;
// set this up weird, forces future generation, odd mod(), etc.
// this says: "vote_accounts for epoch X should be generated at slot index 3 in epoch X-2...
@ -1619,7 +1619,7 @@ mod tests {
.iter()
.filter_map(|(pubkey, (_, account))| {
if let Ok(vote_state) = VoteState::deserialize(&account.data) {
if vote_state.node_id == leader_id {
if vote_state.node_pubkey == leader_pubkey {
Some((*pubkey, true))
} else {
None
@ -1645,7 +1645,7 @@ mod tests {
// child crosses epoch boundary and is the first slot in the epoch
let child = Bank::new_from_parent(
&parent,
&leader_id,
&leader_pubkey,
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH),
);
@ -1654,7 +1654,7 @@ mod tests {
// child crosses epoch boundary but isn't the first slot in the epoch
let child = Bank::new_from_parent(
&parent,
&leader_id,
&leader_pubkey,
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH) + 1,
);
assert!(child.epoch_vote_accounts(i).is_some());

View File

@ -19,7 +19,7 @@ pub struct GenesisBlockInfo {
pub fn create_genesis_block_with_leader(
mint_lamports: u64,
bootstrap_leader_id: &Pubkey,
bootstrap_leader_pubkey: &Pubkey,
bootstrap_leader_stake_lamports: u64,
) -> GenesisBlockInfo {
let mint_keypair = Keypair::new();
@ -31,13 +31,13 @@ pub fn create_genesis_block_with_leader(
// is fully implemented
let (vote_account, vote_state) = vote_state::create_bootstrap_leader_account(
&voting_keypair.pubkey(),
&bootstrap_leader_id,
&bootstrap_leader_pubkey,
0,
bootstrap_leader_stake_lamports,
);
let genesis_block = GenesisBlock::new(
&bootstrap_leader_id,
&bootstrap_leader_pubkey,
&[
// the mint
(
@ -47,7 +47,7 @@ pub fn create_genesis_block_with_leader(
// node needs an account to issue votes and storage proofs from, this will require
// airdrops at some point to cover fees...
(
*bootstrap_leader_id,
*bootstrap_leader_pubkey,
Account::new(42, 0, &system_program::id()),
),
// where votes go to

View File

@ -11,7 +11,7 @@ use solana_sdk::system_instruction;
pub fn load_program(
bank_client: &BankClient,
from_keypair: &Keypair,
loader_id: &Pubkey,
loader_pubkey: &Pubkey,
program: Vec<u8>,
) -> Pubkey {
let program_keypair = Keypair::new();
@ -22,7 +22,7 @@ pub fn load_program(
&program_pubkey,
1,
program.len() as u64,
loader_id,
loader_pubkey,
);
bank_client
.send_instruction(&from_keypair, instruction)
@ -32,7 +32,7 @@ pub fn load_program(
let mut offset = 0;
for chunk in program.chunks(chunk_size) {
let instruction =
loader_instruction::write(&program_pubkey, loader_id, offset, chunk.to_vec());
loader_instruction::write(&program_pubkey, loader_pubkey, offset, chunk.to_vec());
let message = Message::new_with_payer(vec![instruction], Some(&from_keypair.pubkey()));
bank_client
.send_message(&[from_keypair, &program_keypair], message)
@ -40,7 +40,7 @@ pub fn load_program(
offset += chunk_size as u32;
}
let instruction = loader_instruction::finalize(&program_pubkey, loader_id);
let instruction = loader_instruction::finalize(&program_pubkey, loader_pubkey);
let message = Message::new_with_payer(vec![instruction], Some(&from_keypair.pubkey()));
bank_client
.send_message(&[from_keypair, &program_keypair], message)

View File

@ -107,12 +107,12 @@ mod tests {
}
fn setup() -> (Bank, Vec<Transaction>) {
let dummy_leader_id = Pubkey::new_rand();
let dummy_leader_pubkey = Pubkey::new_rand();
let GenesisBlockInfo {
genesis_block,
mint_keypair,
..
} = create_genesis_block_with_leader(500, &dummy_leader_id, 100);
} = create_genesis_block_with_leader(500, &dummy_leader_pubkey, 100);
let bank = Bank::new(&genesis_block);
let pubkey = Pubkey::new_rand();

View File

@ -15,12 +15,12 @@ pub struct Stakes {
}
impl Stakes {
// sum the stakes that point to the given voter_id
fn calculate_stake(&self, voter_id: &Pubkey) -> u64 {
// sum the stakes that point to the given voter_pubkey
fn calculate_stake(&self, voter_pubkey: &Pubkey) -> u64 {
self.stake_accounts
.iter()
.filter(|(_, stake_account)| {
Some(*voter_id) == StakeState::voter_id_from(stake_account)
Some(*voter_pubkey) == StakeState::voter_pubkey_from(stake_account)
})
.map(|(_, stake_account)| stake_account.lamports)
.sum()
@ -44,25 +44,25 @@ impl Stakes {
self.vote_accounts.insert(*pubkey, (stake, account.clone()));
}
} else if solana_stake_api::check_id(&account.owner) {
// old_stake is stake lamports and voter_id from the pre-store() version
// old_stake is stake lamports and voter_pubkey from the pre-store() version
let old_stake = self.stake_accounts.get(pubkey).and_then(|old_account| {
StakeState::voter_id_from(old_account)
.map(|old_voter_id| (old_account.lamports, old_voter_id))
StakeState::voter_pubkey_from(old_account)
.map(|old_voter_pubkey| (old_account.lamports, old_voter_pubkey))
});
let stake =
StakeState::voter_id_from(account).map(|voter_id| (account.lamports, voter_id));
let stake = StakeState::voter_pubkey_from(account)
.map(|voter_pubkey| (account.lamports, voter_pubkey));
// if adjustments need to be made...
if stake != old_stake {
if let Some((old_stake, old_voter_id)) = old_stake {
if let Some((old_stake, old_voter_pubkey)) = old_stake {
self.vote_accounts
.entry(old_voter_id)
.entry(old_voter_pubkey)
.and_modify(|e| e.0 -= old_stake);
}
if let Some((stake, voter_id)) = stake {
if let Some((stake, voter_pubkey)) = stake {
self.vote_accounts
.entry(voter_id)
.entry(voter_pubkey)
.and_modify(|e| e.0 += stake);
}
}
@ -88,19 +88,19 @@ mod tests {
// set up some dummies for a staked node (( vote ) ( stake ))
fn create_staked_node_accounts(stake: u64) -> ((Pubkey, Account), (Pubkey, Account)) {
let vote_id = Pubkey::new_rand();
let vote_account = vote_state::create_account(&vote_id, &Pubkey::new_rand(), 0, 1);
let vote_pubkey = Pubkey::new_rand();
let vote_account = vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 1);
(
(vote_id, vote_account),
create_stake_account(stake, &vote_id),
(vote_pubkey, vote_account),
create_stake_account(stake, &vote_pubkey),
)
}
// add stake to a vote_id ( stake )
fn create_stake_account(stake: u64, vote_id: &Pubkey) -> (Pubkey, Account) {
// add stake to a vote_pubkey ( stake )
fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, Account) {
(
Pubkey::new_rand(),
stake_state::create_delegate_stake_account(&vote_id, &VoteState::default(), stake),
stake_state::create_delegate_stake_account(&vote_pubkey, &VoteState::default(), stake),
)
}
@ -108,32 +108,32 @@ mod tests {
fn test_stakes_basic() {
let mut stakes = Stakes::default();
let ((vote_id, vote_account), (stake_id, mut stake_account)) =
let ((vote_pubkey, vote_account), (stake_pubkey, mut stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_id, &vote_account);
stakes.store(&stake_id, &stake_account);
stakes.store(&vote_pubkey, &vote_account);
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 10);
}
stake_account.lamports = 42;
stakes.store(&stake_id, &stake_account);
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 42);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 42);
}
stake_account.lamports = 0;
stakes.store(&stake_id, &stake_account);
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 0);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 0);
}
}
@ -141,32 +141,32 @@ mod tests {
fn test_stakes_vote_account_disappear_reappear() {
let mut stakes = Stakes::default();
let ((vote_id, mut vote_account), (stake_id, stake_account)) =
let ((vote_pubkey, mut vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_id, &vote_account);
stakes.store(&stake_id, &stake_account);
stakes.store(&vote_pubkey, &vote_account);
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 10);
}
vote_account.lamports = 0;
stakes.store(&vote_id, &vote_account);
stakes.store(&vote_pubkey, &vote_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_none());
assert!(vote_accounts.get(&vote_pubkey).is_none());
}
vote_account.lamports = 1;
stakes.store(&vote_id, &vote_account);
stakes.store(&vote_pubkey, &vote_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 10);
}
}
@ -174,54 +174,56 @@ mod tests {
fn test_stakes_change_delegate() {
let mut stakes = Stakes::default();
let ((vote_id, vote_account), (stake_id, stake_account)) = create_staked_node_accounts(10);
let ((vote_id2, vote_account2), (_stake_id2, stake_account2)) =
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_id, &vote_account);
stakes.store(&vote_id2, &vote_account2);
let ((vote_pubkey2, vote_account2), (_stake_pubkey2, stake_account2)) =
create_staked_node_accounts(10);
// delegates to vote_id
stakes.store(&stake_id, &stake_account);
stakes.store(&vote_pubkey, &vote_account);
stakes.store(&vote_pubkey2, &vote_account2);
// delegates to vote_pubkey
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 10);
assert!(vote_accounts.get(&vote_id2).is_some());
assert_eq!(vote_accounts.get(&vote_id2).unwrap().0, 0);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey2).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey2).unwrap().0, 0);
}
// delegates to vote_id2
stakes.store(&stake_id, &stake_account2);
// delegates to vote_pubkey2
stakes.store(&stake_pubkey, &stake_account2);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 0);
assert!(vote_accounts.get(&vote_id2).is_some());
assert_eq!(vote_accounts.get(&vote_id2).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 0);
assert!(vote_accounts.get(&vote_pubkey2).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey2).unwrap().0, 10);
}
}
#[test]
fn test_stakes_multiple_stakers() {
let mut stakes = Stakes::default();
let ((vote_id, vote_account), (stake_id, stake_account)) = create_staked_node_accounts(10);
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
let (stake_id2, stake_account2) = create_stake_account(10, &vote_id);
let (stake_pubkey2, stake_account2) = create_stake_account(10, &vote_pubkey);
stakes.store(&vote_id, &vote_account);
stakes.store(&vote_pubkey, &vote_account);
// delegates to vote_id
stakes.store(&stake_id, &stake_account);
stakes.store(&stake_id2, &stake_account2);
// delegates to vote_pubkey
stakes.store(&stake_pubkey, &stake_account);
stakes.store(&stake_pubkey2, &stake_account2);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 20);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 20);
}
}
@ -229,23 +231,24 @@ mod tests {
fn test_stakes_not_delegate() {
let mut stakes = Stakes::default();
let ((vote_id, vote_account), (stake_id, stake_account)) = create_staked_node_accounts(10);
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_id, &vote_account);
stakes.store(&stake_id, &stake_account);
stakes.store(&vote_pubkey, &vote_account);
stakes.store(&stake_pubkey, &stake_account);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 10);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 10);
}
// not a stake account, and whacks above entry
stakes.store(&stake_id, &Account::new(1, 0, &solana_stake_api::id()));
stakes.store(&stake_pubkey, &Account::new(1, 0, &solana_stake_api::id()));
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_id).is_some());
assert_eq!(vote_accounts.get(&vote_id).unwrap().0, 0);
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey).unwrap().0, 0);
}
}