Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:optimize chain config #807

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions consensus/forks/cancunfork.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package forks

import (
"github.com/Qitmeer/qng/core/protocol"
"github.com/Qitmeer/qng/params"
"github.com/ethereum/go-ethereum/common"
"math"
"math/big"
)

const (
// TODO:Future decision on whether to start
// Support cancun height
CancunForkEvmHeight = math.MaxInt64
)

func IsCancunForkHeight(height int64) bool {
if params.ActiveNetParams.Net == protocol.PrivNet {
return true
}
return height >= CancunForkEvmHeight
}

func GetCancunForkDifficulty(height int64) *big.Int {
if IsCancunForkHeight(height) {
func GetCancunForkDifficulty(number *big.Int) *big.Int {
if params.ActiveNetParams.IsCancunFork(number) {
return common.Big0
}
return common.Big1
Expand Down
20 changes: 0 additions & 20 deletions consensus/forks/emptyblockfork.go

This file was deleted.

24 changes: 0 additions & 24 deletions consensus/forks/gaslimitfork.go

This file was deleted.

27 changes: 0 additions & 27 deletions consensus/forks/meerchangefork.go

This file was deleted.

37 changes: 3 additions & 34 deletions consensus/forks/meerevmfork.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package forks

import (
"github.com/Qitmeer/qng/core/protocol"
"github.com/Qitmeer/qng/core/types"
"github.com/Qitmeer/qng/engine/txscript"
"github.com/Qitmeer/qng/params"
)

const (
// MeerEVM is enabled and new subsidy calculation
MeerEVMForkMainHeight = 951100

// What main height can transfer the locked utxo in genesis to MeerEVM
// Must after MeerEVMForkMainHeight
MeerEVMUTXOUnlockMainHeight = 1200000

// 21024000000000000 (Total)-5051813000000000 (locked genesis)-1215912000000000 (meerevm genesis) = 14756275000000000
MeerEVMForkTotalSubsidy = 14756275000000000

Expand All @@ -32,13 +24,11 @@ const (
)

func IsVaildEVMUTXOUnlockTx(tx *types.Transaction, ip *types.TxInput, mainHeight int64) bool {
if params.ActiveNetParams.Net != protocol.MainNet {
return false
}
if mainHeight < MeerEVMForkMainHeight ||
mainHeight < MeerEVMUTXOUnlockMainHeight {
if !params.ActiveNetParams.IsMeerEVMFork(mainHeight) ||
!params.ActiveNetParams.IsMeerUTXOFork(mainHeight) {
return false
}

if !types.IsCrossChainExportTx(tx) {
return false
}
Expand Down Expand Up @@ -68,24 +58,3 @@ func IsMaxLockUTXOInGenesis(op *types.TxOutPoint) bool {
}
return false
}

func IsMeerEVMForkHeight(mainHeight int64) bool {
if params.ActiveNetParams.Net != protocol.MainNet {
return false
}
return mainHeight >= MeerEVMForkMainHeight
}

func IsMeerEVMUTXOHeight(mainHeight int64) bool {
if params.ActiveNetParams.Net != protocol.MainNet {
return false
}
return mainHeight >= MeerEVMUTXOUnlockMainHeight
}

func IsBeforeMeerEVMForkHeight(mainHeight int64) bool {
if params.ActiveNetParams.Net != protocol.MainNet {
return false
}
return mainHeight < MeerEVMForkMainHeight
}
6 changes: 3 additions & 3 deletions core/blockchain/subsidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewSubsidyCache(blocks int64, params *params.Params) *SubsidyCache {
//
// Safe for concurrent access.
func (s *SubsidyCache) CalcBlockSubsidy(bi *meerdag.BlueInfo) int64 {
if forks.IsMeerEVMForkHeight(bi.GetHeight()) {
if params.ActiveNetParams.IsMeerEVMFork(bi.GetHeight()) {
return s.CalcBlockSubsidyByMeerEVMFork(bi)
}
if s.params.TargetTotalSubsidy > 0 {
Expand All @@ -91,7 +91,7 @@ func (s *SubsidyCache) CalcTotalControlBlockSubsidy(bi *meerdag.BlueInfo) int64
}

func (s *SubsidyCache) GetMode(height int64) string {
if forks.IsMeerEVMForkHeight(height) {
if params.ActiveNetParams.IsMeerEVMFork(height) {
return "meerevmfork"
}
if s.params.TargetTotalSubsidy > 0 {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *SubsidyCache) CalcBlockSubsidyByMeerEVMFork(bi *meerdag.BlueInfo) int64
if bi.GetWeight() >= targetTotalSubsidy {
return 0
}
realHeight := bi.GetHeight() - forks.MeerEVMForkMainHeight
realHeight := bi.GetHeight() - params.ActiveNetParams.MeerEVMForkBlock.Int64()
iteration := uint64(realHeight) / forks.SubsidyReductionInterval
blockSubsidy := s.estimateSupply(iteration, forks.MulSubsidy, forks.DivSubsidy)
if bi.GetWeight()+blockSubsidy > targetTotalSubsidy {
Expand Down
6 changes: 3 additions & 3 deletions core/blockchain/subsidy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestEstimateSupplyByMeerEVMFork(t *testing.T) {
params.ActiveNetParams = &params.MainNetParam
param := params.MainNetParam.Params
maxTestInterval := int64(28)
endBlockHeight := int64(forks.MeerEVMForkMainHeight + forks.SubsidyReductionInterval*maxTestInterval + 1)
endBlockHeight := int64(param.MeerEVMForkBlock.Int64() + forks.SubsidyReductionInterval*maxTestInterval + 1)
bis := map[int64]*meerdag.BlueInfo{}

subsidyCache := NewSubsidyCache(0, param)
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestEstimateSupplyByMeerEVMFork(t *testing.T) {
blockTwoSubsidy := calcBlockSubsidy(2)

baseSubsidy := int64(1000000000)
forkSubsidy := int64(forks.MeerEVMForkMainHeight * baseSubsidy)
forkSubsidy := int64(param.MeerEVMForkBlock.Int64() * baseSubsidy)

type testData struct {
height int64
Expand All @@ -68,7 +68,7 @@ func TestEstimateSupplyByMeerEVMFork(t *testing.T) {

firstIndex := len(tests)
for i := int64(0); i < maxTestInterval; i++ {
td := testData{height: forks.MeerEVMForkMainHeight + forks.SubsidyReductionInterval*i, expectSubsidy: subsidyCache.subsidyCache[uint64(i)], expectMode: "meerevmfork"}
td := testData{height: param.MeerEVMForkBlock.Int64() + forks.SubsidyReductionInterval*i, expectSubsidy: subsidyCache.subsidyCache[uint64(i)], expectMode: "meerevmfork"}
if i == 0 {
td.expectTotalSubsidy = forkSubsidy
td.expectSubsidy = baseSubsidy
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ func (b *BlockChain) IsValidTxType(tt types.TxType) bool {
}
ok := true
if params.ActiveNetParams.Net == protocol.MainNet {
if !forks.IsMeerEVMForkHeight(int64(b.BestSnapshot().GraphState.GetMainHeight())) {
if !params.ActiveNetParams.IsMeerEVMFork(int64(b.BestSnapshot().GraphState.GetMainHeight())) {
ok = false
}
}
Expand Down
3 changes: 1 addition & 2 deletions meerdag/meerdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/Qitmeer/qng/common/hash"
"github.com/Qitmeer/qng/common/roughtime"
"github.com/Qitmeer/qng/consensus/forks"
"github.com/Qitmeer/qng/consensus/model"
l "github.com/Qitmeer/qng/log"
"github.com/Qitmeer/qng/meerdag/anticone"
Expand Down Expand Up @@ -927,7 +926,7 @@ func (bd *MeerDAG) checkLegality(parentsNode []IBlock) bool {

// Checking the priority of block legitimacy
func (bd *MeerDAG) checkPriority(parents []IBlock, b IBlockData) bool {
if forks.IsEmptyBlockForkHeight(int64(parents[0].GetHeight()) + 1) {
if params.ActiveNetParams.IsEmptyBlockFork(int64(parents[0].GetHeight()) + 1) {
return true
}
if b.GetPriority() <= 0 {
Expand Down
4 changes: 2 additions & 2 deletions meerdag/tips.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package meerdag
import (
"fmt"
"github.com/Qitmeer/qng/common/hash"
"github.com/Qitmeer/qng/consensus/forks"
"github.com/Qitmeer/qng/core/merkle"
"github.com/Qitmeer/qng/params"
"math"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func (bd *MeerDAG) GetValidTips(expectPriority int) []*hash.Hash {

result := []*hash.Hash{tips[0].GetHash()}
epNum := expectPriority
if forks.IsEmptyBlockForkHeight(int64(tips[0].GetHeight()) + 1) {
if params.ActiveNetParams.IsEmptyBlockFork(int64(tips[0].GetHeight()) + 1) {
epNum = MaxPriority
}
for k, v := range tips {
Expand Down
3 changes: 1 addition & 2 deletions meerevm/amana/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package amana

import (
mparams "github.com/Qitmeer/qng/meerevm/params"
qparams "github.com/Qitmeer/qng/params"
qcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -17,7 +16,7 @@ var (

func AmanaGenesis() *core.Genesis {
return &core.Genesis{
Config: mparams.AmanaChainConfig,
Config: qparams.ActiveNetParams.AmanaConfig,
Nonce: 0,
Number: 0,
ExtraData: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000071bc4403af41634cda7c32600a8024d54e7f64990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
Expand Down
2 changes: 1 addition & 1 deletion meerevm/cmd/mkalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
fileContent = fileHeader
for _, np := range params.AllNetParams {
alloc := meer.DoDecodeAlloc(np.Params, genesisJ, burnListJ)
genesis := meer.Genesis(np.Net, alloc)
genesis := meer.Genesis(np.Params, alloc)
genesisHash := genesis.ToBlock().Hash()
log.Printf("network = %s, genesisHash= %s\n", np.Name, genesisHash.String())
fileContent += fmt.Sprintf("\nconst %sGenesisHash = \"%s\"", np.Net.String(), genesisHash.String())
Expand Down
9 changes: 7 additions & 2 deletions meerevm/meer/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package meer
import (
"encoding/hex"
"fmt"
"github.com/Qitmeer/qng/consensus/forks"
"github.com/Qitmeer/qng/meerevm/meer/meerchange"
"github.com/Qitmeer/qng/params"
"github.com/ethereum/go-ethereum/common"
"math"
)

type MeerChainInfo struct {
Expand Down Expand Up @@ -67,7 +68,11 @@ func (api *PublicMeerChainAPI) GetMeerChainInfo() (interface{}, error) {

header := api.mc.GetCurHeader()
if header != nil {
mci.Fork = fmt.Sprintf("%d/%d", header.Number.Uint64(), forks.GetMeerChangeForkHeight())
forkNumber := int64(math.MaxInt64)
if params.ActiveNetParams.MeerChangeForkBlock != nil {
forkNumber = params.ActiveNetParams.MeerChangeForkBlock.Int64()
}
mci.Fork = fmt.Sprintf("%d/%d", header.Number.Uint64(), forkNumber)
}
return mi, nil
}
Expand Down
45 changes: 19 additions & 26 deletions meerevm/meer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
mcommon "github.com/Qitmeer/qng/meerevm/common"
"github.com/Qitmeer/qng/meerevm/eth"
mconsensus "github.com/Qitmeer/qng/meerevm/meer/consensus"
mparams "github.com/Qitmeer/qng/meerevm/params"
"github.com/Qitmeer/qng/p2p/common"
qparams "github.com/Qitmeer/qng/params"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -20,6 +20,7 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/params"
"math/big"
"path/filepath"
"time"
)
Expand Down Expand Up @@ -118,36 +119,28 @@ func createConsensusEngine(config *params.ChainConfig, db ethdb.Database) (conse
return mconsensus.New(), nil
}

func ChainConfig() *params.ChainConfig {
switch qparams.ActiveNetParams.Net {
case protocol.MainNet:
return mparams.QngMainnetChainConfig
case protocol.TestNet:
return mparams.QngTestnetChainConfig
case protocol.MixNet:
return mparams.QngMixnetChainConfig
case protocol.PrivNet:
return mparams.QngPrivnetChainConfig
func Genesis(net *qparams.Params, alloc types.GenesisAlloc) *core.Genesis {
if alloc == nil {
alloc = DecodeAlloc(net)
}
return nil
}

func Genesis(net protocol.Network, alloc types.GenesisAlloc) *core.Genesis {
switch net {
case protocol.MainNet:
return QngGenesis(alloc)
case protocol.TestNet:
return QngTestnetGenesis(alloc)
case protocol.MixNet:
return QngMixnetGenesis(alloc)
case protocol.PrivNet:
return QngPrivnetGenesis(alloc)
gen := &core.Genesis{
Config: net.MeerConfig,
Nonce: 0,
Number: 0,
ExtraData: hexutil.MustDecode("0x00"),
GasLimit: 100000000,
Difficulty: big.NewInt(0),
Alloc: alloc,
Timestamp: uint64(net.GenesisBlock.Block().Header.Timestamp.Unix()),
}
if net.Net == protocol.TestNet {
gen.GasLimit = 8000000
}
return nil
return gen
}

func CurrentGenesis() *core.Genesis {
return Genesis(qparams.ActiveNetParams.Net, nil)
return Genesis(qparams.ActiveNetParams.Params, nil)
}

func getBootstrapNodes(port int) []*enode.Node {
Expand Down
Loading
Loading