Skip to content
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/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error {
}
configExtra := params.GetExtra(chainConfig)
var err error
env.BaseFee, err = customheader.BaseFee(configExtra, feeConfig, parent, env.Timestamp)
env.BaseFee, err = customheader.BaseFee(configExtra, feeConfig, parent, env.Timestamp*1000)
if err != nil {
return NewError(ErrorConfig, fmt.Errorf("failed calculating base fee: %v", err))
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func verifyHeaderGasFields(config *extras.ChainConfig, header *types.Header, par
}

// Verify header.BaseFee matches the expected value.
expectedBaseFee, err := customheader.BaseFee(config, feeConfig, parent, header.Time)
timeMS := customtypes.HeaderTimeMilliseconds(header)
expectedBaseFee, err := customheader.BaseFee(config, feeConfig, parent, timeMS)
if err != nil {
return fmt.Errorf("failed to calculate base fee: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,18 @@ func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int,

func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.StateDB, engine consensus.Engine) *types.Header {
time := parent.Time() + gap // block time is fixed at [gap] seconds
timeMS := customtypes.HeaderTimeMilliseconds(parent.Header()) + gap*1000

feeConfig, _, err := cm.GetFeeConfigAt(parent.Header())
if err != nil {
panic(err)
}
config := params.GetExtra(cm.config)
gasLimit, err := customheader.GasLimit(config, feeConfig, parent.Header(), time)
gasLimit, err := customheader.GasLimit(config, feeConfig, parent.Header(), timeMS)
if err != nil {
panic(err)
}
baseFee, err := customheader.BaseFee(config, feeConfig, parent.Header(), time)
baseFee, err := customheader.BaseFee(config, feeConfig, parent.Header(), timeMS)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -420,8 +422,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.S

if config.IsGranite(header.Time) {
headerExtra := customtypes.GetHeaderExtra(header)
timeMilliseconds := header.Time * 1000 // convert to milliseconds
headerExtra.TimeMilliseconds = &timeMilliseconds
headerExtra.TimeMilliseconds = &timeMS
}
return header
}
Expand Down
19 changes: 10 additions & 9 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/ava-labs/subnet-evm/plugin/evm/customheader"
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/legacy"
"github.com/ava-labs/subnet-evm/utils"
"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"
)
Expand Down Expand Up @@ -357,14 +358,16 @@ func TestStateProcessorErrors(t *testing.T) {
// - valid pow (fake), ancestry, difficulty, gaslimit etc
func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Transactions, config *params.ChainConfig) *types.Block {
fakeChainReader := newChainMaker(nil, config, engine)
time := parent.Time() + 10
feeConfig, _, err := fakeChainReader.GetFeeConfigAt(parent.Header())
if err != nil {
panic(err)
}
configExtra := params.GetExtra(config)
gasLimit, _ := customheader.GasLimit(configExtra, feeConfig, parent.Header(), time)
baseFee, _ := customheader.BaseFee(configExtra, feeConfig, parent.Header(), time)
gap := uint64(10) // 10 seconds
time := parent.Time() + gap
timeMS := customtypes.HeaderTimeMilliseconds(parent.Header()) + gap*1000
gasLimit, _ := customheader.GasLimit(configExtra, feeConfig, parent.Header(), timeMS)
baseFee, _ := customheader.BaseFee(configExtra, feeConfig, parent.Header(), timeMS)
header := &types.Header{
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
Expand All @@ -380,6 +383,10 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
UncleHash: types.EmptyUncleHash,
BaseFee: baseFee,
}
if configExtra.IsGranite(header.Time) {
headerExtra := customtypes.GetHeaderExtra(header)
headerExtra.TimeMilliseconds = utils.NewUint64(timeMS)
}

if params.GetExtra(config).IsSubnetEVM(header.Time) {
headerExtra := customtypes.GetHeaderExtra(header)
Expand Down Expand Up @@ -418,12 +425,6 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
header.ParentBeaconRoot = new(common.Hash)
}

if configExtra.IsGranite(header.Time) {
headerExtra := customtypes.GetHeaderExtra(header)
headerExtra.TimeMilliseconds = new(uint64)
*headerExtra.TimeMilliseconds = header.Time * 1000
}

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))
}
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
15 changes: 13 additions & 2 deletions core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
"github.com/ava-labs/subnet-evm/core/txpool"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/plugin/evm/customheader"
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/legacy"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm"
"github.com/holiman/billy"
Expand All @@ -76,6 +77,7 @@ var testChainConfig *params.ChainConfig

func init() {
params.RegisterExtras()
customtypes.Register()

testChainConfig = new(params.ChainConfig)
*testChainConfig = params.Copy(params.TestChainConfig)
Expand Down Expand Up @@ -123,8 +125,12 @@ func (bc *testBlockChain) CurrentBlock() *types.Header {
Extra: make([]byte, subnetevm.WindowSize),
}
config := params.GetExtra(bc.config)
timeMS := blockTime * 1000
if config.IsGranite(blockTime) {
customtypes.GetHeaderExtra(parent).TimeMilliseconds = &timeMS
}
baseFee, err := customheader.BaseFee(
config, config.FeeConfig, parent, blockTime,
config, config.FeeConfig, parent, timeMS,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -154,14 +160,19 @@ func (bc *testBlockChain) CurrentBlock() *types.Header {
}
excessBlobGas := lo.Uint64()

return &types.Header{
head := &types.Header{
Number: blockNumber,
Time: blockTime,
GasLimit: gasLimit,
BaseFee: baseFee,
ExcessBlobGas: &excessBlobGas,
Extra: make([]byte, subnetevm.WindowSize),
}
if params.GetExtra(bc.config).IsGranite(blockTime) {
timeMS := blockTime * 1000
customtypes.GetHeaderExtra(head).TimeMilliseconds = &timeMS
}
return head
}

func (bc *testBlockChain) CurrentFinalBlock() *types.Header {
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
8 changes: 7 additions & 1 deletion core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ import (
"github.com/ava-labs/subnet-evm/core"
"github.com/ava-labs/subnet-evm/core/txpool"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
"github.com/holiman/uint256"
)

func TestMain(m *testing.M) {
params.RegisterExtras()
customtypes.Register()
os.Exit(m.Run())
}

Expand Down Expand Up @@ -110,10 +112,14 @@ func (bc *testBlockChain) CurrentBlock() *types.Header {
bc.lock.Lock()
defer bc.lock.Unlock()

return &types.Header{
header := &types.Header{
Number: new(big.Int),
GasLimit: bc.gasLimit.Load(),
}
if params.GetExtra(bc.config).IsGranite(0) {
customtypes.GetHeaderExtra(header).TimeMilliseconds = new(uint64)
}
return header
}

func (bc *testBlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
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
7 changes: 4 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte
if err != nil {
return nil, err
}
gasLimit, err := customheader.GasLimit(chainExtra, feeConfig, parent, header.Time)
gasLimit, err := customheader.GasLimit(chainExtra, feeConfig, parent, timestampMS)
if err != nil {
return nil, fmt.Errorf("calculating new gas limit: %w", err)
}
header.GasLimit = gasLimit

baseFee, err := customheader.BaseFee(chainExtra, feeConfig, parent, header.Time)
baseFee, err := customheader.BaseFee(chainExtra, feeConfig, parent, timestampMS)
if err != nil {
return nil, fmt.Errorf("failed to calculate new base fee: %w", err)
}
Expand Down Expand Up @@ -287,7 +287,8 @@ func (w *worker) createCurrentEnvironment(predicateContext *precompileconfig.Pre
return nil, err
}
chainConfig := params.GetExtra(w.chainConfig)
capacity, err := customheader.GasCapacity(chainConfig, feeConfig, parent, header.Time)
timeMS := customtypes.HeaderTimeMilliseconds(header)
capacity, err := customheader.GasCapacity(chainConfig, feeConfig, parent, timeMS)
if err != nil {
return nil, fmt.Errorf("calculating gas capacity: %w", err)
}
Expand Down
18 changes: 7 additions & 11 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 All @@ -23,8 +21,9 @@ func BaseFee(
config *extras.ChainConfig,
feeConfig commontype.FeeConfig,
parent *types.Header,
timestamp uint64,
timeMS uint64,
) (*big.Int, error) {
timestamp := timeMS / 1000
switch {
case config.IsSubnetEVM(timestamp):
return baseFeeFromWindow(config, feeConfig, parent, timestamp)
Expand All @@ -46,12 +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)
return BaseFee(config, feeConfig, parent, timestamp)
parentMS := customtypes.HeaderTimeMilliseconds(parent)
timeMS = max(timeMS, parentMS)
return BaseFee(config, feeConfig, parent, timeMS)
}
Loading
Loading