cargo fmt
This commit is contained in:
parent
85159a0eb4
commit
0f1582c196
|
@ -100,7 +100,11 @@ pub fn sample_tx_count(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send loopback payment of 0 tokens and confirm the network processed it
|
/// Send loopback payment of 0 tokens and confirm the network processed it
|
||||||
pub fn send_barrier_transaction(barrier_client: &mut ThinClient, block_hash: &mut Hash, id: &Keypair) {
|
pub fn send_barrier_transaction(
|
||||||
|
barrier_client: &mut ThinClient,
|
||||||
|
block_hash: &mut Hash,
|
||||||
|
id: &Keypair,
|
||||||
|
) {
|
||||||
let transfer_start = Instant::now();
|
let transfer_start = Instant::now();
|
||||||
|
|
||||||
let mut poll_count = 0;
|
let mut poll_count = 0;
|
||||||
|
|
|
@ -464,7 +464,8 @@ mod tests {
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
// 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 = SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, block_hash, 0);
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, block_hash, 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);
|
||||||
|
@ -547,11 +548,21 @@ mod tests {
|
||||||
let block_hash = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
|
|
||||||
// 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 =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 2, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair1.pubkey(),
|
||||||
|
2,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
||||||
let tx =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 2, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair2.pubkey(),
|
||||||
|
2,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
||||||
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
||||||
|
@ -594,7 +605,13 @@ mod tests {
|
||||||
&entry_1_to_mint.hash,
|
&entry_1_to_mint.hash,
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 2, bank.last_block_hash(), 0), // should be fine
|
SystemTransaction::new_account(
|
||||||
|
&keypair2,
|
||||||
|
keypair3.pubkey(),
|
||||||
|
2,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
), // should be fine
|
||||||
SystemTransaction::new_account(
|
SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
mint_keypair.pubkey(),
|
mint_keypair.pubkey(),
|
||||||
|
@ -625,18 +642,40 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair1.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair2.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
||||||
let block_hash = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(
|
||||||
|
&keypair1,
|
||||||
|
keypair3.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_account(&keypair2, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(
|
||||||
|
&keypair2,
|
||||||
|
keypair4.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
||||||
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
||||||
|
@ -654,11 +693,21 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair1.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx =
|
let tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
|
&mint_keypair,
|
||||||
|
keypair2.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
let block_hash = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
|
@ -670,7 +719,13 @@ mod tests {
|
||||||
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, block_hash, 0);
|
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, block_hash, 0);
|
||||||
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 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(&keypair1, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(
|
||||||
|
&keypair1,
|
||||||
|
keypair4.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_2 = next_entry(&tick.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&tick.hash, 1, vec![tx]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
par_process_entries(&bank, &[entry_1.clone(), tick.clone(), entry_2.clone()]),
|
par_process_entries(&bank, &[entry_1.clone(), tick.clone(), entry_2.clone()]),
|
||||||
|
@ -680,7 +735,13 @@ mod tests {
|
||||||
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
||||||
|
|
||||||
// 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(&keypair2, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(
|
||||||
|
&keypair2,
|
||||||
|
keypair3.pubkey(),
|
||||||
|
1,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry_3 = next_entry(&entry_2.hash, 1, vec![tx]);
|
let entry_3 = next_entry(&entry_2.hash, 1, vec![tx]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
par_process_entries(&bank, &[entry_3]),
|
par_process_entries(&bank, &[entry_3]),
|
||||||
|
|
|
@ -124,7 +124,11 @@ impl Fullnode {
|
||||||
let bank_info = &bank_forks_info[0];
|
let bank_info = &bank_forks_info[0];
|
||||||
let bank = bank_forks[bank_info.bank_id].clone();
|
let bank = bank_forks[bank_info.bank_id].clone();
|
||||||
|
|
||||||
info!("starting PoH... {} {}", bank.tick_height(), bank.last_block_hash(),);
|
info!(
|
||||||
|
"starting PoH... {} {}",
|
||||||
|
bank.tick_height(),
|
||||||
|
bank.last_block_hash(),
|
||||||
|
);
|
||||||
let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(
|
let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(
|
||||||
bank.tick_height(),
|
bank.tick_height(),
|
||||||
bank.last_block_hash(),
|
bank.last_block_hash(),
|
||||||
|
@ -441,8 +445,13 @@ pub fn make_active_set_entries(
|
||||||
num_ending_ticks: u64,
|
num_ending_ticks: u64,
|
||||||
) -> (Vec<Entry>, VotingKeypair) {
|
) -> (Vec<Entry>, VotingKeypair) {
|
||||||
// 1) Assume the active_keypair node has no tokens staked
|
// 1) Assume the active_keypair node has no tokens staked
|
||||||
let transfer_tx =
|
let transfer_tx = SystemTransaction::new_account(
|
||||||
SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *block_hash, 0);
|
&token_source,
|
||||||
|
active_keypair.pubkey(),
|
||||||
|
stake,
|
||||||
|
*block_hash,
|
||||||
|
0,
|
||||||
|
);
|
||||||
let mut last_entry_hash = *block_hash;
|
let mut last_entry_hash = *block_hash;
|
||||||
let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]);
|
let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]);
|
||||||
|
|
||||||
|
@ -455,7 +464,8 @@ pub fn make_active_set_entries(
|
||||||
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
||||||
|
|
||||||
// 3) Create vote entry
|
// 3) Create vote entry
|
||||||
let vote_tx = VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *block_hash, 0);
|
let vote_tx =
|
||||||
|
VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *block_hash, 0);
|
||||||
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
||||||
|
|
||||||
// 4) Create `num_ending_ticks` empty ticks
|
// 4) Create `num_ending_ticks` empty ticks
|
||||||
|
|
|
@ -206,7 +206,9 @@ impl ReplayStage {
|
||||||
progress: &mut HashMap<u64, (Hash, usize)>,
|
progress: &mut HashMap<u64, (Hash, usize)>,
|
||||||
) -> result::Result<(Vec<Entry>, usize)> {
|
) -> result::Result<(Vec<Entry>, usize)> {
|
||||||
let bank_id = bank.slot();
|
let bank_id = bank.slot();
|
||||||
let bank_progress = &mut progress.entry(bank_id).or_insert((bank.last_block_hash(), 0));
|
let bank_progress = &mut progress
|
||||||
|
.entry(bank_id)
|
||||||
|
.or_insert((bank.last_block_hash(), 0));
|
||||||
blocktree.get_slot_entries_with_blob_count(bank_id, bank_progress.1 as u64, None)
|
blocktree.get_slot_entries_with_blob_count(bank_id, bank_progress.1 as u64, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +219,9 @@ impl ReplayStage {
|
||||||
forward_entry_sender: &EntrySender,
|
forward_entry_sender: &EntrySender,
|
||||||
num: usize,
|
num: usize,
|
||||||
) -> result::Result<()> {
|
) -> result::Result<()> {
|
||||||
let bank_progress = &mut progress.entry(bank.slot()).or_insert((bank.last_block_hash(), 0));
|
let bank_progress = &mut progress
|
||||||
|
.entry(bank.slot())
|
||||||
|
.or_insert((bank.last_block_hash(), 0));
|
||||||
let result = Self::verify_and_process_entries(&bank, &entries, &bank_progress.0);
|
let result = Self::verify_and_process_entries(&bank, &entries, &bank_progress.0);
|
||||||
bank_progress.1 += num;
|
bank_progress.1 += num;
|
||||||
if let Some(last_entry) = entries.last() {
|
if let Some(last_entry) = entries.last() {
|
||||||
|
|
|
@ -211,7 +211,10 @@ impl RpcSol for RpcSolImpl {
|
||||||
|
|
||||||
fn get_recent_block_hash(&self, meta: Self::Metadata) -> Result<String> {
|
fn get_recent_block_hash(&self, meta: Self::Metadata) -> Result<String> {
|
||||||
info!("get_recent_block_hash rpc request received");
|
info!("get_recent_block_hash rpc request received");
|
||||||
meta.request_processor.read().unwrap().get_recent_block_hash()
|
meta.request_processor
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.get_recent_block_hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_signature_status(&self, meta: Self::Metadata, id: String) -> Result<RpcSignatureStatus> {
|
fn get_signature_status(&self, meta: Self::Metadata, id: String) -> Result<RpcSignatureStatus> {
|
||||||
|
@ -255,12 +258,19 @@ impl RpcSol for RpcSolImpl {
|
||||||
trace!("request_airdrop id={} tokens={}", id, tokens);
|
trace!("request_airdrop id={} tokens={}", id, tokens);
|
||||||
let pubkey = verify_pubkey(id)?;
|
let pubkey = verify_pubkey(id)?;
|
||||||
|
|
||||||
let block_hash = meta.request_processor.read().unwrap().bank()?.last_block_hash();
|
let block_hash = meta
|
||||||
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, block_hash)
|
.request_processor
|
||||||
.map_err(|err| {
|
.read()
|
||||||
info!("request_airdrop_transaction failed: {:?}", err);
|
.unwrap()
|
||||||
Error::internal_error()
|
.bank()?
|
||||||
})?;;
|
.last_block_hash();
|
||||||
|
let transaction =
|
||||||
|
request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, block_hash).map_err(
|
||||||
|
|err| {
|
||||||
|
info!("request_airdrop_transaction failed: {:?}", err);
|
||||||
|
Error::internal_error()
|
||||||
|
},
|
||||||
|
)?;;
|
||||||
|
|
||||||
let data = serialize(&transaction).map_err(|err| {
|
let data = serialize(&transaction).map_err(|err| {
|
||||||
info!("request_airdrop: serialize error: {:?}", err);
|
info!("request_airdrop: serialize error: {:?}", err);
|
||||||
|
|
|
@ -220,9 +220,9 @@ impl ThinClient {
|
||||||
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
|
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
|
||||||
loop {
|
loop {
|
||||||
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
||||||
let response = self
|
let response =
|
||||||
.rpc_client
|
self.rpc_client
|
||||||
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
|
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
|
@ -514,7 +514,9 @@ mod tests {
|
||||||
let block_hash = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
info!("test_thin_client block_hash: {:?}", block_hash);
|
info!("test_thin_client block_hash: {:?}", block_hash);
|
||||||
|
|
||||||
let signature = client.transfer(500, &alice, bob_pubkey, &block_hash).unwrap();
|
let signature = client
|
||||||
|
.transfer(500, &alice, bob_pubkey, &block_hash)
|
||||||
|
.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();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ use std::thread;
|
||||||
|
|
||||||
pub struct TvuRotationInfo {
|
pub struct TvuRotationInfo {
|
||||||
pub tick_height: u64, // tick height, bank might not exist yet
|
pub tick_height: u64, // tick height, bank might not exist yet
|
||||||
pub block_hash: Hash, // block_hash that was voted on
|
pub block_hash: Hash, // block_hash that was voted on
|
||||||
pub slot: u64, // slot height to initiate a rotation
|
pub slot: u64, // slot height to initiate a rotation
|
||||||
pub leader_id: Pubkey, // leader upon rotation
|
pub leader_id: Pubkey, // leader upon rotation
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ impl<'a> RewardsBank<'a> {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let block_hash = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
let tx =
|
||||||
|
VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,12 @@ fn test_bank_storage() {
|
||||||
|
|
||||||
bank.register_tick(&block_hash);
|
bank.register_tick(&block_hash);
|
||||||
|
|
||||||
bank.transfer(10, &alice, jill.pubkey(), block_hash).unwrap();
|
bank.transfer(10, &alice, jill.pubkey(), block_hash)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
bank.transfer(10, &alice, bob.pubkey(), block_hash).unwrap();
|
bank.transfer(10, &alice, bob.pubkey(), block_hash).unwrap();
|
||||||
bank.transfer(10, &alice, jack.pubkey(), block_hash).unwrap();
|
bank.transfer(10, &alice, jack.pubkey(), block_hash)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
|
@ -94,5 +96,8 @@ fn test_bank_storage() {
|
||||||
get_storage_entry_height(&bank, bob.pubkey()),
|
get_storage_entry_height(&bank, bob.pubkey()),
|
||||||
ENTRIES_PER_SEGMENT
|
ENTRIES_PER_SEGMENT
|
||||||
);
|
);
|
||||||
assert_eq!(get_storage_block_hash(&bank, bob.pubkey()), storage_block_hash);
|
assert_eq!(
|
||||||
|
get_storage_block_hash(&bank, bob.pubkey()),
|
||||||
|
storage_block_hash
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ impl<'a> VoteBank<'a> {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let block_hash = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
let tx =
|
||||||
|
VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ fn load_program(bank: &Bank, from: &Keypair, loader_id: Pubkey, program: Vec<u8>
|
||||||
offset += chunk_size as u32;
|
offset += chunk_size as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = LoaderTransaction::new_finalize(&program_account, loader_id, bank.last_block_hash(), 0);
|
let tx =
|
||||||
|
LoaderTransaction::new_finalize(&program_account, loader_id, bank.last_block_hash(), 0);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
||||||
|
|
||||||
|
@ -57,7 +58,14 @@ fn test_program_native_noop() {
|
||||||
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(&mint_keypair, &[], program_id, &1u8, bank.last_block_hash(), 0);
|
let tx = Transaction::new(
|
||||||
|
&mint_keypair,
|
||||||
|
&[],
|
||||||
|
program_id,
|
||||||
|
&1u8,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
||||||
}
|
}
|
||||||
|
@ -73,7 +81,14 @@ fn test_program_native_failure() {
|
||||||
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(&mint_keypair, &[], program_id, &1u8, bank.last_block_hash(), 0);
|
let tx = Transaction::new(
|
||||||
|
&mint_keypair,
|
||||||
|
&[],
|
||||||
|
program_id,
|
||||||
|
&1u8,
|
||||||
|
bank.last_block_hash(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::ProgramError(0, ProgramError::GenericError))
|
Err(BankError::ProgramError(0, ProgramError::GenericError))
|
||||||
|
|
|
@ -32,7 +32,8 @@ fn bench_process_transaction(bencher: &mut Bencher) {
|
||||||
|
|
||||||
// Seed the 'to' account and a cell for its signature.
|
// Seed the 'to' account and a cell for its signature.
|
||||||
let rando1 = Keypair::new();
|
let rando1 = Keypair::new();
|
||||||
let tx = SystemTransaction::new_move(&rando0, rando1.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx =
|
||||||
|
SystemTransaction::new_move(&rando0, rando1.pubkey(), 1, bank.last_block_hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// Finally, return the transaction to the benchmark.
|
// Finally, return the transaction to the benchmark.
|
||||||
|
|
|
@ -34,7 +34,12 @@ impl BudgetTransaction {
|
||||||
|
|
||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// Create and sign a new Transaction. Used for unit-testing.
|
||||||
#[allow(clippy::new_ret_no_self)]
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, recent_block_hash: Hash) -> Transaction {
|
pub fn new(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
to: Pubkey,
|
||||||
|
tokens: u64,
|
||||||
|
recent_block_hash: Hash,
|
||||||
|
) -> Transaction {
|
||||||
Self::new_payment(from_keypair, to, tokens, recent_block_hash, 0)
|
Self::new_payment(from_keypair, to, tokens, recent_block_hash, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,14 @@ impl LoaderTransaction {
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let instruction = LoaderInstruction::Write { offset, bytes };
|
let instruction = LoaderInstruction::Write { offset, bytes };
|
||||||
Transaction::new(from_keypair, &[], loader, &instruction, recent_block_hash, fee)
|
Transaction::new(
|
||||||
|
from_keypair,
|
||||||
|
&[],
|
||||||
|
loader,
|
||||||
|
&instruction,
|
||||||
|
recent_block_hash,
|
||||||
|
fee,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_finalize(
|
pub fn new_finalize(
|
||||||
|
@ -28,6 +35,13 @@ impl LoaderTransaction {
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let instruction = LoaderInstruction::Finalize;
|
let instruction = LoaderInstruction::Finalize;
|
||||||
Transaction::new(from_keypair, &[], loader, &instruction, recent_block_hash, fee)
|
Transaction::new(
|
||||||
|
from_keypair,
|
||||||
|
&[],
|
||||||
|
loader,
|
||||||
|
&instruction,
|
||||||
|
recent_block_hash,
|
||||||
|
fee,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,15 @@ impl SystemTransaction {
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program_id = system_program::id();
|
let program_id = system_program::id();
|
||||||
Self::new_program_account(from_keypair, to, recent_block_hash, tokens, 0, program_id, fee)
|
Self::new_program_account(
|
||||||
|
from_keypair,
|
||||||
|
to,
|
||||||
|
recent_block_hash,
|
||||||
|
tokens,
|
||||||
|
0,
|
||||||
|
program_id,
|
||||||
|
fee,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemInstruction::Assign transaction
|
/// Create and sign new SystemInstruction::Assign transaction
|
||||||
pub fn new_assign(
|
pub fn new_assign(
|
||||||
|
|
|
@ -332,7 +332,8 @@ impl Serialize for Transaction {
|
||||||
.map_err(Error::custom)?;
|
.map_err(Error::custom)?;
|
||||||
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
|
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
|
||||||
.map_err(Error::custom)?;
|
.map_err(Error::custom)?;
|
||||||
wr.write_all(self.recent_block_hash.as_ref()).map_err(Error::custom)?;
|
wr.write_all(self.recent_block_hash.as_ref())
|
||||||
|
.map_err(Error::custom)?;
|
||||||
wr.write_u64::<LittleEndian>(self.fee)
|
wr.write_u64::<LittleEndian>(self.fee)
|
||||||
.map_err(Error::custom)?;
|
.map_err(Error::custom)?;
|
||||||
serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey)
|
serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey)
|
||||||
|
|
|
@ -590,7 +590,8 @@ 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 block_hash = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), block_hash);
|
let mut tx =
|
||||||
|
BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), block_hash);
|
||||||
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())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue