Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions core/txpool/blobpool/blobpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserve txpool.Addres
params.GetExtra(p.chain.Config()),
feeConfig,
p.head,
uint64(time.Now().Unix()),
uint64(time.Now().UnixMilli()),
)
if err != nil {
p.Close()
Expand Down Expand Up @@ -857,7 +857,7 @@ func (p *BlobPool) Reset(oldHead, newHead *types.Header) {
params.GetExtra(p.chain.Config()),
feeConfig,
p.head,
uint64(time.Now().Unix()),
uint64(time.Now().UnixMilli()),
)
if err != nil {
log.Error("Failed to estimate next base fee to reset blobpool fees", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ func (pool *LegacyPool) updateBaseFeeAt(head *types.Header) error {
return err
}
chainConfig := params.GetExtra(pool.chainconfig)
baseFeeEstimate, err := customheader.EstimateNextBaseFee(chainConfig, feeConfig, head, uint64(time.Now().Unix()))
baseFeeEstimate, err := customheader.EstimateNextBaseFee(chainConfig, feeConfig, head, uint64(time.Now().UnixMilli()))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (oracle *Oracle) estimateNextBaseFee(ctx context.Context) (*big.Int, error)
// based on the current time and add it to the tip to estimate the
// total gas price estimate.
chainConfig := params.GetExtra(oracle.backend.ChainConfig())
return customheader.EstimateNextBaseFee(chainConfig, feeConfig, header, oracle.clock.Unix())
return customheader.EstimateNextBaseFee(chainConfig, feeConfig, header, uint64(oracle.clock.Time().UnixMilli()))
}

// SuggestPrice returns an estimated price for legacy transactions.
Expand Down
14 changes: 4 additions & 10 deletions plugin/evm/customheader/base_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
package customheader

import (
"errors"
"math/big"

"github.com/ava-labs/libevm/core/types"

"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
)

var errEstimateBaseFeeWithoutActivation = errors.New("cannot estimate base fee for chain without activation scheduled")

// BaseFee takes the previous header and the timestamp of its child block and
// calculates the expected base fee for the child block.
//
Expand Down Expand Up @@ -47,13 +45,9 @@ func EstimateNextBaseFee(
config *extras.ChainConfig,
feeConfig commontype.FeeConfig,
parent *types.Header,
timestamp uint64,
timeMS uint64,
) (*big.Int, error) {
if config.SubnetEVMTimestamp == nil {
return nil, errEstimateBaseFeeWithoutActivation
}

timestamp = max(timestamp, parent.Time, *config.SubnetEVMTimestamp)
timeMS := timestamp * 1000
parentMS := customtypes.HeaderTimeMilliseconds(parent)
timeMS = max(timeMS, parentMS)
return BaseFee(config, feeConfig, parent, timeMS)
}
23 changes: 8 additions & 15 deletions plugin/evm/customheader/base_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func BaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) {
Time: 1,
Extra: (&subnetevm.Window{}).Bytes(),
},
timeMS: 0,
wantErr: errInvalidTimestamp,
},
{
Expand Down Expand Up @@ -232,14 +231,13 @@ func TestEstimateNextBaseFee(t *testing.T) {

func EstimateNextBaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) {
testBaseFee := uint64(225 * utils.GWei)
nilUpgrade := extras.NetworkUpgrades{}
tests := []struct {
name string
upgrades extras.NetworkUpgrades
parent *types.Header
timestamp uint64
want *big.Int
wantErr error
name string
upgrades extras.NetworkUpgrades
parent *types.Header
timeMS uint64
want *big.Int
wantErr error
}{
{
name: "activated",
Expand All @@ -249,7 +247,7 @@ func EstimateNextBaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) {
Extra: (&subnetevm.Window{}).Bytes(),
BaseFee: new(big.Int).SetUint64(testBaseFee),
},
timestamp: 1,
timeMS: 1000,
want: func() *big.Int {
var (
gasTarget = feeConfig.TargetGas.Uint64()
Expand All @@ -264,11 +262,6 @@ func EstimateNextBaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) {
return new(big.Int).SetUint64(baseFee)
}(),
},
{
name: "not_scheduled",
upgrades: nilUpgrade,
wantErr: errEstimateBaseFeeWithoutActivation,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -277,7 +270,7 @@ func EstimateNextBaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) {
config := &extras.ChainConfig{
NetworkUpgrades: test.upgrades,
}
got, err := EstimateNextBaseFee(config, feeConfig, test.parent, test.timestamp)
got, err := EstimateNextBaseFee(config, feeConfig, test.parent, test.timeMS)
require.ErrorIs(err, test.wantErr)
require.Equal(test.want, got)
})
Expand Down