Skip to content

Commit

Permalink
chore(core-processor): remove ActorExecutionError::UnsupportedMessage (
Browse files Browse the repository at this point in the history
  • Loading branch information
grishasobol authored Jan 23, 2025
1 parent 29f26e8 commit acddf02
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 62 deletions.
9 changes: 1 addition & 8 deletions core-processor/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -478,7 +471,7 @@ impl ActorExecutionErrorReplyReason {
TrapExplanation::StackLimitExceeded => SimpleExecutionError::StackLimitExceeded,
TrapExplanation::Unknown => SimpleExecutionError::UnreachableInstruction,
},
Self::Environment | Self::UnsupportedMessage => SimpleExecutionError::Unsupported,
Self::Environment => SimpleExecutionError::Unsupported,
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions core-processor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions core-processor/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -1456,7 +1455,6 @@ mod tests {
self.program_id,
self.context_settings,
)
.unwrap()
}

fn with_outgoing_limit(mut self, outgoing_limit: u32) -> Self {
Expand Down
45 changes: 16 additions & 29 deletions core/src/message/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,17 @@ impl MessageContext {
dispatch: IncomingDispatch,
program_id: ProgramId,
settings: ContextSettings,
) -> Option<Self> {
) -> 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.
Expand Down Expand Up @@ -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));
Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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]));

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lazy-pages/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
9 changes: 1 addition & 8 deletions pallets/gear-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,7 @@ impl<T: Config> BuiltinDispatcher for BuiltinRegistry<T> {
// 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
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15398,7 +15398,7 @@ fn incorrect_store_context() {
let limit = <Test as Config>::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 {
Expand Down
3 changes: 1 addition & 2 deletions utils/wasm-gen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit acddf02

Please sign in to comment.