-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add try-state
hook to pallet aura
#14363
Add try-state
hook to pallet aura
#14363
Conversation
); | ||
} | ||
|
||
let authorities_len = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure sure what this has to be the case -- a manual-seal node (or something similar) that has this pallet in a dormant mode seems valid to me, but woudl not pass this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with either dormant mode nor manual seal, but when authorities_len
is zero, then I think that on_initialize
would panic at let authority_index = *new_slot % n_authorities as u64;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I went for @kianenigma suggestion and triggered do_try_state after every unit test, I didn't add any tests that would actually trigger panic from these checks. IMHO this would be a bit misleading. For example, suppose that we craft a test that sets CurrentSlot to the maximal value and disallow multiple blocks per slot. Having such a test might give a wrong impression, that the pallet itself guards this and would panic, while in reality, only feature-gated check would do so.
I think so long as the test is feature gated it's OK. The try-state invariants don't guard against incorrect usage of the pallet, but more so just checks that the pallet doesn't have any internal bugs. I'd personally feel more confident if the fail-cases of our try-state hooks are tested, but curious to hear @kianenigma's thoughts too.
I actually have a different opinion. A priori, the end goal, is to write correct code, and make sure we are notified if we have not written correct code. With that goal in mind, in my experience, I the outcome is better if I craft all tests such that they handle all happy paths, and all validly reachable error paths, and leave what is meant to never reach as-is. Whatever assumption is in This is mostly a personal opinion that I acquired after reviewing and maintaining That being said, I see no big harm in testing invariants and defensive operations either. |
bot merge |
* Add aura try-state hook * Trigger checks after unit tests
Description
This PR introduces storage invariants to pallet aura via
try-state
hook. Checks are also triggered after pallet unit tests.Completes one of the goals of paritytech/polkadot-sdk#239.
Notes
do_try_state
after every unit test, I didn't add any tests that would actually trigger panic from these checks. IMHO this would be a bit misleading. For example, suppose that we craft a test that setsCurrentSlot
to the maximal value and disallow multiple blocks per slot. Having such a test might give a wrong impression, that the pallet itself guards this and would panic, while in reality, only feature-gated check would do so.on_initialize
will panic if the previous block has clearedAuthorities
item (e.g. a malfunctioning pallet removed all validators). Is that okay?Checklist
A
,B
,C
andD
required)