Skip to content

Commit

Permalink
Merge pull request ethereum#27 from lochjin/v1.12.0-qng
Browse files Browse the repository at this point in the history
V1.12.0 qng
  • Loading branch information
dindinw authored Jun 2, 2023
2 parents e501b3b + fefd13d commit 3ddc148
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 14 deletions.
14 changes: 9 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,10 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
Fatalf("Failed to register the Ethereum service: %v", err)
}
stack.RegisterAPIs(tracers.APIs(backend.ApiBackend))
if err := lescatalyst.Register(stack, backend); err != nil {
Fatalf("Failed to register the Engine API service: %v", err)
if backend.BlockChain().Config().TerminalTotalDifficulty != nil {
if err := lescatalyst.Register(stack, backend); err != nil {
Fatalf("Failed to register the Engine API service: %v", err)
}
}
return backend.ApiBackend, nil
}
Expand All @@ -1914,8 +1916,10 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
Fatalf("Failed to create the LES server: %v", err)
}
}
if err := ethcatalyst.Register(stack, backend); err != nil {
Fatalf("Failed to register the Engine API service: %v", err)
if backend.BlockChain().Config().TerminalTotalDifficulty != nil {
if err := ethcatalyst.Register(stack, backend); err != nil {
Fatalf("Failed to register the Engine API service: %v", err)
}
}
stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
return backend.APIBackend, backend
Expand Down Expand Up @@ -2134,7 +2138,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if err != nil {
Fatalf("%v", err)
}
engine, err := ethconfig.CreateConsensusEngine(config, chainDb)
engine, err := ethconfig.CreateDefaultConsensusEngine(config, chainDb)
if err != nil {
Fatalf("%v", err)
}
Expand Down
6 changes: 6 additions & 0 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ func (pool *TxPool) Has(hash common.Hash) bool {
return pool.all.Get(hash) != nil
}

func (pool *TxPool) RemoveTx(hash common.Hash, outofbound bool) {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.removeTx(hash, outofbound)
}

// removeTx removes a single transaction from the queue, moving all subsequent
// transactions back to the future queue.
// Returns the number of transactions removed from the pending queue.
Expand Down
5 changes: 5 additions & 0 deletions core/txpool/txpool_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package txpool

func (pool *TxPool) All() *lookup {
return pool.all
}
2 changes: 1 addition & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (b *EthAPIBackend) CurrentHeader() *types.Header {
return b.eth.blockchain.CurrentHeader()
}

func (b *EthAPIBackend) Miner() *miner.Miner {
func (b *EthAPIBackend) Miner() miner.IMiner {
return b.eth.Miner()
}

Expand Down
14 changes: 10 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

miner *miner.Miner
miner miner.IMiner
gasPrice *big.Int
etherbase common.Address

Expand Down Expand Up @@ -138,10 +138,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
engine, err := config.ConsensusEngine(chainConfig, chainDb)
if err != nil {
return nil, err
}

eth := &Ethereum{
config: config,
merger: consensus.NewMerger(chainDb),
Expand Down Expand Up @@ -224,7 +225,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, &config.Miner, eth.blockchain.Config(), eth.EventMux(), eth.engine, eth.isLocalBlock)
if config.Miner.External == nil {
eth.miner = miner.New(eth, &config.Miner, eth.blockchain.Config(), eth.EventMux(), eth.engine, eth.isLocalBlock)
} else {
eth.miner = config.Miner.External
}

eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
Expand Down Expand Up @@ -447,7 +453,7 @@ func (s *Ethereum) StopMining() {
}

func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) Miner() miner.IMiner { return s.miner }

func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
Expand Down
7 changes: 6 additions & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
ConsensusEngine: CreateDefaultConsensusEngine,
}

type CreateConsensusEngine func(*params.ChainConfig, ethdb.Database) (consensus.Engine, error)

//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go

// Config contains configuration options for of the ETH and LES protocols.
Expand Down Expand Up @@ -162,12 +165,14 @@ type Config struct {

// OverrideCancun (TODO: remove after the fork)
OverrideCancun *uint64 `toml:",omitempty"`

ConsensusEngine CreateConsensusEngine
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
// Clique is allowed for now to live standalone, but ethash is forbidden and can
// only exist on already merged networks.
func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
func CreateDefaultConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
// If proof-of-authority is requested, set it up
if config.Clique != nil {
return beacon.New(clique.New(config.Clique, db)), nil
Expand Down
16 changes: 16 additions & 0 deletions expose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2017-2022 The qitmeer developers

package ethereum

import (
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/internal/web3ext"
"github.com/urfave/cli/v2"
"math/big"
)

var Modules = web3ext.Modules

func GlobalBig(ctx *cli.Context, name string) *big.Int {
return flags.GlobalBig(ctx, name)
}
2 changes: 0 additions & 2 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,6 @@ web3._extend({
new web3._extend.Method({
name: 'start',
call: 'miner_start',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'stop',
Expand Down
2 changes: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
return nil, genesisErr
}
engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
engine, err := ethconfig.CreateDefaultConsensusEngine(chainConfig, chainDb)
if err != nil {
return nil, err
}
Expand Down
28 changes: 28 additions & 0 deletions miner/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package miner

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/event"
"time"
)

type IMiner interface {
Start()
Stop()
Close()
Mining() bool
Hashrate() uint64
SetExtra(extra []byte) error
SetRecommitInterval(interval time.Duration)
Pending() (*types.Block, *state.StateDB)
PendingBlock() *types.Block
PendingBlockAndReceipts() (*types.Block, types.Receipts)
SetEtherbase(addr common.Address)
SetGasCeil(ceil uint64)
EnablePreseal()
DisablePreseal()
SubscribePendingLogs(ch chan<- []*types.Log) event.Subscription
BuildPayload(args *BuildPayloadArgs) (*Payload, error)
}
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Config struct {
GasCeil uint64 // Target gas ceiling for mined blocks.
GasPrice *big.Int // Minimum gas price for mining a transaction
Recommit time.Duration // The time interval for miner to re-create mining work.
External IMiner // External miner

NewPayloadTimeout time.Duration // The maximum time allowance for creating a new payload
}
Expand Down
12 changes: 12 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ func (c *ChainConfig) Description() string {
}
banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network)
switch {
case IsQngNetwork(c.ChainID):
banner += "Consensus: MeerDAG (proof-of-work)\n"
return QngEIPsBanner(banner, c)
case IsAmanaNetwork(c.ChainID):
banner += "Consensus: Amana (proof-of-authority)\n"
return QngEIPsBanner(banner, c)
case IsFlanaNetwork(c.ChainID):
banner += "Consensus: Flana (rollup)\n"
return QngEIPsBanner(banner, c)
case IsMizanaNetwork(c.ChainID):
banner += "Consensus: Mizana (ZK rollup)\n"
return QngEIPsBanner(banner, c)
case c.Ethash != nil:
if c.TerminalTotalDifficulty == nil {
banner += "Consensus: Ethash (proof-of-work)\n"
Expand Down
Loading

0 comments on commit 3ddc148

Please sign in to comment.