Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9062f94
value ranges in consensus cache
svyatonik Aug 2, 2019
ce451c3
skip values in cache
svyatonik Aug 2, 2019
2efc6a4
read epoch0 + epoch1 data from genesis in babe
svyatonik Aug 2, 2019
d9d75bc
sync authorities + session validators at genesis
svyatonik Aug 4, 2019
aa491d0
removed some debug printlns
svyatonik Aug 4, 2019
de097ee
fixed cache encoding
svyatonik Aug 5, 2019
4bbebde
Revert "skip values in cache"
svyatonik Aug 5, 2019
2897a83
Revert "value ranges in consensus cache"
svyatonik Aug 5, 2019
2c72a87
get rid of cache::AUTHORITIES in Babe
svyatonik Aug 5, 2019
1c7b2cd
cleaning up
svyatonik Aug 5, 2019
cb2851f
cleaning up
svyatonik Aug 5, 2019
e5c7bd8
update spec version
svyatonik Aug 5, 2019
a838e9b
lost changes
svyatonik Aug 5, 2019
200a638
fixed tests
svyatonik Aug 5, 2019
3c420ff
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 5, 2019
c4c6788
Update node/runtime/src/lib.rs
svyatonik Aug 6, 2019
04f73d5
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 6, 2019
f30f0fb
fix once-per-block condition
svyatonik Aug 6, 2019
773982b
fix standalone babe + temp_storage in BuildGenesis
svyatonik Aug 6, 2019
c922fad
fix benhes compilation
svyatonik Aug 6, 2019
69fe38a
fixed comment
svyatonik Aug 6, 2019
b5e223e
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 8, 2019
54fd261
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 12, 2019
5991212
re-added light nodes to integration tests
svyatonik Aug 12, 2019
d24bb0b
Merge branch 'master' into fix_flaming_fir_light_sync
Demi-Marie Aug 14, 2019
51b79fc
finalize_with_ancestors from extra_requests
svyatonik Aug 14, 2019
651d8ad
Merge branch 'fix_flaming_fir_light_sync' of https://github.com/parit…
svyatonik Aug 14, 2019
8f106ae
post-merge fix
svyatonik Aug 14, 2019
b4dd1bd
aaand removed debug code
svyatonik Aug 14, 2019
d593290
(another one)
svyatonik Aug 14, 2019
a7adc1c
fix warn in logs (do not call ForkTree::finalize twice for the same b…
svyatonik Aug 14, 2019
707b288
sync digest.next_authorities with actual next authorities
svyatonik Aug 14, 2019
f1d0e41
more docs
svyatonik Aug 15, 2019
515587c
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 15, 2019
b328acb
reverting all commits affecting storage
svyatonik Aug 16, 2019
4786ea7
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 16, 2019
e33fd0f
also remove keys from babe trait
svyatonik Aug 16, 2019
e7644e4
fixed warnings
svyatonik Aug 16, 2019
f70bbcc
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 16, 2019
89447ee
post-merge fixes
svyatonik Aug 16, 2019
320534d
reverted some redundant changes
svyatonik Aug 16, 2019
5bf8db9
reverted more changes
svyatonik Aug 16, 2019
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
Prev Previous commit
Next Next commit
removed some debug printlns
  • Loading branch information
svyatonik committed Aug 4, 2019
commit aa491d0ac30ba89c710ae1937363c747ebd54eaa
16 changes: 10 additions & 6 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
return Box::pin(future::ready(Ok(())))
}
};
println!("=== Babe.OnSlot: {}", slot_number);

let inherent_digest = BabePreDigest {
vrf_proof,
vrf_output: inout.to_output(),
Expand Down Expand Up @@ -1076,7 +1076,7 @@ impl<B, E, Block, I, RA, PRA> BlockImport<Block> for BabeBlockImport<B, E, Block
&is_descendent_of,
&|epoch| epoch.start_slot <= slot_number,
).map_err(|e| ConsensusError::from(ConsensusError::ClientImport(e.to_string())))?;
println!("=== Babe.ImportBlock.slot={} enacted_epoch={:?}", slot_number, enacted_epoch);
println!("=== ENACTED_EPOCH: {:?}", enacted_epoch);
let check_roots = || -> Result<bool, ConsensusError> {
// this can only happen when the chain starts, since there's no
// epoch change at genesis. afterwards every time we expect an epoch
Expand Down Expand Up @@ -1137,16 +1137,21 @@ println!("=== Babe.ImportBlock.slot={} enacted_epoch={:?}", slot_number, enacted
enacted_epoch.encode(),
);

let current_epoch = epoch_from_runtime(&*self.api, &BlockId::Hash(parent_hash))
.ok_or(consensus_common::Error::InvalidAuthoritiesSet)?;
// we really could ignore epoch0 here, because the change epoch0 -> epoch1 doesn't emit any digest
// => we'll never reach this code
let current_epoch = epoch(&*self.api, &BlockId::Hash(parent_hash))?;
let authorities_changed = match current_epoch {
MaybeSpanEpoch::Genesis(_, epoch1) => epoch1.authorities != enacted_epoch.authorities,
MaybeSpanEpoch::Regular(epoch) => epoch.authorities != enacted_epoch.authorities,
};

// if the authorities have changed then we populate the
// `AUTHORITIES` key with the enacted epoch, so that the inner
// `ImportBlock` can process it (`EPOCH` is specific to BABE).
// e.g. in the case of GRANDPA it would require a justification
// for the block, expecting that the authorities actually
// changed.
if current_epoch.authorities != enacted_epoch.authorities {
if authorities_changed {
new_cache.insert(
well_known_cache_keys::AUTHORITIES,
enacted_epoch.authorities.encode(),
Expand All @@ -1157,7 +1162,6 @@ println!("=== Babe.ImportBlock.slot={} enacted_epoch={:?}", slot_number, enacted
old_epoch_changes = Some(epoch_changes.clone());

// track the epoch change in the fork tree
println!("=== Babe.ImportBlock.ImportNextEpoch: {:?}", next_epoch);
epoch_changes.import(
hash,
number,
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/slots/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> {
// never yield the same slot twice.
if slot_num > self.last_slot {
self.last_slot = slot_num;
println!("=== slot_ready: {}", slot_num);

break Poll::Ready(Some(Ok(SlotInfo {
number: slot_num,
duration: self.slot_duration,
Expand Down
54 changes: 31 additions & 23 deletions srml/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,26 +222,11 @@ decl_module! {

/// Initialization
fn on_initialize() {
println!("=== Babe.OnInitialize");
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)
} else {
None
})
{
if EpochStartSlot::get() == 0 {
EpochStartSlot::put(digest.slot_number);
}
println!("=== Babe.OnInitialize: {}", digest.slot_number);
CurrentSlot::put(digest.slot_number);
Self::deposit_vrf_output(&digest.vrf_output);

return;
}
// TODO: this could be safely removed (in current implementation), because:
// 1) session.on_initialize is called first
// 2) session.on_initialize calls should_end_session
// 3) should_end_session calls do_initialize
Self::do_initialize();
}
}
}
Expand Down Expand Up @@ -278,8 +263,10 @@ 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 {
use sr_primitives::traits::OnInitialize;
Self::do_initialize();

let diff = CurrentSlot::get().saturating_sub(EpochStartSlot::get());
println!("=== Babe.should_end_session: {} - {} = {} >= {}", CurrentSlot::get(), EpochStartSlot::get(), diff, T::EpochDuration::get());
diff >= T::EpochDuration::get()
}
}
Expand All @@ -305,6 +292,28 @@ impl<T: Trait> Module<T> {
UnderConstruction::mutate(|z| z.iter_mut().zip(vrf_output).for_each(|(x, y)| *x^=y))
}

fn do_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)
} 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] {
Expand All @@ -330,7 +339,6 @@ impl<T: Trait + staking::Trait> session::OneSessionHandler<T::AccountId> for Mod
fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, queued_validators: I)
where I: Iterator<Item=(&'a T::AccountId, AuthorityId)>
{
println!("=== Session.OnNewSession");
use staking::BalanceOf;
let to_votes = |b: BalanceOf<T>| {
<T::CurrencyToVote as Convert<BalanceOf<T>, u64>>::convert(b)
Expand Down Expand Up @@ -391,7 +399,7 @@ println!("=== Session.OnNewSession");
authorities: next_authorities,
randomness: next_randomness,
};
println!("=== Session.NextEpochData: {:?}", next);

Self::deposit_consensus(ConsensusLog::NextEpochData(next))
}

Expand Down
1 change: 0 additions & 1 deletion srml/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ impl<T: Trait> Module<T> {
/// equivocation punishment after a fork.
pub fn rotate_session() {
let session_index = CurrentIndex::get();
println!("=== Session.RotateSession");
let changed = QueuedChanged::get();
let mut next_changed = Changed::take();

Expand Down