diff --git a/consensus/forks/cancunfork.go b/consensus/forks/cancunfork.go new file mode 100644 index 00000000..a5de4ed4 --- /dev/null +++ b/consensus/forks/cancunfork.go @@ -0,0 +1,29 @@ +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) { + return common.Big0 + } + return common.Big1 +} diff --git a/consensus/forks/meerchangefork.go b/consensus/forks/meerchangefork.go index c581d160..f1c38e35 100644 --- a/consensus/forks/meerchangefork.go +++ b/consensus/forks/meerchangefork.go @@ -8,13 +8,13 @@ import ( const ( // TODO:Future decision on whether to start - // Support MeerChange system contract at height - MeerChangeForkHeight = math.MaxInt64 + // Support MeerChange system contract at evm height + MeerChangeForkEvmHeight = math.MaxInt64 ) -func IsMeerChangeForkHeight(mainHeight int64) bool { +func IsMeerChangeForkHeight(height int64) bool { if params.ActiveNetParams.Net != protocol.MainNet { return true } - return mainHeight >= MeerChangeForkHeight + return height >= MeerChangeForkEvmHeight } diff --git a/meerevm/meer/consensus/consensus.go b/meerevm/meer/consensus/consensus.go index 082c73b4..3fa2736b 100644 --- a/meerevm/meer/consensus/consensus.go +++ b/meerevm/meer/consensus/consensus.go @@ -158,11 +158,15 @@ func (me *MeerEngine) verifyHeader(chain consensus.ChainHeaderReader, header, pa } func (me *MeerEngine) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int { - return big.NewInt(1) + return forks.GetCancunForkDifficulty(parent.Number.Int64()) } func (me *MeerEngine) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error { - header.Difficulty = big.NewInt(1) + number := header.Number.Int64() + if number > 0 { + number-- + } + header.Difficulty = forks.GetCancunForkDifficulty(number) return nil } diff --git a/meerevm/meer/meerchain.go b/meerevm/meer/meerchain.go index e07fc393..ca80b77f 100644 --- a/meerevm/meer/meerchain.go +++ b/meerevm/meer/meerchain.go @@ -183,7 +183,7 @@ func (b *MeerChain) buildBlock(parent *types.Header, qtxs []model.Tx, timestamp gaslimit = 0x10000000000000 } - header := makeHeader(&b.chain.Config().Eth, parentBlock, statedb, timestamp, gaslimit) + header := makeHeader(&b.chain.Config().Eth, parentBlock, statedb, timestamp, gaslimit, forks.GetCancunForkDifficulty(parent.Number.Int64())) if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(header.Number) == 0 { misc.ApplyDAOHardFork(statedb) diff --git a/meerevm/meer/meerpool.go b/meerevm/meer/meerpool.go index d6f23a80..0e638700 100644 --- a/meerevm/meer/meerpool.go +++ b/meerevm/meer/meerpool.go @@ -154,7 +154,7 @@ func (m *MeerPool) handler() { } func (m *MeerPool) prepareMeerChangeTxs(txs []*types.Transaction) bool { - if !forks.IsMeerChangeForkHeight(int64(m.consensus.BlockChain().GetMainChainTip().GetHeight())) { + if !forks.IsMeerChangeForkHeight(m.eth.BlockChain().CurrentBlock().Number.Int64()) { return false } for _, tx := range txs { diff --git a/meerevm/meer/utils.go b/meerevm/meer/utils.go index 01fdc86a..e71fabda 100644 --- a/meerevm/meer/utils.go +++ b/meerevm/meer/utils.go @@ -15,7 +15,7 @@ import ( "math/big" ) -func makeHeader(cfg *ethconfig.Config, parent *types.Block, state *state.StateDB, timestamp int64, gaslimit uint64) *types.Header { +func makeHeader(cfg *ethconfig.Config, parent *types.Block, state *state.StateDB, timestamp int64, gaslimit uint64, difficulty *big.Int) *types.Header { ptt := int64(parent.Time()) if timestamp <= ptt { timestamp = ptt + 1 @@ -25,7 +25,7 @@ func makeHeader(cfg *ethconfig.Config, parent *types.Block, state *state.StateDB Root: state.IntermediateRoot(cfg.Genesis.Config.IsEIP158(parent.Number())), ParentHash: parent.Hash(), Coinbase: parent.Coinbase(), - Difficulty: common.Big1, + Difficulty: difficulty, GasLimit: gaslimit, Number: new(big.Int).Add(parent.Number(), common.Big1), Time: uint64(timestamp),