Move TransactionError into the SDK
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use crate::append_vec::AppendVec;
|
||||
use crate::bank::{Result, TransactionError};
|
||||
use crate::bank::Result;
|
||||
use crate::runtime::has_duplicates;
|
||||
use bincode::serialize;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
@ -11,7 +11,7 @@ use solana_sdk::hash::{hash, Hash};
|
||||
use solana_sdk::native_loader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||
use solana_vote_api;
|
||||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
use crate::accounts::{Accounts, ErrorCounters, InstructionAccounts, InstructionLoaders};
|
||||
use crate::hash_queue::HashQueue;
|
||||
use crate::runtime::{self, InstructionError};
|
||||
use crate::runtime;
|
||||
use crate::status_cache::StatusCache;
|
||||
use bincode::serialize;
|
||||
use hashbrown::HashMap;
|
||||
@ -19,7 +19,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, Signature};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::timing::{duration_as_us, MAX_RECENT_BLOCKHASHES, NUM_TICKS_PER_SECOND};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||
use solana_vote_api::vote_instruction::Vote;
|
||||
use solana_vote_api::vote_state::{Lockout, VoteState};
|
||||
use std::result;
|
||||
@ -104,41 +104,6 @@ impl EpochSchedule {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reasons a transaction might be rejected.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum TransactionError {
|
||||
/// This Pubkey is being processed in another transaction
|
||||
AccountInUse,
|
||||
|
||||
/// Pubkey appears twice in the same transaction, typically in a pay-to-self
|
||||
/// transaction.
|
||||
AccountLoadedTwice,
|
||||
|
||||
/// Attempt to debit from `Pubkey`, but no found no record of a prior credit.
|
||||
AccountNotFound,
|
||||
|
||||
/// The from `Pubkey` does not have sufficient balance to pay the fee to schedule the transaction
|
||||
InsufficientFundsForFee,
|
||||
|
||||
/// The bank has seen `Signature` before. This can occur under normal operation
|
||||
/// when a UDP packet is duplicated, as a user error from a client not updating
|
||||
/// its `recent_blockhash`, or as a double-spend attack.
|
||||
DuplicateSignature,
|
||||
|
||||
/// The bank has not seen the given `recent_blockhash` or the transaction is too old and
|
||||
/// the `recent_blockhash` has been discarded.
|
||||
BlockhashNotFound,
|
||||
|
||||
/// The program returned an error
|
||||
InstructionError(u8, InstructionError),
|
||||
|
||||
/// Loader call chain too deep
|
||||
CallChainTooDeep,
|
||||
|
||||
/// Transaction has a fee but has no signature present
|
||||
MissingSignatureForFee,
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, TransactionError>;
|
||||
|
||||
type BankStatusCache = StatusCache<TransactionError>;
|
||||
@ -882,7 +847,7 @@ mod tests {
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::system_program;
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::transaction::Instruction;
|
||||
use solana_sdk::transaction::{Instruction, InstructionError};
|
||||
|
||||
#[test]
|
||||
fn test_bank_new() {
|
||||
|
@ -1,38 +1,9 @@
|
||||
use crate::bank::TransactionError;
|
||||
use crate::native_loader;
|
||||
use crate::system_program::SystemError;
|
||||
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::system_program;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
|
||||
/// Reasons the runtime might have rejected an instruction.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum InstructionError {
|
||||
/// Executing the instruction produced an error.
|
||||
ProgramError(ProgramError),
|
||||
|
||||
/// Program's instruction lamport balance does not equal the balance after the instruction
|
||||
UnbalancedInstruction,
|
||||
|
||||
/// Program modified an account's program id
|
||||
ModifiedProgramId,
|
||||
|
||||
/// Program spent the lamports of an account that doesn't belong to it
|
||||
ExternalAccountLamportSpend,
|
||||
|
||||
/// Program modified the userdata of an account that doesn't belong to it
|
||||
ExternalAccountUserdataModified,
|
||||
}
|
||||
|
||||
impl InstructionError {
|
||||
pub fn new_result_with_negative_lamports() -> Self {
|
||||
let serialized_error =
|
||||
bincode::serialize(&SystemError::ResultWithNegativeLamports).unwrap();
|
||||
InstructionError::ProgramError(ProgramError::CustomError(serialized_error))
|
||||
}
|
||||
}
|
||||
use solana_sdk::transaction::{InstructionError, Transaction, TransactionError};
|
||||
|
||||
/// Process an instruction
|
||||
/// This method calls the instruction's program entrypoint method
|
||||
|
@ -167,8 +167,8 @@ impl<T: Clone> StatusCache<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bank::TransactionError;
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::transaction::TransactionError;
|
||||
|
||||
type BankStatusCache = StatusCache<TransactionError>;
|
||||
|
||||
|
@ -1,22 +1,14 @@
|
||||
use bincode::serialize;
|
||||
use log::*;
|
||||
use serde_derive::Serialize;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::system_instruction::{SystemError, SystemInstruction};
|
||||
use solana_sdk::system_program;
|
||||
|
||||
const FROM_ACCOUNT_INDEX: usize = 0;
|
||||
const TO_ACCOUNT_INDEX: usize = 1;
|
||||
|
||||
#[derive(Serialize, Debug, Clone, PartialEq)]
|
||||
pub enum SystemError {
|
||||
AccountAlreadyInUse,
|
||||
ResultWithNegativeLamports,
|
||||
SourceNotSystemAccount,
|
||||
}
|
||||
|
||||
fn create_system_account(
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
lamports: u64,
|
||||
|
@ -1,10 +1,10 @@
|
||||
use solana_runtime::bank::{Bank, TransactionError};
|
||||
use solana_runtime::runtime::InstructionError;
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::system_program;
|
||||
use solana_sdk::transaction::{InstructionError, TransactionError};
|
||||
use solana_sdk::transaction_builder::{BuilderInstruction, TransactionBuilder};
|
||||
|
||||
struct SystemBank<'a> {
|
||||
|
Reference in New Issue
Block a user