system_program must be a static lib as it allocates Account memory
This commit is contained in:
parent
8597701b0f
commit
59e6bd115e
|
@ -15,5 +15,9 @@ solana-sdk = { path = "../../../sdk", version = "0.11.0" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "solana_system_program"
|
name = "solana_system_program"
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
# Must be a static lib instead of cdylib because `SystemInstruction::CreateAccount`
|
||||||
|
# allocates Rust memory.
|
||||||
|
# cc: https://github.com/solana-labs/solana/issues/2004#issuecomment-444570081
|
||||||
|
crate-type = ["lib"]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
extern crate env_logger;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -11,21 +10,14 @@ use solana_sdk::native_program::ProgramError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
use std::sync::{Once, ONCE_INIT};
|
|
||||||
|
|
||||||
solana_entrypoint!(entrypoint);
|
solana_entrypoint!(entrypoint);
|
||||||
fn entrypoint(
|
pub fn entrypoint(
|
||||||
_program_id: &Pubkey,
|
_program_id: &Pubkey,
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
_tick_height: u64,
|
_tick_height: u64,
|
||||||
) -> Result<(), ProgramError> {
|
) -> Result<(), ProgramError> {
|
||||||
static INIT: Once = ONCE_INIT;
|
|
||||||
INIT.call_once(|| {
|
|
||||||
// env_logger can only be initialized once
|
|
||||||
env_logger::init();
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Ok(syscall) = deserialize(data) {
|
if let Ok(syscall) = deserialize(data) {
|
||||||
trace!("process_instruction: {:?}", syscall);
|
trace!("process_instruction: {:?}", syscall);
|
||||||
trace!("keyed_accounts: {:?}", keyed_accounts);
|
trace!("keyed_accounts: {:?}", keyed_accounts);
|
||||||
|
|
|
@ -113,6 +113,7 @@ extern crate socket2;
|
||||||
extern crate solana_drone;
|
extern crate solana_drone;
|
||||||
extern crate solana_jsonrpc_core as jsonrpc_core;
|
extern crate solana_jsonrpc_core as jsonrpc_core;
|
||||||
extern crate solana_jsonrpc_http_server as jsonrpc_http_server;
|
extern crate solana_jsonrpc_http_server as jsonrpc_http_server;
|
||||||
|
extern crate solana_system_program;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate solana_jsonrpc_macros as jsonrpc_macros;
|
extern crate solana_jsonrpc_macros as jsonrpc_macros;
|
||||||
extern crate solana_jsonrpc_pubsub as jsonrpc_pubsub;
|
extern crate solana_jsonrpc_pubsub as jsonrpc_pubsub;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use solana_sdk::native_program::ProgramError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
use solana_system_program;
|
||||||
|
|
||||||
/// Reasons the runtime might have rejected a transaction.
|
/// Reasons the runtime might have rejected a transaction.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
@ -36,12 +37,21 @@ fn process_instruction(
|
||||||
.collect();
|
.collect();
|
||||||
keyed_accounts.append(&mut keyed_accounts2);
|
keyed_accounts.append(&mut keyed_accounts2);
|
||||||
|
|
||||||
native_loader::process_instruction(
|
if system_program::check_id(&program_id) {
|
||||||
&program_id,
|
solana_system_program::entrypoint(
|
||||||
&mut keyed_accounts,
|
&program_id,
|
||||||
&tx.instructions[instruction_index].userdata,
|
&mut keyed_accounts[1..],
|
||||||
tick_height,
|
&tx.instructions[instruction_index].userdata,
|
||||||
)
|
tick_height,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
native_loader::process_instruction(
|
||||||
|
&program_id,
|
||||||
|
&mut keyed_accounts,
|
||||||
|
&tx.instructions[instruction_index].userdata,
|
||||||
|
tick_height,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_instruction(
|
fn verify_instruction(
|
||||||
|
|
Loading…
Reference in New Issue