mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Fix light client synchronization on master (#3301)
* value ranges in consensus cache * skip values in cache * read epoch0 + epoch1 data from genesis in babe * sync authorities + session validators at genesis * removed some debug printlns * fixed cache encoding * Revert "skip values in cache" This reverts commit ce451c32823aaa4b67d99ca5b58f1bf3984df4db. * Revert "value ranges in consensus cache" This reverts commit 9062f9434cddd14a01275ddbfcd904b04282e63b. * get rid of cache::AUTHORITIES in Babe * cleaning up * cleaning up * update spec version * lost changes * fixed tests * Update node/runtime/src/lib.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * fix once-per-block condition * fix standalone babe + temp_storage in BuildGenesis * fix benhes compilation * fixed comment * re-added light nodes to integration tests * finalize_with_ancestors from extra_requests * post-merge fix * aaand removed debug code * (another one) * fix warn in logs (do not call ForkTree::finalize twice for the same block) * sync digest.next_authorities with actual next authorities * more docs * reverting all commits affecting storage * also remove keys from babe trait * fixed warnings * post-merge fixes * reverted some redundant changes * reverted more changes
This commit is contained in:
committed by
Gavin Wood
parent
d1dde7e087
commit
3825a21bac
@@ -162,6 +162,10 @@ decl_storage! {
|
||||
/// epoch.
|
||||
SegmentIndex build(|_| 0): u32;
|
||||
UnderConstruction: map u32 => Vec<[u8; 32 /* VRF_OUTPUT_LENGTH */]>;
|
||||
|
||||
/// Temporary value (cleared at block finalization) which is true
|
||||
/// if per-block initialization has already been called for current block.
|
||||
Initialized get(initialized): Option<bool>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(authorities): Vec<(AuthorityId, BabeWeight)>;
|
||||
@@ -193,25 +197,12 @@ decl_module! {
|
||||
|
||||
/// Initialization
|
||||
fn on_initialize() {
|
||||
for digest in Self::get_inherent_digests()
|
||||
.logs
|
||||
.iter()
|
||||
.filter_map(|s| s.as_pre_runtime())
|
||||
.filter_map(|(id, mut data)| if id == BABE_ENGINE_ID {
|
||||
RawBabePreDigest::decode(&mut data).ok()
|
||||
} else {
|
||||
None
|
||||
})
|
||||
{
|
||||
if EpochStartSlot::get() == 0 {
|
||||
EpochStartSlot::put(digest.slot_number);
|
||||
}
|
||||
Self::do_initialize();
|
||||
}
|
||||
|
||||
CurrentSlot::put(digest.slot_number);
|
||||
Self::deposit_vrf_output(&digest.vrf_output);
|
||||
|
||||
return;
|
||||
}
|
||||
/// Block finalization
|
||||
fn on_finalize() {
|
||||
Initialized::kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,6 +239,12 @@ impl<T: Trait> IsMember<AuthorityId> for Module<T> {
|
||||
|
||||
impl<T: Trait> session::ShouldEndSession<T::BlockNumber> for Module<T> {
|
||||
fn should_end_session(_: T::BlockNumber) -> bool {
|
||||
// it might be (and it is in current implementation) that session module is calling
|
||||
// should_end_session() from it's own on_initialize() handler
|
||||
// => because session on_initialize() is called earlier than ours, let's ensure
|
||||
// that we have synced with digest before checking if session should be ended
|
||||
Self::do_initialize();
|
||||
|
||||
let diff = CurrentSlot::get().saturating_sub(EpochStartSlot::get());
|
||||
diff >= T::EpochDuration::get()
|
||||
}
|
||||
@@ -285,6 +282,36 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn do_initialize() {
|
||||
// since do_initialize can be called twice (if session module is present)
|
||||
// => let's ensure that we only modify the storage once per block
|
||||
let initialized = Self::initialized().unwrap_or(false);
|
||||
if initialized {
|
||||
return;
|
||||
}
|
||||
|
||||
Initialized::put(true);
|
||||
for digest in Self::get_inherent_digests()
|
||||
.logs
|
||||
.iter()
|
||||
.filter_map(|s| s.as_pre_runtime())
|
||||
.filter_map(|(id, mut data)| if id == BABE_ENGINE_ID {
|
||||
RawBabePreDigest::decode(&mut data).ok()
|
||||
} else {
|
||||
None
|
||||
})
|
||||
{
|
||||
if EpochStartSlot::get() == 0 {
|
||||
EpochStartSlot::put(digest.slot_number);
|
||||
}
|
||||
|
||||
CurrentSlot::put(digest.slot_number);
|
||||
Self::deposit_vrf_output(&digest.vrf_output);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Call this function exactly once when an epoch changes, to update the
|
||||
/// randomness. Returns the new randomness.
|
||||
fn randomness_change_epoch(next_epoch_index: u64) -> [u8; RANDOMNESS_LENGTH] {
|
||||
|
||||
Reference in New Issue
Block a user