From acddf02fa28130b1e643d4961f04ded996c54b33 Mon Sep 17 00:00:00 2001 From: Gregory Sobol Date: Thu, 23 Jan 2025 18:26:21 +0700 Subject: [PATCH] chore(core-processor): remove ActorExecutionError::UnsupportedMessage (#4453) --- core-processor/src/common.rs | 9 +------ core-processor/src/executor.rs | 12 ++------- core-processor/src/ext.rs | 4 +-- core/src/message/context.rs | 45 ++++++++++++--------------------- lazy-pages/src/common.rs | 1 - pallets/gear-builtin/src/lib.rs | 9 +------ pallets/gear/src/tests.rs | 2 +- utils/wasm-gen/src/tests.rs | 3 +-- 8 files changed, 23 insertions(+), 62 deletions(-) diff --git a/core-processor/src/common.rs b/core-processor/src/common.rs index 84debf9be2b..0e612944a1a 100644 --- a/core-processor/src/common.rs +++ b/core-processor/src/common.rs @@ -454,13 +454,6 @@ pub enum ActorExecutionErrorReplyReason { /// Trap explanation #[display(fmt = "{_0}")] Trap(TrapExplanation), - // TODO: move this to SystemExecutionError after runtime upgrade, - // if wait-list does not contain messages with total outgoing bytes more than `OutgoingBytesLimit` #3751. - /// Message is not supported now - #[display( - fmt = "Message is not supported: outgoing bytes limit is exceeded after runtime-upgrade" - )] - UnsupportedMessage, } impl ActorExecutionErrorReplyReason { @@ -478,7 +471,7 @@ impl ActorExecutionErrorReplyReason { TrapExplanation::StackLimitExceeded => SimpleExecutionError::StackLimitExceeded, TrapExplanation::Unknown => SimpleExecutionError::UnreachableInstruction, }, - Self::Environment | Self::UnsupportedMessage => SimpleExecutionError::Unsupported, + Self::Environment => SimpleExecutionError::Unsupported, } } } diff --git a/core-processor/src/executor.rs b/core-processor/src/executor.rs index b5fd36e29f6..941056acc2d 100644 --- a/core-processor/src/executor.rs +++ b/core-processor/src/executor.rs @@ -90,14 +90,7 @@ where .map_err(SystemExecutionError::from)?; // Creating message context. - let Some(message_context) = MessageContext::new(dispatch.clone(), program.id, msg_ctx_settings) - else { - return Err(ActorExecutionError { - gas_amount: gas_counter.to_amount(), - reason: ActorExecutionErrorReplyReason::UnsupportedMessage, - } - .into()); - }; + let message_context = MessageContext::new(dispatch.clone(), program.id, msg_ctx_settings); // Creating value counter. // @@ -304,8 +297,7 @@ where ), program.id, Default::default(), - ) - .ok_or("Incorrect message store context: out of outgoing bytes limit")?; + ); let context = ProcessorContext { gas_counter: GasCounter::new(gas_limit), diff --git a/core-processor/src/ext.rs b/core-processor/src/ext.rs index 0454795c8a9..40a22e557e6 100644 --- a/core-processor/src/ext.rs +++ b/core-processor/src/ext.rs @@ -130,8 +130,7 @@ impl ProcessorContext { Default::default(), Default::default(), Default::default(), - ) - .unwrap(), + ), block_info: Default::default(), performance_multiplier: gsys::Percent::new(100), program_id: Default::default(), @@ -1456,7 +1455,6 @@ mod tests { self.program_id, self.context_settings, ) - .unwrap() } fn with_outgoing_limit(mut self, outgoing_limit: u32) -> Self { diff --git a/core/src/message/context.rs b/core/src/message/context.rs index 61c0477968f..c922113bdf2 100644 --- a/core/src/message/context.rs +++ b/core/src/message/context.rs @@ -226,17 +226,17 @@ impl MessageContext { dispatch: IncomingDispatch, program_id: ProgramId, settings: ContextSettings, - ) -> Option { + ) -> Self { let (kind, message, store) = dispatch.into_parts(); - Some(Self { + Self { kind, outcome: ContextOutcome::new(program_id, message.source(), message.id()), current: message, store: store.unwrap_or_default(), outgoing_payloads: OutgoingPayloads::default(), settings, - }) + } } /// Getter for inner settings. @@ -630,8 +630,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); // first init to default ProgramId. assert_ok!(message_context.init_program(Default::default(), 0)); @@ -649,8 +648,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, 10), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let handle = message_context.send_init().unwrap(); @@ -673,8 +671,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, 10), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let handle = message_context.send_init().unwrap(); @@ -721,8 +718,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let handle = message_context.send_init().unwrap(); @@ -773,8 +769,7 @@ mod tests { incoming_dispatch, Default::default(), ContextSettings::with_outgoing_limits(1024, 10), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let handle = message_context.send_init().unwrap(); @@ -819,8 +814,7 @@ mod tests { let settings = ContextSettings::with_outgoing_limits(n, u32::MAX); let mut message_context = - MessageContext::new(Default::default(), Default::default(), settings) - .expect("Outgoing messages bytes limit exceeded"); + MessageContext::new(Default::default(), Default::default(), settings); // send n messages for _ in 0..n { let handle = message_context.send_init().expect("unreachable"); @@ -853,8 +847,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); // Use invalid handle 0. let out_of_bounds = message_context.send_commit(0, Default::default(), 0, None); @@ -880,8 +873,7 @@ mod tests { Default::default(), Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); // First reply. assert_ok!(message_context.reply_commit(Default::default(), None)); @@ -896,8 +888,7 @@ mod tests { #[test] fn reply_commit_message_size_limit() { let mut message_context = - MessageContext::new(Default::default(), Default::default(), Default::default()) - .expect("Outgoing messages bytes limit exceeded"); + MessageContext::new(Default::default(), Default::default(), Default::default()); assert_ok!(message_context.reply_push(&[1])); @@ -937,8 +928,7 @@ mod tests { incoming_dispatch, Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); // Checking that the initial parameters of the context match the passed constants assert_eq!(context.current().id(), MessageId::from(INCOMING_MESSAGE_ID)); @@ -1078,8 +1068,7 @@ mod tests { incoming_dispatch, Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); context.wake(MessageId::default(), 10).unwrap(); @@ -1106,8 +1095,7 @@ mod tests { incoming_dispatch, Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let handle = message_context.send_init().expect("unreachable"); message_context @@ -1141,8 +1129,7 @@ mod tests { incoming_dispatch, Default::default(), ContextSettings::with_outgoing_limits(1024, u32::MAX), - ) - .expect("Outgoing messages bytes limit exceeded"); + ); let message_id = message_context .reply_commit(ReplyPacket::default(), None) diff --git a/lazy-pages/src/common.rs b/lazy-pages/src/common.rs index 8b16cb7dc5a..e638e4943f9 100644 --- a/lazy-pages/src/common.rs +++ b/lazy-pages/src/common.rs @@ -28,7 +28,6 @@ use gear_lazy_pages_common::{GlobalsAccessError, Status}; use numerated::tree::IntervalsTree; use std::{fmt, num::NonZero}; -// TODO: investigate error allocations #2441 #[derive(Debug, derive_more::Display, derive_more::From)] pub enum Error { #[display(fmt = "Accessed memory interval is out of wasm memory")] diff --git a/pallets/gear-builtin/src/lib.rs b/pallets/gear-builtin/src/lib.rs index b7f2f440d17..9da5f425744 100644 --- a/pallets/gear-builtin/src/lib.rs +++ b/pallets/gear-builtin/src/lib.rs @@ -407,14 +407,7 @@ impl BuiltinDispatcher for BuiltinRegistry { // Create an artificial `MessageContext` object that will help us to generate // a reply from the builtin actor. let mut message_context = - MessageContext::new(dispatch, actor_id, Default::default()).unwrap_or_else( - || { - unreachable!( - "BuiltinRegistry::run: Builtin actor can't have context stored, - so must be always possible to create a new message context" - ); - }, - ); + MessageContext::new(dispatch, actor_id, Default::default()); let packet = ReplyPacket::new(response_payload, 0); // Mark reply as sent diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index a2483881eb5..f84c5841216 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -15398,7 +15398,7 @@ fn incorrect_store_context() { let limit = ::OutgoingBytesLimit::get(); let dispatch = IncomingDispatch::new(DispatchKind::Handle, message.clone(), None); let settings = ContextSettings::with_outgoing_limits(1024, limit + 1); - let mut message_context = MessageContext::new(dispatch, pid, settings).unwrap(); + let mut message_context = MessageContext::new(dispatch, pid, settings); let mut counter = 0; // Fill until the limit is reached while counter < limit + 1 { diff --git a/utils/wasm-gen/src/tests.rs b/utils/wasm-gen/src/tests.rs index 38b10a7de5e..2cfe200c1ef 100644 --- a/utils/wasm-gen/src/tests.rs +++ b/utils/wasm-gen/src/tests.rs @@ -1047,8 +1047,7 @@ fn execute_wasm_with_custom_configs( IncomingDispatch::new(DispatchKind::Init, incoming_message, None), program_id, ContextSettings::with_outgoing_limits(outgoing_limit, u32::MAX), - ) - .unwrap(); + ); if imitate_reply { let _ = message_context.reply_commit(ReplyPacket::auto(), None);