Add support for idiomatic error handling to BPF instruction processors (#7968)

This commit is contained in:
Jack May
2020-01-30 09:47:22 -08:00
committed by GitHub
parent 0c55b37976
commit dd276138c2
25 changed files with 515 additions and 108 deletions

View File

@ -15,7 +15,6 @@ use solana_sdk::{
sysvar::rent,
};
use std::{
convert::TryFrom,
io::{prelude::*, Error},
mem,
};
@ -145,18 +144,15 @@ pub fn process_instruction(
info!("Call BPF program");
match vm.execute_program(parameter_bytes.as_slice(), &[], &[heap_region]) {
Ok(status) => match u32::try_from(status) {
Ok(status) => {
if status > 0 {
warn!("BPF program failed: {}", status);
return Err(InstructionError::CustomError(status));
}
Ok(status) => {
// ignore upper 32bits if any, programs only return lower 32bits
let status = status as u32;
if status != 0 {
let error: InstructionError = status.into();
warn!("BPF program failed: {:?}", error);
return Err(error);
}
Err(e) => {
warn!("BPF VM encountered invalid status: {}", e);
return Err(InstructionError::GenericError);
}
},
}
Err(e) => {
warn!("BPF VM failed to run program: {}", e);
return Err(InstructionError::GenericError);