-
Notifications
You must be signed in to change notification settings - Fork 239
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
Extract instruction crate #2405
Conversation
The Firedancer team maintains a line-for-line reimplementation of the |
68b1078
to
b3d20cd
Compare
b3d20cd
to
df7249d
Compare
3da2871
to
461914f
Compare
d446961
to
7c9d7dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lateness, this one was pretty chunky, and I wanted to figure out a future for syscall stubs. Looks great! Just some tiny things.
sdk/instruction/src/error.rs
Outdated
// Warning: Any new error codes added here must also be: | ||
// - Added to the below conversions | ||
// - Added as an equivalent to ProgramError and InstructionError | ||
// - Be featureized in the BPF loader to return `InstructionError::InvalidError` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit typo (I know you didn't do this, but now that it's being moved, we can fix it)
// - Be featureized in the BPF loader to return `InstructionError::InvalidError` | |
// - Be featurized in the BPF loader to return `InstructionError::InvalidError` |
sdk/instruction/src/lib.rs
Outdated
/// Addition that returns [`InstructionError::InsufficientFunds`] on overflow. | ||
/// | ||
/// This is an internal utility function. | ||
#[doc(hidden)] | ||
pub fn checked_add(a: u64, b: u64) -> Result<u64, InstructionError> { | ||
a.checked_add(b).ok_or(InstructionError::InsufficientFunds) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so strange, but it looks like it has uses in the stake and system program. Can you leave it in solana_program
with a note saying to remove it?
sdk/instruction/src/lib.rs
Outdated
/// Describes a single account read or written by a program during instruction | ||
/// execution. | ||
/// | ||
/// When constructing an [`Instruction`], a list of all accounts that may be | ||
/// read or written during the execution of that instruction must be supplied. | ||
/// Any account that may be mutated by the program during execution, either its | ||
/// data or metadata such as held lamports, must be writable. | ||
/// | ||
/// Note that because the Solana runtime schedules parallel transaction | ||
/// execution around which accounts are writable, care should be taken that only | ||
/// accounts which actually may be mutated are specified as writable. As the | ||
/// default [`AccountMeta::new`] constructor creates writable accounts, this is | ||
/// a minor hazard: use [`AccountMeta::new_readonly`] to specify that an account | ||
/// is not writable. | ||
#[repr(C)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Debug, Default, PartialEq, Eq, Clone)] | ||
pub struct AccountMeta { | ||
/// An account's public key. | ||
pub pubkey: Pubkey, | ||
/// True if an `Instruction` requires a `Transaction` signature matching `pubkey`. | ||
pub is_signer: bool, | ||
/// True if the account data or metadata may be mutated during program execution. | ||
pub is_writable: bool, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move AccountMeta
into a separate file? It'll make things neater when adding a new instruction type
sdk/instruction/src/lib.rs
Outdated
serde(rename_all = "camelCase") | ||
)] | ||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct CompiledInstruction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, I really think this belongs more in Message
than Instruction
, but it's currently exported from instruction
... what do you think about leaving this in solana_program
for now, and then moving it to solana_message
whenever that gets broken out? Without breaking the re-exports from solana_program
, of course.
That'll also remove the dep on solana-sanitize
…olana-program to avoid breaking change
a338945
to
d2564f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last question around AccountMeta
, otherwise this is looking good!
"dep:rustc_version", | ||
"dep:solana-frozen-abi", | ||
"dep:solana-frozen-abi-macro", | ||
"serde", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I noticed this was needed while testing, thanks for fixing!
sdk/instruction/src/account_meta.rs
Outdated
@@ -0,0 +1,105 @@ | |||
#[cfg(any(feature = "std", target_arch = "wasm32"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something -- why is this gated on the std feature / wasm32 arch? It should be usable regardless of features and all that, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I took another look and realised this can be much simpler, had been assuming the wasm32 code needed std because we have other places where that's the case but it's not the case here
sdk/instruction/src/account_meta.rs
Outdated
/// default [`AccountMeta::new`] constructor creates writable accounts, this is | ||
/// a minor hazard: use [`AccountMeta::new_readonly`] to specify that an account | ||
/// is not writable. | ||
#[cfg(any(feature = "std", target_arch = "wasm32"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this, is the featurization / arch cfg needed?
/// an error be consistent across software versions. For example, it is | ||
/// dangerous to include error strings from 3rd party crates because they could | ||
/// change at any time and changes to them are difficult to detect. | ||
#[cfg(feature = "std")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is no-std because of the String in one of the errors, correct? I hope we can make a breaking change to make this no-std in the future...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
@yihau can you accept the ownership for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go from my side -- thanks for responding to all the feedback so quickly!
automerge label removed due to a CI failure |
all green! |
* extract instruction crate * remove thiserror * make bincode optional in solana-instruction * make serde optional in solana-instruction * fix doc tests * fmt * harmonize features * fmt Cargo.toml * clippy * fix syscalls.rs imports * update digests * update digest * unused imports * post-rebase fmt * fix doc links * use workspace lints * fmt * make rustc_version dep optional * update digest * update digest * update import * fmt * fix dup import * remove dev-context-only-utils (no longer needed) * fmt * remove unnecessary allow() * fix overwriting instruction syscall stubs * fmt * move get_processed_sibling_instruction and get_stack_height back to solana-program to avoid breaking change * fix path * fix typo * move the checked_add utility function back to solana-program * move AccountMeta to its own file * fix bad import * move ProcessedSiblingInstruction to syscalls.rs * move CompiledInstruction back to solana-program * move ProcessedSiblingInstruction back into lib.rs * make std optional in solana-instruction * fix required features for frozen-abi * update digest * update digest * missing import * update digest * don't assume std is imported in frozen-abi macros * fix import warnings * simplify cfg usage
Problem
solana_program::instruction
needs to be made available outsidesolana_program
This branches off #2394 so that needs to be merged first
Summary of Changes
solana_instruction
crate and re-export the relevant contents insolana_program::instruction
for backwards compatibilityACCOUNT_ALREADY_INITIALIZED
etc) andimpl<T> From<T> for InstructionError
fromprogram_error.rs
tosolana-instruction
. The compiler requires this.Fun fact: a release build of the new crate without default features takes <1 second on my machine