Unfinalized program format is now same as mvir compiler outputs (#5458)
This commit is contained in:
@ -9,6 +9,7 @@ use stdlib::stdlib_modules;
|
|||||||
use types::{
|
use types::{
|
||||||
account_address::AccountAddress,
|
account_address::AccountAddress,
|
||||||
byte_array::ByteArray,
|
byte_array::ByteArray,
|
||||||
|
transaction::Program,
|
||||||
write_set::{WriteOp, WriteSet},
|
write_set::{WriteOp, WriteSet},
|
||||||
};
|
};
|
||||||
use vm::{
|
use vm::{
|
||||||
@ -38,11 +39,8 @@ fn to_array_32(array: &[u8]) -> &[u8; 32] {
|
|||||||
pub enum LibraAccountState {
|
pub enum LibraAccountState {
|
||||||
/// No data for this account yet
|
/// No data for this account yet
|
||||||
Unallocated,
|
Unallocated,
|
||||||
/// Serialized compiled program bytes
|
/// Json string representation of types::transaction::Program
|
||||||
CompiledProgram {
|
CompiledProgram(String),
|
||||||
script_bytes: Vec<u8>,
|
|
||||||
modules_bytes: Vec<Vec<u8>>,
|
|
||||||
},
|
|
||||||
/// Serialized verified program bytes
|
/// Serialized verified program bytes
|
||||||
VerifiedProgram {
|
VerifiedProgram {
|
||||||
script_bytes: Vec<u8>,
|
script_bytes: Vec<u8>,
|
||||||
@ -101,10 +99,9 @@ impl LibraAccountState {
|
|||||||
.expect("Unable to serialize module");
|
.expect("Unable to serialize module");
|
||||||
modules_bytes.push(buf);
|
modules_bytes.push(buf);
|
||||||
}
|
}
|
||||||
LibraAccountState::CompiledProgram {
|
LibraAccountState::CompiledProgram(
|
||||||
script_bytes,
|
serde_json::to_string(&Program::new(script_bytes, modules_bytes, vec![])).unwrap(),
|
||||||
modules_bytes,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_user(owner: &Pubkey, write_set: WriteSet) -> Self {
|
pub fn create_user(owner: &Pubkey, write_set: WriteSet) -> Self {
|
||||||
|
@ -25,6 +25,11 @@ pub fn map_data_error(err: std::boxed::Box<bincode::ErrorKind>) -> InstructionEr
|
|||||||
debug!("Error: Account data: {:?}", err);
|
debug!("Error: Account data: {:?}", err);
|
||||||
InstructionError::InvalidAccountData
|
InstructionError::InvalidAccountData
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn map_json_error(err: serde_json::error::Error) -> InstructionError {
|
||||||
|
debug!("Error: serde_json: {:?}", err);
|
||||||
|
InstructionError::InvalidAccountData
|
||||||
|
}
|
||||||
pub fn map_vm_verification_error(
|
pub fn map_vm_verification_error(
|
||||||
err: (CompiledModule, Vec<vm::errors::VerificationError>),
|
err: (CompiledModule, Vec<vm::errors::VerificationError>),
|
||||||
) -> InstructionError {
|
) -> InstructionError {
|
||||||
|
@ -11,7 +11,7 @@ use solana_sdk::{
|
|||||||
};
|
};
|
||||||
use types::{
|
use types::{
|
||||||
account_address::AccountAddress,
|
account_address::AccountAddress,
|
||||||
transaction::{TransactionArgument, TransactionOutput},
|
transaction::{Program, TransactionArgument, TransactionOutput},
|
||||||
};
|
};
|
||||||
use vm::{
|
use vm::{
|
||||||
access::ModuleAccess,
|
access::ModuleAccess,
|
||||||
@ -123,51 +123,51 @@ impl MoveProcessor {
|
|||||||
fn deserialize_compiled_program(
|
fn deserialize_compiled_program(
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<(CompiledScript, Vec<CompiledModule>), InstructionError> {
|
) -> Result<(CompiledScript, Vec<CompiledModule>), InstructionError> {
|
||||||
let (script_bytes, modules_bytes) =
|
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
LibraAccountState::CompiledProgram(string) => {
|
||||||
LibraAccountState::CompiledProgram {
|
let program: Program = serde_json::from_str(&string).map_err(map_json_error)?;
|
||||||
script_bytes,
|
|
||||||
modules_bytes,
|
|
||||||
} => (script_bytes, modules_bytes),
|
|
||||||
_ => {
|
|
||||||
debug!("Error: Program account does not contain a program");
|
|
||||||
return Err(InstructionError::InvalidArgument);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let script = CompiledScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
let script =
|
||||||
let modules = modules_bytes
|
CompiledScript::deserialize(&program.code()).map_err(map_vm_binary_error)?;
|
||||||
.iter()
|
let modules = program
|
||||||
.map(|bytes| CompiledModule::deserialize(&bytes))
|
.modules()
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.iter()
|
||||||
.map_err(map_vm_binary_error)?;
|
.map(|bytes| CompiledModule::deserialize(&bytes))
|
||||||
|
.collect::<Result<Vec<_>, _>>()
|
||||||
|
.map_err(map_vm_binary_error)?;
|
||||||
|
|
||||||
Ok((script, modules))
|
Ok((script, modules))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
debug!("Error: Program account does not contain a program");
|
||||||
|
Err(InstructionError::InvalidArgument)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_verified_program(
|
fn deserialize_verified_program(
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<(VerifiedScript, Vec<VerifiedModule>), InstructionError> {
|
) -> Result<(VerifiedScript, Vec<VerifiedModule>), InstructionError> {
|
||||||
let (script_bytes, modules_bytes) =
|
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
LibraAccountState::VerifiedProgram {
|
||||||
LibraAccountState::VerifiedProgram {
|
script_bytes,
|
||||||
script_bytes,
|
modules_bytes,
|
||||||
modules_bytes,
|
} => {
|
||||||
} => (script_bytes, modules_bytes),
|
let script =
|
||||||
_ => {
|
VerifiedScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
||||||
debug!("Error: Program account does not contain a program");
|
let modules = modules_bytes
|
||||||
return Err(InstructionError::InvalidArgument);
|
.iter()
|
||||||
}
|
.map(|bytes| VerifiedModule::deserialize(&bytes))
|
||||||
};
|
.collect::<Result<Vec<_>, _>>()
|
||||||
|
.map_err(map_vm_binary_error)?;
|
||||||
|
|
||||||
let script = VerifiedScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
Ok((script, modules))
|
||||||
let modules = modules_bytes
|
}
|
||||||
.iter()
|
_ => {
|
||||||
.map(|bytes| VerifiedModule::deserialize(&bytes))
|
debug!("Error: Program account does not contain a program");
|
||||||
.collect::<Result<Vec<_>, _>>()
|
Err(InstructionError::InvalidArgument)
|
||||||
.map_err(map_vm_binary_error)?;
|
}
|
||||||
|
}
|
||||||
Ok((script, modules))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(
|
fn execute(
|
||||||
|
Reference in New Issue
Block a user