Skip to content
Open
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 accounts/abi/bind/v2/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
if gasFeeCap == nil {
gasFeeCap = new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(head.BaseFee, big.NewInt(basefeeWiggleMultiplier)),
new(big.Int).Mul(head.BaseFee(), big.NewInt(basefeeWiggleMultiplier)),
)
}
if gasFeeCap.Cmp(gasTipCap) < 0 {
Expand Down
3 changes: 2 additions & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
GasLimit: data.GasLimit,
GasUsed: data.GasUsed,
Time: data.Timestamp,
BaseFee: data.BaseFeePerGas,
EthBaseFee: data.BaseFeePerGas,
RskMinimumGasPrice: data.BaseFeePerGas,
Extra: data.ExtraData,
MixDigest: data.Random,
WithdrawalsHash: withdrawalsRoot,
Expand Down
18 changes: 9 additions & 9 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
}
}
// Verify the header is not malformed
if header.BaseFee == nil {
if header.BaseFee() == nil {
return errors.New("header is missing baseFee")
}
// Verify the baseFee is correct based on the parent header.
expectedBaseFee := CalcBaseFee(config, parent, header.Time)
if header.BaseFee.Cmp(expectedBaseFee) != 0 {
if header.BaseFee().Cmp(expectedBaseFee) != 0 {
return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
header.BaseFee, expectedBaseFee, parent.BaseFee, parent.GasUsed)
header.BaseFee(), expectedBaseFee, parent.BaseFee(), parent.GasUsed)
}
return nil
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func calcBaseFeeInner(config *params.ChainConfig, parent *types.Header, elastici
}
// If the parent gasMetered is the same as the target, the baseFee remains unchanged.
if parentGasMetered == parentGasTarget {
return new(big.Int).Set(parent.BaseFee)
return new(big.Int).Set(parent.BaseFee())
}

var (
Expand All @@ -115,22 +115,22 @@ func calcBaseFeeInner(config *params.ChainConfig, parent *types.Header, elastici
// If the parent block used more gas than its target, the baseFee should increase.
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasMetered - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Mul(num, parent.BaseFee())
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(denominator))
if num.Cmp(common.Big1) < 0 {
return num.Add(parent.BaseFee, common.Big1)
return num.Add(parent.BaseFee(), common.Big1)
}
return num.Add(parent.BaseFee, num)
return num.Add(parent.BaseFee(), num)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasTarget - parentGasMetered)
num.Mul(num, parent.BaseFee)
num.Mul(num, parent.BaseFee())
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(denominator))

baseFee := num.Sub(parent.BaseFee, num)
baseFee := num.Sub(parent.BaseFee(), num)
if baseFee.Cmp(common.Big0) < 0 {
baseFee = common.Big0
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/misc/eip4844/eip4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func calcExcessBlobGas(isOsaka bool, bcfg *BlobConfig, parent *types.Header) uin
if isOsaka {
var (
baseCost = big.NewInt(params.BlobBaseCost)
reservePrice = baseCost.Mul(baseCost, parent.BaseFee)
reservePrice = baseCost.Mul(baseCost, parent.BaseFee())
blobPrice = bcfg.blobPrice(parentExcessBlobGas)
)
if reservePrice.Cmp(blobPrice) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_optimism.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
)

func updateOptimismBlockMetrics(header *types.Header) error {
headBaseFeeGauge.TryUpdate(header.BaseFee)
headBaseFeeGauge.TryUpdate(header.BaseFee())
headGasUsedGauge.Update(int64(header.GasUsed))
headBlobGasUsedGauge.TryUpdateUint64(header.BlobGasUsed)
headGasUsedHist.Update(int64(header.GasUsed))
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (bc *BlockChain) GetCanonicalReceipt(tx *types.Transaction, blockHash commo
BlockHash: blockHash,
BlockNumber: blockNumber,
BlockTime: header.Time,
BaseFee: header.BaseFee,
BaseFee: header.BaseFee(),
BlobGasPrice: blobGasPrice,
GasUsed: ctx.GasUsed,
LogIndex: ctx.LogIndex,
Expand Down
6 changes: 3 additions & 3 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (b *BlockGen) Timestamp() uint64 {

// BaseFee returns the EIP-1559 base fee of the block being generated.
func (b *BlockGen) BaseFee() *big.Int {
return new(big.Int).Set(b.header.BaseFee)
return new(big.Int).Set(b.header.BaseFee())
}

// Gas returns the amount of gas left in the current block.
Expand Down Expand Up @@ -239,7 +239,7 @@ func (b *BlockGen) AddUncle(h *types.Header) {
// The gas limit and price should be derived from the parent
h.GasLimit = parent.GasLimit
if b.cm.config.IsLondon(h.Number) {
h.BaseFee = eip1559.CalcBaseFee(b.cm.config, parent, h.Time)
h.EthBaseFee = eip1559.CalcBaseFee(b.cm.config, parent, h.Time)
if !b.cm.config.IsLondon(parent.Number) {
parentGasLimit := parent.GasLimit * b.cm.config.ElasticityMultiplier()
h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
Expand Down Expand Up @@ -619,7 +619,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
}

if cm.config.IsLondon(header.Number) {
header.BaseFee = eip1559.CalcBaseFee(cm.config, parentHeader, header.Time)
header.EthBaseFee = eip1559.CalcBaseFee(cm.config, parentHeader, header.Time)
if !cm.config.IsLondon(parent.Number()) {
parentGasLimit := parent.GasLimit() * cm.config.ElasticityMultiplier()
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
Expand Down
4 changes: 2 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
} else {
beneficiary = *author
}
if header.BaseFee != nil {
baseFee = new(big.Int).Set(header.BaseFee)
if header.BaseFee() != nil {
baseFee = new(big.Int).Set(header.BaseFee())
}
if header.ExcessBlobGas != nil {
blobBaseFee = eip4844.CalcBlobFee(chain.Config(), header)
Expand Down
11 changes: 7 additions & 4 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
genesis.Difficulty = genesisHeader.Difficulty
genesis.Mixhash = genesisHeader.MixDigest
genesis.Coinbase = genesisHeader.Coinbase
genesis.BaseFee = genesisHeader.BaseFee
genesis.BaseFee = genesisHeader.BaseFee()
genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas
genesis.BlobGasUsed = genesisHeader.BlobGasUsed
// A nil or empty alloc, with a non-matching state-root in the block header, intents to override the state-root.
Expand Down Expand Up @@ -619,7 +619,8 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has
Extra: g.ExtraData,
GasLimit: g.GasLimit,
GasUsed: g.GasUsed,
BaseFee: g.BaseFee,
EthBaseFee: g.BaseFee,
RskMinimumGasPrice: g.BaseFee,
Difficulty: g.Difficulty,
MixDigest: g.Mixhash,
Coinbase: g.Coinbase,
Expand All @@ -637,9 +638,11 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has
}
if g.Config != nil && g.Config.IsLondon(common.Big0) {
if g.BaseFee != nil {
head.BaseFee = g.BaseFee
head.EthBaseFee = g.BaseFee
head.RskMinimumGasPrice = g.BaseFee
} else {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
head.EthBaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
head.RskMinimumGasPrice = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
var withdrawals []*types.Withdrawal
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 @@ -617,7 +617,7 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64,
if header == nil {
baseFee = big.NewInt(0)
} else {
baseFee = header.BaseFee
baseFee = header.BaseFee()
}
// Compute effective blob gas price.
var blobGasPrice *big.Int
Expand Down
1 change: 1 addition & 0 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (j *journal) revertToSnapshot(revid int, s *StateDB) {
return j.validRevisions[i].id >= revid
})
if idx == len(j.validRevisions) || j.validRevisions[idx].id != revid {
fmt.Printf("\n\n journal.go ~ revertToSnapshot ~ revision id %v cannot be reverted\n\n", revid)
panic(fmt.Errorf("revision id %v cannot be reverted", revid))
}
snapshot := j.validRevisions[idx].journalIndex
Expand Down
3 changes: 3 additions & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ func (s *stateObject) empty() bool {

// newObject creates a state object.
func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *stateObject {
fmt.Println("state_object.go ~ newObject ~ Creating state object", address, acct)
origin := acct
if acct == nil {
acct = types.NewEmptyStateAccount()
fmt.Println("state_object.go ~ newObject ~ New empty state account", acct)
}
fmt.Println("state_object.go ~ newObject ~ State account", acct)
return &stateObject{
db: db,
address: address,
Expand Down
5 changes: 5 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject {

start := time.Now()
acct, err := s.reader.Account(addr)
fmt.Println("statedb.go ~ getStateObject ~ Account", acct, err)
if err != nil {
s.setError(fmt.Errorf("getStateObject (%x) error: %w", addr.Bytes(), err))
return nil
Expand All @@ -647,17 +648,21 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject {

// Short circuit if the account is not found
if acct == nil {
fmt.Println("statedb.go ~ getStateObject ~ Account is nil")
return nil
}
// Schedule the resolved account for prefetching if it's enabled.
if s.prefetcher != nil {
fmt.Println("statedb.go ~ getStateObject ~ Prefetcher is not nil")
if err = s.prefetcher.prefetch(common.Hash{}, s.originalRoot, common.Address{}, []common.Address{addr}, nil, true); err != nil {
log.Error("Failed to prefetch account", "addr", addr, "err", err)
}
}
// Insert into the live set
obj := newObject(s, addr, acct)
fmt.Println("statedb.go ~ getStateObject ~ Setting state object", obj)
s.setStateObject(obj)
fmt.Println("statedb.go ~ getStateObject ~ State object set", obj)
return obj
}

Expand Down
7 changes: 7 additions & 0 deletions core/state/trie_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package state

import (
"errors"
"fmt"
"sync"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -159,6 +160,7 @@ func (p *triePrefetcher) report() {
// repeated.
// 2. Finalize of the main account trie. This happens only once per block.
func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr common.Address, addrs []common.Address, slots []common.Hash, read bool) error {
fmt.Println("trie_prefetcher.go ~ prefetch ~ Prefetching", owner, root, addr, addrs, slots, read)
// If the state item is only being read, but reads are disabled, return
if read && p.noreads {
return nil
Expand All @@ -170,11 +172,16 @@ func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr comm
default:
}
id := p.trieID(owner, root)
fmt.Println("trie_prefetcher.go ~ prefetch ~ Trie ID", id)
fetcher := p.fetchers[id]
if fetcher == nil {
fmt.Println("trie_prefetcher.go ~ prefetch ~ New subfetcher")
fetcher = newSubfetcher(p.db, p.root, owner, root, addr)
p.fetchers[id] = fetcher
} else {
fmt.Println("trie_prefetcher.go ~ prefetch ~ Subfetcher already exists")
}
fmt.Println("trie_prefetcher.go ~ prefetch ~ Scheduling", addrs, slots, read)
return fetcher.schedule(addrs, slots, read)
}

Expand Down
2 changes: 1 addition & 1 deletion core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
evm := vm.NewEVM(NewEVMBlockContext(header, p.chain, nil, p.config, stateCpy), stateCpy, p.config, cfg)

// Convert the transaction into an executable message and pre-cache its sender
msg, err := TransactionToMessage(tx, signer, header.BaseFee)
msg, err := TransactionToMessage(tx, signer, header.EthBaseFee)
if err != nil {
fails.Add(1)
return nil // Also invalid block, bail out
Expand Down
4 changes: 2 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg

// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
msg, err := TransactionToMessage(tx, signer, header.BaseFee)
msg, err := TransactionToMessage(tx, signer, header.BaseFee())
if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, error) {
msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee)
msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee())
if err != nil {
return nil, err
}
Expand Down
Loading