From 11527692a76bbd938ede3d07d66b2f20376355fe Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Wed, 4 Sep 2024 17:32:45 +0200 Subject: [PATCH 1/5] EVM/Kernel: differentiate Runtime trait from SDK Runtime trait --- etherlink/kernel_evm/kernel/src/block.rs | 3 +- .../kernel/src/block_in_progress.rs | 2 +- etherlink/kernel_evm/runtime/src/lib.rs | 1 + etherlink/kernel_evm/runtime/src/runtime.rs | 25 ++++++++++++ .../kernel_evm/runtime/src/safe_storage.rs | 38 ++++++++----------- 5 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 etherlink/kernel_evm/runtime/src/runtime.rs diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index c701eb59b121..0821a848dfba 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -31,7 +31,8 @@ use tezos_ethereum::block::BlockFees; use tezos_ethereum::transaction::TransactionHash; use tezos_evm_logging::{log, Level::*}; use tezos_evm_runtime::internal_runtime::InternalRuntime; -use tezos_evm_runtime::safe_storage::{KernelRuntime, SafeStorage}; +use tezos_evm_runtime::runtime::Runtime as KernelRuntime; +use tezos_evm_runtime::safe_storage::SafeStorage; use tezos_smart_rollup::outbox::OutboxQueue; use tezos_smart_rollup_host::path::{Path, RefPath}; use tezos_smart_rollup_host::runtime::Runtime; diff --git a/etherlink/kernel_evm/kernel/src/block_in_progress.rs b/etherlink/kernel_evm/kernel/src/block_in_progress.rs index 44218dc79837..2d4873a34a36 100644 --- a/etherlink/kernel_evm/kernel/src/block_in_progress.rs +++ b/etherlink/kernel_evm/kernel/src/block_in_progress.rs @@ -26,7 +26,7 @@ use tezos_ethereum::transaction::{ }; use tezos_ethereum::Bloom; use tezos_evm_logging::{log, Level::*}; -use tezos_evm_runtime::safe_storage::KernelRuntime; +use tezos_evm_runtime::runtime::Runtime as KernelRuntime; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_host::path::{concat, RefPath}; use tezos_smart_rollup_host::runtime::Runtime; diff --git a/etherlink/kernel_evm/runtime/src/lib.rs b/etherlink/kernel_evm/runtime/src/lib.rs index 5ceb77baf0ec..b050c9d90f6a 100644 --- a/etherlink/kernel_evm/runtime/src/lib.rs +++ b/etherlink/kernel_evm/runtime/src/lib.rs @@ -4,4 +4,5 @@ pub mod internal_runtime; pub mod mock_internal; +pub mod runtime; pub mod safe_storage; diff --git a/etherlink/kernel_evm/runtime/src/runtime.rs b/etherlink/kernel_evm/runtime/src/runtime.rs new file mode 100644 index 000000000000..37d1052cd434 --- /dev/null +++ b/etherlink/kernel_evm/runtime/src/runtime.rs @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2023 Nomadic Labs +// SPDX-FileCopyrightText: 2023 Functori +// SPDX-FileCopyrightText: 2023 Trilitech +// SPDX-FileCopyrightText: 2023 Marigold +// +// SPDX-License-Identifier: MIT + +// The kernel runtime requires both the standard Runtime and the +// new Extended one. + +use crate::internal_runtime::{ExtendedRuntime, InternalRuntime}; +use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; +use tezos_smart_rollup_host::{ + dal_parameters::RollupDalParameters, + input::Message, + metadata::RollupMetadata, + path::Path, + runtime::{Runtime as SdkRuntime, RuntimeError, ValueType}, +}; + +pub trait Runtime: SdkRuntime + InternalRuntime + ExtendedRuntime {} + +// If a type implements the Runtime, InternalRuntime and ExtendedRuntime traits, +// it also implements the kernel Runtime. +impl Runtime for T {} diff --git a/etherlink/kernel_evm/runtime/src/safe_storage.rs b/etherlink/kernel_evm/runtime/src/safe_storage.rs index 5fea289e5904..940a0919f300 100644 --- a/etherlink/kernel_evm/runtime/src/safe_storage.rs +++ b/etherlink/kernel_evm/runtime/src/safe_storage.rs @@ -12,7 +12,7 @@ use tezos_smart_rollup_host::{ input::Message, metadata::RollupMetadata, path::{concat, OwnedPath, Path, RefPath}, - runtime::{Runtime, RuntimeError, ValueType}, + runtime::{Runtime as SdkRuntime, RuntimeError, ValueType}, }; pub const TMP_PATH: RefPath = RefPath::assert_from(b"/tmp"); @@ -21,32 +21,15 @@ pub const TMP_WORLD_STATE_PATH: RefPath = RefPath::assert_from(b"/tmp/evm/world_ pub const TRACE_PATH: RefPath = RefPath::assert_from(b"/evm/trace"); pub const TMP_TRACE_PATH: RefPath = RefPath::assert_from(b"/tmp/evm/trace"); -// The kernel runtime requires both the standard Runtime and the -// new Extended one. -pub trait KernelRuntime: Runtime + ExtendedRuntime {} - -// Every type implementing an InternalRuntime will implement -// the ExtendedRuntime. -impl ExtendedRuntime for T { - fn store_get_hash(&mut self, path: &P) -> Result, RuntimeError> { - let path = safe_path(path)?; - self.__internal_store_get_hash(&path) - } +pub fn safe_path(path: &T) -> Result { + concat(&TMP_PATH, path).map_err(|_| RuntimeError::PathNotFound) } -// If a type implements the Runtime and InternalRuntime traits, -// it also implements the KernelRuntime. -impl KernelRuntime for T {} - pub struct SafeStorage { pub host: Host, pub internal: Internal, } -pub fn safe_path(path: &T) -> Result { - concat(&TMP_PATH, path).map_err(|_| RuntimeError::PathNotFound) -} - impl InternalRuntime for SafeStorage<&mut Host, &mut InternalHost> { @@ -58,7 +41,18 @@ impl InternalRuntime } } -impl Runtime for SafeStorage<&mut Host, &mut InternalHost> { +impl ExtendedRuntime + for SafeStorage<&mut Host, &mut InternalHost> +{ + fn store_get_hash(&mut self, path: &P) -> Result, RuntimeError> { + let path = safe_path(path)?; + self.__internal_store_get_hash(&path) + } +} + +impl SdkRuntime + for SafeStorage<&mut Host, &mut InternalHost> +{ fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError> { self.host.write_output(from) } @@ -212,7 +206,7 @@ impl Runtime for SafeStorage<&mut Host, &mut Intern } } -impl SafeStorage<&mut Host, &mut Internal> { +impl SafeStorage<&mut Host, &mut Internal> { pub fn start(&mut self) -> Result<(), RuntimeError> { self.host .store_copy(&WORLD_STATE_PATH, &TMP_WORLD_STATE_PATH) -- GitLab From 5ae290477f55a64c08ac0f38752807b44533bfc6 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Wed, 4 Sep 2024 17:50:21 +0200 Subject: [PATCH 2/5] EVM/Kernel: add KernelHost --- etherlink/kernel_evm/runtime/src/runtime.rs | 193 ++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/etherlink/kernel_evm/runtime/src/runtime.rs b/etherlink/kernel_evm/runtime/src/runtime.rs index 37d1052cd434..bf81396e033d 100644 --- a/etherlink/kernel_evm/runtime/src/runtime.rs +++ b/etherlink/kernel_evm/runtime/src/runtime.rs @@ -23,3 +23,196 @@ pub trait Runtime: SdkRuntime + InternalRuntime + ExtendedRuntime {} // If a type implements the Runtime, InternalRuntime and ExtendedRuntime traits, // it also implements the kernel Runtime. impl Runtime for T {} + +pub struct KernelHost { + pub host: Host, + pub internal: Internal, +} + +impl SdkRuntime + for KernelHost<&mut Host, &mut Internal> +{ + #[inline(always)] + fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError> { + self.host.write_output(from) + } + + #[inline(always)] + fn write_debug(&self, msg: &str) { + self.host.write_debug(msg) + } + + #[inline(always)] + fn read_input(&mut self) -> Result, RuntimeError> { + self.host.read_input() + } + + #[inline(always)] + fn store_has(&self, path: &T) -> Result, RuntimeError> { + self.host.store_has(path) + } + + #[inline(always)] + fn store_read( + &self, + path: &T, + from_offset: usize, + max_bytes: usize, + ) -> Result, RuntimeError> { + self.host.store_read(path, from_offset, max_bytes) + } + + #[inline(always)] + fn store_read_slice( + &self, + path: &T, + from_offset: usize, + buffer: &mut [u8], + ) -> Result { + self.host.store_read_slice(path, from_offset, buffer) + } + + #[inline(always)] + fn store_read_all(&self, path: &impl Path) -> Result, RuntimeError> { + self.host.store_read_all(path) + } + + #[inline(always)] + fn store_write( + &mut self, + path: &T, + src: &[u8], + at_offset: usize, + ) -> Result<(), RuntimeError> { + self.host.store_write(path, src, at_offset) + } + + #[inline(always)] + fn store_write_all( + &mut self, + path: &T, + src: &[u8], + ) -> Result<(), RuntimeError> { + self.host.store_write_all(path, src) + } + + #[inline(always)] + fn store_delete(&mut self, path: &T) -> Result<(), RuntimeError> { + self.host.store_delete(path) + } + + #[inline(always)] + fn store_delete_value(&mut self, path: &T) -> Result<(), RuntimeError> { + self.host.store_delete_value(path) + } + + #[inline(always)] + fn store_count_subkeys(&self, prefix: &T) -> Result { + self.host.store_count_subkeys(prefix) + } + + #[inline(always)] + fn store_move( + &mut self, + from_path: &impl Path, + to_path: &impl Path, + ) -> Result<(), RuntimeError> { + self.host.store_move(from_path, to_path) + } + + #[inline(always)] + fn store_copy( + &mut self, + from_path: &impl Path, + to_path: &impl Path, + ) -> Result<(), RuntimeError> { + self.host.store_copy(from_path, to_path) + } + + #[inline(always)] + fn reveal_preimage( + &self, + hash: &[u8; PREIMAGE_HASH_SIZE], + destination: &mut [u8], + ) -> Result { + self.host.reveal_preimage(hash, destination) + } + + #[inline(always)] + fn store_value_size(&self, path: &impl Path) -> Result { + self.host.store_value_size(path) + } + + #[inline(always)] + fn mark_for_reboot(&mut self) -> Result<(), RuntimeError> { + self.host.mark_for_reboot() + } + + #[inline(always)] + fn reveal_metadata(&self) -> RollupMetadata { + self.host.reveal_metadata() + } + + #[inline(always)] + fn reveal_dal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + destination: &mut [u8], + ) -> Result { + self.host + .reveal_dal_page(published_level, slot_index, page_index, destination) + } + + #[inline(always)] + fn reveal_dal_parameters(&self) -> RollupDalParameters { + self.host.reveal_dal_parameters() + } + + #[inline(always)] + fn last_run_aborted(&self) -> Result { + self.host.last_run_aborted() + } + + #[inline(always)] + fn upgrade_failed(&self) -> Result { + self.host.upgrade_failed() + } + + #[inline(always)] + fn restart_forced(&self) -> Result { + self.host.restart_forced() + } + + #[inline(always)] + fn reboot_left(&self) -> Result { + self.host.reboot_left() + } + + #[inline(always)] + fn runtime_version(&self) -> Result { + self.host.runtime_version() + } +} + +impl InternalRuntime + for KernelHost<&mut Host, &mut Internal> +{ + #[inline(always)] + fn __internal_store_get_hash( + &mut self, + path: &T, + ) -> Result, RuntimeError> { + self.internal.__internal_store_get_hash(path) + } +} + +impl ExtendedRuntime + for KernelHost<&mut Host, &mut Internal> +{ + #[inline(always)] + fn store_get_hash(&mut self, path: &T) -> Result, RuntimeError> { + self.__internal_store_get_hash(path) + } +} -- GitLab From 6f06f2184a88366e09964cd6ebffd96f15274ebb Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Wed, 4 Sep 2024 18:15:37 +0200 Subject: [PATCH 3/5] EVM/Kernel: use our own runtime Not in test yet, wait for the next commits --- etherlink/kernel_evm/kernel/src/block.rs | 5 ++-- .../kernel/src/block_in_progress.rs | 11 ++++--- .../kernel/src/blueprint_storage.rs | 3 +- .../kernel_evm/kernel/src/configuration.rs | 2 +- .../kernel_evm/kernel/src/delayed_inbox.rs | 3 +- .../kernel/src/evm_node_entrypoint.rs | 8 ++++- etherlink/kernel_evm/kernel/src/inbox.rs | 2 +- etherlink/kernel_evm/kernel/src/lib.rs | 29 ++++++++++++++----- .../kernel_evm/kernel/src/reveal_storage.rs | 2 +- etherlink/kernel_evm/kernel/src/simulation.rs | 2 +- etherlink/kernel_evm/kernel/src/stage_one.rs | 2 +- etherlink/kernel_evm/kernel/src/upgrade.rs | 2 +- 12 files changed, 45 insertions(+), 26 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index 0821a848dfba..81baa88c6827 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -31,11 +31,10 @@ use tezos_ethereum::block::BlockFees; use tezos_ethereum::transaction::TransactionHash; use tezos_evm_logging::{log, Level::*}; use tezos_evm_runtime::internal_runtime::InternalRuntime; -use tezos_evm_runtime::runtime::Runtime as KernelRuntime; +use tezos_evm_runtime::runtime::Runtime; use tezos_evm_runtime::safe_storage::SafeStorage; use tezos_smart_rollup::outbox::OutboxQueue; use tezos_smart_rollup_host::path::{Path, RefPath}; -use tezos_smart_rollup_host::runtime::Runtime; use tick_model::estimate_remaining_ticks_for_transaction_execution; use tezos_ethereum::block::BlockConstants; @@ -252,7 +251,7 @@ fn next_bip_from_blueprints( } #[allow(clippy::too_many_arguments)] -fn compute_bip( +fn compute_bip( host: &mut Host, outbox_queue: &OutboxQueue<'_, impl Path>, mut block_in_progress: BlockInProgress, diff --git a/etherlink/kernel_evm/kernel/src/block_in_progress.rs b/etherlink/kernel_evm/kernel/src/block_in_progress.rs index 2d4873a34a36..ceea8e8042b2 100644 --- a/etherlink/kernel_evm/kernel/src/block_in_progress.rs +++ b/etherlink/kernel_evm/kernel/src/block_in_progress.rs @@ -26,10 +26,9 @@ use tezos_ethereum::transaction::{ }; use tezos_ethereum::Bloom; use tezos_evm_logging::{log, Level::*}; -use tezos_evm_runtime::runtime::Runtime as KernelRuntime; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_host::path::{concat, RefPath}; -use tezos_smart_rollup_host::runtime::Runtime; #[derive(Debug, PartialEq, Clone)] /// Container for all data needed during block computation @@ -310,7 +309,7 @@ impl BlockInProgress { self.add_ticks(tick_model::ticks_of_invalid_transaction(tx_data_size)); } - fn safe_store_get_hash( + fn safe_store_get_hash( host: &mut Host, path: &RefPath, ) -> Result, anyhow::Error> { @@ -326,7 +325,7 @@ impl BlockInProgress { fn receipts_root( &self, - host: &mut impl KernelRuntime, + host: &mut impl Runtime, previous_receipts_root: Vec, ) -> anyhow::Result> { if self.valid_txs.is_empty() { @@ -350,7 +349,7 @@ impl BlockInProgress { fn transactions_root( &self, - host: &mut impl KernelRuntime, + host: &mut impl Runtime, previous_transactions_root: Vec, ) -> anyhow::Result> { if self.valid_txs.is_empty() { @@ -372,7 +371,7 @@ impl BlockInProgress { } #[cfg_attr(feature = "benchmark", inline(never))] - pub fn finalize_and_store( + pub fn finalize_and_store( self, host: &mut Host, block_constants: &BlockConstants, diff --git a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs index 0cdcf0d927db..110556513841 100644 --- a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs +++ b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs @@ -20,10 +20,11 @@ use sha3::{Digest, Keccak256}; use tezos_ethereum::rlp_helpers; use tezos_ethereum::tx_common::EthereumTransactionCommon; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup::types::Timestamp; use tezos_smart_rollup_core::MAX_INPUT_MESSAGE_SIZE; use tezos_smart_rollup_host::path::*; -use tezos_smart_rollup_host::runtime::{Runtime, RuntimeError}; +use tezos_smart_rollup_host::runtime::RuntimeError; use tezos_storage::{ error::Error as GenStorageError, read_rlp, store_read_slice, store_rlp, }; diff --git a/etherlink/kernel_evm/kernel/src/configuration.rs b/etherlink/kernel_evm/kernel/src/configuration.rs index fbfd79f46e34..a538065c71df 100644 --- a/etherlink/kernel_evm/kernel/src/configuration.rs +++ b/etherlink/kernel_evm/kernel/src/configuration.rs @@ -13,7 +13,7 @@ use crate::{ use evm_execution::read_ticketer; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_evm_logging::{log, Level::*}; -use tezos_smart_rollup_debug::Runtime; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::public_key::PublicKey; #[derive(Debug, Clone, Default)] diff --git a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs index 4b82d8a06058..a31b13b5c57a 100644 --- a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs +++ b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs @@ -18,8 +18,9 @@ use tezos_ethereum::{ tx_common::EthereumTransactionCommon, }; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::timestamp::Timestamp; -use tezos_smart_rollup_host::{path::RefPath, runtime::Runtime}; +use tezos_smart_rollup_host::path::RefPath; pub struct DelayedInbox(LinkedList); diff --git a/etherlink/kernel_evm/kernel/src/evm_node_entrypoint.rs b/etherlink/kernel_evm/kernel/src/evm_node_entrypoint.rs index 6d45f33dea98..e091e0f3bd48 100644 --- a/etherlink/kernel_evm/kernel/src/evm_node_entrypoint.rs +++ b/etherlink/kernel_evm/kernel/src/evm_node_entrypoint.rs @@ -10,6 +10,7 @@ use crate::{delayed_inbox::DelayedInbox, inbox::Transaction}; use tezos_ethereum::rlp_helpers::FromRlpBytes; +use tezos_evm_runtime::{internal_runtime::InternalHost, runtime::KernelHost}; use tezos_smart_rollup_core::rollup_host::RollupHost; use tezos_smart_rollup_host::{path::RefPath, runtime::Runtime}; @@ -18,7 +19,12 @@ const DELAYED_INPUT_PATH: RefPath = RefPath::assert_from(b"/__delayed_input"); #[allow(dead_code)] #[no_mangle] pub extern "C" fn populate_delayed_inbox() { - let mut host = unsafe { RollupHost::new() }; + let mut sdk_host = unsafe { RollupHost::new() }; + let mut internal = InternalHost(); + let mut host = KernelHost { + host: &mut sdk_host, + internal: &mut internal, + }; let payload = host.store_read_all(&DELAYED_INPUT_PATH).unwrap(); let transaction = Transaction::from_rlp_bytes(&payload).unwrap(); let mut delayed_inbox = DelayedInbox::new(&mut host).unwrap(); diff --git a/etherlink/kernel_evm/kernel/src/inbox.rs b/etherlink/kernel_evm/kernel/src/inbox.rs index 5510059e784c..a6ca91f450de 100644 --- a/etherlink/kernel_evm/kernel/src/inbox.rs +++ b/etherlink/kernel_evm/kernel/src/inbox.rs @@ -38,8 +38,8 @@ use tezos_ethereum::transaction::{ }; use tezos_ethereum::tx_common::EthereumTransactionCommon; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::public_key::PublicKey; -use tezos_smart_rollup_host::runtime::Runtime; #[allow(clippy::large_enum_variant)] #[derive(Debug, PartialEq, Clone)] diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index 2cbf34291b00..5724f543c201 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -29,6 +29,7 @@ use storage::{ use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_ethereum::block::BlockFees; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::{KernelHost, Runtime}; use tezos_evm_runtime::safe_storage::WORLD_STATE_PATH; use tezos_smart_rollup::entrypoint; use tezos_smart_rollup::michelson::MichelsonUnit; @@ -37,7 +38,7 @@ use tezos_smart_rollup::outbox::{ }; use tezos_smart_rollup_encoding::public_key::PublicKey; use tezos_smart_rollup_encoding::timestamp::Timestamp; -use tezos_smart_rollup_host::runtime::{Runtime, ValueType}; +use tezos_smart_rollup_host::runtime::ValueType; mod apply; mod block; @@ -257,7 +258,7 @@ pub fn main(host: &mut Host) -> Result<(), anyhow::Error> { // Fetch kernel metadata: // 1. Fetch the smart rollup address via the host function, it cannot fail. - let smart_rollup_address = Runtime::reveal_metadata(host).raw_rollup_address; + let smart_rollup_address = host.reveal_metadata().raw_rollup_address; // 2. Fetch the per mode configuration of the kernel. Returns the default // configuration if it fails. let mut configuration = fetch_configuration(host); @@ -305,12 +306,22 @@ pub fn main(host: &mut Host) -> Result<(), anyhow::Error> { } #[entrypoint::main] -pub fn kernel_loop(host: &mut Host) { +pub fn kernel_loop(host: &mut Host) { // In order to setup the temporary directory, we need to move something // from /evm to /tmp, so /evm must be non empty, this only happen // at the first run. + // The kernel host is initialized as soon as possible. `kernel_loop` + // shouldn't be called in tests as it won't use `MockInternal` for the + // internal runtime. + let mut internal_storage = tezos_evm_runtime::internal_runtime::InternalHost(); + let mut host = KernelHost { + host, + internal: &mut internal_storage, + }; + let reboot_counter = host + .host .reboot_left() .expect("The kernel failed to get the number of reboot left"); if reboot_counter == 1000 { @@ -321,17 +332,19 @@ pub fn kernel_loop(host: &mut Host) { } let world_state_subkeys = host + .host .store_count_subkeys(&WORLD_STATE_PATH) .expect("The kernel failed to read the number of /evm/world_state subkeys"); if world_state_subkeys == 0 { - host.store_write(&WORLD_STATE_PATH, "Un festival de GADT".as_bytes(), 0) + host.host + .store_write(&WORLD_STATE_PATH, "Un festival de GADT".as_bytes(), 0) .unwrap(); } - if is_revealed_storage(host) { + if is_revealed_storage(&host) { reveal_storage( - host, + &mut host, option_env!("EVM_SEQUENCER").map(|s| { PublicKey::from_b58check(s).expect("Failed parsing EVM_SEQUENCER") }), @@ -341,10 +354,10 @@ pub fn kernel_loop(host: &mut Host) { ); } - match main(host) { + match main(&mut host) { Ok(()) => (), Err(err) => { - log!(host, Fatal, "The kernel produced an error: {:?}", err); + log!(&mut host, Fatal, "The kernel produced an error: {:?}", err); } } } diff --git a/etherlink/kernel_evm/kernel/src/reveal_storage.rs b/etherlink/kernel_evm/kernel/src/reveal_storage.rs index 5b53a04c13b0..294670a97282 100644 --- a/etherlink/kernel_evm/kernel/src/reveal_storage.rs +++ b/etherlink/kernel_evm/kernel/src/reveal_storage.rs @@ -8,7 +8,7 @@ use rlp::{Decodable, DecoderError, Rlp}; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_ethereum::rlp_helpers::{decode_field, next, FromRlpBytes}; use tezos_evm_logging::{log, Level::*}; -use tezos_smart_rollup_debug::Runtime; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::public_key::PublicKey; use tezos_smart_rollup_host::path::{OwnedPath, RefPath}; use tezos_smart_rollup_host::runtime::ValueType; diff --git a/etherlink/kernel_evm/kernel/src/simulation.rs b/etherlink/kernel_evm/kernel/src/simulation.rs index 5bf6704f1a7f..e036fdba4ccd 100644 --- a/etherlink/kernel_evm/kernel/src/simulation.rs +++ b/etherlink/kernel_evm/kernel/src/simulation.rs @@ -39,8 +39,8 @@ use tezos_ethereum::rlp_helpers::{ use tezos_ethereum::transaction::TransactionObject; use tezos_ethereum::tx_common::EthereumTransactionCommon; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup::types::Timestamp; -use tezos_smart_rollup_host::runtime::Runtime; // SIMULATION/SIMPLE/RLP_ENCODED_SIMULATION pub const SIMULATION_SIMPLE_TAG: u8 = 1; diff --git a/etherlink/kernel_evm/kernel/src/stage_one.rs b/etherlink/kernel_evm/kernel/src/stage_one.rs index 51e326be7e58..af213b949a84 100644 --- a/etherlink/kernel_evm/kernel/src/stage_one.rs +++ b/etherlink/kernel_evm/kernel/src/stage_one.rs @@ -16,9 +16,9 @@ use std::ops::Add; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_ethereum::block::L2Block; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::public_key::PublicKey; use tezos_smart_rollup_host::metadata::RAW_ROLLUP_ADDRESS_SIZE; -use tezos_smart_rollup_host::runtime::Runtime; pub fn fetch_proxy_blueprints( host: &mut Host, diff --git a/etherlink/kernel_evm/kernel/src/upgrade.rs b/etherlink/kernel_evm/kernel/src/upgrade.rs index e86ce388824b..32f69aa0ed42 100644 --- a/etherlink/kernel_evm/kernel/src/upgrade.rs +++ b/etherlink/kernel_evm/kernel/src/upgrade.rs @@ -24,13 +24,13 @@ use tezos_ethereum::rlp_helpers::decode_public_key; use tezos_ethereum::rlp_helpers::decode_timestamp; use tezos_ethereum::rlp_helpers::next; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; use tezos_smart_rollup_encoding::public_key::PublicKey; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_host::path::OwnedPath; use tezos_smart_rollup_host::path::Path; use tezos_smart_rollup_host::path::RefPath; -use tezos_smart_rollup_host::runtime::Runtime; use tezos_smart_rollup_installer_config::binary::promote::upgrade_reveal_flow; use tezos_storage::read_optional_rlp; -- GitLab From 8f9d2671a24cb0c9b633590c57b7105bd1a0b2c0 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Wed, 4 Sep 2024 19:03:37 +0200 Subject: [PATCH 4/5] EVM/Kernel: safe_storage depends on our runtime --- etherlink/kernel_evm/kernel/src/block.rs | 17 ++----- .../kernel_evm/runtime/src/safe_storage.rs | 48 +++++++++++++------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index 81baa88c6827..e62e993ccc2f 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -30,7 +30,6 @@ use primitive_types::{H160, H256, U256}; use tezos_ethereum::block::BlockFees; use tezos_ethereum::transaction::TransactionHash; use tezos_evm_logging::{log, Level::*}; -use tezos_evm_runtime::internal_runtime::InternalRuntime; use tezos_evm_runtime::runtime::Runtime; use tezos_evm_runtime::safe_storage::SafeStorage; use tezos_smart_rollup::outbox::OutboxQueue; @@ -321,7 +320,7 @@ fn compute_bip( } fn revert_block( - safe_host: &mut SafeStorage<&mut Host, &mut impl InternalRuntime>, + safe_host: &mut SafeStorage<&mut Host>, block_in_progress: bool, number: U256, error: anyhow::Error, @@ -351,7 +350,7 @@ fn clean_delayed_transactions( } fn promote_block( - safe_host: &mut SafeStorage<&mut Host, &mut impl InternalRuntime>, + safe_host: &mut SafeStorage<&mut Host>, outbox_queue: &OutboxQueue<'_, impl Path>, block_in_progress: bool, number: U256, @@ -424,17 +423,10 @@ pub fn produce( let at_most_one_block = host.store_has(&AT_MOST_ONE_BLOCK)?.is_some(); - #[cfg(not(test))] - let mut internal_storage = tezos_evm_runtime::internal_runtime::InternalHost(); - #[cfg(test)] - let mut internal_storage = tezos_evm_runtime::mock_internal::MockInternal(); - let mut safe_host = SafeStorage { - host, - internal: &mut internal_storage, - }; + let mut safe_host = SafeStorage { host }; let outbox_queue = OutboxQueue::new(&WITHDRAWAL_OUTBOX_QUEUE, u32::MAX)?; let precompiles = - precompiles::precompile_set::>(config.enable_fa_bridge); + precompiles::precompile_set::>(config.enable_fa_bridge); // Check if there's a BIP in storage to resume its execution match storage::read_block_in_progress(&safe_host)? { @@ -614,6 +606,7 @@ mod tests { TransactionHash, TransactionStatus, TransactionType, TRANSACTION_HASH_SIZE, }; use tezos_ethereum::tx_common::EthereumTransactionCommon; + use tezos_evm_runtime::runtime::KernelHost; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_mock::MockHost; diff --git a/etherlink/kernel_evm/runtime/src/safe_storage.rs b/etherlink/kernel_evm/runtime/src/safe_storage.rs index 940a0919f300..bce9d0ac6af8 100644 --- a/etherlink/kernel_evm/runtime/src/safe_storage.rs +++ b/etherlink/kernel_evm/runtime/src/safe_storage.rs @@ -6,6 +6,7 @@ // SPDX-License-Identifier: MIT use crate::internal_runtime::{ExtendedRuntime, InternalRuntime}; +use crate::runtime::Runtime; use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; use tezos_smart_rollup_host::dal_parameters::RollupDalParameters; use tezos_smart_rollup_host::{ @@ -25,51 +26,50 @@ pub fn safe_path(path: &T) -> Result { concat(&TMP_PATH, path).map_err(|_| RuntimeError::PathNotFound) } -pub struct SafeStorage { - pub host: Host, - pub internal: Internal, +pub struct SafeStorage { + pub host: Runtime, } -impl InternalRuntime - for SafeStorage<&mut Host, &mut InternalHost> -{ +impl InternalRuntime for SafeStorage<&mut Host> { fn __internal_store_get_hash( &mut self, path: &T, ) -> Result, RuntimeError> { - self.internal.__internal_store_get_hash(path) + self.host.__internal_store_get_hash(path) } } -impl ExtendedRuntime - for SafeStorage<&mut Host, &mut InternalHost> -{ +impl ExtendedRuntime for SafeStorage<&mut Host> { + #[inline(always)] fn store_get_hash(&mut self, path: &P) -> Result, RuntimeError> { let path = safe_path(path)?; self.__internal_store_get_hash(&path) } } -impl SdkRuntime - for SafeStorage<&mut Host, &mut InternalHost> -{ +impl SdkRuntime for SafeStorage<&mut Host> { + #[inline(always)] fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError> { self.host.write_output(from) } + #[inline(always)] fn write_debug(&self, msg: &str) { self.host.write_debug(msg) } + #[inline(always)] fn read_input(&mut self) -> Result, RuntimeError> { self.host.read_input() } + #[inline(always)] fn store_has(&self, path: &T) -> Result, RuntimeError> { let path = safe_path(path)?; self.host.store_has(&path) } + #[inline(always)] fn store_read( &self, path: &T, @@ -80,6 +80,7 @@ impl SdkRuntime self.host.store_read(&path, from_offset, max_bytes) } + #[inline(always)] fn store_read_slice( &self, path: &T, @@ -90,11 +91,13 @@ impl SdkRuntime self.host.store_read_slice(&path, from_offset, buffer) } + #[inline(always)] fn store_read_all(&self, path: &impl Path) -> Result, RuntimeError> { let path = safe_path(path)?; self.host.store_read_all(&path) } + #[inline(always)] fn store_write( &mut self, path: &T, @@ -105,6 +108,7 @@ impl SdkRuntime self.host.store_write(&path, src, at_offset) } + #[inline(always)] fn store_write_all( &mut self, path: &T, @@ -114,21 +118,25 @@ impl SdkRuntime self.host.store_write_all(&path, src) } + #[inline(always)] fn store_delete(&mut self, path: &T) -> Result<(), RuntimeError> { let path = safe_path(path)?; self.host.store_delete(&path) } + #[inline(always)] fn store_delete_value(&mut self, path: &T) -> Result<(), RuntimeError> { let path = safe_path(path)?; self.host.store_delete_value(&path) } + #[inline(always)] fn store_count_subkeys(&self, prefix: &T) -> Result { let prefix = safe_path(prefix)?; self.host.store_count_subkeys(&prefix) } + #[inline(always)] fn store_move( &mut self, from_path: &impl Path, @@ -139,6 +147,7 @@ impl SdkRuntime self.host.store_move(&from_path, &to_path) } + #[inline(always)] fn store_copy( &mut self, from_path: &impl Path, @@ -149,6 +158,7 @@ impl SdkRuntime self.host.store_copy(&from_path, &to_path) } + #[inline(always)] fn reveal_preimage( &self, hash: &[u8; PREIMAGE_HASH_SIZE], @@ -157,19 +167,23 @@ impl SdkRuntime self.host.reveal_preimage(hash, destination) } + #[inline(always)] fn store_value_size(&self, path: &impl Path) -> Result { let path = safe_path(path)?; self.host.store_value_size(&path) } + #[inline(always)] fn mark_for_reboot(&mut self) -> Result<(), RuntimeError> { self.host.mark_for_reboot() } + #[inline(always)] fn reveal_metadata(&self) -> RollupMetadata { self.host.reveal_metadata() } + #[inline(always)] fn reveal_dal_page( &self, published_level: i32, @@ -181,32 +195,38 @@ impl SdkRuntime .reveal_dal_page(published_level, slot_index, page_index, destination) } + #[inline(always)] fn reveal_dal_parameters(&self) -> RollupDalParameters { self.host.reveal_dal_parameters() } + #[inline(always)] fn last_run_aborted(&self) -> Result { self.host.last_run_aborted() } + #[inline(always)] fn upgrade_failed(&self) -> Result { self.host.upgrade_failed() } + #[inline(always)] fn restart_forced(&self) -> Result { self.host.restart_forced() } + #[inline(always)] fn reboot_left(&self) -> Result { self.host.reboot_left() } + #[inline(always)] fn runtime_version(&self) -> Result { self.host.runtime_version() } } -impl SafeStorage<&mut Host, &mut Internal> { +impl SafeStorage<&mut Host> { pub fn start(&mut self) -> Result<(), RuntimeError> { self.host .store_copy(&WORLD_STATE_PATH, &TMP_WORLD_STATE_PATH) -- GitLab From 473ca5657c548c8673200cc99075c061bb714f58 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Thu, 5 Sep 2024 11:02:10 +0200 Subject: [PATCH 5/5] EVM/Kernel: update tests to use our own runtime Unfortunately the pattern ``` let mut host = MockHost::default(); let mut internal = MockInternal(); let mut host = KernelHost { host: &mut host, internal: &mut internal, } ``` cannot be made into an helper, as the helper would allocate `host` and `internal`, and they would both be returned by the function, which would escape the scope. --- etherlink/kernel_evm/kernel/src/block.rs | 95 +++++++++++++- .../kernel/src/blueprint_storage.rs | 8 ++ .../kernel_evm/kernel/src/delayed_inbox.rs | 12 ++ etherlink/kernel_evm/kernel/src/gas_price.rs | 9 ++ etherlink/kernel_evm/kernel/src/inbox.rs | 81 ++++++++++-- etherlink/kernel_evm/kernel/src/lib.rs | 53 +++++--- etherlink/kernel_evm/kernel/src/simulation.rs | 26 ++++ etherlink/kernel_evm/kernel/src/stage_one.rs | 116 +++++++++++++++--- 8 files changed, 350 insertions(+), 50 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index e62e993ccc2f..2ffdf9ac5522 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -606,8 +606,10 @@ mod tests { TransactionHash, TransactionStatus, TransactionType, TRANSACTION_HASH_SIZE, }; use tezos_ethereum::tx_common::EthereumTransactionCommon; - use tezos_evm_runtime::runtime::KernelHost; + use tezos_evm_runtime::mock_internal::MockInternal; + use tezos_evm_runtime::runtime::{KernelHost, Runtime}; use tezos_smart_rollup_encoding::timestamp::Timestamp; + use tezos_smart_rollup_host::runtime::Runtime as SdkRuntime; use tezos_smart_rollup_mock::MockHost; fn blueprint(transactions: Vec) -> Blueprint { @@ -837,6 +839,11 @@ mod tests { // Test if the invalid transactions are producing receipts fn test_invalid_transactions_receipt_status() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -881,6 +888,11 @@ mod tests { // Test if a valid transaction is producing a receipt with a success status fn test_valid_transactions_receipt_status() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -925,6 +937,11 @@ mod tests { // Test if a valid transaction is producing a receipt with a contract address fn test_valid_transactions_receipt_contract_address() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -980,6 +997,11 @@ mod tests { // Test if several valid transactions can be performed fn test_several_valid_transactions() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1002,6 +1024,11 @@ mod tests { // Test if several valid proposals can produce valid blocks fn test_several_valid_proposals() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1057,6 +1084,11 @@ mod tests { // Test transfers gas consumption consistency fn test_cumulative_transfers_gas_consumption() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let base_gas = U256::from(21000); crate::storage::store_minimum_base_fee_per_gas(&mut host, base_gas).unwrap(); @@ -1120,6 +1152,11 @@ mod tests { // a block production fn test_read_storage_current_block_after_block_production_with_filled_queue() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut evm_account_storage = init_account_storage().unwrap(); @@ -1132,6 +1169,11 @@ mod tests { // Test that the same transaction can not be replayed twice fn test_replay_attack() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1192,6 +1234,11 @@ mod tests { #[test] fn test_blocks_are_indexed() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1258,6 +1305,11 @@ mod tests { fn test_stop_computation() { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let block_constants = first_block(&mut host); let precompiles = precompiles::precompile_set(false); @@ -1336,6 +1388,11 @@ mod tests { #[test] fn invalid_transaction_should_bump_nonce() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut evm_account_storage = init_account_storage().unwrap(); @@ -1408,6 +1465,11 @@ mod tests { #[test] fn test_first_blocks() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; // first block should be 0 let blueprint = almost_empty_blueprint(); @@ -1521,6 +1583,11 @@ mod tests { fn test_reboot_many_tx_one_proposal() { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1607,6 +1674,11 @@ mod tests { fn test_reboot_many_tx_many_proposal() { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, @@ -1690,11 +1762,7 @@ mod tests { matches!(computation_result, ComputationResult::RebootNeeded); // The block is in progress, therefore it is in the safe storage. - let mut mock_internal = MockHost::default(); - let safe_host = SafeStorage { - host: &mut host, - internal: &mut mock_internal, - }; + let safe_host = SafeStorage { host: &mut host }; let bip = read_block_in_progress(&safe_host) .expect("Should be able to read the block in progress") .expect("The reboot context should have a block in progress"); @@ -1723,6 +1791,11 @@ mod tests { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; // ensure we're using the default block fees to test. let block_fees = crate::retrieve_block_fees(&mut host).unwrap(); @@ -1787,6 +1860,11 @@ mod tests { fn test_non_retriable_transaction_are_marked_as_failed() { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), @@ -1910,6 +1988,11 @@ mod tests { // Test if a valid transaction is producing a receipt with a success status fn test_type_propagation() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, DUMMY_BASE_FEE_PER_GAS.into(), diff --git a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs index 110556513841..9eb637714f9b 100644 --- a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs +++ b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs @@ -492,11 +492,19 @@ mod tests { use primitive_types::H256; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_ethereum::transaction::TRANSACTION_HASH_SIZE; + use tezos_evm_runtime::mock_internal::MockInternal; + use tezos_evm_runtime::runtime::KernelHost; use tezos_smart_rollup_encoding::public_key::PublicKey; + use tezos_smart_rollup_host::runtime::Runtime; use tezos_smart_rollup_mock::MockHost; fn test_invalid_sequencer_blueprint_is_removed(enable_dal: bool) { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let delayed_inbox = DelayedInbox::new(&mut host).expect("Delayed inbox should be created"); let delayed_bridge: ContractKt1Hash = diff --git a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs index a31b13b5c57a..e099bea8a87e 100644 --- a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs +++ b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs @@ -381,6 +381,8 @@ mod tests { use crate::current_timestamp; use crate::inbox::Transaction; use primitive_types::{H160, U256}; + use tezos_evm_runtime::mock_internal::MockInternal; + use tezos_evm_runtime::runtime::KernelHost; use tezos_smart_rollup_encoding::timestamp::Timestamp; use crate::inbox::TransactionContent::{Ethereum, EthereumDelayed}; @@ -421,6 +423,11 @@ mod tests { #[test] fn test_delayed_inbox_roundtrip() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut delayed_inbox = DelayedInbox::new(&mut host).expect("Delayed inbox should be created"); @@ -444,6 +451,11 @@ mod tests { #[test] fn test_delayed_inbox_roundtrip_error_non_delayed() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut delayed_inbox = DelayedInbox::new(&mut host).expect("Delayed inbox should be created"); diff --git a/etherlink/kernel_evm/kernel/src/gas_price.rs b/etherlink/kernel_evm/kernel/src/gas_price.rs index eda27c03a276..b08f7dad4659 100644 --- a/etherlink/kernel_evm/kernel/src/gas_price.rs +++ b/etherlink/kernel_evm/kernel/src/gas_price.rs @@ -167,6 +167,10 @@ mod test { use super::*; use proptest::prelude::*; use std::collections::VecDeque; + use tezos_evm_runtime::{ + mock_internal::MockInternal, + runtime::{KernelHost, Runtime}, + }; use tezos_smart_rollup_mock::MockHost; proptest! { @@ -198,6 +202,11 @@ mod test { #[test] fn gas_price_responds_to_load() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let timestamp = 0_i64; let mut block_fees = BlockFees::new(U256::zero(), U256::zero(), U256::zero()); diff --git a/etherlink/kernel_evm/kernel/src/inbox.rs b/etherlink/kernel_evm/kernel/src/inbox.rs index a6ca91f450de..bc63e821e4ed 100644 --- a/etherlink/kernel_evm/kernel/src/inbox.rs +++ b/etherlink/kernel_evm/kernel/src/inbox.rs @@ -714,6 +714,8 @@ mod tests { use tezos_crypto_rs::hash::UnknownSignature; use tezos_data_encoding::types::Bytes; use tezos_ethereum::transaction::TRANSACTION_HASH_SIZE; + use tezos_evm_runtime::mock_internal::MockInternal; + use tezos_evm_runtime::runtime::KernelHost; use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; use tezos_smart_rollup_encoding::contract::Contract; use tezos_smart_rollup_encoding::inbox::ExternalMessageFrame; @@ -832,6 +834,11 @@ mod tests { #[test] fn parse_valid_simple_transaction() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let tx_bytes = &hex::decode("f86d80843b9aca00825208940b52d4d3be5d18a7ab5e4476a2f5382bbf2b38d888016345785d8a000080820a95a0d9ef1298c18c88604e3f08e14907a17dfa81b1dc6b37948abe189d8db5cb8a43a06fc7040a71d71d3cb74bd05ead7046b10668ad255da60391c017eea31555f156").unwrap(); let tx = EthereumTransactionCommon::from_bytes(tx_bytes).unwrap(); @@ -842,7 +849,8 @@ mod tests { content: Ethereum(tx.clone()), }))); - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))); let inbox_content = read_proxy_inbox( &mut host, @@ -863,6 +871,11 @@ mod tests { fn parse_valid_chunked_transaction() { let address = smart_rollup_address(); let mut host = MockHost::with_address(&address); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let (data, tx) = large_transaction(); let tx_hash: [u8; TRANSACTION_HASH_SIZE] = Keccak256::digest(data.clone()).into(); @@ -870,7 +883,8 @@ mod tests { let inputs = make_chunked_transactions(tx_hash, data); for input in inputs { - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))) + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))) } let inbox_content = read_proxy_inbox( @@ -891,6 +905,11 @@ mod tests { #[test] fn parse_valid_kernel_upgrade() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; // Prepare the upgrade's payload let preimage_hash: [u8; PREIMAGE_HASH_SIZE] = hex::decode( @@ -921,7 +940,7 @@ mod tests { MichelsonOr::Right(MichelsonBytes(kernel_upgrade_payload)); let transfer_metadata = TransferMetadata::new(sender.clone(), source); - host.add_transfer(payload, &transfer_metadata); + host.host.add_transfer(payload, &transfer_metadata); let _inbox_content = read_proxy_inbox( &mut host, [0; 20], @@ -950,6 +969,11 @@ mod tests { // the first `NewChunkedTransaction` should be considered. fn recreate_chunked_transaction() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let chunk_hashes = vec![[1; TRANSACTION_HASH_SIZE], [2; TRANSACTION_HASH_SIZE]]; let tx_hash = [0; TRANSACTION_HASH_SIZE]; @@ -964,11 +988,11 @@ mod tests { chunk_hashes, }); - host.add_external(Bytes::from(input_to_bytes( + host.host.add_external(Bytes::from(input_to_bytes( SMART_ROLLUP_ADDRESS, new_chunk1, ))); - host.add_external(Bytes::from(input_to_bytes( + host.host.add_external(Bytes::from(input_to_bytes( SMART_ROLLUP_ADDRESS, new_chunk2, ))); @@ -992,6 +1016,11 @@ mod tests { // not make the kernel fail. fn out_of_bound_chunk_is_ignored() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let (data, _tx) = large_transaction(); let tx_hash = ZERO_TX_HASH; @@ -1001,7 +1030,8 @@ mod tests { let chunk = inputs.remove(0); // Announce a chunked transaction. - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, new_chunk))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, new_chunk))); // Give a chunk with an invalid `i`. let out_of_bound_i = 42; @@ -1019,7 +1049,8 @@ mod tests { }), _ => panic!("Expected a transaction chunk"), }; - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk))); let _inbox_content = read_proxy_inbox( &mut host, @@ -1043,6 +1074,11 @@ mod tests { // not make the kernel fail. fn unknown_chunk_is_ignored() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let (data, _tx) = large_transaction(); let tx_hash = ZERO_TX_HASH; @@ -1056,7 +1092,8 @@ mod tests { _ => panic!("Expected a transaction chunk"), }; - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk))); let _inbox_content = read_proxy_inbox( &mut host, @@ -1095,6 +1132,11 @@ mod tests { // |--> Fails because the chunk is unknown fn transaction_is_complete_when_each_chunk_is_stored() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let (data, tx) = large_transaction(); let tx_hash: [u8; TRANSACTION_HASH_SIZE] = Keccak256::digest(data.clone()).into(); @@ -1107,9 +1149,11 @@ mod tests { let new_chunk = inputs[0].clone(); let chunk0 = inputs[1].clone(); - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, new_chunk))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, new_chunk))); - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk0))); + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, chunk0))); let inbox_content = read_proxy_inbox( &mut host, @@ -1128,7 +1172,8 @@ mod tests { // On the next level, try to re-give the chunks, but this time in full: for input in inputs { - host.add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))) + host.host + .add_external(Bytes::from(input_to_bytes(SMART_ROLLUP_ADDRESS, input))) } let inbox_content = read_proxy_inbox( &mut host, @@ -1153,6 +1198,11 @@ mod tests { let address = smart_rollup_address(); let mut host = MockHost::with_address(&address); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let tx_bytes = &hex::decode("f86d80843b9aca00825208940b52d4d3be5d18a7ab5\ e4476a2f5382bbf2b38d888016345785d8a000080820a95a0d9ef1298c18c88604e3f08e14907a17dfa81b1dc6b37948abe189d8db5cb8a43a06\ @@ -1189,7 +1239,7 @@ mod tests { contents: buffer, }; - host.add_external(framed); + host.host.add_external(framed); let inbox_content = read_proxy_inbox( &mut host, @@ -1209,11 +1259,16 @@ mod tests { #[test] fn empty_inbox_returns_none() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; // Even reading the inbox with only the default elements returns // an empty inbox content. As we test in isolation there is nothing // in the inbox, we mock it by adding a single input. - host.add_external(Bytes::from(vec![])); + host.host.add_external(Bytes::from(vec![])); let inbox_content = read_proxy_inbox( &mut host, SMART_ROLLUP_ADDRESS, diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index 5724f543c201..0d7422a258b5 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -402,6 +402,7 @@ mod tests { tx_common::EthereumTransactionCommon, }; use tezos_evm_runtime::mock_internal::MockInternal; + use tezos_evm_runtime::runtime::KernelHost; use tezos_evm_runtime::safe_storage::SafeStorage; use tezos_smart_rollup::michelson::ticket::FA2_1Ticket; @@ -521,6 +522,11 @@ mod tests { fn test_reboot_during_block_production() { // init host let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; crate::storage::store_minimum_base_fee_per_gas( &mut host, @@ -626,6 +632,11 @@ mod tests { fn load_block_fees_new() { // Arrange let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; // Act let result = crate::retrieve_block_fees(&mut host); @@ -648,6 +659,11 @@ mod tests { // Arrange let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let min_base_fee = U256::from(17); let curr_base_fee = U256::from(20); @@ -672,11 +688,14 @@ mod tests { #[test] fn test_xtz_withdrawal_applied() { // init host - let mut mock_host = MockHost::default(); + let mut host = MockHost::default(); let mut internal = MockInternal(); + let mut mock_host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut safe_storage = SafeStorage { host: &mut mock_host, - internal: &mut internal, }; safe_storage .store_write_all( @@ -687,7 +706,7 @@ mod tests { store_chain_id(&mut safe_storage, DUMMY_CHAIN_ID).unwrap(); // run level in order to initialize outbox counter (by SOL message) - let level = safe_storage.host.run_level(|_| ()); + let level = safe_storage.host.host.run_level(|_| ()); // provision sender account let sender = H160::from_str("af1276cbb260bb13deddb4209ae99ae6e497f446").unwrap(); @@ -752,14 +771,14 @@ mod tests { contents, }; - safe_storage.host.add_external(message); + safe_storage.host.host.add_external(message); // run kernel twice to get to the stage with block creation: main(&mut safe_storage).expect("Kernel error"); main(&mut safe_storage).expect("Kernel error"); // verify outbox is not empty - let outbox = safe_storage.host.outbox_at(level + 1); + let outbox = safe_storage.host.host.outbox_at(level + 1); assert!(!outbox.is_empty()); // check message contents: @@ -796,11 +815,14 @@ mod tests { fn send_fa_deposit(enable_fa_bridge: bool) -> Option { // init host - let mut mock_host = MockHost::default(); + let mut host = MockHost::default(); let mut internal = MockInternal(); + let mut mock_host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut safe_storage = SafeStorage { host: &mut mock_host, - internal: &mut internal, }; // enable FA bridge feature @@ -843,7 +865,7 @@ mod tests { "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5", "tz1P2Po7YM526ughEsRbY4oR9zaUPDZjxFrb", ); - safe_storage.host.add_transfer(payload, &metadata); + safe_storage.host.host.add_transfer(payload, &metadata); // run kernel main(&mut safe_storage).expect("Kernel error"); @@ -870,7 +892,7 @@ mod tests { let deposit = FaDeposit { amount: 42.into(), proxy: Some(H160([2u8; 20])), - inbox_level: safe_storage.host.level(), // level not yet advanced + inbox_level: safe_storage.host.host.level(), // level not yet advanced inbox_msg_id: 2, receiver: H160([1u8; 20]), ticket_hash: ticket_hash(&ticket).unwrap(), @@ -894,11 +916,14 @@ mod tests { fn send_fa_withdrawal(enable_fa_bridge: bool) -> Vec> { // init host - let mut mock_host = MockHost::default(); + let mut host = MockHost::default(); let mut internal = MockInternal(); + let mut mock_host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut safe_storage = SafeStorage { host: &mut mock_host, - internal: &mut internal, }; // enable FA bridge feature @@ -909,7 +934,7 @@ mod tests { } // run level in order to initialize outbox counter (by SOL message) - let level = safe_storage.host.run_level(|_| ()); + let level = safe_storage.host.host.run_level(|_| ()); // provision sender account let sender = H160::from_str("af1276cbb260bb13deddb4209ae99ae6e497f446").unwrap(); @@ -991,14 +1016,14 @@ mod tests { contents, }; - safe_storage.host.add_external(message); + safe_storage.host.host.add_external(message); // run kernel main(&mut safe_storage).expect("Kernel error"); // QUESTION: looks like to get to the stage with block creation we need to call main twice (maybe check blueprint instead?) [2] main(&mut safe_storage).expect("Kernel error"); - safe_storage.host.outbox_at(level + 1) + safe_storage.host.host.outbox_at(level + 1) } #[test] diff --git a/etherlink/kernel_evm/kernel/src/simulation.rs b/etherlink/kernel_evm/kernel/src/simulation.rs index e036fdba4ccd..285fd0892f34 100644 --- a/etherlink/kernel_evm/kernel/src/simulation.rs +++ b/etherlink/kernel_evm/kernel/src/simulation.rs @@ -814,6 +814,7 @@ mod tests { use tezos_ethereum::{ block::BlockConstants, transaction::TransactionType, tx_signature::TxSignature, }; + use tezos_evm_runtime::{mock_internal::MockInternal, runtime::KernelHost}; use tezos_smart_rollup_mock::MockHost; use crate::{ @@ -954,6 +955,11 @@ mod tests { fn simulation_result() { // setup let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let new_address = create_contract(&mut host); // run evaluation num @@ -1012,6 +1018,11 @@ mod tests { fn evaluation_result_no_gas() { // setup let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let new_address = create_contract(&mut host); // run evaluation num @@ -1080,6 +1091,11 @@ mod tests { fn parse_simulation2() { // setup let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let new_address = create_contract(&mut host); let to = Some(new_address); @@ -1210,6 +1226,11 @@ mod tests { #[test] fn test_tx_validation_gas_price() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let block_fees = crate::retrieve_block_fees(&mut host).unwrap(); let gas_price = U256::one(); let tx_data = vec![]; @@ -1269,6 +1290,11 @@ mod tests { #[test] fn test_tx_validation_da_fees_not_covered() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let block_fees = crate::retrieve_block_fees(&mut host).unwrap(); let transaction = EthereumTransactionCommon::new( diff --git a/etherlink/kernel_evm/kernel/src/stage_one.rs b/etherlink/kernel_evm/kernel/src/stage_one.rs index af213b949a84..56d0413b3b7c 100644 --- a/etherlink/kernel_evm/kernel/src/stage_one.rs +++ b/etherlink/kernel_evm/kernel/src/stage_one.rs @@ -170,6 +170,7 @@ mod tests { use primitive_types::U256; use tezos_crypto_rs::hash::HashTrait; use tezos_data_encoding::types::Bytes; + use tezos_evm_runtime::{mock_internal::MockInternal, runtime::KernelHost}; use tezos_smart_rollup::{ michelson::{ ticket::FA2_1Ticket, MichelsonBytes, MichelsonOption, MichelsonOr, @@ -189,6 +190,11 @@ mod tests { fn dummy_sequencer_config(enable_dal: bool) -> Configuration { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let delayed_inbox = DelayedInbox::new(&mut host).expect("Delayed inbox should be created"); let delayed_bridge: ContractKt1Hash = @@ -300,7 +306,13 @@ mod tests { #[test] fn test_parsing_proxy_transaction() { let mut host = MockHost::default(); - host.add_external(Bytes::from(hex::decode(DUMMY_TRANSACTION).unwrap())); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host + .add_external(Bytes::from(hex::decode(DUMMY_TRANSACTION).unwrap())); let mut conf = dummy_proxy_configuration(); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); @@ -316,9 +328,17 @@ mod tests { #[test] fn test_parsing_proxy_chunked_transaction() { let mut host = MockHost::default(); - host.add_external(Bytes::from(hex::decode(DUMMY_NEW_CHUNKED_TX).unwrap())); - host.add_external(Bytes::from(hex::decode(DUMMY_CHUNK1).unwrap())); - host.add_external(Bytes::from(hex::decode(DUMMY_CHUNK2).unwrap())); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host + .add_external(Bytes::from(hex::decode(DUMMY_NEW_CHUNKED_TX).unwrap())); + host.host + .add_external(Bytes::from(hex::decode(DUMMY_CHUNK1).unwrap())); + host.host + .add_external(Bytes::from(hex::decode(DUMMY_CHUNK2).unwrap())); let mut conf = dummy_proxy_configuration(); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); @@ -333,7 +353,13 @@ mod tests { fn test_sequencer_reject_proxy_transactions(enable_dal: bool) { let mut host = MockHost::default(); - host.add_external(Bytes::from(hex::decode(DUMMY_TRANSACTION).unwrap())); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host + .add_external(Bytes::from(hex::decode(DUMMY_TRANSACTION).unwrap())); let mut conf = dummy_sequencer_config(enable_dal); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); @@ -358,9 +384,17 @@ mod tests { fn test_sequencer_reject_proxy_chunked_transactions(enable_dal: bool) { let mut host = MockHost::default(); - host.add_external(Bytes::from(hex::decode(DUMMY_NEW_CHUNKED_TX).unwrap())); - host.add_external(Bytes::from(hex::decode(DUMMY_CHUNK1).unwrap())); - host.add_external(Bytes::from(hex::decode(DUMMY_CHUNK2).unwrap())); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host + .add_external(Bytes::from(hex::decode(DUMMY_NEW_CHUNKED_TX).unwrap())); + host.host + .add_external(Bytes::from(hex::decode(DUMMY_CHUNK1).unwrap())); + host.host + .add_external(Bytes::from(hex::decode(DUMMY_CHUNK2).unwrap())); let mut conf = dummy_sequencer_config(enable_dal); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); @@ -385,7 +419,12 @@ mod tests { fn test_parsing_valid_sequencer_chunk(enable_dal: bool) { let mut host = MockHost::default(); - host.add_external(Bytes::from( + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host.add_external(Bytes::from( hex::decode(DUMMY_BLUEPRINT_CHUNK_NUMBER_10).unwrap(), )); let mut conf = dummy_sequencer_config(enable_dal); @@ -414,7 +453,12 @@ mod tests { fn test_parsing_invalid_sequencer_chunk(enable_dal: bool) { let mut host = MockHost::default(); - host.add_external(Bytes::from( + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host.add_external(Bytes::from( hex::decode(DUMMY_BLUEPRINT_CHUNK_UNPARSABLE).unwrap(), )); let mut conf = dummy_sequencer_config(enable_dal); @@ -441,7 +485,12 @@ mod tests { fn test_proxy_rejects_sequencer_chunk(enable_dal: bool) { let mut host = MockHost::default(); - host.add_external(Bytes::from( + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; + host.host.add_external(Bytes::from( hex::decode(DUMMY_BLUEPRINT_CHUNK_NUMBER_10).unwrap(), )); let mut conf = dummy_sequencer_config(enable_dal); @@ -485,12 +534,18 @@ mod tests { fn test_parsing_delayed_inbox(enable_dal: bool) { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_sequencer_config(enable_dal); let metadata = TransferMetadata::new( delayed_bridge(&conf), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer(dummy_delayed_transaction(), &metadata); + host.host + .add_transfer(dummy_delayed_transaction(), &metadata); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); if read_next_blueprint(&mut host, &mut conf) @@ -518,12 +573,18 @@ mod tests { fn test_parsing_l1_contract_inbox(enable_dal: bool) { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_sequencer_config(enable_dal); let metadata = TransferMetadata::new( ContractKt1Hash::from_b58check(DUMMY_INVALID_TICKETER).unwrap(), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer(dummy_delayed_transaction(), &metadata); + host.host + .add_transfer(dummy_delayed_transaction(), &metadata); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); if read_next_blueprint(&mut host, &mut conf) @@ -552,12 +613,18 @@ mod tests { #[test] fn test_parsing_delayed_inbox_rejected_in_proxy() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_proxy_configuration(); let metadata = TransferMetadata::new( ContractKt1Hash::from_b58check(DUMMY_INVALID_TICKETER).unwrap(), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer(dummy_delayed_transaction(), &metadata); + host.host + .add_transfer(dummy_delayed_transaction(), &metadata); fetch_blueprints(&mut host, DEFAULT_SR_ADDRESS, &mut conf).expect("fetch failed"); match read_next_blueprint(&mut host, &mut conf) @@ -573,12 +640,17 @@ mod tests { #[test] fn test_deposit_in_proxy_mode() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_proxy_configuration(); let metadata = TransferMetadata::new( conf.tezos_contracts.ticketer.clone().unwrap(), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer( + host.host.add_transfer( dummy_deposit(conf.tezos_contracts.ticketer.clone().unwrap()), &metadata, ); @@ -600,12 +672,17 @@ mod tests { #[test] fn test_deposit_with_invalid_ticketer() { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_proxy_configuration(); let metadata = TransferMetadata::new( ContractKt1Hash::from_b58check(DUMMY_INVALID_TICKETER).unwrap(), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer( + host.host.add_transfer( dummy_deposit( ContractKt1Hash::from_b58check(DUMMY_INVALID_TICKETER).unwrap(), ), @@ -628,12 +705,17 @@ mod tests { fn test_deposit_in_sequencer_mode(enable_dal: bool) { let mut host = MockHost::default(); + let mut internal = MockInternal(); + let mut host = KernelHost { + host: &mut host, + internal: &mut internal, + }; let mut conf = dummy_sequencer_config(enable_dal); let metadata = TransferMetadata::new( conf.tezos_contracts.ticketer.clone().unwrap(), PublicKeyHash::from_b58check("tz1NiaviJwtMbpEcNqSP6neeoBYj8Brb3QPv").unwrap(), ); - host.add_transfer( + host.host.add_transfer( dummy_deposit(conf.tezos_contracts.ticketer.clone().unwrap()), &metadata, ); -- GitLab