diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 08de71ee831b..b93928bef60c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 } @@ -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 @@ -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, ðashConfig, cliqueConfig, nil, false, chainDb) + engine := ethconfig.CreateDefaultConsensusEngine(stack, ðashConfig, cliqueConfig, nil, false, chainDb) if gcmode := ctx.String(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" { Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name) } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index ac4486c6cba8..1d3f66e45a14 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -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. diff --git a/eth/api_backend.go b/eth/api_backend.go index 643f6369df0e..d8439d641306 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -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() } diff --git a/eth/backend.go b/eth/backend.go index 6368c0e03c56..24dc419bdbcc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -87,7 +87,7 @@ type Ethereum struct { APIBackend *EthAPIBackend - miner *miner.Miner + miner miner.IMiner gasPrice *big.Int etherbase common.Address @@ -141,7 +141,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if err != nil { return nil, err } - engine := ethconfig.CreateConsensusEngine(stack, ðashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb) + engine := config.ConsensusEngine(stack, ðashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb) eth := &Ethereum{ config: config, @@ -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} @@ -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 } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index db686c5d0875..73bf21664b1b 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -90,6 +90,7 @@ var Defaults = Config{ RPCEVMTimeout: 5 * time.Second, GPO: FullNodeGPO, RPCTxFeeCap: 1, // 1 ether + ConsensusEngine:CreateDefaultConsensusEngine, } func init() { @@ -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. @@ -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 { diff --git a/expose.go b/expose.go new file mode 100644 index 000000000000..e369faaa7f31 --- /dev/null +++ b/expose.go @@ -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) +} \ No newline at end of file diff --git a/les/client.go b/les/client.go index 9ac85ecdac6f..c9d6a5d6362e 100644 --- a/les/client.go +++ b/les/client.go @@ -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(), diff --git a/miner/interface.go b/miner/interface.go new file mode 100644 index 000000000000..460a9aba27be --- /dev/null +++ b/miner/interface.go @@ -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) +} diff --git a/miner/miner.go b/miner/miner.go index c969aec73546..6e66d169c03b 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -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 } diff --git a/params/config.go b/params/config.go index e04b16673c6b..47566276fc12 100644 --- a/params/config.go +++ b/params/config.go @@ -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" } diff --git a/params/qng_config.go b/params/qng_config.go new file mode 100644 index 000000000000..2de3b0a8bd31 --- /dev/null +++ b/params/qng_config.go @@ -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 +}