runtime: add tx_hash to runtime params

This commit is contained in:
zero
2024-04-01 11:40:01 +02:00
parent 5c9e3bd4a1
commit 0967744635
4 changed files with 35 additions and 8 deletions

View File

@@ -289,8 +289,14 @@ fn benchmark_wasm_calls(
for (idx, call) in tx.calls.iter().enumerate() {
let overlay = BlockchainOverlay::new(&validator.blockchain).expect("blockchain overlay");
let wasm = overlay.lock().unwrap().wasm_bincode.get(call.data.contract_id).unwrap();
let mut runtime = Runtime::new(&wasm, overlay.clone(), call.data.contract_id, block_height)
.expect("runtime");
let mut runtime = Runtime::new(
&wasm,
overlay.clone(),
call.data.contract_id,
block_height,
tx.hash().clone(),
)
.expect("runtime");
let mut payload = vec![];
payload.write_u32(idx as u32).unwrap(); // Call index
tx.calls.encode(&mut payload).unwrap(); // Actual call data

View File

@@ -94,8 +94,11 @@ pub struct Env {
pub memory: Option<Memory>,
/// Object store for transferring memory from the host to VM
pub objects: RefCell<Vec<Vec<u8>>>,
/// Block height number runtime verifys against
/// Block height number runtime verifies against.
/// For unconfirmed txs, this will be the current max height in the chain.
pub verifying_block_height: u64,
/// The hash for this transaction the runtime is being run against.
pub tx_hash: TransactionHash,
/// Parent `Instance`
pub instance: Option<Arc<Instance>>,
}
@@ -151,6 +154,7 @@ impl Runtime {
blockchain: BlockchainOverlayPtr,
contract_id: ContractId,
verifying_block_height: u64,
tx_hash: TransactionHash,
) -> Result<Self> {
info!(target: "runtime::vm_runtime", "[WASM] Instantiating a new runtime");
// This function will be called for each `Operator` encountered during
@@ -192,6 +196,7 @@ impl Runtime {
memory: None,
objects: RefCell::new(vec![]),
verifying_block_height,
tx_hash,
instance: None,
},
);

View File

@@ -84,7 +84,13 @@ pub async fn deploy_native_contracts(overlay: &BlockchainOverlayPtr) -> Result<(
for nc in native_contracts {
info!(target: "validator::utils::deploy_native_contracts", "Deploying {} with ContractID {}", nc.0, nc.1);
let mut runtime = Runtime::new(&nc.2[..], overlay.clone(), nc.1, verifying_block_height)?;
let mut runtime = Runtime::new(
&nc.2[..],
overlay.clone(),
nc.1,
verifying_block_height,
TransactionHash::none(),
)?;
runtime.deploy(&nc.3)?;

View File

@@ -282,8 +282,13 @@ pub async fn verify_producer_transaction(
debug!(target: "validator::verification::verify_producer_transaction", "Instantiating WASM runtime");
let wasm = overlay.lock().unwrap().wasm_bincode.get(call.data.contract_id)?;
let mut runtime =
Runtime::new(&wasm, overlay.clone(), call.data.contract_id, verifying_block_height)?;
let mut runtime = Runtime::new(
&wasm,
overlay.clone(),
call.data.contract_id,
verifying_block_height,
tx_hash.clone(),
)?;
debug!(target: "validator::verification::verify_producer_transaction", "Executing \"metadata\" call");
let metadata = runtime.metadata(&payload)?;
@@ -444,8 +449,13 @@ pub async fn verify_transaction(
debug!(target: "validator::verification::verify_transaction", "Instantiating WASM runtime");
let wasm = overlay.lock().unwrap().wasm_bincode.get(call.data.contract_id)?;
let mut runtime =
Runtime::new(&wasm, overlay.clone(), call.data.contract_id, verifying_block_height)?;
let mut runtime = Runtime::new(
&wasm,
overlay.clone(),
call.data.contract_id,
verifying_block_height,
tx_hash.clone(),
)?;
debug!(target: "validator::verification::verify_transaction", "Executing \"metadata\" call");
let metadata = runtime.metadata(&payload)?;