Skip to content

Commit

Permalink
Calculate correct intrinsic gas
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamc1 committed Jan 16, 2025
1 parent a85a28d commit 4efebfe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions txnprovider/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func (p *TxPool) best(ctx context.Context, n int, txns *TxnsRlp, onTopOf, availa
// not an exact science using intrinsic gas but as close as we could hope for at
// this stage
authorizationLen := uint64(len(mt.TxnSlot.Authorizations))
intrinsicGas, floorGas, _ := fixedgas.CalcIntrinsicGas(uint64(mt.TxnSlot.DataLen), uint64(mt.TxnSlot.DataNonZeroLen), authorizationLen, 0, 0, mt.TxnSlot.Creation, true, true, isShanghai, isPrague)
intrinsicGas, floorGas, _ := fixedgas.CalcIntrinsicGas(uint64(mt.TxnSlot.DataLen), uint64(mt.TxnSlot.DataNonZeroLen), authorizationLen, uint64(mt.TxnSlot.AccessListAddrCount), uint64(mt.TxnSlot.AccessListStorCount), mt.TxnSlot.Creation, true, true, isShanghai, isPrague)
if isPrague && floorGas > intrinsicGas {
intrinsicGas = floorGas
}
Expand Down Expand Up @@ -906,7 +906,7 @@ func (p *TxPool) validateTx(txn *TxnSlot, isLocal bool, stateCache kvcache.Cache
return txpoolcfg.UnderPriced
}

gas, floorGas, overflow := fixedgas.CalcIntrinsicGas(uint64(txn.DataLen), uint64(txn.DataNonZeroLen), uint64(authorizationLen), 0, 0, txn.Creation, true, true, isShanghai, p.isPrague())
gas, floorGas, overflow := fixedgas.CalcIntrinsicGas(uint64(txn.DataLen), uint64(txn.DataNonZeroLen), uint64(authorizationLen), uint64(txn.AccessListAddrCount), uint64(txn.AccessListStorCount), txn.Creation, true, true, isShanghai, p.isPrague())
if p.isPrague() && floorGas > gas {
gas = floorGas
}
Expand Down
36 changes: 18 additions & 18 deletions txnprovider/txpool/pool_txn_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (ctx *TxnParseContext) parseTransactionBody(payload []byte, pos, p0 int, sl
if err != nil {
return 0, fmt.Errorf("%w: tuple addr len: %s", ErrParseTxn, err) //nolint
}
slot.AlAddrCount++
slot.AccessListAddrCount++
var storagePos, storageLen int
storagePos, storageLen, err = rlp.ParseList(payload, addrPos+20)
if err != nil {
Expand All @@ -446,7 +446,7 @@ func (ctx *TxnParseContext) parseTransactionBody(payload []byte, pos, p0 int, sl
if err != nil {
return 0, fmt.Errorf("%w: tuple storage key len: %s", ErrParseTxn, err) //nolint
}
slot.AlStorCount++
slot.AccessListStorCount++
sKeyPos += 32
}
if sKeyPos != storagePos+storageLen {
Expand Down Expand Up @@ -659,22 +659,22 @@ func (ctx *TxnParseContext) parseTransactionBody(payload []byte, pos, p0 int, sl
// TxnSlot contains information extracted from an Ethereum transaction, which is enough to manage it inside the transaction.
// Also, it contains some auxiliary information, like ephemeral fields, and indices within priority queues
type TxnSlot struct {
Rlp []byte // Is set to nil after flushing to db, frees memory, later we look for it in the db, if needed
Value uint256.Int // Value transferred by the transaction
Tip uint256.Int // Maximum tip that transaction is giving to miner/block proposer
FeeCap uint256.Int // Maximum fee that transaction burns and gives to the miner/block proposer
SenderID uint64 // SenderID - require external mapping to it's address
Nonce uint64 // Nonce of the transaction
DataLen int // Length of transaction's data (for calculation of intrinsic gas)
DataNonZeroLen int
AlAddrCount int // Number of addresses in the access list
AlStorCount int // Number of storage keys in the access list
Gas uint64 // Gas limit of the transaction
IDHash [32]byte // Transaction hash for the purposes of using it as a transaction Id
Traced bool // Whether transaction needs to be traced throughout transaction pool code and generate debug printing
Creation bool // Set to true if "To" field of the transaction is not set
Type byte // Transaction type
Size uint32 // Size of the payload (without the RLP string envelope for typed transactions)
Rlp []byte // Is set to nil after flushing to db, frees memory, later we look for it in the db, if needed
Value uint256.Int // Value transferred by the transaction
Tip uint256.Int // Maximum tip that transaction is giving to miner/block proposer
FeeCap uint256.Int // Maximum fee that transaction burns and gives to the miner/block proposer
SenderID uint64 // SenderID - require external mapping to it's address
Nonce uint64 // Nonce of the transaction
DataLen int // Length of transaction's data (for calculation of intrinsic gas)
DataNonZeroLen int
AccessListAddrCount int // Number of addresses in the access list
AccessListStorCount int // Number of storage keys in the access list
Gas uint64 // Gas limit of the transaction
IDHash [32]byte // Transaction hash for the purposes of using it as a transaction Id
Traced bool // Whether transaction needs to be traced throughout transaction pool code and generate debug printing
Creation bool // Set to true if "To" field of the transaction is not set
Type byte // Transaction type
Size uint32 // Size of the payload (without the RLP string envelope for typed transactions)

// EIP-4844: Shard Blob Transactions
BlobFeeCap uint256.Int // max_fee_per_blob_gas
Expand Down
4 changes: 2 additions & 2 deletions txnprovider/txpool/pool_txn_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ func TestBlobTxnParsing(t *testing.T) {
assert.Equal(t, thinTxn.Nonce, fatTxn.Nonce)
assert.Equal(t, thinTxn.DataLen, fatTxn.DataLen)
assert.Equal(t, thinTxn.DataNonZeroLen, fatTxn.DataNonZeroLen)
assert.Equal(t, thinTxn.AlAddrCount, fatTxn.AlAddrCount)
assert.Equal(t, thinTxn.AlStorCount, fatTxn.AlStorCount)
assert.Equal(t, thinTxn.AccessListAddrCount, fatTxn.AccessListAddrCount)
assert.Equal(t, thinTxn.AccessListStorCount, fatTxn.AccessListStorCount)
assert.Equal(t, thinTxn.Gas, fatTxn.Gas)
assert.Equal(t, thinTxn.IDHash, fatTxn.IDHash)
assert.Equal(t, thinTxn.Creation, fatTxn.Creation)
Expand Down

0 comments on commit 4efebfe

Please sign in to comment.