diff --git a/fvm/src/kernel/default.rs b/fvm/src/kernel/default.rs index 2a706b3c8..09ae8bf3d 100644 --- a/fvm/src/kernel/default.rs +++ b/fvm/src/kernel/default.rs @@ -65,6 +65,7 @@ where C: CallManager, { type CallManager = C; + type Limiter = <::Machine as Machine>::Limiter; fn into_inner(self) -> (Self::CallManager, BlockRegistry) where @@ -264,6 +265,10 @@ where Err(err) => Err(err), } } + + fn limiter_mut(&mut self) -> &mut Self::Limiter { + self.call_manager.limiter_mut() + } } impl DefaultKernel @@ -949,17 +954,6 @@ where } } -impl LimiterOps for DefaultKernel -where - C: CallManager, -{ - type Limiter = <::Machine as Machine>::Limiter; - - fn limiter_mut(&mut self) -> &mut Self::Limiter { - self.call_manager.limiter_mut() - } -} - impl EventOps for DefaultKernel where C: CallManager, diff --git a/fvm/src/kernel/filecoin.rs b/fvm/src/kernel/filecoin.rs index 04c18d579..d63b78567 100644 --- a/fvm/src/kernel/filecoin.rs +++ b/fvm/src/kernel/filecoin.rs @@ -98,7 +98,6 @@ pub trait FilecoinKernel: Kernel { #[delegate(NetworkOps)] #[delegate(RandomnessOps)] #[delegate(SelfOps)] -#[delegate(LimiterOps)] pub struct DefaultFilecoinKernel(pub K) where K: Kernel; @@ -251,6 +250,7 @@ where C: CallManager, { type CallManager = C; + type Limiter = as Kernel>::Limiter; fn into_inner(self) -> (Self::CallManager, BlockRegistry) where @@ -303,6 +303,10 @@ where read_only, )) } + + fn limiter_mut(&mut self) -> &mut Self::Limiter { + self.0.call_manager.limiter_mut() + } } fn catch_and_log_panic Result + UnwindSafe, R>(context: &str, f: F) -> Result { diff --git a/fvm/src/kernel/mod.rs b/fvm/src/kernel/mod.rs index 3d1879565..b0fe0055b 100644 --- a/fvm/src/kernel/mod.rs +++ b/fvm/src/kernel/mod.rs @@ -33,23 +33,11 @@ pub struct CallResult { /// /// Actors may call into the kernel via the syscalls defined in the [`syscalls`][crate::syscalls] /// module. -pub trait Kernel: - SyscallHandler - + ActorOps - + IpldBlockOps - + CryptoOps - + DebugOps - + EventOps - + GasOps - + MessageOps - + NetworkOps - + RandomnessOps - + SelfOps - + LimiterOps - + 'static -{ +pub trait Kernel: GasOps + SyscallHandler + 'static { /// The [`Kernel`]'s [`CallManager`] is type CallManager: CallManager; + /// The [`Kernel`]'s memory allocation tracker. + type Limiter: MemoryLimiter; /// Consume the [`Kernel`] and return the underlying [`CallManager`] and [`BlockRegistry`]. fn into_inner(self) -> (Self::CallManager, BlockRegistry) @@ -101,6 +89,9 @@ pub trait Kernel: new_code_cid: Cid, params_id: BlockId, ) -> Result; + + /// Give access to the limiter of the underlying call manager. + fn limiter_mut(&mut self) -> &mut Self::Limiter; } pub trait SyscallHandler: Sized { @@ -293,18 +284,6 @@ pub trait DebugOps { fn store_artifact(&self, name: &str, data: &[u8]) -> Result<()>; } -/// Track and limit memory expansion. -/// -/// This interface is not one of the operations the kernel provides to actors. -/// It's only part of the kernel out of necessity to pass it through to the -/// call manager which tracks the limits across the whole execution stack. -#[delegatable_trait] -pub trait LimiterOps { - type Limiter: MemoryLimiter; - /// Give access to the limiter of the underlying call manager. - fn limiter_mut(&mut self) -> &mut Self::Limiter; -} - /// Eventing APIs. #[delegatable_trait] pub trait EventOps { @@ -322,17 +301,16 @@ pub trait EventOps { #[doc(hidden)] pub use { ambassador_impl_CryptoOps, ambassador_impl_DebugOps, ambassador_impl_EventOps, - ambassador_impl_GasOps, ambassador_impl_IpldBlockOps, ambassador_impl_LimiterOps, - ambassador_impl_MessageOps, ambassador_impl_NetworkOps, ambassador_impl_RandomnessOps, - ambassador_impl_SelfOps, + ambassador_impl_GasOps, ambassador_impl_IpldBlockOps, ambassador_impl_MessageOps, + ambassador_impl_NetworkOps, ambassador_impl_RandomnessOps, ambassador_impl_SelfOps, }; /// Import this module (with a glob) if you're implementing a kernel, _especially_ if you want to /// use ambassador to delegate the implementation. pub mod prelude { pub use super::{ - ActorOps, CryptoOps, DebugOps, EventOps, GasOps, IpldBlockOps, LimiterOps, MessageOps, - NetworkOps, RandomnessOps, SelfOps, + ActorOps, CryptoOps, DebugOps, EventOps, GasOps, IpldBlockOps, MessageOps, NetworkOps, + RandomnessOps, SelfOps, }; pub use super::{Block, BlockId, BlockRegistry, BlockStat, CallResult, Kernel, SyscallHandler}; pub use crate::gas::{Gas, GasTimer, PriceList}; @@ -355,8 +333,8 @@ pub mod prelude { pub use { ambassador_impl_ActorOps, ambassador_impl_CryptoOps, ambassador_impl_DebugOps, ambassador_impl_EventOps, ambassador_impl_GasOps, ambassador_impl_IpldBlockOps, - ambassador_impl_LimiterOps, ambassador_impl_MessageOps, ambassador_impl_NetworkOps, - ambassador_impl_RandomnessOps, ambassador_impl_SelfOps, + ambassador_impl_MessageOps, ambassador_impl_NetworkOps, ambassador_impl_RandomnessOps, + ambassador_impl_SelfOps, }; } diff --git a/fvm/src/syscalls/mod.rs b/fvm/src/syscalls/mod.rs index 89b551ff6..9541c1a0d 100644 --- a/fvm/src/syscalls/mod.rs +++ b/fvm/src/syscalls/mod.rs @@ -7,7 +7,10 @@ use wasmtime::{AsContextMut, ExternType, Global, Linker, Memory, Module, Val}; use crate::call_manager::{backtrace, CallManager}; use crate::gas::{Gas, GasInstant, GasTimer}; use crate::kernel::filecoin::DefaultFilecoinKernel; -use crate::kernel::{ExecutionError, SyscallHandler}; +use crate::kernel::{ + ActorOps, CryptoOps, DebugOps, EventOps, ExecutionError, GasOps, IpldBlockOps, MessageOps, + NetworkOps, RandomnessOps, SelfOps, SyscallHandler, +}; use crate::machine::limiter::MemoryLimiter; use crate::{DefaultKernel, Kernel}; @@ -238,7 +241,17 @@ use self::bind::BindSyscall; impl SyscallHandler for DefaultKernel where - K: Kernel, + K: Kernel + + ActorOps + + IpldBlockOps + + CryptoOps + + DebugOps + + EventOps + + GasOps + + MessageOps + + NetworkOps + + RandomnessOps + + SelfOps, { fn bind_syscalls( &self, diff --git a/testing/conformance/src/vm.rs b/testing/conformance/src/vm.rs index e849857d1..6c0642124 100644 --- a/testing/conformance/src/vm.rs +++ b/testing/conformance/src/vm.rs @@ -170,7 +170,6 @@ where #[delegate(NetworkOps)] #[delegate(RandomnessOps)] #[delegate(SelfOps)] -#[delegate(LimiterOps)] pub struct TestKernel>>>( pub K, ); @@ -182,6 +181,7 @@ where K: Kernel, { type CallManager = K::CallManager; + type Limiter = K::Limiter; fn into_inner(self) -> (Self::CallManager, BlockRegistry) where @@ -237,6 +237,10 @@ where fn upgrade_actor(&mut self, new_code_cid: Cid, params_id: BlockId) -> Result { self.0.upgrade_actor::(new_code_cid, params_id) } + + fn limiter_mut(&mut self) -> &mut Self::Limiter { + self.0.limiter_mut() + } } impl SyscallHandler> for TestKernel