Skip to content

Commit

Permalink
Merge pull request ethereum#11 from lochjin/v1.10.21-qng
Browse files Browse the repository at this point in the history
V1.10.21 qng
  • Loading branch information
dindinw authored Aug 17, 2022
2 parents 6710942 + 25e02ea commit 229ff49
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
if ctx.Bool(FakePoWFlag.Name) {
ethashConf.PowMode = ethash.ModeFake
}
engine = ethconfig.CreateConsensusEngine(stack, config, &ethashConf, nil, false, chainDb)
engine = ethconfig.CreateDefaultConsensusEngine(stack, config, &ethashConf, nil, false, chainDb)
if gcmode := ctx.String(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
Expand Down
6 changes: 6 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,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.
func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
Expand Down
2 changes: 1 addition & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,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
13 changes: 9 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

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

Expand Down Expand Up @@ -159,7 +159,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
chainDb: chainDb,
eventMux: stack.EventMux(),
accountManager: stack.AccountManager(),
engine: ethconfig.CreateConsensusEngine(stack, chainConfig, &ethashConfig, config.Miner.Notify, config.Miner.Noverify, chainDb),
engine: config.ConsensusEngine(stack, chainConfig, &ethashConfig, config.Miner.Notify, config.Miner.Noverify, chainDb),
closeBloomHandler: make(chan struct{}),
networkID: config.NetworkId,
gasPrice: config.Miner.GasPrice,
Expand Down Expand Up @@ -241,7 +241,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
if config.Miner.External == nil {
eth.miner = miner.New(eth, &config.Miner, chainConfig, 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 @@ -490,7 +495,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
9 changes: 7 additions & 2 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The go-ethereum Authors
// 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
Expand Down Expand Up @@ -93,6 +93,7 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
ConsensusEngine:CreateDefaultConsensusEngine,
}

func init() {
Expand All @@ -116,6 +117,8 @@ func init() {
}
}

type CreateConsensusEngine func (*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine

//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 @@ -210,10 +213,12 @@ type Config struct {

// OverrideTerminalTotalDifficulty (TODO: remove after the fork)
OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"`

ConsensusEngine CreateConsensusEngine
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
func CreateDefaultConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
var engine consensus.Engine
if chainConfig.Clique != nil {
Expand Down
7 changes: 7 additions & 0 deletions expose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2017-2022 The qitmeer developers

package ethereum

import "github.com/ethereum/go-ethereum/internal/web3ext"

var Modules = web3ext.Modules
2 changes: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
reqDist: newRequestDistributor(peers, &mclock.System{}),
accountManager: stack.AccountManager(),
merger: merger,
engine: ethconfig.CreateConsensusEngine(stack, chainConfig, &config.Ethash, nil, false, chainDb),
engine: config.ConsensusEngine(stack, chainConfig, &config.Ethash, nil, false, chainDb),
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
p2pServer: stack.Server(),
Expand Down
29 changes: 29 additions & 0 deletions miner/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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(coinbase common.Address)
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
GetSealingBlockAsync(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, noTxs bool) (chan *types.Block, error)
GetSealingBlockSync(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, noTxs bool) (*types.Block, error)
}
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Config struct {
GasPrice *big.Int // Minimum gas price for mining a transaction
Recommit time.Duration // The time interval for miner to re-create mining work.
Noverify bool // Disable remote mining solution verification(only useful in ethash).
External IMiner // External miner
}

// Miner creates blocks and searches for proof-of-work values.
Expand Down

0 comments on commit 229ff49

Please sign in to comment.