Skip to content

Commit

Permalink
Merge pull request ethereum#41 from lochjin/v1.14.2-qng
Browse files Browse the repository at this point in the history
V1.14.2 qng
  • Loading branch information
dindinw authored May 12, 2024
2 parents 35b2d07 + d1d4e60 commit 77e64a7
Show file tree
Hide file tree
Showing 14 changed files with 292 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 @@ -2150,7 +2150,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
20 changes: 20 additions & 0 deletions core/txpool/legacypool/legacypool_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package legacypool

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

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

func (pool *LegacyPool) All() *lookup {
return pool.all
}

func (pool *LegacyPool) AddRemotesSync(txs []*types.Transaction) []error {
return pool.addRemotesSync(txs)
}
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 (p *TxPool) Subpools() []SubPool {
return p.subpools
}
2 changes: 1 addition & 1 deletion crypto/signature_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"errors"
"fmt"

secp256k1 "github.com/Qitmeer/go-secp256k1"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)

// Ecrecover returns the uncompressed public key that created the given signature.
Expand Down
13 changes: 9 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

miner *miner.Miner
miner miner.IMiner
gasPrice *big.Int

networkID uint64
Expand Down Expand Up @@ -146,7 +146,7 @@ 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
}
Expand Down Expand Up @@ -260,7 +260,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, config.Miner, eth.engine)
if config.Miner.External == nil {
eth.miner = miner.New(eth, config.Miner, eth.engine)
} 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 @@ -348,7 +353,7 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}

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 @@ -67,8 +67,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 ETH and LES protocols.
Expand Down Expand Up @@ -163,12 +166,14 @@ type Config struct {

// OverrideVerkle (TODO: remove after the fork)
OverrideVerkle *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) {
// Geth v1.14.0 dropped support for non-merged networks in any consensus
// mode. If such a network is requested, reject startup.
if !config.TerminalTotalDifficultyPassed {
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)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/ethereum/go-ethereum

go 1.21
go 1.22.3

require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
github.com/Microsoft/go-winio v0.6.1
github.com/Qitmeer/go-secp256k1 v0.5.1
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/aws/aws-sdk-go-v2 v1.21.2
github.com/aws/aws-sdk-go-v2/config v1.18.45
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Qitmeer/go-secp256k1 v0.5.1 h1:t3u4VMSz7LRn9Ki1lecG7tyTNwbLGILt1CwdOAA5N7M=
github.com/Qitmeer/go-secp256k1 v0.5.1/go.mod h1:AkrSQDAMwdV4+pXUQnEAPvPbUiIN4DAHMAm0ueneJB8=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
Expand Down
2 changes: 2 additions & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ 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

}

// DefaultConfig contains default settings for miner.
Expand Down
28 changes: 28 additions & 0 deletions miner/miner_qng.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/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
"math/big"
)

type IMiner interface {
SetExtra(extra []byte) error
Pending() (*types.Block, types.Receipts, *state.StateDB)
SetGasCeil(ceil uint64)
SetGasTip(tip *big.Int) error
BuildPayload(args *BuildPayloadArgs) (*Payload, error)
}

type TransactionsByPriceAndNonce interface {
Peek() (*txpool.LazyTransaction, *uint256.Int)
Shift()
Pop()
}

func NewTransactionsByPriceAndNonce(signer types.Signer, txs map[common.Address][]*txpool.LazyTransaction, baseFee *big.Int) TransactionsByPriceAndNonce {
return newTransactionsByPriceAndNonce(signer, txs, baseFee)
}
12 changes: 12 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,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
187 changes: 187 additions & 0 deletions params/config_qng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package params

import (
"fmt"
"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.Cmp(QngMainnetChainConfig.ChainID) == 0 ||
chainID.Cmp(QngTestnetChainConfig.ChainID) == 0 ||
chainID.Cmp(QngMixnetChainConfig.ChainID) == 0 ||
chainID.Cmp(QngPrivnetChainConfig.ChainID) == 0 {
return true
}
return false
}

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

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

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

func QngEIPsBanner(banner string, c *ChainConfig) string {
banner += "\n"

// Create a list of forks with a short description of them. Forks that only
// makes sense for mainnet should be optional at printing to avoid bloating
// the output for testnets and private networks.
banner += "Pre-Merge hard forks (block based):\n"
banner += fmt.Sprintf(" - Homestead: #%-8v (EIP-606 Requires:EIP-2, EIP-7, EIP-8)\n", c.HomesteadBlock)
if c.DAOForkBlock != nil {
banner += fmt.Sprintf(" - DAO Fork: #%-8v (EIP-779 Requires:EIP-606)\n", c.DAOForkBlock)
}
banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): #%-8v (EIP-608 Requires:EIP-150, EIP-779)\n", c.EIP150Block)
banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): #%-8v (EIP-607 Requires:EIP-155, EIP-160, EIP-161, EIP-170, EIP-608)\n", c.EIP155Block)
banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): #%-8v (EIP-607 Requires:EIP-155, EIP-160, EIP-161, EIP-170, EIP-608)\n", c.EIP155Block)
banner += fmt.Sprintf(" - Byzantium: #%-8v (EIP-609 Requires:EIP-100, EIP-140, EIP-196, EIP-197, EIP-198, EIP-211, EIP-214, EIP-607, EIP-649, EIP-658)\n", c.ByzantiumBlock)
banner += fmt.Sprintf(" - Constantinople: #%-8v (EIP-1013 Requires:EIP-145, EIP-609, EIP-1014, EIP-1052, EIP-1234, EIP-1283)\n", c.ConstantinopleBlock)
banner += fmt.Sprintf(" - Petersburg: #%-8v (EIP-1716 Requires:EIP-1013, EIP-1283)\n", c.PetersburgBlock)
banner += fmt.Sprintf(" - Istanbul: #%-8v (EIP-1679 Requires:EIP-152, EIP-1108, EIP-1344, EIP-1716, EIP-1884, EIP-2028, EIP-2200)\n", c.IstanbulBlock)
if c.MuirGlacierBlock != nil {
banner += fmt.Sprintf(" - Muir Glacier: #%-8v (EIP-2387 Requires:EIP-1679, EIP-2384)\n", c.MuirGlacierBlock)
}
banner += fmt.Sprintf(" - Berlin: #%-8v (EIP-2565 EIP-2929 EIP-2718 EIP-2930 Requires:EIP-198)\n", c.BerlinBlock)
banner += fmt.Sprintf(" - London: #%-8v (EIP-1559 EIP-3198 EIP-3529 EIP-3541 EIP-3554 Requires:EIP-2718, EIP-2930, EIP-2200, EIP-2929, EIP-2930)\n", c.LondonBlock)
if c.ArrowGlacierBlock != nil {
banner += fmt.Sprintf(" - Arrow Glacier: #%-8v (EIP-4345)\n", c.ArrowGlacierBlock)
}
if c.GrayGlacierBlock != nil {
banner += fmt.Sprintf(" - Gray Glacier: #%-8v (EIP-5133)\n", c.GrayGlacierBlock)
}
banner += "\n"

// Add a special section for the merge as it's non-obvious
if c.TerminalTotalDifficulty == nil {
banner += "The Merge is not yet available for this network!\n"
banner += " - Hard-fork specification: EIP-3675 EIP-4399 Requires:EIP-2124\n"
} else {
banner += "Merge configured:\n"
banner += " - Hard-fork specification: EIP-3675 EIP-4399 Requires:EIP-2124\n"
banner += fmt.Sprintf(" - Network known to be merged: %v\n", c.TerminalTotalDifficultyPassed)
banner += fmt.Sprintf(" - Total terminal difficulty: %v\n", c.TerminalTotalDifficulty)
if c.MergeNetsplitBlock != nil {
banner += fmt.Sprintf(" - Merge netsplit block: #%-8v\n", c.MergeNetsplitBlock)
}
}
banner += "\n"

// Create a list of forks post-merge
banner += "Post-Merge hard forks (timestamp based):\n"
if c.ShanghaiTime != nil {
banner += fmt.Sprintf(" - Shanghai: @%-10v (EIP-3651 EIP-3855 EIP-3860 EIP-4895 EIP-6049 Requires:EIP-2929, EIP-170)\n", *c.ShanghaiTime)
}
if c.CancunTime != nil {
banner += fmt.Sprintf(" - Cancun: @%-10v\n", *c.CancunTime)
}
if c.PragueTime != nil {
banner += fmt.Sprintf(" - Prague: @%-10v\n", *c.PragueTime)
}

return banner
}
Loading

0 comments on commit 77e64a7

Please sign in to comment.