forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get_processed_sibling_instruction syscall (solana-labs#22859)
- Loading branch information
1 parent
9403e2f
commit a30d4a4
Showing
19 changed files
with
897 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "solana-bpf-rust-sibling_inner-instructions" | ||
version = "1.10.0" | ||
description = "Solana BPF test program written in Rust" | ||
authors = ["Solana Maintainers <[email protected]>"] | ||
repository = "https://github.com/solana-labs/solana" | ||
license = "Apache-2.0" | ||
homepage = "https://solana.com/" | ||
documentation = "https://docs.rs/solana-bpf-rust-log-data" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" } | ||
|
||
[features] | ||
default = ["program"] | ||
program = [] | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! Example Rust-based BPF program that queries sibling instructions | ||
#![cfg(feature = "program")] | ||
|
||
use solana_program::{ | ||
account_info::AccountInfo, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
instruction::{ | ||
get_processed_sibling_instruction, get_stack_height, AccountMeta, Instruction, | ||
TRANSACTION_LEVEL_STACK_HEIGHT, | ||
}, | ||
msg, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
_instruction_data: &[u8], | ||
) -> ProgramResult { | ||
msg!("sibling inner"); | ||
|
||
// account 0 is mint | ||
// account 1 is noop | ||
// account 2 is invoke_and_return | ||
|
||
// Check sibling instructions | ||
|
||
let sibling_instruction2 = Instruction::new_with_bytes( | ||
*accounts[2].key, | ||
&[3], | ||
vec![AccountMeta::new_readonly(*accounts[1].key, false)], | ||
); | ||
let sibling_instruction1 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[2], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[0].key, true), | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
], | ||
); | ||
let sibling_instruction0 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[1], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
AccountMeta::new_readonly(*accounts[0].key, true), | ||
], | ||
); | ||
|
||
assert_eq!(TRANSACTION_LEVEL_STACK_HEIGHT + 1, get_stack_height()); | ||
assert_eq!( | ||
get_processed_sibling_instruction(0), | ||
Some(sibling_instruction0) | ||
); | ||
assert_eq!( | ||
get_processed_sibling_instruction(1), | ||
Some(sibling_instruction1) | ||
); | ||
assert_eq!( | ||
get_processed_sibling_instruction(2), | ||
Some(sibling_instruction2) | ||
); | ||
assert_eq!(get_processed_sibling_instruction(3), None); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "solana-bpf-rust-sibling-instructions" | ||
version = "1.10.0" | ||
description = "Solana BPF test program written in Rust" | ||
authors = ["Solana Maintainers <[email protected]>"] | ||
repository = "https://github.com/solana-labs/solana" | ||
license = "Apache-2.0" | ||
homepage = "https://solana.com/" | ||
documentation = "https://docs.rs/solana-bpf-rust-log-data" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" } | ||
|
||
[features] | ||
default = ["program"] | ||
program = [] | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//! Example Rust-based BPF program that queries sibling instructions | ||
#![cfg(feature = "program")] | ||
|
||
use solana_program::{ | ||
account_info::AccountInfo, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
instruction::{ | ||
get_processed_sibling_instruction, get_stack_height, AccountMeta, Instruction, | ||
TRANSACTION_LEVEL_STACK_HEIGHT, | ||
}, | ||
msg, | ||
program::invoke, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
_instruction_data: &[u8], | ||
) -> ProgramResult { | ||
msg!("sibling"); | ||
|
||
// account 0 is mint | ||
// account 1 is noop | ||
// account 2 is invoke_and_return | ||
// account 3 is sibling_inner | ||
|
||
// Invoke child instructions | ||
|
||
let instruction3 = Instruction::new_with_bytes( | ||
*accounts[2].key, | ||
&[3], | ||
vec![AccountMeta::new_readonly(*accounts[1].key, false)], | ||
); | ||
let instruction2 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[2], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[0].key, true), | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
], | ||
); | ||
let instruction1 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[1], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
AccountMeta::new_readonly(*accounts[0].key, true), | ||
], | ||
); | ||
let instruction0 = Instruction::new_with_bytes( | ||
*accounts[3].key, | ||
&[0], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[0].key, false), | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
AccountMeta::new_readonly(*accounts[2].key, false), | ||
AccountMeta::new_readonly(*accounts[3].key, false), | ||
], | ||
); | ||
invoke(&instruction3, accounts)?; | ||
invoke(&instruction2, accounts)?; | ||
invoke(&instruction1, accounts)?; | ||
invoke(&instruction0, accounts)?; | ||
|
||
// Check sibling instructions | ||
|
||
let sibling_instruction1 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[43], | ||
vec![ | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
AccountMeta::new(*accounts[0].key, true), | ||
], | ||
); | ||
let sibling_instruction0 = Instruction::new_with_bytes( | ||
*accounts[1].key, | ||
&[42], | ||
vec![ | ||
AccountMeta::new(*accounts[0].key, true), | ||
AccountMeta::new_readonly(*accounts[1].key, false), | ||
], | ||
); | ||
|
||
assert_eq!(TRANSACTION_LEVEL_STACK_HEIGHT, get_stack_height()); | ||
assert_eq!( | ||
get_processed_sibling_instruction(0), | ||
Some(sibling_instruction0) | ||
); | ||
assert_eq!( | ||
get_processed_sibling_instruction(1), | ||
Some(sibling_instruction1) | ||
); | ||
assert_eq!(get_processed_sibling_instruction(2), None); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.