Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make solana-address-lookup-table-program crate bpf compatible #23700

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion programs/address-lookup-table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ num-traits = "0.2"
serde = { version = "1.0.136", features = ["derive"] }
solana-frozen-abi = { path = "../../frozen-abi", 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-sdk = { path = "../../sdk", version = "=1.10.3" }
thiserror = "1.0"

[build-dependencies]
rustc_version = "0.4"
Expand Down
34 changes: 34 additions & 0 deletions programs/address-lookup-table/src/error.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
Comment on lines +24 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what do you think about keeping just this part in solana-sdk? Then you can avoid at least one target_arch cfg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then solana-sdk would need to depend on solana-address-lookup-table-program and there would be a circular dependency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, of course

2 changes: 1 addition & 1 deletion programs/address-lookup-table/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::id,
serde::{Deserialize, Serialize},
solana_sdk::{
solana_program::{
clock::Slot,
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
Expand Down
4 changes: 3 additions & 1 deletion programs/address-lookup-table/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
#![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;
#[cfg(not(target_arch = "bpf"))]
pub mod processor;
pub mod state;

Expand Down
4 changes: 2 additions & 2 deletions programs/address-lookup-table/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use {
crate::error::AddressLookupError,
serde::{Deserialize, Serialize},
solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample},
solana_sdk::{
solana_program::{
clock::Slot,
instruction::InstructionError,
pubkey::Pubkey,
slot_hashes::{SlotHashes, MAX_ENTRIES},
transaction::AddressLookupError,
},
std::borrow::Cow,
};
Expand Down
2 changes: 2 additions & 0 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions programs/bpf/rust/dep_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ edition = "2021"
[dependencies]
byteorder = { version = "1", default-features = false }
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" }
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea!


[lib]
crate-type = ["cdylib"]
Expand Down
7 changes: 2 additions & 5 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use {
},
log::*,
rand::{thread_rng, Rng},
solana_address_lookup_table_program::state::AddressLookupTable,
solana_address_lookup_table_program::{error::AddressLookupError, state::AddressLookupTable},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
Expand All @@ -43,10 +43,7 @@ use {
slot_hashes::SlotHashes,
system_program,
sysvar::{self, instructions::construct_instructions_data},
transaction::{
AddressLookupError, Result, SanitizedTransaction, TransactionAccountLocks,
TransactionError,
},
transaction::{Result, SanitizedTransaction, TransactionAccountLocks, TransactionError},
transaction_context::TransactionAccount,
},
std::{
Expand Down
5 changes: 2 additions & 3 deletions runtime/src/bank/address_lookup_table.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use {
super::Bank,
solana_address_lookup_table_program::error::AddressLookupError,
solana_sdk::{
message::v0::{LoadedAddresses, MessageAddressTableLookup},
transaction::{
AddressLoader, AddressLookupError, Result as TransactionResult, TransactionError,
},
transaction::{AddressLoader, Result as TransactionResult, TransactionError},
},
};

Expand Down
30 changes: 0 additions & 30 deletions sdk/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,3 @@ impl From<SanitizeMessageError> for TransactionError {
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,
}
}
}