Skip to content

Commit

Permalink
Removed all references to EIP1559 from the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed May 9, 2023
1 parent 25b0381 commit 61106bc
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 52 deletions.
15 changes: 13 additions & 2 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed(), header.GasLimit())
}
// Verify the block's gas usage and verify the base fee.
if err := misc.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
// Verify the header's EIP-1559 attributes.
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit()
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit()); err != nil {
return err
}
// Verify the header is not malformed
if header.BaseFee() == nil {
return fmt.Errorf("header is missing baseFee")
}
// Verify the baseFee is correct based on the parent header.
expectedBaseFee := misc.CalcBaseFee(chain.Config(), parent)
if header.BaseFee().Cmp(expectedBaseFee) != 0 {
return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
expectedBaseFee, header.BaseFee(), parent.BaseFee(), parent.GasUsed())
}
}
// Verify that the block number is parent's +1
if diff := new(big.Int).Sub(header.Number(), parent.Number()); diff.Cmp(big.NewInt(1)) != 0 {
Expand Down
23 changes: 0 additions & 23 deletions consensus/misc/eip1559.go → consensus/misc/basefee.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package misc

import (
"fmt"
"math/big"

"github.com/dominant-strategies/go-quai/common"
Expand All @@ -26,28 +25,6 @@ import (
"github.com/dominant-strategies/go-quai/params"
)

// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
// - gas limit check
// - basefee check
func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Header) error {
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit()
if err := VerifyGaslimit(parentGasLimit, header.GasLimit()); err != nil {
return err
}
// Verify the header is not malformed
if header.BaseFee() == nil {
return fmt.Errorf("header is missing baseFee")
}
// Verify the baseFee is correct based on the parent header.
expectedBaseFee := CalcBaseFee(config, parent)
if header.BaseFee().Cmp(expectedBaseFee) != 0 {
return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
expectedBaseFee, header.BaseFee(), parent.BaseFee(), parent.GasUsed())
}
return nil
}

// CalcBaseFee calculates the basefee of the header taking into account the basefee ceiling
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
calculatedBaseFee := calcBaseFee(config, parent)
Expand Down
23 changes: 19 additions & 4 deletions consensus/misc/eip1559_test.go → consensus/misc/basefee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package misc

import (
"fmt"
"math/big"
"testing"

Expand All @@ -39,8 +40,7 @@ func config() *params.ChainConfig {
return config
}

// TestBlockGasLimits tests the gasLimit checks for blocks both across
// the EIP-1559 boundary and post-1559 blocks
// TestBlockGasLimits tests the gasLimit checks for blocks
func TestBlockGasLimits(t *testing.T) {
initial := new(big.Int).SetUint64(params.InitialBaseFee)

Expand Down Expand Up @@ -79,7 +79,23 @@ func TestBlockGasLimits(t *testing.T) {
BaseFee: initial,
Number: big.NewInt(tc.pNum + 1),
}
err := VerifyEip1559Header(config(), parent, header)
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit()
var err error
if err := VerifyGaslimit(parentGasLimit, header.GasLimit()); err != nil {
t.Error(err)
}
// Verify the header is not malformed
if header.BaseFee() == nil {
err = fmt.Errorf("header is missing baseFee")
}
// Verify the baseFee is correct based on the parent header.
expectedBaseFee := CalcBaseFee(config(), parent)
if header.BaseFee().Cmp(expectedBaseFee) != 0 {
err = fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
expectedBaseFee, header.BaseFee(), parent.BaseFee(), parent.GasUsed())
}

if tc.ok && err != nil {
t.Errorf("test %d: Expected valid header: %s", i, err)
}
Expand All @@ -89,7 +105,6 @@ func TestBlockGasLimits(t *testing.T) {
}
}

// TestCalcBaseFee assumes all blocks are 1559-blocks
func TestCalcBaseFee(t *testing.T) {
tests := []struct {
parentBaseFee int64
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (b *BlockGen) Number() *big.Int {
return new(big.Int).Set(b.header.Number())
}

// BaseFee returns the EIP-1559 base fee of the block being generated.
// BaseFee returns the base fee of the block being generated.
func (b *BlockGen) BaseFee() *big.Int {
return new(big.Int).Set(b.header.BaseFee())
}
Expand Down
3 changes: 1 addition & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ func (c *Core) SetRecommitInterval(interval time.Duration) {
c.sl.miner.SetRecommitInterval(interval)
}

// SetGasCeil sets the gaslimit to strive for when mining blocks post 1559.
// For pre-1559 blocks, it sets the ceiling.
// SetGasCeil sets the gaslimit to strive for when mining blocks.
func (c *Core) SetGasCeil(ceil uint64) {
c.sl.miner.SetGasCeil(ceil)
}
Expand Down
3 changes: 1 addition & 2 deletions core/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ func (miner *Miner) SetEtherbase(addr common.Address) {
miner.worker.setEtherbase(addr)
}

// SetGasCeil sets the gaslimit to strive for when mining blocks post 1559.
// For pre-1559 blocks, it sets the ceiling.
// SetGasCeil sets the gaslimit to strive for when mining blocks.
func (miner *Miner) SetGasCeil(ceil uint64) {
miner.worker.setGasCeil(ceil)
}
Expand Down
4 changes: 0 additions & 4 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ type TxPool struct {
signer types.Signer
mu sync.RWMutex

eip1559 bool // Fork indicator whether we are using EIP-1559 type transactions.

currentState *state.StateDB // Current state in the blockchain head
pendingNonces *txNoncer // Pending state tracking virtual nonces
currentMaxGas uint64 // Current gas limit for transaction caps
Expand Down Expand Up @@ -1300,8 +1298,6 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
log.Debug("Reinjecting stale transactions", "count", len(reinject))
senderCacher.recover(pool.signer, reinject)
pool.addTxsLocked(reinject, false)

pool.eip1559 = true
}

// promoteExecutables moves transactions that have become processable from the
Expand Down
2 changes: 1 addition & 1 deletion core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestBlockEncoding(t *testing.T) {
}
}

func TestEIP1559BlockEncoding(t *testing.T) {
func TestBlockEncoding(t *testing.T) {
blockEnc := common.FromHex("f9030bf901fea083cafc574e1f51ba9dc0568fc617a08ea2429fb384059c972f13b19fa1c8dd55a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4843b9aca00f90106f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1b8a302f8a0018080843b9aca008301e24194095e7baea6a6c7c4c2dfeb977efac326af552d878080f838f7940000000000000000000000000000000000000001e1a0000000000000000000000000000000000000000000000000000000000000000080a0fe38ca4e44a30002ac54af7cf922a6ac2ba11b7d22f548e8ecb3f51f41cb31b0a06de6a5cbae13c0c856e33acf021b51819636cfc009d39eafb9f606d546e305a8c0")
var block Block
if err := rlp.DecodeBytes(blockEnc, &block); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestTransactionPriceNonceSortLegacy(t *testing.T) {
testTransactionPriceNonceSort(t, nil)
}

func TestTransactionPriceNonceSort1559(t *testing.T) {
func TestTransactionPriceNonceSort(t *testing.T) {
testTransactionPriceNonceSort(t, big.NewInt(0))
testTransactionPriceNonceSort(t, big.NewInt(5))
testTransactionPriceNonceSort(t, big.NewInt(50))
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Config struct {
Debug bool // Enables debugging
Tracer Tracer // Opcode logger
NoRecursion bool // Disables call, callcode, delegate call and create
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
NoBaseFee bool // Forces the baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages

JumpTable [256]*operation // EVM instruction table, automatically populated if unset
Expand Down
4 changes: 2 additions & 2 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ type CallMsg struct {
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
GasFeeCap *big.Int // fee cap per gas.
GasTipCap *big.Int // tip per gas.
Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation

Expand Down
9 changes: 4 additions & 5 deletions internal/quaiapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
if nodeCtx != common.ZONE_CTX {
return types.Message{}, errors.New("toMessage can only called in zone chain")
}
// Reject invalid combinations of pre- and post-1559 fee styles
// Reject invalid combinations of fee styles
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return types.Message{}, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
Expand All @@ -202,20 +202,19 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
gasTipCap *big.Int
)
if baseFee == nil {
// If there's no basefee, then it must be a non-1559 execution
gasPrice = new(big.Int)
if args.GasPrice != nil {
gasPrice = args.GasPrice.ToInt()
}
gasFeeCap, gasTipCap = gasPrice, gasPrice
} else {
// A basefee is provided, necessitating 1559-type execution
// A basefee is provided
if args.GasPrice != nil {
// User specified the legacy gas field, convert to 1559 gas typing
// User specified the legacy gas field, convert
gasPrice = args.GasPrice.ToInt()
gasFeeCap, gasTipCap = gasPrice, gasPrice
} else {
// User specified 1559 gas feilds (or none), use those
// User specified max fee (or none), use those
gasFeeCap = new(big.Int)
if args.MaxFeePerGas != nil {
gasFeeCap = args.MaxFeePerGas.ToInt()
Expand Down
6 changes: 3 additions & 3 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const (
CreateBySelfdestructGas uint64 = 25000

BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 1 // Initial base fee for EIP-1559 blocks.
MaxBaseFee = 1 * GWei // Maximum base fee for EIP-1559 blocks.
ElasticityMultiplier = 2 // Bounds the maximum gas limit a block may have.
InitialBaseFee = 1 // Initial base fee for blocks.
MaxBaseFee = 1 * GWei // Maximum base fee for blocks.

MaxCodeSize = 24576 // Maximum bytecode to permit for a contract

Expand Down
2 changes: 1 addition & 1 deletion quaiclient/ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
return (*big.Int)(&hex), nil
}

// SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to
// SuggestGasTipCap retrieves the currently suggested gas tip cap to
// allow a timely execution of a transaction.
func (ec *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
var hex hexutil.Big
Expand Down

0 comments on commit 61106bc

Please sign in to comment.