diff --git a/benches/banking_stage.rs b/benches/banking_stage.rs index c236346946..94272ec837 100644 --- a/benches/banking_stage.rs +++ b/benches/banking_stage.rs @@ -74,7 +74,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) { let fund = Transaction::system_move( &mint.keypair(), tx.account_keys[0], - mint_total / txes as i64, + mint_total / txes as u64, mint.last_id(), 0, ); @@ -175,7 +175,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) { let fund = Transaction::system_move( &mint.keypair(), tx.account_keys[0], - mint_total / txes as i64, + mint_total / txes as u64, mint.last_id(), 0, ); diff --git a/programs/bpf/rust/noop/build.sh b/programs/bpf/rust/noop/build.sh index 4d84de1ee9..77390546dd 100755 --- a/programs/bpf/rust/noop/build.sh +++ b/programs/bpf/rust/noop/build.sh @@ -7,4 +7,4 @@ mkdir -p "$OUTDIR" # cargo +nightly rustc --release -- -C panic=abort --emit=llvm-ir cargo +nightly rustc --release -- -C panic=abort --emit=llvm-bc cp "$INTERDIR"/deps/noop_rust-*.bc "$OUTDIR"/noop_rust.bc -/usr/local/opt/llvm/bin/llc -march=bpf -filetype=obj -o "$OUTDIR"/noop_rust.o "$OUTDIR"/noop_rust.bc \ No newline at end of file +/usr/local/opt/llvm/bin/llc -march=bpf -filetype=obj -o "$OUTDIR"/noop_rust.o "$OUTDIR"/noop_rust.bc diff --git a/programs/bpf/rust/noop/dump.sh b/programs/bpf/rust/noop/dump.sh index 47180ced45..5703734ad9 100755 --- a/programs/bpf/rust/noop/dump.sh +++ b/programs/bpf/rust/noop/dump.sh @@ -1,3 +1,3 @@ #!/bin/sh -/usr/local/opt/llvm/bin/llvm-objdump -color -source -disassemble target/release/noop_rust.o \ No newline at end of file +/usr/local/opt/llvm/bin/llvm-objdump -color -source -disassemble target/release/noop_rust.o diff --git a/programs/native/bpf_loader/src/lib.rs b/programs/native/bpf_loader/src/lib.rs index 30cd225706..e08876fb89 100644 --- a/programs/native/bpf_loader/src/lib.rs +++ b/programs/native/bpf_loader/src/lib.rs @@ -70,7 +70,7 @@ fn serialize_parameters(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> Vec .unwrap(); for info in keyed_accounts.iter_mut() { v.write_all(info.key.as_ref()).unwrap(); - v.write_i64::(info.account.tokens).unwrap(); + v.write_u64::(info.account.tokens).unwrap(); v.write_u64::(info.account.userdata.len() as u64) .unwrap(); v.write_all(&info.account.userdata).unwrap(); @@ -87,7 +87,7 @@ fn deserialize_parameters(keyed_accounts: &mut [KeyedAccount], buffer: &[u8]) { let mut start = mem::size_of::(); for info in keyed_accounts.iter_mut() { start += mem::size_of::(); // skip pubkey - info.account.tokens = LittleEndian::read_i64(&buffer[start..]); + info.account.tokens = LittleEndian::read_u64(&buffer[start..]); start += mem::size_of::() // skip tokens + mem::size_of::(); // skip length tag diff --git a/rfcs/0001-smart-contracts-engine.md b/rfcs/0001-smart-contracts-engine.md index 9a0d68212d..914c3fa06f 100644 --- a/rfcs/0001-smart-contracts-engine.md +++ b/rfcs/0001-smart-contracts-engine.md @@ -68,7 +68,7 @@ pub struct Transaction { pub last_id: Hash, /// The number of tokens paid for processing and storage of this transaction. - pub fee: i64, + pub fee: u64, /// Keys identifying programs in the instructions vector. pub program_ids: Vec, @@ -86,7 +86,7 @@ Accounts maintain token state as well as program specific memory. /// An Account with userdata that is stored on chain pub struct Account { /// tokens in the account - pub tokens: i64, + pub tokens: u64, /// user data /// A transaction can write to its userdata pub userdata: Vec, @@ -145,7 +145,7 @@ pub enum SystemProgram { /// * space - memory to allocate if greater then zero /// * program_id - the program id of the new account CreateAccount { - tokens: i64, + tokens: u64, space: u64, program_id: Pubkey, }, @@ -155,7 +155,7 @@ pub enum SystemProgram { /// Move tokens /// * Transaction::keys[0] - source /// * Transaction::keys[1] - destination - Move { tokens: i64 }, + Move { tokens: u64 }, } ``` The interface is best described by the `Instruction::userdata` that the user encodes. diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 01ec8fdc50..39354d650b 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -5,7 +5,7 @@ use pubkey::Pubkey; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Account { /// tokens in the account - pub tokens: i64, + pub tokens: u64, /// user data /// A transaction can write to its userdata pub userdata: Vec, @@ -21,7 +21,7 @@ pub struct Account { impl Account { // TODO do we want to add executable and leader_program_id even though they should always be false/default? - pub fn new(tokens: i64, space: usize, program_id: Pubkey) -> Account { + pub fn new(tokens: u64, space: usize, program_id: Pubkey) -> Account { Account { tokens, userdata: vec![0u8; space], diff --git a/src/bank.rs b/src/bank.rs index 522a5a1d2a..5c69d12ef1 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -33,7 +33,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, RwLock}; use std::time::Instant; use storage_program::StorageProgram; -use system_program::SystemProgram; +use system_program::{Error, SystemProgram}; use system_transaction::SystemTransaction; use timing::{duration_as_us, timestamp}; use token_program; @@ -80,6 +80,7 @@ pub enum BankError { LedgerVerificationFailed, /// Contract's transaction token balance does not equal the balance after the transaction UnbalancedTransaction(u8), + /// Contract's transactions resulted in an account with a negative balance /// The difference from InsufficientFundsForFee is that the transaction was executed by the /// contract @@ -528,8 +529,8 @@ impl Bank { /// tick that has achieved finality pub fn get_finality_timestamp( &self, - ticks_and_stakes: &mut [(u64, i64)], - supermajority_stake: i64, + ticks_and_stakes: &mut [(u64, u64)], + supermajority_stake: u64, ) -> Option { // Sort by tick height ticks_and_stakes.sort_by(|a, b| a.0.cmp(&b.0)); @@ -712,7 +713,7 @@ impl Bank { instruction_index: usize, tx_program_id: &Pubkey, pre_program_id: &Pubkey, - pre_tokens: i64, + pre_tokens: u64, account: &Account, ) -> Result<()> { // Verify the transaction @@ -727,9 +728,6 @@ impl Bank { instruction_index as u8, )); } - if account.tokens < 0 { - return Err(BankError::ResultWithNegativeTokens(instruction_index as u8)); - } Ok(()) } @@ -763,7 +761,7 @@ impl Bank { let tx_program_id = tx.program_id(instruction_index); // TODO: the runtime should be checking read/write access to memory // we are trusting the hard coded contracts not to clobber or allocate - let pre_total: i64 = program_accounts.iter().map(|a| a.tokens).sum(); + let pre_total: u64 = program_accounts.iter().map(|a| a.tokens).sum(); let pre_data: Vec<_> = program_accounts .iter_mut() .map(|a| (a.program_id, a.tokens)) @@ -783,9 +781,14 @@ impl Bank { // Call the contract method // It's up to the contract to implement its own rules on moving funds if SystemProgram::check_id(&tx_program_id) { - if SystemProgram::process_transaction(&tx, instruction_index, program_accounts).is_err() + if let Err(err) = + SystemProgram::process_transaction(&tx, instruction_index, program_accounts) { - return Err(BankError::ProgramRuntimeError(instruction_index as u8)); + let err = match err { + Error::ResultWithNegativeTokens(i) => BankError::ResultWithNegativeTokens(i), + _ => BankError::ProgramRuntimeError(instruction_index as u8), + }; + return Err(err); } } else if BudgetState::check_id(&tx_program_id) { if BudgetState::process_transaction(&tx, instruction_index, program_accounts).is_err() { @@ -873,7 +876,7 @@ impl Bank { } } // The total sum of all the tokens in all the pages cannot change. - let post_total: i64 = program_accounts.iter().map(|a| a.tokens).sum(); + let post_total: u64 = program_accounts.iter().map(|a| a.tokens).sum(); if pre_total != post_total { Err(BankError::UnbalancedTransaction(instruction_index as u8)) } else { @@ -1288,7 +1291,7 @@ impl Bank { /// `n` tokens where `last_id` is the last Entry ID observed by the client. pub fn transfer( &self, - n: i64, + n: u64, keypair: &Keypair, to: Pubkey, last_id: Hash, @@ -1298,7 +1301,7 @@ impl Bank { self.process_transaction(&tx).map(|_| signature) } - pub fn read_balance(account: &Account) -> i64 { + pub fn read_balance(account: &Account) -> u64 { if SystemProgram::check_id(&account.program_id) { SystemProgram::get_balance(account) } else if BudgetState::check_id(&account.program_id) { @@ -1309,7 +1312,7 @@ impl Bank { } /// Each contract would need to be able to introspect its own state /// this is hard coded to the budget contract language - pub fn get_balance(&self, pubkey: &Pubkey) -> i64 { + pub fn get_balance(&self, pubkey: &Pubkey) -> u64 { self.get_account(pubkey) .map(|x| Self::read_balance(&x)) .unwrap_or(0) @@ -1317,7 +1320,7 @@ impl Bank { /// TODO: Need to implement a real staking contract to hold node stake. /// Right now this just gets the account balances. See github issue #1655. - pub fn get_stake(&self, pubkey: &Pubkey) -> i64 { + pub fn get_stake(&self, pubkey: &Pubkey) -> u64 { self.get_balance(pubkey) } @@ -1482,7 +1485,6 @@ mod tests { use hash::hash; use jsonrpc_macros::pubsub::{Subscriber, SubscriptionId}; use ledger; - use logger; use signature::Keypair; use signature::{GenKeys, KeypairUtil}; use std; @@ -1611,18 +1613,6 @@ mod tests { assert_eq!(bank.get_signature(&t1.last_id, &t1.signature), Some(Ok(()))); } - #[test] - fn test_negative_tokens() { - logger::setup(); - let mint = Mint::new(1); - let pubkey = Keypair::new().pubkey(); - let bank = Bank::new(&mint); - let res = bank.transfer(-1, &mint.keypair(), pubkey, mint.last_id()); - println!("{:?}", bank.get_account(&pubkey)); - assert_matches!(res, Err(BankError::ResultWithNegativeTokens(0))); - assert_eq!(bank.transaction_count(), 0); - } - // TODO: This test demonstrates that fees are not paid when a program fails. // See github issue 1157 (https://github.com/solana-labs/solana/issues/1157) #[test] @@ -1890,7 +1880,7 @@ mod tests { let dummy_leader_id = Keypair::new().pubkey(); let dummy_leader_tokens = 1; let mint = Mint::new_with_leader( - length as i64 + 1 + dummy_leader_tokens, + length as u64 + 1 + dummy_leader_tokens, dummy_leader_id, dummy_leader_tokens, ); diff --git a/src/bin/bench-tps.rs b/src/bin/bench-tps.rs index c2bf7009d1..70a6ccb3bf 100644 --- a/src/bin/bench-tps.rs +++ b/src/bin/bench-tps.rs @@ -46,7 +46,7 @@ pub struct NodeStats { pub tx: u64, // Total transactions reported by this node } -fn metrics_submit_token_balance(token_balance: i64) { +fn metrics_submit_token_balance(token_balance: u64) { println!("Token balance: {}", token_balance); metrics::submit( influxdb::Point::new("bench-tps") @@ -313,14 +313,14 @@ fn verify_transfer(client: &mut ThinClient, tx: &Transaction) -> bool { /// fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX /// on every iteration. This allows us to replay the transfers because the source is either empty, /// or full -fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], tokens: i64) { - let total = tokens * dests.len() as i64; - let mut funded: Vec<(&Keypair, i64)> = vec![(source, total)]; +fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], tokens: u64) { + let total = tokens * dests.len() as u64; + let mut funded: Vec<(&Keypair, u64)> = vec![(source, total)]; let mut notfunded: Vec<&Keypair> = dests.iter().collect(); println!("funding keys {}", dests.len()); while !notfunded.is_empty() { - let mut new_funded: Vec<(&Keypair, i64)> = vec![]; + let mut new_funded: Vec<(&Keypair, u64)> = vec![]; let mut to_fund = vec![]; println!("creating from... {}", funded.len()); for f in &mut funded { @@ -329,7 +329,7 @@ fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], token break; } let start = notfunded.len() - max_units; - let per_unit = f.1 / (max_units as i64); + let per_unit = f.1 / (max_units as u64); let moves: Vec<_> = notfunded[start..] .iter() .map(|k| (k.pubkey(), per_unit)) @@ -376,7 +376,7 @@ fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], token } } -fn airdrop_tokens(client: &mut ThinClient, leader: &NodeInfo, id: &Keypair, tx_count: i64) { +fn airdrop_tokens(client: &mut ThinClient, leader: &NodeInfo, id: &Keypair, tx_count: u64) { let mut drone_addr = leader.contact_info.tpu; drone_addr.set_port(DRONE_PORT); @@ -494,7 +494,7 @@ fn compute_and_report_stats( // First transfer 3/4 of the tokens to the dest accounts // then ping-pong 1/4 of the tokens back to the other account // this leaves 1/4 token buffer in each account -fn should_switch_directions(num_tokens_per_account: i64, i: i64) -> bool { +fn should_switch_directions(num_tokens_per_account: u64, i: u64) -> bool { i % (num_tokens_per_account / 4) == 0 && (i >= (3 * num_tokens_per_account) / 4) } @@ -653,7 +653,7 @@ fn main() { total_keys += target; target /= MAX_SPENDS_PER_TX; } - let gen_keypairs = rnd.gen_n_keypairs(total_keys as i64); + let gen_keypairs = rnd.gen_n_keypairs(total_keys as u64); let barrier_id = rnd.gen_n_keypairs(1).pop().unwrap(); println!("Get tokens..."); @@ -667,7 +667,7 @@ fn main() { if num_tokens_per_account > keypair0_balance { let extra = num_tokens_per_account - keypair0_balance; - let total = extra * (gen_keypairs.len() as i64); + let total = extra * (gen_keypairs.len() as u64); airdrop_tokens(&mut client, &leader, &id, total); println!("adding more tokens {}", extra); fund_keys(&mut client, &id, &gen_keypairs, extra); @@ -730,7 +730,7 @@ fn main() { let mut reclaim_tokens_back_to_source_account = false; let mut i = keypair0_balance; while start.elapsed() < duration { - let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(-1); + let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(0); metrics_submit_token_balance(balance); // ping-pong between source and destination accounts for each loop iteration @@ -782,7 +782,7 @@ fn main() { } } - let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(-1); + let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(0); metrics_submit_token_balance(balance); compute_and_report_stats( diff --git a/src/bin/genesis.rs b/src/bin/genesis.rs index dadea25ce1..a60dff0e70 100644 --- a/src/bin/genesis.rs +++ b/src/bin/genesis.rs @@ -59,7 +59,7 @@ fn main() -> Result<(), Box> { let leader_keypair = leader_config.keypair(); // Parse the input mint configuration - let num_tokens = value_t_or_exit!(matches, "num_tokens", i64); + let num_tokens = value_t_or_exit!(matches, "num_tokens", u64); let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap(); let pkcs8: Vec = serde_json::from_reader(&file)?; let mint = Mint::new_with_pkcs8(num_tokens, pkcs8, leader_keypair.pubkey(), 1); diff --git a/src/budget_expr.rs b/src/budget_expr.rs index dd47847f28..ef1a1fbebd 100644 --- a/src/budget_expr.rs +++ b/src/budget_expr.rs @@ -51,17 +51,17 @@ pub enum BudgetExpr { impl BudgetExpr { /// Create the simplest budget - one that pays `tokens` to Pubkey. - pub fn new_payment(tokens: i64, to: Pubkey) -> Self { + pub fn new_payment(tokens: u64, to: Pubkey) -> Self { BudgetExpr::Pay(Payment { tokens, to }) } /// Create a budget that pays `tokens` to `to` after being witnessed by `from`. - pub fn new_authorized_payment(from: Pubkey, tokens: i64, to: Pubkey) -> Self { + pub fn new_authorized_payment(from: Pubkey, tokens: u64, to: Pubkey) -> Self { BudgetExpr::After(Condition::Signature(from), Payment { tokens, to }) } /// Create a budget that pays tokens` to `to` after being witnessed by 2x `from`s - pub fn new_2_2_multisig_payment(from0: Pubkey, from1: Pubkey, tokens: i64, to: Pubkey) -> Self { + pub fn new_2_2_multisig_payment(from0: Pubkey, from1: Pubkey, tokens: u64, to: Pubkey) -> Self { BudgetExpr::And( Condition::Signature(from0), Condition::Signature(from1), @@ -70,7 +70,7 @@ impl BudgetExpr { } /// Create a budget that pays `tokens` to `to` after the given DateTime. - pub fn new_future_payment(dt: DateTime, from: Pubkey, tokens: i64, to: Pubkey) -> Self { + pub fn new_future_payment(dt: DateTime, from: Pubkey, tokens: u64, to: Pubkey) -> Self { BudgetExpr::After(Condition::Timestamp(dt, from), Payment { tokens, to }) } @@ -79,7 +79,7 @@ impl BudgetExpr { pub fn new_cancelable_future_payment( dt: DateTime, from: Pubkey, - tokens: i64, + tokens: u64, to: Pubkey, ) -> Self { BudgetExpr::Or( @@ -97,7 +97,7 @@ impl BudgetExpr { } /// Return true if the budget spends exactly `spendable_tokens`. - pub fn verify(&self, spendable_tokens: i64) -> bool { + pub fn verify(&self, spendable_tokens: u64) -> bool { match self { BudgetExpr::Pay(payment) | BudgetExpr::After(_, payment) diff --git a/src/budget_instruction.rs b/src/budget_instruction.rs index d80d5d2e94..78ca94e2ac 100644 --- a/src/budget_instruction.rs +++ b/src/budget_instruction.rs @@ -5,7 +5,7 @@ use chrono::prelude::{DateTime, Utc}; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Contract { /// The number of tokens allocated to the `BudgetExpr` and any transaction fees. - pub tokens: i64, + pub tokens: u64, pub budget_expr: BudgetExpr, } diff --git a/src/budget_program.rs b/src/budget_program.rs index 8975f2f02b..718c5abc43 100644 --- a/src/budget_program.rs +++ b/src/budget_program.rs @@ -235,7 +235,7 @@ impl BudgetState { } //TODO the contract needs to provide a "get_balance" introspection call of the userdata - pub fn get_balance(account: &Account) -> i64 { + pub fn get_balance(account: &Account) -> u64 { if let Ok(state) = deserialize(&account.userdata) { let state: BudgetState = state; if state.is_pending() { diff --git a/src/budget_transaction.rs b/src/budget_transaction.rs index c8eac3ca84..2845119ec4 100644 --- a/src/budget_transaction.rs +++ b/src/budget_transaction.rs @@ -16,12 +16,12 @@ pub trait BudgetTransaction { fn budget_new_taxed( from_keypair: &Keypair, to: Pubkey, - tokens: i64, - fee: i64, + tokens: u64, + fee: u64, last_id: Hash, ) -> Self; - fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self; + fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self; fn budget_new_timestamp( from_keypair: &Keypair, @@ -45,7 +45,7 @@ pub trait BudgetTransaction { dt: DateTime, dt_pubkey: Pubkey, cancelable: Option, - tokens: i64, + tokens: u64, last_id: Hash, ) -> Self; @@ -55,7 +55,7 @@ pub trait BudgetTransaction { contract: Pubkey, witness: Pubkey, cancelable: Option, - tokens: i64, + tokens: u64, last_id: Hash, ) -> Self; @@ -70,8 +70,8 @@ impl BudgetTransaction for Transaction { fn budget_new_taxed( from_keypair: &Keypair, to: Pubkey, - tokens: i64, - fee: i64, + tokens: u64, + fee: u64, last_id: Hash, ) -> Self { let contract = Keypair::new().pubkey(); @@ -106,7 +106,7 @@ impl BudgetTransaction for Transaction { } /// Create and sign a new Transaction. Used for unit-testing. - fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self { + fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self { Self::budget_new_taxed(from_keypair, to, tokens, 0, last_id) } @@ -157,7 +157,7 @@ impl BudgetTransaction for Transaction { dt: DateTime, dt_pubkey: Pubkey, cancelable: Option, - tokens: i64, + tokens: u64, last_id: Hash, ) -> Self { let expr = if let Some(from) = cancelable { @@ -186,7 +186,7 @@ impl BudgetTransaction for Transaction { contract: Pubkey, witness: Pubkey, cancelable: Option, - tokens: i64, + tokens: u64, last_id: Hash, ) -> Self { let expr = if let Some(from) = cancelable { @@ -221,7 +221,7 @@ impl BudgetTransaction for Transaction { fn verify_plan(&self) -> bool { if let Some(SystemProgram::Move { tokens }) = self.system_instruction(0) { if let Some(Instruction::NewBudget(expr)) = self.instruction(1) { - if !(self.fee >= 0 && self.fee <= tokens && expr.verify(tokens - self.fee)) { + if !(self.fee <= tokens && expr.verify(tokens - self.fee)) { return false; } } @@ -261,8 +261,6 @@ mod tests { let keypair0 = Keypair::new(); let pubkey1 = Keypair::new().pubkey(); assert!(Transaction::budget_new_taxed(&keypair0, pubkey1, 1, 1, zero).verify_plan()); - assert!(!Transaction::budget_new_taxed(&keypair0, pubkey1, 1, 2, zero).verify_plan()); - assert!(!Transaction::budget_new_taxed(&keypair0, pubkey1, 1, -1, zero).verify_plan()); } #[test] diff --git a/src/compute_leader_finality_service.rs b/src/compute_leader_finality_service.rs index a2842a6c81..00df142283 100644 --- a/src/compute_leader_finality_service.rs +++ b/src/compute_leader_finality_service.rs @@ -34,7 +34,7 @@ impl ComputeLeaderFinalityService { ) -> result::Result { let mut total_stake = 0; - let mut ticks_and_stakes: Vec<(u64, i64)> = { + let mut ticks_and_stakes: Vec<(u64, u64)> = { let bank_accounts = bank.accounts.read().unwrap(); // TODO: Doesn't account for duplicates since a single validator could potentially register // multiple vote accounts. Once that is no longer possible (see the TODO in vote_program.rs, diff --git a/src/drone.rs b/src/drone.rs index 0b9cf1288d..4f74dd8375 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -131,7 +131,7 @@ impl Drone { Transaction::system_new( &self.mint_keypair, client_pubkey, - airdrop_request_amount as i64, + airdrop_request_amount as u64, last_id, ) } @@ -310,8 +310,8 @@ mod tests { #[test] #[ignore] fn test_send_airdrop() { - const SMALL_BATCH: i64 = 50; - const TPS_BATCH: i64 = 5_000_000; + const SMALL_BATCH: u64 = 50; + const TPS_BATCH: u64 = 5_000_000; logger::setup(); let leader_keypair = Arc::new(Keypair::new()); diff --git a/src/leader_scheduler.rs b/src/leader_scheduler.rs index 5ecd5277ec..5d79d032a7 100644 --- a/src/leader_scheduler.rs +++ b/src/leader_scheduler.rs @@ -549,7 +549,7 @@ mod tests { let num_vote_account_tokens = 1; let mint = Mint::new( (((num_validators + 1) / 2) * (num_validators + 1) - + num_vote_account_tokens * num_validators) as i64, + + num_vote_account_tokens * num_validators) as u64, ); let bank = Bank::new(&mint); let mut validators = vec![]; @@ -564,7 +564,7 @@ mod tests { validators.push(new_pubkey); // Give the validator some tokens bank.transfer( - (i + 1 + num_vote_account_tokens) as i64, + (i + 1 + num_vote_account_tokens) as u64, &mint.keypair(), new_pubkey, last_id, @@ -574,7 +574,7 @@ mod tests { let new_vote_account = create_vote_account( &new_validator, &bank, - num_vote_account_tokens as i64, + num_vote_account_tokens as u64, mint.last_id(), ).unwrap(); // Vote to make the validator part of the active set for the entire test @@ -743,7 +743,7 @@ mod tests { fn test_rank_active_set() { let num_validators: usize = 101; // Give mint sum(1..num_validators) tokens - let mint = Mint::new((((num_validators + 1) / 2) * (num_validators + 1)) as i64); + let mint = Mint::new((((num_validators + 1) / 2) * (num_validators + 1)) as u64); let bank = Bank::new(&mint); let mut validators = vec![]; let last_id = mint @@ -756,7 +756,7 @@ mod tests { let new_pubkey = new_validator.pubkey(); validators.push(new_validator); bank.transfer( - (num_validators - i) as i64, + (num_validators - i) as u64, &mint.keypair(), new_pubkey, last_id, @@ -782,7 +782,7 @@ mod tests { let new_pubkey = new_validator.pubkey(); new_validators.push(new_validator); bank.transfer( - (num_validators - i) as i64, + (num_validators - i) as u64, &validators[i], new_pubkey, last_id, @@ -803,7 +803,7 @@ mod tests { } // Break ties between validators with the same balances using public key - let mint = Mint::new(num_validators as i64); + let mint = Mint::new(num_validators as u64); let bank = Bank::new(&mint); let mut tied_validators_pk = vec![]; let last_id = mint @@ -956,7 +956,7 @@ mod tests { // Create the bank and validators let mint = Mint::new( ((((num_validators + 1) / 2) * (num_validators + 1)) - + (num_vote_account_tokens * num_validators)) as i64, + + (num_vote_account_tokens * num_validators)) as u64, ); let bank = Bank::new(&mint); let mut validators = vec![]; @@ -971,7 +971,7 @@ mod tests { validators.push(new_pubkey); // Give the validator some tokens bank.transfer( - (i + 1 + num_vote_account_tokens) as i64, + (i + 1 + num_vote_account_tokens) as u64, &mint.keypair(), new_pubkey, last_id, @@ -981,7 +981,7 @@ mod tests { let new_vote_account = create_vote_account( &new_validator, &bank, - num_vote_account_tokens as i64, + num_vote_account_tokens as u64, mint.last_id(), ).unwrap(); diff --git a/src/ledger.rs b/src/ledger.rs index 79774c5912..a81ed40e07 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -623,9 +623,9 @@ pub fn create_tmp_ledger_with_mint(name: &str, mint: &Mint) -> String { pub fn create_tmp_genesis( name: &str, - num: i64, + num: u64, bootstrap_leader_id: Pubkey, - bootstrap_leader_tokens: i64, + bootstrap_leader_tokens: u64, ) -> (Mint, String) { let mint = Mint::new_with_leader(num, bootstrap_leader_id, bootstrap_leader_tokens); let path = create_tmp_ledger_with_mint(name, &mint); @@ -646,10 +646,10 @@ pub fn create_ticks(num_ticks: usize, mut hash: Hash) -> Vec { pub fn create_tmp_sample_ledger( name: &str, - num_tokens: i64, + num_tokens: u64, num_ending_ticks: usize, bootstrap_leader_id: Pubkey, - bootstrap_leader_tokens: i64, + bootstrap_leader_tokens: u64, ) -> (Mint, String, Vec) { let mint = Mint::new_with_leader(num_tokens, bootstrap_leader_id, bootstrap_leader_tokens); let path = get_tmp_ledger_path(name); diff --git a/src/loader_transaction.rs b/src/loader_transaction.rs index bfdd06498f..ac15ef5e9c 100644 --- a/src/loader_transaction.rs +++ b/src/loader_transaction.rs @@ -14,10 +14,10 @@ pub trait LoaderTransaction { offset: u32, bytes: Vec, last_id: Hash, - fee: i64, + fee: u64, ) -> Self; - fn finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: i64) -> Self; + fn finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self; } impl LoaderTransaction for Transaction { @@ -27,7 +27,7 @@ impl LoaderTransaction for Transaction { offset: u32, bytes: Vec, last_id: Hash, - fee: i64, + fee: u64, ) -> Self { trace!( "LoaderTransaction::Write() program {:?} offset {} length {}", @@ -40,7 +40,7 @@ impl LoaderTransaction for Transaction { Transaction::new(from_keypair, &[], loader, userdata, last_id, fee) } - fn finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: i64) -> Self { + fn finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self { trace!( "LoaderTransaction::Finalize() program {:?}", from_keypair.pubkey(), diff --git a/src/mint.rs b/src/mint.rs index 70322e111c..e14fac16b4 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -13,17 +13,17 @@ use untrusted::Input; pub struct Mint { pub pkcs8: Vec, pubkey: Pubkey, - pub tokens: i64, + pub tokens: u64, pub bootstrap_leader_id: Pubkey, - pub bootstrap_leader_tokens: i64, + pub bootstrap_leader_tokens: u64, } impl Mint { pub fn new_with_pkcs8( - tokens: i64, + tokens: u64, pkcs8: Vec, bootstrap_leader_id: Pubkey, - bootstrap_leader_tokens: i64, + bootstrap_leader_tokens: u64, ) -> Self { let keypair = Keypair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in mint pub fn new"); @@ -38,9 +38,9 @@ impl Mint { } pub fn new_with_leader( - tokens: i64, + tokens: u64, bootstrap_leader: Pubkey, - bootstrap_leader_tokens: i64, + bootstrap_leader_tokens: u64, ) -> Self { let rnd = SystemRandom::new(); let pkcs8 = Keypair::generate_pkcs8(&rnd) @@ -49,7 +49,7 @@ impl Mint { Self::new_with_pkcs8(tokens, pkcs8, bootstrap_leader, bootstrap_leader_tokens) } - pub fn new(tokens: i64) -> Self { + pub fn new(tokens: u64) -> Self { let rnd = SystemRandom::new(); let pkcs8 = Keypair::generate_pkcs8(&rnd) .expect("generate_pkcs8 in mint pub fn new") diff --git a/src/payment_plan.rs b/src/payment_plan.rs index 5450bed5cb..c0f5f1e651 100644 --- a/src/payment_plan.rs +++ b/src/payment_plan.rs @@ -20,7 +20,7 @@ pub enum Witness { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Payment { /// Amount to be paid. - pub tokens: i64, + pub tokens: u64, /// The `Pubkey` that `tokens` should be paid to. pub to: Pubkey, diff --git a/src/rpc.rs b/src/rpc.rs index dccf3af7eb..54063cc6bb 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -135,7 +135,7 @@ build_rpc_trait! { fn get_account_info(&self, Self::Metadata, String) -> Result; #[rpc(meta, name = "getBalance")] - fn get_balance(&self, Self::Metadata, String) -> Result; + fn get_balance(&self, Self::Metadata, String) -> Result; #[rpc(meta, name = "getFinality")] fn get_finality(&self, Self::Metadata) -> Result; @@ -172,7 +172,7 @@ impl RpcSol for RpcSolImpl { let pubkey = verify_pubkey(id)?; meta.request_processor.get_account_info(pubkey) } - fn get_balance(&self, meta: Self::Metadata, id: String) -> Result { + fn get_balance(&self, meta: Self::Metadata, id: String) -> Result { info!("get_balance rpc request received: {:?}", id); let pubkey = verify_pubkey(id)?; meta.request_processor.get_balance(pubkey) @@ -276,7 +276,7 @@ impl JsonRpcRequestProcessor { .get_account(&pubkey) .ok_or_else(Error::invalid_request) } - fn get_balance(&self, pubkey: Pubkey) -> Result { + fn get_balance(&self, pubkey: Pubkey) -> Result { let val = self.bank.get_balance(&pubkey); Ok(val) } diff --git a/src/rpc_request.rs b/src/rpc_request.rs index 5ccfdd126d..1d2260d936 100644 --- a/src/rpc_request.rs +++ b/src/rpc_request.rs @@ -175,7 +175,7 @@ mod tests { Some(json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx")), ); assert!(balance.is_ok()); - assert_eq!(balance.unwrap().as_i64().unwrap(), 50); + assert_eq!(balance.unwrap().as_u64().unwrap(), 50); let last_id = RpcRequest::GetLastId.make_rpc_request(&rpc_addr, 2, None); assert!(last_id.is_ok()); diff --git a/src/signature.rs b/src/signature.rs index cdc30853e4..17c24b345d 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -84,11 +84,11 @@ impl GenKeys { seed } - fn gen_n_seeds(&mut self, n: i64) -> Vec<[u8; 32]> { + fn gen_n_seeds(&mut self, n: u64) -> Vec<[u8; 32]> { (0..n).map(|_| self.gen_seed()).collect() } - pub fn gen_n_keypairs(&mut self, n: i64) -> Vec { + pub fn gen_n_keypairs(&mut self, n: u64) -> Vec { self.gen_n_seeds(n) .into_par_iter() .map(|seed| Keypair::from_seed_unchecked(Input::from(&seed)).unwrap()) @@ -124,7 +124,7 @@ mod tests { } } - fn gen_n_pubkeys(seed: [u8; 32], n: i64) -> HashSet { + fn gen_n_pubkeys(seed: [u8; 32], n: u64) -> HashSet { GenKeys::new(seed) .gen_n_keypairs(n) .into_iter() diff --git a/src/storage_program.rs b/src/storage_program.rs index 7010f0d9d1..7c2050d635 100644 --- a/src/storage_program.rs +++ b/src/storage_program.rs @@ -31,7 +31,7 @@ impl StorageProgram { Pubkey::new(&STORAGE_PROGRAM_ID) } - pub fn get_balance(account: &Account) -> i64 { + pub fn get_balance(account: &Account) -> u64 { account.tokens } diff --git a/src/system_program.rs b/src/system_program.rs index 0fc5fcee5f..13c4410324 100644 --- a/src/system_program.rs +++ b/src/system_program.rs @@ -11,6 +11,7 @@ pub enum Error { InvalidArgument, AssignOfUnownedAccount, AccountNotFinalized, + ResultWithNegativeTokens(u8), } impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -30,7 +31,7 @@ pub enum SystemProgram { /// * space - memory to allocate if greater then zero /// * program_id - the program id of the new account CreateAccount { - tokens: i64, + tokens: u64, space: u64, program_id: Pubkey, }, @@ -40,7 +41,7 @@ pub enum SystemProgram { /// Move tokens /// * Transaction::keys[0] - source /// * Transaction::keys[1] - destination - Move { tokens: i64 }, + Move { tokens: u64 }, /// Spawn a new program from an account Spawn, @@ -56,7 +57,7 @@ impl SystemProgram { pub fn id() -> Pubkey { Pubkey::new(&SYSTEM_PROGRAM_ID) } - pub fn get_balance(account: &Account) -> i64 { + pub fn get_balance(account: &Account) -> u64 { account.tokens } pub fn process_transaction( @@ -84,6 +85,10 @@ impl SystemProgram { info!("Invalid account[1]"); Err(Error::InvalidArgument)?; } + if tokens > accounts[0].tokens { + info!("Insufficient tokens in account[0]"); + Err(Error::ResultWithNegativeTokens(pix as u8))?; + } accounts[0].tokens -= tokens; accounts[1].tokens += tokens; accounts[1].program_id = program_id; @@ -99,6 +104,10 @@ impl SystemProgram { } SystemProgram::Move { tokens } => { //bank should be verifying correctness + if tokens > accounts[0].tokens { + info!("Insufficient tokens in account[0]"); + Err(Error::ResultWithNegativeTokens(pix as u8))?; + } accounts[0].tokens -= tokens; accounts[1].tokens += tokens; } diff --git a/src/system_transaction.rs b/src/system_transaction.rs index bab6bd42cc..9d7338f1aa 100644 --- a/src/system_transaction.rs +++ b/src/system_transaction.rs @@ -12,32 +12,32 @@ pub trait SystemTransaction { from_keypair: &Keypair, to: Pubkey, last_id: Hash, - tokens: i64, + tokens: u64, space: u64, program_id: Pubkey, - fee: i64, + fee: u64, ) -> Self; - fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: i64) -> Self; + fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: u64) -> Self; - fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self; + fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self; fn system_move( from_keypair: &Keypair, to: Pubkey, - tokens: i64, + tokens: u64, last_id: Hash, - fee: i64, + fee: u64, ) -> Self; fn system_move_many( from_keypair: &Keypair, - moves: &[(Pubkey, i64)], + moves: &[(Pubkey, u64)], last_id: Hash, - fee: i64, + fee: u64, ) -> Self; - fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: i64) -> Self; + fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: u64) -> Self; } impl SystemTransaction for Transaction { @@ -46,10 +46,10 @@ impl SystemTransaction for Transaction { from_keypair: &Keypair, to: Pubkey, last_id: Hash, - tokens: i64, + tokens: u64, space: u64, program_id: Pubkey, - fee: i64, + fee: u64, ) -> Self { let create = SystemProgram::CreateAccount { tokens, //TODO, the tokens to allocate might need to be higher then 0 in the future @@ -67,7 +67,7 @@ impl SystemTransaction for Transaction { ) } /// Create and sign new SystemProgram::Assign transaction - fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: i64) -> Self { + fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: u64) -> Self { let assign = SystemProgram::Assign { program_id }; let userdata = serialize(&assign).unwrap(); Transaction::new( @@ -80,16 +80,16 @@ impl SystemTransaction for Transaction { ) } /// Create and sign new SystemProgram::CreateAccount transaction with some defaults - fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self { + fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self { Transaction::system_create(from_keypair, to, last_id, tokens, 0, Pubkey::default(), 0) } /// Create and sign new SystemProgram::Move transaction fn system_move( from_keypair: &Keypair, to: Pubkey, - tokens: i64, + tokens: u64, last_id: Hash, - fee: i64, + fee: u64, ) -> Self { let move_tokens = SystemProgram::Move { tokens }; let userdata = serialize(&move_tokens).unwrap(); @@ -103,7 +103,7 @@ impl SystemTransaction for Transaction { ) } /// Create and sign new SystemProgram::Move transaction to many destinations - fn system_move_many(from: &Keypair, moves: &[(Pubkey, i64)], last_id: Hash, fee: i64) -> Self { + fn system_move_many(from: &Keypair, moves: &[(Pubkey, u64)], last_id: Hash, fee: u64) -> Self { let instructions: Vec<_> = moves .iter() .enumerate() @@ -127,7 +127,7 @@ impl SystemTransaction for Transaction { ) } /// Create and sign new SystemProgram::Spawn transaction - fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: i64) -> Self { + fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: u64) -> Self { let spawn = SystemProgram::Spawn; let userdata = serialize(&spawn).unwrap(); Transaction::new( diff --git a/src/thin_client.rs b/src/thin_client.rs index 07c880a607..ef76f43285 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -154,7 +154,7 @@ impl ThinClient { node_keypair: &Keypair, vote_account_id: Pubkey, last_id: &Hash, - num_tokens: i64, + num_tokens: u64, ) -> io::Result { let tx = Transaction::vote_account_new(&node_keypair, vote_account_id, *last_id, num_tokens); @@ -175,7 +175,7 @@ impl ThinClient { /// Creates, signs, and processes a Transaction. Useful for writing unit-tests. pub fn transfer( &self, - n: i64, + n: u64, keypair: &Keypair, to: Pubkey, last_id: &Hash, @@ -215,7 +215,7 @@ impl ThinClient { /// Request the balance of the user holding `pubkey`. This method blocks /// until the server sends a response. If the response packet is dropped /// by the network, this method will hang indefinitely. - pub fn get_balance(&mut self, pubkey: &Pubkey) -> io::Result { + pub fn get_balance(&mut self, pubkey: &Pubkey) -> io::Result { trace!("get_balance sending request to {}", self.requests_addr); let req = Request::GetAccount { key: *pubkey }; let data = serialize(&req).expect("serialize GetAccount in pub fn get_balance"); @@ -337,7 +337,7 @@ impl ThinClient { pubkey: &Pubkey, polling_frequency: &Duration, timeout: &Duration, - ) -> io::Result { + ) -> io::Result { let now = Instant::now(); loop { match self.get_balance(&pubkey) { @@ -356,7 +356,7 @@ impl ThinClient { } } - pub fn poll_get_balance(&mut self, pubkey: &Pubkey) -> io::Result { + pub fn poll_get_balance(&mut self, pubkey: &Pubkey) -> io::Result { self.poll_balance_with_timeout(pubkey, &Duration::from_millis(100), &Duration::from_secs(1)) } @@ -473,8 +473,8 @@ pub fn poll_gossip_for_leader(leader_ncp: SocketAddr, timeout: Option) -> R pub fn retry_get_balance( client: &mut ThinClient, bob_pubkey: &Pubkey, - expected_balance: Option, -) -> Option { + expected_balance: Option, +) -> Option { const LAST: usize = 30; for run in 0..LAST { let balance_result = client.poll_get_balance(bob_pubkey); diff --git a/src/transaction.rs b/src/transaction.rs index 1ac24e725f..af3e847602 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -40,7 +40,7 @@ pub struct Transaction { pub last_id: Hash, /// The number of tokens paid for processing and storage of this transaction. - pub fee: i64, + pub fee: u64, /// Keys identifying programs in the instructions vector. pub program_ids: Vec, @@ -56,7 +56,7 @@ impl Transaction { program_id: Pubkey, userdata: Vec, last_id: Hash, - fee: i64, + fee: u64, ) -> Self { let program_ids = vec![program_id]; let instructions = vec![Instruction { @@ -85,7 +85,7 @@ impl Transaction { from_keypair: &Keypair, keys: &[Pubkey], last_id: Hash, - fee: i64, + fee: u64, program_ids: Vec, instructions: Vec, ) -> Self { diff --git a/src/vote_transaction.rs b/src/vote_transaction.rs index 00ae2f31be..07c8013427 100644 --- a/src/vote_transaction.rs +++ b/src/vote_transaction.rs @@ -15,24 +15,24 @@ use transaction::Transaction; use vote_program::{Vote, VoteInstruction, VoteProgram}; pub trait VoteTransaction { - fn vote_new(vote_account: &Keypair, vote: Vote, last_id: Hash, fee: i64) -> Self; + fn vote_new(vote_account: &Keypair, vote: Vote, last_id: Hash, fee: u64) -> Self; fn vote_account_new( validator_id: &Keypair, new_vote_account_id: Pubkey, last_id: Hash, - num_tokens: i64, + num_tokens: u64, ) -> Self; fn vote_account_register( validator_id: &Keypair, vote_account_id: Pubkey, last_id: Hash, - fee: i64, + fee: u64, ) -> Self; fn get_votes(&self) -> Vec<(Pubkey, Vote, Hash)>; } impl VoteTransaction for Transaction { - fn vote_new(vote_account: &Keypair, vote: Vote, last_id: Hash, fee: i64) -> Self { + fn vote_new(vote_account: &Keypair, vote: Vote, last_id: Hash, fee: u64) -> Self { let instruction = VoteInstruction::NewVote(vote); let userdata = serialize(&instruction).expect("serialize instruction"); Transaction::new(vote_account, &[], VoteProgram::id(), userdata, last_id, fee) @@ -42,7 +42,7 @@ impl VoteTransaction for Transaction { validator_id: &Keypair, new_vote_account_id: Pubkey, last_id: Hash, - num_tokens: i64, + num_tokens: u64, ) -> Self { Transaction::system_create( validator_id, @@ -59,7 +59,7 @@ impl VoteTransaction for Transaction { validator_id: &Keypair, vote_account_id: Pubkey, last_id: Hash, - fee: i64, + fee: u64, ) -> Self { let register_tx = VoteInstruction::RegisterAccount; let userdata = serialize(®ister_tx).unwrap(); @@ -91,7 +91,7 @@ impl VoteTransaction for Transaction { pub fn create_vote_account( node_keypair: &Keypair, bank: &Bank, - num_tokens: i64, + num_tokens: u64, last_id: Hash, ) -> Result { let new_vote_account = Keypair::new(); diff --git a/src/wallet.rs b/src/wallet.rs index 282c415287..93012898d4 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -37,7 +37,7 @@ const USERDATA_CHUNK_SIZE: usize = 256; #[derive(Debug, PartialEq)] pub enum WalletCommand { Address, - AirDrop(i64), + AirDrop(u64), Balance, Cancel(Pubkey), Confirm(Signature), @@ -45,7 +45,7 @@ pub enum WalletCommand { GetTransactionCount, // Pay(tokens, to, timestamp, timestamp_pubkey, witness(es), cancelable) Pay( - i64, + u64, Pubkey, Option>, Option, @@ -308,7 +308,7 @@ pub fn process_command(config: &WalletConfig) -> Result tokens, None => Err(WalletError::RpcRequestError( @@ -325,7 +325,7 @@ pub fn process_command(config: &WalletConfig) -> Result Result Ok("No account found! Request an airdrop to get started.".to_string()), Some(tokens) => Ok(format!("Your balance is: {:?}", tokens)), @@ -385,7 +385,7 @@ pub fn process_command(config: &WalletConfig) -> Result Result Result result::Result<()> { let initial_leader_balance = 500; let (alice, ledger_path) = create_tmp_genesis( "leader_restart_validator_start_from_old_ledger", - 100_000 + 500 * solana::window_service::MAX_REPAIR_BACKOFF as i64, + 100_000 + 500 * solana::window_service::MAX_REPAIR_BACKOFF as u64, leader_keypair.pubkey(), initial_leader_balance, ); @@ -737,7 +737,7 @@ fn test_multi_node_dynamic_network() { info!("Took {} s to converge", duration_as_s(&start.elapsed()),); info!("Verifying signature of the last transaction in the validators"); - let mut num_nodes_behind = 0i64; + let mut num_nodes_behind = 0u64; validators.retain(|server| { let mut client = mk_client(&server.0); trace!("{} checking signature", server.0.id); @@ -855,11 +855,11 @@ fn test_leader_to_validator_transition() { // to ensure that each transaction is packaged as a single entry, // so that we can be sure leader rotation is triggered let result = - send_tx_and_retry_get_balance(&leader_info, &mint, &bob_pubkey, 1, Some(i as i64)); + send_tx_and_retry_get_balance(&leader_info, &mint, &bob_pubkey, 1, Some(i as u64)); // If the transaction wasn't reflected in the node, then we assume // the node has transitioned already - if result != Some(i as i64) { + if result != Some(i as u64) { break; } @@ -989,7 +989,7 @@ fn test_leader_validator_basic() { // If the transaction wasn't reflected in the node, then we assume // the node has transitioned already - if result != Some(i as i64) { + if result != Some(i as u64) { break; } @@ -1470,9 +1470,9 @@ fn send_tx_and_retry_get_balance( leader: &NodeInfo, alice: &Mint, bob_pubkey: &Pubkey, - transfer_amount: i64, - expected: Option, -) -> Option { + transfer_amount: u64, + expected: Option, +) -> Option { let mut client = mk_client(leader); trace!("getting leader last_id"); let last_id = client.get_last_id(); @@ -1486,8 +1486,8 @@ fn retry_send_tx_and_retry_get_balance( leader: &NodeInfo, alice: &Mint, bob_pubkey: &Pubkey, - expected: Option, -) -> Option { + expected: Option, +) -> Option { let mut client = mk_client(leader); trace!("getting leader last_id"); let last_id = client.get_last_id();