Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

don't read events in elections anymore. #9898

Merged
3 commits merged into from
Oct 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,12 @@ impl<T: Config> Pallet<T> {
match current_phase {
Phase::Unsigned((true, opened)) if opened == now => {
// Mine a new solution, cache it, and attempt to submit it
let initial_output = Self::ensure_offchain_repeat_frequency(now)
.and_then(|_| Self::mine_check_save_submit());
let initial_output = Self::ensure_offchain_repeat_frequency(now).and_then(|_| {
// This is executed at the beginning of each round. Any cache is now invalid.
// Clear it.
kill_ocw_solution::<T>();
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
Self::mine_check_save_submit()
});
log!(debug, "initial offchain thread output: {:?}", initial_output);
},
Phase::Unsigned((true, opened)) if opened < now => {
Expand All @@ -1214,20 +1218,6 @@ impl<T: Config> Pallet<T> {
},
_ => {},
}

// After election finalization, clear OCW solution storage.
//
// We can read the events here because offchain worker doesn't affect PoV.
if <frame_system::Pallet<T>>::read_events_no_consensus()
.into_iter()
.filter_map(|event_record| {
let local_event = <T as Config>::Event::from(event_record.event);
local_event.try_into().ok()
})
.any(|event| matches!(event, Event::ElectionFinalized(_)))
{
unsigned::kill_ocw_solution::<T>();
}
}

/// Logic for [`<Pallet as Hooks>::on_initialize`] when signed phase is being opened.
Expand Down