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

Integrate new Aura / Parachain Consensus Logic in Parachain-Template / Polkadot-Parachain #2864

Merged
merged 40 commits into from
Aug 3, 2023

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Jul 13, 2023

Closes #2476

This is a catch-all PR which:

  • Updates the basic and lookahead collators to explicitly produce Futures which are Send
  • Migrates node-template and polkadot-parachain to use some of the new consensus infrastructure, deprecating some old pieces
  • Migrates node-template to use the new basic collator
  • Adds a function to the aura-ext::FixedVelocityConsensusHook which can be used to implement the AuraUnincludedSegmentApi

@@ -246,6 +246,7 @@ pub struct StartCollatorParams<Block: BlockT, RA, BS, Spawner> {
}

/// Start the collator.
#[deprecated = "Collators should run consensus futures which handle this logic internally"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the futures in the run() functions of lookahead.rs and basic.rs examples of the "consensus futures" you mention here?

Perhaps we would call said run() functions instead of old_consensus::start_collator() in parachain-template/node/src/service.rs to fully activate async backing aura?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly.

The first step is to use the basic.rs future, which is intended to have the exact same behavior as current Aura. Then, when asynchronous backing is being enabled, the lookahead.rs future would be swapped in.

pallets/aura-ext/src/consensus_hook.rs Show resolved Hide resolved
pallets/aura-ext/src/consensus_hook.rs Show resolved Hide resolved
@paritytech-ci paritytech-ci requested a review from a team July 18, 2023 20:16
@rphmeier rphmeier added A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. T0-node This PR/Issue is related to the topic “node”. labels Jul 19, 2023
@rphmeier rphmeier changed the title Integrate new Aura / Parachain Consensus Logic Integrate new Aura / Parachain Consensus Logic in Parachain-Template / Polkadot-Parachain Jul 19, 2023
Copy link
Contributor

@BradleyOlson64 BradleyOlson64 left a comment

Choose a reason for hiding this comment

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

Didn't find any issues this time.

Now that the new basic aura collator is plugged in, I can take a first pass at showing those changes in the user update guide.

Comment on lines 164 to 166
// TODO [now]: it'd be nice to handle this gracefully when unincluded segment
// is at maximum.
match params
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it responsibility of can_build_upon?

I'm having hard time understanding "graceful" handling in this todo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use can_build_upon in this collator, as it's intended to be fully backwards compatible, so doesn't depend on AuraUnincludedSegmentApi. Unfortunately, we can't "half-depend" on it (i.e. use it when it's present and not when it's not) because of https://github.com/paritytech/substrate/issues/13331 .

This does lead to panics when the runtime does have an unincluded segment of max size 1 and the collation-generation subsystem requests blocks to be built when there is a candidate pending.

Honestly, this change is unnecessary because of paritytech/polkadot#7514 so I will just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add a dependency on AuraUnincludedSegmentApi but it then requires the user to implement that in their most recent version of the native runtime, which I'm not sure we should require. Maybe useful to do that.


// This needs to change to support elastic scaling, but for continuously
// scheduled chains this ensures that the backlog will grow steadily.
for n_built in 0..2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this should use max_ancestry_lookback which already hardcodes 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually more of a velocity hardcoding than ancestry lookback. It will need to be adjusted when we start dealing with dynamic velocities, but saving that for a later date as velocity won't exceed 1 per relay-block for a while.

The specific behavior we're dealing with is that most parachains hardcode an Aura slot duration of 12 seconds, so they can actually author at 2 different relay parents. These chains should set velocity=2 in their runtime as they expect 2 blocks to be included per slot. That allows them to author 3 blocks per slot when the unincluded segment has space, and this change just spreads that out and showed better results in testing.

Generalizing a bit - any slot duration which is a multiple of the relay chain slot duration probably doesn't want to try authoring all the blocks in their slot at the front, but rather spread them out.

It's definitely not ideal or particularly elegant, but couldn't think of a better solution at the time.

The alternative is to keep track in aura-ext how many blocks are authored per relay-chain slot not per parachain slot, and change can_build_upon to `can_build_upon(included_hash, relay_chain_slot) . But then slot durations become kind of meaningless in a relay-chain setting, except for rotating keys.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, my initial comment is not correct, first I was confused where does hardcoded 2 come from, then noticed the below function and assumed it's the same.

We had this discussion about filling backlog in the first PR, and I guess looping while can_build is ok for the start. When I was thinking about this, I imagined parachains would somehow customize this rate of block production, like

enum BlockProductionRate {
    /// Only author every N seconds.
    Fixed(Duration),
    /// No fixed block time, attempt to author whenever possible,
    Asap,
    // ... and 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.

Let's revisit this in a new issue. The design space is pretty open, though I think the best the runtime can do is give "hints" and not expect them to be obeyed.

@rphmeier rphmeier merged commit fe3d6ee into slumber-async-backing-feature Aug 3, 2023
3 checks passed
@rphmeier rphmeier deleted the rh-integrate-new-aura branch August 3, 2023 16:04
paritytech-processbot bot pushed a commit that referenced this pull request Aug 18, 2023
* Update substrate & polkadot

* min changes to make async backing compile

* (async backing) parachain-system: track limitations for unincluded blocks (#2438)

* unincluded segment draft

* read para head from storage proof

* read_para_head -> read_included_para_head

* Provide pub interface

* add errors

* fix unincluded segment update

* BlockTracker -> Ancestor

* add a dmp limit

* Read para head depending on the storage switch

* doc comments

* storage items docs

* add a sanity check on block initialize

* Check watermark

* append to the segment on block finalize

* Move segment update into set_validation_data

* Resolve para head todo

* option watermark

* fix comment

* Drop dmq check

* fix weight

* doc-comments on inherent invariant

* Remove TODO

* add todo

* primitives tests

* pallet tests

* doc comments

* refactor unincluded segment length into a ConsensusHook (#2501)

* refactor unincluded segment length into a ConsensusHook

* add docs

* refactor bandwidth_out calculation

Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com>

* test for limits from impl

* fmt

* make tests compile

* update comment

* uncomment test

* fix collator test by adding parent to state proof

* patch HRMP watermark rules for unincluded segment

* get consensus-common tests to pass, using unincluded segment

* fix unincluded segment tests

* get all tests passing

* fmt

* rustdoc CI

* aura-ext: limit the number of authored blocks per slot (#2551)

* aura_ext consensus hook

* reverse dependency

* include weight into hook

* fix tests

* remove stray println

Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com>

* fix test warning

* fix doc link

---------

Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com>
Co-authored-by: Chris Sosnin <chris125_@live.com>

* parachain-system: ignore go ahead signal once upgrade is processed (#2594)

* handle goahead signal for unincluded segment

* doc comment

* add test

* parachain-system: drop processed messages from inherent data (#2590)

* implement `drop_processed_messages`

* drop messages based on relay parent number

* adjust tests

* drop changes to mqc

* fix comment

* drop test

* drop more dead code

* clippy

* aura-ext: check slot in consensus hook and remove all `CheckInherents` logic (#2658)

* aura-ext: check slot in consensus hook

* convert relay chain slot

* Make relay chain slot duration generic

* use fixed velocity hook for pallets with aura

* purge timestamp inherent

* fix warning

* adjust runtime tests

* fix slots in tests

* Make `xcm-emulator` test pass for new consensus hook (#2722)

* add pallets on_initialize

* tests pass

* add AuraExt on_init

* ".git/.scripts/commands/fmt/fmt.sh"

---------

Co-authored-by: command-bot <>

---------

Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>

* update polkadot git refs

* CollationGenerationConfig closure is now optional (#2772)

* CollationGenerationConfig closure is now optional

* fix test

* propagate network-protocol-staging feature (#2899)

* Feature Flagging Consensus Hook Type Parameter (#2911)

* First pass

* fmt

* Added as default feature in tomls

* Changed to direct dependency feature

* Dealing with clippy error

* Update pallets/parachain-system/src/lib.rs

Co-authored-by: asynchronous rob <rphmeier@gmail.com>

---------

Co-authored-by: asynchronous rob <rphmeier@gmail.com>

* fmt

* bump deps and remove warning

* parachain-system: update RelevantMessagingState according to the unincluded segment (#2948)

* mostly address 2471 with a bug introduced

* adjust relevant messaging state after computing total

* fmt

* max -> min

* fix test implementation of xcmp source

* add test

* fix test message sending logic

* fix + test

* add more to unincluded segment test

* fmt

---------

Co-authored-by: Chris Sosnin <chris125_@live.com>

* Integrate new Aura / Parachain Consensus Logic in Parachain-Template / Polkadot-Parachain (#2864)

* add a comment

* refactor client/service utilities

* deprecate start_collator

* update parachain-template

* update test-service in the same way

* update polkadot-parachain crate

* fmt

* wire up new SubmitCollation message

* some runtime utilities for implementing unincluded segment runtime APIs

* allow parachains to configure their level of sybil-resistance when starting the network

* make aura-ext compile

* update to specify sybil resistance levels

* fmt

* specify relay chain slot duration in milliseconds

* update Aura to explicitly produce Send futures

also, make relay_chain_slot_duration a Duration

* add authoring duration to basic collator and document params

* integrate new basic collator into parachain-template

* remove assert_send used for testing

* basic-aura: only author when parent included

* update polkadot-parachain-bin

* fmt

* some fixes

* fixes

* add a RelayNumberMonotonicallyIncreases

* add a utility function for initializing subsystems

* some logging for timestamp adjustment

* fmt

* some fixes for lookahead collator

* add a log

* update `find_potential_parents` to account for sessions

* bound the loop

* restore & deprecate old start_collator and start_full_node functions.

* remove unnecessary await calls

* fix warning

* clippy

* more clippy

* remove unneeded logic

* ci

* update comment

Co-authored-by: Marcin S. <marcin@bytedude.com>

* (async backing) restore `CheckInherents` for backwards-compatibility (#2977)

* bring back timestamp

* Restore CheckInherents

* revert to empty CheckInherents

* make CheckInherents optional

* attempt

* properly end system blocks

* add some more comments

* ignore failing system parachain tests

* update refs after main feature branch merge

* comment out the offending tests because CI runs ignored tests

* fix warnings

* fmt

* revert to polkadot master

* cargo update -p polkadot-primitives -p sp-io

---------

Co-authored-by: asynchronous rob <rphmeier@gmail.com>
Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>
Co-authored-by: Bradley Olson <34992650+BradleyOlson64@users.noreply.github.com>
Co-authored-by: Marcin S. <marcin@bytedude.com>
Co-authored-by: eskimor <eskimor@users.noreply.github.com>
Co-authored-by: Andronik <write@reusable.software>
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. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants