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

consensus/misc: rollback CalcBlobFee #2306

Merged
merged 1 commit into from
Mar 19, 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
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/ethtest/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ 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.
parentExcessBlobGas := pre.Env.ParentExcessBlobGas
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
Expand Down
13 changes: 0 additions & 13 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 0 additions & 36 deletions common/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestBytesConversion(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}
15 changes: 2 additions & 13 deletions consensus/misc/eip4844/eip4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions consensus/misc/eip4844/eip4844_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/blobpool/blobpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ var (
ShanghaiTime: newUint64(0),
KeplerTime: newUint64(0),
FeynmanTime: newUint64(0),
FeynmanFixTime: newUint64(0),
CancunTime: newUint64(0),
Parlia: &ParliaConfig{
Period: 3,
Expand Down
5 changes: 0 additions & 5 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading