reduce replicode, introduce passive staking support (#4207)
This commit is contained in:
@ -26,9 +26,9 @@ serde_json = "1.0.38"
|
||||
solana-logger = { path = "../logger", version = "0.15.0" }
|
||||
solana-metrics = { path = "../metrics", version = "0.15.0" }
|
||||
solana-sdk = { path = "../sdk", version = "0.15.0" }
|
||||
solana-stake-api = { path = "../programs/stake_api", version = "0.15.0" }
|
||||
solana-vote-api = { path = "../programs/vote_api", version = "0.15.0" }
|
||||
|
||||
[lib]
|
||||
name = "solana_runtime"
|
||||
crate-type = ["lib"]
|
||||
|
||||
|
@ -1042,52 +1042,17 @@ impl Drop for Bank {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::genesis_utils::{create_genesis_block_with_leader, BOOTSTRAP_LEADER_LAMPORTS};
|
||||
use solana_sdk::genesis_block::create_genesis_block;
|
||||
use solana_sdk::hash;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction;
|
||||
use solana_sdk::system_program;
|
||||
use solana_sdk::system_transaction;
|
||||
use solana_vote_api::vote_instruction;
|
||||
use solana_vote_api::vote_state::{self, VoteState};
|
||||
|
||||
// The default stake placed with the bootstrap leader
|
||||
pub(crate) const BOOTSTRAP_LEADER_LAMPORTS: u64 = 42;
|
||||
|
||||
pub(crate) fn create_genesis_block_with_leader(
|
||||
mint_lamports: u64,
|
||||
leader_id: &Pubkey,
|
||||
leader_stake_lamports: u64,
|
||||
) -> (GenesisBlock, Keypair, Keypair) {
|
||||
let mint_keypair = Keypair::new();
|
||||
let voting_keypair = Keypair::new();
|
||||
|
||||
let genesis_block = GenesisBlock::new(
|
||||
&leader_id,
|
||||
&[
|
||||
(
|
||||
mint_keypair.pubkey(),
|
||||
Account::new(mint_lamports, 0, &system_program::id()),
|
||||
),
|
||||
(
|
||||
voting_keypair.pubkey(),
|
||||
vote_state::create_bootstrap_leader_account(
|
||||
&voting_keypair.pubkey(),
|
||||
&leader_id,
|
||||
0,
|
||||
leader_stake_lamports,
|
||||
),
|
||||
),
|
||||
],
|
||||
&[],
|
||||
);
|
||||
|
||||
(genesis_block, mint_keypair, voting_keypair)
|
||||
}
|
||||
use solana_vote_api::vote_state::VoteState;
|
||||
|
||||
#[test]
|
||||
fn test_bank_new() {
|
||||
|
60
runtime/src/genesis_utils.rs
Normal file
60
runtime/src/genesis_utils.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_program;
|
||||
use solana_stake_api::stake_state;
|
||||
use solana_vote_api::vote_state;
|
||||
|
||||
// The default stake placed with the bootstrap leader
|
||||
pub const BOOTSTRAP_LEADER_LAMPORTS: u64 = 42;
|
||||
|
||||
pub fn create_genesis_block_with_leader(
|
||||
mint_lamports: u64,
|
||||
bootstrap_leader_id: &Pubkey,
|
||||
bootstrap_leader_stake_lamports: u64,
|
||||
) -> (GenesisBlock, Keypair, Keypair) {
|
||||
let mint_keypair = Keypair::new();
|
||||
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(
|
||||
&voting_keypair.pubkey(),
|
||||
&bootstrap_leader_id,
|
||||
0,
|
||||
bootstrap_leader_stake_lamports,
|
||||
);
|
||||
|
||||
let genesis_block = GenesisBlock::new(
|
||||
&bootstrap_leader_id,
|
||||
&[
|
||||
// the mint
|
||||
(
|
||||
mint_keypair.pubkey(),
|
||||
Account::new(mint_lamports, 0, &system_program::id()),
|
||||
),
|
||||
// node needs an account to issue votes from, this will require
|
||||
// airdrops at some point to cover fees...
|
||||
(
|
||||
*bootstrap_leader_id,
|
||||
Account::new(1, 0, &system_program::id()),
|
||||
),
|
||||
// where votes go to
|
||||
(voting_keypair.pubkey(), vote_account),
|
||||
// passive bootstrap leader stake, duplicates above temporarily
|
||||
(
|
||||
staking_keypair.pubkey(),
|
||||
stake_state::create_delegate_stake_account(
|
||||
&voting_keypair.pubkey(),
|
||||
&vote_state,
|
||||
bootstrap_leader_stake_lamports,
|
||||
),
|
||||
),
|
||||
],
|
||||
&[],
|
||||
);
|
||||
|
||||
(genesis_block, mint_keypair, voting_keypair)
|
||||
}
|
@ -6,6 +6,7 @@ pub mod bank;
|
||||
pub mod bank_client;
|
||||
mod blockhash_queue;
|
||||
pub mod bloom;
|
||||
pub mod genesis_utils;
|
||||
pub mod loader_utils;
|
||||
pub mod locked_accounts_results;
|
||||
pub mod message_processor;
|
||||
|
@ -53,7 +53,7 @@ impl<'a, 'b, I: Borrow<Transaction>> Drop for LockedAccountsResults<'a, 'b, I> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bank::tests::create_genesis_block_with_leader;
|
||||
use crate::genesis_utils::create_genesis_block_with_leader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction;
|
||||
|
Reference in New Issue
Block a user