diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 9ac3d71862..d9efe26244 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -781,7 +781,7 @@ func (s *Suite) makeBlobTxs(count, blobs int, discriminator byte) (txs types.Tra GasTipCap: uint256.NewInt(1), GasFeeCap: uint256.MustFromBig(s.chain.Head().BaseFee()), Gas: 100000, - BlobFeeCap: uint256.MustFromBig(eip4844.CalcBlobFee(*s.chain.Head().ExcessBlobGas(), nil)), + BlobFeeCap: uint256.MustFromBig(eip4844.CalcBlobFee(*s.chain.Head().ExcessBlobGas())), BlobHashes: makeSidecar(blobdata...).BlobHashes(), Sidecar: makeSidecar(blobdata...), } diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 860ec438dc..ca1590833e 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -170,7 +170,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, var excessBlobGas uint64 if pre.Env.ExcessBlobGas != nil { excessBlobGas := *pre.Env.ExcessBlobGas - vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas, chainConfig) + vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas) } else { // If it is not explicitly defined, but we have the parent values, we try // to calculate it ourselves. @@ -178,7 +178,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, parentBlobGasUsed := pre.Env.ParentBlobGasUsed if parentExcessBlobGas != nil && parentBlobGasUsed != nil { excessBlobGas = eip4844.CalcExcessBlobGas(*parentExcessBlobGas, *parentBlobGasUsed) - vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas, chainConfig) + vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas) } } // If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's diff --git a/common/types.go b/common/types.go index a19e0fd8c4..aadca87f82 100644 --- a/common/types.go +++ b/common/types.go @@ -475,16 +475,3 @@ func (d *Decimal) UnmarshalJSON(input []byte) error { return err } } - -// IsNil uses reflect to distinguish data that is truly nil. -func IsNil(i interface{}) bool { - if i == nil { - return true - } - - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - } - return false -} diff --git a/common/types_test.go b/common/types_test.go index d3bc42ec2e..cec689ea39 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -26,8 +26,6 @@ import ( "strings" "testing" "time" - - "github.com/stretchr/testify/require" ) func TestBytesConversion(t *testing.T) { @@ -597,37 +595,3 @@ func BenchmarkPrettyDuration(b *testing.B) { } b.Logf("Post %s", a) } - -type dummyInterface interface { - dummy() -} -type dummyImplement struct { -} - -func (d *dummyImplement) dummy() {} - -func TestIsNIl(t *testing.T) { - convertNilInterface := func(di *dummyImplement) dummyInterface { - return di - } - convertNilChan := func() chan bool { - return nil - } - convertNilSlice := func() []byte { - return nil - } - tests := []struct { - i interface{} - expect bool - }{ - {nil, true}, - {struct{}{}, false}, - {make(chan bool), false}, - {convertNilChan(), true}, - {convertNilSlice(), true}, - {convertNilInterface(nil), true}, - } - for i, item := range tests { - require.Equal(t, item.expect, IsNil(item.i), i) - } -} diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index 07c006fd66..2dad9a0cd3 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -76,19 +76,8 @@ func CalcExcessBlobGas(parentExcessBlobGas uint64, parentBlobGasUsed uint64) uin } // CalcBlobFee calculates the blobfee from the header's excess blob gas field. -// config param aims to support eth's test suit. -func CalcBlobFee(excessBlobGas uint64, config *params.ChainConfig) *big.Int { - dynamicPrice := fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(excessBlobGas), blobGaspriceUpdateFraction) - if config == nil || config.Parlia == nil { - return dynamicPrice - } - if dynamicPrice.Cmp(params.MinBlobGasPriceInBSC) < 0 { - return params.MinBlobGasPriceInBSC - } - if dynamicPrice.Cmp(params.MaxBlobGasPriceInBSC) > 0 { - return params.MaxBlobGasPriceInBSC - } - return dynamicPrice +func CalcBlobFee(excessBlobGas uint64) *big.Int { + return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(excessBlobGas), blobGaspriceUpdateFraction) } // fakeExponential approximates factor * e ** (numerator / denominator) using diff --git a/consensus/misc/eip4844/eip4844_test.go b/consensus/misc/eip4844/eip4844_test.go index dc10563713..ec417380fc 100644 --- a/consensus/misc/eip4844/eip4844_test.go +++ b/consensus/misc/eip4844/eip4844_test.go @@ -61,20 +61,14 @@ func TestCalcBlobFee(t *testing.T) { tests := []struct { excessBlobGas uint64 blobfee int64 - config *params.ChainConfig }{ - {0, 1, nil}, - {2314057, 1, nil}, - {2314058, 2, nil}, - {10 * 1024 * 1024, 23, nil}, - {0, params.MinBlobGasPriceInBSC.Int64(), params.ParliaTestChainConfig}, - {555 * params.BlobTxBlobGasPerBlob, params.MinBlobGasPriceInBSC.Int64(), params.ParliaTestChainConfig}, - {556 * params.BlobTxBlobGasPerBlob, 3021819819, params.ParliaTestChainConfig}, - {627 * params.BlobTxBlobGasPerBlob, 49077044416, params.ParliaTestChainConfig}, - {628 * params.BlobTxBlobGasPerBlob, params.MaxBlobGasPriceInBSC.Int64(), params.ParliaTestChainConfig}, + {0, 1}, + {2314057, 1}, + {2314058, 2}, + {10 * 1024 * 1024, 23}, } for i, tt := range tests { - have := CalcBlobFee(tt.excessBlobGas, tt.config) + have := CalcBlobFee(tt.excessBlobGas) if have.Int64() != tt.blobfee { t.Errorf("test %d: blobfee mismatch: have %v want %v", i, have, tt.blobfee) } diff --git a/core/blockchain.go b/core/blockchain.go index d3f24aa636..04573c7123 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2431,7 +2431,7 @@ func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log { var blobGasPrice *big.Int excessBlobGas := b.ExcessBlobGas() if excessBlobGas != nil { - blobGasPrice = eip4844.CalcBlobFee(*excessBlobGas, bc.chainConfig) + blobGasPrice = eip4844.CalcBlobFee(*excessBlobGas) } receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64()) if err := receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), blobGasPrice, b.Transactions()); err != nil { diff --git a/core/chain_makers.go b/core/chain_makers.go index 456e6f3667..3970fe8ad0 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -414,7 +414,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse } var blobGasPrice *big.Int if block.ExcessBlobGas() != nil { - blobGasPrice = eip4844.CalcBlobFee(*block.ExcessBlobGas(), config) + blobGasPrice = eip4844.CalcBlobFee(*block.ExcessBlobGas()) } if err := receipts.DeriveFields(config, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, txs); err != nil { panic(err) diff --git a/core/evm.go b/core/evm.go index 199dc38977..e509f836d1 100644 --- a/core/evm.go +++ b/core/evm.go @@ -61,11 +61,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common baseFee = new(big.Int).Set(header.BaseFee) } if header.ExcessBlobGas != nil { - var config *params.ChainConfig - if !common.IsNil(chain) { - config = chain.Config() - } - blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas, config) + blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas) } if header.Difficulty.Cmp(common.Big0) == 0 { random = &header.MixDigest diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index ffe20a6f62..91529dc380 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -672,7 +672,7 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64, // Compute effective blob gas price. var blobGasPrice *big.Int if header != nil && header.ExcessBlobGas != nil { - blobGasPrice = eip4844.CalcBlobFee(*header.ExcessBlobGas, config) + blobGasPrice = eip4844.CalcBlobFee(*header.ExcessBlobGas) } if err := receipts.DeriveFields(config, hash, number, time, baseFee, blobGasPrice, body.Transactions); err != nil { log.Error("Failed to derive block receipts fields", "hash", hash, "number", number, "err", err) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index b2c035ff3e..69027ed4da 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -407,7 +407,7 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserve txpool.Addres blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice) ) if p.head.ExcessBlobGas != nil { - blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas, p.chain.Config())) + blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas)) } p.evict = newPriceHeap(basefee, blobfee, &p.index) @@ -828,7 +828,7 @@ func (p *BlobPool) Reset(oldHead, newHead *types.Header) { blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice)) ) if newHead.ExcessBlobGas != nil { - blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*newHead.ExcessBlobGas, p.chain.Config())) + blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*newHead.ExcessBlobGas)) } p.evict.reinit(basefee, blobfee, false) diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index b2f2aaf8d8..3e465a9214 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -119,7 +119,7 @@ func (bc *testBlockChain) CurrentBlock() *types.Header { mid := new(big.Int).Add(lo, hi) mid.Div(mid, big.NewInt(2)) - if eip4844.CalcBlobFee(mid.Uint64(), nil).Cmp(bc.blobfee.ToBig()) > 0 { + if eip4844.CalcBlobFee(mid.Uint64()).Cmp(bc.blobfee.ToBig()) > 0 { hi = mid } else { lo = mid diff --git a/eth/handler_test.go b/eth/handler_test.go index 6ef7cd1b3d..2ebd16ebe3 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -272,11 +272,11 @@ func newTestParliaHandlerAfterCancun(t *testing.T, config *params.ChainConfig, m _, bs, _ := core.GenerateChainWithGenesis(gspec, engine, int(preCancunBlks+postCancunBlks), func(i int, gen *core.BlockGen) { if !config.IsCancun(gen.Number(), gen.Timestamp()) { - tx, _ := makeMockTx(config, signer, testKey, gen.TxNonce(testAddr), gen.BaseFee().Uint64(), eip4844.CalcBlobFee(gen.ExcessBlobGas(), config).Uint64(), false) + tx, _ := makeMockTx(config, signer, testKey, gen.TxNonce(testAddr), gen.BaseFee().Uint64(), eip4844.CalcBlobFee(gen.ExcessBlobGas()).Uint64(), false) gen.AddTxWithChain(chain, tx) return } - tx, sidecar := makeMockTx(config, signer, testKey, gen.TxNonce(testAddr), gen.BaseFee().Uint64(), eip4844.CalcBlobFee(gen.ExcessBlobGas(), config).Uint64(), true) + tx, sidecar := makeMockTx(config, signer, testKey, gen.TxNonce(testAddr), gen.BaseFee().Uint64(), eip4844.CalcBlobFee(gen.ExcessBlobGas()).Uint64(), true) gen.AddTxWithChain(chain, tx) gen.AddBlobSidecar(sidecar) }) diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 22ecbd5db3..b492a6b482 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -251,7 +251,7 @@ func (args *TransactionArgs) setCancunFeeDefaults(ctx context.Context, head *typ excessBlobGas = *head.ExcessBlobGas } // ExcessBlobGas must be set for a Cancun block. - blobBaseFee := eip4844.CalcBlobFee(excessBlobGas, b.ChainConfig()) + blobBaseFee := eip4844.CalcBlobFee(excessBlobGas) // Set the max fee to be 2 times larger than the previous block's blob base fee. // The additional slack allows the tx to not become invalidated if the base // fee is rising. diff --git a/miner/worker.go b/miner/worker.go index 8b54098a03..cc26434cd2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1055,7 +1055,7 @@ func (w *worker) fillTransactions(interruptCh chan int32, env *environment, stop filter.BaseFee = uint256.MustFromBig(env.header.BaseFee) } if env.header.ExcessBlobGas != nil { - filter.BlobFee = uint256.MustFromBig(eip4844.CalcBlobFee(*env.header.ExcessBlobGas, w.chainConfig)) + filter.BlobFee = uint256.MustFromBig(eip4844.CalcBlobFee(*env.header.ExcessBlobGas)) } filter.OnlyPlainTxs, filter.OnlyBlobTxs = true, false pendingPlainTxs := w.eth.TxPool().Pending(filter) diff --git a/params/config.go b/params/config.go index 16880e192e..cd78432770 100644 --- a/params/config.go +++ b/params/config.go @@ -270,6 +270,7 @@ var ( ShanghaiTime: newUint64(0), KeplerTime: newUint64(0), FeynmanTime: newUint64(0), + FeynmanFixTime: newUint64(0), CancunTime: newUint64(0), Parlia: &ParliaConfig{ Period: 3, diff --git a/params/protocol_params.go b/params/protocol_params.go index 76585dc989..31eeb6899e 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -202,8 +202,3 @@ var ( // SystemAddress is where the system-transaction is sent from as per EIP-4788 SystemAddress common.Address = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") ) - -var ( - MinBlobGasPriceInBSC = new(big.Int).SetUint64(3_000_000_000) // Price for MinBlobGasPrice, now it's 3 Gwei - MaxBlobGasPriceInBSC = new(big.Int).SetUint64(50_000_000_000) // Price for MaxBlobGasPrice, now it's 50 Gwei -) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index c5191dd666..5f1694ae7b 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -290,7 +290,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh context.Difficulty = big.NewInt(0) } if config.IsCancun(new(big.Int), block.Time()) && t.json.Env.ExcessBlobGas != nil { - context.BlobBaseFee = eip4844.CalcBlobFee(*t.json.Env.ExcessBlobGas, config) + context.BlobBaseFee = eip4844.CalcBlobFee(*t.json.Env.ExcessBlobGas) } evm := vm.NewEVM(context, txContext, state.StateDB, config, vmconfig)