Skip to content

Commit

Permalink
[FastX adapter/verifier] Implement Move module initializers (MystenLa…
Browse files Browse the repository at this point in the history
…bs#337)

* Added adapter test that can use Move code from source files

* Renamed directory containing Move tests data to make it more clear that no Rust code is involved

* First take at running module initializers

* Fixes and changes to get all the current tests working in presence of module initializers

* Added additional restrictions on module initializer function and relevant tests

* Added non-zero gas budget to make sure that publish calls do not (intentionally) fail due to insufficient gas

* Make sure to test 0 gas budget when publishing without initializers

* Update context modified in the Move VM only for publishing-related calls

* Cosmetic changes

* Handle running out of gas gracefully rather than panicking due to overflow
  • Loading branch information
awelc authored Feb 11, 2022
1 parent 488a67e commit d75b684
Show file tree
Hide file tree
Showing 23 changed files with 893 additions and 258 deletions.
2 changes: 1 addition & 1 deletion fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl ClientServerBenchmark {
match reply_message {
Ok(SerializedMessage::OrderResp(res)) => {
if let Some(e) = res.signed_effects {
if e.effects.status != ExecutionStatus::Success {
if matches!(e.effects.status, ExecutionStatus::Success { .. }) {
info!("Execution Error {:?}", e.effects.status);
}
}
Expand Down
17 changes: 13 additions & 4 deletions fastpay/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub enum WalletCommands {
/// ID of the gas object for gas payment, in 20 bytes Hex string
#[structopt(long)]
gas: ObjectID,

/// gas budget for running module initializers
#[structopt(default_value = "0")]
gas_budget: u64,
},

/// Call Move
Expand Down Expand Up @@ -130,11 +134,15 @@ pub enum WalletCommands {
impl WalletCommands {
pub async fn execute(&mut self, context: &mut WalletContext) -> Result<(), anyhow::Error> {
match self {
WalletCommands::Publish { path, gas } => {
WalletCommands::Publish {
path,
gas,
gas_budget,
} => {
// Find owner of gas object
let owner = context.find_owner(gas)?;
let client_state = context.get_or_create_client_state(&owner)?;
publish(client_state, path.clone(), *gas).await;
publish(client_state, path.clone(), *gas, *gas_budget).await;
}

WalletCommands::Object { id, deep } => {
Expand Down Expand Up @@ -256,17 +264,18 @@ async fn publish(
client_state: &mut ClientState<AuthorityClient>,
path: String,
gas_object_id: ObjectID,
gas_budget: u64,
) {
let gas_obj_ref = *client_state
.object_refs()
.get(&gas_object_id)
.expect("Gas object not found");

let pub_resp = client_state.publish(path, gas_obj_ref).await;
let pub_resp = client_state.publish(path, gas_obj_ref, gas_budget).await;

match pub_resp {
Ok((_, effects)) => {
if effects.status != ExecutionStatus::Success {
if !matches!(effects.status, ExecutionStatus::Success { .. }) {
error!("Error publishing module: {:#?}", effects.status);
}
show_object_effects(effects);
Expand Down
3 changes: 2 additions & 1 deletion fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ impl AuthorityState {
m.modules,
m.sender,
tx_ctx,
m.gas_budget,
gas_object.clone(),
),
}?;
Expand Down Expand Up @@ -383,7 +384,7 @@ impl AuthorityState {

output_object.transfer(Authenticator::Address(recipient));
temporary_store.write_object(output_object);
Ok(ExecutionStatus::Success)
Ok(ExecutionStatus::Success { gas_used })
}

pub async fn handle_order_info_request(
Expand Down
11 changes: 7 additions & 4 deletions fastpay_core/src/authority/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,14 @@ impl Storage for AuthorityTemporaryStore {
}

fn read_object(&self, id: &ObjectID) -> Option<Object> {
match self.objects.get(id) {
match self.written.get(id) {
Some(x) => Some(x.clone()),
None => match self.object_store.get_object(id) {
Ok(o) => o,
Err(e) => panic!("Could not read object {}", e),
None => match self.objects.get(id) {
Some(x) => Some(x.clone()),
None => match self.object_store.get_object(id) {
Ok(o) => o,
Err(e) => panic!("Could not read object {}", e),
},
},
}
}
Expand Down
3 changes: 3 additions & 0 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub trait Client {
&mut self,
package_source_files_path: String,
gas_object_ref: ObjectRef,
gas_budget: u64,
) -> Result<(CertifiedOrder, OrderEffects), anyhow::Error>;

/// Get the object information
Expand Down Expand Up @@ -565,13 +566,15 @@ where
&mut self,
package_source_files_path: String,
gas_object_ref: ObjectRef,
gas_budget: u64,
) -> Result<(CertifiedOrder, OrderEffects), anyhow::Error> {
// Try to compile the package at the given path
let compiled_modules = build_move_package_to_bytes(Path::new(&package_source_files_path))?;
let move_publish_order = Order::new_module(
self.address,
gas_object_ref,
compiled_modules,
gas_budget,
&*self.secret,
);
self.execute_transaction(move_publish_order).await
Expand Down
Loading

0 comments on commit d75b684

Please sign in to comment.