Skip to content

Commit

Permalink
Merge pull request ethereum#24 from lochjin/v1.11.5-qng
Browse files Browse the repository at this point in the history
V1.11.5 qng
  • Loading branch information
dindinw authored Mar 31, 2023
2 parents a38f410 + 814a356 commit 4fef9c1
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 13 deletions.
14 changes: 9 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1995,8 +1995,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 @@ -2010,8 +2012,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 @@ -2234,7 +2238,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if ctx.Bool(FakePoWFlag.Name) {
ethashConfig.PowMode = ethash.ModeFake
}
engine := ethconfig.CreateConsensusEngine(stack, &ethashConfig, cliqueConfig, nil, false, chainDb)
engine := ethconfig.CreateDefaultConsensusEngine(stack, &ethashConfig, cliqueConfig, 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/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,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
2 changes: 1 addition & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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 @@ -87,7 +87,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

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

Expand Down Expand Up @@ -141,7 +141,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
engine := ethconfig.CreateConsensusEngine(stack, &ethashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb)
engine := config.ConsensusEngine(stack, &ethashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb)

eth := &Ethereum{
config: config,
Expand Down Expand Up @@ -230,7 +230,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 @@ -464,7 +469,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
8 changes: 6 additions & 2 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
ConsensusEngine:CreateDefaultConsensusEngine,
}

func init() {
Expand All @@ -113,6 +114,7 @@ func init() {
}
}

type CreateConsensusEngine func (*node.Node, *ethash.Config, *params.CliqueConfig, []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 @@ -207,10 +209,12 @@ type Config struct {

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

ConsensusEngine CreateConsensusEngine
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
func CreateConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// CreateDefaultConsensusEngine creates a consensus engine for the given chain configuration.
func CreateDefaultConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
var engine consensus.Engine
if cliqueConfig != 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: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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, &config.Ethash, chainConfig.Clique, nil, false, chainDb),
engine: config.ConsensusEngine(stack, &config.Ethash, chainConfig.Clique, nil, false, chainDb),
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
p2pServer: stack.Server(),
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 @@ -54,6 +54,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

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 @@ -498,6 +498,18 @@ func (c *ChainConfig) Description() string {
} else {
banner += "Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n"
}
case IsQngNetwork(c.ChainID):
banner += "Consensus: MeerDAG (proof-of-work)\n"
return banner
case IsAmanaNetwork(c.ChainID):
banner += "Consensus: Amana (proof-of-authority)\n"
return banner
case IsFlanaNetwork(c.ChainID):
banner += "Consensus: Flana (rollup)\n"
return banner
case IsMizanaNetwork(c.ChainID):
banner += "Consensus: Mizana (ZK rollup)\n"
return banner
default:
banner += "Consensus: unknown\n"
}
Expand Down
123 changes: 123 additions & 0 deletions params/qng_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package params

import "math/big"

type MeerChainConfig struct {
ChainID *big.Int // chainId identifies the current chain and is used for replay protection
}

var (
QngMainnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(813),
}
QngTestnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8131),
}
QngMixnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8132),
}
QngPrivnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8133),
}

AmanaChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8134),
}
AmanaTestnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81341),
}
AmanaMixnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81342),
}
AmanaPrivnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81343),
}

FlanaChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8135),
}
FlanaTestnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81351),
}
FlanaMixnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81352),
}
FlanaPrivnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81353),
}

MizanaChainConfig = &MeerChainConfig{
ChainID: big.NewInt(8136),
}
MizanaTestnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81361),
}
MizanaMixnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81362),
}
MizanaPrivnetChainConfig = &MeerChainConfig{
ChainID: big.NewInt(81363),
}
)

func init() {
NetworkNames[QngMainnetChainConfig.ChainID.String()] = "qng"
NetworkNames[QngTestnetChainConfig.ChainID.String()] = "qng-test"
NetworkNames[QngMixnetChainConfig.ChainID.String()] = "qng-mix"
NetworkNames[QngPrivnetChainConfig.ChainID.String()] = "qng-priv"

NetworkNames[AmanaChainConfig.ChainID.String()] = "amana"
NetworkNames[AmanaTestnetChainConfig.ChainID.String()] = "amana-test"
NetworkNames[AmanaMixnetChainConfig.ChainID.String()] = "amana-mix"
NetworkNames[AmanaPrivnetChainConfig.ChainID.String()] = "amana-priv"

NetworkNames[FlanaChainConfig.ChainID.String()] = "flana"
NetworkNames[FlanaTestnetChainConfig.ChainID.String()] = "flana-test"
NetworkNames[FlanaMixnetChainConfig.ChainID.String()] = "flana-mix"
NetworkNames[FlanaPrivnetChainConfig.ChainID.String()] = "flana-priv"

NetworkNames[MizanaChainConfig.ChainID.String()] = "mizana"
NetworkNames[MizanaTestnetChainConfig.ChainID.String()] = "mizana-test"
NetworkNames[MizanaMixnetChainConfig.ChainID.String()] = "mizana-mix"
NetworkNames[MizanaPrivnetChainConfig.ChainID.String()] = "mizana-priv"
}

func IsQngNetwork(chainID *big.Int) bool {
if chainID == QngMainnetChainConfig.ChainID ||
chainID == QngTestnetChainConfig.ChainID ||
chainID == QngMixnetChainConfig.ChainID ||
chainID == QngPrivnetChainConfig.ChainID {
return true
}
return false
}

func IsAmanaNetwork(chainID *big.Int) bool {
if chainID == AmanaChainConfig.ChainID ||
chainID == AmanaTestnetChainConfig.ChainID ||
chainID == AmanaMixnetChainConfig.ChainID ||
chainID == AmanaPrivnetChainConfig.ChainID {
return true
}
return false
}

func IsFlanaNetwork(chainID *big.Int) bool {
if chainID == FlanaChainConfig.ChainID ||
chainID == FlanaTestnetChainConfig.ChainID ||
chainID == FlanaMixnetChainConfig.ChainID ||
chainID == FlanaPrivnetChainConfig.ChainID {
return true
}
return false
}

func IsMizanaNetwork(chainID *big.Int) bool {
if chainID == MizanaChainConfig.ChainID ||
chainID == MizanaTestnetChainConfig.ChainID ||
chainID == MizanaMixnetChainConfig.ChainID ||
chainID == MizanaPrivnetChainConfig.ChainID {
return true
}
return false
}

0 comments on commit 4fef9c1

Please sign in to comment.