fix single node testnet, remove bootstrap vote (#5534)

This commit is contained in:
Rob Walker 2019-08-15 18:58:46 -07:00 committed by GitHub
parent 4ee212ae4c
commit 94f1132fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 58 deletions

View File

@ -166,6 +166,7 @@ impl Tower {
}
pub fn record_vote(&mut self, slot: u64, hash: Hash) -> Option<u64> {
trace!("{} record_vote for {}", self.node_pubkey, slot);
let root_slot = self.lockouts.root_slot;
let vote = Vote { slot, hash };
self.lockouts.process_vote_unchecked(&vote);
@ -344,6 +345,12 @@ impl Tower {
if let Some((_stake, vote_account)) = bank.vote_accounts().get(vote_account_pubkey) {
let vote_state = VoteState::deserialize(&vote_account.data)
.expect("vote_account isn't a VoteState?");
trace!(
"{} lockouts initialized to {:?}",
self.node_pubkey,
vote_state
);
assert_eq!(
vote_state.node_pubkey, self.node_pubkey,
"vote account's node_pubkey doesn't match",

View File

@ -586,7 +586,7 @@ impl ReplayStage {
})
.filter(|b| {
let has_voted = tower.has_voted(b.slot());
trace!("bank is has_voted: {} {}", b.slot(), has_voted);
trace!("bank has_voted: {} {}", b.slot(), has_voted);
!has_voted
})
.filter(|b| {

View File

@ -245,12 +245,17 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_storage_keypair = read_keypair(bootstrap_storage_keypair_file)?;
let mint_keypair = read_keypair(mint_keypair_file)?;
let (vote_account, vote_state) = vote_state::create_bootstrap_leader_account(
let vote_account = vote_state::create_account(
&bootstrap_vote_keypair.pubkey(),
&bootstrap_leader_keypair.pubkey(),
0,
1,
);
let stake_account = stake_state::create_account(
&bootstrap_vote_keypair.pubkey(),
&vote_account,
bootstrap_leader_stake_lamports,
);
let mut builder = Builder::new()
.accounts(&[
@ -267,14 +272,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
// where votes go to
(bootstrap_vote_keypair.pubkey(), vote_account),
// passive bootstrap leader stake
(
bootstrap_stake_keypair.pubkey(),
stake_state::create_stake_account(
&bootstrap_vote_keypair.pubkey(),
&vote_state,
bootstrap_leader_stake_lamports,
),
),
(bootstrap_stake_keypair.pubkey(), stake_account),
(
bootstrap_storage_keypair.pubkey(),
storage_contract::create_validator_storage_account(

View File

@ -417,18 +417,16 @@ where
}
// utility function, used by Bank, tests, genesis
pub fn create_stake_account(
voter_pubkey: &Pubkey,
vote_state: &VoteState,
lamports: u64,
) -> Account {
pub fn create_account(voter_pubkey: &Pubkey, vote_account: &Account, lamports: u64) -> Account {
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
let vote_state = VoteState::from(vote_account).expect("vote_state");
stake_account
.set_state(&StakeState::Stake(Stake::new_bootstrap(
lamports,
voter_pubkey,
vote_state,
&vote_state,
)))
.expect("set_state");

View File

@ -380,25 +380,6 @@ pub fn create_account(
vote_account
}
// utility function, used by solana-genesis, tests
pub fn create_bootstrap_leader_account(
vote_pubkey: &Pubkey,
node_pubkey: &Pubkey,
commission: u8,
vote_lamports: u64,
) -> (Account, VoteState) {
// Construct a vote account for the bootstrap_leader such that the leader_scheduler
// will be forced to select it as the leader for height 0
let mut vote_account = create_account(&vote_pubkey, &node_pubkey, commission, vote_lamports);
let mut vote_state: VoteState = vote_account.state().unwrap();
// TODO: get a hash for slot 0?
vote_state.process_slot_vote_unchecked(0);
vote_account.set_state(&vote_state).unwrap();
(vote_account, vote_state)
}
#[cfg(test)]
mod tests {
use super::*;
@ -469,16 +450,6 @@ mod tests {
)
}
#[test]
fn test_vote_create_bootstrap_leader_account() {
let vote_pubkey = Pubkey::new_rand();
let (_vote_account, vote_state) =
vote_state::create_bootstrap_leader_account(&vote_pubkey, &Pubkey::new_rand(), 0, 100);
assert_eq!(vote_state.votes.len(), 1);
assert_eq!(vote_state.votes[0], Lockout::new(&Vote::default()));
}
#[test]
fn test_vote_serialize() {
let mut buffer: Vec<u8> = vec![0; VoteState::size_of()];

View File

@ -6,7 +6,7 @@ use solana_sdk::{
signature::{Keypair, KeypairUtil},
system_program,
};
use solana_stake_api;
use solana_stake_api::stake_state;
use solana_vote_api::vote_state;
// The default stake placed with the bootstrap leader
@ -32,15 +32,20 @@ pub fn create_genesis_block_with_leader(
let voting_keypair = Keypair::new();
let staking_keypair = Keypair::new();
// TODO: de-duplicate the stake once passive staking
// is fully implemented
let (vote_account, vote_state) = vote_state::create_bootstrap_leader_account(
// TODO: de-duplicate the stake... passive staking is fully implemented
let vote_account = vote_state::create_account(
&voting_keypair.pubkey(),
&bootstrap_leader_pubkey,
0,
bootstrap_leader_stake_lamports,
);
let stake_account = stake_state::create_account(
&voting_keypair.pubkey(),
&vote_account,
bootstrap_leader_stake_lamports,
);
let mut builder = Builder::new()
.accounts(&[
// the mint
@ -57,14 +62,7 @@ pub fn create_genesis_block_with_leader(
// where votes go to
(voting_keypair.pubkey(), vote_account),
// passive bootstrap leader stake, duplicates above temporarily
(
staking_keypair.pubkey(),
solana_stake_api::stake_state::create_stake_account(
&voting_keypair.pubkey(),
&vote_state,
bootstrap_leader_stake_lamports,
),
),
(staking_keypair.pubkey(), stake_account),
])
// Bare minimum program set
.native_instruction_processors(&[

View File

@ -222,7 +222,11 @@ pub mod tests {
pub fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, Account) {
(
Pubkey::new_rand(),
stake_state::create_stake_account(&vote_pubkey, &VoteState::default(), stake),
stake_state::create_account(
&vote_pubkey,
&vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 1),
stake,
),
)
}