Skip to content

Commit

Permalink
Fixed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mqxf committed Feb 7, 2024
1 parent e99f5c0 commit a8d95f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/src/message/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub struct ContextStore {
}

impl ContextStore {
// TODO: Remove, only used in migrations (#issue)
// TODO: Remove, only used in migrations (#issue 3721)
/// Create a new context store with the provided parameters.
pub fn new(
outgoing: BTreeMap<u32, Option<Payload>>,
Expand Down
1 change: 0 additions & 1 deletion core/src/message/stored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl StoredDelayedDispatch {
Self { kind, message }
}


/// Decompose StoredDelayedDispatch for it's components: DispatchKind, StoredMessage.
pub fn into_parts(self) -> (DispatchKind, StoredMessage) {
self.into()
Expand Down
16 changes: 10 additions & 6 deletions pallets/gear-messenger/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV3<T> {
DispatchStash::<T>::translate(
|_, store: (v2::StoredDispatch, Interval<BlockNumberFor<T>>)| {
if store.0.context.is_some() {
log::error!("Previous context on StoredDispatch in DispatchStash should always be None, but was {:?}", store.0.context);
log::error!("Previous context on StoredDispatch in DispatchStash should always be None, but was Some for message id {:?}", store.0.message.id());
}
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
Some((store.0.into(), store.1))
Expand All @@ -87,7 +87,13 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV3<T> {
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
let mut count = v2::Waitlist::<T>::iter().count();
count += v2::Dispatches::<T>::iter().count();
count += v2::DispatchStash::<T>::iter().count();
count += v2::DispatchStash::<T>::iter().inspect(
|store| {
if store.1.0.context.is_some() {
log::error!("Previous context on StoredDispatch in DispatchStash should always be None, but was Some for message id {:?}", store.1.0.message.id());
}
},
).count();

Ok((count as u64).encode())
}
Expand Down Expand Up @@ -257,6 +263,7 @@ mod tests {
};
use gear_core_errors::{ReplyCode, SignalCode, SuccessReplyReason};
use rand::random;
use sp_runtime::traits::Zero;

fn random_payload() -> Payload {
Payload::try_from(up_to(8 * 1024, random::<u8>).collect::<Vec<_>>())
Expand Down Expand Up @@ -396,10 +403,7 @@ mod tests {
.collect::<Vec<_>>();

for (msg_id, dispatch, interval) in dispatch_stash.clone() {
v2::DispatchStash::<Test>::insert(
dispatch.0,
(dispatch.1.clone(), dispatch.2.clone()),
);
v2::DispatchStash::<Test>::insert(msg_id, (dispatch.clone(), interval.clone()));
}

let state = MigrateToV3::<Test>::pre_upgrade().unwrap();
Expand Down

0 comments on commit a8d95f1

Please sign in to comment.