diff --git a/script/src/scheduler.rs b/script/src/scheduler.rs index 4ace66ab37..348b5caeaa 100644 --- a/script/src/scheduler.rs +++ b/script/src/scheduler.rs @@ -48,7 +48,7 @@ where DL: CellDataProvider, { /// Immutable context data for current running transaction & script. - pub sg_data: Arc>, + pub sg_data: SgData
, /// Mutable context data used by current scheduler pub debug_context: DebugContext, @@ -113,7 +113,7 @@ where /// Create a new scheduler from empty state pub fn new(sg_data: SgData
, debug_context: DebugContext) -> Self { Self { - sg_data: Arc::new(sg_data), + sg_data, debug_context, total_cycles: Arc::new(AtomicU64::new(0)), iteration_cycles: 0, @@ -153,7 +153,7 @@ where full: FullSuspendedState, ) -> Self { let mut scheduler = Self { - sg_data: Arc::new(sg_data), + sg_data, debug_context, total_cycles: Arc::new(AtomicU64::new(full.total_cycles)), iteration_cycles: 0, @@ -232,7 +232,7 @@ where pub fn run(&mut self, mode: RunMode) -> Result<(i8, Cycle), Error> { if self.states.is_empty() { // Booting phase, we will need to initialize the first VM. - let program_id = self.sg_data.program_data_piece_id.clone(); + let program_id = self.sg_data.sg_info.program_data_piece_id.clone(); assert_eq!( self.boot_vm( &DataLocation { @@ -877,7 +877,7 @@ where // The code here looks slightly weird, since I don't want to copy over all syscall // impls here again. Ideally, this scheduler package should be merged with ckb-script, // or simply replace ckb-script. That way, the quirks here will be eliminated. - let version = &self.sg_data.script_version; + let version = &self.sg_data.sg_info.script_version; let core_machine = CoreMachineType::new( version.vm_isa(), version.vm_version(), @@ -887,9 +887,7 @@ where let vm_context = VmContext { base_cycles: Arc::clone(&self.total_cycles), message_box: Arc::clone(&self.message_box), - snapshot2_context: Arc::new(Mutex::new(Snapshot2Context::new(Arc::clone( - &self.sg_data, - )))), + snapshot2_context: Arc::new(Mutex::new(Snapshot2Context::new(self.sg_data.clone()))), }; let machine_builder = DefaultMachineBuilder::new(core_machine) diff --git a/script/src/syscalls/debugger.rs b/script/src/syscalls/debugger.rs index d71732303e..75d2771638 100644 --- a/script/src/syscalls/debugger.rs +++ b/script/src/syscalls/debugger.rs @@ -1,4 +1,6 @@ -use crate::types::{DebugContext, DebugPrinter, SgData}; +use crate::types::{ + DebugContext, DebugPrinter, {SgData, SgInfo}, +}; use crate::{cost_model::transferred_byte_cycles, syscalls::DEBUG_PRINT_SYSCALL_NUMBER}; use ckb_vm::{ registers::{A0, A7}, @@ -6,21 +8,21 @@ use ckb_vm::{ }; use std::sync::Arc; -pub struct Debugger
{ - sg_data: Arc>, +pub struct Debugger { + sg_info: Arc, printer: DebugPrinter, } -impl
Debugger
{ - pub fn new(sg_data: &Arc>, debug_context: &DebugContext) -> Debugger
{ +impl Debugger { + pub fn new
(sg_data: &SgData
, debug_context: &DebugContext) -> Debugger { Debugger { - sg_data: Arc::clone(sg_data), + sg_info: Arc::clone(&sg_data.sg_info), printer: Arc::clone(&debug_context.debug_printer), } } } -impl Syscalls for Debugger
{ +impl Syscalls for Debugger { fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } @@ -49,7 +51,7 @@ impl Syscalls for Debugger
{ machine.add_cycles_no_checking(transferred_byte_cycles(buffer.len() as u64))?; let s = String::from_utf8(buffer) .map_err(|e| VMError::External(format!("String from buffer {e:?}")))?; - (self.printer)(self.sg_data.current_script_hash(), s.as_str()); + (self.printer)(&self.sg_info.script_hash, s.as_str()); Ok(true) } diff --git a/script/src/syscalls/exec.rs b/script/src/syscalls/exec.rs index 97140104fd..ac1ce8cb70 100644 --- a/script/src/syscalls/exec.rs +++ b/script/src/syscalls/exec.rs @@ -15,33 +15,32 @@ use ckb_vm::{ Error as VMError, Register, SupportMachine, Syscalls, }; use ckb_vm::{DEFAULT_STACK_SIZE, RISCV_MAX_MEMORY}; -use std::sync::Arc; #[derive(Debug)] pub struct Exec
{ - sg_data: Arc>, + sg_data: SgData
, } -impl Exec
{ - pub fn new(sg_data: &Arc>) -> Exec
{ +impl Exec
{ + pub fn new(sg_data: &SgData
) -> Exec
{ Exec { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } #[inline] fn resolved_inputs(&self) -> &Vec { - &self.sg_data.rtx().resolved_inputs + &self.sg_data.rtx.resolved_inputs } #[inline] fn resolved_cell_deps(&self) -> &Vec { - &self.sg_data.rtx().resolved_cell_deps + &self.sg_data.rtx.resolved_cell_deps } #[inline] fn witnesses(&self) -> BytesVec { - self.sg_data.rtx().transaction.witnesses() + self.sg_data.rtx.transaction.witnesses() } fn fetch_cell(&self, source: Source, index: usize) -> Result<&CellMeta, u8> { @@ -92,7 +91,7 @@ impl Exec
{ } } -impl Syscalls for Exec
{ +impl Syscalls for Exec
{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } diff --git a/script/src/syscalls/generator.rs b/script/src/syscalls/generator.rs index c57adb8629..98e8e7c1d5 100644 --- a/script/src/syscalls/generator.rs +++ b/script/src/syscalls/generator.rs @@ -8,12 +8,11 @@ use crate::{ }; use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider}; use ckb_vm::Syscalls; -use std::sync::Arc; /// Generate RISC-V syscalls in CKB environment pub fn generate_ckb_syscalls
( vm_id: &VmId, - sg_data: &Arc>, + sg_data: &SgData
, vm_context: &VmContext
, debug_context: &DebugContext, ) -> Vec)>> @@ -31,7 +30,7 @@ where Box::new(LoadCellData::new(vm_context)), Box::new(Debugger::new(sg_data, debug_context)), ]; - let script_version = &sg_data.script_version; + let script_version = &sg_data.sg_info.script_version; if script_version >= &ScriptVersion::V1 { syscalls.append(&mut vec![ Box::new(VMVersion::new()), @@ -56,8 +55,8 @@ where ]); } #[cfg(test)] - syscalls.push(Box::new(crate::syscalls::Pause::new(Arc::clone( - &debug_context.skip_pause, - )))); + syscalls.push(Box::new(crate::syscalls::Pause::new( + std::sync::Arc::clone(&debug_context.skip_pause), + ))); syscalls } diff --git a/script/src/syscalls/load_block_extension.rs b/script/src/syscalls/load_block_extension.rs index 0594a890e3..d38cf4b8cc 100644 --- a/script/src/syscalls/load_block_extension.rs +++ b/script/src/syscalls/load_block_extension.rs @@ -15,33 +15,32 @@ use ckb_vm::{ registers::{A0, A3, A4, A7}, Error as VMError, Register, SupportMachine, Syscalls, }; -use std::sync::Arc; #[derive(Debug)] pub struct LoadBlockExtension
{ - sg_data: Arc>, + sg_data: SgData
, } -impl LoadBlockExtension
{ - pub fn new(sg_data: &Arc>) -> LoadBlockExtension
{ +impl LoadBlockExtension
{ + pub fn new(sg_data: &SgData
) -> LoadBlockExtension
{ LoadBlockExtension { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } #[inline] fn header_deps(&self) -> Byte32Vec { - self.sg_data.rtx().transaction.header_deps() + self.sg_data.rtx.transaction.header_deps() } #[inline] fn resolved_inputs(&self) -> &Vec { - &self.sg_data.rtx().resolved_inputs + &self.sg_data.rtx.resolved_inputs } #[inline] fn resolved_cell_deps(&self) -> &Vec { - &self.sg_data.rtx().resolved_cell_deps + &self.sg_data.rtx.resolved_cell_deps } fn load_block_extension(&self, cell_meta: &CellMeta) -> Option { @@ -102,7 +101,7 @@ impl LoadBlockExtension
{ } } -impl Syscalls +impl Syscalls for LoadBlockExtension
{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { diff --git a/script/src/syscalls/load_cell.rs b/script/src/syscalls/load_cell.rs index 78260c378b..3c6212b1bd 100644 --- a/script/src/syscalls/load_cell.rs +++ b/script/src/syscalls/load_cell.rs @@ -4,7 +4,7 @@ use crate::{ utils::store_data, CellField, Source, SourceEntry, INDEX_OUT_OF_BOUND, ITEM_MISSING, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER, LOAD_CELL_SYSCALL_NUMBER, SUCCESS, }, - types::{SgData, TxData}, + types::{SgData, TxInfo}, }; use byteorder::{LittleEndian, WriteBytesExt}; use ckb_traits::CellDataProvider; @@ -17,32 +17,31 @@ use ckb_vm::{ registers::{A0, A3, A4, A5, A7}, Error as VMError, Register, SupportMachine, Syscalls, }; -use std::sync::Arc; pub struct LoadCell
{ - sg_data: Arc>, + sg_data: SgData
, } -impl LoadCell
{ - pub fn new(sg_data: &Arc>) -> LoadCell
{ +impl LoadCell
{ + pub fn new(sg_data: &SgData
) -> LoadCell
{ LoadCell { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } #[inline] - fn tx_data(&self) -> &TxData
{ - &self.sg_data.tx_data + fn tx_info(&self) -> &TxInfo
{ + &self.sg_data.tx_info } #[inline] fn resolved_inputs(&self) -> &Vec { - &self.sg_data.rtx().resolved_inputs + &self.sg_data.rtx.resolved_inputs } #[inline] fn resolved_cell_deps(&self) -> &Vec { - &self.sg_data.rtx().resolved_cell_deps + &self.sg_data.rtx.resolved_cell_deps } fn fetch_cell(&self, source: Source, index: usize) -> Result<&CellMeta, u8> { @@ -51,7 +50,7 @@ impl LoadCell
{ self.resolved_inputs().get(index).ok_or(INDEX_OUT_OF_BOUND) } Source::Transaction(SourceEntry::Output) => { - self.tx_data().outputs.get(index).ok_or(INDEX_OUT_OF_BOUND) + self.tx_info().outputs.get(index).ok_or(INDEX_OUT_OF_BOUND) } Source::Transaction(SourceEntry::CellDep) => self .resolved_cell_deps() @@ -74,7 +73,7 @@ impl LoadCell
{ .get(index) .ok_or(INDEX_OUT_OF_BOUND) .and_then(|actual_index| { - self.tx_data() + self.tx_info() .outputs .get(*actual_index) .ok_or(INDEX_OUT_OF_BOUND) @@ -110,7 +109,7 @@ impl LoadCell
{ (SUCCESS, store_data(machine, &buffer)?) } CellField::DataHash => { - if let Some(bytes) = self.tx_data().data_loader.load_cell_data_hash(cell) { + if let Some(bytes) = self.tx_info().data_loader.load_cell_data_hash(cell) { (SUCCESS, store_data(machine, &bytes.as_bytes())?) } else { (ITEM_MISSING, 0) @@ -160,7 +159,9 @@ impl LoadCell
{ } } -impl Syscalls for LoadCell
{ +impl Syscalls + for LoadCell
+{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } diff --git a/script/src/syscalls/load_cell_data.rs b/script/src/syscalls/load_cell_data.rs index 53b14b0d1c..3aa6b24645 100644 --- a/script/src/syscalls/load_cell_data.rs +++ b/script/src/syscalls/load_cell_data.rs @@ -20,7 +20,7 @@ pub struct LoadCellData
where DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + Clone + 'static, { - snapshot2_context: Arc>>>>, + snapshot2_context: Arc>>>, } impl
LoadCellData
diff --git a/script/src/syscalls/load_header.rs b/script/src/syscalls/load_header.rs index 5e503e3c1d..10629c844c 100644 --- a/script/src/syscalls/load_header.rs +++ b/script/src/syscalls/load_header.rs @@ -17,17 +17,15 @@ use ckb_vm::{ registers::{A0, A3, A4, A5, A7}, Error as VMError, Register, SupportMachine, Syscalls, }; -use std::sync::Arc; - #[derive(Debug)] pub struct LoadHeader
{ - sg_data: Arc>, + sg_data: SgData
, } -impl LoadHeader
{ - pub fn new(sg_data: &Arc>) -> LoadHeader
{ +impl LoadHeader
{ + pub fn new(sg_data: &SgData
) -> LoadHeader
{ LoadHeader { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } @@ -42,17 +40,17 @@ impl LoadHeader
{ #[inline] fn header_deps(&self) -> Byte32Vec { - self.sg_data.rtx().transaction.header_deps() + self.sg_data.rtx.transaction.header_deps() } #[inline] fn resolved_inputs(&self) -> &Vec { - &self.sg_data.rtx().resolved_inputs + &self.sg_data.rtx.resolved_inputs } #[inline] fn resolved_cell_deps(&self) -> &Vec { - &self.sg_data.rtx().resolved_cell_deps + &self.sg_data.rtx.resolved_cell_deps } fn load_header(&self, cell_meta: &CellMeta) -> Option { @@ -66,7 +64,7 @@ impl LoadHeader
{ .into_iter() .any(|hash| &hash == block_hash) { - self.sg_data.tx_data.data_loader.get_header(block_hash) + self.sg_data.tx_info.data_loader.get_header(block_hash) } else { None } @@ -91,7 +89,7 @@ impl LoadHeader
{ .ok_or(INDEX_OUT_OF_BOUND) .and_then(|block_hash| { self.sg_data - .tx_data + .tx_info .data_loader .get_header(&block_hash) .ok_or(ITEM_MISSING) @@ -146,7 +144,9 @@ impl LoadHeader
{ } } -impl Syscalls for LoadHeader
{ +impl Syscalls + for LoadHeader
+{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } diff --git a/script/src/syscalls/load_input.rs b/script/src/syscalls/load_input.rs index 5d0513a45e..2d1f415f32 100644 --- a/script/src/syscalls/load_input.rs +++ b/script/src/syscalls/load_input.rs @@ -15,23 +15,22 @@ use ckb_vm::{ registers::{A0, A3, A4, A5, A7}, Error as VMError, Register, SupportMachine, Syscalls, }; -use std::sync::Arc; #[derive(Debug)] pub struct LoadInput
{ - sg_data: Arc>, + sg_data: SgData
, } -impl
LoadInput
{ - pub fn new(sg_data: &Arc>) -> Self { +impl LoadInput
{ + pub fn new(sg_data: &SgData
) -> Self { LoadInput { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } #[inline] fn inputs(&self) -> CellInputVec { - self.sg_data.rtx().transaction.inputs() + self.sg_data.rtx.transaction.inputs() } fn fetch_input(&self, source: Source, index: usize) -> Result { @@ -88,7 +87,7 @@ impl
LoadInput
{ } } -impl Syscalls for LoadInput
{ +impl Syscalls for LoadInput
{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } diff --git a/script/src/syscalls/load_script.rs b/script/src/syscalls/load_script.rs index 6ea2ec8d32..545e8e7492 100644 --- a/script/src/syscalls/load_script.rs +++ b/script/src/syscalls/load_script.rs @@ -1,7 +1,7 @@ use crate::{ cost_model::transferred_byte_cycles, syscalls::{utils::store_data, LOAD_SCRIPT_SYSCALL_NUMBER, SUCCESS}, - types::SgData, + types::{SgData, SgInfo}, }; use ckb_types::prelude::*; use ckb_vm::{ @@ -11,19 +11,19 @@ use ckb_vm::{ use std::sync::Arc; #[derive(Debug)] -pub struct LoadScript
{ - sg_data: Arc>, +pub struct LoadScript { + sg_info: Arc, } -impl
LoadScript
{ - pub fn new(sg_data: &Arc>) -> Self { +impl LoadScript { + pub fn new
(sg_data: &SgData
) -> Self { Self { - sg_data: Arc::clone(sg_data), + sg_info: Arc::clone(&sg_data.sg_info), } } } -impl Syscalls for LoadScript
{ +impl Syscalls for LoadScript { fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } @@ -33,7 +33,7 @@ impl Syscalls for LoadScript
{ return Ok(false); } - let data = self.sg_data.script_group.script.as_slice(); + let data = self.sg_info.script_group.script.as_slice(); let wrote_size = store_data(machine, data)?; machine.add_cycles_no_checking(transferred_byte_cycles(wrote_size))?; diff --git a/script/src/syscalls/load_script_hash.rs b/script/src/syscalls/load_script_hash.rs index 73ecefa88e..0fe93e2f30 100644 --- a/script/src/syscalls/load_script_hash.rs +++ b/script/src/syscalls/load_script_hash.rs @@ -1,7 +1,7 @@ use crate::{ cost_model::transferred_byte_cycles, syscalls::{utils::store_data, LOAD_SCRIPT_HASH_SYSCALL_NUMBER, SUCCESS}, - types::SgData, + types::{SgData, SgInfo}, }; use ckb_vm::{ registers::{A0, A7}, @@ -10,19 +10,19 @@ use ckb_vm::{ use std::sync::Arc; #[derive(Debug)] -pub struct LoadScriptHash
{ - sg_data: Arc>, +pub struct LoadScriptHash { + sg_info: Arc, } -impl
LoadScriptHash
{ - pub fn new(sg_data: &Arc>) -> LoadScriptHash
{ +impl LoadScriptHash { + pub fn new
(sg_data: &SgData
) -> LoadScriptHash { LoadScriptHash { - sg_data: Arc::clone(sg_data), + sg_info: Arc::clone(&sg_data.sg_info), } } } -impl Syscalls for LoadScriptHash
{ +impl Syscalls for LoadScriptHash { fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } @@ -32,7 +32,7 @@ impl Syscalls for LoadScriptHash
return Ok(false); } - let data = self.sg_data.current_script_hash().as_reader().raw_data(); + let data = self.sg_info.script_hash.as_reader().raw_data(); let wrote_size = store_data(machine, data)?; machine.add_cycles_no_checking(transferred_byte_cycles(wrote_size))?; diff --git a/script/src/syscalls/load_tx.rs b/script/src/syscalls/load_tx.rs index fb4576682d..d0db1a3ce0 100644 --- a/script/src/syscalls/load_tx.rs +++ b/script/src/syscalls/load_tx.rs @@ -18,9 +18,9 @@ pub struct LoadTx { } impl LoadTx { - pub fn new
(sg_data: &Arc>) -> LoadTx { + pub fn new
(sg_data: &SgData
) -> LoadTx { LoadTx { - rtx: Arc::clone(&sg_data.tx_data.rtx), + rtx: Arc::clone(&sg_data.rtx), } } } diff --git a/script/src/syscalls/load_witness.rs b/script/src/syscalls/load_witness.rs index 09e1698db3..3ff4863199 100644 --- a/script/src/syscalls/load_witness.rs +++ b/script/src/syscalls/load_witness.rs @@ -11,23 +11,22 @@ use ckb_vm::{ registers::{A0, A3, A4, A7}, Error as VMError, Register, SupportMachine, Syscalls, }; -use std::sync::Arc; #[derive(Debug)] pub struct LoadWitness
{ - sg_data: Arc>, + sg_data: SgData
, } -impl
LoadWitness
{ - pub fn new(sg_data: &Arc>) -> Self { +impl LoadWitness
{ + pub fn new(sg_data: &SgData
) -> Self { LoadWitness { - sg_data: Arc::clone(sg_data), + sg_data: sg_data.clone(), } } #[inline] fn witnesses(&self) -> BytesVec { - self.sg_data.rtx().transaction.witnesses() + self.sg_data.rtx.transaction.witnesses() } fn fetch_witness(&self, source: Source, index: usize) -> Option { @@ -49,7 +48,7 @@ impl
LoadWitness
{ } } -impl Syscalls for LoadWitness
{ +impl Syscalls for LoadWitness
{ fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { Ok(()) } diff --git a/script/src/syscalls/spawn.rs b/script/src/syscalls/spawn.rs index 6fb7d536eb..a90ed3082a 100644 --- a/script/src/syscalls/spawn.rs +++ b/script/src/syscalls/spawn.rs @@ -20,7 +20,7 @@ where { id: VmId, message_box: Arc>>, - snapshot2_context: Arc>>>>, + snapshot2_context: Arc>>>, } impl
Spawn
diff --git a/script/src/syscalls/tests/utils.rs b/script/src/syscalls/tests/utils.rs index 6d5d95330b..4f2da451e9 100644 --- a/script/src/syscalls/tests/utils.rs +++ b/script/src/syscalls/tests/utils.rs @@ -1,5 +1,7 @@ use crate::{ - types::{DataPieceId, ScriptGroup, ScriptGroupType, ScriptVersion, SgData, TxData}, + types::{ + DataPieceId, ScriptGroup, ScriptGroupType, ScriptVersion, SgData, SgInfo, TxData, TxInfo, + }, verify_env::TxVerifyEnv, }; use ckb_chain_spec::consensus::ConsensusBuilder; @@ -62,11 +64,7 @@ pub(crate) fn build_cell_meta(capacity_bytes: usize, data: Bytes) -> CellMeta { } } -pub(crate) fn build_tx_data(rtx: Arc) -> TxData { - build_tx_data_with_loader(rtx, new_mock_data_loader()) -} - -pub(crate) fn build_tx_data_with_loader( +fn build_tx_data_with_loader( rtx: Arc, data_loader: MockDataLoader, ) -> TxData { @@ -75,22 +73,34 @@ pub(crate) fn build_tx_data_with_loader( TxData { rtx, - data_loader, - consensus: Arc::new(consensus), - tx_env: Arc::new(tx_env), - binaries_by_data_hash: HashMap::default(), - binaries_by_type_hash: HashMap::default(), - lock_groups: BTreeMap::default(), - type_groups: BTreeMap::default(), - outputs: Vec::new(), + info: Arc::new(TxInfo { + data_loader, + consensus: Arc::new(consensus), + tx_env: Arc::new(tx_env), + binaries_by_data_hash: HashMap::default(), + binaries_by_type_hash: HashMap::default(), + lock_groups: BTreeMap::default(), + type_groups: BTreeMap::default(), + outputs: Vec::new(), + }), } } pub(crate) fn build_sg_data( - tx_data: Arc>, + rtx: Arc, input_indices: Vec, output_indices: Vec, -) -> Arc> { +) -> SgData { + build_sg_data_with_loader(rtx, new_mock_data_loader(), input_indices, output_indices) +} + +pub(crate) fn build_sg_data_with_loader( + rtx: Arc, + data_loader: MockDataLoader, + input_indices: Vec, + output_indices: Vec, +) -> SgData { + let tx_data = build_tx_data_with_loader(rtx, data_loader); let script_group = ScriptGroup { script: Script::default(), group_type: ScriptGroupType::Lock, @@ -98,11 +108,34 @@ pub(crate) fn build_sg_data( output_indices, }; let script_hash = script_group.script.calc_script_hash(); - Arc::new(SgData { - tx_data, - script_version: ScriptVersion::latest(), - script_group, - script_hash, - program_data_piece_id: DataPieceId::CellDep(0), - }) + SgData { + rtx: tx_data.rtx, + tx_info: tx_data.info, + sg_info: Arc::new(SgInfo { + script_version: ScriptVersion::latest(), + script_group, + script_hash, + program_data_piece_id: DataPieceId::CellDep(0), + }), + } +} + +pub(crate) fn update_tx_info)>( + mut sg_data: SgData, + f: F, +) -> SgData { + let mut tx_info = sg_data.tx_info.as_ref().clone(); + f(&mut tx_info); + sg_data.tx_info = Arc::new(tx_info); + sg_data +} + +pub(crate) fn update_sg_info( + mut sg_data: SgData, + f: F, +) -> SgData { + let mut sg_info = sg_data.sg_info.as_ref().clone(); + f(&mut sg_info); + sg_data.sg_info = Arc::new(sg_info); + sg_data } diff --git a/script/src/syscalls/tests/vm_latest/syscalls_1.rs b/script/src/syscalls/tests/vm_latest/syscalls_1.rs index 444a67a124..98f7843dcc 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_1.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_1.rs @@ -53,13 +53,8 @@ fn _test_load_cell_not_exist(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -99,13 +94,8 @@ fn _test_load_cell_all(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output.clone()]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -193,13 +183,8 @@ fn _test_load_cell_from_group(data: &[u8], source: SourceEntry) -> Result<(), Te resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output.clone()]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -284,13 +269,8 @@ fn _test_load_cell_out_of_bound(index: u64, source: u64) -> Result<(), TestCaseE resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -346,13 +326,8 @@ fn _test_load_cell_length(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -402,13 +377,8 @@ fn _test_load_cell_partial(data: &[u8], offset: u64) -> Result<(), TestCaseError resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); + let sg_data = update_tx_info(sg_data, |tx_info| tx_info.outputs = vec![output.clone()]); let mut load_cell = LoadCell::new(&sg_data); @@ -471,8 +441,7 @@ fn _test_load_cell_capacity(capacity: Capacity) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -530,8 +499,7 @@ fn _test_load_cell_occupied_capacity(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -590,8 +558,7 @@ fn test_load_missing_data_hash() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -635,13 +602,10 @@ fn _test_load_missing_contract(field: CellField) { resolved_dep_groups: vec![], }); - let tx_data = { - // Mutable TxData should only used in tests - let mut tx_data = build_tx_data(rtx); - tx_data.outputs = vec![output_cell]; - Arc::new(tx_data) - }; - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); + let sg_data = update_tx_info(sg_data, |tx_info| { + tx_info.outputs = vec![output_cell.clone()] + }); let mut load_cell = LoadCell::new(&sg_data); @@ -712,8 +676,7 @@ fn _test_load_header( resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data_with_loader(rtx, data_loader)); - let sg_data = build_sg_data(tx_data, vec![0], vec![]); + let sg_data = build_sg_data_with_loader(rtx, data_loader, vec![0], vec![]); let mut load_header = LoadHeader::new(&sg_data); @@ -830,8 +793,7 @@ fn _test_load_header_by_field(data: &[u8], field: HeaderField) -> Result<(), Tes resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data_with_loader(rtx, data_loader)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data_with_loader(rtx, data_loader, vec![], vec![]); let mut load_header = LoadHeader::new(&sg_data); @@ -883,8 +845,7 @@ fn _test_load_tx_hash(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_tx = LoadTx::new(&sg_data); @@ -937,8 +898,7 @@ fn _test_load_tx(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_tx = LoadTx::new(&sg_data); @@ -992,15 +952,12 @@ fn _test_load_current_script_hash(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); // Swap the internal script in VmData - let sg_data = { - let mut sg_data = sg_data.as_ref().clone(); - sg_data.script_hash = script.calc_script_hash(); - sg_data.script_group.script = script; - Arc::new(sg_data) - }; + let sg_data = update_sg_info(sg_data, |sg_info| { + sg_info.script_hash = script.calc_script_hash(); + sg_info.script_group.script = script.clone(); + }); let mut load_script_hash = LoadScriptHash::new(&sg_data); @@ -1074,8 +1031,7 @@ fn _test_load_input_lock_script_hash(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -1137,8 +1093,7 @@ fn _test_load_input_lock_script(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -1203,8 +1158,7 @@ fn _test_load_input_type_script(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -1271,8 +1225,7 @@ fn _test_load_input_type_script_hash(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_cell = LoadCell::new(&sg_data); @@ -1328,8 +1281,7 @@ fn _test_load_witness(data: &[u8], source: SourceEntry) -> Result<(), TestCaseEr resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let mut load_witness = LoadWitness::new(&sg_data); @@ -1394,8 +1346,7 @@ fn _test_load_group_witness(data: &[u8], source: SourceEntry) -> Result<(), Test resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![1], vec![1]); + let sg_data = build_sg_data(rtx, vec![1], vec![1]); let mut load_witness = LoadWitness::new(&sg_data); @@ -1451,15 +1402,12 @@ fn _test_load_script(data: &[u8]) -> Result<(), TestCaseError> { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); // Swap the internal script in VmData - let sg_data = { - let mut sg_data = sg_data.as_ref().clone(); - sg_data.script_hash = script.calc_script_hash(); - sg_data.script_group.script = script.clone(); - Arc::new(sg_data) - }; + let sg_data = update_sg_info(sg_data, |sg_info| { + sg_info.script_hash = script.calc_script_hash(); + sg_info.script_group.script = script.clone(); + }); let mut load_script = LoadScript::new(&sg_data); @@ -1524,8 +1472,7 @@ fn _test_load_cell_data_as_code( resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1592,8 +1539,7 @@ fn _test_load_cell_data( resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1695,8 +1641,7 @@ fn test_load_overflowed_cell_data_as_code() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1740,8 +1685,7 @@ fn _test_load_cell_data_on_freezed_memory(data: &[u8]) -> Result<(), TestCaseErr resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1783,8 +1727,7 @@ fn _test_load_cell_data_as_code_on_freezed_memory(data: &[u8]) -> Result<(), Tes resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1837,8 +1780,7 @@ fn test_load_code_unaligned_error() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1878,8 +1820,7 @@ fn test_load_code_slice_out_of_bound_error() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1922,8 +1863,7 @@ fn test_load_code_not_enough_space_error() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -1989,8 +1929,7 @@ fn _test_load_input( resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![0], vec![]); + let sg_data = build_sg_data(rtx, vec![0], vec![]); let mut load_input = LoadInput::new(&sg_data); @@ -2129,8 +2068,7 @@ fn test_load_cell_data_size_zero() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -2169,8 +2107,7 @@ fn test_load_cell_data_size_zero_index_out_of_bound() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![0], vec![0]); + let sg_data = build_sg_data(rtx, vec![0], vec![0]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); diff --git a/script/src/syscalls/tests/vm_latest/syscalls_2.rs b/script/src/syscalls/tests/vm_latest/syscalls_2.rs index 38b3f7c9ef..0f40dc1e51 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_2.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_2.rs @@ -60,8 +60,7 @@ fn test_current_cycles() { resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data(rtx)); - let sg_data = build_sg_data(tx_data, vec![], vec![]); + let sg_data = build_sg_data(rtx, vec![], vec![]); let vm_context = VmContext::new(&sg_data, &Arc::new(Mutex::new(Vec::new()))); @@ -121,8 +120,7 @@ fn _test_load_extension( resolved_dep_groups: vec![], }); - let tx_data = Arc::new(build_tx_data_with_loader(rtx, data_loader)); - let sg_data = build_sg_data(tx_data, vec![0], vec![]); + let sg_data = build_sg_data_with_loader(rtx, data_loader, vec![0], vec![]); let mut load_block_extension = LoadBlockExtension::new(&sg_data); diff --git a/script/src/types.rs b/script/src/types.rs index eee70ab348..a7c9cdfbac 100644 --- a/script/src/types.rs +++ b/script/src/types.rs @@ -564,6 +564,15 @@ impl Binaries { pub struct TxData
{ /// ResolvedTransaction. pub rtx: Arc, + + /// Passed & derived information. + pub info: Arc>, +} + +/// Information that is either passed as the context of the transaction, +/// or can be derived from the transaction. +#[derive(Clone, Debug)] +pub struct TxInfo
{ /// Data loader. pub data_loader: DL, /// Chain consensus parameters @@ -663,17 +672,30 @@ where Self { rtx, - data_loader, - consensus, - tx_env, - binaries_by_data_hash, - binaries_by_type_hash, - lock_groups, - type_groups, - outputs, + info: Arc::new(TxInfo { + data_loader, + consensus, + tx_env, + binaries_by_data_hash, + binaries_by_type_hash, + lock_groups, + type_groups, + outputs, + }), } } + #[inline] + /// Extracts actual script binary either in dep cells. + pub fn extract_script(&self, script: &Script) -> Result { + self.info.extract_script(script) + } +} + +impl
TxInfo
+where + DL: CellDataProvider, +{ #[inline] /// Extracts actual script binary either in dep cells. pub fn extract_script(&self, script: &Script) -> Result { @@ -683,6 +705,50 @@ where } impl
TxData
{ + #[inline] + /// Calculates transaction hash + pub fn tx_hash(&self) -> Byte32 { + self.rtx.transaction.hash() + } + + #[inline] + /// Extracts the index of the script binary in dep cells + pub fn extract_referenced_dep_index(&self, script: &Script) -> Result { + self.info.extract_referenced_dep_index(script) + } + + #[inline] + /// Finds the script group from cell deps. + pub fn find_script_group( + &self, + script_group_type: ScriptGroupType, + script_hash: &Byte32, + ) -> Option<&ScriptGroup> { + self.info.find_script_group(script_group_type, script_hash) + } + + #[inline] + /// Returns the version of the machine based on the script and the consensus rules. + pub fn select_version(&self, script: &Script) -> Result { + self.info.select_version(script) + } + + #[inline] + /// Returns all script groups. + pub fn groups(&self) -> impl Iterator { + self.info.groups() + } + + #[inline] + /// Returns all script groups with type. + pub fn groups_with_type( + &self, + ) -> impl Iterator { + self.info.groups_with_type() + } +} + +impl
TxInfo
{ #[inline] /// Extracts the index of the script binary in dep cells pub fn extract_referenced_dep_index(&self, script: &Script) -> Result { @@ -719,12 +785,6 @@ impl
TxData
{ } } - #[inline] - /// Calculates transaction hash - pub fn tx_hash(&self) -> Byte32 { - self.rtx.transaction.hash() - } - /// Finds the script group from cell deps. pub fn find_script_group( &self, @@ -818,9 +878,19 @@ impl
TxData
{ /// Immutable context data at script group level #[derive(Clone, Debug)] pub struct SgData
{ - /// Transaction level data - pub tx_data: Arc>, + /// ResolvedTransaction. + pub rtx: Arc, + + /// Passed & derived information at transaction level. + pub tx_info: Arc>, + /// Passed & derived information at script group level. + pub sg_info: Arc, +} + +/// Script group level derived information. +#[derive(Clone, Debug)] +pub struct SgInfo { /// Currently executed script version pub script_version: ScriptVersion, /// Currently executed script group @@ -832,7 +902,7 @@ pub struct SgData
{ } impl
SgData
{ - pub fn new(tx_data: &Arc>, script_group: &ScriptGroup) -> Result { + pub fn new(tx_data: &TxData
, script_group: &ScriptGroup) -> Result { let script_hash = script_group.script.calc_script_hash(); let script_version = tx_data.select_version(&script_group.script)?; let dep_index = tx_data @@ -840,94 +910,89 @@ impl
SgData
{ .try_into() .map_err(|_| ScriptError::Other("u32 overflow".to_string()))?; Ok(Self { - tx_data: Arc::clone(tx_data), - script_version, - script_hash, - script_group: script_group.clone(), - program_data_piece_id: DataPieceId::CellDep(dep_index), + rtx: Arc::clone(&tx_data.rtx), + tx_info: Arc::clone(&tx_data.info), + sg_info: Arc::new(SgInfo { + script_version, + script_hash, + script_group: script_group.clone(), + program_data_piece_id: DataPieceId::CellDep(dep_index), + }), }) } - pub fn rtx(&self) -> &ResolvedTransaction { - &self.tx_data.rtx - } - pub fn data_loader(&self) -> &DL { - &self.tx_data.data_loader + &self.tx_info.data_loader } pub fn group_inputs(&self) -> &[usize] { - &self.script_group.input_indices + &self.sg_info.script_group.input_indices } pub fn group_outputs(&self) -> &[usize] { - &self.script_group.output_indices + &self.sg_info.script_group.output_indices } pub fn outputs(&self) -> &[CellMeta] { - &self.tx_data.outputs - } - - pub fn current_script_hash(&self) -> &Byte32 { - &self.script_hash + &self.tx_info.outputs } } -impl
DataSource for Arc> +impl
DataSource for SgData
where DL: CellDataProvider, { fn load_data(&self, id: &DataPieceId, offset: u64, length: u64) -> Option<(Bytes, u64)> { match id { DataPieceId::Input(i) => self - .tx_data .rtx .resolved_inputs .get(*i as usize) - .and_then(|cell| self.tx_data.data_loader.load_cell_data(cell)), + .and_then(|cell| self.data_loader().load_cell_data(cell)), DataPieceId::Output(i) => self - .tx_data .rtx .transaction .outputs_data() .get(*i as usize) .map(|data| data.raw_data()), DataPieceId::CellDep(i) => self - .tx_data .rtx .resolved_cell_deps .get(*i as usize) - .and_then(|cell| self.tx_data.data_loader.load_cell_data(cell)), + .and_then(|cell| self.data_loader().load_cell_data(cell)), DataPieceId::GroupInput(i) => self + .sg_info .script_group .input_indices .get(*i as usize) - .and_then(|gi| self.tx_data.rtx.resolved_inputs.get(*gi)) - .and_then(|cell| self.tx_data.data_loader.load_cell_data(cell)), + .and_then(|gi| self.rtx.resolved_inputs.get(*gi)) + .and_then(|cell| self.data_loader().load_cell_data(cell)), DataPieceId::GroupOutput(i) => self + .sg_info .script_group .output_indices .get(*i as usize) - .and_then(|gi| self.tx_data.rtx.transaction.outputs_data().get(*gi)) + .and_then(|gi| self.rtx.transaction.outputs_data().get(*gi)) .map(|data| data.raw_data()), DataPieceId::Witness(i) => self - .tx_data .rtx .transaction .witnesses() .get(*i as usize) .map(|data| data.raw_data()), DataPieceId::WitnessGroupInput(i) => self + .sg_info .script_group .input_indices .get(*i as usize) - .and_then(|gi| self.tx_data.rtx.transaction.witnesses().get(*gi)) + .and_then(|gi| self.rtx.transaction.witnesses().get(*gi)) .map(|data| data.raw_data()), DataPieceId::WitnessGroupOutput(i) => self + .sg_info .script_group .output_indices .get(*i as usize) - .and_then(|gi| self.tx_data.rtx.transaction.witnesses().get(*gi)) + .and_then(|gi| self.rtx.transaction.witnesses().get(*gi)) .map(|data| data.raw_data()), } .map(|data| { @@ -952,21 +1017,21 @@ where pub(crate) base_cycles: Arc, /// A mutable reference to scheduler's message box pub(crate) message_box: Arc>>, - pub(crate) snapshot2_context: Arc>>>>, + pub(crate) snapshot2_context: Arc>>>, } impl
VmContext
where - DL: CellDataProvider, + DL: CellDataProvider + Clone, { /// Creates a new VM context. It is by design that parameters to this function /// are references. It is a reminder that the inputs are designed to be shared /// among different entities. - pub fn new(sg_data: &Arc>, message_box: &Arc>>) -> Self { + pub fn new(sg_data: &SgData
, message_box: &Arc>>) -> Self { Self { base_cycles: Arc::new(AtomicU64::new(0)), message_box: Arc::clone(message_box), - snapshot2_context: Arc::new(Mutex::new(Snapshot2Context::new(Arc::clone(sg_data)))), + snapshot2_context: Arc::new(Mutex::new(Snapshot2Context::new(sg_data.clone()))), } }