diff --git a/pallets/gear-builtin/src/bls12_381.rs b/pallets/gear-builtin/src/bls12_381.rs index c1ed6aa4638..2d11c18f46a 100644 --- a/pallets/gear-builtin/src/bls12_381.rs +++ b/pallets/gear-builtin/src/bls12_381.rs @@ -30,9 +30,10 @@ const IS_VALIDATED: Validate = ark_scale::is_validated(HOST_CALL); pub struct Actor(PhantomData); impl BuiltinActor for Actor { - type Error = BuiltinActorError; - - fn handle(dispatch: &StoredDispatch, gas_limit: u64) -> (Result, u64) { + fn handle( + dispatch: &StoredDispatch, + gas_limit: u64, + ) -> (Result, u64) { let message = dispatch.message(); let payload = message.payload_bytes(); let (result, gas_spent) = match payload.first().copied() { diff --git a/pallets/gear-builtin/src/lib.rs b/pallets/gear-builtin/src/lib.rs index 4109567c7ad..9e2fc0c61f3 100644 --- a/pallets/gear-builtin/src/lib.rs +++ b/pallets/gear-builtin/src/lib.rs @@ -79,6 +79,8 @@ type CallOf = ::RuntimeCall; const LOG_TARGET: &str = "gear::builtin"; +pub type ActorErrorHandleFn = HandleFn; + /// Built-in actor error type #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, derive_more::Display)] pub enum BuiltinActorError { @@ -113,10 +115,11 @@ impl From for ActorExecutionErrorReplyReason { /// A trait representing an interface of a builtin actor that can handle a message /// from message queue (a `StoredDispatch`) to produce an outcome and gas spent. pub trait BuiltinActor { - type Error; - /// Handles a message and returns a result and the actual gas spent. - fn handle(dispatch: &StoredDispatch, gas_limit: u64) -> (Result, u64); + fn handle( + dispatch: &StoredDispatch, + gas_limit: u64, + ) -> (Result, u64); } /// A marker struct to associate a builtin actor with its unique ID. @@ -125,33 +128,29 @@ pub struct ActorWithId(PhantomData); /// Glue trait to implement `BuiltinCollection` for a tuple of `ActorWithId`. trait BuiltinActorWithId { const ID: u64; - - type Error; - type Actor: BuiltinActor; + type Actor: BuiltinActor; } impl BuiltinActorWithId for ActorWithId { const ID: u64 = ID; - - type Error = A::Error; type Actor = A; } /// A trait defining a method to convert a tuple of `BuiltinActor` types into /// a in-memory collection of builtin actors. -pub trait BuiltinCollection { +pub trait BuiltinCollection { fn collect( - registry: &mut BTreeMap>>, + registry: &mut BTreeMap>, id_converter: &dyn Fn(u64) -> ProgramId, ); } // Assuming as many as 16 builtin actors for the meantime #[impl_for_tuples(16)] -#[tuple_types_custom_trait_bound(BuiltinActorWithId + 'static)] -impl BuiltinCollection for Tuple { +#[tuple_types_custom_trait_bound(BuiltinActorWithId + 'static)] +impl BuiltinCollection for Tuple { fn collect( - registry: &mut BTreeMap>>, + registry: &mut BTreeMap>, id_converter: &dyn Fn(u64) -> ProgramId, ) { for_tuples!( @@ -199,7 +198,7 @@ pub mod pallet { + GetDispatchInfo; /// The builtin actor type. - type Builtins: BuiltinCollection; + type Builtins: BuiltinCollection; /// Weight cost incurred by builtin actors calls. type WeightInfo: WeightInfo; @@ -261,6 +260,7 @@ pub mod pallet { impl BuiltinDispatcherFactory for Pallet { type Error = BuiltinActorError; + type Output = BuiltinRegistry; fn create() -> (BuiltinRegistry, u64) { @@ -272,7 +272,7 @@ impl BuiltinDispatcherFactory for Pallet { } pub struct BuiltinRegistry { - pub registry: BTreeMap>>, + pub registry: BTreeMap>, pub _phantom: sp_std::marker::PhantomData, } impl BuiltinRegistry { @@ -290,13 +290,13 @@ impl BuiltinRegistry { impl BuiltinDispatcher for BuiltinRegistry { type Error = BuiltinActorError; - fn lookup<'a>(&'a self, id: &ProgramId) -> Option<&'a HandleFn> { + fn lookup<'a>(&'a self, id: &ProgramId) -> Option<&'a ActorErrorHandleFn> { self.registry.get(id).map(|f| &**f) } fn run( &self, - f: &HandleFn, + f: &ActorErrorHandleFn, dispatch: StoredDispatch, gas_limit: u64, ) -> Vec { diff --git a/pallets/gear-builtin/src/mock.rs b/pallets/gear-builtin/src/mock.rs index 77d22b0809b..0b585917290 100644 --- a/pallets/gear-builtin/src/mock.rs +++ b/pallets/gear-builtin/src/mock.rs @@ -229,8 +229,6 @@ pallet_gear::impl_config!( // A builtin actor who always returns success (even if not enough gas is provided). pub struct SuccessBuiltinActor {} impl BuiltinActor for SuccessBuiltinActor { - type Error = BuiltinActorError; - fn handle( dispatch: &StoredDispatch, _gas_limit: u64, @@ -256,8 +254,6 @@ impl BuiltinActor for SuccessBuiltinActor { // A builtin actor that always returns an error. pub struct ErrorBuiltinActor {} impl BuiltinActor for ErrorBuiltinActor { - type Error = BuiltinActorError; - fn handle( dispatch: &StoredDispatch, _gas_limit: u64, @@ -279,8 +275,6 @@ impl BuiltinActor for ErrorBuiltinActor { // An honest bulitin actor that actually checks whether the gas is sufficient. pub struct HonestBuiltinActor {} impl BuiltinActor for HonestBuiltinActor { - type Error = BuiltinActorError; - fn handle( dispatch: &StoredDispatch, gas_limit: u64, diff --git a/pallets/gear-builtin/src/proxy.rs b/pallets/gear-builtin/src/proxy.rs index 0a68ca2c5c2..06beaa17a01 100644 --- a/pallets/gear-builtin/src/proxy.rs +++ b/pallets/gear-builtin/src/proxy.rs @@ -75,9 +75,10 @@ where ::ProxyType: From, CallOf: From>, { - type Error = BuiltinActorError; - - fn handle(dispatch: &StoredDispatch, gas_limit: u64) -> (Result, u64) { + fn handle( + dispatch: &StoredDispatch, + gas_limit: u64, + ) -> (Result, u64) { let Ok(request) = Request::decode(&mut dispatch.payload_bytes()) else { return (Err(BuiltinActorError::DecodingError), 0); }; diff --git a/pallets/gear-builtin/src/staking.rs b/pallets/gear-builtin/src/staking.rs index a5a24370cd5..913640203da 100644 --- a/pallets/gear-builtin/src/staking.rs +++ b/pallets/gear-builtin/src/staking.rs @@ -104,9 +104,10 @@ where T::AccountId: Origin, CallOf: From>, { - type Error = BuiltinActorError; - - fn handle(dispatch: &StoredDispatch, gas_limit: u64) -> (Result, u64) { + fn handle( + dispatch: &StoredDispatch, + gas_limit: u64, + ) -> (Result, u64) { let message = dispatch.message(); let origin = dispatch.source(); let mut payload = message.payload_bytes(); diff --git a/pallets/gear-builtin/src/tests/bad_builtin_ids.rs b/pallets/gear-builtin/src/tests/bad_builtin_ids.rs index bef2567d7d2..37dd5e42d69 100644 --- a/pallets/gear-builtin/src/tests/bad_builtin_ids.rs +++ b/pallets/gear-builtin/src/tests/bad_builtin_ids.rs @@ -99,8 +99,6 @@ pallet_gear::impl_config!( pub struct SomeBuiltinActor {} impl BuiltinActor for SomeBuiltinActor { - type Error = BuiltinActorError; - fn handle( _dispatch: &StoredDispatch, _gas_limit: u64, diff --git a/pallets/gear-eth-bridge/src/builtin.rs b/pallets/gear-eth-bridge/src/builtin.rs index 68223d976d0..32c887fe407 100644 --- a/pallets/gear-eth-bridge/src/builtin.rs +++ b/pallets/gear-eth-bridge/src/builtin.rs @@ -39,9 +39,10 @@ impl BuiltinActor for Actor where T::AccountId: Origin, { - type Error = BuiltinActorError; - - fn handle(dispatch: &StoredDispatch, gas_limit: u64) -> (Result, u64) { + fn handle( + dispatch: &StoredDispatch, + gas_limit: u64, + ) -> (Result, u64) { if !dispatch.value().is_zero() { return ( Err(BuiltinActorError::Custom(LimitedStr::from_small_str(