5

Anecdotally, I know that one of Substrate's most important points of differentiation is its support for modular & hot-swappable consensus. What does this mean and how does Substrate enable this capability?

1
  • 2
    Actually, I don't think this is a thing anymore. Hot-swappable consensus was needed as part of the lifecycle of a parachain when it would offboard and become a solo-chain until it won another auction and joined Polkadot again. Now that we have the idea of parathreads, chains can continue to produce new blocks even after offboarding as a parachain. But that is only AFAIK.
    – Shawn Tabrizi
    Feb 10, 2022 at 0:16

2 Answers 2

5

Hot-swappable consensus was an item on the roadmap for a while but has been indefinitely postponed because it's very involved and doesn't provide much real-world utility.

Substrate enables modular consensus mostly through the BlockImport trait: this allows composable, custom, and atomic block import logic to be defined by code outside of the client. BlockImport can do custom checks on the block or even manipulate the block and provides input about the fork-choice rule to the Client. The BlockImport implementation that's used blocks the import pipeline and is guaranteed to be called for every single block imported by the node, whether it comes from authorship or the network or a file.

The Client also exposes APIs to finalize blocks that are already present.

Authoring and other consensus tasks are just normal futures that are executed in the background to implement things like finality gadgets or to create blocks.

1
1

Most projects rarely actually want to write their own consensus, and prefer to use one of the prebuilt consensus pallets. Writing your own consensus is obviously non-trivial but if that's the thing that your set on, take a look at Aleph Zero's codebase. They have implemented their own (DAG) consensus while using a lot of the other standard substrate modules. Their blog post explains why for them, substrate made a lot of sense: https://alephzero.org/blog/substrate-aleph-zero-consensus/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.