From 6051e4676d21459a076c039337f9216618e3d19b Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 16:43:24 +0200 Subject: [PATCH 01/12] first part --- massa-api-exports/src/execution.rs | 4 ++++ massa-api/src/public.rs | 6 +++++ massa-client/src/cmds.rs | 3 +++ massa-execution-exports/src/types.rs | 4 ++++ massa-execution-worker/src/execution.rs | 31 +++++++++++++++++++++++++ massa-grpc/src/public.rs | 3 +++ 6 files changed, 51 insertions(+) diff --git a/massa-api-exports/src/execution.rs b/massa-api-exports/src/execution.rs index 826f1bba31e..bb4a581da3e 100644 --- a/massa-api-exports/src/execution.rs +++ b/massa-api-exports/src/execution.rs @@ -81,6 +81,10 @@ pub struct ReadOnlyCall { pub parameter: Vec, /// caller's address, optional pub caller_address: Option
, + + pub coins: Option, + + pub fee: Option, /// whether to start execution from final or active state. Default false #[serde(default)] pub is_final: bool, diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 4ba2efda4b7..a04acc4c3fc 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -186,6 +186,8 @@ impl MassaRpcServer for API { operation_datastore: op_datastore, }], is_final, + coins: None, + fee: None, }; // run @@ -231,6 +233,8 @@ impl MassaRpcServer for API { parameter, caller_address, is_final, + coins, + fee, } in reqs { let caller_address = if let Some(addr) = caller_address { @@ -275,6 +279,8 @@ impl MassaRpcServer for API { }, ], is_final, + coins, + fee, }; // run diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index a7ab61607ea..b3857975a9c 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1186,6 +1186,9 @@ impl Command { parameter, max_gas, is_final, + // todo add coins and fee + coins: None, + fee: None, }) .await { diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index 8e3e469aa9d..26ac88b9b42 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -257,6 +257,10 @@ pub struct ReadOnlyExecutionRequest { pub call_stack: Vec, /// Target of the request pub target: ReadOnlyExecutionTarget, + + pub coins: Option, + + pub fee: Option, /// execution start state /// /// Whether to start execution from final or active state diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 94d2425939f..1425dbfc49a 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1454,6 +1454,36 @@ impl ExecutionState { // set the execution context *context_guard!(self) = execution_context; + if req.fee.is_some() || req.coins.is_some() { + let mut context = context_guard!(self); + let call_stack_addr = context.get_call_stack(); + if let Some(fee) = req.fee { + // Transfer fee from sender to none + if let Some(addr) = call_stack_addr.get(0) { + context.transfer_coins( + Some(addr.clone()), + None, + Amount::from_raw(fee), + false, + )?; + } + } + + if let Some(coins) = req.coins { + // Transfer coins from sender to called address + if let Some(from) = call_stack_addr.get(0) { + if let Some(to) = call_stack_addr.get(1) { + context.transfer_coins( + Some(from.clone()), + Some(to.clone()), + Amount::from_raw(coins), + false, + )?; + } + } + } + } + // load and execute the compiled module // IMPORTANT: do not keep a lock here as `run_function` uses the `get_module` interface let module = self @@ -1486,6 +1516,7 @@ impl ExecutionState { // return the execution output let execution_output = context_guard!(self).settle_slot(None); + dbg!(&execution_output); Ok(ReadOnlyExecutionOutput { out: execution_output, gas_cost: req.max_gas.saturating_sub(exec_response.remaining_gas), diff --git a/massa-grpc/src/public.rs b/massa-grpc/src/public.rs index 834516652ef..80e0e22f4a2 100644 --- a/massa-grpc/src/public.rs +++ b/massa-grpc/src/public.rs @@ -114,6 +114,9 @@ pub(crate) fn execute_read_only_call( call_stack, target, is_final: call.is_final, + // todo add fee and coins to proto file + coins: None, + fee: None, }; let output = grpc From 62464b78961a56cb9eaa66aa8a52c39d18742aff Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 17:39:08 +0200 Subject: [PATCH 02/12] fix first part --- massa-api-exports/src/execution.rs | 12 +++--- massa-api/src/public.rs | 3 +- massa-client/src/cmds.rs | 1 + massa-execution-exports/src/types.rs | 4 +- massa-execution-worker/src/execution.rs | 53 +++++++++++-------------- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/massa-api-exports/src/execution.rs b/massa-api-exports/src/execution.rs index bb4a581da3e..e784664ce58 100644 --- a/massa-api-exports/src/execution.rs +++ b/massa-api-exports/src/execution.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use massa_final_state::StateChanges; -use massa_models::{address::Address, output_event::SCOutputEvent, slot::Slot}; +use massa_models::{address::Address, amount::Amount, output_event::SCOutputEvent, slot::Slot}; use serde::{Deserialize, Serialize}; use std::{collections::VecDeque, fmt::Display}; @@ -63,6 +63,8 @@ pub struct ReadOnlyBytecodeExecution { pub address: Option
, /// Operation datastore, optional pub operation_datastore: Option>, + /// fee + pub fee: Option, /// whether to start execution from final or active state. Default false #[serde(default)] pub is_final: bool, @@ -81,10 +83,10 @@ pub struct ReadOnlyCall { pub parameter: Vec, /// caller's address, optional pub caller_address: Option
, - - pub coins: Option, - - pub fee: Option, + /// coins + pub coins: Option, + /// fee + pub fee: Option, /// whether to start execution from final or active state. Default false #[serde(default)] pub is_final: bool, diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index a04acc4c3fc..f1abe92029a 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -133,6 +133,7 @@ impl MassaRpcServer for API { bytecode, operation_datastore, is_final, + fee, } in reqs { let address = if let Some(addr) = address { @@ -187,7 +188,7 @@ impl MassaRpcServer for API { }], is_final, coins: None, - fee: None, + fee, }; // run diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index b3857975a9c..8834f30d847 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1151,6 +1151,7 @@ impl Command { address, operation_datastore: None, // TODO - #3072 is_final, + fee: None, }) .await { diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index 26ac88b9b42..f0cb62e3052 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -258,9 +258,9 @@ pub struct ReadOnlyExecutionRequest { /// Target of the request pub target: ReadOnlyExecutionTarget, - pub coins: Option, + pub coins: Option, - pub fee: Option, + pub fee: Option, /// execution start state /// /// Whether to start execution from final or active state diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 1425dbfc49a..f65767d044f 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1421,7 +1421,15 @@ impl ExecutionState { let exec_response = match req.target { ReadOnlyExecutionTarget::BytecodeExecution(bytecode) => { // set the execution context - *context_guard!(self) = execution_context; + let mut context = context_guard!(self); + *context = execution_context; + + let call_stack_addr = context.get_call_stack(); + + // transfer fee + if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { + context.transfer_coins(Some(*addr), None, fee, false)?; + } // load the tmp module let module = self @@ -1452,36 +1460,21 @@ impl ExecutionState { .0; // set the execution context - *context_guard!(self) = execution_context; - - if req.fee.is_some() || req.coins.is_some() { - let mut context = context_guard!(self); - let call_stack_addr = context.get_call_stack(); - if let Some(fee) = req.fee { - // Transfer fee from sender to none - if let Some(addr) = call_stack_addr.get(0) { - context.transfer_coins( - Some(addr.clone()), - None, - Amount::from_raw(fee), - false, - )?; - } - } + let mut context = context_guard!(self); + *context = execution_context; - if let Some(coins) = req.coins { - // Transfer coins from sender to called address - if let Some(from) = call_stack_addr.get(0) { - if let Some(to) = call_stack_addr.get(1) { - context.transfer_coins( - Some(from.clone()), - Some(to.clone()), - Amount::from_raw(coins), - false, - )?; - } - } - } + let call_stack_addr = context.get_call_stack(); + + // transfer fee + if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { + context.transfer_coins(Some(*addr), None, fee, false)?; + } + + // transfer coins + if let (Some(coins), Some(from), Some(to)) = + (req.coins, call_stack_addr.get(0), call_stack_addr.get(1)) + { + context.transfer_coins(Some(*from), Some(*to), coins, false)?; } // load and execute the compiled module From 68b170431487ab7972029393a293c48abe70d538 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 19:52:09 +0200 Subject: [PATCH 03/12] fix deadlock --- massa-execution-worker/src/execution.rs | 42 +++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index f65767d044f..0559790f977 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1420,15 +1420,16 @@ impl ExecutionState { // run the interpreter according to the target type let exec_response = match req.target { ReadOnlyExecutionTarget::BytecodeExecution(bytecode) => { - // set the execution context - let mut context = context_guard!(self); - *context = execution_context; + { + let mut context = context_guard!(self); + *context = execution_context; - let call_stack_addr = context.get_call_stack(); + let call_stack_addr = context.get_call_stack(); - // transfer fee - if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { - context.transfer_coins(Some(*addr), None, fee, false)?; + // transfer fee + if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { + context.transfer_coins(Some(*addr), None, fee, false)?; + } } // load the tmp module @@ -1459,22 +1460,23 @@ impl ExecutionState { .unwrap_or_default() .0; - // set the execution context - let mut context = context_guard!(self); - *context = execution_context; + { + let mut context = context_guard!(self); + *context = execution_context; - let call_stack_addr = context.get_call_stack(); + let call_stack_addr = context.get_call_stack(); - // transfer fee - if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { - context.transfer_coins(Some(*addr), None, fee, false)?; - } + // transfer fee + if let (Some(fee), Some(addr)) = (req.fee, call_stack_addr.get(0)) { + context.transfer_coins(Some(*addr), None, fee, false)?; + } - // transfer coins - if let (Some(coins), Some(from), Some(to)) = - (req.coins, call_stack_addr.get(0), call_stack_addr.get(1)) - { - context.transfer_coins(Some(*from), Some(*to), coins, false)?; + // transfer coins + if let (Some(coins), Some(from), Some(to)) = + (req.coins, call_stack_addr.get(0), call_stack_addr.get(1)) + { + context.transfer_coins(Some(*from), Some(*to), coins, false)?; + } } // load and execute the compiled module From 2278b2911189ec3cc477976bc0d3693cacc2c0c4 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 19:56:28 +0200 Subject: [PATCH 04/12] add doc --- massa-execution-exports/src/types.rs | 4 ++-- massa-execution-worker/src/execution.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index f0cb62e3052..b05184507e9 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -257,9 +257,9 @@ pub struct ReadOnlyExecutionRequest { pub call_stack: Vec, /// Target of the request pub target: ReadOnlyExecutionTarget, - + /// Coins transferred to the target address during the call pub coins: Option, - + /// Fee pub fee: Option, /// execution start state /// diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 0559790f977..d05b2b78579 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1511,7 +1511,6 @@ impl ExecutionState { // return the execution output let execution_output = context_guard!(self).settle_slot(None); - dbg!(&execution_output); Ok(ReadOnlyExecutionOutput { out: execution_output, gas_cost: req.max_gas.saturating_sub(exec_response.remaining_gas), From 9de663a6c62b94f2cac141586cdbb1820fbeb363 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 20:40:00 +0200 Subject: [PATCH 05/12] coins and fee params from massa client --- massa-client/src/cmds.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 8834f30d847..93cf65c0535 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -33,6 +33,7 @@ use std::fmt::Write as _; use std::fmt::{Debug, Display}; use std::net::IpAddr; use std::path::PathBuf; +use std::str::FromStr; use strum::{EnumMessage, EnumProperty, IntoEnumIterator}; use strum_macros::{Display, EnumIter, EnumString}; @@ -280,20 +281,20 @@ pub enum Command { #[strum( ascii_case_insensitive, props( - args = "PathToBytecode MaxGas Address IsFinal", + args = "PathToBytecode MaxGas Address IsFinal Fee", pwd_not_needed = "true" ), - message = "execute byte code, address is optional, is_final is optional. Nothing is really executed on chain" + message = "execute byte code, address is optional, is_final is optional, fee is optional. Nothing is really executed on chain" )] read_only_execute_smart_contract, #[strum( ascii_case_insensitive, props( - args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress IsFinal", + args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress IsFinal Coins Fee", pwd_not_needed = "true" ), - message = "call a smart contract function, sender address is optional, is_final is optional. Nothing is really executed on chain" + message = "call a smart contract function, sender address, is_final, coins and fee are optional. Nothing is really executed on chain" )] read_only_call, @@ -1142,6 +1143,12 @@ impl Command { } else { false }; + + let fee = if let Some(fee) = parameters.get(4) { + Some(Amount::from_str(fee)?) + } else { + None + }; let bytecode = get_file_as_byte_vec(&path).await?; match client .public @@ -1151,7 +1158,7 @@ impl Command { address, operation_datastore: None, // TODO - #3072 is_final, - fee: None, + fee, }) .await { @@ -1178,6 +1185,16 @@ impl Command { } else { false }; + let coins: Option = if let Some(coins) = parameters.get(6) { + Some(Amount::from_str(coins)?) + } else { + None + }; + let fee = if let Some(fee) = parameters.get(7) { + Some(Amount::from_str(fee)?) + } else { + None + }; match client .public .execute_read_only_call(ReadOnlyCall { @@ -1187,9 +1204,8 @@ impl Command { parameter, max_gas, is_final, - // todo add coins and fee - coins: None, - fee: None, + coins, + fee, }) .await { From 9b90a424229e7a9b426cab44e2bb06e82eca5d37 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 6 Oct 2023 20:45:34 +0200 Subject: [PATCH 06/12] readability with transpose --- massa-client/src/cmds.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 93cf65c0535..d2891dc1398 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1143,12 +1143,10 @@ impl Command { } else { false }; - - let fee = if let Some(fee) = parameters.get(4) { - Some(Amount::from_str(fee)?) - } else { - None - }; + let fee = parameters + .get(7) + .map(|fee| Amount::from_str(fee)) + .transpose()?; let bytecode = get_file_as_byte_vec(&path).await?; match client .public @@ -1185,16 +1183,11 @@ impl Command { } else { false }; - let coins: Option = if let Some(coins) = parameters.get(6) { - Some(Amount::from_str(coins)?) - } else { - None - }; - let fee = if let Some(fee) = parameters.get(7) { - Some(Amount::from_str(fee)?) - } else { - None - }; + let coins = parameters.get(6).map(|c| Amount::from_str(c)).transpose()?; + let fee = parameters + .get(7) + .map(|fee| Amount::from_str(fee)) + .transpose()?; match client .public .execute_read_only_call(ReadOnlyCall { From 16c5dd20f843f9ac16d978c504e4a190ee864207 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 9 Oct 2023 09:06:08 +0200 Subject: [PATCH 07/12] fix unit test --- massa-execution-worker/src/tests/scenarios_mandatories.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index e764c468135..8ad1d83f3a5 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -180,6 +180,8 @@ mod tests { include_bytes!("./wasm/event_test.wasm").to_vec(), ), is_final: true, + coins: None, + fee: None, }) .expect("readonly execution failed"); @@ -195,6 +197,8 @@ mod tests { include_bytes!("./wasm/event_test.wasm").to_vec(), ), is_final: false, + coins: None, + fee: None, }) .expect("readonly execution failed"); From 716102b69387ba03f593a00fa84ae8fa3d330abe Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 9 Oct 2023 09:15:08 +0200 Subject: [PATCH 08/12] update JSONRpc api spec --- massa-node/base_config/openrpc.json | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index f9c67d59df6..282c3e8fc2c 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2576,7 +2576,7 @@ }, "op_exec_status": { "description": "true if the operation execution succeeded, false if failed, None means unknown", - "type" : "boolean" + "type": "boolean" } }, "additionalProperties": false @@ -2772,6 +2772,14 @@ "is_final": { "description": "Whether to start execution from final or active state", "type": "boolean" + }, + "coins": { + "description": "Amount in coins, optional", + "type": "number" + }, + "fee": { + "description": "Fee, optional", + "type": "number" } }, "additionalProperties": false @@ -2806,6 +2814,14 @@ "caller_address": { "description": "Caller's address, optional", "type": "string" + }, + "coins": { + "description": "Amount in coins, optional", + "type": "number" + }, + "fee": { + "description": "Fee, optional", + "type": "number" } }, "additionalProperties": false @@ -3320,4 +3336,4 @@ } } } -} +} \ No newline at end of file From 545d9f75e39c054d3495d2df5a59a127d3c56721 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 16 Oct 2023 11:39:08 +0200 Subject: [PATCH 09/12] update sc-runtime --- Cargo.lock | 6 +++--- Cargo.toml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2354628067..e58b77fb54f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2536,7 +2536,7 @@ dependencies = [ [[package]] name = "massa-proto-rs" version = "0.1.0" -source = "git+https://github.com/massalabs/massa-proto-rs?rev=b45cccca3fb09aa2bbee08aade080127521e39b8#b45cccca3fb09aa2bbee08aade080127521e39b8" +source = "git+https://github.com/massalabs/massa-proto-rs?rev=7a5674743033b803af6e022738e3aa0ab7e39e33#7a5674743033b803af6e022738e3aa0ab7e39e33" dependencies = [ "glob", "prost", @@ -2549,7 +2549,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?rev=4883fe075afca4dd4b7346ed7dff2d506323f9c7#4883fe075afca4dd4b7346ed7dff2d506323f9c7" +source = "git+https://github.com/massalabs/massa-sc-runtime?rev=24defd4e319bbba72b4a3cf47078ac8695976c38#24defd4e319bbba72b4a3cf47078ac8695976c38" dependencies = [ "anyhow", "as-ffi-bindings", @@ -3845,7 +3845,7 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "peernet" version = "0.1.0" -source = "git+https://github.com/massalabs/PeerNet?rev=1d10f55ea883e685691ff527c2466f733ba3e1b2#1d10f55ea883e685691ff527c2466f733ba3e1b2" +source = "git+https://github.com/massalabs/PeerNet?branch=main#1d10f55ea883e685691ff527c2466f733ba3e1b2" dependencies = [ "crossbeam", "enum_delegate", diff --git a/Cargo.toml b/Cargo.toml index b0c5f77e7c1..0d8325340b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,13 +98,13 @@ massa_versioning = { path = "./massa-versioning" } massa_wallet = { path = "./massa-wallet" } # Massa projects dependencies -massa-proto-rs = {git = "https://github.com/massalabs/massa-proto-rs", "rev" = "b45cccca3fb09aa2bbee08aade080127521e39b8"} -massa-sc-runtime = {git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "4883fe075afca4dd4b7346ed7dff2d506323f9c7"} -peernet = { git = "https://github.com/massalabs/PeerNet", "rev" = "1d10f55ea883e685691ff527c2466f733ba3e1b2" } +massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", "rev" = "7a5674743033b803af6e022738e3aa0ab7e39e33" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "24defd4e319bbba72b4a3cf47078ac8695976c38" } +peernet = { git = "https://github.com/massalabs/PeerNet", "branch" = "main" } # Common dependencies transition = { git = "https://github.com/massalabs/transition.git", "rev" = "93fa3bf82f9f5ff421c78536879b7fd1b948ca75" } -substruct = { git = "https://github.com/massalabs/substruct", "rev" = "2fb3ae0dc9d913a0566ce6415eaa7a7ca1690fe1"} +substruct = { git = "https://github.com/massalabs/substruct", "rev" = "2fb3ae0dc9d913a0566ce6415eaa7a7ca1690fe1" } machine = { git = "https://github.com/massalabs/machine", "rev" = "1736a01400aac54f69a81002862f8555b08caa9b" } aes-gcm = "0.10" anyhow = "1.0" From 65c12108b8ede4b81745a26b4a66b7109c79df3d Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 16 Oct 2023 14:32:22 +0200 Subject: [PATCH 10/12] update grpc --- massa-grpc/src/public.rs | 18 +++++++++++++++--- massa-grpc/src/tests/public.rs | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/massa-grpc/src/public.rs b/massa-grpc/src/public.rs index 8819db66fce..9d77e68e232 100644 --- a/massa-grpc/src/public.rs +++ b/massa-grpc/src/public.rs @@ -12,6 +12,7 @@ use massa_execution_exports::{ ExecutionQueryRequest, ExecutionStackElement, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, }; use massa_models::address::Address; +use massa_models::amount::Amount; use massa_models::block::{Block, BlockGraphStatus}; use massa_models::block_id::BlockId; use massa_models::config::CompactConfig; @@ -114,9 +115,20 @@ pub(crate) fn execute_read_only_call( call_stack, target, is_final: call.is_final, - // todo add fee and coins to proto file - coins: None, - fee: None, + coins: call + .coins + .map(|native_amount| { + Amount::from_mantissa_scale(native_amount.mantissa, native_amount.scale) + .map_err(|_| GrpcError::InvalidArgument("invalid amount".to_string())) + }) + .transpose()?, + fee: call + .fee + .map(|native_amount| { + Amount::from_mantissa_scale(native_amount.mantissa, native_amount.scale) + .map_err(|_| GrpcError::InvalidArgument("invalid amount".to_string())) + }) + .transpose()?, }; let output = grpc diff --git a/massa-grpc/src/tests/public.rs b/massa-grpc/src/tests/public.rs index 0d80d7a1113..b6ee7de12e9 100644 --- a/massa-grpc/src/tests/public.rs +++ b/massa-grpc/src/tests/public.rs @@ -378,6 +378,8 @@ async fn execute_read_only_call() { target_function: "function".to_string(), parameter: vec![], })), + coins: None, + fee: None, }; let call = public_client From f5a5db9ba86b0abcbe68a79f88b53d033ba078d2 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 16 Oct 2023 15:29:13 +0200 Subject: [PATCH 11/12] update unit test --- massa-api/src/tests/public.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/massa-api/src/tests/public.rs b/massa-api/src/tests/public.rs index 32496683d7b..9baba339466 100644 --- a/massa-api/src/tests/public.rs +++ b/massa-api/src/tests/public.rs @@ -605,7 +605,8 @@ async fn execute_read_only_bytecode() { Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap() ), operation_datastore: None, - is_final: false + is_final: false, + fee: None }]]; let response: Result, Error> = client .request("execute_read_only_bytecode", params.clone()) @@ -618,7 +619,8 @@ async fn execute_read_only_bytecode() { bytecode: "hi".as_bytes().to_vec(), address: None, operation_datastore: None, - is_final: false + is_final: false, + fee: None, }]]; let response: Result, Error> = client .request("execute_read_only_bytecode", params.clone()) @@ -631,7 +633,8 @@ async fn execute_read_only_bytecode() { bytecode: "hi".as_bytes().to_vec(), address: None, operation_datastore: Some("hi".as_bytes().to_vec()), - is_final: false + is_final: false, + fee: None }]]; let response: Result, Error> = client .request("execute_read_only_bytecode", params.clone()) @@ -692,7 +695,9 @@ async fn execute_read_only_call() { target_function: "hello".to_string(), parameter: vec![], caller_address: None, - is_final: false + is_final: false, + fee: None, + coins: None, }]]; let response: Vec = client .request("execute_read_only_call", params.clone()) From a01e96c16b969a8b7c5e6caa02dfe45f3640ddef Mon Sep 17 00:00:00 2001 From: modship Date: Wed, 18 Oct 2023 09:26:41 +0200 Subject: [PATCH 12/12] add coins to the last stack element --- massa-api/src/public.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 65fdddb9197..58e0877ce2f 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -26,6 +26,7 @@ use massa_execution_exports::{ }; use massa_models::{ address::Address, + amount::Amount, block::{Block, BlockGraphStatus}, block_id::BlockId, clique::Clique, @@ -274,7 +275,7 @@ impl MassaRpcServer for API { }, ExecutionStackElement { address: target_address, - coins: Default::default(), + coins: coins.unwrap_or(Amount::default()), owned_addresses: vec![target_address], operation_datastore: None, // should always be None },