Make solana-address-lookup-table-program crate bpf compatible (#23700)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4287,6 +4287,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"solana-frozen-abi 1.10.3",
|
"solana-frozen-abi 1.10.3",
|
||||||
"solana-frozen-abi-macro 1.10.3",
|
"solana-frozen-abi-macro 1.10.3",
|
||||||
|
"solana-program 1.10.3",
|
||||||
"solana-program-runtime",
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
@ -18,9 +18,12 @@ num-traits = "0.2"
|
|||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
solana-frozen-abi = { path = "../../frozen-abi", version = "=1.10.3" }
|
solana-frozen-abi = { path = "../../frozen-abi", version = "=1.10.3" }
|
||||||
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.10.3" }
|
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.10.3" }
|
||||||
|
solana-program = { path = "../../sdk/program", version = "=1.10.3" }
|
||||||
|
thiserror = "1.0"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "bpf"))'.dependencies]
|
||||||
solana-program-runtime = { path = "../../program-runtime", version = "=1.10.3" }
|
solana-program-runtime = { path = "../../program-runtime", version = "=1.10.3" }
|
||||||
solana-sdk = { path = "../../sdk", version = "=1.10.3" }
|
solana-sdk = { path = "../../sdk", version = "=1.10.3" }
|
||||||
thiserror = "1.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
rustc_version = "0.4"
|
rustc_version = "0.4"
|
||||||
|
34
programs/address-lookup-table/src/error.rs
Normal file
34
programs/address-lookup-table/src/error.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
|
use solana_sdk::transaction::TransactionError;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error, PartialEq, Eq, Clone)]
|
||||||
|
pub enum AddressLookupError {
|
||||||
|
/// Attempted to lookup addresses from a table that does not exist
|
||||||
|
#[error("Attempted to lookup addresses from a table that does not exist")]
|
||||||
|
LookupTableAccountNotFound,
|
||||||
|
|
||||||
|
/// Attempted to lookup addresses from an account owned by the wrong program
|
||||||
|
#[error("Attempted to lookup addresses from an account owned by the wrong program")]
|
||||||
|
InvalidAccountOwner,
|
||||||
|
|
||||||
|
/// Attempted to lookup addresses from an invalid account
|
||||||
|
#[error("Attempted to lookup addresses from an invalid account")]
|
||||||
|
InvalidAccountData,
|
||||||
|
|
||||||
|
/// Address lookup contains an invalid index
|
||||||
|
#[error("Address lookup contains an invalid index")]
|
||||||
|
InvalidLookupIndex,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
|
impl From<AddressLookupError> for TransactionError {
|
||||||
|
fn from(err: AddressLookupError) -> Self {
|
||||||
|
match err {
|
||||||
|
AddressLookupError::LookupTableAccountNotFound => Self::AddressLookupTableNotFound,
|
||||||
|
AddressLookupError::InvalidAccountOwner => Self::InvalidAddressLookupTableOwner,
|
||||||
|
AddressLookupError::InvalidAccountData => Self::InvalidAddressLookupTableData,
|
||||||
|
AddressLookupError::InvalidLookupIndex => Self::InvalidAddressLookupTableIndex,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
use {
|
use {
|
||||||
crate::id,
|
crate::id,
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_sdk::{
|
solana_program::{
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
|
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
|
||||||
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
|
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
|
||||||
|
|
||||||
use solana_sdk::declare_id;
|
use solana_program::declare_id;
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
pub mod instruction;
|
pub mod instruction;
|
||||||
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub mod processor;
|
pub mod processor;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use {
|
use {
|
||||||
|
crate::error::AddressLookupError,
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample},
|
solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample},
|
||||||
solana_sdk::{
|
solana_program::{
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
slot_hashes::{SlotHashes, MAX_ENTRIES},
|
slot_hashes::{SlotHashes, MAX_ENTRIES},
|
||||||
transaction::AddressLookupError,
|
|
||||||
},
|
},
|
||||||
std::borrow::Cow,
|
std::borrow::Cow,
|
||||||
};
|
};
|
||||||
|
2
programs/bpf/Cargo.lock
generated
2
programs/bpf/Cargo.lock
generated
@ -2763,6 +2763,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"solana-frozen-abi 1.10.3",
|
"solana-frozen-abi 1.10.3",
|
||||||
"solana-frozen-abi-macro 1.10.3",
|
"solana-frozen-abi-macro 1.10.3",
|
||||||
|
"solana-program 1.10.3",
|
||||||
"solana-program-runtime",
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
@ -2901,6 +2902,7 @@ name = "solana-bpf-rust-dep-crate"
|
|||||||
version = "1.10.3"
|
version = "1.10.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.4.3",
|
"byteorder 1.4.3",
|
||||||
|
"solana-address-lookup-table-program",
|
||||||
"solana-program 1.10.3",
|
"solana-program 1.10.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = { version = "1", default-features = false }
|
byteorder = { version = "1", default-features = false }
|
||||||
solana-program = { path = "../../../../sdk/program", version = "=1.10.3" }
|
solana-program = { path = "../../../../sdk/program", version = "=1.10.3" }
|
||||||
|
# list of crates which must be buildable for bpf programs
|
||||||
|
solana-address-lookup-table-program = { path = "../../../../programs/address-lookup-table", version = "=1.10.3" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -23,7 +23,7 @@ use {
|
|||||||
},
|
},
|
||||||
log::*,
|
log::*,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
solana_address_lookup_table_program::state::AddressLookupTable,
|
solana_address_lookup_table_program::{error::AddressLookupError, state::AddressLookupTable},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
@ -43,10 +43,7 @@ use {
|
|||||||
slot_hashes::SlotHashes,
|
slot_hashes::SlotHashes,
|
||||||
system_program,
|
system_program,
|
||||||
sysvar::{self, instructions::construct_instructions_data},
|
sysvar::{self, instructions::construct_instructions_data},
|
||||||
transaction::{
|
transaction::{Result, SanitizedTransaction, TransactionAccountLocks, TransactionError},
|
||||||
AddressLookupError, Result, SanitizedTransaction, TransactionAccountLocks,
|
|
||||||
TransactionError,
|
|
||||||
},
|
|
||||||
transaction_context::TransactionAccount,
|
transaction_context::TransactionAccount,
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use {
|
use {
|
||||||
super::Bank,
|
super::Bank,
|
||||||
|
solana_address_lookup_table_program::error::AddressLookupError,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
message::v0::{LoadedAddresses, MessageAddressTableLookup},
|
message::v0::{LoadedAddresses, MessageAddressTableLookup},
|
||||||
transaction::{
|
transaction::{AddressLoader, Result as TransactionResult, TransactionError},
|
||||||
AddressLoader, AddressLookupError, Result as TransactionResult, TransactionError,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,33 +150,3 @@ impl From<SanitizeMessageError> for TransactionError {
|
|||||||
Self::SanitizeFailure
|
Self::SanitizeFailure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error, PartialEq, Eq, Clone)]
|
|
||||||
pub enum AddressLookupError {
|
|
||||||
/// Attempted to lookup addresses from a table that does not exist
|
|
||||||
#[error("Attempted to lookup addresses from a table that does not exist")]
|
|
||||||
LookupTableAccountNotFound,
|
|
||||||
|
|
||||||
/// Attempted to lookup addresses from an account owned by the wrong program
|
|
||||||
#[error("Attempted to lookup addresses from an account owned by the wrong program")]
|
|
||||||
InvalidAccountOwner,
|
|
||||||
|
|
||||||
/// Attempted to lookup addresses from an invalid account
|
|
||||||
#[error("Attempted to lookup addresses from an invalid account")]
|
|
||||||
InvalidAccountData,
|
|
||||||
|
|
||||||
/// Address lookup contains an invalid index
|
|
||||||
#[error("Address lookup contains an invalid index")]
|
|
||||||
InvalidLookupIndex,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AddressLookupError> for TransactionError {
|
|
||||||
fn from(err: AddressLookupError) -> Self {
|
|
||||||
match err {
|
|
||||||
AddressLookupError::LookupTableAccountNotFound => Self::AddressLookupTableNotFound,
|
|
||||||
AddressLookupError::InvalidAccountOwner => Self::InvalidAddressLookupTableOwner,
|
|
||||||
AddressLookupError::InvalidAccountData => Self::InvalidAddressLookupTableData,
|
|
||||||
AddressLookupError::InvalidLookupIndex => Self::InvalidAddressLookupTableIndex,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user