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

Conversation

@rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Sep 16, 2019

This is the counterpart to the initial type-definition work done in #3611 on the core side.

Rough overview of changeset:

  • Extract SharedEpochChanges logic out to its own module in a way that can be more cleanly tested
  • Track chain total-weight offchain and handle it in the block-import worker
  • Define epoch 0 as starting at block 1. There might be multiple block 1s, so they might all kick off slightly competing epochs.
  • Allow epochs to change between blocks and grab epoch based on start slot as well as ancestry.
  • Detect that the first block in an epoch is such by comparing the epoch start slot to the parent block's slot. The first block in an epoch must issue a NextEpochDescriptor about the following epoch.
  • Does not define pruning of the epoch fork-tree at this point. That can come in a follow-up PR, since the logic is complex.
  • Fix BABE tests

@rphmeier rphmeier added the A3-in_progress Pull request is in progress. No review needed at this stage. label Sep 16, 2019
@rphmeier rphmeier added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Sep 18, 2019
)
}

/// Write the cumulative chain-weight of a block ot aux storage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Write the cumulative chain-weight of a block ot aux storage.
/// Write the cumulative chain-weight of a block to aux storage.


/// Build an `is_descendent_of` function.
///
/// The `current` parameter can be `Some` with the details a fresh block whose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The `current` parameter can be `Some` with the details a fresh block whose
/// The `current` parameter can be `Some` with the details of a fresh block whose

// prune any epochs which could not be _live_ as of the children of the
// finalized block.
// i.e. re-root the fork tree to the earliest ancestor of (hash, number)
// where epoch.start_slot + epoch.duration >= slot(hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.inner.prune(hash, number, is_descendent_of) should work, but I'll verify again before merging this PR.

// TODO: write tests within the scope of this module.
//
// 1. mock up an `IsDescendentOfBuilder`. Don't use the `Client` - these tests should be
// minimal and focused.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to share that code!

Ok(slots::start_slot_worker(

let epoch_changes = babe_link.epoch_changes.clone();
let pruning_task = client.finality_notification_stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only be started by validators this way and it must be run by all full nodes. That's why it was returned with the import queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I realized that earlier today, which a bit too late. Still, I don't think that forcing the user to spawn a background task is friendly at all.

I'd rather have us prune implicitly every time we add an epoch, based on the finalized block.

// TODO: block-import handles fork choice and this shouldn't even have the
// option to specify one.
// https://github.com/paritytech/substrate/issues/3623
fork_choice: ForkChoiceStrategy::LongestChain,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are authoring (before import), i.e. by this exact point, do we guarantee that nothing else gets imported in the meantime? I'm worried that we can author a primary block and won't reorg to it because in the meantime we might have imported a secondary block (with longest chain we would keep the secondary at the same height). The previous code was also susceptible to this kind of race condition if it exists.

In the meantime I read the code below and figured out that this logic was moved to BabeBlockImport which also takes care of the race condition issue.


old_epoch_changes = Some(epoch_changes.clone());

babe_info!("New epoch {} launching at block {} (block slot {} >= start slot {}).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, should these be downgraded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer these to go in the info logs since we won't get them that often (although due to forks we might get a couple ~duplicates at a time).

@rphmeier rphmeier merged commit a82f7f6 into rh-fix-babe-epochs Sep 19, 2019
@rphmeier rphmeier deleted the rh-fix-epochs-core branch September 19, 2019 13:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants