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

Minimize diff from upstream #147

Merged
merged 1 commit into from
Feb 29, 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
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion common/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 0 additions & 5 deletions common/hexutil/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions consensus/ethash/ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package ethash

import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/consensus"
Expand Down Expand Up @@ -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")
}
25 changes: 23 additions & 2 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
56 changes: 28 additions & 28 deletions core/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
34 changes: 15 additions & 19 deletions core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions core/types/gen_account_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions core/types/gen_header_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions core/types/gen_log_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions core/types/gen_withdrawal_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions core/utils/gas_limit.go

This file was deleted.

3 changes: 2 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions miner/sbundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading