Skip to content

Commit

Permalink
Storage stage no longer implicitly creates a storage account
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 23, 2019
1 parent 36bab88 commit e25ba04
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 67 deletions.
13 changes: 10 additions & 3 deletions core/src/cluster_tests.rs
Expand Up @@ -142,12 +142,19 @@ pub fn kill_entry_and_spend_and_verify_rest(
assert!(cluster_nodes.len() >= nodes);
let client = create_client(entry_point_info.client_facing_addr(), FULLNODE_PORT_RANGE);
let first_two_epoch_slots = MINIMUM_SLOT_LENGTH * 3;

for ingress_node in &cluster_nodes {
client
.poll_get_balance(&ingress_node.id)
.unwrap_or_else(|err| panic!("Node {} has no balance: {}", ingress_node.id, err));
}

info!("sleeping for 2 leader fortnights");
sleep(Duration::from_millis(
slot_millis * first_two_epoch_slots as u64,
));
info!("done sleeping for first 2 warmup epochs");
info!("killing entry point");
info!("killing entry point: {}", entry_point_info.id);
assert!(client.fullnode_exit().unwrap());
info!("sleeping for some time");
sleep(Duration::from_millis(
Expand All @@ -160,10 +167,10 @@ pub fn kill_entry_and_spend_and_verify_rest(
}

let client = create_client(ingress_node.client_facing_addr(), FULLNODE_PORT_RANGE);
let bal = client
let balance = client
.poll_get_balance(&funding_keypair.pubkey())
.expect("balance in source");
assert!(bal > 0);
assert_ne!(balance, 0);

let mut result = Ok(());
let mut retries = 0;
Expand Down
55 changes: 47 additions & 8 deletions core/src/local_cluster.rs
Expand Up @@ -11,6 +11,7 @@ use solana_client::thin_client::create_client;
use solana_client::thin_client::ThinClient;
use solana_sdk::client::SyncClient;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::message::Message;
use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
Expand All @@ -19,6 +20,7 @@ use solana_sdk::timing::DEFAULT_SLOTS_PER_EPOCH;
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::transaction::Transaction;
use solana_stake_api::stake_instruction;
use solana_storage_api::storage_instruction;
use solana_vote_api::vote_instruction;
use solana_vote_api::vote_state::VoteState;
use std::collections::HashMap;
Expand Down Expand Up @@ -120,6 +122,7 @@ impl LocalCluster {
mut genesis_block,
mint_keypair,
voting_keypair,
storage_keypair,
} = create_genesis_block_with_leader(
config.cluster_lamports,
&leader_pubkey,
Expand All @@ -135,7 +138,7 @@ impl LocalCluster {
let (genesis_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
let leader_contact_info = leader_node.info.clone();
let leader_storage_keypair = Arc::new(Keypair::new());
let leader_storage_keypair = Arc::new(storage_keypair);
let leader_voting_keypair = Arc::new(voting_keypair);
let leader_server = Fullnode::new(
leader_node,
Expand Down Expand Up @@ -238,12 +241,12 @@ impl LocalCluster {
// setup as a listener
info!("listener {} ", validator_pubkey,);
} else {
// Send each validator some lamports to vote
// Give the validator some lamports to setup vote and storage accounts
let validator_balance = Self::transfer_with_client(
&client,
&self.funding_keypair,
&validator_pubkey,
stake * 2 + 1,
stake * 2 + 2,
);
info!(
"validator {} balance {}",
Expand All @@ -257,6 +260,9 @@ impl LocalCluster {
stake,
)
.unwrap();

Self::setup_storage_account(&client, &storage_keypair, &validator_keypair, false)
.unwrap();
}

let voting_keypair = Arc::new(voting_keypair);
Expand Down Expand Up @@ -298,21 +304,24 @@ impl LocalCluster {

fn add_replicator(&mut self) {
let replicator_keypair = Arc::new(Keypair::new());
let replicator_id = replicator_keypair.pubkey();
let replicator_pubkey = replicator_keypair.pubkey();
let storage_keypair = Arc::new(Keypair::new());
let storage_id = storage_keypair.pubkey();
let storage_pubkey = storage_keypair.pubkey();
let client = create_client(
self.entry_point_info.client_facing_addr(),
FULLNODE_PORT_RANGE,
);

// Give the replicator some lamports to setup its storage accounts
Self::transfer_with_client(
&client,
&self.funding_keypair,
&replicator_keypair.pubkey(),
42,
);
let replicator_node = Node::new_localhost_replicator(&replicator_id);
let replicator_node = Node::new_localhost_replicator(&replicator_pubkey);

Self::setup_storage_account(&client, &storage_keypair, &replicator_keypair, true).unwrap();

let (replicator_ledger_path, _blockhash) = create_new_tmp_ledger!(&self.genesis_block);
let replicator = Replicator::new(
Expand All @@ -326,8 +335,8 @@ impl LocalCluster {

self.replicators.push(replicator);
self.replicator_infos.insert(
replicator_id,
ReplicatorInfo::new(storage_id, replicator_ledger_path),
replicator_pubkey,
ReplicatorInfo::new(storage_pubkey, replicator_ledger_path),
);
}

Expand Down Expand Up @@ -464,6 +473,36 @@ impl LocalCluster {
"expected successful vote account registration",
))
}

fn setup_storage_account(
client: &ThinClient,
storage_keypair: &Keypair,
from_keypair: &Arc<Keypair>,
replicator: bool,
) -> Result<()> {
let message = Message::new_with_payer(
if replicator {
storage_instruction::create_replicator_storage_account(
&from_keypair.pubkey(),
&storage_keypair.pubkey(),
1,
)
} else {
storage_instruction::create_validator_storage_account(
&from_keypair.pubkey(),
&storage_keypair.pubkey(),
1,
)
},
Some(&from_keypair.pubkey()),
);
let signer_keys = vec![from_keypair.as_ref()];
let blockhash = client.get_recent_blockhash().unwrap().0;
let mut transaction = Transaction::new(&signer_keys, message, blockhash);
client
.retry_transfer(&from_keypair, &mut transaction, 5)
.map(|_signature| ())
}
}

impl Cluster for LocalCluster {
Expand Down
60 changes: 14 additions & 46 deletions core/src/storage_stage.rs
Expand Up @@ -193,52 +193,12 @@ impl StorageStage {
.spawn(move || {
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();

// Create the validator storage account if necessary
loop {
let (blockhash, storage_account, keypair_balance) = {
let working_bank = bank_forks.read().unwrap().working_bank();
(
working_bank.confirmed_last_blockhash(),
working_bank.get_account(&storage_keypair.pubkey()),
working_bank.get_balance(&keypair.pubkey()),
)
};

if storage_account.is_some() {
info!("Storage account found: {}", storage_keypair.pubkey());
break;
}
info!("Creating validator storage account");
info!(
"keypair account balance: {}: {}",
keypair.pubkey(),
keypair_balance
);
let signer_keys = vec![keypair.as_ref()];
let message = Message::new_with_payer(
storage_instruction::create_validator_storage_account(
&keypair.pubkey(),
&storage_keypair.pubkey(),
1,
),
Some(&signer_keys[0].pubkey()),
);
let transaction = Transaction::new(&signer_keys, message, blockhash);

transactions_socket
.send_to(
&bincode::serialize(&transaction).unwrap(),
cluster_info.read().unwrap().my_data().tpu,
)
.unwrap_or_else(|err| {
info!("failed to send create storage transaction: {:?}", err);
0
});

if exit.load(Ordering::Relaxed) {
break;
{
let working_bank = bank_forks.read().unwrap().working_bank();
let storage_account = working_bank.get_account(&storage_keypair.pubkey());
if storage_account.is_none() {
warn!("Storage account not found: {}", storage_keypair.pubkey());
}
sleep(Duration::from_millis(100));
}

loop {
Expand Down Expand Up @@ -289,7 +249,15 @@ impl StorageStage {
let blockhash = working_bank.confirmed_last_blockhash();
let keypair_balance = working_bank.get_balance(&keypair.pubkey());

info!("keypair account balance: {}", keypair_balance);
if keypair_balance == 0 {
warn!("keypair account balance empty: {}", keypair.pubkey(),);
} else {
debug!(
"keypair account balance: {}: {}",
keypair.pubkey(),
keypair_balance
);
}
if working_bank
.get_account(&storage_keypair.pubkey())
.is_none()
Expand Down
51 changes: 41 additions & 10 deletions multinode-demo/fullnode.sh
Expand Up @@ -73,12 +73,13 @@ rsync_url() { # adds the 'rsync://` prefix to URLs that need it
echo "rsync://$url"
}

setup_vote_and_stake_accounts() {
setup_validator_accounts() {
declare entrypoint_ip=$1
declare node_keypair_path=$2
declare vote_keypair_path=$3
declare stake_keypair_path=$4
declare stake=$5
declare storage_keypair_path=$5
declare stake=$6

declare node_pubkey
node_pubkey=$($solana_keygen pubkey "$node_keypair_path")
Expand All @@ -89,6 +90,9 @@ setup_vote_and_stake_accounts() {
declare stake_pubkey
stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path")

declare storage_pubkey
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")

if [[ -f "$node_keypair_path".configured ]]; then
echo "Vote and stake accounts have already been configured"
else
Expand All @@ -108,15 +112,19 @@ setup_vote_and_stake_accounts() {
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
delegate-stake "$stake_keypair_path" "$vote_pubkey" || return $?

# Setup validator storage account
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
create-validator-storage-account "$storage_pubkey" || return $?

touch "$node_keypair_path".configured
fi

$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
show-vote-account "$vote_pubkey"

show-vote-account "$vote_pubkey"
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
show-stake-account "$stake_pubkey"

show-stake-account "$stake_pubkey"
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
show-storage-account "$storage_pubkey"

return 0
}
Expand All @@ -131,14 +139,28 @@ ledger_not_setup() {
setup_replicator_account() {
declare entrypoint_ip=$1
declare node_keypair_path=$2
declare stake=$3
declare storage_keypair_path=$2
declare stake=$4

declare storage_pubkey
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")

if [[ -f "$node_keypair_path".configured ]]; then
echo "Replicator account has already been configured"
else
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" airdrop "$stake" || return $?

# Setup replicator storage account
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
create-replicator-storage-account "$storage_keypair_path" || return $?

touch "$node_keypair_path".configured
fi

$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
show-storage-account "$storage_pubkey"

return 0
}

args=()
Expand Down Expand Up @@ -227,7 +249,6 @@ if [[ $node_type = bootstrap_leader ]]; then
accounts_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts
fullnode_storage_keypair_path=$SOLANA_CONFIG_DIR/bootstrap-leader-storage-keypair.json


default_arg --rpc-port 8899
default_arg --rpc-drone-address 127.0.0.1:9900
default_arg --gossip-port 8001
Expand Down Expand Up @@ -299,11 +320,13 @@ else

fullnode_pubkey=$($solana_keygen pubkey "$fullnode_keypair_path")
fullnode_vote_pubkey=$($solana_keygen pubkey "$fullnode_vote_keypair_path")
fullnode_storage_pubkey=$($solana_keygen pubkey "$fullnode_storage_keypair_path")

cat <<EOF
======================[ Fullnode configuration ]======================
node pubkey: $fullnode_pubkey
vote pubkey: $fullnode_vote_pubkey
storage pubkey: $fullnode_storage_pubkey
ledger: $ledger_config_dir
accounts: $accounts_config_dir
======================================================================
Expand Down Expand Up @@ -361,9 +384,17 @@ while true; do
trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR

if [[ $node_type = validator ]] && ((stake)); then
setup_vote_and_stake_accounts "${entrypoint_address%:*}" "$fullnode_keypair_path" "$fullnode_vote_keypair_path" "$fullnode_stake_keypair_path" "$stake"
setup_validator_accounts "${entrypoint_address%:*}" \
"$fullnode_keypair_path" \
"$fullnode_vote_keypair_path" \
"$fullnode_stake_keypair_path" \
"$fullnode_storage_keypair_path" \
"$stake"
elif [[ $node_type = replicator ]] && ((stake)); then
setup_replicator_account "${entrypoint_address%:*}" "$replicator_keypair_path" "$stake"
setup_replicator_account "${entrypoint_address%:*}" \
"$replicator_keypair_path" \
"$replicator_storage_keypair_path" \
"$stake"
fi

echo "$PS4$program ${args[*]}"
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/genesis_utils.rs
Expand Up @@ -14,6 +14,7 @@ pub struct GenesisBlockInfo {
pub genesis_block: GenesisBlock,
pub mint_keypair: Keypair,
pub voting_keypair: Keypair,
pub storage_keypair: Keypair,
}

pub fn create_genesis_block_with_leader(
Expand Down Expand Up @@ -77,5 +78,6 @@ pub fn create_genesis_block_with_leader(
genesis_block,
mint_keypair,
voting_keypair,
storage_keypair,
}
}

0 comments on commit e25ba04

Please sign in to comment.