-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consensus: add Istanbul BFT #166
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
74b4c40
cmd, consensus, eth, ethstats: add protocol interface into consensus …
markya0616 d60b0e2
params: add Istanbul consensus engine config to ChainConfig
markya0616 9a96d96
cmd/*: add Istanbul command line flags
bailantaotao 2da9aa2
consensus/istanbul, eth: add Istanbul configuration
markya0616 0390eec
node: add an interface to retrieve node key from config
59b636e
consensus: add Istanbul consensus engine interface
markya0616 11a4e96
consensus/istanbul: common Istanbul interfaces and types
markya0616 0281fa2
consensus/istanbul: Istanbul validator set implementation
markya0616 c05faf4
consensus/istanbul: Istanbul core implementation
markya0616 7d1a4b3
consensus/istanbul: add tests for Istanbul core
markya0616 bac4ff3
core/types: add Istanbul specific block hash calculation
bailantaotao 8831a46
consensus/istanbul: Istanbul consensus backend implementation
markya0616 1f8266b
internal/web3ext: add Istanbul JS RPC API
bailantaotao b3ecfcc
core, eth, miner: Istanbul consensus integration
markya0616 60de7e5
cmd/*, core, params: add ottoman testnet
markya0616 67ca428
miner: enable private transactions in worker
markya0616 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/state" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/p2p" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
@@ -90,6 +91,21 @@ type Engine interface { | |
|
||
// APIs returns the RPC APIs this consensus engine provides. | ||
APIs(chain ChainReader) []rpc.API | ||
|
||
// Protocol returns the protocol for this consensus | ||
Protocol() Protocol | ||
} | ||
|
||
// Handler should be implemented is the consensus needs to handle and send peer's message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo? Should "is" be "if"? |
||
type Handler interface { | ||
// NewChainHead handles a new head block comes | ||
NewChainHead() error | ||
|
||
// HandleMsg handles a message from peer | ||
HandleMsg(address common.Address, data p2p.Msg) (bool, error) | ||
|
||
// SetBroadcaster sets the broadcaster to send message to peers | ||
SetBroadcaster(Broadcaster) | ||
} | ||
|
||
// PoW is a consensus engine based on proof-of-work. | ||
|
@@ -99,3 +115,14 @@ type PoW interface { | |
// Hashrate returns the current mining hashrate of a PoW consensus engine. | ||
Hashrate() float64 | ||
} | ||
|
||
// Istanbul is a consensus engine to avoid byzantine failure | ||
type Istanbul interface { | ||
Engine | ||
|
||
// Start starts the engine | ||
Start(chain ChainReader, currentBlock func() *types.Block, hasBadBlock func(hash common.Hash) bool) error | ||
|
||
// Stop stops the engine | ||
Stop() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2017 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package istanbul | ||
|
||
import ( | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/event" | ||
) | ||
|
||
// Backend provides application specific functions for Istanbul core | ||
type Backend interface { | ||
// Address returns the owner's address | ||
Address() common.Address | ||
|
||
// Validators returns the validator set | ||
Validators(proposal Proposal) ValidatorSet | ||
|
||
// EventMux returns the event mux in backend | ||
EventMux() *event.TypeMux | ||
|
||
// Broadcast sends a message to all validators (include self) | ||
Broadcast(valSet ValidatorSet, payload []byte) error | ||
|
||
// Gossip sends a message to all validators (exclude self) | ||
Gossip(valSet ValidatorSet, payload []byte) error | ||
|
||
// Commit delivers an approved proposal to backend. | ||
// The delivered proposal will be put into blockchain. | ||
Commit(proposal Proposal, seals [][]byte) error | ||
|
||
// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, | ||
// the time difference of the proposal and current time is also returned. | ||
Verify(Proposal) (time.Duration, error) | ||
|
||
// Sign signs input data with the backend's private key | ||
Sign([]byte) ([]byte, error) | ||
|
||
// CheckSignature verifies the signature by checking if it's signed by | ||
// the given validator | ||
CheckSignature(data []byte, addr common.Address, sig []byte) error | ||
|
||
// LastProposal retrieves latest committed proposal and the address of proposer | ||
LastProposal() (Proposal, common.Address) | ||
|
||
// HasPropsal checks if the combination of the given hash and height matches any existing blocks | ||
HasPropsal(hash common.Hash, number *big.Int) bool | ||
|
||
// GetProposer returns the proposer of the given block height | ||
GetProposer(number uint64) common.Address | ||
|
||
// ParentValidators returns the validator set of the given proposal's parent block | ||
ParentValidators(proposal Proposal) ValidatorSet | ||
|
||
// HasBadBlock returns whether the block with the hash is a bad block | ||
HasBadProposal(hash common.Hash) bool | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we might want to use another (higher) number that's less likely to cause a conflict in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the upstream codebase. We submit the same code to geth, so if that gets merged, we are going to grab network id 5. If we eventually get a larger number, I think we can update it here accordingly.