mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
paras: Add runtime events for PVF pre-checking (#4683)
In this PR, paras module emit runtime events on certain PVF pre-checking related conditions. Specifically, there are 3 new events in the paras module: 1. PvfCheckStarted 2. PvfCheckAccepted 3. PvfCheckRejected All of those have identifiers for the parachain that triggered the PVF pre-checking and the validation code that goes through the pre-checking. The mechanics of those are as follows. Each time a new PVF is added, be it due to onboarding or upgrading, the `PvfCheckStarted` will be triggered. If another parachain triggers a pre-checking process for the validation code which is already being pre-checked, another `PvfCheckStarted` event will be triggered with the corresponding para id. When the PVF pre-checking voting for a PVF was finished, several `PvfCheckAccepted/Rejected` events will be triggered: one for each para id that was subscribed to this check (i.e. was a "cause" for it). If the PVF pre-checking is disabled, then one can still expect these events to be fired. Since insta PVF approval is syncronous, the `PvfCheckStarted` will be followed by the `PvfCheckAccepted` with the same validation code and para id. If somebody is interested in following validation code changes for a PVF of a parachain, they would need to subscribe to those events. I did not supply the topics for the events, since I am not sure if that's needed or will be used, but they can be added later if needed.
This commit is contained in:
@@ -113,6 +113,49 @@ fn check_code_is_not_stored(validation_code: &ValidationCode) {
|
||||
assert!(!<Paras as Store>::CodeByHash::contains_key(validation_code.hash()));
|
||||
}
|
||||
|
||||
/// An utility for checking that certain events were deposited.
|
||||
struct EventValidator {
|
||||
events:
|
||||
Vec<frame_system::EventRecord<<Test as frame_system::Config>::Event, primitives::v1::Hash>>,
|
||||
}
|
||||
|
||||
impl EventValidator {
|
||||
fn new() -> Self {
|
||||
Self { events: Vec::new() }
|
||||
}
|
||||
|
||||
fn started(&mut self, code: &ValidationCode, id: ParaId) -> &mut Self {
|
||||
self.events.push(frame_system::EventRecord {
|
||||
phase: frame_system::Phase::Initialization,
|
||||
event: Event::PvfCheckStarted(code.hash(), id).into(),
|
||||
topics: vec![],
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
fn rejected(&mut self, code: &ValidationCode, id: ParaId) -> &mut Self {
|
||||
self.events.push(frame_system::EventRecord {
|
||||
phase: frame_system::Phase::Initialization,
|
||||
event: Event::PvfCheckRejected(code.hash(), id).into(),
|
||||
topics: vec![],
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
fn accepted(&mut self, code: &ValidationCode, id: ParaId) -> &mut Self {
|
||||
self.events.push(frame_system::EventRecord {
|
||||
phase: frame_system::Phase::Initialization,
|
||||
event: Event::PvfCheckAccepted(code.hash(), id).into(),
|
||||
topics: vec![],
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
fn check(&self) {
|
||||
assert_eq!(&frame_system::Pallet::<Test>::events(), &self.events);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn para_past_code_pruning_works_correctly() {
|
||||
let mut past_code = ParaPastCodeMeta::default();
|
||||
@@ -1048,6 +1091,14 @@ fn pvf_check_coalescing_onboarding_and_upgrade() {
|
||||
<Paras as Store>::FutureCodeUpgrades::get(&a),
|
||||
Some(RELAY_PARENT + validation_upgrade_delay),
|
||||
);
|
||||
|
||||
// Verify that the required events were emitted.
|
||||
EventValidator::new()
|
||||
.started(&validation_code, b)
|
||||
.started(&validation_code, a)
|
||||
.accepted(&validation_code, b)
|
||||
.accepted(&validation_code, a)
|
||||
.check();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1157,6 +1208,9 @@ fn pvf_check_upgrade_reject() {
|
||||
assert!(<Paras as Store>::PvfActiveVoteMap::get(&new_code.hash()).is_none());
|
||||
assert!(Paras::pvfs_require_precheck().is_empty());
|
||||
assert!(<Paras as Store>::FutureCodeHash::get(&a).is_none());
|
||||
|
||||
// Verify that the required events were emitted.
|
||||
EventValidator::new().started(&new_code, a).rejected(&new_code, a).check();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1398,6 +1452,12 @@ fn add_trusted_validation_code_insta_approval() {
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
Some(1 + validation_upgrade_delay)
|
||||
);
|
||||
|
||||
// Verify that the required events were emitted.
|
||||
EventValidator::new()
|
||||
.started(&validation_code, para_id)
|
||||
.accepted(&validation_code, para_id)
|
||||
.check();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user