Skip to content

Commit

Permalink
Add block data usage detection flags
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkovAlexander committed Feb 28, 2024
1 parent 2d4c9e5 commit 02a0806
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
23 changes: 14 additions & 9 deletions src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mutex<bool>>,
pub block_collation_was_finished: Arc<Mutex<bool>>,
}

pub struct ActionPhaseResult {
Expand Down Expand Up @@ -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)),
}
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions src/vmsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,9 +41,22 @@ pub struct VMSetup {
gas: Option<Gas>,
libraries: Vec<HashmapE>,
ctx: VMSetupContext,
vm_execution_is_block_related: Arc<Mutex<bool>>,
block_collation_was_finished: Arc<Mutex<bool>>,
}

impl VMSetup {

pub fn set_block_related_flags(
mut self,
vm_execution_is_block_related: Arc<Mutex<bool>>,
block_collation_was_finished: Arc<Mutex<bool>>,
) -> 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 {
Expand All @@ -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)),
}
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit 02a0806

Please sign in to comment.