-
Notifications
You must be signed in to change notification settings - Fork 1
PR Review Guide
PR #166 Review Guide
This document is to help PR #166 review for Istanbul BFT to merge into Quorum.
The complete specification can be found in EIP 650
- cmd, consensus, eth, ethstats: add protocol interface into consensus to support custom messages
- params: add Istanbul consensus engine config to ChainConfig
- cmd/*: add Istanbul command line flags
- consensus/istanbul, eth: add Istanbul configuration
- node: add an interface to retrieve node key from config
- consensus: add Istanbul consensus engine interface
- consensus/istanbul: common Istanbul interfaces and types
- consensus/istanbul: Istanbul validator set implementation
- core/types: add Istanbul specific block hash calculation
- consensus/istanbul: add tests for Istanbul core
- consensus/istanbul: Istanbul core implementation
- consensus/istanbul: Istanbul consensus backend implementation
- internal/web3ext: add Istanbul JS RPC API
- core, eth, miner: Istanbul consensus integration
- cmd/*, core, params: add ottoman testnet
- miner: enable private transactions in worker
- In Istanbul BFT implementation, we introduced another message exchange protocol
64
to support IBFT muplti-phrase consensus protocol. Therefore inconsensus/consensus.go
, we've added another functionProtocol()
for all consensus implementations to return their own supported protocols. -
Handler
interface inconsensus/consensus.go
: For consensus to handle incoming messages and new head blocks as well as to set theBroadcaster
as the utility of block and message broadcasting. -
Broadcaster
interface inconsensus/protocol.go
:-
Enqueue()
: Adds a block into the fetcher queue, so the block will be inserted to blockchain through fetcher. -
FindPeers()
: Utility function to find validator peers.
-
- In
handleMsg()
ofeth/handler.go
: If the consensus engine implementsconsensus.Handler
, it would callhandler.HandleMsg
to handle the incoming message. - Istanbul implements
consensus.Handler
interface inconsensus/istanbul/backend/handler.go
.
Adds Istanbul config parameters in genesis.json
. Inside the Istanbul
configuration, Epoch
and ProposerPolicy
can be defined as well.
Sample configuration can be found in EIP 650
Adds validator running parameters. Usage details can be found in cmd/utils/flags.go
.
Adds Istanbul configuration.
Adds function in node/service.go
to return node key. We need this since we use node key's associated public key to whitelist the validator set. All consensus messages are going to be signed by the node key as well.
Adds Istanbul consensus engine interface, which inherits existing consensus engine and adds Start()
and Stop()
functions.
-
consensus/istanbul/backend.go
: Defines the application backend interface for Istanbul core implementation. -
consensus/istanbul/events.go
: Defines events which are handled in backend core handler inconsensus/istanbul/core/handler.go
.-
RequestEvent
: Posted when a proposer proposes a block. -
MessageEvent
: Posted when receiving Istanbul consensus messages, which would essentially be handled inconsensus/istanbul/core/handler.go
and dispatched to different consensus message handlers. -
FinalCommittedEvent
: Posted when there is a new chain head (a proposal is committed).
-
-
consensus/istanbul/types.go
: Defines data structures used in consensus.- Note that only
PREPREPARE
exchanges message withProposal
, other consensus phrases exchange withSubject
. Checkconsensus/istanbul/core/preprepare.go#sendPreprepare()
andconsensus/istanbul/core/prepare.go#sendPrepare()
for the comparison.
- Note that only
-
consensus/istanbul/validator.go
: Defines the collection interface/data structure for peer validators.
-
ValidatorSet
implementation: Validators are sorted by address so all validators can know who is the current proposer in each round and height.
- Istanbul block headers are different from original ethereum in:
Istanbul core implementation tests.
Istanbul core implementation.
-
consensus/istanbul/core/roundstate.go
: defines data structure for one consensus round, includinground
,sequence
,preprepare
message set,commit
message set,lockedHash
,pendingRequest
, andhasBadProposal()
function for blacklisting validators. Note that we haven't implemented blacklisting in this PR yet. -
consensus/istanbul/core/request.go
: Istanbul BFT depends onworker
to generate blocks for consensus, defined inminer/agent.go#mine()
, it callsengine.Seal()
to deal with the newly generated blocks. In Istanbul engine implementation inconsensus/istanbul/backend/engine.go#Seal()
, it postsistanbul.RequestEvent
event to start the consensus process. The event will first go throughconsensus/istanbul/core/handler.go#handleEvents()
to do some preprocessing then be dispatched tohandleRequest()
function. Since there is only one validator can be proposer, there will be only one validator can successfully broadcastPREPREPARE
message at each round. However, there are chances round change would happen, so another validator would have chance to broadcastPREPREPARE
message. To handle this,processPendingRequests()
would check the pending requests and postistanbul.RequestEvent
event again to attempt to sendPREPREPARE
.-
handleRequest()
: Tries to broadcastPREPREPARE
message if it is the proposer. -
storeRequestMsg()
: Called byconsensus/istanbul/core/handler.go#handleEvents()
to store the request to pending requests. -
processPendingRequests()
: Called when current state is changed toStateAcceptRequest
.
-
-
consensus/istanbul/core/backlog.go
: Backlog is used to store future consensus messages, which can be processed later when the receiving validator reaches the proper state. -
consensus/istanbul/core/core.go
: Implements shared core consensus utility functions.-
finalizeMessage()
: Called before broadcasting consensus message for validator to sign the message. Note that when the message isCOMMIT
message, it signsCOMMITTED_SEAL
for other validators to compose consensus proof as well. For details about consensus proof, please reference EIP 650. -
commit()
: Commits current consensus block. Before inserting to blockchain, it composes consensus proof incommittedSeals
and letconsensus/istanbul/backend/backend.go#Commit()
to handle the rest. -
startNewRound()
: Starts a new consensus round.
-
-
consensus/istanbul/core/events.go
:-
backlogEvent
: Posted when a backlog message can be processed or receiving futurePREPREPARE
message. Referenceconsensus/istanbul/core/backlog.go#processBacklog()
andconsensus/istanbul/core/preprepare.go#handlePreprepare()
. -
timeoutEvent
: Posted when round change timer expires, essentially triggersconsensus/istanbul/core/handler.go#handleTimeoutMsg()
function to handle round change timeout.
-
-
consensus/istanbul/core/handler.go
: Core handler which handlesistanbul.RequestEvent
,istanbul.MessageEvent
,istanbul.FinalCommittedEvent
,backlogEvent
, andtimeoutEvent
. -
consensus/istanbul/core/message_set.go
: Defines the data structure to store consensus message set for each message type. For example, in each round there will be one message set forPREPREPARE
messages, one message set forPREPARE
messages, and one message set forCOMMIT
messages. - Consensus message handling: Pre-prepare, Prepare, and Commit.
- Pre-prepare:
consensus/istanbul/core/preprepare.go
, functionhandlePreprepare()
handlesPREPREPARE
message. - Prepare:
consensus/istanbul/core/prepare.go
, functionhandlePrepare()
handlesPREPARE
message. Upon receiving2 * F
PREPARE
messages, the receiving validator entersPREPARED
state. Note that it checksIsHashLocked()
for block locking mechanism. Please reference EIP 650 "Block locking mechanism" section for detail. - Commit:
consensus/istanbul/core/commit.go
, functionhandleCommit()
handlesCOMMIT
message. Upon receiving2 * F
COMMIT
messages, the receiving validator entersCOMMITTED
state, as defined inconsensus/istanbul/core/core.go#commit()
. Then it inserts the block into blockchain, as inconsensus/istanbul/backend/backend.go#Commit()
, which callsEnqueue()
to enqueue the block to fetcher through its broadcaster. - Final committed:
consensus/istanbul/core/commit.go
, starts a new consensus round.
- Pre-prepare:
-
consensus/istanbul/core/roundchange.go
: Implements round change protocol. Details can be found in EIP 650 "Round change flow" section. -
consensus/istanbul/core/types.go
: Defines consensus message type.
Istanbul consensus backend implementation.
-
consensus/istanbul/backend/api.go
: Istanbul command line api. -
consensus/istanbul/backend/snapshot.go
: DefineSnapshot
data structure for handling validator voting in each epoch. The data would be stored in local db. -
consensus/istanbul/backend/backend.go
: Implementsistanbul.Backend
interface. -
consensus/istanbul/backend/engine.go
: Implementsconsensus.Istanbul
interfaces which includesconsensus.Engine
interface. -
consensus/istanbul/backend/handler.go
: Implementsconsensus.Handler.HandleMsg
, which handles protocol64
messages and postsistanbul.MessageEvent
events forconsensus/istanbul/core/handler.go
to handle consensus messages.
Implements Istanbul console commands.
Enables Istanbul in current geth.
Adds Ottoman testnet configuration.
Enables private transactions in worker.