Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow calling InvokeEVM on accounts #1081

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions actors/account/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_actor_utils::receiver::UniversalReceiverParams;
use fvm_shared::address::{Address, Protocol};
use fvm_shared::crypto::signature::SignatureType::{Secp256k1, BLS};
use fvm_shared::crypto::signature::{Signature, SignatureType};
Expand Down Expand Up @@ -36,6 +35,7 @@ pub enum Method {
// AuthenticateMessage = 3,
AuthenticateMessageExported = frc42_dispatch::method_hash!("AuthenticateMessage"),
UniversalReceiverHook = frc42_dispatch::method_hash!("Receive"),
InvokeEVM = frc42_dispatch::method_hash!("InvokeEVM"),
}

/// Account Actor
Expand Down Expand Up @@ -91,15 +91,6 @@ impl Actor {

Ok(())
}

// Always succeeds, accepting any transfers.
pub fn universal_receiver_hook(
rt: &mut impl Runtime,
_params: UniversalReceiverParams,
) -> Result<(), ActorError> {
rt.validate_immediate_caller_accept_any()?;
Ok(())
}
}

impl ActorCode for Actor {
Expand All @@ -108,6 +99,7 @@ impl ActorCode for Actor {
Constructor => constructor,
PubkeyAddress => pubkey_address,
AuthenticateMessageExported => authenticate_message,
UniversalReceiverHook => universal_receiver_hook,
UniversalReceiverHook => (),
InvokeEVM => (),
}
}
14 changes: 3 additions & 11 deletions actors/ethaccount/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod types;

use fvm_actor_utils::receiver::UniversalReceiverParams;
use fvm_shared::address::{Payload, Protocol};
use fvm_shared::crypto::hash::SupportedHashes::Keccak256;
use fvm_shared::error::ExitCode;
Expand All @@ -25,6 +24,7 @@ pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
AuthenticateMessageExported = frc42_dispatch::method_hash!("AuthenticateMessage"),
UniversalReceiverHook = frc42_dispatch::method_hash!("Receive"),
InvokeEVM = frc42_dispatch::method_hash!("InvokeEVM"),
}

/// Ethereum Account actor.
Expand Down Expand Up @@ -126,22 +126,14 @@ impl EthAccountActor {

Ok(())
}

// Always succeeds, accepting any transfers.
pub fn universal_receiver_hook(
rt: &mut impl Runtime,
_params: UniversalReceiverParams,
) -> Result<(), ActorError> {
rt.validate_immediate_caller_accept_any()?;
Ok(())
}
}

impl ActorCode for EthAccountActor {
type Methods = Method;
actor_dispatch! {
Constructor => constructor,
AuthenticateMessageExported => authenticate_message,
UniversalReceiverHook => universal_receiver_hook,
UniversalReceiverHook => (),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this skip decoding the ignore parameters too (#1066)? 🎉

Could you revert this change in the tests to demonstrate this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this skip decoding the ignore parameters too (#1066)? 🎉

Yes.

Could you revert this change in the tests to demonstrate this?

Can do.

InvokeEVM => (),
}
}
26 changes: 22 additions & 4 deletions runtime/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::ActorError;
/// ```
#[macro_export]
macro_rules! actor_dispatch {
($($(#[$m:meta])* $method:ident => $func:ident,)*) => {
($($(#[$m:meta])* $method:ident => $func:tt,)*) => {
fn invoke_method<RT>(
rt: &mut RT,
method: MethodNum,
Expand All @@ -36,16 +36,25 @@ macro_rules! actor_dispatch {
{
restrict_internal_api(rt, method)?;
match FromPrimitive::from_u64(method) {
$($(#[$m])* Some(Self::Methods::$method) => $crate::dispatch(rt, Self::$func, &args),)*
$($(#[$m])* Some(Self::Methods::$method) => {
$crate::actor_dispatch!(@dispatch (rt args) $func)
}),*
None => Err(actor_error!(unhandled_message; "invalid method: {}", method)),
}
}
};
(@dispatch ($rt:ident $args:ident) ()) => {{
$rt.validate_immediate_caller_accept_any()?;
Ok(None)
}};
(@dispatch ($rt:ident $args:ident) $func:ident) => {
$crate::dispatch($rt, Self::$func, &$args)
};
}

#[macro_export]
macro_rules! actor_dispatch_unrestricted {
($($(#[$m:meta])* $method:ident => $func:ident,)*) => {
($($(#[$m:meta])* $method:ident => $func:tt,)*) => {
fn invoke_method<RT>(
rt: &mut RT,
method: MethodNum,
Expand All @@ -56,11 +65,20 @@ macro_rules! actor_dispatch_unrestricted {
RT::Blockstore: Clone,
{
match FromPrimitive::from_u64(method) {
$($(#[$m])* Some(Self::Methods::$method) => $crate::dispatch(rt, Self::$func, &args),)*
$($(#[$m])* Some(Self::Methods::$method) => {
$crate::actor_dispatch!(@dispatch (rt args) $func)
}),*
None => Err(actor_error!(unhandled_message; "invalid method: {}", method)),
}
}
};
(@dispatch ($rt:ident $args:ident) ()) => {{
$rt.validate_immediate_caller_accept_any()?;
Ok(None)
}};
(@dispatch ($rt:ident $args:ident) $func:ident) => {
$crate::dispatch($rt, Self::$func, &$args)
};
}

pub trait Dispatch<'de, RT> {
Expand Down