diff options
-rw-r--r-- | consensus/dexcon/api.go | 26 | ||||
-rw-r--r-- | consensus/dexcon/dexcon.go | 133 | ||||
-rw-r--r-- | eth/backend.go | 5 | ||||
-rw-r--r-- | params/config.go | 17 | ||||
m--------- | tests/testdata | 0 |
5 files changed, 178 insertions, 3 deletions
diff --git a/consensus/dexcon/api.go b/consensus/dexcon/api.go new file mode 100644 index 000000000..6f314b96b --- /dev/null +++ b/consensus/dexcon/api.go @@ -0,0 +1,26 @@ +// Copyright 2018 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 dexcon + +// API exposes ethash related methods for the RPC interface. +type API struct { + dexcon *Dexcon +} + +func (api *API) Hello() error { + return nil +} diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go new file mode 100644 index 000000000..bbdd06ed8 --- /dev/null +++ b/consensus/dexcon/dexcon.go @@ -0,0 +1,133 @@ +// Copyright 2017 The DEXON 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 dexcon + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rpc" +) + +// Dexcon is a delegated proof-of-stake consensus engine. +type Dexcon struct { + config *params.DexconConfig +} + +// New creates a Clique proof-of-authority consensus engine with the initial +// signers set to the ones provided by the user. +func New(config *params.DexconConfig) *Dexcon { + return &Dexcon{ + config: config, + } +} + +// Author implements consensus.Engine, returning the Ethereum address recovered +// from the signature in the header's extra-data section. +func (d *Dexcon) Author(header *types.Header) (common.Address, error) { + return common.Address{}, nil +} + +// VerifyHeader checks whether a header conforms to the consensus rules. +func (d *Dexcon) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error { + return nil +} + +// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. The +// method returns a quit channel to abort the operations and a results channel to +// retrieve the async verifications (the order is that of the input slice). +func (d *Dexcon) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { + return make(chan struct{}), make(chan error) +} + +// verifyHeader checks whether a header conforms to the consensus rules.The +// caller may optionally pass in a batch of parents (ascending order) to avoid +// looking those up from the database. This is useful for concurrently verifying +// a batch of new headers. +func (d *Dexcon) verifyHeader(chain consensus.ChainReader, header *types.Header, parents []*types.Header) error { + return nil +} + +// verifyCascadingFields verifies all the header fields that are not standalone, +// rather depend on a batch of previous headers. The caller may optionally pass +// in a batch of parents (ascending order) to avoid looking those up from the +// database. This is useful for concurrently verifying a batch of new headers. +func (d *Dexcon) verifyCascadingFields(chain consensus.ChainReader, header *types.Header, parents []*types.Header) error { + return nil +} + +// VerifyUncles implements consensus.Engine, always returning an error for any +// uncles as this consensus mechanism doesn't permit uncles. +func (d *Dexcon) VerifyUncles(chain consensus.ChainReader, block *types.Block) error { + return nil +} + +// VerifySeal implements consensus.Engine, checking whether the signature contained +// in the header satisfies the consensus protocol requirements. +func (d *Dexcon) VerifySeal(chain consensus.ChainReader, header *types.Header) error { + return nil +} + +// Prepare implements consensus.Engine, preparing all the consensus fields of the +// header for running the transactions on top. +func (d *Dexcon) Prepare(chain consensus.ChainReader, header *types.Header) error { + return nil +} + +// Finalize implements consensus.Engine, ensuring no uncles are set, nor block +// rewards given, and returns the final block. +func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { + return nil, nil +} + +// Seal implements consensus.Engine, attempting to create a sealed block using +// the local signing credentials. +func (d *Dexcon) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { + return nil +} + +// SealHash returns the hash of a block prior to it being sealed. +func (d *Dexcon) SealHash(header *types.Header) (hash common.Hash) { + return common.Hash{} +} + +// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty +// that a new block should have based on the previous blocks in the chain and the +// current signer. +func (d *Dexcon) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int { + return big.NewInt(0) +} + +// Close implements consensus.Engine. It's a noop for clique as there is are no background threads. +func (d *Dexcon) Close() error { + return nil +} + +// APIs implements consensus.Engine, returning the user facing RPC API to allow +// controlling the signer voting. +func (d *Dexcon) APIs(chain consensus.ChainReader) []rpc.API { + return []rpc.API{{ + Namespace: "dexcon", + Version: "1.0", + Service: &API{dexcon: d}, + Public: false, + }} +} diff --git a/eth/backend.go b/eth/backend.go index 2a9d56c5c..19f48662d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -30,6 +30,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/clique" + "github.com/ethereum/go-ethereum/consensus/dexcon" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/bloombits" @@ -224,6 +225,10 @@ 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, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { // If proof-of-authority is requested, set it up + if chainConfig.Dexcon != nil { + return dexcon.New(chainConfig.Dexcon) + } + // If proof-of-authority is requested, set it up if chainConfig.Clique != nil { return clique.New(chainConfig.Clique, db) } diff --git a/params/config.go b/params/config.go index 254508c0a..3cf86e9be 100644 --- a/params/config.go +++ b/params/config.go @@ -142,16 +142,16 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil} + AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} + AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} - TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil} + TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} TestRules = TestChainConfig.Rules(new(big.Int)) ) @@ -195,6 +195,7 @@ type ChainConfig struct { // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` Clique *CliqueConfig `json:"clique,omitempty"` + Dexcon *DexconConfig `json:"dexcon,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing. @@ -216,6 +217,16 @@ func (c *CliqueConfig) String() string { return "clique" } +// DexconConfig is the consensus engine configs for DEXON consensus. +type DexconConfig struct { + GovernanceContractAddress string +} + +// String implements the stringer interface, returning the consensus engine details. +func (c *DexconConfig) String() string { + return "dexcon" +} + // String implements the fmt.Stringer interface. func (c *ChainConfig) String() string { var engine interface{} diff --git a/tests/testdata b/tests/testdata -Subproject 6b85703b568f4456582a00665d8a3e5c3b20b48 +Subproject 3721fd6d83366103fe23dd29bbbf34bb80f9eb9 |