substrate icon indicating copy to clipboard operation
substrate copied to clipboard

Add `TryState` hook for `MessageQueue`

Open ggwpez opened this issue 2 years ago • 2 comments

The MessageQueue pallet has quite a few storage assumptions which could be checked in a try_state hook.

:point_right: Mentor issues are meant for new-comers. Please ask before picking them up.

ggwpez avatar Jan 10 '23 14:01 ggwpez

i am a newcomer, can i pick this up?

mahmudsudo avatar Jan 12 '23 01:01 mahmudsudo

Yes @mahmudsudo !
Please familiarize yourself with the try_state hook implementations that we have in other pallets and how to write them.
For example in the bags-list pallet or in nomination-pools.
Then take a look at the message-queue and especially all the debug_assert!+defensive! in it. Ideally we check all these invariants in the try_state function.
So for example check that every page can be decoded into peek_* functions etc.

ggwpez avatar Jan 12 '23 11:01 ggwpez

Hey @mahmudsudo , are you still working on this? If not, I would like to take this over.

gitofdeepanshu avatar Feb 01 '23 08:02 gitofdeepanshu

Looks stake, please go ahead @gitofdeepanshu

ggwpez avatar Feb 23 '23 09:02 ggwpez

Hey @ggwpez I have written the function taking following assumptions:

If serviceHead points to a ready Queue (i.e. has some value), then BookState of that Queue has: * message_count > 0 * size > 0 * end > begin * Some(ready_neighbours) * If ready_neighbours.next == self.origin, then ready_neighbours.prev == self.origin (only queue in ring)

For a particular BookState of Queue present in ReadyRing, all pages from begin to end-1 should have: * remaining > 0 * remaining_size > 0 * first <= last * Every page can be decoded into peek_* functions

If all these assumptions are correct then all Queue present in ReadyRing must have atleast 1 message. (Is this correct?) But there are some tests which add Queue with empty book into ReadyRing which causes try_state function to panic. Should I leave those tests or is there something wrong with my assumptions?

gitofdeepanshu avatar Mar 01 '23 08:03 gitofdeepanshu

If all these assumptions are correct then all Queue present in ReadyRing must have atleast 1 message. (Is this correct?) But there are some tests which add Queue with empty book into ReadyRing which causes try_state function to panic. Should I leave those tests or is there something wrong with my assumptions?

Looks good so far. Please open a Merge request with your changes. I will then go over them in more details.
But AFAIK yes; there should be no empty books in the ready ring.

ggwpez avatar Mar 01 '23 10:03 ggwpez

@ggwpez I have opened the merge request, kindly let me know if you want me to change anything.

gitofdeepanshu avatar Mar 01 '23 12:03 gitofdeepanshu