From c1f7d6204ba7a696a66b36b4135853995601e358 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 11 Jun 2024 11:27:46 +0800 Subject: [PATCH] consensus/misc: move eip1559 into a package (#27828) --- consensus/XDPoS/engines/engine_v1/engine.go | 3 ++- consensus/XDPoS/engines/engine_v2/verifyHeader.go | 3 ++- consensus/ethash/consensus.go | 3 ++- consensus/misc/{ => eip1559}/eip1559.go | 2 +- core/chain_makers.go | 6 +++--- core/txpool/txpool.go | 4 ++-- eth/gasprice/feehistory.go | 4 ++-- internal/ethapi/api.go | 4 ++-- miner/worker.go | 3 ++- 9 files changed, 18 insertions(+), 14 deletions(-) rename consensus/misc/{ => eip1559}/eip1559.go (99%) diff --git a/consensus/XDPoS/engines/engine_v1/engine.go b/consensus/XDPoS/engines/engine_v1/engine.go index b1dcb9a7af6e..dd94925191ff 100644 --- a/consensus/XDPoS/engines/engine_v1/engine.go +++ b/consensus/XDPoS/engines/engine_v1/engine.go @@ -19,6 +19,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils" "github.com/XinFinOrg/XDPoSChain/consensus/clique" "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/crypto" @@ -242,7 +243,7 @@ func (x *XDPoS_v1) verifyCascadingFields(chain consensus.ChainReader, header *ty return utils.ErrInvalidTimestamp } // Verify the header's EIP-1559 attributes. - if err := misc.VerifyEip1559Header(chain.Config(), header); err != nil { + if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil { return err } diff --git a/consensus/XDPoS/engines/engine_v2/verifyHeader.go b/consensus/XDPoS/engines/engine_v2/verifyHeader.go index 518700fcc817..6c144b17b198 100644 --- a/consensus/XDPoS/engines/engine_v2/verifyHeader.go +++ b/consensus/XDPoS/engines/engine_v2/verifyHeader.go @@ -9,6 +9,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/consensus" "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils" "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/log" ) @@ -95,7 +96,7 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade return utils.ErrInvalidUncleHash } // Verify the header's EIP-1559 attributes. - if err := misc.VerifyEip1559Header(chain.Config(), header); err != nil { + if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil { return err } if header.Difficulty.Cmp(big.NewInt(1)) != 0 { diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 7b978a6da1c3..92806693aeb4 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -28,6 +28,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/common/math" "github.com/XinFinOrg/XDPoSChain/consensus" "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/params" @@ -254,7 +255,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent * return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit) } // Verify the header's EIP-1559 attributes. - if err := misc.VerifyEip1559Header(chain.Config(), header); err != nil { + if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil { return err } diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559/eip1559.go similarity index 99% rename from consensus/misc/eip1559.go rename to consensus/misc/eip1559/eip1559.go index c993d97062a2..0763ebd9c9bd 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package misc +package eip1559 import ( "fmt" diff --git a/core/chain_makers.go b/core/chain_makers.go index 33572f00b37e..88b3c3d05986 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -20,11 +20,11 @@ import ( "fmt" "math/big" - "github.com/XinFinOrg/XDPoSChain/core/rawdb" - "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/consensus" "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" + "github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/core/vm" @@ -285,7 +285,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S Time: time, } - header.BaseFee = misc.CalcBaseFee(chain.Config(), header) + header.BaseFee = eip1559.CalcBaseFee(chain.Config(), header) return header } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 96bfb70fe8e4..140d0ef8e8fc 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -29,7 +29,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/prque" "github.com/XinFinOrg/XDPoSChain/consensus" - "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/types" @@ -1319,7 +1319,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt if reset != nil { pool.demoteUnexecutables() if reset.newHead != nil && pool.chainconfig.IsEIP1559(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) { - pendingBaseFee := misc.CalcBaseFee(pool.chainconfig, reset.newHead) + pendingBaseFee := eip1559.CalcBaseFee(pool.chainconfig, reset.newHead) pool.priced.SetBaseFee(pendingBaseFee) } // Update all accounts to the latest known pending nonce diff --git a/eth/gasprice/feehistory.go b/eth/gasprice/feehistory.go index f32cff1ccb9d..09e2f991e7cc 100644 --- a/eth/gasprice/feehistory.go +++ b/eth/gasprice/feehistory.go @@ -27,7 +27,7 @@ import ( "sync/atomic" "github.com/XinFinOrg/XDPoSChain/common" - "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/rpc" @@ -89,7 +89,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) { bf.results.baseFee = new(big.Int) } if chainconfig.IsEIP1559(big.NewInt(int64(bf.blockNumber + 1))) { - bf.results.nextBaseFee = misc.CalcBaseFee(chainconfig, bf.header) + bf.results.nextBaseFee = eip1559.CalcBaseFee(chainconfig, bf.header) } else { bf.results.nextBaseFee = new(big.Int) } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 96a88f7bdbf8..40b31cfad8d6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -39,7 +39,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS" "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils" "github.com/XinFinOrg/XDPoSChain/consensus/ethash" - "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" contractValidator "github.com/XinFinOrg/XDPoSChain/contracts/validator/contract" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core/state" @@ -1933,7 +1933,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, config *params.ChainConfig) *RPCTransaction { var baseFee *big.Int if current != nil { - baseFee = misc.CalcBaseFee(config, current) + baseFee = eip1559.CalcBaseFee(config, current) } return newRPCTransaction(tx, common.Hash{}, 0, 0, baseFee) } diff --git a/miner/worker.go b/miner/worker.go index 50fd1da3129e..b6eae32ad67b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -32,6 +32,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/consensus" "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS" "github.com/XinFinOrg/XDPoSChain/consensus/misc" + "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559" "github.com/XinFinOrg/XDPoSChain/contracts" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core/state" @@ -616,7 +617,7 @@ func (self *worker) commitNewWork() { Time: big.NewInt(tstamp), } // Set baseFee if we are on an EIP-1559 chain - header.BaseFee = misc.CalcBaseFee(self.config, header) + header.BaseFee = eip1559.CalcBaseFee(self.config, header) // Only set the coinbase if we are mining (avoid spurious block rewards) if atomic.LoadInt32(&self.mining) == 1 {