From feeccdf4ec1084b38dac112ff4f86809efd7c0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 10 Apr 2017 13:24:12 +0300 Subject: consensus/clique: Proof of Authority (#3753) This PR is a prototype implementation of plugable consensus engines and the Clique PoA protocol ethereum/EIPs#225 --- eth/backend.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'eth') diff --git a/eth/backend.go b/eth/backend.go index 6c3ccb9b9..4dffa2990 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -230,6 +231,11 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data // CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine { + // If proof-of-authority is requested, set it up + if chainConfig.Clique != nil { + return clique.New(chainConfig.Clique, db) + } + // Otherwise assume proof-of-work switch { case config.PowFake: log.Warn("Ethash used in fake mode") @@ -333,6 +339,14 @@ func (s *Ethereum) StartMining(local bool) error { log.Error("Cannot start mining without etherbase", "err", err) return fmt.Errorf("etherbase missing: %v", err) } + if clique, ok := s.engine.(*clique.Clique); ok { + wallet, err := s.accountManager.Find(accounts.Account{Address: eb}) + if wallet == nil || err != nil { + log.Error("Etherbase account unavailable locally", "err", err) + return fmt.Errorf("singer missing: %v", err) + } + clique.Authorize(eb, wallet.SignHash) + } if local { // If local (CPU) mining is started, we can disable the transaction rejection // mechanism introduced to speed sync times. CPU mining on mainnet is ludicrous -- cgit v1.2.3