diff --git a/Cargo.toml b/Cargo.toml index dc4ee35..db4d918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ log = "0.4" thiserror = "1.0.56" tvm_block = { git = "https://github.com/tvmlabs/tvm-block", tag = "2.0.0" } tvm_types = { git = "https://github.com/tvmlabs/tvm-types", tag = "3.0.1" } -tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", tag="2.0.0" } +tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", branch = "feature-block_usage_detection" } [features] signature_with_id = [ "tvm_block/signature_with_id", "tvm_vm/signature_with_id" ] diff --git a/src/transaction_executor.rs b/src/transaction_executor.rs index 615a6d6..a60e386 100644 --- a/src/transaction_executor.rs +++ b/src/transaction_executor.rs @@ -15,7 +15,7 @@ use std::collections::LinkedList; use std::convert::TryInto; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use tvm_block::AccStatusChange; use tvm_block::Account; @@ -123,6 +123,8 @@ pub struct ExecuteParams { pub block_version: u32, #[cfg(feature = "signature_with_id")] pub signature_id: i32, + pub vm_execution_is_block_related: Arc>, + pub block_collation_was_finished: Arc>, } pub struct ActionPhaseResult { @@ -161,6 +163,8 @@ impl Default for ExecuteParams { block_version: 0, #[cfg(feature = "signature_with_id")] signature_id: 0, + vm_execution_is_block_related: Arc::new(Mutex::new(false)), + block_collation_was_finished: Arc::new(Mutex::new(false)), } } } @@ -477,14 +481,15 @@ pub trait TransactionExecutor { signature_id: params.signature_id, }, ) - .set_smart_contract_info(smc_info)? - .set_stack(stack) - .set_data(data)? - .set_libraries(libs) - .set_gas(gas) - .set_debug(params.debug) - .create(); - + .set_smart_contract_info(smc_info)? + .set_stack(stack) + .set_data(data)? + .set_libraries(libs) + .set_gas(gas) + .set_debug(params.debug) + .set_block_related_flags(params.vm_execution_is_block_related.clone(), params.block_collation_was_finished.clone()) + .create(); + if let Some(modifiers) = params.behavior_modifiers.clone() { vm.modify_behavior(modifiers); } diff --git a/src/vmsetup.rs b/src/vmsetup.rs index e894cc0..1345867 100644 --- a/src/vmsetup.rs +++ b/src/vmsetup.rs @@ -9,6 +9,7 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. +use std::sync::{Arc, Mutex}; use tvm_block::GlobalCapabilities; use tvm_types::Cell; use tvm_types::HashmapE; @@ -40,9 +41,22 @@ pub struct VMSetup { gas: Option, libraries: Vec, ctx: VMSetupContext, + vm_execution_is_block_related: Arc>, + block_collation_was_finished: Arc>, } impl VMSetup { + + pub fn set_block_related_flags( + mut self, + vm_execution_is_block_related: Arc>, + block_collation_was_finished: Arc>, + ) -> VMSetup { + self.vm_execution_is_block_related = vm_execution_is_block_related; + self.block_collation_was_finished = block_collation_was_finished; + self + } + /// Creates new instance of VMSetup with contract code. /// Initializes some registers of TVM with predefined values. pub fn with_context(code: SliceData, ctx: VMSetupContext) -> Self { @@ -54,6 +68,8 @@ impl VMSetup { gas: Some(Gas::empty()), libraries: vec![], ctx, + vm_execution_is_block_related: Arc::new(Mutex::new(false)), + block_collation_was_finished: Arc::new(Mutex::new(false)), } } @@ -147,6 +163,10 @@ impl VMSetup { vm.set_block_version(self.ctx.block_version); #[cfg(feature = "signature_with_id")] vm.set_signature_id(self.ctx.signature_id); + vm.set_block_related_flags( + self.vm_execution_is_block_related, + self.block_collation_was_finished, + ); vm } }