Skip to content

Commit

Permalink
Always compile install_actor but disable at runtime behind feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Nov 21, 2023
1 parent e4c777d commit a57a4ca
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 59 deletions.
1 change: 0 additions & 1 deletion fvm/src/gas/price_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ impl PriceList {
}

/// Returns the gas required for installing an actor.
#[cfg(feature = "m2-native")]
pub fn on_install_actor(&self, wasm_size: usize) -> GasCharge {
GasCharge::new(
"OnInstallActor",
Expand Down
40 changes: 17 additions & 23 deletions fvm/src/kernel/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,23 @@ where
.create_actor(code_id, actor_id, delegated_address)
}

fn install_actor(&mut self, code_id: Cid) -> Result<()> {
let start = GasTimer::start();
let size = self
.call_manager
.engine()
.preload(self.call_manager.blockstore(), &[code_id])
.context("failed to install actor")
.or_illegal_argument()?;

let t = self
.call_manager
.charge_gas(self.call_manager.price_list().on_install_actor(size))?;
t.stop_with(start);

Ok(())
}

fn get_builtin_actor_type(&self, code_cid: &Cid) -> Result<u32> {
let t = self
.call_manager
Expand Down Expand Up @@ -888,29 +905,6 @@ where
}
}

impl<C> InstallActorOps for DefaultKernel<C>
where
C: CallManager,
{
#[cfg(feature = "m2-native")]
fn install_actor(&mut self, code_id: Cid) -> Result<()> {
let start = GasTimer::start();
let size = self
.call_manager
.engine()
.preload(self.call_manager.blockstore(), &[code_id])
.context("failed to install actor")
.or_illegal_argument()?;

let t = self
.call_manager
.charge_gas(self.call_manager.price_list().on_install_actor(size))?;
t.stop_with(start);

Ok(())
}
}

impl<C> DebugOps for DefaultKernel<C>
where
C: CallManager,
Expand Down
10 changes: 0 additions & 10 deletions fvm/src/kernel/filecoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,6 @@ where
}
}

impl<C> InstallActorOps for DefaultFilecoinKernel<DefaultKernel<C>>
where
C: CallManager,
{
#[cfg(feature = "m2-native")]
fn install_actor(&mut self, code_id: Cid) -> Result<()> {
self.0.install_actor(code_id)
}
}

impl<C> ConstructKernel<C> for DefaultFilecoinKernel<DefaultKernel<C>>
where
C: CallManager,
Expand Down
10 changes: 2 additions & 8 deletions fvm/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub trait Kernel:
SyscallHandler<Self>
+ ConstructKernel<<Self as Kernel>::CallManager>
+ ActorOps
+ InstallActorOps
+ IpldBlockOps
+ CircSupplyOps
+ CryptoOps
Expand Down Expand Up @@ -234,6 +233,8 @@ pub trait ActorOps {
delegated_address: Option<Address>,
) -> Result<()>;

fn install_actor(&mut self, code_cid: Cid) -> Result<()>;

/// Returns the actor's "type" (if builitin) or 0 (if not).
fn get_builtin_actor_type(&self, code_cid: &Cid) -> Result<u32>;

Expand All @@ -244,13 +245,6 @@ pub trait ActorOps {
fn balance_of(&self, actor_id: ActorID) -> Result<TokenAmount>;
}

// we are not delegating this trait as ambassador seems to not support feature flags
pub trait InstallActorOps {
/// Installs actor code pointed by cid
#[cfg(feature = "m2-native")]
fn install_actor(&mut self, code_cid: Cid) -> Result<()>;
}

/// Operations to query the circulating supply.
#[delegatable_trait]
pub trait CircSupplyOps {
Expand Down
1 change: 0 additions & 1 deletion fvm/src/syscalls/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ pub fn get_code_cid_for_type(
context.memory.write_cid(&k, obuf_off, obuf_len)
}

#[cfg(feature = "m2-native")]
pub fn install_actor(
context: Context<'_, impl Kernel>,
typ_off: u32, // Cid
Expand Down
5 changes: 3 additions & 2 deletions fvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ where
linker.bind("actor", "balance_of", actor::balance_of)?;

// Only wire this syscall when M2 native is enabled.
#[cfg(feature = "m2-native")]
linker.bind("actor", "install_actor", actor::install_actor)?;
if cfg!(feature = "m2-native") {
linker.bind("actor", "install_actor", actor::install_actor)?;
}

linker.bind("crypto", "verify_signature", crypto::verify_signature)?;
linker.bind(
Expand Down
1 change: 0 additions & 1 deletion sdk/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ pub fn upgrade_actor(new_code_cid: &Cid, params: Option<IpldBlock>) -> SyscallRe

/// Installs or ensures an actor code CID is valid and loaded.
/// Note: this is a privileged syscall, restricted to the init actor.
#[cfg(feature = "m2-native")]
pub fn install_actor(code_cid: &Cid) -> SyscallResult<()> {
let cid = code_cid.to_bytes();
unsafe { sys::actor::install_actor(cid.as_ptr()) }
Expand Down
1 change: 0 additions & 1 deletion sdk/src/sys/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ super::fvm_syscalls! {

/// Installs and ensures actor code is valid and loaded.
/// **Privileged:** May only be called by the init actor.
#[cfg(feature = "m2-native")]
pub fn install_actor(cid_off: *const u8) -> Result<()>;

/// Gets the balance of the specified actor.
Expand Down
16 changes: 4 additions & 12 deletions testing/conformance/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ where
self.0.create_actor(code_id, actor_id, delegated_address)
}

fn install_actor(&mut self, _code_id: Cid) -> Result<()> {
Ok(())
}

fn get_builtin_actor_type(&self, code_cid: &Cid) -> Result<u32> {
self.0.get_builtin_actor_type(code_cid)
}
Expand All @@ -325,18 +329,6 @@ where
}
}

impl<M, C, K> InstallActorOps for TestKernel<K>
where
M: Machine,
C: CallManager<Machine = TestMachine<M>>,
K: Kernel<CallManager = C>,
{
#[cfg(feature = "m2-native")]
fn install_actor(&mut self, _code_id: Cid) -> Result<()> {
Ok(())
}
}

impl<M, C, K> IpldBlockOps for TestKernel<K>
where
M: Machine,
Expand Down

0 comments on commit a57a4ca

Please sign in to comment.