Rename BankError to TransactionError
This commit is contained in:
@ -25,7 +25,7 @@ When Futures 0.3.0 is released, the Transact trait may look like this:
|
|||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
trait Transact {
|
trait Transact {
|
||||||
async fn send_transactions(txs: &[Transaction]) -> Vec<Result<(), BankError>>;
|
async fn send_transactions(txs: &[Transaction]) -> Vec<Result<(), TransactionError>>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ use crate::service::Service;
|
|||||||
use crate::sigverify_stage::VerifiedPackets;
|
use crate::sigverify_stage::VerifiedPackets;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use solana_metrics::counter::Counter;
|
use solana_metrics::counter::Counter;
|
||||||
use solana_runtime::bank::{self, Bank, BankError};
|
use solana_runtime::bank::{self, Bank, TransactionError};
|
||||||
use solana_sdk::timing::{self, duration_as_us, MAX_RECENT_BLOCKHASHES};
|
use solana_sdk::timing::{self, duration_as_us, MAX_RECENT_BLOCKHASHES};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
@ -208,7 +208,7 @@ impl BankingStage {
|
|||||||
.zip(txs.iter())
|
.zip(txs.iter())
|
||||||
.filter_map(|(r, x)| match r {
|
.filter_map(|(r, x)| match r {
|
||||||
Ok(_) => Some(x.clone()),
|
Ok(_) => Some(x.clone()),
|
||||||
Err(BankError::InstructionError(index, err)) => {
|
Err(TransactionError::InstructionError(index, err)) => {
|
||||||
info!("instruction error {:?}, {:?}", index, err);
|
info!("instruction error {:?}, {:?}", index, err);
|
||||||
Some(x.clone())
|
Some(x.clone())
|
||||||
}
|
}
|
||||||
@ -682,7 +682,7 @@ mod tests {
|
|||||||
assert_eq!(entries[0].0.transactions.len(), transactions.len());
|
assert_eq!(entries[0].0.transactions.len(), transactions.len());
|
||||||
|
|
||||||
// ProgramErrors should still be recorded
|
// ProgramErrors should still be recorded
|
||||||
results[0] = Err(BankError::InstructionError(
|
results[0] = Err(TransactionError::InstructionError(
|
||||||
1,
|
1,
|
||||||
InstructionError::new_result_with_negative_lamports(),
|
InstructionError::new_result_with_negative_lamports(),
|
||||||
));
|
));
|
||||||
@ -690,8 +690,8 @@ mod tests {
|
|||||||
let (_, entries) = entry_receiver.recv().unwrap();
|
let (_, entries) = entry_receiver.recv().unwrap();
|
||||||
assert_eq!(entries[0].0.transactions.len(), transactions.len());
|
assert_eq!(entries[0].0.transactions.len(), transactions.len());
|
||||||
|
|
||||||
// Other BankErrors should not be recorded
|
// Other TransactionErrors should not be recorded
|
||||||
results[0] = Err(BankError::AccountNotFound);
|
results[0] = Err(TransactionError::AccountNotFound);
|
||||||
BankingStage::record_transactions(&transactions, &results, &poh_recorder).unwrap();
|
BankingStage::record_transactions(&transactions, &results, &poh_recorder).unwrap();
|
||||||
let (_, entries) = entry_receiver.recv().unwrap();
|
let (_, entries) = entry_receiver.recv().unwrap();
|
||||||
assert_eq!(entries[0].0.transactions.len(), transactions.len() - 1);
|
assert_eq!(entries[0].0.transactions.len(), transactions.len() - 1);
|
||||||
|
@ -229,7 +229,7 @@ mod tests {
|
|||||||
use crate::blocktree::create_new_tmp_ledger;
|
use crate::blocktree::create_new_tmp_ledger;
|
||||||
use crate::blocktree::tests::entries_to_blobs;
|
use crate::blocktree::tests::entries_to_blobs;
|
||||||
use crate::entry::{create_ticks, next_entry, Entry};
|
use crate::entry::{create_ticks, next_entry, Entry};
|
||||||
use solana_runtime::bank::BankError;
|
use solana_runtime::bank::TransactionError;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
@ -383,32 +383,32 @@ mod tests {
|
|||||||
fn test_first_err() {
|
fn test_first_err() {
|
||||||
assert_eq!(first_err(&[Ok(())]), Ok(()));
|
assert_eq!(first_err(&[Ok(())]), Ok(()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_err(&[Ok(()), Err(BankError::DuplicateSignature)]),
|
first_err(&[Ok(()), Err(TransactionError::DuplicateSignature)]),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_err(&[
|
first_err(&[
|
||||||
Ok(()),
|
Ok(()),
|
||||||
Err(BankError::DuplicateSignature),
|
Err(TransactionError::DuplicateSignature),
|
||||||
Err(BankError::AccountInUse)
|
Err(TransactionError::AccountInUse)
|
||||||
]),
|
]),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_err(&[
|
first_err(&[
|
||||||
Ok(()),
|
Ok(()),
|
||||||
Err(BankError::AccountInUse),
|
Err(TransactionError::AccountInUse),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
]),
|
]),
|
||||||
Err(BankError::AccountInUse)
|
Err(TransactionError::AccountInUse)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_err(&[
|
first_err(&[
|
||||||
Err(BankError::AccountInUse),
|
Err(TransactionError::AccountInUse),
|
||||||
Ok(()),
|
Ok(()),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
]),
|
]),
|
||||||
Err(BankError::AccountInUse)
|
Err(TransactionError::AccountInUse)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ mod tests {
|
|||||||
// First, ensure the TX is rejected because of the unregistered last ID
|
// First, ensure the TX is rejected because of the unregistered last ID
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::BlockhashNotFound)
|
Err(TransactionError::BlockhashNotFound)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Now ensure the TX is accepted despite pointing to the ID of an empty entry.
|
// Now ensure the TX is accepted despite pointing to the ID of an empty entry.
|
||||||
@ -733,7 +733,7 @@ mod tests {
|
|||||||
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!(
|
||||||
process_entries(&bank, &[entry_3]),
|
process_entries(&bank, &[entry_3]),
|
||||||
Err(BankError::AccountNotFound)
|
Err(TransactionError::AccountNotFound)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ pub enum Error {
|
|||||||
RecvTimeoutError(std::sync::mpsc::RecvTimeoutError),
|
RecvTimeoutError(std::sync::mpsc::RecvTimeoutError),
|
||||||
TryRecvError(std::sync::mpsc::TryRecvError),
|
TryRecvError(std::sync::mpsc::TryRecvError),
|
||||||
Serialize(std::boxed::Box<bincode::ErrorKind>),
|
Serialize(std::boxed::Box<bincode::ErrorKind>),
|
||||||
BankError(bank::BankError),
|
TransactionError(bank::TransactionError),
|
||||||
ClusterInfoError(cluster_info::ClusterInfoError),
|
ClusterInfoError(cluster_info::ClusterInfoError),
|
||||||
BlobError(packet::BlobError),
|
BlobError(packet::BlobError),
|
||||||
#[cfg(feature = "erasure")]
|
#[cfg(feature = "erasure")]
|
||||||
@ -57,9 +57,9 @@ impl std::convert::From<std::sync::mpsc::RecvTimeoutError> for Error {
|
|||||||
Error::RecvTimeoutError(e)
|
Error::RecvTimeoutError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::convert::From<bank::BankError> for Error {
|
impl std::convert::From<bank::TransactionError> for Error {
|
||||||
fn from(e: bank::BankError) -> Error {
|
fn from(e: bank::TransactionError) -> Error {
|
||||||
Error::BankError(e)
|
Error::TransactionError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::convert::From<cluster_info::ClusterInfoError> for Error {
|
impl std::convert::From<cluster_info::ClusterInfoError> for Error {
|
||||||
|
@ -9,7 +9,7 @@ use bs58;
|
|||||||
use jsonrpc_core::{Error, ErrorCode, Metadata, Result};
|
use jsonrpc_core::{Error, ErrorCode, Metadata, Result};
|
||||||
use jsonrpc_derive::rpc;
|
use jsonrpc_derive::rpc;
|
||||||
use solana_drone::drone::request_airdrop_transaction;
|
use solana_drone::drone::request_airdrop_transaction;
|
||||||
use solana_runtime::bank::{self, Bank, BankError};
|
use solana_runtime::bank::{self, Bank, TransactionError};
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
@ -261,9 +261,11 @@ impl RpcSol for RpcSolImpl {
|
|||||||
} else {
|
} else {
|
||||||
match res.unwrap() {
|
match res.unwrap() {
|
||||||
Ok(_) => RpcSignatureStatus::Confirmed,
|
Ok(_) => RpcSignatureStatus::Confirmed,
|
||||||
Err(BankError::AccountInUse) => RpcSignatureStatus::AccountInUse,
|
Err(TransactionError::AccountInUse) => RpcSignatureStatus::AccountInUse,
|
||||||
Err(BankError::AccountLoadedTwice) => RpcSignatureStatus::AccountLoadedTwice,
|
Err(TransactionError::AccountLoadedTwice) => {
|
||||||
Err(BankError::InstructionError(_, _)) => {
|
RpcSignatureStatus::AccountLoadedTwice
|
||||||
|
}
|
||||||
|
Err(TransactionError::InstructionError(_, _)) => {
|
||||||
RpcSignatureStatus::ProgramRuntimeError
|
RpcSignatureStatus::ProgramRuntimeError
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -6,7 +6,7 @@ use core::hash::Hash;
|
|||||||
use jsonrpc_core::futures::Future;
|
use jsonrpc_core::futures::Future;
|
||||||
use jsonrpc_pubsub::typed::Sink;
|
use jsonrpc_pubsub::typed::Sink;
|
||||||
use jsonrpc_pubsub::SubscriptionId;
|
use jsonrpc_pubsub::SubscriptionId;
|
||||||
use solana_runtime::bank::{self, Bank, BankError};
|
use solana_runtime::bank::{self, Bank, TransactionError};
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
@ -98,8 +98,10 @@ impl RpcSubscriptions {
|
|||||||
pub fn check_signature(&self, signature: &Signature, bank_error: &bank::Result<()>) {
|
pub fn check_signature(&self, signature: &Signature, bank_error: &bank::Result<()>) {
|
||||||
let status = match bank_error {
|
let status = match bank_error {
|
||||||
Ok(_) => RpcSignatureStatus::Confirmed,
|
Ok(_) => RpcSignatureStatus::Confirmed,
|
||||||
Err(BankError::AccountInUse) => RpcSignatureStatus::AccountInUse,
|
Err(TransactionError::AccountInUse) => RpcSignatureStatus::AccountInUse,
|
||||||
Err(BankError::InstructionError(_, _)) => RpcSignatureStatus::ProgramRuntimeError,
|
Err(TransactionError::InstructionError(_, _)) => {
|
||||||
|
RpcSignatureStatus::ProgramRuntimeError
|
||||||
|
}
|
||||||
Err(_) => RpcSignatureStatus::GenericFailure,
|
Err(_) => RpcSignatureStatus::GenericFailure,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_runtime::bank::BankError;
|
use solana_runtime::bank::TransactionError;
|
||||||
use solana_runtime::loader_utils::load_program;
|
use solana_runtime::loader_utils::load_program;
|
||||||
use solana_runtime::runtime::InstructionError;
|
use solana_runtime::runtime::InstructionError;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
@ -26,7 +26,7 @@ fn test_program_native_failure() {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
InstructionError::ProgramError(ProgramError::GenericError)
|
InstructionError::ProgramError(ProgramError::GenericError)
|
||||||
))
|
))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use solana_runtime::bank::BankError;
|
use solana_runtime::bank::TransactionError;
|
||||||
use solana_runtime::bank::{Bank, Result};
|
use solana_runtime::bank::{Bank, Result};
|
||||||
use solana_runtime::runtime::InstructionError;
|
use solana_runtime::runtime::InstructionError;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
@ -135,7 +135,7 @@ fn test_vote_via_bank_with_no_signature() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
Err(BankError::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
1,
|
1,
|
||||||
InstructionError::ProgramError(ProgramError::InvalidArgument)
|
InstructionError::ProgramError(ProgramError::InvalidArgument)
|
||||||
))
|
))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::append_vec::AppendVec;
|
use crate::append_vec::AppendVec;
|
||||||
use crate::bank::{BankError, Result};
|
use crate::bank::{Result, TransactionError};
|
||||||
use crate::runtime::has_duplicates;
|
use crate::runtime::has_duplicates;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
@ -608,12 +608,12 @@ impl AccountsDB {
|
|||||||
) -> Result<Vec<Account>> {
|
) -> Result<Vec<Account>> {
|
||||||
// Copy all the accounts
|
// Copy all the accounts
|
||||||
if tx.signatures.is_empty() && tx.fee != 0 {
|
if tx.signatures.is_empty() && tx.fee != 0 {
|
||||||
Err(BankError::MissingSignatureForFee)
|
Err(TransactionError::MissingSignatureForFee)
|
||||||
} else {
|
} else {
|
||||||
// Check for unique account keys
|
// Check for unique account keys
|
||||||
if has_duplicates(&tx.account_keys) {
|
if has_duplicates(&tx.account_keys) {
|
||||||
error_counters.account_loaded_twice += 1;
|
error_counters.account_loaded_twice += 1;
|
||||||
return Err(BankError::AccountLoadedTwice);
|
return Err(TransactionError::AccountLoadedTwice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is no way to predict what program will execute without an error
|
// There is no way to predict what program will execute without an error
|
||||||
@ -624,10 +624,10 @@ impl AccountsDB {
|
|||||||
}
|
}
|
||||||
if called_accounts.is_empty() || called_accounts[0].lamports == 0 {
|
if called_accounts.is_empty() || called_accounts[0].lamports == 0 {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
Err(BankError::AccountNotFound)
|
Err(TransactionError::AccountNotFound)
|
||||||
} else if called_accounts[0].lamports < tx.fee {
|
} else if called_accounts[0].lamports < tx.fee {
|
||||||
error_counters.insufficient_funds += 1;
|
error_counters.insufficient_funds += 1;
|
||||||
Err(BankError::InsufficientFundsForFee)
|
Err(TransactionError::InsufficientFundsForFee)
|
||||||
} else {
|
} else {
|
||||||
called_accounts[0].lamports -= tx.fee;
|
called_accounts[0].lamports -= tx.fee;
|
||||||
Ok(called_accounts)
|
Ok(called_accounts)
|
||||||
@ -652,7 +652,7 @@ impl AccountsDB {
|
|||||||
|
|
||||||
if depth >= 5 {
|
if depth >= 5 {
|
||||||
error_counters.call_chain_too_deep += 1;
|
error_counters.call_chain_too_deep += 1;
|
||||||
return Err(BankError::CallChainTooDeep);
|
return Err(TransactionError::CallChainTooDeep);
|
||||||
}
|
}
|
||||||
depth += 1;
|
depth += 1;
|
||||||
|
|
||||||
@ -660,12 +660,12 @@ impl AccountsDB {
|
|||||||
Some(program) => program,
|
Some(program) => program,
|
||||||
None => {
|
None => {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
return Err(BankError::AccountNotFound);
|
return Err(TransactionError::AccountNotFound);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !program.executable || program.owner == Pubkey::default() {
|
if !program.executable || program.owner == Pubkey::default() {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
return Err(BankError::AccountNotFound);
|
return Err(TransactionError::AccountNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add loader to chain
|
// add loader to chain
|
||||||
@ -688,7 +688,7 @@ impl AccountsDB {
|
|||||||
.map(|ix| {
|
.map(|ix| {
|
||||||
if tx.program_ids.len() <= ix.program_ids_index as usize {
|
if tx.program_ids.len() <= ix.program_ids_index as usize {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
return Err(BankError::AccountNotFound);
|
return Err(TransactionError::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)
|
||||||
@ -889,7 +889,7 @@ impl Accounts {
|
|||||||
for k in keys {
|
for k in keys {
|
||||||
if locks.contains(k) {
|
if locks.contains(k) {
|
||||||
error_counters.account_in_use += 1;
|
error_counters.account_in_use += 1;
|
||||||
return Err(BankError::AccountInUse);
|
return Err(TransactionError::AccountInUse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k in keys {
|
for k in keys {
|
||||||
@ -905,7 +905,7 @@ impl Accounts {
|
|||||||
account_locks: &mut HashMap<Fork, HashSet<Pubkey>>,
|
account_locks: &mut HashMap<Fork, HashSet<Pubkey>>,
|
||||||
) {
|
) {
|
||||||
match result {
|
match result {
|
||||||
Err(BankError::AccountInUse) => (),
|
Err(TransactionError::AccountInUse) => (),
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(locks) = account_locks.get_mut(&fork) {
|
if let Some(locks) = account_locks.get_mut(&fork) {
|
||||||
for k in &tx.account_keys {
|
for k in &tx.account_keys {
|
||||||
@ -1060,7 +1060,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountNotFound));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::AccountNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1084,7 +1084,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountNotFound));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::AccountNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1116,7 +1116,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountNotFound));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::AccountNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1144,7 +1144,10 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.insufficient_funds, 1);
|
assert_eq!(error_counters.insufficient_funds, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::InsufficientFundsForFee));
|
assert_eq!(
|
||||||
|
loaded_accounts[0],
|
||||||
|
Err(TransactionError::InsufficientFundsForFee)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1248,7 +1251,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.call_chain_too_deep, 1);
|
assert_eq!(error_counters.call_chain_too_deep, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::CallChainTooDeep));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::CallChainTooDeep));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1282,7 +1285,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountNotFound));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::AccountNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1315,7 +1318,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountNotFound));
|
assert_eq!(loaded_accounts[0], Err(TransactionError::AccountNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1408,7 +1411,10 @@ mod tests {
|
|||||||
assert_eq!(error_counters.account_loaded_twice, 1);
|
assert_eq!(error_counters.account_loaded_twice, 1);
|
||||||
assert_eq!(loaded_accounts.len(), 1);
|
assert_eq!(loaded_accounts.len(), 1);
|
||||||
loaded_accounts[0].clone().unwrap_err();
|
loaded_accounts[0].clone().unwrap_err();
|
||||||
assert_eq!(loaded_accounts[0], Err(BankError::AccountLoadedTwice));
|
assert_eq!(
|
||||||
|
loaded_accounts[0],
|
||||||
|
Err(TransactionError::AccountLoadedTwice)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@ -1867,7 +1873,7 @@ mod tests {
|
|||||||
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(TransactionError::AccountNotFound)
|
||||||
);
|
);
|
||||||
assert_eq!(error_counters.account_not_found, 1);
|
assert_eq!(error_counters.account_not_found, 1);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ impl EpochSchedule {
|
|||||||
|
|
||||||
/// Reasons a transaction might be rejected.
|
/// Reasons a transaction might be rejected.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum BankError {
|
pub enum TransactionError {
|
||||||
/// This Pubkey is being processed in another transaction
|
/// This Pubkey is being processed in another transaction
|
||||||
AccountInUse,
|
AccountInUse,
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ pub enum BankError {
|
|||||||
MissingSignatureForFee,
|
MissingSignatureForFee,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, BankError>;
|
pub type Result<T> = result::Result<T, TransactionError>;
|
||||||
|
|
||||||
type BankStatusCache = StatusCache<BankError>;
|
type BankStatusCache = StatusCache<TransactionError>;
|
||||||
|
|
||||||
/// Manager for the state of all accounts and programs after processing its entries.
|
/// Manager for the state of all accounts and programs after processing its entries.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -395,9 +395,9 @@ impl Bank {
|
|||||||
status_cache.add(&tx.signatures[0]);
|
status_cache.add(&tx.signatures[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(BankError::BlockhashNotFound) => (),
|
Err(TransactionError::BlockhashNotFound) => (),
|
||||||
Err(BankError::DuplicateSignature) => (),
|
Err(TransactionError::DuplicateSignature) => (),
|
||||||
Err(BankError::AccountNotFound) => (),
|
Err(TransactionError::AccountNotFound) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !tx.signatures.is_empty() {
|
if !tx.signatures.is_empty() {
|
||||||
status_cache.add(&tx.signatures[0]);
|
status_cache.add(&tx.signatures[0]);
|
||||||
@ -512,7 +512,7 @@ impl Bank {
|
|||||||
.map(|(tx, lock_res)| {
|
.map(|(tx, lock_res)| {
|
||||||
if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_blockhash, max_age) {
|
if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_blockhash, max_age) {
|
||||||
error_counters.reserve_blockhash += 1;
|
error_counters.reserve_blockhash += 1;
|
||||||
Err(BankError::BlockhashNotFound)
|
Err(TransactionError::BlockhashNotFound)
|
||||||
} else {
|
} else {
|
||||||
lock_res
|
lock_res
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
if lock_res.is_ok() && StatusCache::has_signature_all(&caches, &tx.signatures[0]) {
|
if lock_res.is_ok() && StatusCache::has_signature_all(&caches, &tx.signatures[0]) {
|
||||||
error_counters.duplicate_signature += 1;
|
error_counters.duplicate_signature += 1;
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
} else {
|
} else {
|
||||||
lock_res
|
lock_res
|
||||||
}
|
}
|
||||||
@ -650,7 +650,7 @@ impl Bank {
|
|||||||
.iter()
|
.iter()
|
||||||
.zip(executed.iter())
|
.zip(executed.iter())
|
||||||
.map(|(tx, res)| match *res {
|
.map(|(tx, res)| match *res {
|
||||||
Err(BankError::InstructionError(_, _)) => {
|
Err(TransactionError::InstructionError(_, _)) => {
|
||||||
// Charge the transaction fee even in case of InstructionError
|
// Charge the transaction fee even in case of InstructionError
|
||||||
self.withdraw(&tx.account_keys[0], tx.fee)?;
|
self.withdraw(&tx.account_keys[0], tx.fee)?;
|
||||||
fees += tx.fee;
|
fees += tx.fee;
|
||||||
@ -759,14 +759,14 @@ impl Bank {
|
|||||||
match self.get_account(pubkey) {
|
match self.get_account(pubkey) {
|
||||||
Some(mut account) => {
|
Some(mut account) => {
|
||||||
if lamports > account.lamports {
|
if lamports > account.lamports {
|
||||||
return Err(BankError::InsufficientFundsForFee);
|
return Err(TransactionError::InsufficientFundsForFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
account.lamports -= lamports;
|
account.lamports -= lamports;
|
||||||
self.accounts.store_slow(self.accounts_id, pubkey, &account);
|
self.accounts.store_slow(self.accounts_id, pubkey, &account);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => Err(BankError::AccountNotFound),
|
None => Err(TransactionError::AccountNotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -942,7 +942,7 @@ mod tests {
|
|||||||
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(()));
|
||||||
assert_eq!(res[1], Err(BankError::AccountInUse));
|
assert_eq!(res[1], Err(TransactionError::AccountInUse));
|
||||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
||||||
assert_eq!(bank.get_balance(&key1), 1);
|
assert_eq!(bank.get_balance(&key1), 1);
|
||||||
assert_eq!(bank.get_balance(&key2), 0);
|
assert_eq!(bank.get_balance(&key2), 0);
|
||||||
@ -950,7 +950,7 @@ mod tests {
|
|||||||
// TODO: Transactions that fail to pay a fee could be dropped silently
|
// TODO: Transactions that fail to pay a fee could be dropped silently
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.get_signature_status(&t2.signatures[0]),
|
bank.get_signature_status(&t2.signatures[0]),
|
||||||
Some(Err(BankError::AccountInUse))
|
Some(Err(TransactionError::AccountInUse))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -989,7 +989,7 @@ mod tests {
|
|||||||
assert_eq!(bank.get_balance(&key2), 0);
|
assert_eq!(bank.get_balance(&key2), 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.get_signature_status(&t1.signatures[0]),
|
bank.get_signature_status(&t1.signatures[0]),
|
||||||
Some(Err(BankError::InstructionError(
|
Some(Err(TransactionError::InstructionError(
|
||||||
1,
|
1,
|
||||||
InstructionError::new_result_with_negative_lamports(),
|
InstructionError::new_result_with_negative_lamports(),
|
||||||
)))
|
)))
|
||||||
@ -1037,7 +1037,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
InstructionError::new_result_with_negative_lamports(),
|
InstructionError::new_result_with_negative_lamports(),
|
||||||
))
|
))
|
||||||
@ -1057,7 +1057,7 @@ mod tests {
|
|||||||
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(TransactionError::AccountNotFound)
|
||||||
);
|
);
|
||||||
assert_eq!(bank.transaction_count(), 0);
|
assert_eq!(bank.transaction_count(), 0);
|
||||||
}
|
}
|
||||||
@ -1073,7 +1073,7 @@ mod tests {
|
|||||||
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::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
InstructionError::new_result_with_negative_lamports(),
|
InstructionError::new_result_with_negative_lamports(),
|
||||||
))
|
))
|
||||||
@ -1119,7 +1119,7 @@ mod tests {
|
|||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.withdraw(&key.pubkey(), 10),
|
bank.withdraw(&key.pubkey(), 10),
|
||||||
Err(BankError::AccountNotFound)
|
Err(TransactionError::AccountNotFound)
|
||||||
);
|
);
|
||||||
|
|
||||||
bank.deposit(&key.pubkey(), 3);
|
bank.deposit(&key.pubkey(), 3);
|
||||||
@ -1128,7 +1128,7 @@ mod tests {
|
|||||||
// Low balance
|
// Low balance
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.withdraw(&key.pubkey(), 10),
|
bank.withdraw(&key.pubkey(), 10),
|
||||||
Err(BankError::InsufficientFundsForFee)
|
Err(TransactionError::InsufficientFundsForFee)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Enough balance
|
// Enough balance
|
||||||
@ -1174,7 +1174,7 @@ mod tests {
|
|||||||
|
|
||||||
let results = vec![
|
let results = vec![
|
||||||
Ok(()),
|
Ok(()),
|
||||||
Err(BankError::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
1,
|
1,
|
||||||
InstructionError::new_result_with_negative_lamports(),
|
InstructionError::new_result_with_negative_lamports(),
|
||||||
)),
|
)),
|
||||||
@ -1252,13 +1252,13 @@ 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(TransactionError::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(TransactionError::AccountInUse)
|
||||||
);
|
);
|
||||||
|
|
||||||
bank.unlock_accounts(&pay_alice, &results_alice);
|
bank.unlock_accounts(&pay_alice, &results_alice);
|
||||||
@ -1311,7 +1311,7 @@ mod tests {
|
|||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(TransactionError::DuplicateSignature)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1524,7 +1524,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::MissingSignatureForFee)
|
Err(TransactionError::MissingSignatureForFee)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set the fee to 0, this should give an InstructionError
|
// Set the fee to 0, this should give an InstructionError
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::bank::BankError;
|
use crate::bank::TransactionError;
|
||||||
use crate::native_loader;
|
use crate::native_loader;
|
||||||
use crate::system_program::SystemError;
|
use crate::system_program::SystemError;
|
||||||
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
|
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
|
||||||
@ -196,7 +196,7 @@ pub fn execute_transaction(
|
|||||||
loaders: &mut [Vec<(Pubkey, Account)>],
|
loaders: &mut [Vec<(Pubkey, Account)>],
|
||||||
tx_accounts: &mut [Account],
|
tx_accounts: &mut [Account],
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
) -> Result<(), BankError> {
|
) -> Result<(), TransactionError> {
|
||||||
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
|
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
|
||||||
let executable_accounts = &mut (&mut loaders[instruction.program_ids_index as usize]);
|
let executable_accounts = &mut (&mut loaders[instruction.program_ids_index as usize]);
|
||||||
let mut program_accounts = get_subset_unchecked_mut(tx_accounts, &instruction.accounts);
|
let mut program_accounts = get_subset_unchecked_mut(tx_accounts, &instruction.accounts);
|
||||||
@ -207,7 +207,7 @@ pub fn execute_transaction(
|
|||||||
&mut program_accounts,
|
&mut program_accounts,
|
||||||
tick_height,
|
tick_height,
|
||||||
)
|
)
|
||||||
.map_err(|err| BankError::InstructionError(instruction_index as u8, err))?;
|
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -167,10 +167,10 @@ impl<T: Clone> StatusCache<T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::bank::BankError;
|
use crate::bank::TransactionError;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
|
|
||||||
type BankStatusCache = StatusCache<BankError>;
|
type BankStatusCache = StatusCache<TransactionError>;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_signature() {
|
fn test_has_signature() {
|
||||||
@ -293,11 +293,11 @@ mod tests {
|
|||||||
let blockhash = hash(Hash::default().as_ref());
|
let blockhash = hash(Hash::default().as_ref());
|
||||||
let mut first = StatusCache::new(&blockhash);
|
let mut first = StatusCache::new(&blockhash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
first.save_failure_status(&sig, TransactionError::DuplicateSignature);
|
||||||
assert_eq!(first.has_signature(&sig), true);
|
assert_eq!(first.has_signature(&sig), true);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first.get_signature_status(&sig),
|
first.get_signature_status(&sig),
|
||||||
Some(Err(BankError::DuplicateSignature)),
|
Some(Err(TransactionError::DuplicateSignature)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,10 +308,10 @@ mod tests {
|
|||||||
let mut first = StatusCache::new(&blockhash);
|
let mut first = StatusCache::new(&blockhash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.has_signature(&sig), true);
|
assert_eq!(first.has_signature(&sig), true);
|
||||||
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
first.save_failure_status(&sig, TransactionError::DuplicateSignature);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first.get_signature_status(&sig),
|
first.get_signature_status(&sig),
|
||||||
Some(Err(BankError::DuplicateSignature)),
|
Some(Err(TransactionError::DuplicateSignature)),
|
||||||
);
|
);
|
||||||
first.clear();
|
first.clear();
|
||||||
assert_eq!(first.has_signature(&sig), false);
|
assert_eq!(first.has_signature(&sig), false);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use solana_runtime::bank::{Bank, BankError};
|
use solana_runtime::bank::{Bank, TransactionError};
|
||||||
use solana_runtime::runtime::InstructionError;
|
use solana_runtime::runtime::InstructionError;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::native_program::ProgramError;
|
use solana_sdk::native_program::ProgramError;
|
||||||
@ -47,7 +47,7 @@ fn test_system_unsigned_transaction() {
|
|||||||
.sign(&[&to_keypair], blockhash);
|
.sign(&[&to_keypair], blockhash);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
system_bank.bank.process_transaction(&tx),
|
system_bank.bank.process_transaction(&tx),
|
||||||
Err(BankError::InstructionError(
|
Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
|
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
|
||||||
))
|
))
|
||||||
|
Reference in New Issue
Block a user