fix single node testnet, remove bootstrap vote (#5534)
This commit is contained in:
parent
4ee212ae4c
commit
94f1132fb6
|
@ -166,6 +166,7 @@ impl Tower {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn record_vote(&mut self, slot: u64, hash: Hash) -> Option<u64> {
|
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 root_slot = self.lockouts.root_slot;
|
||||||
let vote = Vote { slot, hash };
|
let vote = Vote { slot, hash };
|
||||||
self.lockouts.process_vote_unchecked(&vote);
|
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) {
|
if let Some((_stake, vote_account)) = bank.vote_accounts().get(vote_account_pubkey) {
|
||||||
let vote_state = VoteState::deserialize(&vote_account.data)
|
let vote_state = VoteState::deserialize(&vote_account.data)
|
||||||
.expect("vote_account isn't a VoteState?");
|
.expect("vote_account isn't a VoteState?");
|
||||||
|
trace!(
|
||||||
|
"{} lockouts initialized to {:?}",
|
||||||
|
self.node_pubkey,
|
||||||
|
vote_state
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vote_state.node_pubkey, self.node_pubkey,
|
vote_state.node_pubkey, self.node_pubkey,
|
||||||
"vote account's node_pubkey doesn't match",
|
"vote account's node_pubkey doesn't match",
|
||||||
|
|
|
@ -586,7 +586,7 @@ impl ReplayStage {
|
||||||
})
|
})
|
||||||
.filter(|b| {
|
.filter(|b| {
|
||||||
let has_voted = tower.has_voted(b.slot());
|
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
|
!has_voted
|
||||||
})
|
})
|
||||||
.filter(|b| {
|
.filter(|b| {
|
||||||
|
|
|
@ -245,12 +245,17 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
let bootstrap_storage_keypair = read_keypair(bootstrap_storage_keypair_file)?;
|
let bootstrap_storage_keypair = read_keypair(bootstrap_storage_keypair_file)?;
|
||||||
let mint_keypair = read_keypair(mint_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_vote_keypair.pubkey(),
|
||||||
&bootstrap_leader_keypair.pubkey(),
|
&bootstrap_leader_keypair.pubkey(),
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
let stake_account = stake_state::create_account(
|
||||||
|
&bootstrap_vote_keypair.pubkey(),
|
||||||
|
&vote_account,
|
||||||
|
bootstrap_leader_stake_lamports,
|
||||||
|
);
|
||||||
|
|
||||||
let mut builder = Builder::new()
|
let mut builder = Builder::new()
|
||||||
.accounts(&[
|
.accounts(&[
|
||||||
|
@ -267,14 +272,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
// where votes go to
|
// where votes go to
|
||||||
(bootstrap_vote_keypair.pubkey(), vote_account),
|
(bootstrap_vote_keypair.pubkey(), vote_account),
|
||||||
// passive bootstrap leader stake
|
// passive bootstrap leader stake
|
||||||
(
|
(bootstrap_stake_keypair.pubkey(), stake_account),
|
||||||
bootstrap_stake_keypair.pubkey(),
|
|
||||||
stake_state::create_stake_account(
|
|
||||||
&bootstrap_vote_keypair.pubkey(),
|
|
||||||
&vote_state,
|
|
||||||
bootstrap_leader_stake_lamports,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
bootstrap_storage_keypair.pubkey(),
|
bootstrap_storage_keypair.pubkey(),
|
||||||
storage_contract::create_validator_storage_account(
|
storage_contract::create_validator_storage_account(
|
||||||
|
|
|
@ -417,18 +417,16 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility function, used by Bank, tests, genesis
|
// utility function, used by Bank, tests, genesis
|
||||||
pub fn create_stake_account(
|
pub fn create_account(voter_pubkey: &Pubkey, vote_account: &Account, lamports: u64) -> Account {
|
||||||
voter_pubkey: &Pubkey,
|
|
||||||
vote_state: &VoteState,
|
|
||||||
lamports: u64,
|
|
||||||
) -> Account {
|
|
||||||
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
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
|
stake_account
|
||||||
.set_state(&StakeState::Stake(Stake::new_bootstrap(
|
.set_state(&StakeState::Stake(Stake::new_bootstrap(
|
||||||
lamports,
|
lamports,
|
||||||
voter_pubkey,
|
voter_pubkey,
|
||||||
vote_state,
|
&vote_state,
|
||||||
)))
|
)))
|
||||||
.expect("set_state");
|
.expect("set_state");
|
||||||
|
|
||||||
|
|
|
@ -380,25 +380,6 @@ pub fn create_account(
|
||||||
vote_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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn test_vote_serialize() {
|
fn test_vote_serialize() {
|
||||||
let mut buffer: Vec<u8> = vec![0; VoteState::size_of()];
|
let mut buffer: Vec<u8> = vec![0; VoteState::size_of()];
|
||||||
|
|
|
@ -6,7 +6,7 @@ use solana_sdk::{
|
||||||
signature::{Keypair, KeypairUtil},
|
signature::{Keypair, KeypairUtil},
|
||||||
system_program,
|
system_program,
|
||||||
};
|
};
|
||||||
use solana_stake_api;
|
use solana_stake_api::stake_state;
|
||||||
use solana_vote_api::vote_state;
|
use solana_vote_api::vote_state;
|
||||||
|
|
||||||
// The default stake placed with the bootstrap leader
|
// 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 voting_keypair = Keypair::new();
|
||||||
let staking_keypair = Keypair::new();
|
let staking_keypair = Keypair::new();
|
||||||
|
|
||||||
// TODO: de-duplicate the stake once passive staking
|
// TODO: de-duplicate the stake... passive staking is fully implemented
|
||||||
// is fully implemented
|
let vote_account = vote_state::create_account(
|
||||||
let (vote_account, vote_state) = vote_state::create_bootstrap_leader_account(
|
|
||||||
&voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
&bootstrap_leader_pubkey,
|
&bootstrap_leader_pubkey,
|
||||||
0,
|
0,
|
||||||
bootstrap_leader_stake_lamports,
|
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()
|
let mut builder = Builder::new()
|
||||||
.accounts(&[
|
.accounts(&[
|
||||||
// the mint
|
// the mint
|
||||||
|
@ -57,14 +62,7 @@ pub fn create_genesis_block_with_leader(
|
||||||
// where votes go to
|
// where votes go to
|
||||||
(voting_keypair.pubkey(), vote_account),
|
(voting_keypair.pubkey(), vote_account),
|
||||||
// passive bootstrap leader stake, duplicates above temporarily
|
// passive bootstrap leader stake, duplicates above temporarily
|
||||||
(
|
(staking_keypair.pubkey(), stake_account),
|
||||||
staking_keypair.pubkey(),
|
|
||||||
solana_stake_api::stake_state::create_stake_account(
|
|
||||||
&voting_keypair.pubkey(),
|
|
||||||
&vote_state,
|
|
||||||
bootstrap_leader_stake_lamports,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
// Bare minimum program set
|
// Bare minimum program set
|
||||||
.native_instruction_processors(&[
|
.native_instruction_processors(&[
|
||||||
|
|
|
@ -222,7 +222,11 @@ pub mod tests {
|
||||||
pub fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, Account) {
|
pub fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, Account) {
|
||||||
(
|
(
|
||||||
Pubkey::new_rand(),
|
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,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue