pass Pubkeys as refs, copy only where values needed (#3213)
* pass Pubkeys as refs, copy only where values needed * Pubkey is pervasive * fixup
This commit is contained in:
parent
ac226c3e14
commit
195a880576
|
@ -120,7 +120,7 @@ pub fn send_barrier_transaction(
|
||||||
|
|
||||||
*blockhash = barrier_client.get_recent_blockhash();
|
*blockhash = barrier_client.get_recent_blockhash();
|
||||||
let signature = barrier_client
|
let signature = barrier_client
|
||||||
.transfer(0, &source_keypair, *dest_id, blockhash)
|
.transfer(0, &source_keypair, dest_id, blockhash)
|
||||||
.expect("Unable to send barrier transaction");
|
.expect("Unable to send barrier transaction");
|
||||||
|
|
||||||
let confirmatiom = barrier_client.poll_for_signature(&signature);
|
let confirmatiom = barrier_client.poll_for_signature(&signature);
|
||||||
|
@ -196,7 +196,7 @@ pub fn generate_txs(
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(id, keypair)| {
|
.map(|(id, keypair)| {
|
||||||
(
|
(
|
||||||
SystemTransaction::new_account(id, keypair.pubkey(), 1, blockhash, 0),
|
SystemTransaction::new_account(id, &keypair.pubkey(), 1, blockhash, 0),
|
||||||
timestamp(),
|
timestamp(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -200,7 +200,7 @@ fn append_vec_concurrent_get_append(bencher: &mut Bencher) {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_account_serialize(bencher: &mut Bencher) {
|
fn bench_account_serialize(bencher: &mut Bencher) {
|
||||||
let num: usize = 1000;
|
let num: usize = 1000;
|
||||||
let account = Account::new(2, 100, Keypair::new().pubkey());
|
let account = Account::new(2, 100, &Keypair::new().pubkey());
|
||||||
let len = get_serialized_size(&account);
|
let len = get_serialized_size(&account);
|
||||||
let ser_len = align_up!(len + std::mem::size_of::<u64>(), std::mem::size_of::<u64>());
|
let ser_len = align_up!(len + std::mem::size_of::<u64>(), std::mem::size_of::<u64>());
|
||||||
let mut memory = vec![0; num * ser_len];
|
let mut memory = vec![0; num * ser_len];
|
||||||
|
@ -225,7 +225,7 @@ fn bench_account_serialize(bencher: &mut Bencher) {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_account_serialize_bincode(bencher: &mut Bencher) {
|
fn bench_account_serialize_bincode(bencher: &mut Bencher) {
|
||||||
let num: usize = 1000;
|
let num: usize = 1000;
|
||||||
let account = Account::new(2, 100, Keypair::new().pubkey());
|
let account = Account::new(2, 100, &Keypair::new().pubkey());
|
||||||
let len = serialized_size(&account).unwrap() as usize;
|
let len = serialized_size(&account).unwrap() as usize;
|
||||||
let mut memory = vec![0u8; num * len];
|
let mut memory = vec![0u8; num * len];
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let dummy = SystemTransaction::new_move(
|
let dummy = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -77,7 +77,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
|
||||||
transactions.iter().for_each(|tx| {
|
transactions.iter().for_each(|tx| {
|
||||||
let fund = SystemTransaction::new_move(
|
let fund = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
tx.account_keys[0],
|
&tx.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -147,7 +147,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let dummy = SystemTransaction::new_move(
|
let dummy = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -185,7 +185,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
transactions.iter().for_each(|tx| {
|
transactions.iter().for_each(|tx| {
|
||||||
let fund = SystemTransaction::new_move(
|
let fund = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
tx.account_keys[0],
|
&tx.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn bench_block_to_blobs_to_block(bencher: &mut Bencher) {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let one = hash(&zero.as_ref());
|
let one = hash(&zero.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = SystemTransaction::new_move(&keypair, keypair.pubkey(), 1, one, 0);
|
let tx0 = SystemTransaction::new_move(&keypair, &keypair.pubkey(), 1, one, 0);
|
||||||
let transactions = vec![tx0; 10];
|
let transactions = vec![tx0; 10];
|
||||||
let entries = next_entries(&zero, 1, transactions);
|
let entries = next_entries(&zero, 1, transactions);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ mod tests {
|
||||||
let (genesis_block, _) = GenesisBlock::new(10_000);
|
let (genesis_block, _) = GenesisBlock::new(10_000);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let mut bank_forks = BankForks::new(0, bank);
|
let mut bank_forks = BankForks::new(0, bank);
|
||||||
let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1);
|
let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1);
|
||||||
child_bank.register_tick(&Hash::default());
|
child_bank.register_tick(&Hash::default());
|
||||||
bank_forks.insert(1, child_bank);
|
bank_forks.insert(1, child_bank);
|
||||||
assert_eq!(bank_forks[1u64].tick_height(), 1);
|
assert_eq!(bank_forks[1u64].tick_height(), 1);
|
||||||
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
let (genesis_block, _) = GenesisBlock::new(10_000);
|
let (genesis_block, _) = GenesisBlock::new(10_000);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let mut bank_forks = BankForks::new(0, bank);
|
let mut bank_forks = BankForks::new(0, bank);
|
||||||
let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1);
|
let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1);
|
||||||
bank_forks.insert(1, child_bank);
|
bank_forks.insert(1, child_bank);
|
||||||
assert!(bank_forks.frozen_banks().get(&0).is_some());
|
assert!(bank_forks.frozen_banks().get(&0).is_some());
|
||||||
assert!(bank_forks.frozen_banks().get(&1).is_none());
|
assert!(bank_forks.frozen_banks().get(&1).is_none());
|
||||||
|
@ -124,7 +124,7 @@ mod tests {
|
||||||
let (genesis_block, _) = GenesisBlock::new(10_000);
|
let (genesis_block, _) = GenesisBlock::new(10_000);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let mut bank_forks = BankForks::new(0, bank);
|
let mut bank_forks = BankForks::new(0, bank);
|
||||||
let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1);
|
let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1);
|
||||||
bank_forks.insert(1, child_bank);
|
bank_forks.insert(1, child_bank);
|
||||||
assert_eq!(bank_forks.active_banks(), vec![1]);
|
assert_eq!(bank_forks.active_banks(), vec![1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -440,15 +440,15 @@ mod tests {
|
||||||
|
|
||||||
// good tx
|
// good tx
|
||||||
let keypair = mint_keypair;
|
let keypair = mint_keypair;
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// good tx, but no verify
|
// good tx, but no verify
|
||||||
let tx_no_ver =
|
let tx_no_ver =
|
||||||
SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// bad tx, AccountNotFound
|
// bad tx, AccountNotFound
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx_anf = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
let tx_anf = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// send 'em over
|
// send 'em over
|
||||||
let packets = to_packets(&[tx, tx_no_ver, tx_anf]);
|
let packets = to_packets(&[tx, tx_no_ver, tx_anf]);
|
||||||
|
@ -500,7 +500,7 @@ mod tests {
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
&alice.pubkey(),
|
||||||
2,
|
2,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -514,7 +514,7 @@ mod tests {
|
||||||
// Process a second batch that spends one of those lamports.
|
// Process a second batch that spends one of those lamports.
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&alice,
|
&alice,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -567,8 +567,8 @@ mod tests {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
|
|
||||||
let transactions = vec![
|
let transactions = vec![
|
||||||
SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.hash(), 0),
|
SystemTransaction::new_move(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
||||||
SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.hash(), 0),
|
SystemTransaction::new_move(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut results = vec![Ok(()), Ok(())];
|
let mut results = vec![Ok(()), Ok(())];
|
||||||
|
@ -601,7 +601,7 @@ mod tests {
|
||||||
|
|
||||||
let transactions = vec![SystemTransaction::new_move(
|
let transactions = vec![SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
pubkey,
|
&pubkey,
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -642,7 +642,7 @@ mod tests {
|
||||||
|
|
||||||
let transactions = vec![SystemTransaction::new_move(
|
let transactions = vec![SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
pubkey,
|
&pubkey,
|
||||||
2,
|
2,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -63,14 +63,14 @@ pub trait BlockstreamEvents {
|
||||||
&self,
|
&self,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: &Pubkey,
|
||||||
entries: &Entry,
|
entries: &Entry,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
fn emit_block_event(
|
fn emit_block_event(
|
||||||
&self,
|
&self,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: &Pubkey,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: &Pubkey,
|
||||||
entry: &Entry,
|
entry: &Entry,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let json_entry = serde_json::to_string(&entry)?;
|
let json_entry = serde_json::to_string(&entry)?;
|
||||||
|
@ -108,7 +108,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: &Pubkey,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let payload = format!(
|
let payload = format!(
|
||||||
|
@ -175,14 +175,14 @@ mod test {
|
||||||
for tick_height in tick_height_initial..=tick_height_final {
|
for tick_height in tick_height_initial..=tick_height_final {
|
||||||
if tick_height == 5 {
|
if tick_height == 5 {
|
||||||
blockstream
|
blockstream
|
||||||
.emit_block_event(curr_slot, tick_height - 1, leader_id, blockhash)
|
.emit_block_event(curr_slot, tick_height - 1, &leader_id, blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
curr_slot += 1;
|
curr_slot += 1;
|
||||||
}
|
}
|
||||||
let entry = Entry::new(&mut blockhash, 1, vec![]); // just ticks
|
let entry = Entry::new(&mut blockhash, 1, vec![]); // just ticks
|
||||||
blockhash = entry.hash;
|
blockhash = entry.hash;
|
||||||
blockstream
|
blockstream
|
||||||
.emit_entry_event(curr_slot, tick_height, leader_id, &entry)
|
.emit_entry_event(curr_slot, tick_height, &leader_id, &entry)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
expected_entries.push(entry.clone());
|
expected_entries.push(entry.clone());
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
|
|
@ -80,13 +80,13 @@ impl BlockstreamService {
|
||||||
tick_height += 1;
|
tick_height += 1;
|
||||||
}
|
}
|
||||||
blockstream
|
blockstream
|
||||||
.emit_entry_event(slot, tick_height, slot_leader, &entry)
|
.emit_entry_event(slot, tick_height, &slot_leader, &entry)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
debug!("Blockstream error: {:?}, {:?}", e, blockstream.output);
|
debug!("Blockstream error: {:?}, {:?}", e, blockstream.output);
|
||||||
});
|
});
|
||||||
if i == entries.len() - 1 {
|
if i == entries.len() - 1 {
|
||||||
blockstream
|
blockstream
|
||||||
.emit_block_event(slot, tick_height, slot_leader, entry.hash)
|
.emit_block_event(slot, tick_height, &slot_leader, entry.hash)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
debug!("Blockstream error: {:?}, {:?}", e, blockstream.output);
|
debug!("Blockstream error: {:?}, {:?}", e, blockstream.output);
|
||||||
});
|
});
|
||||||
|
@ -140,7 +140,7 @@ mod test {
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mut blockhash = entries[3].hash;
|
let mut blockhash = entries[3].hash;
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, Hash::default(), 0);
|
||||||
let entry = Entry::new(&mut blockhash, 1, vec![tx]);
|
let entry = Entry::new(&mut blockhash, 1, vec![tx]);
|
||||||
blockhash = entry.hash;
|
blockhash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
|
|
@ -194,7 +194,7 @@ pub fn process_blocktree(
|
||||||
if next_meta.is_full() {
|
if next_meta.is_full() {
|
||||||
let next_bank = Arc::new(Bank::new_from_parent(
|
let next_bank = Arc::new(Bank::new_from_parent(
|
||||||
&bank,
|
&bank,
|
||||||
leader_schedule_utils::slot_leader_at(next_slot, &bank).unwrap(),
|
&leader_schedule_utils::slot_leader_at(next_slot, &bank).unwrap(),
|
||||||
next_slot,
|
next_slot,
|
||||||
));
|
));
|
||||||
trace!("Add child bank for slot={}", next_slot);
|
trace!("Add child bank for slot={}", next_slot);
|
||||||
|
@ -429,7 +429,7 @@ mod tests {
|
||||||
let slot_entries = create_ticks(genesis_block.ticks_per_slot - 1, genesis_block.hash());
|
let slot_entries = create_ticks(genesis_block.ticks_per_slot - 1, genesis_block.hash());
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
slot_entries.last().unwrap().hash,
|
slot_entries.last().unwrap().hash,
|
||||||
0,
|
0,
|
||||||
|
@ -450,7 +450,7 @@ mod tests {
|
||||||
fn test_process_ledger_simple() {
|
fn test_process_ledger_simple() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let leader_pubkey = Keypair::new().pubkey();
|
let leader_pubkey = Keypair::new().pubkey();
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader_pubkey, 50);
|
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader_pubkey, 50);
|
||||||
let (ledger_path, mut last_entry_hash) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, mut last_entry_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ mod tests {
|
||||||
// Transfer one token from the mint to a random account
|
// Transfer one token from the mint to a random account
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, blockhash, 0);
|
SystemTransaction::new_account(&mint_keypair, &keypair.pubkey(), 1, blockhash, 0);
|
||||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||||
last_entry_hash = entry.hash;
|
last_entry_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -468,7 +468,7 @@ mod tests {
|
||||||
// Add a second Transaction that will produce a
|
// Add a second Transaction that will produce a
|
||||||
// ProgramError<0, ResultWithNegativeLamports> error when processed
|
// ProgramError<0, ResultWithNegativeLamports> error when processed
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, blockhash, 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair2.pubkey(), 42, blockhash, 0);
|
||||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||||
last_entry_hash = entry.hash;
|
last_entry_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -545,7 +545,7 @@ mod tests {
|
||||||
// ensure bank can process 2 entries that have a common account and no tick is registered
|
// ensure bank can process 2 entries that have a common account and no tick is registered
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -553,7 +553,7 @@ mod tests {
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -575,11 +575,11 @@ mod tests {
|
||||||
|
|
||||||
// fund: put 4 in each of 1 and 2
|
// fund: put 4 in each of 1 and 2
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
bank.transfer(4, &mint_keypair, keypair1.pubkey(), bank.last_blockhash()),
|
bank.transfer(4, &mint_keypair, &keypair1.pubkey(), bank.last_blockhash()),
|
||||||
Ok(_)
|
Ok(_)
|
||||||
);
|
);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
bank.transfer(4, &mint_keypair, keypair2.pubkey(), bank.last_blockhash()),
|
bank.transfer(4, &mint_keypair, &keypair2.pubkey(), bank.last_blockhash()),
|
||||||
Ok(_)
|
Ok(_)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ mod tests {
|
||||||
1,
|
1,
|
||||||
vec![SystemTransaction::new_account(
|
vec![SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -602,14 +602,14 @@ mod tests {
|
||||||
vec![
|
vec![
|
||||||
SystemTransaction::new_account(
|
SystemTransaction::new_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
), // should be fine
|
), // should be fine
|
||||||
SystemTransaction::new_account(
|
SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -639,7 +639,7 @@ mod tests {
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -647,7 +647,7 @@ mod tests {
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -658,7 +658,7 @@ mod tests {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -666,7 +666,7 @@ mod tests {
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
keypair4.pubkey(),
|
&keypair4.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -690,7 +690,7 @@ mod tests {
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -698,7 +698,7 @@ mod tests {
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -711,12 +711,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
||||||
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, blockhash, 0);
|
let tx = SystemTransaction::new_account(&keypair2, &keypair3.pubkey(), 1, blockhash, 0);
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
keypair4.pubkey(),
|
&keypair4.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -732,7 +732,7 @@ mod tests {
|
||||||
// ensure that an error is returned for an empty account (keypair2)
|
// ensure that an error is returned for an empty account (keypair2)
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -281,7 +281,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_dummy_broadcast_service(
|
fn setup_dummy_broadcast_service(
|
||||||
leader_pubkey: Pubkey,
|
leader_pubkey: &Pubkey,
|
||||||
ledger_path: &str,
|
ledger_path: &str,
|
||||||
entry_receiver: Receiver<WorkingBankEntries>,
|
entry_receiver: Receiver<WorkingBankEntries>,
|
||||||
) -> MockBroadcastStage {
|
) -> MockBroadcastStage {
|
||||||
|
@ -293,7 +293,7 @@ mod test {
|
||||||
|
|
||||||
// Make a node to broadcast to
|
// Make a node to broadcast to
|
||||||
let buddy_keypair = Keypair::new();
|
let buddy_keypair = Keypair::new();
|
||||||
let broadcast_buddy = Node::new_localhost_with_pubkey(buddy_keypair.pubkey());
|
let broadcast_buddy = Node::new_localhost_with_pubkey(&buddy_keypair.pubkey());
|
||||||
|
|
||||||
// Fill the cluster_info with the buddy's info
|
// Fill the cluster_info with the buddy's info
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info.clone());
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info.clone());
|
||||||
|
@ -332,7 +332,7 @@ mod test {
|
||||||
|
|
||||||
let (entry_sender, entry_receiver) = channel();
|
let (entry_sender, entry_receiver) = channel();
|
||||||
let broadcast_service = setup_dummy_broadcast_service(
|
let broadcast_service = setup_dummy_broadcast_service(
|
||||||
leader_keypair.pubkey(),
|
&leader_keypair.pubkey(),
|
||||||
&ledger_path,
|
&ledger_path,
|
||||||
entry_receiver,
|
entry_receiver,
|
||||||
);
|
);
|
||||||
|
|
|
@ -126,7 +126,7 @@ mod tests {
|
||||||
&mut num_hashes,
|
&mut num_hashes,
|
||||||
vec![SystemTransaction::new_account(
|
vec![SystemTransaction::new_account(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
one,
|
one,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl ClusterInfo {
|
||||||
entrypoint: None,
|
entrypoint: None,
|
||||||
};
|
};
|
||||||
let id = contact_info.id;
|
let id = contact_info.id;
|
||||||
me.gossip.set_self(id);
|
me.gossip.set_self(&id);
|
||||||
me.insert_self(contact_info);
|
me.insert_self(contact_info);
|
||||||
me.push_self(&HashMap::new());
|
me.push_self(&HashMap::new());
|
||||||
me
|
me
|
||||||
|
@ -209,15 +209,15 @@ impl ClusterInfo {
|
||||||
pub fn id(&self) -> Pubkey {
|
pub fn id(&self) -> Pubkey {
|
||||||
self.gossip.id
|
self.gossip.id
|
||||||
}
|
}
|
||||||
pub fn lookup(&self, id: Pubkey) -> Option<&ContactInfo> {
|
pub fn lookup(&self, id: &Pubkey) -> Option<&ContactInfo> {
|
||||||
let entry = CrdsValueLabel::ContactInfo(id);
|
let entry = CrdsValueLabel::ContactInfo(*id);
|
||||||
self.gossip
|
self.gossip
|
||||||
.crds
|
.crds
|
||||||
.lookup(&entry)
|
.lookup(&entry)
|
||||||
.and_then(|x| x.contact_info())
|
.and_then(|x| x.contact_info())
|
||||||
}
|
}
|
||||||
pub fn my_data(&self) -> ContactInfo {
|
pub fn my_data(&self) -> ContactInfo {
|
||||||
self.lookup(self.id()).cloned().unwrap()
|
self.lookup(&self.id()).cloned().unwrap()
|
||||||
}
|
}
|
||||||
fn leader_id(&self) -> Pubkey {
|
fn leader_id(&self) -> Pubkey {
|
||||||
self.gossip_leader_id
|
self.gossip_leader_id
|
||||||
|
@ -228,7 +228,7 @@ impl ClusterInfo {
|
||||||
if leader_id == Pubkey::default() {
|
if leader_id == Pubkey::default() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
self.lookup(leader_id)
|
self.lookup(&leader_id)
|
||||||
}
|
}
|
||||||
pub fn contact_info_trace(&self) -> String {
|
pub fn contact_info_trace(&self) -> String {
|
||||||
let leader_id = self.leader_id();
|
let leader_id = self.leader_id();
|
||||||
|
@ -264,14 +264,14 @@ impl ClusterInfo {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_leader(&mut self, leader_id: Pubkey) {
|
pub fn set_leader(&mut self, leader_id: &Pubkey) {
|
||||||
warn!(
|
warn!(
|
||||||
"{}: LEADER_UPDATE TO {} from {}",
|
"{}: LEADER_UPDATE TO {} from {}",
|
||||||
self.gossip.id,
|
self.gossip.id,
|
||||||
leader_id,
|
leader_id,
|
||||||
self.leader_id()
|
self.leader_id()
|
||||||
);
|
);
|
||||||
self.gossip_leader_id = leader_id;
|
self.gossip_leader_id = *leader_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_vote(&mut self, vote: Transaction) {
|
pub fn push_vote(&mut self, vote: Transaction) {
|
||||||
|
@ -822,7 +822,7 @@ impl ClusterInfo {
|
||||||
}
|
}
|
||||||
pr.into_iter()
|
pr.into_iter()
|
||||||
.map(|(peer, filter, gossip, self_info)| {
|
.map(|(peer, filter, gossip, self_info)| {
|
||||||
self.gossip.mark_pull_request_creation_time(peer, now);
|
self.gossip.mark_pull_request_creation_time(&peer, now);
|
||||||
(gossip, Protocol::PullRequest(filter, self_info))
|
(gossip, Protocol::PullRequest(filter, self_info))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1022,7 +1022,7 @@ impl ClusterInfo {
|
||||||
to_shared_blob(rsp, from.gossip).ok().into_iter().collect()
|
to_shared_blob(rsp, from.gossip).ok().into_iter().collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn handle_pull_response(me: &Arc<RwLock<Self>>, from: Pubkey, data: Vec<CrdsValue>) {
|
fn handle_pull_response(me: &Arc<RwLock<Self>>, from: &Pubkey, data: Vec<CrdsValue>) {
|
||||||
let len = data.len();
|
let len = data.len();
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let self_id = me.read().unwrap().gossip.id;
|
let self_id = me.read().unwrap().gossip.id;
|
||||||
|
@ -1038,7 +1038,7 @@ impl ClusterInfo {
|
||||||
}
|
}
|
||||||
fn handle_push_message(
|
fn handle_push_message(
|
||||||
me: &Arc<RwLock<Self>>,
|
me: &Arc<RwLock<Self>>,
|
||||||
from: Pubkey,
|
from: &Pubkey,
|
||||||
data: &[CrdsValue],
|
data: &[CrdsValue],
|
||||||
) -> Vec<SharedBlob> {
|
) -> Vec<SharedBlob> {
|
||||||
let self_id = me.read().unwrap().gossip.id;
|
let self_id = me.read().unwrap().gossip.id;
|
||||||
|
@ -1059,7 +1059,7 @@ impl ClusterInfo {
|
||||||
pubkey: self_id,
|
pubkey: self_id,
|
||||||
prunes,
|
prunes,
|
||||||
signature: Signature::default(),
|
signature: Signature::default(),
|
||||||
destination: from,
|
destination: *from,
|
||||||
wallclock: timestamp(),
|
wallclock: timestamp(),
|
||||||
};
|
};
|
||||||
prune_msg.sign(&me.read().unwrap().keypair);
|
prune_msg.sign(&me.read().unwrap().keypair);
|
||||||
|
@ -1109,7 +1109,7 @@ impl ClusterInfo {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.gossip
|
.gossip
|
||||||
.crds
|
.crds
|
||||||
.update_record_timestamp(from.id, timestamp());
|
.update_record_timestamp(&from.id, timestamp());
|
||||||
let my_info = me.read().unwrap().my_data().clone();
|
let my_info = me.read().unwrap().my_data().clone();
|
||||||
inc_new_counter_info!("cluster_info-window-request-recv", 1);
|
inc_new_counter_info!("cluster_info-window-request-recv", 1);
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -1158,7 +1158,7 @@ impl ClusterInfo {
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
});
|
});
|
||||||
Self::handle_pull_response(me, from, data);
|
Self::handle_pull_response(me, &from, data);
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
Protocol::PushMessage(from, mut data) => {
|
Protocol::PushMessage(from, mut data) => {
|
||||||
|
@ -1169,15 +1169,15 @@ impl ClusterInfo {
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
});
|
});
|
||||||
Self::handle_push_message(me, from, &data)
|
Self::handle_push_message(me, &from, &data)
|
||||||
}
|
}
|
||||||
Protocol::PruneMessage(from, data) => {
|
Protocol::PruneMessage(from, data) => {
|
||||||
if data.verify() {
|
if data.verify() {
|
||||||
inc_new_counter_info!("cluster_info-prune_message", 1);
|
inc_new_counter_info!("cluster_info-prune_message", 1);
|
||||||
inc_new_counter_info!("cluster_info-prune_message-size", data.prunes.len());
|
inc_new_counter_info!("cluster_info-prune_message-size", data.prunes.len());
|
||||||
match me.write().unwrap().gossip.process_prune_msg(
|
match me.write().unwrap().gossip.process_prune_msg(
|
||||||
from,
|
&from,
|
||||||
data.destination,
|
&data.destination,
|
||||||
&data.prunes,
|
&data.prunes,
|
||||||
data.wallclock,
|
data.wallclock,
|
||||||
timestamp(),
|
timestamp(),
|
||||||
|
@ -1272,7 +1272,7 @@ impl ClusterInfo {
|
||||||
let (_, gossip_socket) = bind_in_range(FULLNODE_PORT_RANGE).unwrap();
|
let (_, gossip_socket) = bind_in_range(FULLNODE_PORT_RANGE).unwrap();
|
||||||
let daddr = socketaddr_any!();
|
let daddr = socketaddr_any!();
|
||||||
|
|
||||||
let node = ContactInfo::new(*id, daddr, daddr, daddr, daddr, daddr, daddr, timestamp());
|
let node = ContactInfo::new(id, daddr, daddr, daddr, daddr, daddr, daddr, timestamp());
|
||||||
(node, gossip_socket)
|
(node, gossip_socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1345,9 +1345,9 @@ pub struct Node {
|
||||||
impl Node {
|
impl Node {
|
||||||
pub fn new_localhost() -> Self {
|
pub fn new_localhost() -> Self {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
Self::new_localhost_with_pubkey(pubkey)
|
Self::new_localhost_with_pubkey(&pubkey)
|
||||||
}
|
}
|
||||||
pub fn new_localhost_with_pubkey(pubkey: Pubkey) -> Self {
|
pub fn new_localhost_with_pubkey(pubkey: &Pubkey) -> Self {
|
||||||
let tpu = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let tpu = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
let gossip = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let gossip = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
let tvu = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let tvu = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
@ -1383,7 +1383,7 @@ impl Node {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_with_external_ip(pubkey: Pubkey, gossip_addr: &SocketAddr) -> Node {
|
pub fn new_with_external_ip(pubkey: &Pubkey, gossip_addr: &SocketAddr) -> Node {
|
||||||
fn bind() -> (u16, UdpSocket) {
|
fn bind() -> (u16, UdpSocket) {
|
||||||
bind_in_range(FULLNODE_PORT_RANGE).expect("Failed to bind")
|
bind_in_range(FULLNODE_PORT_RANGE).expect("Failed to bind")
|
||||||
};
|
};
|
||||||
|
@ -1485,43 +1485,43 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cluster_info_new() {
|
fn test_cluster_info_new() {
|
||||||
let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
let cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
|
let cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
|
||||||
assert_eq!(d.id, cluster_info.my_data().id);
|
assert_eq!(d.id, cluster_info.my_data().id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_info_test() {
|
fn insert_info_test() {
|
||||||
let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d);
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d);
|
||||||
let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
let label = CrdsValueLabel::ContactInfo(d.id);
|
let label = CrdsValueLabel::ContactInfo(d.id);
|
||||||
cluster_info.insert_info(d);
|
cluster_info.insert_info(d);
|
||||||
assert!(cluster_info.gossip.crds.lookup(&label).is_some());
|
assert!(cluster_info.gossip.crds.lookup(&label).is_some());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_insert_self() {
|
fn test_insert_self() {
|
||||||
let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
|
||||||
let entry_label = CrdsValueLabel::ContactInfo(cluster_info.id());
|
let entry_label = CrdsValueLabel::ContactInfo(cluster_info.id());
|
||||||
assert!(cluster_info.gossip.crds.lookup(&entry_label).is_some());
|
assert!(cluster_info.gossip.crds.lookup(&entry_label).is_some());
|
||||||
|
|
||||||
// inserting something else shouldn't work
|
// inserting something else shouldn't work
|
||||||
let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
cluster_info.insert_self(d.clone());
|
cluster_info.insert_self(d.clone());
|
||||||
let label = CrdsValueLabel::ContactInfo(d.id);
|
let label = CrdsValueLabel::ContactInfo(d.id);
|
||||||
assert!(cluster_info.gossip.crds.lookup(&label).is_none());
|
assert!(cluster_info.gossip.crds.lookup(&label).is_none());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn window_index_request() {
|
fn window_index_request() {
|
||||||
let me = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp());
|
let me = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(me);
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(me);
|
||||||
let rv = cluster_info.window_index_request(0, 0, false);
|
let rv = cluster_info.window_index_request(0, 0, false);
|
||||||
assert_matches!(rv, Err(Error::ClusterInfoError(ClusterInfoError::NoPeers)));
|
assert_matches!(rv, Err(Error::ClusterInfoError(ClusterInfoError::NoPeers)));
|
||||||
|
|
||||||
let gossip_addr = socketaddr!([127, 0, 0, 1], 1234);
|
let gossip_addr = socketaddr!([127, 0, 0, 1], 1234);
|
||||||
let nxt = ContactInfo::new(
|
let nxt = ContactInfo::new(
|
||||||
Keypair::new().pubkey(),
|
&Keypair::new().pubkey(),
|
||||||
gossip_addr,
|
gossip_addr,
|
||||||
socketaddr!([127, 0, 0, 1], 1235),
|
socketaddr!([127, 0, 0, 1], 1235),
|
||||||
socketaddr!([127, 0, 0, 1], 1236),
|
socketaddr!([127, 0, 0, 1], 1236),
|
||||||
|
@ -1537,7 +1537,7 @@ mod tests {
|
||||||
|
|
||||||
let gossip_addr2 = socketaddr!([127, 0, 0, 2], 1234);
|
let gossip_addr2 = socketaddr!([127, 0, 0, 2], 1234);
|
||||||
let nxt = ContactInfo::new(
|
let nxt = ContactInfo::new(
|
||||||
Keypair::new().pubkey(),
|
&Keypair::new().pubkey(),
|
||||||
gossip_addr2,
|
gossip_addr2,
|
||||||
socketaddr!([127, 0, 0, 1], 1235),
|
socketaddr!([127, 0, 0, 1], 1235),
|
||||||
socketaddr!([127, 0, 0, 1], 1236),
|
socketaddr!([127, 0, 0, 1], 1236),
|
||||||
|
@ -1570,7 +1570,7 @@ mod tests {
|
||||||
{
|
{
|
||||||
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
|
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
|
||||||
let me = ContactInfo::new(
|
let me = ContactInfo::new(
|
||||||
Keypair::new().pubkey(),
|
&Keypair::new().pubkey(),
|
||||||
socketaddr!("127.0.0.1:1234"),
|
socketaddr!("127.0.0.1:1234"),
|
||||||
socketaddr!("127.0.0.1:1235"),
|
socketaddr!("127.0.0.1:1235"),
|
||||||
socketaddr!("127.0.0.1:1236"),
|
socketaddr!("127.0.0.1:1236"),
|
||||||
|
@ -1671,7 +1671,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default_leader() {
|
fn test_default_leader() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let contact_info = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let contact_info = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
||||||
let network_entry_point =
|
let network_entry_point =
|
||||||
ContactInfo::new_gossip_entry_point(&socketaddr!("127.0.0.1:1239"));
|
ContactInfo::new_gossip_entry_point(&socketaddr!("127.0.0.1:1239"));
|
||||||
|
@ -1682,7 +1682,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn new_with_external_ip_test_random() {
|
fn new_with_external_ip_test_random() {
|
||||||
let ip = Ipv4Addr::from(0);
|
let ip = Ipv4Addr::from(0);
|
||||||
let node = Node::new_with_external_ip(Keypair::new().pubkey(), &socketaddr!(ip, 0));
|
let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(ip, 0));
|
||||||
assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip);
|
assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip);
|
||||||
assert!(node.sockets.tvu.len() > 1);
|
assert!(node.sockets.tvu.len() > 1);
|
||||||
for tx_socket in node.sockets.tvu.iter() {
|
for tx_socket in node.sockets.tvu.iter() {
|
||||||
|
@ -1715,7 +1715,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn new_with_external_ip_test_gossip() {
|
fn new_with_external_ip_test_gossip() {
|
||||||
let ip = IpAddr::V4(Ipv4Addr::from(0));
|
let ip = IpAddr::V4(Ipv4Addr::from(0));
|
||||||
let node = Node::new_with_external_ip(Keypair::new().pubkey(), &socketaddr!(0, 8050));
|
let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(0, 8050));
|
||||||
assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip);
|
assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip);
|
||||||
assert!(node.sockets.tvu.len() > 1);
|
assert!(node.sockets.tvu.len() > 1);
|
||||||
for tx_socket in node.sockets.tvu.iter() {
|
for tx_socket in node.sockets.tvu.iter() {
|
||||||
|
@ -1752,11 +1752,11 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let peer_keypair = Keypair::new();
|
let peer_keypair = Keypair::new();
|
||||||
let leader_keypair = Keypair::new();
|
let leader_keypair = Keypair::new();
|
||||||
let contact_info = ContactInfo::new_localhost(keypair.pubkey(), 0);
|
let contact_info = ContactInfo::new_localhost(&keypair.pubkey(), 0);
|
||||||
let leader = ContactInfo::new_localhost(leader_keypair.pubkey(), 0);
|
let leader = ContactInfo::new_localhost(&leader_keypair.pubkey(), 0);
|
||||||
let peer = ContactInfo::new_localhost(peer_keypair.pubkey(), 0);
|
let peer = ContactInfo::new_localhost(&peer_keypair.pubkey(), 0);
|
||||||
let mut cluster_info = ClusterInfo::new(contact_info.clone(), Arc::new(keypair));
|
let mut cluster_info = ClusterInfo::new(contact_info.clone(), Arc::new(keypair));
|
||||||
cluster_info.set_leader(leader.id);
|
cluster_info.set_leader(&leader.id);
|
||||||
cluster_info.insert_info(peer.clone());
|
cluster_info.insert_info(peer.clone());
|
||||||
//check that all types of gossip messages are signed correctly
|
//check that all types of gossip messages are signed correctly
|
||||||
let (_, _, vals) = cluster_info.gossip.new_push_messages(timestamp());
|
let (_, _, vals) = cluster_info.gossip.new_push_messages(timestamp());
|
||||||
|
@ -1926,7 +1926,7 @@ mod tests {
|
||||||
fn test_push_vote() {
|
fn test_push_vote() {
|
||||||
let keys = Keypair::new();
|
let keys = Keypair::new();
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
let contact_info = ContactInfo::new_localhost(keys.pubkey(), 0);
|
let contact_info = ContactInfo::new_localhost(&keys.pubkey(), 0);
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
||||||
|
|
||||||
// make sure empty crds is handled correctly
|
// make sure empty crds is handled correctly
|
||||||
|
@ -1953,11 +1953,11 @@ mod tests {
|
||||||
fn test_add_entrypoint() {
|
fn test_add_entrypoint() {
|
||||||
let node_keypair = Arc::new(Keypair::new());
|
let node_keypair = Arc::new(Keypair::new());
|
||||||
let mut cluster_info = ClusterInfo::new(
|
let mut cluster_info = ClusterInfo::new(
|
||||||
ContactInfo::new_localhost(node_keypair.pubkey(), timestamp()),
|
ContactInfo::new_localhost(&node_keypair.pubkey(), timestamp()),
|
||||||
node_keypair,
|
node_keypair,
|
||||||
);
|
);
|
||||||
let entrypoint_id = Keypair::new().pubkey();
|
let entrypoint_id = Keypair::new().pubkey();
|
||||||
let entrypoint = ContactInfo::new_localhost(entrypoint_id, timestamp());
|
let entrypoint = ContactInfo::new_localhost(&entrypoint_id, timestamp());
|
||||||
cluster_info.set_entrypoint(entrypoint.clone());
|
cluster_info.set_entrypoint(entrypoint.clone());
|
||||||
let pulls = cluster_info.new_pull_requests(&HashMap::new());
|
let pulls = cluster_info.new_pull_requests(&HashMap::new());
|
||||||
assert_eq!(1, pulls.len());
|
assert_eq!(1, pulls.len());
|
||||||
|
@ -1978,7 +1978,7 @@ fn test_add_entrypoint() {
|
||||||
// now add this message back to the table and make sure after the next pull, the entrypoint is unset
|
// now add this message back to the table and make sure after the next pull, the entrypoint is unset
|
||||||
let entrypoint_crdsvalue = CrdsValue::ContactInfo(entrypoint.clone());
|
let entrypoint_crdsvalue = CrdsValue::ContactInfo(entrypoint.clone());
|
||||||
let cluster_info = Arc::new(RwLock::new(cluster_info));
|
let cluster_info = Arc::new(RwLock::new(cluster_info));
|
||||||
ClusterInfo::handle_pull_response(&cluster_info, entrypoint_id, vec![entrypoint_crdsvalue]);
|
ClusterInfo::handle_pull_response(&cluster_info, &entrypoint_id, vec![entrypoint_crdsvalue]);
|
||||||
let pulls = cluster_info
|
let pulls = cluster_info
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub fn spend_and_verify_all_nodes(
|
||||||
assert!(bal > 0);
|
assert!(bal > 0);
|
||||||
let mut transaction = SystemTransaction::new_move(
|
let mut transaction = SystemTransaction::new_move(
|
||||||
&funding_keypair,
|
&funding_keypair,
|
||||||
random_keypair.pubkey(),
|
&random_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
client.get_recent_blockhash(),
|
client.get_recent_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -124,7 +124,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
|
||||||
assert!(bal > 0);
|
assert!(bal > 0);
|
||||||
let mut transaction = SystemTransaction::new_move(
|
let mut transaction = SystemTransaction::new_move(
|
||||||
&funding_keypair,
|
&funding_keypair,
|
||||||
random_keypair.pubkey(),
|
&random_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
client.get_recent_blockhash(),
|
client.get_recent_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Default for ContactInfo {
|
||||||
|
|
||||||
impl ContactInfo {
|
impl ContactInfo {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: Pubkey,
|
id: &Pubkey,
|
||||||
gossip: SocketAddr,
|
gossip: SocketAddr,
|
||||||
tvu: SocketAddr,
|
tvu: SocketAddr,
|
||||||
tpu: SocketAddr,
|
tpu: SocketAddr,
|
||||||
|
@ -93,7 +93,7 @@ impl ContactInfo {
|
||||||
now: u64,
|
now: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id: *id,
|
||||||
signature: Signature::default(),
|
signature: Signature::default(),
|
||||||
gossip,
|
gossip,
|
||||||
tvu,
|
tvu,
|
||||||
|
@ -105,7 +105,7 @@ impl ContactInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_localhost(id: Pubkey, now: u64) -> Self {
|
pub fn new_localhost(id: &Pubkey, now: u64) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
id,
|
id,
|
||||||
socketaddr!("127.0.0.1:1234"),
|
socketaddr!("127.0.0.1:1234"),
|
||||||
|
@ -124,7 +124,7 @@ impl ContactInfo {
|
||||||
let addr = socketaddr!("224.0.1.255:1000");
|
let addr = socketaddr!("224.0.1.255:1000");
|
||||||
assert!(addr.ip().is_multicast());
|
assert!(addr.ip().is_multicast());
|
||||||
Self::new(
|
Self::new(
|
||||||
Keypair::new().pubkey(),
|
&Keypair::new().pubkey(),
|
||||||
addr,
|
addr,
|
||||||
addr,
|
addr,
|
||||||
addr,
|
addr,
|
||||||
|
@ -139,7 +139,7 @@ impl ContactInfo {
|
||||||
nxt_addr.set_port(addr.port() + nxt);
|
nxt_addr.set_port(addr.port() + nxt);
|
||||||
nxt_addr
|
nxt_addr
|
||||||
}
|
}
|
||||||
fn new_with_pubkey_socketaddr(pubkey: Pubkey, bind_addr: &SocketAddr) -> Self {
|
fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self {
|
||||||
let tpu_addr = *bind_addr;
|
let tpu_addr = *bind_addr;
|
||||||
let gossip_addr = Self::next_port(&bind_addr, 1);
|
let gossip_addr = Self::next_port(&bind_addr, 1);
|
||||||
let tvu_addr = Self::next_port(&bind_addr, 2);
|
let tvu_addr = Self::next_port(&bind_addr, 2);
|
||||||
|
@ -158,14 +158,14 @@ impl ContactInfo {
|
||||||
}
|
}
|
||||||
pub fn new_with_socketaddr(bind_addr: &SocketAddr) -> Self {
|
pub fn new_with_socketaddr(bind_addr: &SocketAddr) -> Self {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
Self::new_with_pubkey_socketaddr(keypair.pubkey(), bind_addr)
|
Self::new_with_pubkey_socketaddr(&keypair.pubkey(), bind_addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a ContactInfo that's only usable for gossip
|
// Construct a ContactInfo that's only usable for gossip
|
||||||
pub fn new_gossip_entry_point(gossip_addr: &SocketAddr) -> Self {
|
pub fn new_gossip_entry_point(gossip_addr: &SocketAddr) -> Self {
|
||||||
let daddr: SocketAddr = socketaddr!("0.0.0.0:0");
|
let daddr: SocketAddr = socketaddr!("0.0.0.0:0");
|
||||||
Self::new(
|
Self::new(
|
||||||
Pubkey::default(),
|
&Pubkey::default(),
|
||||||
*gossip_addr,
|
*gossip_addr,
|
||||||
daddr,
|
daddr,
|
||||||
daddr,
|
daddr,
|
||||||
|
@ -292,7 +292,7 @@ mod tests {
|
||||||
fn replayed_data_new_with_socketaddr_with_pubkey() {
|
fn replayed_data_new_with_socketaddr_with_pubkey() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let d1 = ContactInfo::new_with_pubkey_socketaddr(
|
let d1 = ContactInfo::new_with_pubkey_socketaddr(
|
||||||
keypair.pubkey().clone(),
|
&keypair.pubkey(),
|
||||||
&socketaddr!("127.0.0.1:1234"),
|
&socketaddr!("127.0.0.1:1234"),
|
||||||
);
|
);
|
||||||
assert_eq!(d1.id, keypair.pubkey());
|
assert_eq!(d1.id, keypair.pubkey());
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl Crds {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the timestamp's of all the labels that are assosciated with Pubkey
|
/// Update the timestamp's of all the labels that are assosciated with Pubkey
|
||||||
pub fn update_record_timestamp(&mut self, pubkey: Pubkey, now: u64) {
|
pub fn update_record_timestamp(&mut self, pubkey: &Pubkey, now: u64) {
|
||||||
for label in &CrdsValue::record_labels(pubkey) {
|
for label in &CrdsValue::record_labels(pubkey) {
|
||||||
self.update_label_timestamp(label, now);
|
self.update_label_timestamp(label, now);
|
||||||
}
|
}
|
||||||
|
@ -187,9 +187,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_update_new() {
|
fn test_update_new() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let original = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0));
|
let original = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0));
|
||||||
assert_matches!(crds.insert(original.clone(), 0), Ok(_));
|
assert_matches!(crds.insert(original.clone(), 0), Ok(_));
|
||||||
let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1));
|
let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 1));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crds.insert(val.clone(), 1).unwrap().unwrap().value,
|
crds.insert(val.clone(), 1).unwrap().unwrap().value,
|
||||||
original
|
original
|
||||||
|
@ -199,7 +199,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_update_timestamp() {
|
fn test_update_timestamp() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0));
|
let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0));
|
||||||
assert_eq!(crds.insert(val.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(val.clone(), 0), Ok(None));
|
||||||
|
|
||||||
crds.update_label_timestamp(&val.label(), 1);
|
crds.update_label_timestamp(&val.label(), 1);
|
||||||
|
@ -210,13 +210,13 @@ mod test {
|
||||||
assert_eq!(val2.label().pubkey(), val.label().pubkey());
|
assert_eq!(val2.label().pubkey(), val.label().pubkey());
|
||||||
assert_matches!(crds.insert(val2.clone(), 0), Ok(Some(_)));
|
assert_matches!(crds.insert(val2.clone(), 0), Ok(Some(_)));
|
||||||
|
|
||||||
crds.update_record_timestamp(val.label().pubkey(), 2);
|
crds.update_record_timestamp(&val.label().pubkey(), 2);
|
||||||
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
|
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
|
||||||
assert_eq!(crds.table[&val.label()].insert_timestamp, 0);
|
assert_eq!(crds.table[&val.label()].insert_timestamp, 0);
|
||||||
assert_eq!(crds.table[&val2.label()].local_timestamp, 2);
|
assert_eq!(crds.table[&val2.label()].local_timestamp, 2);
|
||||||
assert_eq!(crds.table[&val2.label()].insert_timestamp, 0);
|
assert_eq!(crds.table[&val2.label()].insert_timestamp, 0);
|
||||||
|
|
||||||
crds.update_record_timestamp(val.label().pubkey(), 1);
|
crds.update_record_timestamp(&val.label().pubkey(), 1);
|
||||||
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
|
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
|
||||||
assert_eq!(crds.table[&val.label()].insert_timestamp, 0);
|
assert_eq!(crds.table[&val.label()].insert_timestamp, 0);
|
||||||
|
|
||||||
|
@ -259,10 +259,10 @@ mod test {
|
||||||
fn test_hash_order() {
|
fn test_hash_order() {
|
||||||
let v1 = VersionedCrdsValue::new(
|
let v1 = VersionedCrdsValue::new(
|
||||||
1,
|
1,
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)),
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)),
|
||||||
);
|
);
|
||||||
let v2 = VersionedCrdsValue::new(1, {
|
let v2 = VersionedCrdsValue::new(1, {
|
||||||
let mut contact_info = ContactInfo::new_localhost(Pubkey::default(), 0);
|
let mut contact_info = ContactInfo::new_localhost(&Pubkey::default(), 0);
|
||||||
contact_info.rpc = socketaddr!("0.0.0.0:0");
|
contact_info.rpc = socketaddr!("0.0.0.0:0");
|
||||||
CrdsValue::ContactInfo(contact_info)
|
CrdsValue::ContactInfo(contact_info)
|
||||||
});
|
});
|
||||||
|
@ -286,11 +286,11 @@ mod test {
|
||||||
fn test_wallclock_order() {
|
fn test_wallclock_order() {
|
||||||
let v1 = VersionedCrdsValue::new(
|
let v1 = VersionedCrdsValue::new(
|
||||||
1,
|
1,
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1)),
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 1)),
|
||||||
);
|
);
|
||||||
let v2 = VersionedCrdsValue::new(
|
let v2 = VersionedCrdsValue::new(
|
||||||
1,
|
1,
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)),
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)),
|
||||||
);
|
);
|
||||||
assert_eq!(v1.value.label(), v2.value.label());
|
assert_eq!(v1.value.label(), v2.value.label());
|
||||||
assert!(v1 > v2);
|
assert!(v1 > v2);
|
||||||
|
@ -302,11 +302,11 @@ mod test {
|
||||||
fn test_label_order() {
|
fn test_label_order() {
|
||||||
let v1 = VersionedCrdsValue::new(
|
let v1 = VersionedCrdsValue::new(
|
||||||
1,
|
1,
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)),
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)),
|
||||||
);
|
);
|
||||||
let v2 = VersionedCrdsValue::new(
|
let v2 = VersionedCrdsValue::new(
|
||||||
1,
|
1,
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)),
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)),
|
||||||
);
|
);
|
||||||
assert_ne!(v1, v2);
|
assert_ne!(v1, v2);
|
||||||
assert!(!(v1 == v2));
|
assert!(!(v1 == v2));
|
||||||
|
|
|
@ -36,8 +36,8 @@ impl Default for CrdsGossip {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CrdsGossip {
|
impl CrdsGossip {
|
||||||
pub fn set_self(&mut self, id: Pubkey) {
|
pub fn set_self(&mut self, id: &Pubkey) {
|
||||||
self.id = id;
|
self.id = *id;
|
||||||
}
|
}
|
||||||
/// process a push message to the network
|
/// process a push message to the network
|
||||||
pub fn process_push_message(&mut self, values: &[CrdsValue], now: u64) -> Vec<Pubkey> {
|
pub fn process_push_message(&mut self, values: &[CrdsValue], now: u64) -> Vec<Pubkey> {
|
||||||
|
@ -73,8 +73,8 @@ impl CrdsGossip {
|
||||||
/// add the `from` to the peer's filter of nodes
|
/// add the `from` to the peer's filter of nodes
|
||||||
pub fn process_prune_msg(
|
pub fn process_prune_msg(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer: Pubkey,
|
peer: &Pubkey,
|
||||||
destination: Pubkey,
|
destination: &Pubkey,
|
||||||
origin: &[Pubkey],
|
origin: &[Pubkey],
|
||||||
wallclock: u64,
|
wallclock: u64,
|
||||||
now: u64,
|
now: u64,
|
||||||
|
@ -83,7 +83,7 @@ impl CrdsGossip {
|
||||||
if expired {
|
if expired {
|
||||||
return Err(CrdsGossipError::PruneMessageTimeout);
|
return Err(CrdsGossipError::PruneMessageTimeout);
|
||||||
}
|
}
|
||||||
if self.id == destination {
|
if self.id == *destination {
|
||||||
self.push.process_prune_msg(peer, origin);
|
self.push.process_prune_msg(peer, origin);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +97,7 @@ impl CrdsGossip {
|
||||||
self.push.refresh_push_active_set(
|
self.push.refresh_push_active_set(
|
||||||
&self.crds,
|
&self.crds,
|
||||||
stakes,
|
stakes,
|
||||||
self.id,
|
&self.id,
|
||||||
self.pull.pull_request_time.len(),
|
self.pull.pull_request_time.len(),
|
||||||
CRDS_GOSSIP_NUM_ACTIVE,
|
CRDS_GOSSIP_NUM_ACTIVE,
|
||||||
)
|
)
|
||||||
|
@ -109,14 +109,15 @@ impl CrdsGossip {
|
||||||
now: u64,
|
now: u64,
|
||||||
stakes: &HashMap<Pubkey, u64>,
|
stakes: &HashMap<Pubkey, u64>,
|
||||||
) -> Result<(Pubkey, Bloom<Hash>, CrdsValue), CrdsGossipError> {
|
) -> Result<(Pubkey, Bloom<Hash>, CrdsValue), CrdsGossipError> {
|
||||||
self.pull.new_pull_request(&self.crds, self.id, now, stakes)
|
self.pull
|
||||||
|
.new_pull_request(&self.crds, &self.id, now, stakes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// time when a request to `from` was initiated
|
/// time when a request to `from` was initiated
|
||||||
/// This is used for weighted random selection during `new_pull_request`
|
/// This is used for weighted random selection during `new_pull_request`
|
||||||
/// It's important to use the local nodes request creation time as the weight
|
/// It's important to use the local nodes request creation time as the weight
|
||||||
/// instead of the response received time otherwise failed nodes will increase their weight.
|
/// instead of the response received time otherwise failed nodes will increase their weight.
|
||||||
pub fn mark_pull_request_creation_time(&mut self, from: Pubkey, now: u64) {
|
pub fn mark_pull_request_creation_time(&mut self, from: &Pubkey, now: u64) {
|
||||||
self.pull.mark_pull_request_creation_time(from, now)
|
self.pull.mark_pull_request_creation_time(from, now)
|
||||||
}
|
}
|
||||||
/// process a pull request and create a response
|
/// process a pull request and create a response
|
||||||
|
@ -132,7 +133,7 @@ impl CrdsGossip {
|
||||||
/// process a pull response
|
/// process a pull response
|
||||||
pub fn process_pull_response(
|
pub fn process_pull_response(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: Pubkey,
|
from: &Pubkey,
|
||||||
response: Vec<CrdsValue>,
|
response: Vec<CrdsValue>,
|
||||||
now: u64,
|
now: u64,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
|
@ -150,7 +151,7 @@ impl CrdsGossip {
|
||||||
}
|
}
|
||||||
if now > self.pull.crds_timeout {
|
if now > self.pull.crds_timeout {
|
||||||
let min = now - self.pull.crds_timeout;
|
let min = now - self.pull.crds_timeout;
|
||||||
self.pull.purge_active(&mut self.crds, self.id, min);
|
self.pull.purge_active(&mut self.crds, &self.id, min);
|
||||||
}
|
}
|
||||||
if now > 5 * self.pull.crds_timeout {
|
if now > 5 * self.pull.crds_timeout {
|
||||||
let min = now - 5 * self.pull.crds_timeout;
|
let min = now - 5 * self.pull.crds_timeout;
|
||||||
|
@ -188,7 +189,7 @@ mod test {
|
||||||
let mut crds_gossip = CrdsGossip::default();
|
let mut crds_gossip = CrdsGossip::default();
|
||||||
crds_gossip.id = Pubkey::new(&[0; 32]);
|
crds_gossip.id = Pubkey::new(&[0; 32]);
|
||||||
let id = crds_gossip.id;
|
let id = crds_gossip.id;
|
||||||
let ci = ContactInfo::new_localhost(Pubkey::new(&[1; 32]), 0);
|
let ci = ContactInfo::new_localhost(&Pubkey::new(&[1; 32]), 0);
|
||||||
let prune_pubkey = Pubkey::new(&[2; 32]);
|
let prune_pubkey = Pubkey::new(&[2; 32]);
|
||||||
crds_gossip
|
crds_gossip
|
||||||
.crds
|
.crds
|
||||||
|
@ -198,19 +199,19 @@ mod test {
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
//incorrect dest
|
//incorrect dest
|
||||||
let mut res = crds_gossip.process_prune_msg(
|
let mut res = crds_gossip.process_prune_msg(
|
||||||
ci.id,
|
&ci.id,
|
||||||
Pubkey::new(hash(&[1; 32]).as_ref()),
|
&Pubkey::new(hash(&[1; 32]).as_ref()),
|
||||||
&[prune_pubkey],
|
&[prune_pubkey],
|
||||||
now,
|
now,
|
||||||
now,
|
now,
|
||||||
);
|
);
|
||||||
assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination));
|
assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination));
|
||||||
//correct dest
|
//correct dest
|
||||||
res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, now);
|
res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, now);
|
||||||
res.unwrap();
|
res.unwrap();
|
||||||
//test timeout
|
//test timeout
|
||||||
let timeout = now + crds_gossip.push.prune_timeout * 2;
|
let timeout = now + crds_gossip.push.prune_timeout * 2;
|
||||||
res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, timeout);
|
res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, timeout);
|
||||||
assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout));
|
assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl CrdsGossipPull {
|
||||||
pub fn new_pull_request(
|
pub fn new_pull_request(
|
||||||
&self,
|
&self,
|
||||||
crds: &Crds,
|
crds: &Crds,
|
||||||
self_id: Pubkey,
|
self_id: &Pubkey,
|
||||||
now: u64,
|
now: u64,
|
||||||
stakes: &HashMap<Pubkey, u64>,
|
stakes: &HashMap<Pubkey, u64>,
|
||||||
) -> Result<(Pubkey, Bloom<Hash>, CrdsValue), CrdsGossipError> {
|
) -> Result<(Pubkey, Bloom<Hash>, CrdsValue), CrdsGossipError> {
|
||||||
|
@ -65,7 +65,7 @@ impl CrdsGossipPull {
|
||||||
let index = WeightedIndex::new(options.iter().map(|weighted| weighted.0)).unwrap();
|
let index = WeightedIndex::new(options.iter().map(|weighted| weighted.0)).unwrap();
|
||||||
let random = index.sample(&mut rand::thread_rng());
|
let random = index.sample(&mut rand::thread_rng());
|
||||||
let self_info = crds
|
let self_info = crds
|
||||||
.lookup(&CrdsValueLabel::ContactInfo(self_id))
|
.lookup(&CrdsValueLabel::ContactInfo(*self_id))
|
||||||
.unwrap_or_else(|| panic!("self_id invalid {}", self_id));
|
.unwrap_or_else(|| panic!("self_id invalid {}", self_id));
|
||||||
Ok((options[random].1.id, filter, self_info.clone()))
|
Ok((options[random].1.id, filter, self_info.clone()))
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,8 @@ impl CrdsGossipPull {
|
||||||
/// This is used for weighted random selection during `new_pull_request`
|
/// This is used for weighted random selection during `new_pull_request`
|
||||||
/// It's important to use the local nodes request creation time as the weight
|
/// It's important to use the local nodes request creation time as the weight
|
||||||
/// instead of the response received time otherwise failed nodes will increase their weight.
|
/// instead of the response received time otherwise failed nodes will increase their weight.
|
||||||
pub fn mark_pull_request_creation_time(&mut self, from: Pubkey, now: u64) {
|
pub fn mark_pull_request_creation_time(&mut self, from: &Pubkey, now: u64) {
|
||||||
self.pull_request_time.insert(from, now);
|
self.pull_request_time.insert(*from, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Store an old hash in the purged values set
|
/// Store an old hash in the purged values set
|
||||||
|
@ -120,14 +120,14 @@ impl CrdsGossipPull {
|
||||||
self.purged_values
|
self.purged_values
|
||||||
.push_back((val.value_hash, val.local_timestamp))
|
.push_back((val.value_hash, val.local_timestamp))
|
||||||
}
|
}
|
||||||
crds.update_record_timestamp(key, now);
|
crds.update_record_timestamp(&key, now);
|
||||||
rv
|
rv
|
||||||
}
|
}
|
||||||
/// process a pull response
|
/// process a pull response
|
||||||
pub fn process_pull_response(
|
pub fn process_pull_response(
|
||||||
&mut self,
|
&mut self,
|
||||||
crds: &mut Crds,
|
crds: &mut Crds,
|
||||||
from: Pubkey,
|
from: &Pubkey,
|
||||||
response: Vec<CrdsValue>,
|
response: Vec<CrdsValue>,
|
||||||
now: u64,
|
now: u64,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
|
@ -137,7 +137,7 @@ impl CrdsGossipPull {
|
||||||
let old = crds.insert(r, now);
|
let old = crds.insert(r, now);
|
||||||
failed += old.is_err() as usize;
|
failed += old.is_err() as usize;
|
||||||
old.ok().map(|opt| {
|
old.ok().map(|opt| {
|
||||||
crds.update_record_timestamp(owner, now);
|
crds.update_record_timestamp(&owner, now);
|
||||||
opt.map(|val| {
|
opt.map(|val| {
|
||||||
self.purged_values
|
self.purged_values
|
||||||
.push_back((val.value_hash, val.local_timestamp))
|
.push_back((val.value_hash, val.local_timestamp))
|
||||||
|
@ -180,11 +180,11 @@ impl CrdsGossipPull {
|
||||||
}
|
}
|
||||||
/// Purge values from the crds that are older then `active_timeout`
|
/// Purge values from the crds that are older then `active_timeout`
|
||||||
/// The value_hash of an active item is put into self.purged_values queue
|
/// The value_hash of an active item is put into self.purged_values queue
|
||||||
pub fn purge_active(&mut self, crds: &mut Crds, self_id: Pubkey, min_ts: u64) {
|
pub fn purge_active(&mut self, crds: &mut Crds, self_id: &Pubkey, min_ts: u64) {
|
||||||
let old = crds.find_old_labels(min_ts);
|
let old = crds.find_old_labels(min_ts);
|
||||||
let mut purged: VecDeque<_> = old
|
let mut purged: VecDeque<_> = old
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|label| label.pubkey() != self_id)
|
.filter(|label| label.pubkey() != *self_id)
|
||||||
.filter_map(|label| {
|
.filter_map(|label| {
|
||||||
let rv = crds
|
let rv = crds
|
||||||
.lookup_versioned(label)
|
.lookup_versioned(label)
|
||||||
|
@ -216,11 +216,11 @@ mod test {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut stakes = HashMap::new();
|
let mut stakes = HashMap::new();
|
||||||
let node = CrdsGossipPull::default();
|
let node = CrdsGossipPull::default();
|
||||||
let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
crds.insert(me.clone(), 0).unwrap();
|
crds.insert(me.clone(), 0).unwrap();
|
||||||
for i in 1..=30 {
|
for i in 1..=30 {
|
||||||
let entry =
|
let entry =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let id = entry.label().pubkey();
|
let id = entry.label().pubkey();
|
||||||
crds.insert(entry.clone(), 0).unwrap();
|
crds.insert(entry.clone(), 0).unwrap();
|
||||||
stakes.insert(id, i * 100);
|
stakes.insert(id, i * 100);
|
||||||
|
@ -239,23 +239,23 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_pull_request() {
|
fn test_new_pull_request() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let id = entry.label().pubkey();
|
let id = entry.label().pubkey();
|
||||||
let node = CrdsGossipPull::default();
|
let node = CrdsGossipPull::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
node.new_pull_request(&crds, id, 0, &HashMap::new()),
|
node.new_pull_request(&crds, &id, 0, &HashMap::new()),
|
||||||
Err(CrdsGossipError::NoPeers)
|
Err(CrdsGossipError::NoPeers)
|
||||||
);
|
);
|
||||||
|
|
||||||
crds.insert(entry.clone(), 0).unwrap();
|
crds.insert(entry.clone(), 0).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
node.new_pull_request(&crds, id, 0, &HashMap::new()),
|
node.new_pull_request(&crds, &id, 0, &HashMap::new()),
|
||||||
Err(CrdsGossipError::NoPeers)
|
Err(CrdsGossipError::NoPeers)
|
||||||
);
|
);
|
||||||
|
|
||||||
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
crds.insert(new.clone(), 0).unwrap();
|
crds.insert(new.clone(), 0).unwrap();
|
||||||
let req = node.new_pull_request(&crds, id, 0, &HashMap::new());
|
let req = node.new_pull_request(&crds, &id, 0, &HashMap::new());
|
||||||
let (to, _, self_info) = req.unwrap();
|
let (to, _, self_info) = req.unwrap();
|
||||||
assert_eq!(to, new.label().pubkey());
|
assert_eq!(to, new.label().pubkey());
|
||||||
assert_eq!(self_info, entry);
|
assert_eq!(self_info, entry);
|
||||||
|
@ -264,21 +264,21 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_mark_creation_time() {
|
fn test_new_mark_creation_time() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let node_id = entry.label().pubkey();
|
let node_id = entry.label().pubkey();
|
||||||
let mut node = CrdsGossipPull::default();
|
let mut node = CrdsGossipPull::default();
|
||||||
crds.insert(entry.clone(), 0).unwrap();
|
crds.insert(entry.clone(), 0).unwrap();
|
||||||
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
crds.insert(old.clone(), 0).unwrap();
|
crds.insert(old.clone(), 0).unwrap();
|
||||||
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
crds.insert(new.clone(), 0).unwrap();
|
crds.insert(new.clone(), 0).unwrap();
|
||||||
|
|
||||||
// set request creation time to max_value
|
// set request creation time to max_value
|
||||||
node.mark_pull_request_creation_time(new.label().pubkey(), u64::max_value());
|
node.mark_pull_request_creation_time(&new.label().pubkey(), u64::max_value());
|
||||||
|
|
||||||
// odds of getting the other request should be 1 in u64::max_value()
|
// odds of getting the other request should be 1 in u64::max_value()
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let req = node.new_pull_request(&crds, node_id, u64::max_value(), &HashMap::new());
|
let req = node.new_pull_request(&crds, &node_id, u64::max_value(), &HashMap::new());
|
||||||
let (to, _, self_info) = req.unwrap();
|
let (to, _, self_info) = req.unwrap();
|
||||||
assert_eq!(to, old.label().pubkey());
|
assert_eq!(to, old.label().pubkey());
|
||||||
assert_eq!(self_info, entry);
|
assert_eq!(self_info, entry);
|
||||||
|
@ -288,13 +288,13 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_pull_request() {
|
fn test_process_pull_request() {
|
||||||
let mut node_crds = Crds::default();
|
let mut node_crds = Crds::default();
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let node_id = entry.label().pubkey();
|
let node_id = entry.label().pubkey();
|
||||||
let node = CrdsGossipPull::default();
|
let node = CrdsGossipPull::default();
|
||||||
node_crds.insert(entry.clone(), 0).unwrap();
|
node_crds.insert(entry.clone(), 0).unwrap();
|
||||||
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
node_crds.insert(new.clone(), 0).unwrap();
|
node_crds.insert(new.clone(), 0).unwrap();
|
||||||
let req = node.new_pull_request(&node_crds, node_id, 0, &HashMap::new());
|
let req = node.new_pull_request(&node_crds, &node_id, 0, &HashMap::new());
|
||||||
|
|
||||||
let mut dest_crds = Crds::default();
|
let mut dest_crds = Crds::default();
|
||||||
let mut dest = CrdsGossipPull::default();
|
let mut dest = CrdsGossipPull::default();
|
||||||
|
@ -320,22 +320,22 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_pull_request_response() {
|
fn test_process_pull_request_response() {
|
||||||
let mut node_crds = Crds::default();
|
let mut node_crds = Crds::default();
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let node_id = entry.label().pubkey();
|
let node_id = entry.label().pubkey();
|
||||||
let mut node = CrdsGossipPull::default();
|
let mut node = CrdsGossipPull::default();
|
||||||
node_crds.insert(entry.clone(), 0).unwrap();
|
node_crds.insert(entry.clone(), 0).unwrap();
|
||||||
|
|
||||||
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
node_crds.insert(new.clone(), 0).unwrap();
|
node_crds.insert(new.clone(), 0).unwrap();
|
||||||
|
|
||||||
let mut dest = CrdsGossipPull::default();
|
let mut dest = CrdsGossipPull::default();
|
||||||
let mut dest_crds = Crds::default();
|
let mut dest_crds = Crds::default();
|
||||||
let new_id = Keypair::new().pubkey();
|
let new_id = Keypair::new().pubkey();
|
||||||
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(new_id, 1));
|
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&new_id, 1));
|
||||||
dest_crds.insert(new.clone(), 0).unwrap();
|
dest_crds.insert(new.clone(), 0).unwrap();
|
||||||
|
|
||||||
// node contains a key from the dest node, but at an older local timestamp
|
// node contains a key from the dest node, but at an older local timestamp
|
||||||
let same_key = CrdsValue::ContactInfo(ContactInfo::new_localhost(new_id, 0));
|
let same_key = CrdsValue::ContactInfo(ContactInfo::new_localhost(&new_id, 0));
|
||||||
assert_eq!(same_key.label(), new.label());
|
assert_eq!(same_key.label(), new.label());
|
||||||
assert!(same_key.wallclock() < new.wallclock());
|
assert!(same_key.wallclock() < new.wallclock());
|
||||||
node_crds.insert(same_key.clone(), 0).unwrap();
|
node_crds.insert(same_key.clone(), 0).unwrap();
|
||||||
|
@ -349,7 +349,7 @@ mod test {
|
||||||
let mut done = false;
|
let mut done = false;
|
||||||
for _ in 0..30 {
|
for _ in 0..30 {
|
||||||
// there is a chance of a false positive with bloom filters
|
// there is a chance of a false positive with bloom filters
|
||||||
let req = node.new_pull_request(&node_crds, node_id, 0, &HashMap::new());
|
let req = node.new_pull_request(&node_crds, &node_id, 0, &HashMap::new());
|
||||||
let (_, filter, caller) = req.unwrap();
|
let (_, filter, caller) = req.unwrap();
|
||||||
let rsp = dest.process_pull_request(&mut dest_crds, caller, filter, 0);
|
let rsp = dest.process_pull_request(&mut dest_crds, caller, filter, 0);
|
||||||
// if there is a false positive this is empty
|
// if there is a false positive this is empty
|
||||||
|
@ -359,7 +359,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(rsp.len(), 1);
|
assert_eq!(rsp.len(), 1);
|
||||||
let failed = node.process_pull_response(&mut node_crds, node_id, rsp, 1);
|
let failed = node.process_pull_response(&mut node_crds, &node_id, rsp, 1);
|
||||||
assert_eq!(failed, 0);
|
assert_eq!(failed, 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
node_crds
|
node_crds
|
||||||
|
@ -384,12 +384,12 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gossip_purge() {
|
fn test_gossip_purge() {
|
||||||
let mut node_crds = Crds::default();
|
let mut node_crds = Crds::default();
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let node_label = entry.label();
|
let node_label = entry.label();
|
||||||
let node_id = node_label.pubkey();
|
let node_id = node_label.pubkey();
|
||||||
let mut node = CrdsGossipPull::default();
|
let mut node = CrdsGossipPull::default();
|
||||||
node_crds.insert(entry.clone(), 0).unwrap();
|
node_crds.insert(entry.clone(), 0).unwrap();
|
||||||
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
node_crds.insert(old.clone(), 0).unwrap();
|
node_crds.insert(old.clone(), 0).unwrap();
|
||||||
let value_hash = node_crds.lookup_versioned(&old.label()).unwrap().value_hash;
|
let value_hash = node_crds.lookup_versioned(&old.label()).unwrap().value_hash;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ mod test {
|
||||||
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
|
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
|
||||||
|
|
||||||
// purge
|
// purge
|
||||||
node.purge_active(&mut node_crds, node_id, 1);
|
node.purge_active(&mut node_crds, &node_id, 1);
|
||||||
|
|
||||||
//verify self is still valid after purge
|
//verify self is still valid after purge
|
||||||
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
|
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
|
||||||
|
|
|
@ -144,9 +144,9 @@ impl CrdsGossipPush {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// add the `from` to the peer's filter of nodes
|
/// add the `from` to the peer's filter of nodes
|
||||||
pub fn process_prune_msg(&mut self, peer: Pubkey, origins: &[Pubkey]) {
|
pub fn process_prune_msg(&mut self, peer: &Pubkey, origins: &[Pubkey]) {
|
||||||
for origin in origins {
|
for origin in origins {
|
||||||
if let Some(p) = self.active_set.get_mut(&peer) {
|
if let Some(p) = self.active_set.get_mut(peer) {
|
||||||
p.add(origin)
|
p.add(origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ impl CrdsGossipPush {
|
||||||
&mut self,
|
&mut self,
|
||||||
crds: &Crds,
|
crds: &Crds,
|
||||||
stakes: &HashMap<Pubkey, u64>,
|
stakes: &HashMap<Pubkey, u64>,
|
||||||
self_id: Pubkey,
|
self_id: &Pubkey,
|
||||||
network_size: usize,
|
network_size: usize,
|
||||||
ratio: usize,
|
ratio: usize,
|
||||||
) {
|
) {
|
||||||
|
@ -272,7 +272,7 @@ mod test {
|
||||||
fn test_process_push() {
|
fn test_process_push() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let label = value.label();
|
let label = value.label();
|
||||||
// push a new message
|
// push a new message
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -291,7 +291,7 @@ mod test {
|
||||||
fn test_process_push_old_version() {
|
fn test_process_push_old_version() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
ci.wallclock = 1;
|
ci.wallclock = 1;
|
||||||
let value = CrdsValue::ContactInfo(ci.clone());
|
let value = CrdsValue::ContactInfo(ci.clone());
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ mod test {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let timeout = push.msg_timeout;
|
let timeout = push.msg_timeout;
|
||||||
let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
|
|
||||||
// push a version to far in the future
|
// push a version to far in the future
|
||||||
ci.wallclock = timeout + 1;
|
ci.wallclock = timeout + 1;
|
||||||
|
@ -333,7 +333,7 @@ mod test {
|
||||||
fn test_process_push_update() {
|
fn test_process_push_update() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
ci.wallclock = 0;
|
ci.wallclock = 0;
|
||||||
let value_old = CrdsValue::ContactInfo(ci.clone());
|
let value_old = CrdsValue::ContactInfo(ci.clone());
|
||||||
|
|
||||||
|
@ -366,17 +366,19 @@ mod test {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let value1 = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let value1 =
|
||||||
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
|
|
||||||
assert_eq!(crds.insert(value1.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(value1.clone(), 0), Ok(None));
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
|
|
||||||
assert!(push.active_set.get(&value1.label().pubkey()).is_some());
|
assert!(push.active_set.get(&value1.label().pubkey()).is_some());
|
||||||
let value2 = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let value2 =
|
||||||
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert!(push.active_set.get(&value2.label().pubkey()).is_none());
|
assert!(push.active_set.get(&value2.label().pubkey()).is_none());
|
||||||
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
|
||||||
for _ in 0..30 {
|
for _ in 0..30 {
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
if push.active_set.get(&value2.label().pubkey()).is_some() {
|
if push.active_set.get(&value2.label().pubkey()).is_some() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -385,10 +387,10 @@ mod test {
|
||||||
|
|
||||||
for _ in 0..push.num_active {
|
for _ in 0..push.num_active {
|
||||||
let value2 =
|
let value2 =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
|
||||||
}
|
}
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
assert_eq!(push.active_set.len(), push.num_active);
|
assert_eq!(push.active_set.len(), push.num_active);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -399,7 +401,7 @@ mod test {
|
||||||
let mut stakes = HashMap::new();
|
let mut stakes = HashMap::new();
|
||||||
for i in 1..=100 {
|
for i in 1..=100 {
|
||||||
let peer =
|
let peer =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), time));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), time));
|
||||||
let id = peer.label().pubkey();
|
let id = peer.label().pubkey();
|
||||||
crds.insert(peer.clone(), time).unwrap();
|
crds.insert(peer.clone(), time).unwrap();
|
||||||
stakes.insert(id, i * 100);
|
stakes.insert(id, i * 100);
|
||||||
|
@ -417,12 +419,12 @@ mod test {
|
||||||
fn test_new_push_messages() {
|
fn test_new_push_messages() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
|
|
||||||
let new_msg =
|
let new_msg =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
push.process_push_message(&mut crds, new_msg.clone(), 0),
|
push.process_push_message(&mut crds, new_msg.clone(), 0),
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -437,17 +439,17 @@ mod test {
|
||||||
fn test_process_prune() {
|
fn test_process_prune() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
|
|
||||||
let new_msg =
|
let new_msg =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
push.process_push_message(&mut crds, new_msg.clone(), 0),
|
push.process_push_message(&mut crds, new_msg.clone(), 0),
|
||||||
Ok(None)
|
Ok(None)
|
||||||
);
|
);
|
||||||
push.process_prune_msg(peer.label().pubkey(), &[new_msg.label().pubkey()]);
|
push.process_prune_msg(&peer.label().pubkey(), &[new_msg.label().pubkey()]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
push.new_push_messages(&crds, 0),
|
push.new_push_messages(&crds, 0),
|
||||||
(vec![peer.label().pubkey()], vec![])
|
(vec![peer.label().pubkey()], vec![])
|
||||||
|
@ -457,11 +459,11 @@ mod test {
|
||||||
fn test_purge_old_pending_push_messages() {
|
fn test_purge_old_pending_push_messages() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
|
||||||
push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1);
|
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
|
||||||
|
|
||||||
let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
ci.wallclock = 1;
|
ci.wallclock = 1;
|
||||||
let new_msg = CrdsValue::ContactInfo(ci.clone());
|
let new_msg = CrdsValue::ContactInfo(ci.clone());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -479,7 +481,7 @@ mod test {
|
||||||
fn test_purge_old_pushed_once_messages() {
|
fn test_purge_old_pushed_once_messages() {
|
||||||
let mut crds = Crds::default();
|
let mut crds = Crds::default();
|
||||||
let mut push = CrdsGossipPush::default();
|
let mut push = CrdsGossipPush::default();
|
||||||
let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
ci.wallclock = 0;
|
ci.wallclock = 0;
|
||||||
let value = CrdsValue::ContactInfo(ci.clone());
|
let value = CrdsValue::ContactInfo(ci.clone());
|
||||||
let label = value.label();
|
let label = value.label();
|
||||||
|
|
|
@ -108,8 +108,11 @@ impl CrdsValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Return all the possible labels for a record identified by Pubkey.
|
/// Return all the possible labels for a record identified by Pubkey.
|
||||||
pub fn record_labels(key: Pubkey) -> [CrdsValueLabel; 2] {
|
pub fn record_labels(key: &Pubkey) -> [CrdsValueLabel; 2] {
|
||||||
[CrdsValueLabel::ContactInfo(key), CrdsValueLabel::Vote(key)]
|
[
|
||||||
|
CrdsValueLabel::ContactInfo(*key),
|
||||||
|
CrdsValueLabel::Vote(*key),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +162,7 @@ mod test {
|
||||||
fn test_labels() {
|
fn test_labels() {
|
||||||
let mut hits = [false; 2];
|
let mut hits = [false; 2];
|
||||||
// this method should cover all the possible labels
|
// this method should cover all the possible labels
|
||||||
for v in &CrdsValue::record_labels(Pubkey::default()) {
|
for v in &CrdsValue::record_labels(&Pubkey::default()) {
|
||||||
match v {
|
match v {
|
||||||
CrdsValueLabel::ContactInfo(_) => hits[0] = true,
|
CrdsValueLabel::ContactInfo(_) => hits[0] = true,
|
||||||
CrdsValueLabel::Vote(_) => hits[1] = true,
|
CrdsValueLabel::Vote(_) => hits[1] = true,
|
||||||
|
@ -184,7 +187,7 @@ mod test {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let fake_keypair = Keypair::new();
|
let fake_keypair = Keypair::new();
|
||||||
let mut v =
|
let mut v =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(keypair.pubkey(), timestamp()));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&keypair.pubkey(), timestamp()));
|
||||||
v.sign(&keypair);
|
v.sign(&keypair);
|
||||||
assert!(v.verify());
|
assert!(v.verify());
|
||||||
v.sign(&fake_keypair);
|
v.sign(&fake_keypair);
|
||||||
|
|
|
@ -400,8 +400,8 @@ pub fn make_tiny_test_entries_from_hash(start: &Hash, num: usize) -> Vec<Entry>
|
||||||
&mut num_hashes,
|
&mut num_hashes,
|
||||||
vec![BudgetTransaction::new_timestamp(
|
vec![BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
*start,
|
*start,
|
||||||
)],
|
)],
|
||||||
|
@ -423,8 +423,8 @@ pub fn make_large_test_entries(num_entries: usize) -> Vec<Entry> {
|
||||||
|
|
||||||
let tx = BudgetTransaction::new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
one,
|
one,
|
||||||
);
|
);
|
||||||
|
@ -496,8 +496,8 @@ mod tests {
|
||||||
|
|
||||||
// First, verify entries
|
// First, verify entries
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
let tx0 = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
||||||
let tx1 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, zero, 0);
|
let tx1 = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, zero, 0);
|
||||||
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
||||||
assert!(e0.verify(&zero));
|
assert!(e0.verify(&zero));
|
||||||
|
|
||||||
|
@ -515,13 +515,13 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = BudgetTransaction::new_timestamp(
|
let tx0 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
zero,
|
zero,
|
||||||
);
|
);
|
||||||
let tx1 =
|
let tx1 =
|
||||||
BudgetTransaction::new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero);
|
BudgetTransaction::new_signature(&keypair, &keypair.pubkey(), &keypair.pubkey(), zero);
|
||||||
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
||||||
assert!(e0.verify(&zero));
|
assert!(e0.verify(&zero));
|
||||||
|
|
||||||
|
@ -545,8 +545,8 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = BudgetTransaction::new_timestamp(
|
let tx0 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
zero,
|
zero,
|
||||||
);
|
);
|
||||||
|
@ -560,7 +560,7 @@ mod tests {
|
||||||
fn test_next_entry_panic() {
|
fn test_next_entry_panic() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
||||||
next_entry(&zero, 0, vec![tx]);
|
next_entry(&zero, 0, vec![tx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,7 +568,7 @@ mod tests {
|
||||||
fn test_serialized_size() {
|
fn test_serialized_size() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
||||||
let entry = next_entry(&zero, 1, vec![tx.clone()]);
|
let entry = next_entry(&zero, 1, vec![tx.clone()]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Entry::serialized_size(&[tx]),
|
Entry::serialized_size(&[tx]),
|
||||||
|
@ -596,11 +596,11 @@ mod tests {
|
||||||
let one = hash(&zero.as_ref());
|
let one = hash(&zero.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_account = Keypair::new();
|
let vote_account = Keypair::new();
|
||||||
let tx0 = VoteTransaction::new_vote(vote_account.pubkey(), &vote_account, 1, one, 1);
|
let tx0 = VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, one, 1);
|
||||||
let tx1 = BudgetTransaction::new_timestamp(
|
let tx1 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
one,
|
one,
|
||||||
);
|
);
|
||||||
|
@ -645,8 +645,8 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_account = Keypair::new();
|
let vote_account = Keypair::new();
|
||||||
let tx_small =
|
let tx_small =
|
||||||
VoteTransaction::new_vote(vote_account.pubkey(), &vote_account, 1, next_hash, 2);
|
VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, next_hash, 2);
|
||||||
let tx_large = BudgetTransaction::new_payment(&keypair, keypair.pubkey(), 1, next_hash, 0);
|
let tx_large = BudgetTransaction::new_payment(&keypair, &keypair.pubkey(), 1, next_hash, 0);
|
||||||
|
|
||||||
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
||||||
let tx_large_size = tx_large.serialized_size().unwrap() as usize;
|
let tx_large_size = tx_large.serialized_size().unwrap() as usize;
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Fullnode {
|
||||||
mut node: Node,
|
mut node: Node,
|
||||||
keypair: &Arc<Keypair>,
|
keypair: &Arc<Keypair>,
|
||||||
ledger_path: &str,
|
ledger_path: &str,
|
||||||
vote_account: Pubkey,
|
vote_account: &Pubkey,
|
||||||
voting_keypair: T,
|
voting_keypair: T,
|
||||||
entrypoint_info_option: Option<&ContactInfo>,
|
entrypoint_info_option: Option<&ContactInfo>,
|
||||||
config: &FullnodeConfig,
|
config: &FullnodeConfig,
|
||||||
|
@ -208,7 +208,7 @@ impl Fullnode {
|
||||||
&exit,
|
&exit,
|
||||||
);
|
);
|
||||||
let tpu = Tpu::new(
|
let tpu = Tpu::new(
|
||||||
id,
|
&id,
|
||||||
&cluster_info,
|
&cluster_info,
|
||||||
&poh_recorder,
|
&poh_recorder,
|
||||||
entry_receiver,
|
entry_receiver,
|
||||||
|
@ -325,7 +325,7 @@ pub fn make_active_set_entries(
|
||||||
// 1) Assume the active_keypair node has no lamports staked
|
// 1) Assume the active_keypair node has no lamports staked
|
||||||
let transfer_tx = SystemTransaction::new_account(
|
let transfer_tx = SystemTransaction::new_account(
|
||||||
&lamport_source,
|
&lamport_source,
|
||||||
active_keypair.pubkey(),
|
&active_keypair.pubkey(),
|
||||||
stake,
|
stake,
|
||||||
*blockhash,
|
*blockhash,
|
||||||
0,
|
0,
|
||||||
|
@ -339,7 +339,7 @@ pub fn make_active_set_entries(
|
||||||
|
|
||||||
let new_vote_account_tx = VoteTransaction::new_account(
|
let new_vote_account_tx = VoteTransaction::new_account(
|
||||||
active_keypair,
|
active_keypair,
|
||||||
vote_account_id,
|
&vote_account_id,
|
||||||
*blockhash,
|
*blockhash,
|
||||||
stake.saturating_sub(2),
|
stake.saturating_sub(2),
|
||||||
1,
|
1,
|
||||||
|
@ -348,7 +348,7 @@ pub fn make_active_set_entries(
|
||||||
|
|
||||||
// 3) Create vote entry
|
// 3) Create vote entry
|
||||||
let vote_tx = VoteTransaction::new_vote(
|
let vote_tx = VoteTransaction::new_vote(
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
&voting_keypair,
|
&voting_keypair,
|
||||||
slot_to_vote_on,
|
slot_to_vote_on,
|
||||||
*blockhash,
|
*blockhash,
|
||||||
|
@ -373,12 +373,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_exit() {
|
fn validator_exit() {
|
||||||
let leader_keypair = Keypair::new();
|
let leader_keypair = Keypair::new();
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
|
||||||
|
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
GenesisBlock::new_with_leader(10_000, &leader_keypair.pubkey(), 1000);
|
||||||
let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
validator_node,
|
validator_node,
|
||||||
&Arc::new(validator_keypair),
|
&Arc::new(validator_keypair),
|
||||||
&validator_ledger_path,
|
&validator_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
Some(&leader_node.info),
|
Some(&leader_node.info),
|
||||||
&FullnodeConfig::default(),
|
&FullnodeConfig::default(),
|
||||||
|
@ -398,15 +398,15 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_parallel_exit() {
|
fn validator_parallel_exit() {
|
||||||
let leader_keypair = Keypair::new();
|
let leader_keypair = Keypair::new();
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
|
||||||
|
|
||||||
let mut ledger_paths = vec![];
|
let mut ledger_paths = vec![];
|
||||||
let validators: Vec<Fullnode> = (0..2)
|
let validators: Vec<Fullnode> = (0..2)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
GenesisBlock::new_with_leader(10_000, &leader_keypair.pubkey(), 1000);
|
||||||
let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
ledger_paths.push(validator_ledger_path.clone());
|
ledger_paths.push(validator_ledger_path.clone());
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
|
@ -414,7 +414,7 @@ mod tests {
|
||||||
validator_node,
|
validator_node,
|
||||||
&Arc::new(validator_keypair),
|
&Arc::new(validator_keypair),
|
||||||
&validator_ledger_path,
|
&validator_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
Some(&leader_node.info),
|
Some(&leader_node.info),
|
||||||
&FullnodeConfig::default(),
|
&FullnodeConfig::default(),
|
||||||
|
|
|
@ -139,7 +139,7 @@ mod tests {
|
||||||
bank.register_tick(&tick_hash);
|
bank.register_tick(&tick_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
bank = Arc::new(Bank::new_from_parent(&bank, Pubkey::default(), slot));
|
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
|
@ -154,7 +154,7 @@ mod tests {
|
||||||
let voting_pubkey = voting_keypair.pubkey();
|
let voting_pubkey = voting_keypair.pubkey();
|
||||||
|
|
||||||
// Give the validator some lamports
|
// Give the validator some lamports
|
||||||
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), blockhash)
|
bank.transfer(2, &mint_keypair, &validator_keypair.pubkey(), blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
|
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ mod tests {
|
||||||
// Get another validator to vote, so we now have 2/3 consensus
|
// Get another validator to vote, so we now have 2/3 consensus
|
||||||
let voting_keypair = &vote_accounts[7].0;
|
let voting_keypair = &vote_accounts[7].0;
|
||||||
let vote_tx =
|
let vote_tx =
|
||||||
VoteTransaction::new_vote(voting_keypair.pubkey(), voting_keypair, 7, blockhash, 0);
|
VoteTransaction::new_vote(&voting_keypair.pubkey(), voting_keypair, 7, blockhash, 0);
|
||||||
bank.process_transaction(&vote_tx).unwrap();
|
bank.process_transaction(&vote_tx).unwrap();
|
||||||
|
|
||||||
LeaderConfirmationService::compute_confirmation(&bank, &mut last_confirmation_time);
|
LeaderConfirmationService::compute_confirmation(&bank, &mut last_confirmation_time);
|
||||||
|
|
|
@ -59,7 +59,7 @@ mod tests {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
pubkey,
|
&pubkey,
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
);
|
);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
@ -79,7 +79,7 @@ mod tests {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let genesis_block = GenesisBlock::new_with_leader(
|
let genesis_block = GenesisBlock::new_with_leader(
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
pubkey,
|
&pubkey,
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
)
|
)
|
||||||
.0;
|
.0;
|
||||||
|
|
|
@ -39,9 +39,9 @@ impl LocalCluster {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let leader_keypair = Arc::new(Keypair::new());
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
let leader_pubkey = leader_keypair.pubkey();
|
let leader_pubkey = leader_keypair.pubkey();
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
|
||||||
let (genesis_block, mint_keypair) =
|
let (genesis_block, mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(cluster_lamports, leader_pubkey, node_stakes[0]);
|
GenesisBlock::new_with_leader(cluster_lamports, &leader_pubkey, node_stakes[0]);
|
||||||
let (genesis_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (genesis_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||||
let mut ledger_paths = vec![];
|
let mut ledger_paths = vec![];
|
||||||
|
@ -53,7 +53,7 @@ impl LocalCluster {
|
||||||
leader_node,
|
leader_node,
|
||||||
&leader_keypair,
|
&leader_keypair,
|
||||||
&leader_ledger_path,
|
&leader_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
None,
|
None,
|
||||||
fullnode_config,
|
fullnode_config,
|
||||||
|
@ -66,7 +66,7 @@ impl LocalCluster {
|
||||||
let validator_keypair = Arc::new(Keypair::new());
|
let validator_keypair = Arc::new(Keypair::new());
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
let validator_pubkey = validator_keypair.pubkey();
|
let validator_pubkey = validator_keypair.pubkey();
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
||||||
let ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
let ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||||
ledger_paths.push(ledger_path.clone());
|
ledger_paths.push(ledger_path.clone());
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl LocalCluster {
|
||||||
validator_node,
|
validator_node,
|
||||||
&validator_keypair,
|
&validator_keypair,
|
||||||
&ledger_path,
|
&ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
Some(&leader_contact_info),
|
Some(&leader_contact_info),
|
||||||
fullnode_config,
|
fullnode_config,
|
||||||
|
@ -134,7 +134,7 @@ impl LocalCluster {
|
||||||
trace!("getting leader blockhash");
|
trace!("getting leader blockhash");
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
let mut tx =
|
let mut tx =
|
||||||
SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, blockhash, 0);
|
SystemTransaction::new_account(&source_keypair, dest_pubkey, lamports, blockhash, 0);
|
||||||
info!(
|
info!(
|
||||||
"executing transfer of {} from {} to {}",
|
"executing transfer of {} from {} to {}",
|
||||||
lamports,
|
lamports,
|
||||||
|
@ -160,7 +160,7 @@ impl LocalCluster {
|
||||||
// 1) Create vote account
|
// 1) Create vote account
|
||||||
let mut transaction = VoteTransaction::new_account(
|
let mut transaction = VoteTransaction::new_account(
|
||||||
from_account,
|
from_account,
|
||||||
vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
client.get_recent_blockhash(),
|
client.get_recent_blockhash(),
|
||||||
amount,
|
amount,
|
||||||
1,
|
1,
|
||||||
|
@ -175,7 +175,7 @@ impl LocalCluster {
|
||||||
let mut transaction = VoteTransaction::delegate_vote_account(
|
let mut transaction = VoteTransaction::delegate_vote_account(
|
||||||
vote_account,
|
vote_account,
|
||||||
client.get_recent_blockhash(),
|
client.get_recent_blockhash(),
|
||||||
delegate_id,
|
&delegate_id,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -524,7 +524,7 @@ mod tests {
|
||||||
fn test_to_packets() {
|
fn test_to_packets() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let hash = Hash::new(&[1; 32]);
|
let hash = Hash::new(&[1; 32]);
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, hash, 0);
|
let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, hash, 0);
|
||||||
let rv = to_packets(&vec![tx.clone(); 1]);
|
let rv = to_packets(&vec![tx.clone(); 1]);
|
||||||
assert_eq!(rv.len(), 1);
|
assert_eq!(rv.len(), 1);
|
||||||
assert_eq!(rv[0].read().unwrap().packets.len(), 1);
|
assert_eq!(rv[0].read().unwrap().packets.len(), 1);
|
||||||
|
|
|
@ -53,8 +53,8 @@ pub struct ReplayStage {
|
||||||
impl ReplayStage {
|
impl ReplayStage {
|
||||||
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
|
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
|
||||||
pub fn new<T>(
|
pub fn new<T>(
|
||||||
my_id: Pubkey,
|
my_id: &Pubkey,
|
||||||
vote_account: Pubkey,
|
vote_account: &Pubkey,
|
||||||
voting_keypair: Option<Arc<T>>,
|
voting_keypair: Option<Arc<T>>,
|
||||||
blocktree: Arc<Blocktree>,
|
blocktree: Arc<Blocktree>,
|
||||||
bank_forks: &Arc<RwLock<BankForks>>,
|
bank_forks: &Arc<RwLock<BankForks>>,
|
||||||
|
@ -74,6 +74,8 @@ impl ReplayStage {
|
||||||
let subscriptions = subscriptions.clone();
|
let subscriptions = subscriptions.clone();
|
||||||
let bank_forks = bank_forks.clone();
|
let bank_forks = bank_forks.clone();
|
||||||
let poh_recorder = poh_recorder.clone();
|
let poh_recorder = poh_recorder.clone();
|
||||||
|
let my_id = *my_id;
|
||||||
|
let vote_account = *vote_account;
|
||||||
|
|
||||||
// Start the replay stage loop
|
// Start the replay stage loop
|
||||||
let t_replay = Builder::new()
|
let t_replay = Builder::new()
|
||||||
|
@ -132,7 +134,7 @@ impl ReplayStage {
|
||||||
if let Some(ref voting_keypair) = voting_keypair {
|
if let Some(ref voting_keypair) = voting_keypair {
|
||||||
let keypair = voting_keypair.as_ref();
|
let keypair = voting_keypair.as_ref();
|
||||||
let vote = VoteTransaction::new_vote(
|
let vote = VoteTransaction::new_vote(
|
||||||
vote_account,
|
&vote_account,
|
||||||
keypair,
|
keypair,
|
||||||
*latest_slot_vote,
|
*latest_slot_vote,
|
||||||
parent.last_blockhash(),
|
parent.last_blockhash(),
|
||||||
|
@ -148,7 +150,7 @@ impl ReplayStage {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_tpu_bank_active {
|
if !is_tpu_bank_active {
|
||||||
Self::start_leader(my_id, &bank_forks, &poh_recorder, &cluster_info);
|
Self::start_leader(&my_id, &bank_forks, &poh_recorder, &cluster_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
inc_new_counter_info!(
|
inc_new_counter_info!(
|
||||||
|
@ -173,7 +175,7 @@ impl ReplayStage {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn start_leader(
|
pub fn start_leader(
|
||||||
my_id: Pubkey,
|
my_id: &Pubkey,
|
||||||
bank_forks: &Arc<RwLock<BankForks>>,
|
bank_forks: &Arc<RwLock<BankForks>>,
|
||||||
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
|
@ -195,8 +197,8 @@ impl ReplayStage {
|
||||||
"me: {} leader {} at poh slot {}",
|
"me: {} leader {} at poh slot {}",
|
||||||
my_id, next_leader, poh_slot
|
my_id, next_leader, poh_slot
|
||||||
);
|
);
|
||||||
cluster_info.write().unwrap().set_leader(next_leader);
|
cluster_info.write().unwrap().set_leader(&next_leader);
|
||||||
if next_leader == my_id {
|
if next_leader == *my_id {
|
||||||
debug!("starting tpu for slot {}", poh_slot);
|
debug!("starting tpu for slot {}", poh_slot);
|
||||||
let tpu_bank = Bank::new_from_parent(parent, my_id, poh_slot);
|
let tpu_bank = Bank::new_from_parent(parent, my_id, poh_slot);
|
||||||
bank_forks.write().unwrap().insert(poh_slot, tpu_bank);
|
bank_forks.write().unwrap().insert(poh_slot, tpu_bank);
|
||||||
|
@ -325,7 +327,7 @@ impl ReplayStage {
|
||||||
info!("new fork:{} parent:{}", child_id, parent_id);
|
info!("new fork:{} parent:{}", child_id, parent_id);
|
||||||
forks.insert(
|
forks.insert(
|
||||||
child_id,
|
child_id,
|
||||||
Bank::new_from_parent(&parent_bank, leader, child_id),
|
Bank::new_from_parent(&parent_bank, &leader, child_id),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,12 +366,12 @@ mod test {
|
||||||
// Set up dummy node to host a ReplayStage
|
// Set up dummy node to host a ReplayStage
|
||||||
let my_keypair = Keypair::new();
|
let my_keypair = Keypair::new();
|
||||||
let my_id = my_keypair.pubkey();
|
let my_id = my_keypair.pubkey();
|
||||||
let my_node = Node::new_localhost_with_pubkey(my_id);
|
let my_node = Node::new_localhost_with_pubkey(&my_id);
|
||||||
|
|
||||||
// Create keypair for the leader
|
// Create keypair for the leader
|
||||||
let leader_id = Keypair::new().pubkey();
|
let leader_id = Keypair::new().pubkey();
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, &leader_id, 500);
|
||||||
|
|
||||||
let (my_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (my_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
|
@ -388,8 +390,8 @@ mod test {
|
||||||
let blocktree = Arc::new(blocktree);
|
let blocktree = Arc::new(blocktree);
|
||||||
let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank);
|
let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank);
|
||||||
let (replay_stage, _slot_full_receiver, ledger_writer_recv) = ReplayStage::new(
|
let (replay_stage, _slot_full_receiver, ledger_writer_recv) = ReplayStage::new(
|
||||||
my_keypair.pubkey(),
|
&my_keypair.pubkey(),
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
Some(voting_keypair.clone()),
|
Some(voting_keypair.clone()),
|
||||||
blocktree.clone(),
|
blocktree.clone(),
|
||||||
&Arc::new(RwLock::new(bank_forks)),
|
&Arc::new(RwLock::new(bank_forks)),
|
||||||
|
@ -402,7 +404,7 @@ mod test {
|
||||||
|
|
||||||
let keypair = voting_keypair.as_ref();
|
let keypair = voting_keypair.as_ref();
|
||||||
let vote =
|
let vote =
|
||||||
VoteTransaction::new_vote(keypair.pubkey(), keypair, 0, bank.last_blockhash(), 0);
|
VoteTransaction::new_vote(&keypair.pubkey(), keypair, 0, bank.last_blockhash(), 0);
|
||||||
cluster_info_me.write().unwrap().push_vote(vote);
|
cluster_info_me.write().unwrap().push_vote(vote);
|
||||||
|
|
||||||
info!("Send ReplayStage an entry, should see it on the ledger writer receiver");
|
info!("Send ReplayStage an entry, should see it on the ledger writer receiver");
|
||||||
|
|
|
@ -70,13 +70,13 @@ impl JsonRpcRequestProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account_info(&self, pubkey: Pubkey) -> Result<Account> {
|
pub fn get_account_info(&self, pubkey: &Pubkey) -> Result<Account> {
|
||||||
self.bank()?
|
self.bank()?
|
||||||
.get_account(&pubkey)
|
.get_account(&pubkey)
|
||||||
.ok_or_else(Error::invalid_request)
|
.ok_or_else(Error::invalid_request)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_balance(&self, pubkey: Pubkey) -> Result<u64> {
|
pub fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> {
|
||||||
let val = self.bank()?.get_balance(&pubkey);
|
let val = self.bank()?.get_balance(&pubkey);
|
||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
|
@ -229,13 +229,13 @@ impl RpcSol for RpcSolImpl {
|
||||||
meta.request_processor
|
meta.request_processor
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_account_info(pubkey)
|
.get_account_info(&pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_balance(&self, meta: Self::Metadata, id: String) -> Result<u64> {
|
fn get_balance(&self, meta: Self::Metadata, id: String) -> Result<u64> {
|
||||||
info!("get_balance rpc request received: {:?}", id);
|
info!("get_balance rpc request received: {:?}", id);
|
||||||
let pubkey = verify_pubkey(id)?;
|
let pubkey = verify_pubkey(id)?;
|
||||||
meta.request_processor.read().unwrap().get_balance(pubkey)
|
meta.request_processor.read().unwrap().get_balance(&pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_recent_blockhash(&self, meta: Self::Metadata) -> Result<String> {
|
fn get_recent_blockhash(&self, meta: Self::Metadata) -> Result<String> {
|
||||||
|
@ -414,7 +414,7 @@ mod tests {
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
||||||
let (genesis_block, alice) = GenesisBlock::new(10_000);
|
let (genesis_block, alice) = GenesisBlock::new(10_000);
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
@ -457,7 +457,7 @@ mod tests {
|
||||||
request_processor.set_bank(&bank);
|
request_processor.set_bank(&bank);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
bank.process_transaction(&tx).expect("process transaction");
|
bank.process_transaction(&tx).expect("process transaction");
|
||||||
})
|
})
|
||||||
.join()
|
.join()
|
||||||
|
@ -468,7 +468,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_balance() {
|
fn test_rpc_get_balance() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#,
|
||||||
|
@ -486,7 +486,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_tx_count() {
|
fn test_rpc_get_tx_count() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#);
|
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
@ -501,7 +501,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_account_info() {
|
fn test_rpc_get_account_info() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#,
|
||||||
|
@ -528,8 +528,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_confirm_tx() {
|
fn test_rpc_confirm_tx() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
||||||
|
@ -547,8 +547,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_signature_status() {
|
fn test_rpc_get_signature_status() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
|
@ -563,7 +563,7 @@ mod tests {
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
|
|
||||||
// Test getSignatureStatus request on unprocessed tx
|
// Test getSignatureStatus request on unprocessed tx
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 10, blockhash, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
tx.signatures[0]
|
tx.signatures[0]
|
||||||
|
@ -580,7 +580,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_recent_blockhash() {
|
fn test_rpc_get_recent_blockhash() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}}"#);
|
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}}"#);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
@ -595,7 +595,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_fail_request_airdrop() {
|
fn test_rpc_fail_request_airdrop() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
|
|
||||||
// Expect internal error because no drone is available
|
// Expect internal error because no drone is available
|
||||||
let req = format!(
|
let req = format!(
|
||||||
|
@ -674,7 +674,7 @@ mod tests {
|
||||||
fn test_rpc_verify_signature() {
|
fn test_rpc_verify_signature() {
|
||||||
let tx = SystemTransaction::new_move(
|
let tx = SystemTransaction::new_move(
|
||||||
&Keypair::new(),
|
&Keypair::new(),
|
||||||
Keypair::new().pubkey(),
|
&Keypair::new().pubkey(),
|
||||||
20,
|
20,
|
||||||
hash(&[0]),
|
hash(&[0]),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl MockRpcClient {
|
||||||
pub fn retry_get_balance(
|
pub fn retry_get_balance(
|
||||||
&self,
|
&self,
|
||||||
id: u64,
|
id: u64,
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
retries: usize,
|
retries: usize,
|
||||||
) -> Result<Option<u64>, Box<dyn error::Error>> {
|
) -> Result<Option<u64>, Box<dyn error::Error>> {
|
||||||
let params = json!([format!("{}", pubkey)]);
|
let params = json!([format!("{}", pubkey)]);
|
||||||
|
@ -106,6 +106,6 @@ pub fn request_airdrop_transaction(
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let tx = SystemTransaction::new_account(&key, to, lamports, blockhash, 0);
|
let tx = SystemTransaction::new_account(&key, &to, lamports, blockhash, 0);
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ mod tests {
|
||||||
// Simulate a block boundary
|
// Simulate a block boundary
|
||||||
Ok(Arc::new(Bank::new_from_parent(
|
Ok(Arc::new(Bank::new_from_parent(
|
||||||
&bank,
|
&bank,
|
||||||
Pubkey::default(),
|
&Pubkey::default(),
|
||||||
bank.slot() + 1,
|
bank.slot() + 1,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
|
|
||||||
// Test signature subscriptions
|
// Test signature subscriptions
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
|
|
||||||
let session = create_session();
|
let session = create_session();
|
||||||
let (subscriber, _id_receiver, mut receiver) =
|
let (subscriber, _id_receiver, mut receiver) =
|
||||||
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
|
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
||||||
tx.signatures[0].to_string()
|
tx.signatures[0].to_string()
|
||||||
|
@ -348,14 +348,14 @@ mod tests {
|
||||||
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
||||||
rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string());
|
rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string());
|
||||||
|
|
||||||
let tx = SystemTransaction::new_account(&alice, contract_funds.pubkey(), 51, blockhash, 0);
|
let tx = SystemTransaction::new_account(&alice, &contract_funds.pubkey(), 51, blockhash, 0);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
|
|
||||||
let tx = BudgetTransaction::new_when_signed(
|
let tx = BudgetTransaction::new_when_signed(
|
||||||
&contract_funds,
|
&contract_funds,
|
||||||
bob_pubkey,
|
&bob_pubkey,
|
||||||
contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
witness.pubkey(),
|
&witness.pubkey(),
|
||||||
None,
|
None,
|
||||||
51,
|
51,
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -387,13 +387,13 @@ mod tests {
|
||||||
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, blockhash, 0);
|
let tx = SystemTransaction::new_account(&alice, &witness.pubkey(), 1, blockhash, 0);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&witness,
|
&witness,
|
||||||
contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
bob_pubkey,
|
&bob_pubkey,
|
||||||
blockhash,
|
blockhash,
|
||||||
);
|
);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl RpcClient {
|
||||||
pub fn retry_get_balance(
|
pub fn retry_get_balance(
|
||||||
&self,
|
&self,
|
||||||
id: u64,
|
id: u64,
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
retries: usize,
|
retries: usize,
|
||||||
) -> Result<Option<u64>, Box<dyn error::Error>> {
|
) -> Result<Option<u64>, Box<dyn error::Error>> {
|
||||||
let params = json!([format!("{}", pubkey)]);
|
let params = json!([format!("{}", pubkey)]);
|
||||||
|
|
|
@ -123,7 +123,7 @@ mod tests {
|
||||||
.request_processor
|
.request_processor
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_balance(alice.pubkey())
|
.get_balance(&alice.pubkey())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
exit.store(true, Ordering::Relaxed);
|
exit.store(true, Ordering::Relaxed);
|
||||||
|
|
|
@ -210,11 +210,11 @@ mod tests {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
&alice.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
solana_budget_api::id(),
|
&solana_budget_api::id(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
@ -256,11 +256,11 @@ mod tests {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
&alice.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
solana_budget_api::id(),
|
&solana_budget_api::id(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
@ -299,7 +299,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&mint_keypair, &alice.pubkey(), 20, blockhash, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ mod tests {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn new_from_parent(parent: &Arc<Bank>, slot: u64) -> Bank {
|
fn new_from_parent(parent: &Arc<Bank>, slot: u64) -> Bank {
|
||||||
Bank::new_from_parent(parent, Pubkey::default(), slot)
|
Bank::new_from_parent(parent, &Pubkey::default(), slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -154,7 +154,7 @@ mod tests {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let bootstrap_lamports = 3;
|
let bootstrap_lamports = 3;
|
||||||
let (genesis_block, _) =
|
let (genesis_block, _) =
|
||||||
GenesisBlock::new_with_leader(bootstrap_lamports, pubkey, bootstrap_lamports);
|
GenesisBlock::new_with_leader(bootstrap_lamports, &pubkey, bootstrap_lamports);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
// Epoch doesn't exist
|
// Epoch doesn't exist
|
||||||
|
@ -184,7 +184,7 @@ mod tests {
|
||||||
// Give the validator some stake but don't setup a staking account
|
// Give the validator some stake but don't setup a staking account
|
||||||
// Validator has no lamports staked, so they get filtered out. Only the bootstrap leader
|
// Validator has no lamports staked, so they get filtered out. Only the bootstrap leader
|
||||||
// created by the genesis block will get included
|
// created by the genesis block will get included
|
||||||
bank.transfer(1, &mint_keypair, validator.pubkey(), genesis_block.hash())
|
bank.transfer(1, &mint_keypair, &validator.pubkey(), genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Make a mint vote account. Because the mint has nonzero stake, this
|
// Make a mint vote account. Because the mint has nonzero stake, this
|
||||||
|
@ -266,11 +266,11 @@ mod tests {
|
||||||
|
|
||||||
// Delegate 1 has stake of 3
|
// Delegate 1 has stake of 3
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
stakes.push((i, VoteState::new(delegate1)));
|
stakes.push((i, VoteState::new(&delegate1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delegate 1 has stake of 5
|
// Delegate 1 has stake of 5
|
||||||
stakes.push((5, VoteState::new(delegate2)));
|
stakes.push((5, VoteState::new(&delegate2)));
|
||||||
|
|
||||||
let result = to_delegated_stakes(stakes.into_iter());
|
let result = to_delegated_stakes(stakes.into_iter());
|
||||||
assert_eq!(result.len(), 2);
|
assert_eq!(result.len(), 2);
|
||||||
|
|
|
@ -474,7 +474,7 @@ mod tests {
|
||||||
let keypair = Arc::new(Keypair::new());
|
let keypair = Arc::new(Keypair::new());
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let cluster_info = test_cluster_info(keypair.pubkey());
|
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||||
|
|
||||||
let (_storage_entry_sender, storage_entry_receiver) = channel();
|
let (_storage_entry_sender, storage_entry_receiver) = channel();
|
||||||
let storage_state = StorageState::new();
|
let storage_state = StorageState::new();
|
||||||
|
@ -492,7 +492,7 @@ mod tests {
|
||||||
storage_stage.join().unwrap();
|
storage_stage.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_cluster_info(id: Pubkey) -> Arc<RwLock<ClusterInfo>> {
|
fn test_cluster_info(id: &Pubkey) -> Arc<RwLock<ClusterInfo>> {
|
||||||
let contact_info = ContactInfo::new_localhost(id, 0);
|
let contact_info = ContactInfo::new_localhost(id, 0);
|
||||||
let cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
let cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
|
||||||
Arc::new(RwLock::new(cluster_info))
|
Arc::new(RwLock::new(cluster_info))
|
||||||
|
@ -512,7 +512,7 @@ mod tests {
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||||
|
|
||||||
let cluster_info = test_cluster_info(keypair.pubkey());
|
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||||
|
|
||||||
let (storage_entry_sender, storage_entry_receiver) = channel();
|
let (storage_entry_sender, storage_entry_receiver) = channel();
|
||||||
let storage_state = StorageState::new();
|
let storage_state = StorageState::new();
|
||||||
|
@ -574,7 +574,7 @@ mod tests {
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||||
|
|
||||||
let cluster_info = test_cluster_info(keypair.pubkey());
|
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||||
|
|
||||||
let (storage_entry_sender, storage_entry_receiver) = channel();
|
let (storage_entry_sender, storage_entry_receiver) = channel();
|
||||||
let storage_state = StorageState::new();
|
let storage_state = StorageState::new();
|
||||||
|
@ -599,7 +599,7 @@ mod tests {
|
||||||
let mut vote_txs: Vec<_> = Vec::new();
|
let mut vote_txs: Vec<_> = Vec::new();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_tx =
|
let vote_tx =
|
||||||
VoteTransaction::new_vote(keypair.pubkey(), &keypair, 123456, Hash::default(), 1);
|
VoteTransaction::new_vote(&keypair.pubkey(), &keypair, 123456, Hash::default(), 1);
|
||||||
vote_txs.push(vote_tx);
|
vote_txs.push(vote_tx);
|
||||||
let vote_entries = vec![Entry::new(&Hash::default(), 1, vote_txs)];
|
let vote_entries = vec![Entry::new(&Hash::default(), 1, vote_txs)];
|
||||||
storage_entry_sender.send(vote_entries).unwrap();
|
storage_entry_sender.send(vote_entries).unwrap();
|
||||||
|
|
|
@ -7,5 +7,5 @@ pub fn test_tx() -> Transaction {
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
SystemTransaction::new_account(&keypair1, pubkey1, 42, zero, 0)
|
SystemTransaction::new_account(&keypair1, &pubkey1, 42, zero, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl ThinClient {
|
||||||
&self,
|
&self,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
blockhash: &Hash,
|
blockhash: &Hash,
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -420,10 +420,10 @@ pub fn new_fullnode() -> (Fullnode, ContactInfo, Keypair, String) {
|
||||||
use solana_sdk::signature::KeypairUtil;
|
use solana_sdk::signature::KeypairUtil;
|
||||||
|
|
||||||
let node_keypair = Arc::new(Keypair::new());
|
let node_keypair = Arc::new(Keypair::new());
|
||||||
let node = Node::new_localhost_with_pubkey(node_keypair.pubkey());
|
let node = Node::new_localhost_with_pubkey(&node_keypair.pubkey());
|
||||||
let contact_info = node.info.clone();
|
let contact_info = node.info.clone();
|
||||||
|
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, contact_info.id, 42);
|
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, &contact_info.id, 42);
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
|
@ -431,7 +431,7 @@ pub fn new_fullnode() -> (Fullnode, ContactInfo, Keypair, String) {
|
||||||
node,
|
node,
|
||||||
&node_keypair,
|
&node_keypair,
|
||||||
&ledger_path,
|
&ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
None,
|
None,
|
||||||
&FullnodeConfig::default(),
|
&FullnodeConfig::default(),
|
||||||
|
@ -467,7 +467,7 @@ mod tests {
|
||||||
info!("test_thin_client blockhash: {:?}", blockhash);
|
info!("test_thin_client blockhash: {:?}", blockhash);
|
||||||
|
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &alice, bob_pubkey, &blockhash)
|
.transfer(500, &alice, &bob_pubkey, &blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
info!("test_thin_client signature: {:?}", signature);
|
info!("test_thin_client signature: {:?}", signature);
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
@ -493,13 +493,13 @@ mod tests {
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, blockhash, 0);
|
let tx = SystemTransaction::new_account(&alice, &bob_pubkey, 500, blockhash, 0);
|
||||||
|
|
||||||
let _sig = client.transfer_signed(&tx).unwrap();
|
let _sig = client.transfer_signed(&tx).unwrap();
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
|
|
||||||
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, blockhash, 0);
|
let mut tr2 = SystemTransaction::new_account(&alice, &bob_pubkey, 501, blockhash, 0);
|
||||||
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
||||||
if let SystemInstruction::Move { ref mut lamports } = instruction2 {
|
if let SystemInstruction::Move { ref mut lamports } = instruction2 {
|
||||||
*lamports = 502;
|
*lamports = 502;
|
||||||
|
@ -526,7 +526,7 @@ mod tests {
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &alice, validator_keypair.pubkey(), &blockhash)
|
.transfer(500, &alice, &validator_keypair.pubkey(), &blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
@ -537,7 +537,7 @@ mod tests {
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
|
|
||||||
let transaction =
|
let transaction =
|
||||||
VoteTransaction::new_account(&validator_keypair, vote_account_id, blockhash, 1, 1);
|
VoteTransaction::new_account(&validator_keypair, &vote_account_id, blockhash, 1, 1);
|
||||||
let signature = client.transfer_signed(&transaction).unwrap();
|
let signature = client.transfer_signed(&transaction).unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
||||||
|
@ -595,7 +595,7 @@ mod tests {
|
||||||
|
|
||||||
info!("Give Bob 500 lamports");
|
info!("Give Bob 500 lamports");
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &alice, bob_keypair.pubkey(), &blockhash)
|
.transfer(500, &alice, &bob_keypair.pubkey(), &blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
||||||
|
@ -604,7 +604,7 @@ mod tests {
|
||||||
|
|
||||||
info!("Take Bob's 500 lamports away");
|
info!("Take Bob's 500 lamports away");
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &bob_keypair, alice.pubkey(), &blockhash)
|
.transfer(500, &bob_keypair, &alice.pubkey(), &blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct Tpu {
|
||||||
|
|
||||||
impl Tpu {
|
impl Tpu {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: Pubkey,
|
id: &Pubkey,
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
poh_recorder: &Arc<Mutex<PohRecorder>>,
|
||||||
entry_receiver: Receiver<WorkingBankEntries>,
|
entry_receiver: Receiver<WorkingBankEntries>,
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl Tvu {
|
||||||
/// * `blocktree` - the ledger itself
|
/// * `blocktree` - the ledger itself
|
||||||
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
|
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
|
||||||
pub fn new<T>(
|
pub fn new<T>(
|
||||||
vote_account: Pubkey,
|
vote_account: &Pubkey,
|
||||||
voting_keypair: Option<Arc<T>>,
|
voting_keypair: Option<Arc<T>>,
|
||||||
bank_forks: &Arc<RwLock<BankForks>>,
|
bank_forks: &Arc<RwLock<BankForks>>,
|
||||||
bank_forks_info: &[BankForksInfo],
|
bank_forks_info: &[BankForksInfo],
|
||||||
|
@ -107,7 +107,7 @@ impl Tvu {
|
||||||
);
|
);
|
||||||
|
|
||||||
let (replay_stage, slot_full_receiver, forward_entry_receiver) = ReplayStage::new(
|
let (replay_stage, slot_full_receiver, forward_entry_receiver) = ReplayStage::new(
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
vote_account,
|
vote_account,
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
blocktree.clone(),
|
blocktree.clone(),
|
||||||
|
@ -183,7 +183,7 @@ pub mod tests {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let leader = Node::new_localhost();
|
let leader = Node::new_localhost();
|
||||||
let target1_keypair = Keypair::new();
|
let target1_keypair = Keypair::new();
|
||||||
let target1 = Node::new_localhost_with_pubkey(target1_keypair.pubkey());
|
let target1 = Node::new_localhost_with_pubkey(&target1_keypair.pubkey());
|
||||||
|
|
||||||
let starting_balance = 10_000;
|
let starting_balance = 10_000;
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(starting_balance);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new(starting_balance);
|
||||||
|
@ -206,7 +206,7 @@ pub mod tests {
|
||||||
let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank);
|
let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank);
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
let tvu = Tvu::new(
|
let tvu = Tvu::new(
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
Some(Arc::new(voting_keypair)),
|
Some(Arc::new(voting_keypair)),
|
||||||
&Arc::new(RwLock::new(bank_forks)),
|
&Arc::new(RwLock::new(bank_forks)),
|
||||||
&bank_forks_info,
|
&bank_forks_info,
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl RemoteVoteSigner {
|
||||||
impl VoteSigner for RemoteVoteSigner {
|
impl VoteSigner for RemoteVoteSigner {
|
||||||
fn register(
|
fn register(
|
||||||
&self,
|
&self,
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
sig: &Signature,
|
sig: &Signature,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> jsonrpc_core::Result<Pubkey> {
|
) -> jsonrpc_core::Result<Pubkey> {
|
||||||
|
@ -35,7 +35,12 @@ impl VoteSigner for RemoteVoteSigner {
|
||||||
let vote_account: Pubkey = serde_json::from_value(resp).unwrap();
|
let vote_account: Pubkey = serde_json::from_value(resp).unwrap();
|
||||||
Ok(vote_account)
|
Ok(vote_account)
|
||||||
}
|
}
|
||||||
fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<Signature> {
|
fn sign(
|
||||||
|
&self,
|
||||||
|
pubkey: &Pubkey,
|
||||||
|
sig: &Signature,
|
||||||
|
msg: &[u8],
|
||||||
|
) -> jsonrpc_core::Result<Signature> {
|
||||||
let params = json!([pubkey, sig, msg]);
|
let params = json!([pubkey, sig, msg]);
|
||||||
let resp = self
|
let resp = self
|
||||||
.rpc_client
|
.rpc_client
|
||||||
|
@ -44,7 +49,7 @@ impl VoteSigner for RemoteVoteSigner {
|
||||||
let vote_signature: Signature = serde_json::from_value(resp).unwrap();
|
let vote_signature: Signature = serde_json::from_value(resp).unwrap();
|
||||||
Ok(vote_signature)
|
Ok(vote_signature)
|
||||||
}
|
}
|
||||||
fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<()> {
|
fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<()> {
|
||||||
let params = json!([pubkey, sig, msg]);
|
let params = json!([pubkey, sig, msg]);
|
||||||
let _resp = self
|
let _resp = self
|
||||||
.rpc_client
|
.rpc_client
|
||||||
|
@ -70,7 +75,9 @@ impl KeypairUtil for VotingKeypair {
|
||||||
|
|
||||||
fn sign_message(&self, msg: &[u8]) -> Signature {
|
fn sign_message(&self, msg: &[u8]) -> Signature {
|
||||||
let sig = self.keypair.sign_message(msg);
|
let sig = self.keypair.sign_message(msg);
|
||||||
self.signer.sign(self.keypair.pubkey(), &sig, &msg).unwrap()
|
self.signer
|
||||||
|
.sign(&self.keypair.pubkey(), &sig, &msg)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +92,7 @@ impl VotingKeypair {
|
||||||
let msg = "Registering a new node";
|
let msg = "Registering a new node";
|
||||||
let sig = keypair.sign_message(msg.as_bytes());
|
let sig = keypair.sign_message(msg.as_bytes());
|
||||||
let vote_account = signer
|
let vote_account = signer
|
||||||
.register(keypair.pubkey(), &sig, msg.as_bytes())
|
.register(&keypair.pubkey(), &sig, msg.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Self {
|
Self {
|
||||||
keypair: keypair.clone(),
|
keypair: keypair.clone(),
|
||||||
|
@ -109,14 +116,14 @@ pub mod tests {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) {
|
) {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = VoteTransaction::new_account(from_keypair, *voting_pubkey, blockhash, lamports, 0);
|
let tx = VoteTransaction::new_account(from_keypair, voting_pubkey, blockhash, lamports, 0);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
|
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx =
|
let tx =
|
||||||
VoteTransaction::new_vote(voting_keypair.pubkey(), voting_keypair, slot, blockhash, 0);
|
VoteTransaction::new_vote(&voting_keypair.pubkey(), voting_keypair, slot, blockhash, 0);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl Drone {
|
||||||
let mut transaction = Transaction::new(
|
let mut transaction = Transaction::new(
|
||||||
&self.mint_keypair,
|
&self.mint_keypair,
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&create_instruction,
|
&create_instruction,
|
||||||
blockhash,
|
blockhash,
|
||||||
0, /*fee*/
|
0, /*fee*/
|
||||||
|
@ -411,7 +411,7 @@ mod tests {
|
||||||
let mut expected_tx = Transaction::new(
|
let mut expected_tx = Transaction::new(
|
||||||
&keypair,
|
&keypair,
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&expected_instruction,
|
&expected_instruction,
|
||||||
blockhash,
|
blockhash,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn test_local_drone() {
|
||||||
let mut expected_tx = Transaction::new(
|
let mut expected_tx = Transaction::new(
|
||||||
&keypair,
|
&keypair,
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&expected_instruction,
|
&expected_instruction,
|
||||||
blockhash,
|
blockhash,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -229,7 +229,7 @@ fn main() {
|
||||||
fullnode_config.blockstream = matches.value_of("blockstream").map(|s| s.to_string());
|
fullnode_config.blockstream = matches.value_of("blockstream").map(|s| s.to_string());
|
||||||
|
|
||||||
let keypair = Arc::new(keypair);
|
let keypair = Arc::new(keypair);
|
||||||
let mut node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr);
|
let mut node = Node::new_with_external_ip(&keypair.pubkey(), &gossip_addr);
|
||||||
node.info.rpc.set_port(rpc_port);
|
node.info.rpc.set_port(rpc_port);
|
||||||
node.info.rpc_pubsub.set_port(rpc_pubsub_port);
|
node.info.rpc_pubsub.set_port(rpc_pubsub_port);
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ fn main() {
|
||||||
node,
|
node,
|
||||||
&keypair,
|
&keypair,
|
||||||
ledger_path,
|
ledger_path,
|
||||||
staking_account,
|
&staking_account,
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
cluster_entrypoint.as_ref(),
|
cluster_entrypoint.as_ref(),
|
||||||
&fullnode_config,
|
&fullnode_config,
|
||||||
|
|
|
@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
||||||
let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
||||||
lamports,
|
lamports,
|
||||||
bootstrap_leader_keypair.pubkey(),
|
&bootstrap_leader_keypair.pubkey(),
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
);
|
);
|
||||||
genesis_block.mint_id = mint_keypair.pubkey();
|
genesis_block.mint_id = mint_keypair.pubkey();
|
||||||
|
|
|
@ -35,7 +35,7 @@ fn bad_arguments() {
|
||||||
#[test]
|
#[test]
|
||||||
fn nominal() {
|
fn nominal() {
|
||||||
let keypair = Arc::new(Keypair::new());
|
let keypair = Arc::new(Keypair::new());
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, &keypair.pubkey(), 50);
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
|
@ -42,11 +42,11 @@ mod bpf {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
let program_id = load_program(&bank, &mint_keypair, bpf_loader::id(), elf);
|
let program_id = load_program(&bank, &mint_keypair, &bpf_loader::id(), elf);
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[],
|
&[],
|
||||||
program_id,
|
&program_id,
|
||||||
&vec![1u8],
|
&vec![1u8],
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -80,16 +80,16 @@ mod bpf {
|
||||||
let loader_id = load_program(
|
let loader_id = load_program(
|
||||||
&bank,
|
&bank,
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
native_loader::id(),
|
&native_loader::id(),
|
||||||
"solana_bpf_loader".as_bytes().to_vec(),
|
"solana_bpf_loader".as_bytes().to_vec(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
let program_id = load_program(&bank, &mint_keypair, loader_id, elf);
|
let program_id = load_program(&bank, &mint_keypair, &loader_id, elf);
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[],
|
&[],
|
||||||
program_id,
|
&program_id,
|
||||||
&vec![1u8],
|
&vec![1u8],
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
@ -126,16 +126,16 @@ mod bpf {
|
||||||
let loader_id = load_program(
|
let loader_id = load_program(
|
||||||
&bank,
|
&bank,
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
native_loader::id(),
|
&native_loader::id(),
|
||||||
"solana_bpf_loader".as_bytes().to_vec(),
|
"solana_bpf_loader".as_bytes().to_vec(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
let program_id = load_program(&bank, &mint_keypair, loader_id, elf);
|
let program_id = load_program(&bank, &mint_keypair, &loader_id, elf);
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[],
|
&[],
|
||||||
program_id,
|
&program_id,
|
||||||
&vec![1u8],
|
&vec![1u8],
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -175,14 +175,14 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_instruction() {
|
fn test_invalid_instruction() {
|
||||||
let mut accounts = vec![Account::new(1, 0, id()), Account::new(0, 512, id())];
|
let mut accounts = vec![Account::new(1, 0, &id()), Account::new(0, 512, &id())];
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let contract = Keypair::new();
|
let contract = Keypair::new();
|
||||||
let userdata = (1u8, 2u8, 3u8);
|
let userdata = (1u8, 2u8, 3u8);
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&from,
|
&from,
|
||||||
&[contract.pubkey()],
|
&[contract.pubkey()],
|
||||||
id(),
|
&id(),
|
||||||
&userdata,
|
&userdata,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
|
@ -192,7 +192,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unsigned_witness_key() {
|
fn test_unsigned_witness_key() {
|
||||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
|
@ -201,9 +201,9 @@ mod test {
|
||||||
let witness = Keypair::new().pubkey();
|
let witness = Keypair::new().pubkey();
|
||||||
let tx = BudgetTransaction::new_when_signed(
|
let tx = BudgetTransaction::new_when_signed(
|
||||||
&from,
|
&from,
|
||||||
to,
|
&to,
|
||||||
contract,
|
&contract,
|
||||||
witness,
|
&witness,
|
||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -212,7 +212,7 @@ mod test {
|
||||||
|
|
||||||
// Attack! Part 1: Sign a witness transaction with a random key.
|
// Attack! Part 1: Sign a witness transaction with a random key.
|
||||||
let rando = Keypair::new();
|
let rando = Keypair::new();
|
||||||
let mut tx = BudgetTransaction::new_signature(&rando, contract, to, Hash::default());
|
let mut tx = BudgetTransaction::new_signature(&rando, &contract, &to, Hash::default());
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
tx.account_keys.push(from.pubkey());
|
tx.account_keys.push(from.pubkey());
|
||||||
|
@ -227,7 +227,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unsigned_timestamp() {
|
fn test_unsigned_timestamp() {
|
||||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
|
@ -236,10 +236,10 @@ mod test {
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = BudgetTransaction::new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to,
|
&to,
|
||||||
contract,
|
&contract,
|
||||||
dt,
|
dt,
|
||||||
from.pubkey(),
|
&from.pubkey(),
|
||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -248,7 +248,7 @@ mod test {
|
||||||
|
|
||||||
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
||||||
let rando = Keypair::new();
|
let rando = Keypair::new();
|
||||||
let mut tx = BudgetTransaction::new_timestamp(&rando, contract, to, dt, Hash::default());
|
let mut tx = BudgetTransaction::new_timestamp(&rando, &contract, &to, dt, Hash::default());
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
tx.account_keys.push(from.pubkey());
|
tx.account_keys.push(from.pubkey());
|
||||||
|
@ -263,7 +263,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_on_date() {
|
fn test_transfer_on_date() {
|
||||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
let to_account = 2;
|
let to_account = 2;
|
||||||
|
@ -274,10 +274,10 @@ mod test {
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = BudgetTransaction::new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
&to.pubkey(),
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
from.pubkey(),
|
&from.pubkey(),
|
||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -291,8 +291,8 @@ mod test {
|
||||||
// Attack! Try to payout to a rando key
|
// Attack! Try to payout to a rando key
|
||||||
let tx = BudgetTransaction::new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
rando.pubkey(),
|
&rando.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
@ -311,8 +311,8 @@ mod test {
|
||||||
// that pubkey's funds are now available.
|
// that pubkey's funds are now available.
|
||||||
let tx = BudgetTransaction::new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
to.pubkey(),
|
&to.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
@ -335,7 +335,7 @@ mod test {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cancel_transfer() {
|
fn test_cancel_transfer() {
|
||||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
let pay_account = 2;
|
let pay_account = 2;
|
||||||
|
@ -345,10 +345,10 @@ mod test {
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = BudgetTransaction::new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
&to.pubkey(),
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
from.pubkey(),
|
&from.pubkey(),
|
||||||
Some(from.pubkey()),
|
Some(from.pubkey()),
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -360,8 +360,12 @@ mod test {
|
||||||
assert!(budget_state.is_pending());
|
assert!(budget_state.is_pending());
|
||||||
|
|
||||||
// Attack! try to put the lamports into the wrong account with cancel
|
// Attack! try to put the lamports into the wrong account with cancel
|
||||||
let tx =
|
let tx = BudgetTransaction::new_signature(
|
||||||
BudgetTransaction::new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default());
|
&to,
|
||||||
|
&contract.pubkey(),
|
||||||
|
&to.pubkey(),
|
||||||
|
Hash::default(),
|
||||||
|
);
|
||||||
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
||||||
// creating more account vectors
|
// creating more account vectors
|
||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
@ -373,8 +377,8 @@ mod test {
|
||||||
// Now, cancel the transaction. from gets her funds back
|
// Now, cancel the transaction. from gets her funds back
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
from.pubkey(),
|
&from.pubkey(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
@ -385,8 +389,8 @@ mod test {
|
||||||
// try to replay the cancel contract
|
// try to replay the cancel contract
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
&contract.pubkey(),
|
||||||
from.pubkey(),
|
&from.pubkey(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -14,7 +14,7 @@ impl<'a> BudgetBank<'a> {
|
||||||
Self { bank }
|
Self { bank }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pay(&self, from_keypair: &Keypair, to_id: Pubkey, lamports: u64) -> Result<()> {
|
fn pay(&self, from_keypair: &Keypair, to_id: &Pubkey, lamports: u64) -> Result<()> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
let tx = BudgetTransaction::new_payment(from_keypair, to_id, lamports, blockhash, 0);
|
let tx = BudgetTransaction::new_payment(from_keypair, to_id, lamports, blockhash, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
|
@ -27,6 +27,6 @@ fn test_budget_payment_via_bank() {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let budget_bank = BudgetBank::new(&bank);
|
let budget_bank = BudgetBank::new(&bank);
|
||||||
let to_id = Keypair::new().pubkey();
|
let to_id = Keypair::new().pubkey();
|
||||||
budget_bank.pay(&from_keypair, to_id, 100).unwrap();
|
budget_bank.pay(&from_keypair, &to_id, 100).unwrap();
|
||||||
assert_eq!(bank.get_balance(&to_id), 100);
|
assert_eq!(bank.get_balance(&to_id), 100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! The `budget_expr` module provides a domain-specific language for payment plans. Users create BudgetExpr objects that
|
//! The `budget_expr` module provides a domain-specific language for pa&yment plans. Users create BudgetExpr objects that
|
||||||
//! are given to an interpreter. The interpreter listens for `Witness` transactions,
|
//! are given to an interpreter. The interpreter listens for `Witness` transactions,
|
||||||
//! which it uses to reduce the payment plan. When the budget is reduced to a
|
//! which it uses to reduce the payment plan. When the budget is reduced to a
|
||||||
//! `Payment`, the payment is executed.
|
//! `Payment`, the payment is executed.
|
||||||
|
@ -52,36 +52,41 @@ pub enum BudgetExpr {
|
||||||
|
|
||||||
impl BudgetExpr {
|
impl BudgetExpr {
|
||||||
/// Create the simplest budget - one that pays `lamports` to Pubkey.
|
/// Create the simplest budget - one that pays `lamports` to Pubkey.
|
||||||
pub fn new_payment(lamports: u64, to: Pubkey) -> Self {
|
pub fn new_payment(lamports: u64, to: &Pubkey) -> Self {
|
||||||
BudgetExpr::Pay(Payment { lamports, to })
|
BudgetExpr::Pay(Payment { lamports, to: *to })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a budget that pays `lamports` to `to` after being witnessed by `from`.
|
/// Create a budget that pays `lamports` to `to` after being witnessed by `from`.
|
||||||
pub fn new_authorized_payment(from: Pubkey, lamports: u64, to: Pubkey) -> Self {
|
pub fn new_authorized_payment(from: &Pubkey, lamports: u64, to: &Pubkey) -> Self {
|
||||||
BudgetExpr::After(
|
BudgetExpr::After(
|
||||||
Condition::Signature(from),
|
Condition::Signature(*from),
|
||||||
Box::new(Self::new_payment(lamports, to)),
|
Box::new(Self::new_payment(lamports, to)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s
|
/// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s
|
||||||
pub fn new_2_2_multisig_payment(
|
pub fn new_2_2_multisig_payment(
|
||||||
from0: Pubkey,
|
from0: &Pubkey,
|
||||||
from1: Pubkey,
|
from1: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
BudgetExpr::And(
|
BudgetExpr::And(
|
||||||
Condition::Signature(from0),
|
Condition::Signature(*from0),
|
||||||
Condition::Signature(from1),
|
Condition::Signature(*from1),
|
||||||
Box::new(Self::new_payment(lamports, to)),
|
Box::new(Self::new_payment(lamports, to)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a budget that pays `lamports` to `to` after the given DateTime.
|
/// Create a budget that pays `lamports` to `to` after the given DateTime.
|
||||||
pub fn new_future_payment(dt: DateTime<Utc>, from: Pubkey, lamports: u64, to: Pubkey) -> Self {
|
pub fn new_future_payment(
|
||||||
|
dt: DateTime<Utc>,
|
||||||
|
from: &Pubkey,
|
||||||
|
lamports: u64,
|
||||||
|
to: &Pubkey,
|
||||||
|
) -> Self {
|
||||||
BudgetExpr::After(
|
BudgetExpr::After(
|
||||||
Condition::Timestamp(dt, from),
|
Condition::Timestamp(dt, *from),
|
||||||
Box::new(Self::new_payment(lamports, to)),
|
Box::new(Self::new_payment(lamports, to)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -90,17 +95,17 @@ impl BudgetExpr {
|
||||||
/// unless cancelled by `from`.
|
/// unless cancelled by `from`.
|
||||||
pub fn new_cancelable_future_payment(
|
pub fn new_cancelable_future_payment(
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
from: Pubkey,
|
from: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::Or(
|
||||||
(
|
(
|
||||||
Condition::Timestamp(dt, from),
|
Condition::Timestamp(dt, *from),
|
||||||
Box::new(Self::new_payment(lamports, to)),
|
Box::new(Self::new_payment(lamports, to)),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Condition::Signature(from),
|
Condition::Signature(*from),
|
||||||
Box::new(Self::new_payment(lamports, to)),
|
Box::new(Self::new_payment(lamports, to)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -183,10 +188,10 @@ mod tests {
|
||||||
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
||||||
let from = Pubkey::default();
|
let from = Pubkey::default();
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
assert!(BudgetExpr::new_payment(42, to).verify(42));
|
assert!(BudgetExpr::new_payment(42, &to).verify(42));
|
||||||
assert!(BudgetExpr::new_authorized_payment(from, 42, to).verify(42));
|
assert!(BudgetExpr::new_authorized_payment(&from, 42, &to).verify(42));
|
||||||
assert!(BudgetExpr::new_future_payment(dt, from, 42, to).verify(42));
|
assert!(BudgetExpr::new_future_payment(dt, &from, 42, &to).verify(42));
|
||||||
assert!(BudgetExpr::new_cancelable_future_payment(dt, from, 42, to).verify(42));
|
assert!(BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to).verify(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -194,9 +199,9 @@ mod tests {
|
||||||
let from = Pubkey::default();
|
let from = Pubkey::default();
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_authorized_payment(from, 42, to);
|
let mut expr = BudgetExpr::new_authorized_payment(&from, 42, &to);
|
||||||
expr.apply_witness(&Witness::Signature, &from);
|
expr.apply_witness(&Witness::Signature, &from);
|
||||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -205,9 +210,9 @@ mod tests {
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to);
|
let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to);
|
||||||
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
||||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -218,7 +223,7 @@ mod tests {
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to);
|
let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to);
|
||||||
let orig_expr = expr.clone();
|
let orig_expr = expr.clone();
|
||||||
expr.apply_witness(&Witness::Timestamp(dt), &to); // <-- Attack!
|
expr.apply_witness(&Witness::Timestamp(dt), &to); // <-- Attack!
|
||||||
assert_eq!(expr, orig_expr);
|
assert_eq!(expr, orig_expr);
|
||||||
|
@ -230,13 +235,13 @@ mod tests {
|
||||||
let from = Pubkey::default();
|
let from = Pubkey::default();
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to);
|
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to);
|
||||||
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
||||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to);
|
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to);
|
||||||
expr.apply_witness(&Witness::Signature, &from);
|
expr.apply_witness(&Witness::Signature, &from);
|
||||||
assert_eq!(expr, BudgetExpr::new_payment(42, from));
|
assert_eq!(expr, BudgetExpr::new_payment(42, &from));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_2_2_multisig_payment() {
|
fn test_2_2_multisig_payment() {
|
||||||
|
@ -244,9 +249,9 @@ mod tests {
|
||||||
let from1 = Keypair::new().pubkey();
|
let from1 = Keypair::new().pubkey();
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let mut expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
let mut expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||||
expr.apply_witness(&Witness::Signature, &from0);
|
expr.apply_witness(&Witness::Signature, &from0);
|
||||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -256,12 +261,12 @@ mod tests {
|
||||||
let from2 = Keypair::new().pubkey();
|
let from2 = Keypair::new().pubkey();
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||||
let mut expr = BudgetExpr::After(Condition::Signature(from2), Box::new(expr));
|
let mut expr = BudgetExpr::After(Condition::Signature(from2), Box::new(expr));
|
||||||
|
|
||||||
expr.apply_witness(&Witness::Signature, &from2);
|
expr.apply_witness(&Witness::Signature, &from2);
|
||||||
expr.apply_witness(&Witness::Signature, &from0);
|
expr.apply_witness(&Witness::Signature, &from0);
|
||||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -271,16 +276,16 @@ mod tests {
|
||||||
let dt = Utc.ymd(2014, 11, 11).and_hms(7, 7, 7);
|
let dt = Utc.ymd(2014, 11, 11).and_hms(7, 7, 7);
|
||||||
let to = Pubkey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||||
let mut expr = BudgetExpr::After(Condition::Timestamp(dt, from0), Box::new(expr));
|
let mut expr = BudgetExpr::After(Condition::Timestamp(dt, from0), Box::new(expr));
|
||||||
|
|
||||||
expr.apply_witness(&Witness::Timestamp(dt), &from0);
|
expr.apply_witness(&Witness::Timestamp(dt), &from0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expr,
|
expr,
|
||||||
BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to)
|
BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to)
|
||||||
);
|
);
|
||||||
|
|
||||||
expr.apply_witness(&Witness::Signature, &from0);
|
expr.apply_witness(&Witness::Signature, &from0);
|
||||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,32 +28,36 @@ pub enum BudgetInstruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BudgetInstruction {
|
impl BudgetInstruction {
|
||||||
pub fn new_initialize_account(contract: Pubkey, expr: BudgetExpr) -> BuilderInstruction {
|
pub fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> BuilderInstruction {
|
||||||
let mut keys = vec![];
|
let mut keys = vec![];
|
||||||
if let BudgetExpr::Pay(payment) = &expr {
|
if let BudgetExpr::Pay(payment) = &expr {
|
||||||
keys.push((payment.to, false));
|
keys.push((payment.to, false));
|
||||||
}
|
}
|
||||||
keys.push((contract, false));
|
keys.push((*contract, false));
|
||||||
BuilderInstruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
BuilderInstruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_apply_timestamp(
|
pub fn new_apply_timestamp(
|
||||||
from: Pubkey,
|
from: &Pubkey,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
) -> BuilderInstruction {
|
) -> BuilderInstruction {
|
||||||
let mut keys = vec![(from, true), (contract, false)];
|
let mut keys = vec![(*from, true), (*contract, false)];
|
||||||
if from != to {
|
if from != to {
|
||||||
keys.push((to, false));
|
keys.push((*to, false));
|
||||||
}
|
}
|
||||||
BuilderInstruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
|
BuilderInstruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_apply_signature(from: Pubkey, contract: Pubkey, to: Pubkey) -> BuilderInstruction {
|
pub fn new_apply_signature(
|
||||||
let mut keys = vec![(from, true), (contract, false)];
|
from: &Pubkey,
|
||||||
|
contract: &Pubkey,
|
||||||
|
to: &Pubkey,
|
||||||
|
) -> BuilderInstruction {
|
||||||
|
let mut keys = vec![(*from, true), (*contract, false)];
|
||||||
if from != to {
|
if from != to {
|
||||||
keys.push((to, false));
|
keys.push((*to, false));
|
||||||
}
|
}
|
||||||
BuilderInstruction::new(id(), &BudgetInstruction::ApplySignature, keys)
|
BuilderInstruction::new(id(), &BudgetInstruction::ApplySignature, keys)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer() {
|
fn test_serializer() {
|
||||||
let mut a = Account::new(0, 512, id());
|
let mut a = Account::new(0, 512, &id());
|
||||||
let b = BudgetState::default();
|
let b = BudgetState::default();
|
||||||
b.serialize(&mut a.userdata).unwrap();
|
b.serialize(&mut a.userdata).unwrap();
|
||||||
let c = BudgetState::deserialize(&a.userdata).unwrap();
|
let c = BudgetState::deserialize(&a.userdata).unwrap();
|
||||||
|
@ -63,7 +63,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer_userdata_too_small() {
|
fn test_serializer_userdata_too_small() {
|
||||||
let mut a = Account::new(0, 1, id());
|
let mut a = Account::new(0, 1, &id());
|
||||||
let b = BudgetState::default();
|
let b = BudgetState::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
b.serialize(&mut a.userdata),
|
b.serialize(&mut a.userdata),
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl BudgetTransaction {
|
||||||
#[allow(clippy::new_ret_no_self)]
|
#[allow(clippy::new_ret_no_self)]
|
||||||
fn new(
|
fn new(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
expr: BudgetExpr,
|
expr: BudgetExpr,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
|
@ -30,11 +30,11 @@ impl BudgetTransaction {
|
||||||
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(SystemInstruction::new_program_account(
|
.push(SystemInstruction::new_program_account(
|
||||||
from,
|
&from,
|
||||||
contract,
|
contract,
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
id(),
|
&id(),
|
||||||
))
|
))
|
||||||
.push(BudgetInstruction::new_initialize_account(contract, expr))
|
.push(BudgetInstruction::new_initialize_account(contract, expr))
|
||||||
.sign(&[from_keypair], recent_blockhash)
|
.sign(&[from_keypair], recent_blockhash)
|
||||||
|
@ -43,7 +43,7 @@ impl BudgetTransaction {
|
||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// Create and sign a new Transaction. Used for unit-testing.
|
||||||
pub fn new_payment(
|
pub fn new_payment(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -52,7 +52,7 @@ impl BudgetTransaction {
|
||||||
let expr = BudgetExpr::new_payment(lamports, to);
|
let expr = BudgetExpr::new_payment(lamports, to);
|
||||||
Self::new(
|
Self::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
contract,
|
&contract,
|
||||||
expr,
|
expr,
|
||||||
lamports,
|
lamports,
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
|
@ -63,15 +63,15 @@ impl BudgetTransaction {
|
||||||
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
||||||
pub fn new_timestamp(
|
pub fn new_timestamp(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from = from_keypair.pubkey();
|
let from = from_keypair.pubkey();
|
||||||
TransactionBuilder::default()
|
TransactionBuilder::default()
|
||||||
.push(BudgetInstruction::new_apply_timestamp(
|
.push(BudgetInstruction::new_apply_timestamp(
|
||||||
from, contract, to, dt,
|
&from, contract, to, dt,
|
||||||
))
|
))
|
||||||
.sign(&[from_keypair], recent_blockhash)
|
.sign(&[from_keypair], recent_blockhash)
|
||||||
}
|
}
|
||||||
|
@ -79,23 +79,23 @@ impl BudgetTransaction {
|
||||||
/// Create and sign a new Witness Signature. Used for unit-testing.
|
/// Create and sign a new Witness Signature. Used for unit-testing.
|
||||||
pub fn new_signature(
|
pub fn new_signature(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from = from_keypair.pubkey();
|
let from = from_keypair.pubkey();
|
||||||
TransactionBuilder::default()
|
TransactionBuilder::default()
|
||||||
.push(BudgetInstruction::new_apply_signature(from, contract, to))
|
.push(BudgetInstruction::new_apply_signature(&from, contract, to))
|
||||||
.sign(&[from_keypair], recent_blockhash)
|
.sign(&[from_keypair], recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a postdated Transaction. Used for unit-testing.
|
/// Create and sign a postdated Transaction. Used for unit-testing.
|
||||||
pub fn new_on_date(
|
pub fn new_on_date(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
dt_pubkey: Pubkey,
|
dt_pubkey: &Pubkey,
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
|
@ -103,17 +103,17 @@ impl BudgetTransaction {
|
||||||
let expr = if let Some(from) = cancelable {
|
let expr = if let Some(from) = cancelable {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::Or(
|
||||||
(
|
(
|
||||||
Condition::Timestamp(dt, dt_pubkey),
|
Condition::Timestamp(dt, *dt_pubkey),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Condition::Signature(from),
|
Condition::Signature(from),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, from)),
|
Box::new(BudgetExpr::new_payment(lamports, &from)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BudgetExpr::After(
|
BudgetExpr::After(
|
||||||
Condition::Timestamp(dt, dt_pubkey),
|
Condition::Timestamp(dt, *dt_pubkey),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -123,9 +123,9 @@ impl BudgetTransaction {
|
||||||
/// Create and sign a multisig Transaction.
|
/// Create and sign a multisig Transaction.
|
||||||
pub fn new_when_signed(
|
pub fn new_when_signed(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
contract: Pubkey,
|
contract: &Pubkey,
|
||||||
witness: Pubkey,
|
witness: &Pubkey,
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
|
@ -133,17 +133,17 @@ impl BudgetTransaction {
|
||||||
let expr = if let Some(from) = cancelable {
|
let expr = if let Some(from) = cancelable {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::Or(
|
||||||
(
|
(
|
||||||
Condition::Signature(witness),
|
Condition::Signature(*witness),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Condition::Signature(from),
|
Condition::Signature(from),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, from)),
|
Box::new(BudgetExpr::new_payment(lamports, &from)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BudgetExpr::After(
|
BudgetExpr::After(
|
||||||
Condition::Signature(witness),
|
Condition::Signature(*witness),
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -184,7 +184,7 @@ mod tests {
|
||||||
fn test_claim() {
|
fn test_claim() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let tx0 = BudgetTransaction::new_payment(&keypair, keypair.pubkey(), 42, zero, 0);
|
let tx0 = BudgetTransaction::new_payment(&keypair, &keypair.pubkey(), 42, zero, 0);
|
||||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ mod tests {
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0);
|
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0);
|
||||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ mod tests {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let pubkey1 = Keypair::new().pubkey();
|
let pubkey1 = Keypair::new().pubkey();
|
||||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1);
|
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1);
|
||||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ mod tests {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let pubkey1 = Keypair::new().pubkey();
|
let pubkey1 = Keypair::new().pubkey();
|
||||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1);
|
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1);
|
||||||
let buf = serialize(&tx0).unwrap();
|
let buf = serialize(&tx0).unwrap();
|
||||||
let tx1: Transaction = deserialize(&buf).unwrap();
|
let tx1: Transaction = deserialize(&buf).unwrap();
|
||||||
assert_eq!(tx1, tx0);
|
assert_eq!(tx1, tx0);
|
||||||
|
@ -223,7 +223,7 @@ mod tests {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let mut tx = BudgetTransaction::new_payment(&keypair, pubkey, 42, zero, 0);
|
let mut tx = BudgetTransaction::new_payment(&keypair, &pubkey, 42, zero, 0);
|
||||||
let mut system_instruction = BudgetTransaction::system_instruction(&tx, 0).unwrap();
|
let mut system_instruction = BudgetTransaction::system_instruction(&tx, 0).unwrap();
|
||||||
if let SystemInstruction::CreateAccount {
|
if let SystemInstruction::CreateAccount {
|
||||||
ref mut lamports, ..
|
ref mut lamports, ..
|
||||||
|
@ -250,7 +250,7 @@ mod tests {
|
||||||
let thief_keypair = Keypair::new();
|
let thief_keypair = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let mut tx = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0);
|
let mut tx = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0);
|
||||||
let mut instruction = BudgetTransaction::instruction(&tx, 1);
|
let mut instruction = BudgetTransaction::instruction(&tx, 1);
|
||||||
if let Some(BudgetInstruction::InitializeAccount(ref mut expr)) = instruction {
|
if let Some(BudgetInstruction::InitializeAccount(ref mut expr)) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
|
@ -267,7 +267,7 @@ mod tests {
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let mut tx = BudgetTransaction::new_payment(&keypair0, keypair1.pubkey(), 1, zero, 0);
|
let mut tx = BudgetTransaction::new_payment(&keypair0, &keypair1.pubkey(), 1, zero, 0);
|
||||||
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
||||||
if let BudgetInstruction::InitializeAccount(ref mut expr) = instruction {
|
if let BudgetInstruction::InitializeAccount(ref mut expr) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
|
|
|
@ -12,13 +12,13 @@ fn test_program_native_failure() {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let program = "failure".as_bytes().to_vec();
|
let program = "failure".as_bytes().to_vec();
|
||||||
let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program);
|
let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[],
|
&[],
|
||||||
program_id,
|
&program_id,
|
||||||
&1u8,
|
&1u8,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -12,13 +12,13 @@ fn test_program_native_noop() {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let program = "noop".as_bytes().to_vec();
|
let program = "noop".as_bytes().to_vec();
|
||||||
let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program);
|
let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[],
|
&[],
|
||||||
program_id,
|
&program_id,
|
||||||
&1u8,
|
&1u8,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -92,7 +92,7 @@ mod tests {
|
||||||
|
|
||||||
fn create_rewards_account(lamports: u64) -> Account {
|
fn create_rewards_account(lamports: u64) -> Account {
|
||||||
let space = RewardsState::max_size();
|
let space = RewardsState::max_size();
|
||||||
Account::new(lamports, space, solana_rewards_api::id())
|
Account::new(lamports, space, &solana_rewards_api::id())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redeem_vote_credits_(
|
fn redeem_vote_credits_(
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl<'a> RewardsBank<'a> {
|
||||||
fn create_rewards_account(
|
fn create_rewards_account(
|
||||||
&self,
|
&self,
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
rewards_id: Pubkey,
|
rewards_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
|
@ -31,7 +31,7 @@ impl<'a> RewardsBank<'a> {
|
||||||
fn create_vote_account(
|
fn create_vote_account(
|
||||||
&self,
|
&self,
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
vote_id: Pubkey,
|
vote_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
|
@ -41,7 +41,7 @@ impl<'a> RewardsBank<'a> {
|
||||||
|
|
||||||
fn submit_vote(
|
fn submit_vote(
|
||||||
&self,
|
&self,
|
||||||
staking_account: Pubkey,
|
staking_account: &Pubkey,
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
) -> Result<VoteState> {
|
) -> Result<VoteState> {
|
||||||
|
@ -55,7 +55,7 @@ impl<'a> RewardsBank<'a> {
|
||||||
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
fn redeem_credits(&self, rewards_id: &Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, blockhash, 0);
|
let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, blockhash, 0);
|
||||||
self.bank.process_transaction(&tx)?;
|
self.bank.process_transaction(&tx)?;
|
||||||
|
@ -74,26 +74,26 @@ fn test_redeem_vote_credits_via_bank() {
|
||||||
let rewards_keypair = Keypair::new();
|
let rewards_keypair = Keypair::new();
|
||||||
let rewards_id = rewards_keypair.pubkey();
|
let rewards_id = rewards_keypair.pubkey();
|
||||||
rewards_bank
|
rewards_bank
|
||||||
.create_rewards_account(&from_keypair, rewards_id, 100)
|
.create_rewards_account(&from_keypair, &rewards_id, 100)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// A staker create a vote account account and delegates a validator to vote on its behalf.
|
// A staker create a vote account account and delegates a validator to vote on its behalf.
|
||||||
let vote_keypair = Keypair::new();
|
let vote_keypair = Keypair::new();
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
rewards_bank
|
rewards_bank
|
||||||
.create_vote_account(&from_keypair, vote_id, 100)
|
.create_vote_account(&from_keypair, &vote_id, 100)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// The validator submits votes to accumulate credits.
|
// The validator submits votes to accumulate credits.
|
||||||
for i in 0..vote_state::MAX_LOCKOUT_HISTORY {
|
for i in 0..vote_state::MAX_LOCKOUT_HISTORY {
|
||||||
let vote_state = rewards_bank
|
let vote_state = rewards_bank
|
||||||
.submit_vote(vote_id, &vote_keypair, i as u64)
|
.submit_vote(&vote_id, &vote_keypair, i as u64)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(vote_state.credits(), 0);
|
assert_eq!(vote_state.credits(), 0);
|
||||||
}
|
}
|
||||||
let vote_state = rewards_bank
|
let vote_state = rewards_bank
|
||||||
.submit_vote(
|
.submit_vote(
|
||||||
vote_id,
|
&vote_id,
|
||||||
&vote_keypair,
|
&vote_keypair,
|
||||||
vote_state::MAX_LOCKOUT_HISTORY as u64 + 1,
|
vote_state::MAX_LOCKOUT_HISTORY as u64 + 1,
|
||||||
)
|
)
|
||||||
|
@ -108,7 +108,7 @@ fn test_redeem_vote_credits_via_bank() {
|
||||||
// Periodically, the staker sumbits its vote account to the rewards pool
|
// Periodically, the staker sumbits its vote account to the rewards pool
|
||||||
// to exchange its credits for lamports.
|
// to exchange its credits for lamports.
|
||||||
let vote_state = rewards_bank
|
let vote_state = rewards_bank
|
||||||
.redeem_credits(rewards_id, &vote_keypair)
|
.redeem_credits(&rewards_id, &vote_keypair)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(bank.get_balance(&to_id) > to_lamports);
|
assert!(bank.get_balance(&to_id) > to_lamports);
|
||||||
assert_eq!(vote_state.credits(), 0);
|
assert_eq!(vote_state.credits(), 0);
|
||||||
|
|
|
@ -9,11 +9,11 @@ pub enum RewardsInstruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RewardsInstruction {
|
impl RewardsInstruction {
|
||||||
pub fn new_redeem_vote_credits(vote_id: Pubkey, rewards_id: Pubkey) -> BuilderInstruction {
|
pub fn new_redeem_vote_credits(vote_id: &Pubkey, rewards_id: &Pubkey) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
id(),
|
id(),
|
||||||
&RewardsInstruction::RedeemVoteCredits,
|
&RewardsInstruction::RedeemVoteCredits,
|
||||||
vec![(vote_id, true), (rewards_id, false)],
|
vec![(*vote_id, true), (*rewards_id, false)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct RewardsTransaction {}
|
||||||
impl RewardsTransaction {
|
impl RewardsTransaction {
|
||||||
pub fn new_account(
|
pub fn new_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
rewards_id: Pubkey,
|
rewards_id: &Pubkey,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -28,23 +28,23 @@ impl RewardsTransaction {
|
||||||
blockhash,
|
blockhash,
|
||||||
lamports,
|
lamports,
|
||||||
RewardsState::max_size() as u64,
|
RewardsState::max_size() as u64,
|
||||||
id(),
|
&id(),
|
||||||
fee,
|
fee,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_redeem_credits(
|
pub fn new_redeem_credits(
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
rewards_id: Pubkey,
|
rewards_id: &Pubkey,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(RewardsInstruction::new_redeem_vote_credits(
|
.push(RewardsInstruction::new_redeem_vote_credits(
|
||||||
vote_id, rewards_id,
|
&vote_id, rewards_id,
|
||||||
))
|
))
|
||||||
.push(VoteInstruction::new_clear_credits(vote_id))
|
.push(VoteInstruction::new_clear_credits(&vote_id))
|
||||||
.sign(&[vote_keypair], blockhash)
|
.sign(&[vote_keypair], blockhash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_storage_api::{StorageTransaction, ENTRIES_PER_SEGMENT};
|
use solana_storage_api::{StorageTransaction, ENTRIES_PER_SEGMENT};
|
||||||
|
|
||||||
fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 {
|
fn get_storage_entry_height(bank: &Bank, account: &Pubkey) -> u64 {
|
||||||
match bank.get_account(&account) {
|
match bank.get_account(&account) {
|
||||||
Some(storage_system_account) => {
|
Some(storage_system_account) => {
|
||||||
let state = deserialize(&storage_system_account.userdata);
|
let state = deserialize(&storage_system_account.userdata);
|
||||||
|
@ -24,7 +24,7 @@ fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_storage_blockhash(bank: &Bank, account: Pubkey) -> Hash {
|
fn get_storage_blockhash(bank: &Bank, account: &Pubkey) -> Hash {
|
||||||
if let Some(storage_system_account) = bank.get_account(&account) {
|
if let Some(storage_system_account) = bank.get_account(&account) {
|
||||||
let state = deserialize(&storage_system_account.userdata);
|
let state = deserialize(&storage_system_account.userdata);
|
||||||
if let Ok(state) = state {
|
if let Ok(state) = state {
|
||||||
|
@ -51,18 +51,20 @@ fn test_bank_storage() {
|
||||||
|
|
||||||
bank.register_tick(&blockhash);
|
bank.register_tick(&blockhash);
|
||||||
|
|
||||||
bank.transfer(10, &alice, jill.pubkey(), blockhash).unwrap();
|
bank.transfer(10, &alice, &jill.pubkey(), blockhash)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
bank.transfer(10, &alice, bob.pubkey(), blockhash).unwrap();
|
bank.transfer(10, &alice, &bob.pubkey(), blockhash).unwrap();
|
||||||
bank.transfer(10, &alice, jack.pubkey(), blockhash).unwrap();
|
bank.transfer(10, &alice, &jack.pubkey(), blockhash)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
bob.pubkey(),
|
&bob.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
4 * 1024,
|
4 * 1024,
|
||||||
solana_storage_api::id(),
|
&solana_storage_api::id(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -90,11 +92,11 @@ fn test_bank_storage() {
|
||||||
//let _result = bank.process_transaction(&tx).unwrap();
|
//let _result = bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_storage_entry_height(&bank, bob.pubkey()),
|
get_storage_entry_height(&bank, &bob.pubkey()),
|
||||||
ENTRIES_PER_SEGMENT
|
ENTRIES_PER_SEGMENT
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_storage_blockhash(&bank, bob.pubkey()),
|
get_storage_blockhash(&bank, &bob.pubkey()),
|
||||||
storage_blockhash
|
storage_blockhash
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl StorageTransaction {
|
||||||
entry_height,
|
entry_height,
|
||||||
signature,
|
signature,
|
||||||
};
|
};
|
||||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_advertise_recent_blockhash(
|
pub fn new_advertise_recent_blockhash(
|
||||||
|
@ -103,7 +103,7 @@ impl StorageTransaction {
|
||||||
hash: storage_hash,
|
hash: storage_hash,
|
||||||
entry_height,
|
entry_height,
|
||||||
};
|
};
|
||||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_proof_validation(
|
pub fn new_proof_validation(
|
||||||
|
@ -116,7 +116,7 @@ impl StorageTransaction {
|
||||||
entry_height,
|
entry_height,
|
||||||
proof_mask,
|
proof_mask,
|
||||||
};
|
};
|
||||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_reward_claim(
|
pub fn new_reward_claim(
|
||||||
|
@ -125,6 +125,6 @@ impl StorageTransaction {
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program = StorageProgram::ClaimStorageReward { entry_height };
|
let program = StorageProgram::ClaimStorageReward { entry_height };
|
||||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn create_system_account(
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
space: u64,
|
space: u64,
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Result<(), SystemError> {
|
) -> Result<(), SystemError> {
|
||||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||||
info!("CreateAccount: invalid account[from] owner");
|
info!("CreateAccount: invalid account[from] owner");
|
||||||
|
@ -44,7 +44,7 @@ fn create_system_account(
|
||||||
}
|
}
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.owner = program_id;
|
keyed_accounts[TO_ACCOUNT_INDEX].account.owner = *program_id;
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.userdata = vec![0; space as usize];
|
keyed_accounts[TO_ACCOUNT_INDEX].account.userdata = vec![0; space as usize];
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.executable = false;
|
keyed_accounts[TO_ACCOUNT_INDEX].account.executable = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -52,12 +52,12 @@ fn create_system_account(
|
||||||
|
|
||||||
fn assign_account_to_program(
|
fn assign_account_to_program(
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Result<(), ProgramError> {
|
) -> Result<(), ProgramError> {
|
||||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||||
Err(ProgramError::AssignOfUnownedAccount)?;
|
Err(ProgramError::AssignOfUnownedAccount)?;
|
||||||
}
|
}
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = program_id;
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = *program_id;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn move_lamports(keyed_accounts: &mut [KeyedAccount], lamports: u64) -> Result<(), ProgramError> {
|
fn move_lamports(keyed_accounts: &mut [KeyedAccount], lamports: u64) -> Result<(), ProgramError> {
|
||||||
|
@ -94,7 +94,7 @@ pub fn entrypoint(
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
program_id,
|
program_id,
|
||||||
} => create_system_account(keyed_accounts, lamports, space, program_id).map_err(|e| {
|
} => create_system_account(keyed_accounts, lamports, space, &program_id).map_err(|e| {
|
||||||
match e {
|
match e {
|
||||||
SystemError::AccountAlreadyInUse => ProgramError::InvalidArgument,
|
SystemError::AccountAlreadyInUse => ProgramError::InvalidArgument,
|
||||||
SystemError::ResultWithNegativeLamports => {
|
SystemError::ResultWithNegativeLamports => {
|
||||||
|
@ -104,7 +104,7 @@ pub fn entrypoint(
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
SystemInstruction::Assign { program_id } => {
|
SystemInstruction::Assign { program_id } => {
|
||||||
assign_account_to_program(keyed_accounts, program_id)
|
assign_account_to_program(keyed_accounts, &program_id)
|
||||||
}
|
}
|
||||||
SystemInstruction::Move { lamports } => move_lamports(keyed_accounts, lamports),
|
SystemInstruction::Move { lamports } => move_lamports(keyed_accounts, lamports),
|
||||||
}
|
}
|
||||||
|
@ -124,16 +124,16 @@ mod tests {
|
||||||
fn test_create_system_account() {
|
fn test_create_system_account() {
|
||||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
|
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||||
|
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
];
|
];
|
||||||
create_system_account(&mut keyed_accounts, 50, 2, new_program_owner).unwrap();
|
create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner).unwrap();
|
||||||
let from_lamports = from_account.lamports;
|
let from_lamports = from_account.lamports;
|
||||||
let to_lamports = to_account.lamports;
|
let to_lamports = to_account.lamports;
|
||||||
let to_owner = to_account.owner;
|
let to_owner = to_account.owner;
|
||||||
|
@ -149,17 +149,17 @@ mod tests {
|
||||||
// Attempt to create account with more lamports than remaining in from_account
|
// Attempt to create account with more lamports than remaining in from_account
|
||||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
|
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||||
let unchanged_account = to_account.clone();
|
let unchanged_account = to_account.clone();
|
||||||
|
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
];
|
];
|
||||||
let result = create_system_account(&mut keyed_accounts, 150, 2, new_program_owner);
|
let result = create_system_account(&mut keyed_accounts, 150, 2, &new_program_owner);
|
||||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports));
|
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports));
|
||||||
let from_lamports = from_account.lamports;
|
let from_lamports = from_account.lamports;
|
||||||
assert_eq!(from_lamports, 100);
|
assert_eq!(from_lamports, 100);
|
||||||
|
@ -171,18 +171,18 @@ mod tests {
|
||||||
// Attempt to create system account in account already owned by another program
|
// Attempt to create system account in account already owned by another program
|
||||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
|
|
||||||
let original_program_owner = Pubkey::new(&[5; 32]);
|
let original_program_owner = Pubkey::new(&[5; 32]);
|
||||||
let owned_key = Keypair::new().pubkey();
|
let owned_key = Keypair::new().pubkey();
|
||||||
let mut owned_account = Account::new(0, 0, original_program_owner);
|
let mut owned_account = Account::new(0, 0, &original_program_owner);
|
||||||
let unchanged_account = owned_account.clone();
|
let unchanged_account = owned_account.clone();
|
||||||
|
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&owned_key, false, &mut owned_account),
|
KeyedAccount::new(&owned_key, false, &mut owned_account),
|
||||||
];
|
];
|
||||||
let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner);
|
let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
||||||
let from_lamports = from_account.lamports;
|
let from_lamports = from_account.lamports;
|
||||||
assert_eq!(from_lamports, 100);
|
assert_eq!(from_lamports, 100);
|
||||||
|
@ -194,7 +194,7 @@ mod tests {
|
||||||
// Attempt to create system account in account with populated userdata
|
// Attempt to create system account in account with populated userdata
|
||||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
|
|
||||||
let populated_key = Keypair::new().pubkey();
|
let populated_key = Keypair::new().pubkey();
|
||||||
let mut populated_account = Account {
|
let mut populated_account = Account {
|
||||||
|
@ -209,7 +209,7 @@ mod tests {
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&populated_key, false, &mut populated_account),
|
KeyedAccount::new(&populated_key, false, &mut populated_account),
|
||||||
];
|
];
|
||||||
let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner);
|
let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
||||||
assert_eq!(from_account.lamports, 100);
|
assert_eq!(from_account.lamports, 100);
|
||||||
assert_eq!(populated_account, unchanged_account);
|
assert_eq!(populated_account, unchanged_account);
|
||||||
|
@ -220,14 +220,14 @@ mod tests {
|
||||||
let other_program = Pubkey::new(&[9; 32]);
|
let other_program = Pubkey::new(&[9; 32]);
|
||||||
|
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, other_program);
|
let mut from_account = Account::new(100, 0, &other_program);
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
];
|
];
|
||||||
let result = create_system_account(&mut keyed_accounts, 50, 2, other_program);
|
let result = create_system_account(&mut keyed_accounts, 50, 2, &other_program);
|
||||||
assert_eq!(result, Err(SystemError::SourceNotSystemAccount));
|
assert_eq!(result, Err(SystemError::SourceNotSystemAccount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,16 +236,16 @@ mod tests {
|
||||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||||
|
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
let mut keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
let mut keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
||||||
assign_account_to_program(&mut keyed_accounts, new_program_owner).unwrap();
|
assign_account_to_program(&mut keyed_accounts, &new_program_owner).unwrap();
|
||||||
let from_owner = from_account.owner;
|
let from_owner = from_account.owner;
|
||||||
assert_eq!(from_owner, new_program_owner);
|
assert_eq!(from_owner, new_program_owner);
|
||||||
|
|
||||||
// Attempt to assign account not owned by system program
|
// Attempt to assign account not owned by system program
|
||||||
let another_program_owner = Pubkey::new(&[8; 32]);
|
let another_program_owner = Pubkey::new(&[8; 32]);
|
||||||
keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
||||||
let result = assign_account_to_program(&mut keyed_accounts, another_program_owner);
|
let result = assign_account_to_program(&mut keyed_accounts, &another_program_owner);
|
||||||
assert_eq!(result, Err(ProgramError::AssignOfUnownedAccount));
|
assert_eq!(result, Err(ProgramError::AssignOfUnownedAccount));
|
||||||
assert_eq!(from_account.owner, new_program_owner);
|
assert_eq!(from_account.owner, new_program_owner);
|
||||||
}
|
}
|
||||||
|
@ -253,9 +253,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_lamports() {
|
fn test_move_lamports() {
|
||||||
let from = Keypair::new().pubkey();
|
let from = Keypair::new().pubkey();
|
||||||
let mut from_account = Account::new(100, 0, Pubkey::new(&[2; 32])); // account owner should not matter
|
let mut from_account = Account::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let mut to_account = Account::new(1, 0, Pubkey::new(&[3; 32])); // account owner should not matter
|
let mut to_account = Account::new(1, 0, &Pubkey::new(&[3; 32])); // account owner should not matter
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
|
|
|
@ -27,8 +27,8 @@ fn test_system_unsigned_transaction() {
|
||||||
let blockhash = system_bank.bank.last_blockhash();
|
let blockhash = system_bank.bank.last_blockhash();
|
||||||
let tx = TransactionBuilder::default()
|
let tx = TransactionBuilder::default()
|
||||||
.push(SystemInstruction::new_move(
|
.push(SystemInstruction::new_move(
|
||||||
from_keypair.pubkey(),
|
&from_keypair.pubkey(),
|
||||||
to_keypair.pubkey(),
|
&to_keypair.pubkey(),
|
||||||
50,
|
50,
|
||||||
))
|
))
|
||||||
.sign(&[&from_keypair], blockhash);
|
.sign(&[&from_keypair], blockhash);
|
||||||
|
|
|
@ -25,10 +25,10 @@ fn entrypoint(
|
||||||
match deserialize(data).map_err(|_| ProgramError::InvalidUserdata)? {
|
match deserialize(data).map_err(|_| ProgramError::InvalidUserdata)? {
|
||||||
VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts),
|
VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts),
|
||||||
VoteInstruction::DelegateStake(delegate_id) => {
|
VoteInstruction::DelegateStake(delegate_id) => {
|
||||||
vote_state::delegate_stake(keyed_accounts, delegate_id)
|
vote_state::delegate_stake(keyed_accounts, &delegate_id)
|
||||||
}
|
}
|
||||||
VoteInstruction::AuthorizeVoter(voter_id) => {
|
VoteInstruction::AuthorizeVoter(voter_id) => {
|
||||||
vote_state::authorize_voter(keyed_accounts, voter_id)
|
vote_state::authorize_voter(keyed_accounts, &voter_id)
|
||||||
}
|
}
|
||||||
VoteInstruction::Vote(vote) => {
|
VoteInstruction::Vote(vote) => {
|
||||||
debug!("{:?} by {}", vote, keyed_accounts[0].signer_key().unwrap());
|
debug!("{:?} by {}", vote, keyed_accounts[0].signer_key().unwrap());
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl<'a> VoteBank<'a> {
|
||||||
fn create_vote_account(
|
fn create_vote_account(
|
||||||
&self,
|
&self,
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
vote_id: Pubkey,
|
vote_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
|
@ -36,7 +36,7 @@ impl<'a> VoteBank<'a> {
|
||||||
&self,
|
&self,
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
delegate_id: Pubkey,
|
delegate_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let blockhash = self.bank.last_blockhash();
|
let blockhash = self.bank.last_blockhash();
|
||||||
|
@ -53,7 +53,7 @@ impl<'a> VoteBank<'a> {
|
||||||
|
|
||||||
fn submit_vote(
|
fn submit_vote(
|
||||||
&self,
|
&self,
|
||||||
staking_account: Pubkey,
|
staking_account: &Pubkey,
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
) -> Result<VoteState> {
|
) -> Result<VoteState> {
|
||||||
|
@ -77,10 +77,10 @@ fn test_vote_bank_basic() {
|
||||||
let vote_keypair = Keypair::new();
|
let vote_keypair = Keypair::new();
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
vote_bank
|
vote_bank
|
||||||
.create_vote_account(&from_keypair, vote_id, 100)
|
.create_vote_account(&from_keypair, &vote_id, 100)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let vote_state = vote_bank.submit_vote(vote_id, &vote_keypair, 0).unwrap();
|
let vote_state = vote_bank.submit_vote(&vote_id, &vote_keypair, 0).unwrap();
|
||||||
assert_eq!(vote_state.votes.len(), 1);
|
assert_eq!(vote_state.votes.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ fn test_vote_bank_delegate() {
|
||||||
let delegate_keypair = Keypair::new();
|
let delegate_keypair = Keypair::new();
|
||||||
let delegate_id = delegate_keypair.pubkey();
|
let delegate_id = delegate_keypair.pubkey();
|
||||||
vote_bank
|
vote_bank
|
||||||
.create_vote_account_with_delegate(&from_keypair, &vote_keypair, delegate_id, 100)
|
.create_vote_account_with_delegate(&from_keypair, &vote_keypair, &delegate_id, 100)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||||
let vote_keypair = Keypair::new();
|
let vote_keypair = Keypair::new();
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
vote_bank
|
vote_bank
|
||||||
.create_vote_account(&mallory_keypair, vote_id, 100)
|
.create_vote_account(&mallory_keypair, &vote_id, 100)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mallory_id = mallory_keypair.pubkey();
|
let mallory_id = mallory_keypair.pubkey();
|
||||||
|
@ -121,7 +121,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||||
// the 0th account in the second instruction is not! The program
|
// the 0th account in the second instruction is not! The program
|
||||||
// needs to check that it's signed.
|
// needs to check that it's signed.
|
||||||
let tx = TransactionBuilder::default()
|
let tx = TransactionBuilder::default()
|
||||||
.push(SystemInstruction::new_move(mallory_id, vote_id, 1))
|
.push(SystemInstruction::new_move(&mallory_id, &vote_id, 1))
|
||||||
.push(vote_ix)
|
.push(vote_ix)
|
||||||
.sign(&[&mallory_keypair], blockhash);
|
.sign(&[&mallory_keypair], blockhash);
|
||||||
|
|
||||||
|
|
|
@ -32,31 +32,34 @@ pub enum VoteInstruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VoteInstruction {
|
impl VoteInstruction {
|
||||||
pub fn new_clear_credits(vote_id: Pubkey) -> BuilderInstruction {
|
pub fn new_clear_credits(vote_id: &Pubkey) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(vote_id, true)])
|
BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)])
|
||||||
}
|
}
|
||||||
pub fn new_delegate_stake(vote_id: Pubkey, delegate_id: Pubkey) -> BuilderInstruction {
|
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
id(),
|
id(),
|
||||||
&VoteInstruction::DelegateStake(delegate_id),
|
&VoteInstruction::DelegateStake(*delegate_id),
|
||||||
vec![(vote_id, true)],
|
vec![(*vote_id, true)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn new_authorize_voter(vote_id: Pubkey, authorized_voter_id: Pubkey) -> BuilderInstruction {
|
pub fn new_authorize_voter(
|
||||||
|
vote_id: &Pubkey,
|
||||||
|
authorized_voter_id: &Pubkey,
|
||||||
|
) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
id(),
|
id(),
|
||||||
&VoteInstruction::AuthorizeVoter(authorized_voter_id),
|
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
|
||||||
vec![(vote_id, true)],
|
vec![(*vote_id, true)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn new_initialize_account(vote_id: Pubkey) -> BuilderInstruction {
|
pub fn new_initialize_account(vote_id: &Pubkey) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
id(),
|
id(),
|
||||||
&VoteInstruction::InitializeAccount,
|
&VoteInstruction::InitializeAccount,
|
||||||
vec![(vote_id, false)],
|
vec![(*vote_id, false)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn new_vote(vote_id: Pubkey, vote: Vote) -> BuilderInstruction {
|
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(vote_id, true)])
|
BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,14 @@ pub struct VoteState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VoteState {
|
impl VoteState {
|
||||||
pub fn new(staker_id: Pubkey) -> Self {
|
pub fn new(staker_id: &Pubkey) -> Self {
|
||||||
let votes = VecDeque::new();
|
let votes = VecDeque::new();
|
||||||
let credits = 0;
|
let credits = 0;
|
||||||
let root_slot = None;
|
let root_slot = None;
|
||||||
Self {
|
Self {
|
||||||
votes,
|
votes,
|
||||||
delegate_id: staker_id,
|
delegate_id: *staker_id,
|
||||||
authorized_voter_id: staker_id,
|
authorized_voter_id: *staker_id,
|
||||||
credits,
|
credits,
|
||||||
root_slot,
|
root_slot,
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl VoteState {
|
||||||
|
|
||||||
pub fn delegate_stake(
|
pub fn delegate_stake(
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
node_id: Pubkey,
|
node_id: &Pubkey,
|
||||||
) -> Result<(), ProgramError> {
|
) -> Result<(), ProgramError> {
|
||||||
if !check_id(&keyed_accounts[0].account.owner) {
|
if !check_id(&keyed_accounts[0].account.owner) {
|
||||||
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
||||||
|
@ -165,7 +165,7 @@ pub fn delegate_stake(
|
||||||
|
|
||||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||||
if let Ok(mut vote_state) = vote_state {
|
if let Ok(mut vote_state) = vote_state {
|
||||||
vote_state.delegate_id = node_id;
|
vote_state.delegate_id = *node_id;
|
||||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||||
} else {
|
} else {
|
||||||
error!("account[0] does not valid userdata");
|
error!("account[0] does not valid userdata");
|
||||||
|
@ -180,7 +180,7 @@ pub fn delegate_stake(
|
||||||
/// voter. The default voter is the owner of the vote account's pubkey.
|
/// voter. The default voter is the owner of the vote account's pubkey.
|
||||||
pub fn authorize_voter(
|
pub fn authorize_voter(
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
voter_id: Pubkey,
|
voter_id: &Pubkey,
|
||||||
) -> Result<(), ProgramError> {
|
) -> Result<(), ProgramError> {
|
||||||
if !check_id(&keyed_accounts[0].account.owner) {
|
if !check_id(&keyed_accounts[0].account.owner) {
|
||||||
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
||||||
|
@ -194,7 +194,7 @@ pub fn authorize_voter(
|
||||||
|
|
||||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||||
if let Ok(mut vote_state) = vote_state {
|
if let Ok(mut vote_state) = vote_state {
|
||||||
vote_state.authorized_voter_id = voter_id;
|
vote_state.authorized_voter_id = *voter_id;
|
||||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||||
} else {
|
} else {
|
||||||
error!("account[0] does not valid userdata");
|
error!("account[0] does not valid userdata");
|
||||||
|
@ -217,7 +217,7 @@ pub fn initialize_account(keyed_accounts: &mut [KeyedAccount]) -> Result<(), Pro
|
||||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||||
if let Ok(vote_state) = vote_state {
|
if let Ok(vote_state) = vote_state {
|
||||||
if vote_state.delegate_id == Pubkey::default() {
|
if vote_state.delegate_id == Pubkey::default() {
|
||||||
let vote_state = VoteState::new(*staker_id);
|
let vote_state = VoteState::new(staker_id);
|
||||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||||
} else {
|
} else {
|
||||||
error!("account[0] userdata already initialized");
|
error!("account[0] userdata already initialized");
|
||||||
|
@ -274,7 +274,7 @@ pub fn clear_credits(keyed_accounts: &mut [KeyedAccount]) -> Result<(), ProgramE
|
||||||
|
|
||||||
pub fn create_vote_account(lamports: u64) -> Account {
|
pub fn create_vote_account(lamports: u64) -> Account {
|
||||||
let space = VoteState::max_size();
|
let space = VoteState::max_size();
|
||||||
Account::new(lamports, space, id())
|
Account::new(lamports, space, &id())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize_and_deserialize(
|
pub fn initialize_and_deserialize(
|
||||||
|
@ -309,7 +309,7 @@ mod tests {
|
||||||
let mut vote_account = create_vote_account(100);
|
let mut vote_account = create_vote_account(100);
|
||||||
|
|
||||||
let bogus_account_id = Keypair::new().pubkey();
|
let bogus_account_id = Keypair::new().pubkey();
|
||||||
let mut bogus_account = Account::new(100, 0, id());
|
let mut bogus_account = Account::new(100, 0, &id());
|
||||||
|
|
||||||
let mut keyed_accounts = [KeyedAccount::new(
|
let mut keyed_accounts = [KeyedAccount::new(
|
||||||
&bogus_account_id,
|
&bogus_account_id,
|
||||||
|
@ -385,7 +385,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vote_lockout() {
|
fn test_vote_lockout() {
|
||||||
let voter_id = Keypair::new().pubkey();
|
let voter_id = Keypair::new().pubkey();
|
||||||
let mut vote_state = VoteState::new(voter_id);
|
let mut vote_state = VoteState::new(&voter_id);
|
||||||
|
|
||||||
for i in 0..(MAX_LOCKOUT_HISTORY + 1) {
|
for i in 0..(MAX_LOCKOUT_HISTORY + 1) {
|
||||||
vote_state.process_vote(Vote::new((INITIAL_LOCKOUT as usize * i) as u64));
|
vote_state.process_vote(Vote::new((INITIAL_LOCKOUT as usize * i) as u64));
|
||||||
|
@ -415,7 +415,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vote_double_lockout_after_expiration() {
|
fn test_vote_double_lockout_after_expiration() {
|
||||||
let voter_id = Keypair::new().pubkey();
|
let voter_id = Keypair::new().pubkey();
|
||||||
let mut vote_state = VoteState::new(voter_id);
|
let mut vote_state = VoteState::new(&voter_id);
|
||||||
|
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
let vote = Vote::new(i as u64);
|
let vote = Vote::new(i as u64);
|
||||||
|
@ -441,7 +441,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vote_credits() {
|
fn test_vote_credits() {
|
||||||
let voter_id = Keypair::new().pubkey();
|
let voter_id = Keypair::new().pubkey();
|
||||||
let mut vote_state = VoteState::new(voter_id);
|
let mut vote_state = VoteState::new(&voter_id);
|
||||||
|
|
||||||
for i in 0..MAX_LOCKOUT_HISTORY {
|
for i in 0..MAX_LOCKOUT_HISTORY {
|
||||||
vote_state.process_vote(Vote::new(i as u64));
|
vote_state.process_vote(Vote::new(i as u64));
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub struct VoteTransaction {}
|
||||||
|
|
||||||
impl VoteTransaction {
|
impl VoteTransaction {
|
||||||
pub fn new_vote<T: KeypairUtil>(
|
pub fn new_vote<T: KeypairUtil>(
|
||||||
staking_account: Pubkey,
|
staking_account: &Pubkey,
|
||||||
authorized_voter_keypair: &T,
|
authorized_voter_keypair: &T,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
|
@ -30,7 +30,7 @@ impl VoteTransaction {
|
||||||
/// Fund or create the staking account with lamports
|
/// Fund or create the staking account with lamports
|
||||||
pub fn new_account(
|
pub fn new_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
staker_id: Pubkey,
|
staker_id: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -39,11 +39,11 @@ impl VoteTransaction {
|
||||||
let space = VoteState::max_size() as u64;
|
let space = VoteState::max_size() as u64;
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(SystemInstruction::new_program_account(
|
.push(SystemInstruction::new_program_account(
|
||||||
from_id,
|
&from_id,
|
||||||
staker_id,
|
staker_id,
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
id(),
|
&id(),
|
||||||
))
|
))
|
||||||
.push(VoteInstruction::new_initialize_account(staker_id))
|
.push(VoteInstruction::new_initialize_account(staker_id))
|
||||||
.sign(&[from_keypair], recent_blockhash)
|
.sign(&[from_keypair], recent_blockhash)
|
||||||
|
@ -53,7 +53,7 @@ impl VoteTransaction {
|
||||||
pub fn new_account_with_delegate(
|
pub fn new_account_with_delegate(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
voter_keypair: &Keypair,
|
voter_keypair: &Keypair,
|
||||||
delegate_id: Pubkey,
|
delegate_id: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -63,14 +63,14 @@ impl VoteTransaction {
|
||||||
let space = VoteState::max_size() as u64;
|
let space = VoteState::max_size() as u64;
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(SystemInstruction::new_program_account(
|
.push(SystemInstruction::new_program_account(
|
||||||
from_id,
|
&from_id,
|
||||||
voter_id,
|
&voter_id,
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
id(),
|
&id(),
|
||||||
))
|
))
|
||||||
.push(VoteInstruction::new_initialize_account(voter_id))
|
.push(VoteInstruction::new_initialize_account(&voter_id))
|
||||||
.push(VoteInstruction::new_delegate_stake(voter_id, delegate_id))
|
.push(VoteInstruction::new_delegate_stake(&voter_id, &delegate_id))
|
||||||
.sign(&[from_keypair, voter_keypair], recent_blockhash)
|
.sign(&[from_keypair, voter_keypair], recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,12 +78,12 @@ impl VoteTransaction {
|
||||||
pub fn new_authorize_voter(
|
pub fn new_authorize_voter(
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
authorized_voter_id: Pubkey,
|
authorized_voter_id: &Pubkey,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(VoteInstruction::new_authorize_voter(
|
.push(VoteInstruction::new_authorize_voter(
|
||||||
vote_keypair.pubkey(),
|
&vote_keypair.pubkey(),
|
||||||
authorized_voter_id,
|
authorized_voter_id,
|
||||||
))
|
))
|
||||||
.sign(&[vote_keypair], recent_blockhash)
|
.sign(&[vote_keypair], recent_blockhash)
|
||||||
|
@ -93,12 +93,12 @@ impl VoteTransaction {
|
||||||
pub fn delegate_vote_account<T: KeypairUtil>(
|
pub fn delegate_vote_account<T: KeypairUtil>(
|
||||||
vote_keypair: &T,
|
vote_keypair: &T,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
node_id: Pubkey,
|
node_id: &Pubkey,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
TransactionBuilder::new(fee)
|
TransactionBuilder::new(fee)
|
||||||
.push(VoteInstruction::new_delegate_stake(
|
.push(VoteInstruction::new_delegate_stake(
|
||||||
vote_keypair.pubkey(),
|
&vote_keypair.pubkey(),
|
||||||
node_id,
|
node_id,
|
||||||
))
|
))
|
||||||
.sign(&[vote_keypair], recent_blockhash)
|
.sign(&[vote_keypair], recent_blockhash)
|
||||||
|
@ -133,7 +133,7 @@ mod tests {
|
||||||
let slot = 1;
|
let slot = 1;
|
||||||
let recent_blockhash = Hash::default();
|
let recent_blockhash = Hash::default();
|
||||||
let transaction =
|
let transaction =
|
||||||
VoteTransaction::new_vote(keypair.pubkey(), &keypair, slot, recent_blockhash, 0);
|
VoteTransaction::new_vote(&keypair.pubkey(), &keypair, slot, recent_blockhash, 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
VoteTransaction::get_votes(&transaction),
|
VoteTransaction::get_votes(&transaction),
|
||||||
vec![(keypair.pubkey(), Vote::new(slot), recent_blockhash)]
|
vec![(keypair.pubkey(), Vote::new(slot), recent_blockhash)]
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
addr
|
addr
|
||||||
};
|
};
|
||||||
let node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr);
|
let node = Node::new_with_external_ip(&keypair.pubkey(), &gossip_addr);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"replicating the data with keypair={:?} gossip_addr={:?}",
|
"replicating the data with keypair={:?} gossip_addr={:?}",
|
||||||
|
|
|
@ -635,11 +635,12 @@ impl AccountsDB {
|
||||||
fn load_executable_accounts(
|
fn load_executable_accounts(
|
||||||
&self,
|
&self,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
mut program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Result<Vec<(Pubkey, Account)>> {
|
) -> Result<Vec<(Pubkey, Account)>> {
|
||||||
let mut accounts = Vec::new();
|
let mut accounts = Vec::new();
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
|
let mut program_id = *program_id;
|
||||||
loop {
|
loop {
|
||||||
if native_loader::check_id(&program_id) {
|
if native_loader::check_id(&program_id) {
|
||||||
// at the root of the chain, ready to dispatch
|
// at the root of the chain, ready to dispatch
|
||||||
|
@ -687,7 +688,7 @@ impl AccountsDB {
|
||||||
return Err(BankError::AccountNotFound);
|
return Err(BankError::AccountNotFound);
|
||||||
}
|
}
|
||||||
let program_id = tx.program_ids[ix.program_ids_index as usize];
|
let program_id = tx.program_ids[ix.program_ids_index as usize];
|
||||||
self.load_executable_accounts(fork, program_id, error_counters)
|
self.load_executable_accounts(fork, &program_id, error_counters)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -1092,10 +1093,10 @@ mod tests {
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
let key1 = Pubkey::new(&[5u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let account = Account::new(2, 1, Pubkey::default());
|
let account = Account::new(2, 1, &Pubkey::default());
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let instructions = vec![Instruction::new(1, &(), vec![0])];
|
let instructions = vec![Instruction::new(1, &(), vec![0])];
|
||||||
|
@ -1123,7 +1124,7 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let instructions = vec![Instruction::new(1, &(), vec![0])];
|
let instructions = vec![Instruction::new(1, &(), vec![0])];
|
||||||
|
@ -1152,10 +1153,10 @@ mod tests {
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
let key1 = Pubkey::new(&[5u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let account = Account::new(2, 1, Pubkey::default());
|
let account = Account::new(2, 1, &Pubkey::default());
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let instructions = vec![Instruction::new(0, &(), vec![0, 1])];
|
let instructions = vec![Instruction::new(0, &(), vec![0, 1])];
|
||||||
|
@ -1197,35 +1198,35 @@ mod tests {
|
||||||
let key5 = Pubkey::new(&[9u8; 32]);
|
let key5 = Pubkey::new(&[9u8; 32]);
|
||||||
let key6 = Pubkey::new(&[10u8; 32]);
|
let key6 = Pubkey::new(&[10u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let mut account = Account::new(40, 1, Pubkey::default());
|
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = native_loader::id();
|
account.owner = native_loader::id();
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let mut account = Account::new(41, 1, Pubkey::default());
|
let mut account = Account::new(41, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key1;
|
account.owner = key1;
|
||||||
accounts.push((key2, account));
|
accounts.push((key2, account));
|
||||||
|
|
||||||
let mut account = Account::new(42, 1, Pubkey::default());
|
let mut account = Account::new(42, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key2;
|
account.owner = key2;
|
||||||
accounts.push((key3, account));
|
accounts.push((key3, account));
|
||||||
|
|
||||||
let mut account = Account::new(43, 1, Pubkey::default());
|
let mut account = Account::new(43, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key3;
|
account.owner = key3;
|
||||||
accounts.push((key4, account));
|
accounts.push((key4, account));
|
||||||
|
|
||||||
let mut account = Account::new(44, 1, Pubkey::default());
|
let mut account = Account::new(44, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key4;
|
account.owner = key4;
|
||||||
accounts.push((key5, account));
|
accounts.push((key5, account));
|
||||||
|
|
||||||
let mut account = Account::new(45, 1, Pubkey::default());
|
let mut account = Account::new(45, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key5;
|
account.owner = key5;
|
||||||
accounts.push((key6, account));
|
accounts.push((key6, account));
|
||||||
|
@ -1256,10 +1257,10 @@ mod tests {
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
let key1 = Pubkey::new(&[5u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let mut account = Account::new(40, 1, Pubkey::default());
|
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = Pubkey::default();
|
account.owner = Pubkey::default();
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
@ -1290,10 +1291,10 @@ mod tests {
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
let key1 = Pubkey::new(&[5u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let mut account = Account::new(40, 1, Pubkey::default());
|
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||||
account.owner = native_loader::id();
|
account.owner = native_loader::id();
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
|
@ -1325,20 +1326,20 @@ mod tests {
|
||||||
let key2 = Pubkey::new(&[6u8; 32]);
|
let key2 = Pubkey::new(&[6u8; 32]);
|
||||||
let key3 = Pubkey::new(&[7u8; 32]);
|
let key3 = Pubkey::new(&[7u8; 32]);
|
||||||
|
|
||||||
let account = Account::new(1, 1, Pubkey::default());
|
let account = Account::new(1, 1, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let mut account = Account::new(40, 1, Pubkey::default());
|
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = native_loader::id();
|
account.owner = native_loader::id();
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let mut account = Account::new(41, 1, Pubkey::default());
|
let mut account = Account::new(41, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key1;
|
account.owner = key1;
|
||||||
accounts.push((key2, account));
|
accounts.push((key2, account));
|
||||||
|
|
||||||
let mut account = Account::new(42, 1, Pubkey::default());
|
let mut account = Account::new(42, 1, &Pubkey::default());
|
||||||
account.executable = true;
|
account.executable = true;
|
||||||
account.owner = key2;
|
account.owner = key2;
|
||||||
accounts.push((key3, account));
|
accounts.push((key3, account));
|
||||||
|
@ -1386,7 +1387,7 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
|
|
||||||
let account = Account::new(10, 1, Pubkey::default());
|
let account = Account::new(10, 1, &Pubkey::default());
|
||||||
accounts.push((pubkey, account));
|
accounts.push((pubkey, account));
|
||||||
|
|
||||||
let instructions = vec![Instruction::new(0, &(), vec![0, 1])];
|
let instructions = vec![Instruction::new(0, &(), vec![0, 1])];
|
||||||
|
@ -1448,7 +1449,7 @@ mod tests {
|
||||||
let paths = get_tmp_accounts_path!();
|
let paths = get_tmp_accounts_path!();
|
||||||
let db = AccountsDB::new(0, &paths.paths);
|
let db = AccountsDB::new(0, &paths.paths);
|
||||||
let key = Pubkey::default();
|
let key = Pubkey::default();
|
||||||
let account0 = Account::new(1, 0, key);
|
let account0 = Account::new(1, 0, &key);
|
||||||
|
|
||||||
// store value 1 in the "root", i.e. db zero
|
// store value 1 in the "root", i.e. db zero
|
||||||
db.store(0, &key, &account0);
|
db.store(0, &key, &account0);
|
||||||
|
@ -1466,7 +1467,7 @@ mod tests {
|
||||||
// (via root0)
|
// (via root0)
|
||||||
|
|
||||||
// store value 0 in one child
|
// store value 0 in one child
|
||||||
let account1 = Account::new(0, 0, key);
|
let account1 = Account::new(0, 0, &key);
|
||||||
db.store(1, &key, &account1);
|
db.store(1, &key, &account1);
|
||||||
|
|
||||||
// masking accounts is done at the Accounts level, at accountsDB we see
|
// masking accounts is done at the Accounts level, at accountsDB we see
|
||||||
|
@ -1546,12 +1547,12 @@ mod tests {
|
||||||
// 1 token in the "root", i.e. db zero
|
// 1 token in the "root", i.e. db zero
|
||||||
let paths = get_tmp_accounts_path!();
|
let paths = get_tmp_accounts_path!();
|
||||||
let db0 = AccountsDB::new(0, &paths.paths);
|
let db0 = AccountsDB::new(0, &paths.paths);
|
||||||
let account0 = Account::new(1, 0, key);
|
let account0 = Account::new(1, 0, &key);
|
||||||
db0.store(0, &key, &account0);
|
db0.store(0, &key, &account0);
|
||||||
|
|
||||||
db0.add_fork(1, Some(0));
|
db0.add_fork(1, Some(0));
|
||||||
// 0 lamports in the child
|
// 0 lamports in the child
|
||||||
let account1 = Account::new(0, 0, key);
|
let account1 = Account::new(0, 0, &key);
|
||||||
db0.store(1, &key, &account1);
|
db0.store(1, &key, &account1);
|
||||||
|
|
||||||
// masking accounts is done at the Accounts level, at accountsDB we see
|
// masking accounts is done at the Accounts level, at accountsDB we see
|
||||||
|
@ -1670,7 +1671,7 @@ mod tests {
|
||||||
let mut keys = vec![];
|
let mut keys = vec![];
|
||||||
for i in 0..9 {
|
for i in 0..9 {
|
||||||
let key = Keypair::new().pubkey();
|
let key = Keypair::new().pubkey();
|
||||||
let account = Account::new(i + 1, size as usize / 4, key);
|
let account = Account::new(i + 1, size as usize / 4, &key);
|
||||||
accounts.store(0, &key, &account);
|
accounts.store(0, &key, &account);
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
|
@ -1703,7 +1704,7 @@ mod tests {
|
||||||
AccountStorageStatus::StorageFull,
|
AccountStorageStatus::StorageFull,
|
||||||
];
|
];
|
||||||
let pubkey1 = Keypair::new().pubkey();
|
let pubkey1 = Keypair::new().pubkey();
|
||||||
let account1 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, pubkey1);
|
let account1 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, &pubkey1);
|
||||||
accounts.store(0, &pubkey1, &account1);
|
accounts.store(0, &pubkey1, &account1);
|
||||||
{
|
{
|
||||||
let stores = accounts.storage.read().unwrap();
|
let stores = accounts.storage.read().unwrap();
|
||||||
|
@ -1713,7 +1714,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
let pubkey2 = Keypair::new().pubkey();
|
let pubkey2 = Keypair::new().pubkey();
|
||||||
let account2 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, pubkey2);
|
let account2 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, &pubkey2);
|
||||||
accounts.store(0, &pubkey2, &account2);
|
accounts.store(0, &pubkey2, &account2);
|
||||||
{
|
{
|
||||||
let stores = accounts.storage.read().unwrap();
|
let stores = accounts.storage.read().unwrap();
|
||||||
|
@ -1747,7 +1748,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_accounts_vote_filter() {
|
fn test_accounts_vote_filter() {
|
||||||
let accounts = Accounts::new(0, None);
|
let accounts = Accounts::new(0, None);
|
||||||
let mut vote_account = Account::new(1, 0, solana_vote_api::id());
|
let mut vote_account = Account::new(1, 0, &solana_vote_api::id());
|
||||||
let key = Keypair::new().pubkey();
|
let key = Keypair::new().pubkey();
|
||||||
accounts.store_slow(0, &key, &vote_account);
|
accounts.store_slow(0, &key, &vote_account);
|
||||||
|
|
||||||
|
@ -1762,7 +1763,7 @@ mod tests {
|
||||||
vote_accounts = accounts.get_vote_accounts(1).collect();
|
vote_accounts = accounts.get_vote_accounts(1).collect();
|
||||||
assert_eq!(vote_accounts.len(), 0);
|
assert_eq!(vote_accounts.len(), 0);
|
||||||
|
|
||||||
let mut vote_account1 = Account::new(2, 0, solana_vote_api::id());
|
let mut vote_account1 = Account::new(2, 0, &solana_vote_api::id());
|
||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
accounts.store_slow(1, &key1, &vote_account1);
|
accounts.store_slow(1, &key1, &vote_account1);
|
||||||
|
|
||||||
|
@ -1792,7 +1793,7 @@ mod tests {
|
||||||
assert_eq!(account.owner, solana_vote_api::id());
|
assert_eq!(account.owner, solana_vote_api::id());
|
||||||
});
|
});
|
||||||
let lastkey = Keypair::new().pubkey();
|
let lastkey = Keypair::new().pubkey();
|
||||||
let mut lastaccount = Account::new(1, 0, solana_vote_api::id());
|
let mut lastaccount = Account::new(1, 0, &solana_vote_api::id());
|
||||||
accounts_db.store(0, &lastkey, &lastaccount);
|
accounts_db.store(0, &lastkey, &lastaccount);
|
||||||
assert_eq!(accounts_db.get_vote_accounts(0).len(), 2);
|
assert_eq!(accounts_db.get_vote_accounts(0).len(), 2);
|
||||||
|
|
||||||
|
@ -1862,7 +1863,7 @@ mod tests {
|
||||||
let accounts = AccountsDB::new(0, &paths.paths);
|
let accounts = AccountsDB::new(0, &paths.paths);
|
||||||
let mut error_counters = ErrorCounters::default();
|
let mut error_counters = ErrorCounters::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
accounts.load_executable_accounts(0, Keypair::new().pubkey(), &mut error_counters),
|
accounts.load_executable_accounts(0, &Keypair::new().pubkey(), &mut error_counters),
|
||||||
Err(BankError::AccountNotFound)
|
Err(BankError::AccountNotFound)
|
||||||
);
|
);
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
|
@ -1894,13 +1895,13 @@ mod tests {
|
||||||
|
|
||||||
// Load accounts owned by various programs into AccountsDB
|
// Load accounts owned by various programs into AccountsDB
|
||||||
let pubkey0 = Keypair::new().pubkey();
|
let pubkey0 = Keypair::new().pubkey();
|
||||||
let account0 = Account::new(1, 0, Pubkey::new(&[2; 32]));
|
let account0 = Account::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||||
accounts_db.store(0, &pubkey0, &account0);
|
accounts_db.store(0, &pubkey0, &account0);
|
||||||
let pubkey1 = Keypair::new().pubkey();
|
let pubkey1 = Keypair::new().pubkey();
|
||||||
let account1 = Account::new(1, 0, Pubkey::new(&[2; 32]));
|
let account1 = Account::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||||
accounts_db.store(0, &pubkey1, &account1);
|
accounts_db.store(0, &pubkey1, &account1);
|
||||||
let pubkey2 = Keypair::new().pubkey();
|
let pubkey2 = Keypair::new().pubkey();
|
||||||
let account2 = Account::new(1, 0, Pubkey::new(&[3; 32]));
|
let account2 = Account::new(1, 0, &Pubkey::new(&[3; 32]));
|
||||||
accounts_db.store(0, &pubkey2, &account2);
|
accounts_db.store(0, &pubkey2, &account2);
|
||||||
|
|
||||||
let accounts = accounts_db.load_by_program(0, &Pubkey::new(&[2; 32]), false);
|
let accounts = accounts_db.load_by_program(0, &Pubkey::new(&[2; 32]), false);
|
||||||
|
|
|
@ -224,7 +224,7 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new bank that points to an immutable checkpoint of another bank.
|
/// Create a new bank that points to an immutable checkpoint of another bank.
|
||||||
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: Pubkey, slot: u64) -> Self {
|
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: u64) -> Self {
|
||||||
parent.freeze();
|
parent.freeze();
|
||||||
|
|
||||||
assert_ne!(slot, parent.slot());
|
assert_ne!(slot, parent.slot());
|
||||||
|
@ -239,7 +239,7 @@ impl Bank {
|
||||||
bank.slot = slot;
|
bank.slot = slot;
|
||||||
bank.parent = RwLock::new(Some(parent.clone()));
|
bank.parent = RwLock::new(Some(parent.clone()));
|
||||||
bank.parent_hash = parent.hash();
|
bank.parent_hash = parent.hash();
|
||||||
bank.collector_id = collector_id;
|
bank.collector_id = *collector_id;
|
||||||
|
|
||||||
// Accounts needs a unique id
|
// Accounts needs a unique id
|
||||||
static BANK_ACCOUNTS_ID: AtomicUsize = AtomicUsize::new(1);
|
static BANK_ACCOUNTS_ID: AtomicUsize = AtomicUsize::new(1);
|
||||||
|
@ -340,7 +340,7 @@ impl Bank {
|
||||||
executable: false,
|
executable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut vote_state = VoteState::new(genesis_block.bootstrap_leader_id);
|
let mut vote_state = VoteState::new(&genesis_block.bootstrap_leader_id);
|
||||||
vote_state.votes.push_back(Lockout::new(&Vote::new(0)));
|
vote_state.votes.push_back(Lockout::new(&Vote::new(0)));
|
||||||
vote_state
|
vote_state
|
||||||
.serialize(&mut bootstrap_leader_vote_account.userdata)
|
.serialize(&mut bootstrap_leader_vote_account.userdata)
|
||||||
|
@ -731,7 +731,7 @@ impl Bank {
|
||||||
&self,
|
&self,
|
||||||
n: u64,
|
n: u64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let tx = SystemTransaction::new_account(keypair, to, n, blockhash, 0);
|
let tx = SystemTransaction::new_account(keypair, to, n, blockhash, 0);
|
||||||
|
@ -909,7 +909,7 @@ mod tests {
|
||||||
let dummy_leader_id = Keypair::new().pubkey();
|
let dummy_leader_id = Keypair::new().pubkey();
|
||||||
let dummy_leader_lamports = BOOTSTRAP_LEADER_LAMPORTS;
|
let dummy_leader_lamports = BOOTSTRAP_LEADER_LAMPORTS;
|
||||||
let (genesis_block, _) =
|
let (genesis_block, _) =
|
||||||
GenesisBlock::new_with_leader(10_000, dummy_leader_id, dummy_leader_lamports);
|
GenesisBlock::new_with_leader(10_000, &dummy_leader_id, dummy_leader_lamports);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
genesis_block.bootstrap_leader_lamports,
|
genesis_block.bootstrap_leader_lamports,
|
||||||
dummy_leader_lamports
|
dummy_leader_lamports
|
||||||
|
@ -932,11 +932,11 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
||||||
|
|
||||||
bank.transfer(1_000, &mint_keypair, pubkey, genesis_block.hash())
|
bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank.get_balance(&pubkey), 1_000);
|
assert_eq!(bank.get_balance(&pubkey), 1_000);
|
||||||
|
|
||||||
bank.transfer(500, &mint_keypair, pubkey, genesis_block.hash())
|
bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank.get_balance(&pubkey), 1_500);
|
assert_eq!(bank.get_balance(&pubkey), 1_500);
|
||||||
assert_eq!(bank.transaction_count(), 2);
|
assert_eq!(bank.transaction_count(), 2);
|
||||||
|
@ -950,8 +950,8 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
||||||
|
|
||||||
let t1 = SystemTransaction::new_move(&mint_keypair, key1, 1, genesis_block.hash(), 0);
|
let t1 = SystemTransaction::new_move(&mint_keypair, &key1, 1, genesis_block.hash(), 0);
|
||||||
let t2 = SystemTransaction::new_move(&mint_keypair, key2, 1, genesis_block.hash(), 0);
|
let t2 = SystemTransaction::new_move(&mint_keypair, &key2, 1, genesis_block.hash(), 0);
|
||||||
let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]);
|
let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]);
|
||||||
assert_eq!(res.len(), 2);
|
assert_eq!(res.len(), 2);
|
||||||
assert_eq!(res[0], Ok(()));
|
assert_eq!(res[0], Ok(()));
|
||||||
|
@ -1040,7 +1040,7 @@ mod tests {
|
||||||
// source with 0 program context
|
// source with 0 program context
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
dest.pubkey(),
|
&dest.pubkey(),
|
||||||
2,
|
2,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
1,
|
1,
|
||||||
|
@ -1069,7 +1069,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.transfer(1, &keypair, mint_keypair.pubkey(), genesis_block.hash()),
|
bank.transfer(1, &keypair, &mint_keypair.pubkey(), genesis_block.hash()),
|
||||||
Err(BankError::AccountNotFound)
|
Err(BankError::AccountNotFound)
|
||||||
);
|
);
|
||||||
assert_eq!(bank.transaction_count(), 0);
|
assert_eq!(bank.transaction_count(), 0);
|
||||||
|
@ -1080,12 +1080,12 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(11_000);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(11_000);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
bank.transfer(1_000, &mint_keypair, pubkey, genesis_block.hash())
|
bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank.transaction_count(), 1);
|
assert_eq!(bank.transaction_count(), 1);
|
||||||
assert_eq!(bank.get_balance(&pubkey), 1_000);
|
assert_eq!(bank.get_balance(&pubkey), 1_000);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.transfer(10_001, &mint_keypair, pubkey, genesis_block.hash()),
|
bank.transfer(10_001, &mint_keypair, &pubkey, genesis_block.hash()),
|
||||||
Err(BankError::ProgramError(
|
Err(BankError::ProgramError(
|
||||||
0,
|
0,
|
||||||
ProgramError::ResultWithNegativeLamports
|
ProgramError::ResultWithNegativeLamports
|
||||||
|
@ -1103,7 +1103,7 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(10_000);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(10_000);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
bank.transfer(500, &mint_keypair, pubkey, genesis_block.hash())
|
bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank.get_balance(&pubkey), 500);
|
assert_eq!(bank.get_balance(&pubkey), 500);
|
||||||
}
|
}
|
||||||
|
@ -1152,20 +1152,20 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bank_tx_fee() {
|
fn test_bank_tx_fee() {
|
||||||
let leader = Keypair::new().pubkey();
|
let leader = Keypair::new().pubkey();
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader, 3);
|
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader, 3);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
let key2 = Keypair::new();
|
let key2 = Keypair::new();
|
||||||
|
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 2, genesis_block.hash(), 3);
|
SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 2, genesis_block.hash(), 3);
|
||||||
let initial_balance = bank.get_balance(&leader);
|
let initial_balance = bank.get_balance(&leader);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&leader), initial_balance + 3);
|
assert_eq!(bank.get_balance(&leader), initial_balance + 3);
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 2);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 2);
|
||||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 100 - 5 - 3);
|
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 100 - 5 - 3);
|
||||||
|
|
||||||
let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 1);
|
let tx = SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 1);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&leader), initial_balance + 4);
|
assert_eq!(bank.get_balance(&leader), initial_balance + 4);
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 0);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 0);
|
||||||
|
@ -1176,14 +1176,14 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_filter_program_errors_and_collect_fee() {
|
fn test_filter_program_errors_and_collect_fee() {
|
||||||
let leader = Keypair::new().pubkey();
|
let leader = Keypair::new().pubkey();
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader, 3);
|
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader, 3);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let tx1 =
|
let tx1 =
|
||||||
SystemTransaction::new_move(&mint_keypair, key.pubkey(), 2, genesis_block.hash(), 3);
|
SystemTransaction::new_move(&mint_keypair, &key.pubkey(), 2, genesis_block.hash(), 3);
|
||||||
let tx2 =
|
let tx2 =
|
||||||
SystemTransaction::new_move(&mint_keypair, key.pubkey(), 5, genesis_block.hash(), 1);
|
SystemTransaction::new_move(&mint_keypair, &key.pubkey(), 5, genesis_block.hash(), 1);
|
||||||
|
|
||||||
let results = vec![
|
let results = vec![
|
||||||
Ok(()),
|
Ok(()),
|
||||||
|
@ -1207,14 +1207,14 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = SystemTransaction::new_account(
|
let tx0 = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let tx1 = SystemTransaction::new_account(
|
let tx1 = SystemTransaction::new_account(
|
||||||
&keypair,
|
&keypair,
|
||||||
mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -1232,7 +1232,7 @@ mod tests {
|
||||||
let dummy_leader_id = Keypair::new().pubkey();
|
let dummy_leader_id = Keypair::new().pubkey();
|
||||||
let dummy_leader_lamports = 3;
|
let dummy_leader_lamports = 3;
|
||||||
let (genesis_block, _) =
|
let (genesis_block, _) =
|
||||||
GenesisBlock::new_with_leader(5, dummy_leader_id, dummy_leader_lamports);
|
GenesisBlock::new_with_leader(5, &dummy_leader_id, dummy_leader_lamports);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
assert_eq!(bank.get_balance(&genesis_block.mint_id), 2);
|
assert_eq!(bank.get_balance(&genesis_block.mint_id), 2);
|
||||||
assert_eq!(bank.get_balance(&dummy_leader_id), 2);
|
assert_eq!(bank.get_balance(&dummy_leader_id), 2);
|
||||||
|
@ -1247,7 +1247,7 @@ mod tests {
|
||||||
|
|
||||||
let tx1 = SystemTransaction::new_account(
|
let tx1 = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
&alice.pubkey(),
|
||||||
1,
|
1,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
|
@ -1264,20 +1264,20 @@ mod tests {
|
||||||
|
|
||||||
// try executing an interleaved transfer twice
|
// try executing an interleaved transfer twice
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.transfer(1, &mint_keypair, bob.pubkey(), genesis_block.hash()),
|
bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()),
|
||||||
Err(BankError::AccountInUse)
|
Err(BankError::AccountInUse)
|
||||||
);
|
);
|
||||||
// the second time should fail as well
|
// the second time should fail as well
|
||||||
// this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts
|
// this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.transfer(1, &mint_keypair, bob.pubkey(), genesis_block.hash()),
|
bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()),
|
||||||
Err(BankError::AccountInUse)
|
Err(BankError::AccountInUse)
|
||||||
);
|
);
|
||||||
|
|
||||||
bank.unlock_accounts(&pay_alice, &results_alice);
|
bank.unlock_accounts(&pay_alice, &results_alice);
|
||||||
|
|
||||||
assert!(bank
|
assert!(bank
|
||||||
.transfer(2, &mint_keypair, bob.pubkey(), genesis_block.hash())
|
.transfer(2, &mint_keypair, &bob.pubkey(), genesis_block.hash())
|
||||||
.is_ok());
|
.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1342,10 +1342,10 @@ mod tests {
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
bank.transfer(1, &mint_keypair, key1.pubkey(), genesis_block.hash())
|
bank.transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
||||||
let tx = SystemTransaction::new_move(&key1, key1.pubkey(), 1, genesis_block.hash(), 0);
|
let tx = SystemTransaction::new_move(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
let res = bank.process_transactions(&vec![tx.clone()]);
|
let res = bank.process_transactions(&vec![tx.clone()]);
|
||||||
assert_eq!(res.len(), 1);
|
assert_eq!(res.len(), 1);
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
||||||
|
@ -1353,7 +1353,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_from_parent(parent: &Arc<Bank>) -> Bank {
|
fn new_from_parent(parent: &Arc<Bank>) -> Bank {
|
||||||
Bank::new_from_parent(parent, Pubkey::default(), parent.slot() + 1)
|
Bank::new_from_parent(parent, &Pubkey::default(), parent.slot() + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify that the parent's vector is computed correctly
|
/// Verify that the parent's vector is computed correctly
|
||||||
|
@ -1374,7 +1374,7 @@ mod tests {
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0);
|
SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1392,10 +1392,10 @@ mod tests {
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0);
|
SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0);
|
let tx = SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(parent.get_signature_status(&tx.signatures[0]), None);
|
assert_eq!(parent.get_signature_status(&tx.signatures[0]), None);
|
||||||
}
|
}
|
||||||
|
@ -1410,11 +1410,11 @@ mod tests {
|
||||||
|
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
bank0
|
bank0
|
||||||
.transfer(1_000, &mint_keypair, pubkey, bank0.last_blockhash())
|
.transfer(1_000, &mint_keypair, &pubkey, bank0.last_blockhash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_ne!(bank0.hash_internal_state(), initial_state);
|
assert_ne!(bank0.hash_internal_state(), initial_state);
|
||||||
bank1
|
bank1
|
||||||
.transfer(1_000, &mint_keypair, pubkey, bank1.last_blockhash())
|
.transfer(1_000, &mint_keypair, &pubkey, bank1.last_blockhash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
|
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
|
||||||
|
|
||||||
|
@ -1434,7 +1434,7 @@ mod tests {
|
||||||
fn test_bank_hash_internal_state_squash() {
|
fn test_bank_hash_internal_state_squash() {
|
||||||
let collector_id = Pubkey::default();
|
let collector_id = Pubkey::default();
|
||||||
let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0));
|
let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0));
|
||||||
let bank1 = Bank::new_from_parent(&bank0, collector_id, 1);
|
let bank1 = Bank::new_from_parent(&bank0, &collector_id, 1);
|
||||||
|
|
||||||
// no delta in bank1, hashes match
|
// no delta in bank1, hashes match
|
||||||
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
|
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
|
||||||
|
@ -1456,14 +1456,14 @@ mod tests {
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx_move_mint_to_1 =
|
let tx_move_mint_to_1 =
|
||||||
SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0);
|
SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(()));
|
assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(()));
|
||||||
assert_eq!(parent.transaction_count(), 1);
|
assert_eq!(parent.transaction_count(), 1);
|
||||||
|
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
assert_eq!(bank.transaction_count(), parent.transaction_count());
|
assert_eq!(bank.transaction_count(), parent.transaction_count());
|
||||||
let tx_move_1_to_2 =
|
let tx_move_1_to_2 =
|
||||||
SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0);
|
SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
||||||
assert_eq!(bank.transaction_count(), 2);
|
assert_eq!(bank.transaction_count(), 2);
|
||||||
assert_eq!(parent.transaction_count(), 1);
|
assert_eq!(parent.transaction_count(), 1);
|
||||||
|
@ -1502,7 +1502,7 @@ mod tests {
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
|
|
||||||
parent
|
parent
|
||||||
.transfer(1, &mint_keypair, key1.pubkey(), genesis_block.hash())
|
.transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(parent.get_balance(&key1.pubkey()), 1);
|
assert_eq!(parent.get_balance(&key1.pubkey()), 1);
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
|
@ -1514,7 +1514,7 @@ mod tests {
|
||||||
fn test_bank_epoch_vote_accounts() {
|
fn test_bank_epoch_vote_accounts() {
|
||||||
let leader_id = Keypair::new().pubkey();
|
let leader_id = Keypair::new().pubkey();
|
||||||
let leader_lamports = 3;
|
let leader_lamports = 3;
|
||||||
let (mut genesis_block, _) = GenesisBlock::new_with_leader(5, leader_id, leader_lamports);
|
let (mut genesis_block, _) = GenesisBlock::new_with_leader(5, &leader_id, leader_lamports);
|
||||||
|
|
||||||
// set this up weird, forces future generation, odd mod(), etc.
|
// set this up weird, forces future generation, odd mod(), etc.
|
||||||
// this says: "stakes for slot X should be generated at slot index 3 in slot X-2...
|
// this says: "stakes for slot X should be generated at slot index 3 in slot X-2...
|
||||||
|
@ -1557,7 +1557,7 @@ mod tests {
|
||||||
// child crosses epoch boundary and is the first slot in the epoch
|
// child crosses epoch boundary and is the first slot in the epoch
|
||||||
let child = Bank::new_from_parent(
|
let child = Bank::new_from_parent(
|
||||||
&parent,
|
&parent,
|
||||||
leader_id,
|
&leader_id,
|
||||||
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH),
|
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1566,7 +1566,7 @@ mod tests {
|
||||||
// child crosses epoch boundary but isn't the first slot in the epoch
|
// child crosses epoch boundary but isn't the first slot in the epoch
|
||||||
let child = Bank::new_from_parent(
|
let child = Bank::new_from_parent(
|
||||||
&parent,
|
&parent,
|
||||||
leader_id,
|
&leader_id,
|
||||||
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH) + 1,
|
SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH) + 1,
|
||||||
);
|
);
|
||||||
assert!(child.epoch_vote_accounts(i).is_some());
|
assert!(child.epoch_vote_accounts(i).is_some());
|
||||||
|
@ -1584,7 +1584,7 @@ mod tests {
|
||||||
let mut tx = Transaction::new_unsigned(
|
let mut tx = Transaction::new_unsigned(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&[key.pubkey()],
|
&[key.pubkey()],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&move_lamports,
|
&move_lamports,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
2,
|
2,
|
||||||
|
|
|
@ -4,12 +4,12 @@ use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
|
|
||||||
pub fn load_program(bank: &Bank, from: &Keypair, loader_id: Pubkey, program: Vec<u8>) -> Pubkey {
|
pub fn load_program(bank: &Bank, from: &Keypair, loader_id: &Pubkey, program: Vec<u8>) -> Pubkey {
|
||||||
let program_account = Keypair::new();
|
let program_account = Keypair::new();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
from,
|
from,
|
||||||
program_account.pubkey(),
|
&program_account.pubkey(),
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
1,
|
1,
|
||||||
program.len() as u64,
|
program.len() as u64,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use solana_sdk::transaction::Transaction;
|
||||||
/// Reasons the runtime might have rejected a transaction.
|
/// Reasons the runtime might have rejected a transaction.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum RuntimeError {
|
pub enum RuntimeError {
|
||||||
/// Executing the instruction at the given index produced an error.
|
/// Executing the instruction at the give&n index produced an error.
|
||||||
ProgramError(u8, ProgramError),
|
ProgramError(u8, ProgramError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ where
|
||||||
F: Fn(&Pubkey, &mut [KeyedAccount], &[u8]) -> Result<(), E>,
|
F: Fn(&Pubkey, &mut [KeyedAccount], &[u8]) -> Result<(), E>,
|
||||||
{
|
{
|
||||||
for _ in tx_accounts.len()..tx.account_keys.len() {
|
for _ in tx_accounts.len()..tx.account_keys.len() {
|
||||||
tx_accounts.push(Account::new(0, 0, system_program::id()));
|
tx_accounts.push(Account::new(0, 0, &system_program::id()));
|
||||||
}
|
}
|
||||||
for (i, ix) in tx.instructions.iter().enumerate() {
|
for (i, ix) in tx.instructions.iter().enumerate() {
|
||||||
let mut ix_accounts = get_subset_unchecked_mut(tx_accounts, &ix.accounts);
|
let mut ix_accounts = get_subset_unchecked_mut(tx_accounts, &ix.accounts);
|
||||||
|
@ -262,7 +262,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_instruction_change_program_id() {
|
fn test_verify_instruction_change_program_id() {
|
||||||
fn change_program_id(ix: Pubkey, pre: Pubkey, post: Pubkey) -> Result<(), ProgramError> {
|
fn change_program_id(ix: &Pubkey, pre: &Pubkey, post: &Pubkey) -> Result<(), ProgramError> {
|
||||||
verify_instruction(&ix, &pre, 0, &[], &Account::new(0, 0, post))
|
verify_instruction(&ix, &pre, 0, &[], &Account::new(0, 0, post))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,12 +271,12 @@ mod tests {
|
||||||
let mallory_program_id = Keypair::new().pubkey();
|
let mallory_program_id = Keypair::new().pubkey();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
change_program_id(system_program_id, system_program_id, alice_program_id),
|
change_program_id(&system_program_id, &system_program_id, &alice_program_id),
|
||||||
Ok(()),
|
Ok(()),
|
||||||
"system program should be able to change the account owner"
|
"system program should be able to change the account owner"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
change_program_id(mallory_program_id, system_program_id, alice_program_id),
|
change_program_id(&mallory_program_id, &system_program_id, &alice_program_id),
|
||||||
Err(ProgramError::ModifiedProgramId),
|
Err(ProgramError::ModifiedProgramId),
|
||||||
"malicious Mallory should not be able to change the account owner"
|
"malicious Mallory should not be able to change the account owner"
|
||||||
);
|
);
|
||||||
|
@ -284,9 +284,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_instruction_change_userdata() {
|
fn test_verify_instruction_change_userdata() {
|
||||||
fn change_userdata(program_id: Pubkey) -> Result<(), ProgramError> {
|
fn change_userdata(program_id: &Pubkey) -> Result<(), ProgramError> {
|
||||||
let alice_program_id = Keypair::new().pubkey();
|
let alice_program_id = Keypair::new().pubkey();
|
||||||
let account = Account::new(0, 0, alice_program_id);
|
let account = Account::new(0, 0, &alice_program_id);
|
||||||
verify_instruction(&program_id, &alice_program_id, 0, &[42], &account)
|
verify_instruction(&program_id, &alice_program_id, 0, &[42], &account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,12 +294,12 @@ mod tests {
|
||||||
let mallory_program_id = Keypair::new().pubkey();
|
let mallory_program_id = Keypair::new().pubkey();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
change_userdata(system_program_id),
|
change_userdata(&system_program_id),
|
||||||
Ok(()),
|
Ok(()),
|
||||||
"system program should be able to change the userdata"
|
"system program should be able to change the userdata"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
change_userdata(mallory_program_id),
|
change_userdata(&mallory_program_id),
|
||||||
Err(ProgramError::ExternalAccountUserdataModified),
|
Err(ProgramError::ExternalAccountUserdataModified),
|
||||||
"malicious Mallory should not be able to change the account userdata"
|
"malicious Mallory should not be able to change the account userdata"
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,11 +40,11 @@ impl fmt::Debug for Account {
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
// TODO do we want to add executable and leader_owner even though they should always be false/default?
|
// TODO do we want to add executable and leader_owner even though they should always be false/default?
|
||||||
pub fn new(lamports: u64, space: usize, owner: Pubkey) -> Account {
|
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Account {
|
||||||
Account {
|
Account {
|
||||||
lamports,
|
lamports,
|
||||||
userdata: vec![0u8; space],
|
userdata: vec![0u8; space],
|
||||||
owner,
|
owner: *owner,
|
||||||
executable: false,
|
executable: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,23 @@ impl GenesisBlock {
|
||||||
let lamports = lamports
|
let lamports = lamports
|
||||||
.checked_add(BOOTSTRAP_LEADER_LAMPORTS)
|
.checked_add(BOOTSTRAP_LEADER_LAMPORTS)
|
||||||
.unwrap_or(lamports);
|
.unwrap_or(lamports);
|
||||||
Self::new_with_leader(lamports, Keypair::new().pubkey(), BOOTSTRAP_LEADER_LAMPORTS)
|
Self::new_with_leader(
|
||||||
|
lamports,
|
||||||
|
&Keypair::new().pubkey(),
|
||||||
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_leader(
|
pub fn new_with_leader(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
bootstrap_leader_id: Pubkey,
|
bootstrap_leader_id: &Pubkey,
|
||||||
bootstrap_leader_lamports: u64,
|
bootstrap_leader_lamports: u64,
|
||||||
) -> (Self, Keypair) {
|
) -> (Self, Keypair) {
|
||||||
let mint_keypair = Keypair::new();
|
let mint_keypair = Keypair::new();
|
||||||
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
bootstrap_leader_id,
|
bootstrap_leader_id: *bootstrap_leader_id,
|
||||||
bootstrap_leader_lamports,
|
bootstrap_leader_lamports,
|
||||||
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
|
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
|
||||||
mint_id: mint_keypair.pubkey(),
|
mint_id: mint_keypair.pubkey(),
|
||||||
|
@ -97,7 +101,7 @@ mod tests {
|
||||||
fn test_genesis_block_new_with_leader() {
|
fn test_genesis_block_new_with_leader() {
|
||||||
let leader_keypair = Keypair::new();
|
let leader_keypair = Keypair::new();
|
||||||
let (genesis_block, mint) =
|
let (genesis_block, mint) =
|
||||||
GenesisBlock::new_with_leader(20_000, leader_keypair.pubkey(), 123);
|
GenesisBlock::new_with_leader(20_000, &leader_keypair.pubkey(), 123);
|
||||||
|
|
||||||
assert_eq!(genesis_block.lamports, 20_000);
|
assert_eq!(genesis_block.lamports, 20_000);
|
||||||
assert_eq!(genesis_block.mint_id, mint.pubkey());
|
assert_eq!(genesis_block.mint_id, mint.pubkey());
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct LoaderTransaction {}
|
||||||
impl LoaderTransaction {
|
impl LoaderTransaction {
|
||||||
pub fn new_write(
|
pub fn new_write(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
loader: Pubkey,
|
loader: &Pubkey,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
|
@ -30,7 +30,7 @@ impl LoaderTransaction {
|
||||||
|
|
||||||
pub fn new_finalize(
|
pub fn new_finalize(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
loader: Pubkey,
|
loader: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
|
|
|
@ -26,28 +26,28 @@ pub enum SystemInstruction {
|
||||||
|
|
||||||
impl SystemInstruction {
|
impl SystemInstruction {
|
||||||
pub fn new_program_account(
|
pub fn new_program_account(
|
||||||
from_id: Pubkey,
|
from_id: &Pubkey,
|
||||||
to_id: Pubkey,
|
to_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
space: u64,
|
space: u64,
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> BuilderInstruction {
|
) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&SystemInstruction::CreateAccount {
|
&SystemInstruction::CreateAccount {
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
program_id,
|
program_id: *program_id,
|
||||||
},
|
},
|
||||||
vec![(from_id, true), (to_id, false)],
|
vec![(*from_id, true), (*to_id, false)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_move(from_id: Pubkey, to_id: Pubkey, lamports: u64) -> BuilderInstruction {
|
pub fn new_move(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> BuilderInstruction {
|
||||||
BuilderInstruction::new(
|
BuilderInstruction::new(
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&SystemInstruction::Move { lamports },
|
&SystemInstruction::Move { lamports },
|
||||||
vec![(from_id, true), (to_id, false)],
|
vec![(*from_id, true), (*to_id, false)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,22 @@ impl SystemTransaction {
|
||||||
/// Create and sign new SystemInstruction::CreateAccount transaction
|
/// Create and sign new SystemInstruction::CreateAccount transaction
|
||||||
pub fn new_program_account(
|
pub fn new_program_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
space: u64,
|
space: u64,
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let create = SystemInstruction::CreateAccount {
|
let create = SystemInstruction::CreateAccount {
|
||||||
lamports, //TODO, the lamports to allocate might need to be higher then 0 in the future
|
lamports, //TODO, the lamports to allocate might need to be higher then 0 in the future
|
||||||
space,
|
space,
|
||||||
program_id,
|
program_id: *program_id,
|
||||||
};
|
};
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[to],
|
&[*to],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&create,
|
&create,
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
fee,
|
fee,
|
||||||
|
@ -38,7 +38,7 @@ impl SystemTransaction {
|
||||||
/// Create and sign a transaction to create a system account
|
/// Create and sign a transaction to create a system account
|
||||||
pub fn new_account(
|
pub fn new_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -50,7 +50,7 @@ impl SystemTransaction {
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
lamports,
|
lamports,
|
||||||
0,
|
0,
|
||||||
program_id,
|
&program_id,
|
||||||
fee,
|
fee,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -58,14 +58,16 @@ impl SystemTransaction {
|
||||||
pub fn new_assign(
|
pub fn new_assign(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let assign = SystemInstruction::Assign { program_id };
|
let assign = SystemInstruction::Assign {
|
||||||
|
program_id: *program_id,
|
||||||
|
};
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[],
|
&[],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&assign,
|
&assign,
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
fee,
|
fee,
|
||||||
|
@ -74,7 +76,7 @@ impl SystemTransaction {
|
||||||
/// Create and sign new SystemInstruction::Move transaction
|
/// Create and sign new SystemInstruction::Move transaction
|
||||||
pub fn new_move(
|
pub fn new_move(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -82,8 +84,8 @@ impl SystemTransaction {
|
||||||
let move_lamports = SystemInstruction::Move { lamports };
|
let move_lamports = SystemInstruction::Move { lamports };
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[to],
|
&[*to],
|
||||||
system_program::id(),
|
&system_program::id(),
|
||||||
&move_lamports,
|
&move_lamports,
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
fee,
|
fee,
|
||||||
|
|
|
@ -99,12 +99,12 @@ impl Transaction {
|
||||||
pub fn new<S: Serialize, T: KeypairUtil>(
|
pub fn new<S: Serialize, T: KeypairUtil>(
|
||||||
from_keypair: &T,
|
from_keypair: &T,
|
||||||
transaction_keys: &[Pubkey],
|
transaction_keys: &[Pubkey],
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
userdata: &S,
|
userdata: &S,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let program_ids = vec![program_id];
|
let program_ids = vec![*program_id];
|
||||||
let accounts = (0..=transaction_keys.len() as u8).collect();
|
let accounts = (0..=transaction_keys.len() as u8).collect();
|
||||||
let instructions = vec![Instruction::new(0, userdata, accounts)];
|
let instructions = vec![Instruction::new(0, userdata, accounts)];
|
||||||
Self::new_with_instructions(
|
Self::new_with_instructions(
|
||||||
|
@ -119,12 +119,12 @@ impl Transaction {
|
||||||
pub fn new_unsigned<T: Serialize>(
|
pub fn new_unsigned<T: Serialize>(
|
||||||
from_pubkey: &Pubkey,
|
from_pubkey: &Pubkey,
|
||||||
transaction_keys: &[Pubkey],
|
transaction_keys: &[Pubkey],
|
||||||
program_id: Pubkey,
|
program_id: &Pubkey,
|
||||||
userdata: &T,
|
userdata: &T,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let program_ids = vec![program_id];
|
let program_ids = vec![*program_id];
|
||||||
let accounts = (0..=transaction_keys.len() as u8).collect();
|
let accounts = (0..=transaction_keys.len() as u8).collect();
|
||||||
let instructions = vec![Instruction::new(0, userdata, accounts)];
|
let instructions = vec![Instruction::new(0, userdata, accounts)];
|
||||||
let mut keys = vec![*from_pubkey];
|
let mut keys = vec![*from_pubkey];
|
||||||
|
@ -492,7 +492,7 @@ mod tests {
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&keypair,
|
&keypair,
|
||||||
&[keypair.pubkey(), to],
|
&[keypair.pubkey(), to],
|
||||||
program_id,
|
&program_id,
|
||||||
&(1u8, 2u8, 3u8),
|
&(1u8, 2u8, 3u8),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
99,
|
99,
|
||||||
|
@ -511,7 +511,7 @@ mod tests {
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&keypair,
|
&keypair,
|
||||||
&[keypair.pubkey(), to],
|
&[keypair.pubkey(), to],
|
||||||
program_id,
|
&program_id,
|
||||||
&(1u8, 2u8, 3u8),
|
&(1u8, 2u8, 3u8),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
99,
|
99,
|
||||||
|
@ -557,7 +557,7 @@ mod tests {
|
||||||
let tx = Transaction::new(
|
let tx = Transaction::new(
|
||||||
&keypair,
|
&keypair,
|
||||||
&[keypair.pubkey(), to],
|
&[keypair.pubkey(), to],
|
||||||
program_id,
|
&program_id,
|
||||||
&(1u8, 2u8, 3u8),
|
&(1u8, 2u8, 3u8),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
99,
|
99,
|
||||||
|
|
|
@ -8,8 +8,8 @@ use itertools::Itertools;
|
||||||
|
|
||||||
pub type BuilderInstruction = Instruction<Pubkey, (Pubkey, bool)>;
|
pub type BuilderInstruction = Instruction<Pubkey, (Pubkey, bool)>;
|
||||||
|
|
||||||
fn position(keys: &[Pubkey], key: Pubkey) -> u8 {
|
fn position(keys: &[Pubkey], key: &Pubkey) -> u8 {
|
||||||
keys.iter().position(|&k| k == key).unwrap() as u8
|
keys.iter().position(|k| k == key).unwrap() as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_instruction(
|
fn compile_instruction(
|
||||||
|
@ -17,13 +17,9 @@ fn compile_instruction(
|
||||||
keys: &[Pubkey],
|
keys: &[Pubkey],
|
||||||
program_ids: &[Pubkey],
|
program_ids: &[Pubkey],
|
||||||
) -> Instruction<u8, u8> {
|
) -> Instruction<u8, u8> {
|
||||||
let accounts: Vec<_> = ix
|
let accounts: Vec<_> = ix.accounts.iter().map(|(k, _)| position(keys, k)).collect();
|
||||||
.accounts
|
|
||||||
.iter()
|
|
||||||
.map(|&(k, _)| position(keys, k))
|
|
||||||
.collect();
|
|
||||||
Instruction {
|
Instruction {
|
||||||
program_ids_index: position(program_ids, ix.program_ids_index),
|
program_ids_index: position(program_ids, &ix.program_ids_index),
|
||||||
userdata: ix.userdata.clone(),
|
userdata: ix.userdata.clone(),
|
||||||
accounts,
|
accounts,
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) {
|
||||||
let timeout = 60 * 5;
|
let timeout = 60 * 5;
|
||||||
|
|
||||||
// describe the leader
|
// describe the leader
|
||||||
let leader_info = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let leader_info = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.clone());
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.clone());
|
||||||
|
|
||||||
// setup stakes
|
// setup stakes
|
||||||
|
@ -59,7 +59,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) {
|
||||||
chunk.into_iter().for_each(|i| {
|
chunk.into_iter().for_each(|i| {
|
||||||
//distribute neighbors across threads to maximize parallel compute
|
//distribute neighbors across threads to maximize parallel compute
|
||||||
let batch_ix = *i as usize % batches.len();
|
let batch_ix = *i as usize % batches.len();
|
||||||
let node = ContactInfo::new_localhost(Keypair::new().pubkey(), 0);
|
let node = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
|
||||||
stakes.insert(node.id, *i);
|
stakes.insert(node.id, *i);
|
||||||
cluster_info.insert_info(node.clone());
|
cluster_info.insert_info(node.clone());
|
||||||
let (s, r) = channel();
|
let (s, r) = channel();
|
||||||
|
@ -103,7 +103,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) {
|
||||||
while remaining > 0 {
|
while remaining > 0 {
|
||||||
for (id, (recv, r)) in batch.iter_mut() {
|
for (id, (recv, r)) in batch.iter_mut() {
|
||||||
assert!(now.elapsed().as_secs() < timeout, "Timed out");
|
assert!(now.elapsed().as_secs() < timeout, "Timed out");
|
||||||
cluster.gossip.set_self(*id);
|
cluster.gossip.set_self(&*id);
|
||||||
if !mapped_peers.contains_key(id) {
|
if !mapped_peers.contains_key(id) {
|
||||||
let (neighbors, children) = compute_retransmit_peers(
|
let (neighbors, children) = compute_retransmit_peers(
|
||||||
&stakes,
|
&stakes,
|
||||||
|
|
|
@ -17,42 +17,42 @@ use std::sync::{Arc, Mutex};
|
||||||
type Node = Arc<Mutex<CrdsGossip>>;
|
type Node = Arc<Mutex<CrdsGossip>>;
|
||||||
type Network = HashMap<Pubkey, Node>;
|
type Network = HashMap<Pubkey, Node>;
|
||||||
fn star_network_create(num: usize) -> Network {
|
fn star_network_create(num: usize) -> Network {
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let mut network: HashMap<_, _> = (1..num)
|
let mut network: HashMap<_, _> = (1..num)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let new =
|
let new =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let id = new.label().pubkey();
|
let id = new.label().pubkey();
|
||||||
let mut node = CrdsGossip::default();
|
let mut node = CrdsGossip::default();
|
||||||
node.crds.insert(new.clone(), 0).unwrap();
|
node.crds.insert(new.clone(), 0).unwrap();
|
||||||
node.crds.insert(entry.clone(), 0).unwrap();
|
node.crds.insert(entry.clone(), 0).unwrap();
|
||||||
node.set_self(id);
|
node.set_self(&id);
|
||||||
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut node = CrdsGossip::default();
|
let mut node = CrdsGossip::default();
|
||||||
let id = entry.label().pubkey();
|
let id = entry.label().pubkey();
|
||||||
node.crds.insert(entry.clone(), 0).unwrap();
|
node.crds.insert(entry.clone(), 0).unwrap();
|
||||||
node.set_self(id);
|
node.set_self(&id);
|
||||||
network.insert(id, Arc::new(Mutex::new(node)));
|
network.insert(id, Arc::new(Mutex::new(node)));
|
||||||
network
|
network
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rstar_network_create(num: usize) -> Network {
|
fn rstar_network_create(num: usize) -> Network {
|
||||||
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let mut origin = CrdsGossip::default();
|
let mut origin = CrdsGossip::default();
|
||||||
let id = entry.label().pubkey();
|
let id = entry.label().pubkey();
|
||||||
origin.crds.insert(entry.clone(), 0).unwrap();
|
origin.crds.insert(entry.clone(), 0).unwrap();
|
||||||
origin.set_self(id);
|
origin.set_self(&id);
|
||||||
let mut network: HashMap<_, _> = (1..num)
|
let mut network: HashMap<_, _> = (1..num)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let new =
|
let new =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let id = new.label().pubkey();
|
let id = new.label().pubkey();
|
||||||
let mut node = CrdsGossip::default();
|
let mut node = CrdsGossip::default();
|
||||||
node.crds.insert(new.clone(), 0).unwrap();
|
node.crds.insert(new.clone(), 0).unwrap();
|
||||||
origin.crds.insert(new.clone(), 0).unwrap();
|
origin.crds.insert(new.clone(), 0).unwrap();
|
||||||
node.set_self(id);
|
node.set_self(&id);
|
||||||
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -64,11 +64,11 @@ fn ring_network_create(num: usize) -> Network {
|
||||||
let mut network: HashMap<_, _> = (0..num)
|
let mut network: HashMap<_, _> = (0..num)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let new =
|
let new =
|
||||||
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
|
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
|
||||||
let id = new.label().pubkey();
|
let id = new.label().pubkey();
|
||||||
let mut node = CrdsGossip::default();
|
let mut node = CrdsGossip::default();
|
||||||
node.crds.insert(new.clone(), 0).unwrap();
|
node.crds.insert(new.clone(), 0).unwrap();
|
||||||
node.set_self(id);
|
node.set_self(&id);
|
||||||
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
(new.label().pubkey(), Arc::new(Mutex::new(node)))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -195,7 +195,7 @@ fn network_run_push(network: &mut Network, start: usize, end: usize) -> (usize,
|
||||||
let mut node = node.lock().unwrap();
|
let mut node = node.lock().unwrap();
|
||||||
let destination = node.id;
|
let destination = node.id;
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
node.process_prune_msg(*to, destination, &rsps, now, now)
|
node.process_prune_msg(&*to, &destination, &rsps, now, now)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -283,8 +283,8 @@ fn network_run_pull(
|
||||||
network.get(&from).map(|node| {
|
network.get(&from).map(|node| {
|
||||||
node.lock()
|
node.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mark_pull_request_creation_time(from, now);
|
.mark_pull_request_creation_time(&from, now);
|
||||||
overhead += node.lock().unwrap().process_pull_response(from, rsp, now);
|
overhead += node.lock().unwrap().process_pull_response(&from, rsp, now);
|
||||||
});
|
});
|
||||||
(bytes, msgs, overhead)
|
(bytes, msgs, overhead)
|
||||||
})
|
})
|
||||||
|
@ -374,7 +374,7 @@ fn test_prune_errors() {
|
||||||
let mut crds_gossip = CrdsGossip::default();
|
let mut crds_gossip = CrdsGossip::default();
|
||||||
crds_gossip.id = Pubkey::new(&[0; 32]);
|
crds_gossip.id = Pubkey::new(&[0; 32]);
|
||||||
let id = crds_gossip.id;
|
let id = crds_gossip.id;
|
||||||
let ci = ContactInfo::new_localhost(Pubkey::new(&[1; 32]), 0);
|
let ci = ContactInfo::new_localhost(&Pubkey::new(&[1; 32]), 0);
|
||||||
let prune_pubkey = Pubkey::new(&[2; 32]);
|
let prune_pubkey = Pubkey::new(&[2; 32]);
|
||||||
crds_gossip
|
crds_gossip
|
||||||
.crds
|
.crds
|
||||||
|
@ -384,18 +384,18 @@ fn test_prune_errors() {
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
//incorrect dest
|
//incorrect dest
|
||||||
let mut res = crds_gossip.process_prune_msg(
|
let mut res = crds_gossip.process_prune_msg(
|
||||||
ci.id,
|
&ci.id,
|
||||||
Pubkey::new(hash(&[1; 32]).as_ref()),
|
&Pubkey::new(hash(&[1; 32]).as_ref()),
|
||||||
&[prune_pubkey],
|
&[prune_pubkey],
|
||||||
now,
|
now,
|
||||||
now,
|
now,
|
||||||
);
|
);
|
||||||
assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination));
|
assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination));
|
||||||
//correct dest
|
//correct dest
|
||||||
res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, now);
|
res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, now);
|
||||||
res.unwrap();
|
res.unwrap();
|
||||||
//test timeout
|
//test timeout
|
||||||
let timeout = now + crds_gossip.push.prune_timeout * 2;
|
let timeout = now + crds_gossip.push.prune_timeout * 2;
|
||||||
res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, timeout);
|
res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, timeout);
|
||||||
assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout));
|
assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::time::Duration;
|
||||||
|
|
||||||
fn test_node(exit: &Arc<AtomicBool>) -> (Arc<RwLock<ClusterInfo>>, GossipService, UdpSocket) {
|
fn test_node(exit: &Arc<AtomicBool>) -> (Arc<RwLock<ClusterInfo>>, GossipService, UdpSocket) {
|
||||||
let keypair = Arc::new(Keypair::new());
|
let keypair = Arc::new(Keypair::new());
|
||||||
let mut test_node = Node::new_localhost_with_pubkey(keypair.pubkey());
|
let mut test_node = Node::new_localhost_with_pubkey(&keypair.pubkey());
|
||||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new(
|
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new(
|
||||||
test_node.info.clone(),
|
test_node.info.clone(),
|
||||||
keypair,
|
keypair,
|
||||||
|
@ -76,7 +76,7 @@ fn gossip_ring() -> result::Result<()> {
|
||||||
let x = (n + 1) % listen.len();
|
let x = (n + 1) % listen.len();
|
||||||
let mut xv = listen[x].0.write().unwrap();
|
let mut xv = listen[x].0.write().unwrap();
|
||||||
let yv = listen[y].0.read().unwrap();
|
let yv = listen[y].0.read().unwrap();
|
||||||
let mut d = yv.lookup(yv.id()).unwrap().clone();
|
let mut d = yv.lookup(&yv.id()).unwrap().clone();
|
||||||
d.wallclock = timestamp();
|
d.wallclock = timestamp();
|
||||||
xv.insert_info(d);
|
xv.insert_info(d);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ fn gossip_ring_large() -> result::Result<()> {
|
||||||
let x = (n + 1) % listen.len();
|
let x = (n + 1) % listen.len();
|
||||||
let mut xv = listen[x].0.write().unwrap();
|
let mut xv = listen[x].0.write().unwrap();
|
||||||
let yv = listen[y].0.read().unwrap();
|
let yv = listen[y].0.read().unwrap();
|
||||||
let mut d = yv.lookup(yv.id()).unwrap().clone();
|
let mut d = yv.lookup(&yv.id()).unwrap().clone();
|
||||||
d.wallclock = timestamp();
|
d.wallclock = timestamp();
|
||||||
xv.insert_info(d);
|
xv.insert_info(d);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ fn gossip_star() {
|
||||||
let y = (n + 1) % listen.len();
|
let y = (n + 1) % listen.len();
|
||||||
let mut xv = listen[x].0.write().unwrap();
|
let mut xv = listen[x].0.write().unwrap();
|
||||||
let yv = listen[y].0.read().unwrap();
|
let yv = listen[y].0.read().unwrap();
|
||||||
let mut yd = yv.lookup(yv.id()).unwrap().clone();
|
let mut yd = yv.lookup(&yv.id()).unwrap().clone();
|
||||||
yd.wallclock = timestamp();
|
yd.wallclock = timestamp();
|
||||||
xv.insert_info(yd);
|
xv.insert_info(yd);
|
||||||
trace!("star leader {}", &xv.id());
|
trace!("star leader {}", &xv.id());
|
||||||
|
@ -132,7 +132,7 @@ fn gossip_rstar() {
|
||||||
let num = listen.len();
|
let num = listen.len();
|
||||||
let xd = {
|
let xd = {
|
||||||
let xv = listen[0].0.read().unwrap();
|
let xv = listen[0].0.read().unwrap();
|
||||||
xv.lookup(xv.id()).unwrap().clone()
|
xv.lookup(&xv.id()).unwrap().clone()
|
||||||
};
|
};
|
||||||
trace!("rstar leader {}", xd.id);
|
trace!("rstar leader {}", xd.id);
|
||||||
for n in 0..(num - 1) {
|
for n in 0..(num - 1) {
|
||||||
|
|
|
@ -39,11 +39,11 @@ fn test_replicator_startup_basic() {
|
||||||
|
|
||||||
info!("starting leader node");
|
info!("starting leader node");
|
||||||
let leader_keypair = Arc::new(Keypair::new());
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
|
||||||
let leader_info = leader_node.info.clone();
|
let leader_info = leader_node.info.clone();
|
||||||
|
|
||||||
let (genesis_block, mint_keypair) =
|
let (genesis_block, mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42);
|
GenesisBlock::new_with_leader(1_000_000_000, &leader_info.id, 42);
|
||||||
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
||||||
|
@ -57,7 +57,7 @@ fn test_replicator_startup_basic() {
|
||||||
leader_node,
|
leader_node,
|
||||||
&leader_keypair,
|
&leader_keypair,
|
||||||
&leader_ledger_path,
|
&leader_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
None,
|
None,
|
||||||
&fullnode_config,
|
&fullnode_config,
|
||||||
|
@ -74,10 +74,10 @@ fn test_replicator_startup_basic() {
|
||||||
debug!("blockhash: {:?}", blockhash);
|
debug!("blockhash: {:?}", blockhash);
|
||||||
|
|
||||||
leader_client
|
leader_client
|
||||||
.transfer(10, &mint_keypair, validator_keypair.pubkey(), &blockhash)
|
.transfer(10, &mint_keypair, &validator_keypair.pubkey(), &blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
||||||
#[cfg(feature = "chacha")]
|
#[cfg(feature = "chacha")]
|
||||||
let validator_contact_info = validator_node.info.clone();
|
let validator_contact_info = validator_node.info.clone();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ fn test_replicator_startup_basic() {
|
||||||
validator_node,
|
validator_node,
|
||||||
&validator_keypair,
|
&validator_keypair,
|
||||||
&validator_ledger_path,
|
&validator_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
Some(&leader_info),
|
Some(&leader_info),
|
||||||
&fullnode_config,
|
&fullnode_config,
|
||||||
|
@ -98,7 +98,7 @@ fn test_replicator_startup_basic() {
|
||||||
debug!("transfer {}", i);
|
debug!("transfer {}", i);
|
||||||
let blockhash = leader_client.get_recent_blockhash();
|
let blockhash = leader_client.get_recent_blockhash();
|
||||||
let mut transaction =
|
let mut transaction =
|
||||||
SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, blockhash, 0);
|
SystemTransaction::new_account(&mint_keypair, &bob.pubkey(), 1, blockhash, 0);
|
||||||
leader_client
|
leader_client
|
||||||
.retry_transfer(&mint_keypair, &mut transaction, 5)
|
.retry_transfer(&mint_keypair, &mut transaction, 5)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -118,7 +118,7 @@ fn test_replicator_startup_basic() {
|
||||||
// Give the replicator some lamports
|
// Give the replicator some lamports
|
||||||
let mut tx = SystemTransaction::new_account(
|
let mut tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
replicator_keypair.pubkey(),
|
&replicator_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
blockhash,
|
blockhash,
|
||||||
0,
|
0,
|
||||||
|
@ -128,7 +128,7 @@ fn test_replicator_startup_basic() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
info!("starting replicator node");
|
info!("starting replicator node");
|
||||||
let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey());
|
let replicator_node = Node::new_localhost_with_pubkey(&replicator_keypair.pubkey());
|
||||||
let replicator_info = replicator_node.info.clone();
|
let replicator_info = replicator_node.info.clone();
|
||||||
|
|
||||||
let leader_info = ContactInfo::new_gossip_entry_point(&leader_info.gossip);
|
let leader_info = ContactInfo::new_gossip_entry_point(&leader_info.gossip);
|
||||||
|
@ -242,7 +242,7 @@ fn test_replicator_startup_leader_hang() {
|
||||||
let replicator_keypair = Arc::new(Keypair::new());
|
let replicator_keypair = Arc::new(Keypair::new());
|
||||||
|
|
||||||
info!("starting replicator node");
|
info!("starting replicator node");
|
||||||
let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey());
|
let replicator_node = Node::new_localhost_with_pubkey(&replicator_keypair.pubkey());
|
||||||
|
|
||||||
let fake_gossip = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
let fake_gossip = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
||||||
let leader_info = ContactInfo::new_gossip_entry_point(&fake_gossip);
|
let leader_info = ContactInfo::new_gossip_entry_point(&fake_gossip);
|
||||||
|
@ -272,11 +272,11 @@ fn test_replicator_startup_ledger_hang() {
|
||||||
let leader_keypair = Arc::new(Keypair::new());
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42);
|
GenesisBlock::new_with_leader(100, &leader_keypair.pubkey(), 42);
|
||||||
let (replicator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (replicator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
info!("starting leader node");
|
info!("starting leader node");
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
|
||||||
let leader_info = leader_node.info.clone();
|
let leader_info = leader_node.info.clone();
|
||||||
|
|
||||||
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
@ -290,7 +290,7 @@ fn test_replicator_startup_ledger_hang() {
|
||||||
leader_node,
|
leader_node,
|
||||||
&leader_keypair,
|
&leader_keypair,
|
||||||
&leader_ledger_path,
|
&leader_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
None,
|
None,
|
||||||
&fullnode_config,
|
&fullnode_config,
|
||||||
|
@ -298,13 +298,13 @@ fn test_replicator_startup_ledger_hang() {
|
||||||
|
|
||||||
let validator_keypair = Arc::new(Keypair::new());
|
let validator_keypair = Arc::new(Keypair::new());
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
||||||
|
|
||||||
let _ = Fullnode::new(
|
let _ = Fullnode::new(
|
||||||
validator_node,
|
validator_node,
|
||||||
&validator_keypair,
|
&validator_keypair,
|
||||||
&validator_ledger_path,
|
&validator_ledger_path,
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
voting_keypair,
|
voting_keypair,
|
||||||
Some(&leader_info),
|
Some(&leader_info),
|
||||||
&FullnodeConfig::default(),
|
&FullnodeConfig::default(),
|
||||||
|
@ -312,7 +312,7 @@ fn test_replicator_startup_ledger_hang() {
|
||||||
|
|
||||||
info!("starting replicator node");
|
info!("starting replicator node");
|
||||||
let bad_keys = Arc::new(Keypair::new());
|
let bad_keys = Arc::new(Keypair::new());
|
||||||
let mut replicator_node = Node::new_localhost_with_pubkey(bad_keys.pubkey());
|
let mut replicator_node = Node::new_localhost_with_pubkey(&bad_keys.pubkey());
|
||||||
|
|
||||||
// Pass bad TVU sockets to prevent successful ledger download
|
// Pass bad TVU sockets to prevent successful ledger download
|
||||||
replicator_node.sockets.tvu = vec![std::net::UdpSocket::bind("0.0.0.0:0").unwrap()];
|
replicator_node.sockets.tvu = vec![std::net::UdpSocket::bind("0.0.0.0:0").unwrap()];
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn test_rpc_send_tx() {
|
||||||
let blockhash = Hash::new(&blockhash_vec);
|
let blockhash = Hash::new(&blockhash_vec);
|
||||||
|
|
||||||
info!("blockhash: {:?}", blockhash);
|
info!("blockhash: {:?}", blockhash);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0);
|
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
let serial_tx = serialize(&tx).unwrap();
|
let serial_tx = serialize(&tx).unwrap();
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
|
@ -42,7 +42,7 @@ fn test_replay() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let leader = Node::new_localhost();
|
let leader = Node::new_localhost();
|
||||||
let target1_keypair = Keypair::new();
|
let target1_keypair = Keypair::new();
|
||||||
let target1 = Node::new_localhost_with_pubkey(target1_keypair.pubkey());
|
let target1 = Node::new_localhost_with_pubkey(&target1_keypair.pubkey());
|
||||||
let target2 = Node::new_localhost();
|
let target2 = Node::new_localhost();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ fn test_replay() {
|
||||||
let (poh_service_exit, poh_recorder, poh_service, _entry_receiver) =
|
let (poh_service_exit, poh_recorder, poh_service, _entry_receiver) =
|
||||||
create_test_recorder(&bank);
|
create_test_recorder(&bank);
|
||||||
let tvu = Tvu::new(
|
let tvu = Tvu::new(
|
||||||
voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
Some(Arc::new(voting_keypair)),
|
Some(Arc::new(voting_keypair)),
|
||||||
&Arc::new(RwLock::new(bank_forks)),
|
&Arc::new(RwLock::new(bank_forks)),
|
||||||
&bank_forks_info,
|
&bank_forks_info,
|
||||||
|
@ -144,7 +144,7 @@ fn test_replay() {
|
||||||
|
|
||||||
let tx0 = SystemTransaction::new_account(
|
let tx0 = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
bob_keypair.pubkey(),
|
&bob_keypair.pubkey(),
|
||||||
transfer_amount,
|
transfer_amount,
|
||||||
blockhash,
|
blockhash,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl {
|
||||||
signed_msg: Vec<u8>,
|
signed_msg: Vec<u8>,
|
||||||
) -> Result<Pubkey> {
|
) -> Result<Pubkey> {
|
||||||
info!("register rpc request received: {:?}", id);
|
info!("register rpc request received: {:?}", id);
|
||||||
meta.request_processor.register(id, &sig, &signed_msg)
|
meta.request_processor.register(&id, &sig, &signed_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign(
|
fn sign(
|
||||||
|
@ -96,7 +96,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl {
|
||||||
signed_msg: Vec<u8>,
|
signed_msg: Vec<u8>,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
info!("sign rpc request received: {:?}", id);
|
info!("sign rpc request received: {:?}", id);
|
||||||
meta.request_processor.sign(id, &sig, &signed_msg)
|
meta.request_processor.sign(&id, &sig, &signed_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deregister(
|
fn deregister(
|
||||||
|
@ -107,7 +107,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl {
|
||||||
signed_msg: Vec<u8>,
|
signed_msg: Vec<u8>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
info!("deregister rpc request received: {:?}", id);
|
info!("deregister rpc request received: {:?}", id);
|
||||||
meta.request_processor.deregister(id, &sig, &signed_msg)
|
meta.request_processor.deregister(&id, &sig, &signed_msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +120,9 @@ fn verify_signature(sig: &Signature, pubkey: &Pubkey, msg: &[u8]) -> Result<()>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VoteSigner {
|
pub trait VoteSigner {
|
||||||
fn register(&self, pubkey: Pubkey, sig: &Signature, signed_msg: &[u8]) -> Result<Pubkey>;
|
fn register(&self, pubkey: &Pubkey, sig: &Signature, signed_msg: &[u8]) -> Result<Pubkey>;
|
||||||
fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<Signature>;
|
fn sign(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<Signature>;
|
||||||
fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<()>;
|
fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -131,7 +131,7 @@ pub struct LocalVoteSigner {
|
||||||
}
|
}
|
||||||
impl VoteSigner for LocalVoteSigner {
|
impl VoteSigner for LocalVoteSigner {
|
||||||
/// Process JSON-RPC request items sent via JSON-RPC.
|
/// Process JSON-RPC request items sent via JSON-RPC.
|
||||||
fn register(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<Pubkey> {
|
fn register(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<Pubkey> {
|
||||||
verify_signature(&sig, &pubkey, &msg)?;
|
verify_signature(&sig, &pubkey, &msg)?;
|
||||||
{
|
{
|
||||||
if let Some(voting_keypair) = self.nodes.read().unwrap().get(&pubkey) {
|
if let Some(voting_keypair) = self.nodes.read().unwrap().get(&pubkey) {
|
||||||
|
@ -140,17 +140,17 @@ impl VoteSigner for LocalVoteSigner {
|
||||||
}
|
}
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
let voting_pubkey = voting_keypair.pubkey();
|
let voting_pubkey = voting_keypair.pubkey();
|
||||||
self.nodes.write().unwrap().insert(pubkey, voting_keypair);
|
self.nodes.write().unwrap().insert(*pubkey, voting_keypair);
|
||||||
Ok(voting_pubkey)
|
Ok(voting_pubkey)
|
||||||
}
|
}
|
||||||
fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<Signature> {
|
fn sign(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<Signature> {
|
||||||
verify_signature(&sig, &pubkey, &msg)?;
|
verify_signature(&sig, &pubkey, &msg)?;
|
||||||
match self.nodes.read().unwrap().get(&pubkey) {
|
match self.nodes.read().unwrap().get(&pubkey) {
|
||||||
Some(voting_keypair) => Ok(voting_keypair.sign_message(&msg)),
|
Some(voting_keypair) => Ok(voting_keypair.sign_message(&msg)),
|
||||||
None => Err(Error::invalid_request()),
|
None => Err(Error::invalid_request()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<()> {
|
fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<()> {
|
||||||
verify_signature(&sig, &pubkey, &msg)?;
|
verify_signature(&sig, &pubkey, &msg)?;
|
||||||
self.nodes.write().unwrap().remove(&pubkey);
|
self.nodes.write().unwrap().remove(&pubkey);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
|
||||||
)))
|
)))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let command = parse_command(id.pubkey(), &matches)?;
|
let command = parse_command(&id.pubkey(), &matches)?;
|
||||||
|
|
||||||
Ok(WalletConfig {
|
Ok(WalletConfig {
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl WalletConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_command(
|
pub fn parse_command(
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches<'_>,
|
||||||
) -> Result<WalletCommand, Box<dyn error::Error>> {
|
) -> Result<WalletCommand, Box<dyn error::Error>> {
|
||||||
let response = match matches.subcommand() {
|
let response = match matches.subcommand() {
|
||||||
|
@ -231,7 +231,7 @@ pub fn parse_command(
|
||||||
}
|
}
|
||||||
Pubkey::new(&pubkey_vec)
|
Pubkey::new(&pubkey_vec)
|
||||||
} else {
|
} else {
|
||||||
pubkey
|
*pubkey
|
||||||
};
|
};
|
||||||
let timestamp = if pay_matches.is_present("timestamp") {
|
let timestamp = if pay_matches.is_present("timestamp") {
|
||||||
// Parse input for serde_json
|
// Parse input for serde_json
|
||||||
|
@ -280,7 +280,7 @@ pub fn parse_command(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let cancelable = if pay_matches.is_present("cancelable") {
|
let cancelable = if pay_matches.is_present("cancelable") {
|
||||||
Some(pubkey)
|
Some(*pubkey)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -376,7 +376,7 @@ fn process_airdrop(
|
||||||
"Requesting airdrop of {:?} lamports from {}",
|
"Requesting airdrop of {:?} lamports from {}",
|
||||||
lamports, drone_addr
|
lamports, drone_addr
|
||||||
);
|
);
|
||||||
let previous_balance = match rpc_client.retry_get_balance(1, config.id.pubkey(), 5)? {
|
let previous_balance = match rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)? {
|
||||||
Some(lamports) => lamports,
|
Some(lamports) => lamports,
|
||||||
None => Err(WalletError::RpcRequestError(
|
None => Err(WalletError::RpcRequestError(
|
||||||
"Received result of an unexpected type".to_string(),
|
"Received result of an unexpected type".to_string(),
|
||||||
|
@ -386,7 +386,7 @@ fn process_airdrop(
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, lamports)?;
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, lamports)?;
|
||||||
|
|
||||||
let current_balance = rpc_client
|
let current_balance = rpc_client
|
||||||
.retry_get_balance(1, config.id.pubkey(), 5)?
|
.retry_get_balance(1, &config.id.pubkey(), 5)?
|
||||||
.unwrap_or(previous_balance);
|
.unwrap_or(previous_balance);
|
||||||
|
|
||||||
if current_balance < previous_balance {
|
if current_balance < previous_balance {
|
||||||
|
@ -406,7 +406,7 @@ fn process_airdrop(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_balance(config: &WalletConfig, rpc_client: &RpcClient) -> ProcessResult {
|
fn process_balance(config: &WalletConfig, rpc_client: &RpcClient) -> ProcessResult {
|
||||||
let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?;
|
let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?;
|
||||||
match balance {
|
match balance {
|
||||||
Some(0) => Ok("No account found! Request an airdrop to get started.".to_string()),
|
Some(0) => Ok("No account found! Request an airdrop to get started.".to_string()),
|
||||||
Some(lamports) => Ok(format!("Your balance is: {:?}", lamports)),
|
Some(lamports) => Ok(format!("Your balance is: {:?}", lamports)),
|
||||||
|
@ -445,14 +445,14 @@ fn process_configure_staking(
|
||||||
let mut tx = TransactionBuilder::new(0);
|
let mut tx = TransactionBuilder::new(0);
|
||||||
if let Some(delegate_id) = delegate_option {
|
if let Some(delegate_id) = delegate_option {
|
||||||
tx.push(VoteInstruction::new_delegate_stake(
|
tx.push(VoteInstruction::new_delegate_stake(
|
||||||
config.id.pubkey(),
|
&config.id.pubkey(),
|
||||||
delegate_id,
|
&delegate_id,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if let Some(authorized_voter_id) = authorized_voter_option {
|
if let Some(authorized_voter_id) = authorized_voter_option {
|
||||||
tx.push(VoteInstruction::new_authorize_voter(
|
tx.push(VoteInstruction::new_authorize_voter(
|
||||||
config.id.pubkey(),
|
&config.id.pubkey(),
|
||||||
authorized_voter_id,
|
&authorized_voter_id,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let mut tx = tx.sign(&[&config.id], recent_blockhash);
|
let mut tx = tx.sign(&[&config.id], recent_blockhash);
|
||||||
|
@ -463,7 +463,7 @@ fn process_configure_staking(
|
||||||
fn process_create_staking(
|
fn process_create_staking(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &WalletConfig,
|
config: &WalletConfig,
|
||||||
voting_account_id: Pubkey,
|
voting_account_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let recent_blockhash = get_recent_blockhash(&rpc_client)?;
|
let recent_blockhash = get_recent_blockhash(&rpc_client)?;
|
||||||
|
@ -478,7 +478,7 @@ fn process_deploy(
|
||||||
config: &WalletConfig,
|
config: &WalletConfig,
|
||||||
program_location: &str,
|
program_location: &str,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?;
|
let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?;
|
||||||
if let Some(lamports) = balance {
|
if let Some(lamports) = balance {
|
||||||
if lamports < 1 {
|
if lamports < 1 {
|
||||||
Err(WalletError::DynamicProgramError(
|
Err(WalletError::DynamicProgramError(
|
||||||
|
@ -503,11 +503,11 @@ fn process_deploy(
|
||||||
|
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
program_id.pubkey(),
|
&program_id.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
program_userdata.len() as u64,
|
program_userdata.len() as u64,
|
||||||
bpf_loader::id(),
|
&bpf_loader::id(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
trace!("Creating program account");
|
trace!("Creating program account");
|
||||||
|
@ -522,7 +522,7 @@ fn process_deploy(
|
||||||
.map(|(chunk, i)| {
|
.map(|(chunk, i)| {
|
||||||
LoaderTransaction::new_write(
|
LoaderTransaction::new_write(
|
||||||
&program_id,
|
&program_id,
|
||||||
bpf_loader::id(),
|
&bpf_loader::id(),
|
||||||
(i * USERDATA_CHUNK_SIZE) as u32,
|
(i * USERDATA_CHUNK_SIZE) as u32,
|
||||||
chunk.to_vec(),
|
chunk.to_vec(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -533,7 +533,7 @@ fn process_deploy(
|
||||||
send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?;
|
send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?;
|
||||||
|
|
||||||
trace!("Finalizing program account");
|
trace!("Finalizing program account");
|
||||||
let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), blockhash, 0);
|
let mut tx = LoaderTransaction::new_finalize(&program_id, &bpf_loader::id(), blockhash, 0);
|
||||||
send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
@ -548,7 +548,7 @@ fn process_pay(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &WalletConfig,
|
config: &WalletConfig,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
timestamp: Option<DateTime<Utc>>,
|
timestamp: Option<DateTime<Utc>>,
|
||||||
timestamp_pubkey: Option<Pubkey>,
|
timestamp_pubkey: Option<Pubkey>,
|
||||||
witnesses: &Option<Vec<Pubkey>>,
|
witnesses: &Option<Vec<Pubkey>>,
|
||||||
|
@ -573,9 +573,9 @@ fn process_pay(
|
||||||
let mut tx = BudgetTransaction::new_on_date(
|
let mut tx = BudgetTransaction::new_on_date(
|
||||||
&config.id,
|
&config.id,
|
||||||
to,
|
to,
|
||||||
contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
dt_pubkey,
|
&dt_pubkey,
|
||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -604,8 +604,8 @@ fn process_pay(
|
||||||
let mut tx = BudgetTransaction::new_when_signed(
|
let mut tx = BudgetTransaction::new_when_signed(
|
||||||
&config.id,
|
&config.id,
|
||||||
to,
|
to,
|
||||||
contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
witness,
|
&witness,
|
||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -622,10 +622,10 @@ fn process_pay(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult {
|
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey) -> ProcessResult {
|
||||||
let blockhash = get_recent_blockhash(&rpc_client)?;
|
let blockhash = get_recent_blockhash(&rpc_client)?;
|
||||||
let mut tx =
|
let mut tx =
|
||||||
BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), blockhash);
|
BudgetTransaction::new_signature(&config.id, pubkey, &config.id.pubkey(), blockhash);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
}
|
}
|
||||||
|
@ -646,11 +646,11 @@ fn process_time_elapsed(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &WalletConfig,
|
config: &WalletConfig,
|
||||||
drone_addr: SocketAddr,
|
drone_addr: SocketAddr,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?;
|
let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?;
|
||||||
|
|
||||||
if let Some(0) = balance {
|
if let Some(0) = balance {
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
||||||
|
@ -668,10 +668,10 @@ fn process_witness(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &WalletConfig,
|
config: &WalletConfig,
|
||||||
drone_addr: SocketAddr,
|
drone_addr: SocketAddr,
|
||||||
to: Pubkey,
|
to: &Pubkey,
|
||||||
pubkey: Pubkey,
|
pubkey: &Pubkey,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?;
|
let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?;
|
||||||
|
|
||||||
if let Some(0) = balance {
|
if let Some(0) = balance {
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
||||||
|
@ -712,7 +712,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||||
WalletCommand::Balance => process_balance(config, &rpc_client),
|
WalletCommand::Balance => process_balance(config, &rpc_client),
|
||||||
|
|
||||||
// Cancel a contract by contract Pubkey
|
// Cancel a contract by contract Pubkey
|
||||||
WalletCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, pubkey),
|
WalletCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey),
|
||||||
|
|
||||||
// Confirm the last client transaction by signature
|
// Confirm the last client transaction by signature
|
||||||
WalletCommand::Confirm(signature) => process_confirm(&rpc_client, signature),
|
WalletCommand::Confirm(signature) => process_confirm(&rpc_client, signature),
|
||||||
|
@ -729,7 +729,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||||
|
|
||||||
// Create staking account
|
// Create staking account
|
||||||
WalletCommand::CreateStakingAccount(voting_account_id, lamports) => {
|
WalletCommand::CreateStakingAccount(voting_account_id, lamports) => {
|
||||||
process_create_staking(&rpc_client, config, voting_account_id, lamports)
|
process_create_staking(&rpc_client, config, &voting_account_id, lamports)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy a custom program to the chain
|
// Deploy a custom program to the chain
|
||||||
|
@ -751,7 +751,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
lamports,
|
lamports,
|
||||||
to,
|
&to,
|
||||||
timestamp,
|
timestamp,
|
||||||
timestamp_pubkey,
|
timestamp_pubkey,
|
||||||
witnesses,
|
witnesses,
|
||||||
|
@ -760,12 +760,12 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||||
|
|
||||||
// Apply time elapsed to contract
|
// Apply time elapsed to contract
|
||||||
WalletCommand::TimeElapsed(to, pubkey, dt) => {
|
WalletCommand::TimeElapsed(to, pubkey, dt) => {
|
||||||
process_time_elapsed(&rpc_client, config, drone_addr, to, pubkey, dt)
|
process_time_elapsed(&rpc_client, config, drone_addr, &to, &pubkey, dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply witness signature to contract
|
// Apply witness signature to contract
|
||||||
WalletCommand::Witness(to, pubkey) => {
|
WalletCommand::Witness(to, pubkey) => {
|
||||||
process_witness(&rpc_client, config, drone_addr, to, pubkey)
|
process_witness(&rpc_client, config, drone_addr, &to, &pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1241,13 +1241,13 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "airdrop", "50"]);
|
.get_matches_from(vec!["test", "airdrop", "50"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_airdrop).unwrap(),
|
parse_command(&pubkey, &test_airdrop).unwrap(),
|
||||||
WalletCommand::Airdrop(50)
|
WalletCommand::Airdrop(50)
|
||||||
);
|
);
|
||||||
let test_bad_airdrop = test_commands
|
let test_bad_airdrop = test_commands
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "airdrop", "notint"]);
|
.get_matches_from(vec!["test", "airdrop", "notint"]);
|
||||||
assert!(parse_command(pubkey, &test_bad_airdrop).is_err());
|
assert!(parse_command(&pubkey, &test_bad_airdrop).is_err());
|
||||||
|
|
||||||
// Test Cancel Subcommand
|
// Test Cancel Subcommand
|
||||||
let test_cancel =
|
let test_cancel =
|
||||||
|
@ -1255,7 +1255,7 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "cancel", &pubkey_string]);
|
.get_matches_from(vec!["test", "cancel", &pubkey_string]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_cancel).unwrap(),
|
parse_command(&pubkey, &test_cancel).unwrap(),
|
||||||
WalletCommand::Cancel(pubkey)
|
WalletCommand::Cancel(pubkey)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1267,13 +1267,13 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "confirm", &signature_string]);
|
.get_matches_from(vec!["test", "confirm", &signature_string]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_confirm).unwrap(),
|
parse_command(&pubkey, &test_confirm).unwrap(),
|
||||||
WalletCommand::Confirm(signature)
|
WalletCommand::Confirm(signature)
|
||||||
);
|
);
|
||||||
let test_bad_signature = test_commands
|
let test_bad_signature = test_commands
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "confirm", "deadbeef"]);
|
.get_matches_from(vec!["test", "confirm", "deadbeef"]);
|
||||||
assert!(parse_command(pubkey, &test_bad_signature).is_err());
|
assert!(parse_command(&pubkey, &test_bad_signature).is_err());
|
||||||
|
|
||||||
// Test ConfigureStakingAccount Subcommand
|
// Test ConfigureStakingAccount Subcommand
|
||||||
let second_pubkey = Keypair::new().pubkey();
|
let second_pubkey = Keypair::new().pubkey();
|
||||||
|
@ -1287,7 +1287,7 @@ mod tests {
|
||||||
&second_pubkey_string,
|
&second_pubkey_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_configure_staking_account).unwrap(),
|
parse_command(&pubkey, &test_configure_staking_account).unwrap(),
|
||||||
WalletCommand::ConfigureStakingAccount(Some(pubkey), Some(second_pubkey))
|
WalletCommand::ConfigureStakingAccount(Some(pubkey), Some(second_pubkey))
|
||||||
);
|
);
|
||||||
let test_configure_staking_account = test_commands.clone().get_matches_from(vec![
|
let test_configure_staking_account = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1297,7 +1297,7 @@ mod tests {
|
||||||
&pubkey_string,
|
&pubkey_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_configure_staking_account).unwrap(),
|
parse_command(&pubkey, &test_configure_staking_account).unwrap(),
|
||||||
WalletCommand::ConfigureStakingAccount(Some(pubkey), None)
|
WalletCommand::ConfigureStakingAccount(Some(pubkey), None)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1309,7 +1309,7 @@ mod tests {
|
||||||
"50",
|
"50",
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_create_staking_account).unwrap(),
|
parse_command(&pubkey, &test_create_staking_account).unwrap(),
|
||||||
WalletCommand::CreateStakingAccount(pubkey, 50)
|
WalletCommand::CreateStakingAccount(pubkey, 50)
|
||||||
);
|
);
|
||||||
let test_bad_pubkey = test_commands.clone().get_matches_from(vec![
|
let test_bad_pubkey = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1318,7 +1318,7 @@ mod tests {
|
||||||
"deadbeef",
|
"deadbeef",
|
||||||
"50",
|
"50",
|
||||||
]);
|
]);
|
||||||
assert!(parse_command(pubkey, &test_bad_pubkey).is_err());
|
assert!(parse_command(&pubkey, &test_bad_pubkey).is_err());
|
||||||
|
|
||||||
// Test Deploy Subcommand
|
// Test Deploy Subcommand
|
||||||
let test_deploy =
|
let test_deploy =
|
||||||
|
@ -1326,7 +1326,7 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "deploy", "/Users/test/program.o"]);
|
.get_matches_from(vec!["test", "deploy", "/Users/test/program.o"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_deploy).unwrap(),
|
parse_command(&pubkey, &test_deploy).unwrap(),
|
||||||
WalletCommand::Deploy("/Users/test/program.o".to_string())
|
WalletCommand::Deploy("/Users/test/program.o".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1336,13 +1336,13 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "pay", &pubkey_string, "50"]);
|
.get_matches_from(vec!["test", "pay", &pubkey_string, "50"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_pay).unwrap(),
|
parse_command(&pubkey, &test_pay).unwrap(),
|
||||||
WalletCommand::Pay(50, pubkey, None, None, None, None)
|
WalletCommand::Pay(50, pubkey, None, None, None, None)
|
||||||
);
|
);
|
||||||
let test_bad_pubkey = test_commands
|
let test_bad_pubkey = test_commands
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "pay", "deadbeef", "50"]);
|
.get_matches_from(vec!["test", "pay", "deadbeef", "50"]);
|
||||||
assert!(parse_command(pubkey, &test_bad_pubkey).is_err());
|
assert!(parse_command(&pubkey, &test_bad_pubkey).is_err());
|
||||||
|
|
||||||
// Test Pay Subcommand w/ Witness
|
// Test Pay Subcommand w/ Witness
|
||||||
let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![
|
let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1356,7 +1356,7 @@ mod tests {
|
||||||
&witness1_string,
|
&witness1_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_pay_multiple_witnesses).unwrap(),
|
parse_command(&pubkey, &test_pay_multiple_witnesses).unwrap(),
|
||||||
WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0, witness1]), None)
|
WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0, witness1]), None)
|
||||||
);
|
);
|
||||||
let test_pay_single_witness = test_commands.clone().get_matches_from(vec![
|
let test_pay_single_witness = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1368,7 +1368,7 @@ mod tests {
|
||||||
&witness0_string,
|
&witness0_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_pay_single_witness).unwrap(),
|
parse_command(&pubkey, &test_pay_single_witness).unwrap(),
|
||||||
WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0]), None)
|
WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0]), None)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1384,7 +1384,7 @@ mod tests {
|
||||||
&witness0_string,
|
&witness0_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_pay_timestamp).unwrap(),
|
parse_command(&pubkey, &test_pay_timestamp).unwrap(),
|
||||||
WalletCommand::Pay(50, pubkey, Some(dt), Some(witness0), None, None)
|
WalletCommand::Pay(50, pubkey, Some(dt), Some(witness0), None, None)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1396,7 +1396,7 @@ mod tests {
|
||||||
&pubkey_string,
|
&pubkey_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_send_signature).unwrap(),
|
parse_command(&pubkey, &test_send_signature).unwrap(),
|
||||||
WalletCommand::Witness(pubkey, pubkey)
|
WalletCommand::Witness(pubkey, pubkey)
|
||||||
);
|
);
|
||||||
let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![
|
let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1414,7 +1414,7 @@ mod tests {
|
||||||
&witness1_string,
|
&witness1_string,
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_pay_multiple_witnesses).unwrap(),
|
parse_command(&pubkey, &test_pay_multiple_witnesses).unwrap(),
|
||||||
WalletCommand::Pay(
|
WalletCommand::Pay(
|
||||||
50,
|
50,
|
||||||
pubkey,
|
pubkey,
|
||||||
|
@ -1435,7 +1435,7 @@ mod tests {
|
||||||
"2018-09-19T17:30:59",
|
"2018-09-19T17:30:59",
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(pubkey, &test_send_timestamp).unwrap(),
|
parse_command(&pubkey, &test_send_timestamp).unwrap(),
|
||||||
WalletCommand::TimeElapsed(pubkey, pubkey, dt)
|
WalletCommand::TimeElapsed(pubkey, pubkey, dt)
|
||||||
);
|
);
|
||||||
let test_bad_timestamp = test_commands.clone().get_matches_from(vec![
|
let test_bad_timestamp = test_commands.clone().get_matches_from(vec![
|
||||||
|
@ -1446,7 +1446,7 @@ mod tests {
|
||||||
"--date",
|
"--date",
|
||||||
"20180919T17:30:59",
|
"20180919T17:30:59",
|
||||||
]);
|
]);
|
||||||
assert!(parse_command(pubkey, &test_bad_timestamp).is_err());
|
assert!(parse_command(&pubkey, &test_bad_timestamp).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1688,7 +1688,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0);
|
let tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
let signature = send_transaction(&rpc_client, &tx);
|
let signature = send_transaction(&rpc_client, &tx);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
@ -1724,7 +1724,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let mut tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0);
|
let mut tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
let signer = Keypair::new();
|
let signer = Keypair::new();
|
||||||
|
|
||||||
|
@ -1750,8 +1750,8 @@ mod tests {
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let blockhash = Hash::new(&vec);
|
let blockhash = Hash::new(&vec);
|
||||||
let prev_tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0);
|
let prev_tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0);
|
||||||
let mut tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0);
|
let mut tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
resign_transaction(&rpc_client, &mut tx, &key).unwrap();
|
resign_transaction(&rpc_client, &mut tx, &key).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use std::sync::mpsc::channel;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use solana::thin_client::new_fullnode;
|
use solana::thin_client::new_fullnode;
|
||||||
|
|
||||||
fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: Pubkey) {
|
fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
|
||||||
let balance = client.retry_get_balance(1, pubkey, 1).unwrap().unwrap();
|
let balance = client.retry_get_balance(1, pubkey, 1).unwrap().unwrap();
|
||||||
assert_eq!(balance, expected_balance);
|
assert_eq!(balance, expected_balance);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ fn test_wallet_timestamp_tx() {
|
||||||
assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey());
|
assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config_payer.id, 50).unwrap();
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config_payer.id, 50).unwrap();
|
||||||
check_balance(50, &rpc_client, config_payer.id.pubkey());
|
check_balance(50, &rpc_client, &config_payer.id.pubkey());
|
||||||
|
|
||||||
// Make transaction (from config_payer to bob_pubkey) requiring timestamp from config_witness
|
// Make transaction (from config_payer to bob_pubkey) requiring timestamp from config_witness
|
||||||
let date_string = "\"2018-09-19T17:30:59Z\"";
|
let date_string = "\"2018-09-19T17:30:59Z\"";
|
||||||
|
@ -62,17 +62,17 @@ fn test_wallet_timestamp_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, process_id); // contract balance
|
check_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_witness.command = WalletCommand::TimeElapsed(bob_pubkey, process_id, dt);
|
config_witness.command = WalletCommand::TimeElapsed(bob_pubkey, process_id, dt);
|
||||||
process_command(&config_witness).unwrap();
|
process_command(&config_witness).unwrap();
|
||||||
|
|
||||||
check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, process_id); // contract balance
|
check_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(10, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -119,17 +119,17 @@ fn test_wallet_witness_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, process_id); // contract balance
|
check_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_witness.command = WalletCommand::Witness(bob_pubkey, process_id);
|
config_witness.command = WalletCommand::Witness(bob_pubkey, process_id);
|
||||||
process_command(&config_witness).unwrap();
|
process_command(&config_witness).unwrap();
|
||||||
|
|
||||||
check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, process_id); // contract balance
|
check_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(10, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -176,17 +176,17 @@ fn test_wallet_cancel_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, process_id); // contract balance
|
check_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_payer.command = WalletCommand::Cancel(process_id);
|
config_payer.command = WalletCommand::Cancel(process_id);
|
||||||
process_command(&config_payer).unwrap();
|
process_command(&config_payer).unwrap();
|
||||||
|
|
||||||
check_balance(50, &rpc_client, config_payer.id.pubkey()); // config_payer balance
|
check_balance(50, &rpc_client, &config_payer.id.pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, process_id); // contract balance
|
check_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, bob_pubkey); // recipient balance
|
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn test_wallet_request_airdrop() {
|
||||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||||
|
|
||||||
let balance = rpc_client
|
let balance = rpc_client
|
||||||
.retry_get_balance(1, bob_config.id.pubkey(), 1)
|
.retry_get_balance(1, &bob_config.id.pubkey(), 1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(balance, 50);
|
assert_eq!(balance, 50);
|
||||||
|
|
Loading…
Reference in New Issue