Is it feasible to implement a Raft/PBFT like (leader election between authorized nodes) consensus algorithm in the substrate?

Viewed 79

I'm new to the substrate. I'm trying to improve the availability of block generation of permissioned networks by substituting Aura with Raft/PBFT like consensus algorithm. I'm referring to an algorithm that solves the "who can generate blocks" problem by electing a leader (via libp2p) among authorized nodes.

After running the tutorials and viewing Aura's source code, I'm still confused about if it is possible to do that. some of the questions are below:

  1. Is that possible to implement leader selection off-chain, and get the result in runtime? (It seems that an off-chain worker can only submit a transaction. but how can runtime reading data from that?)
  2. How to communicate the off-chain worker of another node in the current off-chain worker? It seems that sc-network has the ability to do that.
  3. Why does Aura's implementation have code in both sc-consensus-aura and frame-aura. What does the client do in sc-consensus-aura?
  4. Here says "Polkadot uses a hybrid PBFT / Aurand consensus mechanism", is that mean a yes to my question? And somehow I can not find related code.

And if that is possible, is there any work/example I can learn from?

Thanks for your help!

1 Answers

I'm confident that the answer is YES after reading AURA and [GRANDPA][grandpaimplementation ]'s and even implementing finality-pbft[1] myself.

The basic idea here is that any leader based (or not leader based) concensus could be a alternative to the GRANDPA. AURA is just a way to generate (seal) the blocks.

  1. Leader elections should be implemeneted in the finality-grandpa. It's natively embedded into the Substrate.
  2. Using an off-chain worker is not necessary if you are only implementing a consensus mechanism.
  3. In Substrate, client/sc- behaves as native code, whereas frame/sp- defines the Runtime behaviour. AURA, for example, is a block-generation algorithm so it must be implemented as native code. In the meanwhile, AURA provide some hooks/functions for runtime. This is the reason why it has both code in client and frame.
  4. Still, I can't seem to find that code. But the response is in the affirmative.

[1] finality-pbft and substrate-with-pBFT

Related