Add Rust BPF Tick Height test (#4718)
This commit is contained in:
parent
e43a634944
commit
fdb57bc5db
|
@ -67,7 +67,15 @@ fn main() {
|
||||||
.expect("Unable to create BPF install directory")
|
.expect("Unable to create BPF install directory")
|
||||||
.success());
|
.success());
|
||||||
|
|
||||||
let rust_programs = ["alloc", "dep_crate", "iter", "many_args", "noop", "panic"];
|
let rust_programs = [
|
||||||
|
"alloc",
|
||||||
|
"dep_crate",
|
||||||
|
"iter",
|
||||||
|
"many_args",
|
||||||
|
"noop",
|
||||||
|
"panic",
|
||||||
|
"tick_height",
|
||||||
|
];
|
||||||
for program in rust_programs.iter() {
|
for program in rust_programs.iter() {
|
||||||
println!(
|
println!(
|
||||||
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
/target/
|
||||||
|
|
||||||
|
Cargo.lock
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
# Note: This crate must be built using build.sh
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "solana-bpf-rust-tick-height"
|
||||||
|
version = "0.16.0"
|
||||||
|
description = "Solana BPF noop program written in Rust"
|
||||||
|
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||||
|
repository = "https://github.com/solana-labs/solana"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
homepage = "https://solana.com/"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
byteorder = { version = "1", default-features = false }
|
||||||
|
|
||||||
|
solana-sdk-bpf-utils = { path = "../../../../sdk/bpf/rust/rust-utils", version = "0.16.0" }
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = []
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
name = "solana_bpf_rust_tick_height"
|
|
@ -0,0 +1,6 @@
|
||||||
|
[dependencies.compiler_builtins]
|
||||||
|
path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/compiler-builtins"
|
||||||
|
features = ["c", "mem"]
|
||||||
|
|
||||||
|
[target.bpfel-unknown-unknown.dependencies]
|
||||||
|
alloc = { path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/liballoc" }
|
|
@ -0,0 +1,27 @@
|
||||||
|
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
#![allow(unreachable_code)]
|
||||||
|
|
||||||
|
extern crate solana_sdk_bpf_utils;
|
||||||
|
|
||||||
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
use solana_sdk_bpf_utils::entrypoint;
|
||||||
|
use solana_sdk_bpf_utils::entrypoint::*;
|
||||||
|
use solana_sdk_bpf_utils::log::*;
|
||||||
|
|
||||||
|
entrypoint!(process_instruction);
|
||||||
|
fn process_instruction(
|
||||||
|
ka: &mut [Option<SolKeyedAccount>; MAX_ACCOUNTS],
|
||||||
|
_info: &SolClusterInfo,
|
||||||
|
_data: &[u8],
|
||||||
|
) -> bool {
|
||||||
|
sol_log("Tick Height:");
|
||||||
|
if let Some(k) = &ka[2] {
|
||||||
|
let tick_height = LittleEndian::read_u64(k.data);
|
||||||
|
assert_eq!(10u64, tick_height);
|
||||||
|
sol_log("Success");
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
panic!();
|
||||||
|
}
|
|
@ -75,8 +75,10 @@ mod bpf {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::bpf_loader;
|
use solana_sdk::bpf_loader;
|
||||||
use solana_sdk::client::SyncClient;
|
use solana_sdk::client::SyncClient;
|
||||||
|
use solana_sdk::hash;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
|
use solana_sdk::syscall::tick_height;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -90,6 +92,7 @@ mod bpf {
|
||||||
("solana_bpf_rust_noop", true),
|
("solana_bpf_rust_noop", true),
|
||||||
("solana_bpf_rust_dep_crate", true),
|
("solana_bpf_rust_dep_crate", true),
|
||||||
("solana_bpf_rust_panic", false),
|
("solana_bpf_rust_panic", false),
|
||||||
|
("solana_bpf_rust_tick_height", true),
|
||||||
];
|
];
|
||||||
for program in programs.iter() {
|
for program in programs.iter() {
|
||||||
let filename = create_bpf_path(program.0);
|
let filename = create_bpf_path(program.0);
|
||||||
|
@ -104,6 +107,10 @@ mod bpf {
|
||||||
..
|
..
|
||||||
} = create_genesis_block(50);
|
} = create_genesis_block(50);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
// register some ticks, used by solana_bpf_rust_tick_height
|
||||||
|
for i in 0..10 {
|
||||||
|
bank.register_tick(&hash::hash(format!("hashing {}", i).as_bytes()));
|
||||||
|
}
|
||||||
let bank_client = BankClient::new(bank);
|
let bank_client = BankClient::new(bank);
|
||||||
|
|
||||||
// Call user program
|
// Call user program
|
||||||
|
@ -111,6 +118,7 @@ mod bpf {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||||
AccountMeta::new(Keypair::new().pubkey(), false),
|
AccountMeta::new(Keypair::new().pubkey(), false),
|
||||||
|
AccountMeta::new(tick_height::id(), false),
|
||||||
];
|
];
|
||||||
let instruction = Instruction::new(program_id, &1u8, account_metas);
|
let instruction = Instruction::new(program_id, &1u8, account_metas);
|
||||||
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
||||||
|
|
Loading…
Reference in New Issue