diff --git a/Makefile b/Makefile index ec9fc9e681..cd6c395b19 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,7 @@ lint: ## Run linters. $(GORUN) build/ci.go lint fmt: - gofmt -s -w . - gofumpt -extra -w . - gci write . + go fmt go mod tidy clean: diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 5087cdcc29..d333c17559 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -86,7 +86,6 @@ if one is set. Otherwise it prints the genesis from the datadir.`, utils.CacheGCFlag, utils.MetricsEnabledFlag, utils.MetricsEnabledExpensiveFlag, - utils.MetricsEnabledBuilderFlag, utils.MetricsHTTPFlag, utils.MetricsPortFlag, utils.MetricsEnableInfluxDBFlag, diff --git a/common/big.go b/common/big.go index 55383e1a4b..9986bacee7 100644 --- a/common/big.go +++ b/common/big.go @@ -29,7 +29,6 @@ var ( Big3 = big.NewInt(3) Big0 = big.NewInt(0) Big32 = big.NewInt(32) - Big100 = big.NewInt(100) Big256 = big.NewInt(256) Big257 = big.NewInt(257) diff --git a/common/hexutil/json.go b/common/hexutil/json.go index 02b5f45bb6..e0ac98f52d 100644 --- a/common/hexutil/json.go +++ b/common/hexutil/json.go @@ -265,11 +265,6 @@ func (b *U256) UnmarshalText(input []byte) error { return (*uint256.Int)(b).SetFromHex(string(input)) } -// ToInt converts b to a uint256.Int. -func (b *U256) ToInt() *uint256.Int { - return (*uint256.Int)(b) -} - // String returns the hex encoding of b. func (b *U256) String() string { return (*uint256.Int)(b).Hex() diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 316a5acefa..a350e383a2 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -395,9 +395,9 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea // // Note, the method returns immediately and will send the result async. More // than one result may also be returned depending on the consensus algorithm. -func (beacon *Beacon) Seal(chain consensus.ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error { +func (beacon *Beacon) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { if !beacon.IsPoSHeader(block.Header()) { - return beacon.ethone.Seal(chain, block, profit, results, stop) + return beacon.ethone.Seal(chain, block, results, stop) } // The seal verification is done by the external consensus engine, // return directly without pushing any block back. In another word diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 367e659e93..c693189ea5 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -612,7 +612,7 @@ func (c *Clique) Authorize(signer common.Address, signFn SignerFn) { // Seal implements consensus.Engine, attempting to create a sealed block using // the local signing credentials. -func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error { +func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { header := block.Header() // Sealing the genesis block is not supported diff --git a/consensus/consensus.go b/consensus/consensus.go index b2d87a6b77..3a2c2d2229 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -104,7 +104,7 @@ type Engine interface { // // Note, the method returns immediately and will send the result async. More // than one result may also be returned depending on the consensus algorithm. - Seal(chain ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error + Seal(chain ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error // SealHash returns the hash of a block prior to it being sealed. SealHash(header *types.Header) common.Hash diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 5788fb1f99..f37ec26056 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -18,7 +18,6 @@ package ethash import ( - "math/big" "time" "github.com/ethereum/go-ethereum/consensus" @@ -81,6 +80,6 @@ func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API { // Seal generates a new sealing request for the given input block and pushes // the result into the given channel. For the ethash engine, this method will // just panic as sealing is not supported anymore. -func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error { +func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { panic("ethash (pow) sealing not supported any more") } diff --git a/core/block_validator.go b/core/block_validator.go index e0bd58f5ba..f3d65cea25 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/utils" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" ) @@ -146,6 +145,28 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD return nil } +// CalcGasLimit computes the gas limit of the next block after parent. It aims +// to keep the baseline gas close to the provided target, and increase it towards +// the target if the baseline gas is lower. func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 { - return utils.CalcGasLimit(parentGasLimit, desiredLimit) + delta := parentGasLimit/params.GasLimitBoundDivisor - 1 + limit := parentGasLimit + if desiredLimit < params.MinGasLimit { + desiredLimit = params.MinGasLimit + } + // If we're outside our allowed gas range, we try to hone towards them + if limit < desiredLimit { + limit = parentGasLimit + delta + if limit > desiredLimit { + limit = desiredLimit + } + return limit + } + if limit > desiredLimit { + limit = parentGasLimit - delta + if limit < desiredLimit { + limit = desiredLimit + } + } + return limit } diff --git a/core/blockchain.go b/core/blockchain.go index d840a5c304..317881fc81 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -38,7 +38,6 @@ import ( "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/utils" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -2471,7 +2470,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad return errors.New("parent not found") } - calculatedGasLimit := utils.CalcGasLimit(parent.GasLimit, registeredGasLimit) + calculatedGasLimit := CalcGasLimit(parent.GasLimit, registeredGasLimit) if calculatedGasLimit != header.GasLimit { return errors.New("incorrect gas limit set") } diff --git a/core/gen_genesis.go b/core/gen_genesis.go index 2028f98edc..b8acf9df7c 100644 --- a/core/gen_genesis.go +++ b/core/gen_genesis.go @@ -19,21 +19,21 @@ var _ = (*genesisSpecMarshaling)(nil) // MarshalJSON marshals as JSON. func (g Genesis) MarshalJSON() ([]byte, error) { type Genesis struct { - Config *params.ChainConfig `json:"config"` - Nonce math.HexOrDecimal64 `json:"nonce"` - Timestamp math.HexOrDecimal64 `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extraData"` - GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` - Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` - Mixhash common.Hash `json:"mixHash"` - Coinbase common.Address `json:"coinbase"` + Config *params.ChainConfig `json:"config"` + Nonce math.HexOrDecimal64 `json:"nonce"` + Timestamp math.HexOrDecimal64 `json:"timestamp"` + ExtraData hexutil.Bytes `json:"extraData"` + GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` + Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` + Mixhash common.Hash `json:"mixHash"` + Coinbase common.Address `json:"coinbase"` Alloc map[common.UnprefixedAddress]types.Account `json:"alloc" gencodec:"required"` - Number math.HexOrDecimal64 `json:"number"` - GasUsed math.HexOrDecimal64 `json:"gasUsed"` - ParentHash common.Hash `json:"parentHash"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + Number math.HexOrDecimal64 `json:"number"` + GasUsed math.HexOrDecimal64 `json:"gasUsed"` + ParentHash common.Hash `json:"parentHash"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` } var enc Genesis enc.Config = g.Config @@ -62,21 +62,21 @@ func (g Genesis) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (g *Genesis) UnmarshalJSON(input []byte) error { type Genesis struct { - Config *params.ChainConfig `json:"config"` - Nonce *math.HexOrDecimal64 `json:"nonce"` - Timestamp *math.HexOrDecimal64 `json:"timestamp"` - ExtraData *hexutil.Bytes `json:"extraData"` - GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` - Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` - Mixhash *common.Hash `json:"mixHash"` - Coinbase *common.Address `json:"coinbase"` + Config *params.ChainConfig `json:"config"` + Nonce *math.HexOrDecimal64 `json:"nonce"` + Timestamp *math.HexOrDecimal64 `json:"timestamp"` + ExtraData *hexutil.Bytes `json:"extraData"` + GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` + Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` + Mixhash *common.Hash `json:"mixHash"` + Coinbase *common.Address `json:"coinbase"` Alloc map[common.UnprefixedAddress]types.Account `json:"alloc" gencodec:"required"` - Number *math.HexOrDecimal64 `json:"number"` - GasUsed *math.HexOrDecimal64 `json:"gasUsed"` - ParentHash *common.Hash `json:"parentHash"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + Number *math.HexOrDecimal64 `json:"number"` + GasUsed *math.HexOrDecimal64 `json:"gasUsed"` + ParentHash *common.Hash `json:"parentHash"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` } var dec Genesis if err := json.Unmarshal(input, &dec); err != nil { diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 0172db5ae0..2f67f0e8b9 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1332,9 +1332,7 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest, if len(events) > 0 { var txs []*types.Transaction for _, set := range events { - for _, tx := range set.Flatten() { - txs = append(txs, tx) - } + txs = append(txs, set.Flatten()...) } pool.txFeed.Send(core.NewTxsEvent{Txs: txs}) } diff --git a/core/txpool/validation.go b/core/txpool/validation.go index e1dfec8a13..a9bd14020b 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -38,8 +38,6 @@ type ValidationOptions struct { Accept uint8 // Bitmap of transaction types that should be accepted for the calling pool MaxSize uint64 // Maximum size of a transaction that the caller can meaningfully handle MinTip *big.Int // Minimum gas tip needed to allow a transaction into the caller pool - - sbundle bool // Whether the transaction pool is from sbundle } // ValidateTransaction is a helper method to check whether a transaction is valid @@ -65,8 +63,8 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types if !opts.Config.IsLondon(head.Number) && tx.Type() == types.DynamicFeeTxType { return fmt.Errorf("%w: type %d rejected, pool not yet in London", core.ErrTxTypeNotSupported, tx.Type()) } - if opts.Config.CancunTime == nil && tx.Type() == types.BlobTxType { - return fmt.Errorf("%w: type %d rejected, pool not configured for Cancun", core.ErrTxTypeNotSupported, tx.Type()) + if !opts.Config.IsCancun(head.Number, head.Time) && tx.Type() == types.BlobTxType { + return fmt.Errorf("%w: type %d rejected, pool not yet in Cancun", core.ErrTxTypeNotSupported, tx.Type()) } // Check whether the init code size has been exceeded if opts.Config.IsShanghai(head.Number, head.Time) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { @@ -96,21 +94,19 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types if _, err := types.Sender(signer, tx); err != nil { return ErrInvalidSender } - if !opts.sbundle { - // Ensure the transaction has more gas than the bare minimum needed to cover - // the transaction metadata - intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number, head.Time)) - if err != nil { - return err - } - if tx.Gas() < intrGas { - return fmt.Errorf("%w: needed %v, allowed %v", core.ErrIntrinsicGas, intrGas, tx.Gas()) - } - // Ensure the gasprice is high enough to cover the requirement of the calling - // pool and/or block producer - if tx.GasTipCapIntCmp(opts.MinTip) < 0 { - return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap()) - } + // Ensure the transaction has more gas than the bare minimum needed to cover + // the transaction metadata + intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number, head.Time)) + if err != nil { + return err + } + if tx.Gas() < intrGas { + return fmt.Errorf("%w: needed %v, allowed %v", core.ErrIntrinsicGas, intrGas, tx.Gas()) + } + // Ensure the gasprice is high enough to cover the requirement of the calling + // pool and/or block producer + if tx.GasTipCapIntCmp(opts.MinTip) < 0 { + return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap()) } // Ensure blob transactions have valid commitments if tx.Type() == types.BlobTxType { diff --git a/core/types/gen_account_rlp.go b/core/types/gen_account_rlp.go index 3d2f67ab0f..8b424493af 100644 --- a/core/types/gen_account_rlp.go +++ b/core/types/gen_account_rlp.go @@ -2,11 +2,8 @@ package types -import ( - "io" - - "github.com/ethereum/go-ethereum/rlp" -) +import "github.com/ethereum/go-ethereum/rlp" +import "io" func (obj *StateAccount) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index e6da0d0656..ed6a1a002c 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -2,11 +2,8 @@ package types -import ( - "io" - - "github.com/ethereum/go-ethereum/rlp" -) +import "github.com/ethereum/go-ethereum/rlp" +import "io" func (obj *Header) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_log_rlp.go b/core/types/gen_log_rlp.go index 89f2083d4b..7e89629668 100644 --- a/core/types/gen_log_rlp.go +++ b/core/types/gen_log_rlp.go @@ -2,11 +2,8 @@ package types -import ( - "io" - - "github.com/ethereum/go-ethereum/rlp" -) +import "github.com/ethereum/go-ethereum/rlp" +import "io" func (obj *Log) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_withdrawal_rlp.go b/core/types/gen_withdrawal_rlp.go index 7d8b9bad06..6a97c04c81 100644 --- a/core/types/gen_withdrawal_rlp.go +++ b/core/types/gen_withdrawal_rlp.go @@ -2,11 +2,8 @@ package types -import ( - "io" - - "github.com/ethereum/go-ethereum/rlp" -) +import "github.com/ethereum/go-ethereum/rlp" +import "io" func (obj *Withdrawal) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/utils/gas_limit.go b/core/utils/gas_limit.go deleted file mode 100644 index 8be0a6a43e..0000000000 --- a/core/utils/gas_limit.go +++ /dev/null @@ -1,29 +0,0 @@ -package utils - -import "github.com/ethereum/go-ethereum/params" - -// CalcGasLimit computes the gas limit of the next block after parent. It aims -// to keep the baseline gas close to the provided target, and increase it towards -// the target if the baseline gas is lower. -func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 { - delta := parentGasLimit/params.GasLimitBoundDivisor - 1 - limit := parentGasLimit - if desiredLimit < params.MinGasLimit { - desiredLimit = params.MinGasLimit - } - // If we're outside our allowed gas range, we try to hone towards them - if limit < desiredLimit { - limit = parentGasLimit + delta - if limit > desiredLimit { - limit = desiredLimit - } - return limit - } - if limit > desiredLimit { - limit = parentGasLimit - delta - if limit < desiredLimit { - limit = desiredLimit - } - } - return limit -} diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 90e7712fc5..abe20961a8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1761,7 +1761,8 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction, pr return common.Hash{}, err } // Print a log with full tx details for manual investigations and interventions - signer := types.LatestSigner(b.ChainConfig()) + head := b.CurrentBlock() + signer := types.MakeSigner(b.ChainConfig(), head.Number, head.Time) from, err := types.Sender(signer, tx) if err != nil { return common.Hash{}, err diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 3fd824ad46..d221c14db5 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -204,6 +204,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro } return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas } + // Sanity check the non-EIP-1559 fee parameters. isLondon := b.ChainConfig().IsLondon(head.Number) if args.GasPrice != nil && !eip1559ParamsSet { diff --git a/miner/sbundle_test.go b/miner/sbundle_test.go index a1bebc97a9..1fe18cdbb7 100644 --- a/miner/sbundle_test.go +++ b/miner/sbundle_test.go @@ -461,12 +461,12 @@ func TestSBundles(t *testing.T) { expectedKickbackReceivers = make([]common.Address, 0, len(tt.ExtractedRefunds)) ) for _, refund := range tt.ExtractedRefunds { - refundBeforSplit := common.PercentOf(refund.Value.ToInt(), refund.Percent) + refundBeforeSplit := common.PercentOf((*uint256.Int)(refund.Value), refund.Percent) fees := new(uint256.Int).Mul(uint256.MustFromBig(testSuite.Header.BaseFee), core.SbundlePayoutMaxCost) fees.Mul(fees, uint256.NewInt(uint64(len(refund.RefundSplit)))) for recipient, split := range refund.RefundSplit { - value := new(uint256.Int).Sub(refundBeforSplit, fees) + value := new(uint256.Int).Sub(refundBeforeSplit, fees) value = common.PercentOf(value, split) expectedKickbackValues = append(expectedKickbackValues, value) expectedKickbackReceivers = append(expectedKickbackReceivers, recipient) diff --git a/miner/stress/clique/main.go b/miner/stress/clique/main.go index 830b734917..ac25db73e9 100644 --- a/miner/stress/clique/main.go +++ b/miner/stress/clique/main.go @@ -146,7 +146,7 @@ func main() { // makeGenesis creates a custom Clique genesis block based on some pre-defined // signer and faucet accounts. -func makeGenesis(faucets, sealers []*ecdsa.PrivateKey) *core.Genesis { +func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core.Genesis { // Create a Clique network based off of the Sepolia config genesis := core.DefaultSepoliaGenesisBlock() genesis.GasLimit = 25000000 diff --git a/miner/worker.go b/miner/worker.go index 6c2a5cbc28..fb3872a817 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -723,7 +723,7 @@ func (w *worker) taskLoop() { w.pendingTasks[sealHash] = task w.pendingMu.Unlock() - if err := w.engine.Seal(w.chain, task.block, task.profit.ToBig(), w.resultCh, stopCh); err != nil { + if err := w.engine.Seal(w.chain, task.block, w.resultCh, stopCh); err != nil { log.Warn("Block sealing failed", "err", err) w.pendingMu.Lock() delete(w.pendingTasks, sealHash)