Skip to content

Commit

Permalink
fix(eth_receipts): gasUsed not cumGasUsed (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
revitteth authored Dec 9, 2024
1 parent c87f9bb commit 0792a9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 13 additions & 4 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ type EthAPI interface {
}

type BaseAPI struct {
stateCache kvcache.Cache // thread-safe
blocksLRU *lru.Cache[common.Hash, *types.Block] // thread-safe
stateCache kvcache.Cache // thread-safe
blocksLRU *lru.Cache[common.Hash, *types.Block] // thread-safe
receiptsCache *lru.Cache[common.Hash, []*types.Receipt]

filters *rpchelper.Filters
_chainConfig atomic.Pointer[chain.Config]
_genesis atomic.Pointer[types.Block]
Expand All @@ -132,16 +134,23 @@ type BaseAPI struct {
}

func NewBaseApi(f *rpchelper.Filters, stateCache kvcache.Cache, blockReader services.FullBlockReader, agg *libstate.AggregatorV3, singleNodeMode bool, evmCallTimeout time.Duration, engine consensus.EngineReader, dirs datadir.Dirs) *BaseAPI {
blocksLRUSize := 128 // ~32Mb
var (
blocksLRUSize = 128 // ~32Mb
receiptsCacheLimit = 32
)
if !singleNodeMode {
blocksLRUSize = 512
}
blocksLRU, err := lru.New[common.Hash, *types.Block](blocksLRUSize)
if err != nil {
panic(err)
}
receiptsCache, err := lru.New[common.Hash, []*types.Receipt](receiptsCacheLimit)
if err != nil {
panic(err)
}

return &BaseAPI{filters: f, stateCache: stateCache, blocksLRU: blocksLRU, _blockReader: blockReader, _txnReader: blockReader, _agg: agg, evmCallTimeout: evmCallTimeout, _engine: engine, dirs: dirs}
return &BaseAPI{filters: f, stateCache: stateCache, blocksLRU: blocksLRU, _blockReader: blockReader, _txnReader: blockReader, _agg: agg, evmCallTimeout: evmCallTimeout, _engine: engine, dirs: dirs, receiptsCache: receiptsCache}
}

func (api *BaseAPI) SetGasless(gasless bool) {
Expand Down
14 changes: 12 additions & 2 deletions cmd/rpcdaemon/commands/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ import (
)

func (api *BaseAPI) getReceipts(ctx context.Context, tx kv.Tx, chainConfig *chain.Config, block *types.Block, senders []common.Address) (types.Receipts, error) {
if cached := rawdb.ReadReceipts_zkEvm(tx, block, senders); cached != nil {
return cached, nil
if receipts, ok := api.receiptsCache.Get(block.Hash()); ok {
return receipts, nil
}

if receipts := rawdb.ReadReceipts(tx, block, senders); receipts != nil {
api.receiptsCache.Add(block.Hash(), receipts)
return receipts, nil
}

engine := api.engine()
chainConfig, err := api.chainConfig(tx)
if err != nil {
return nil, err
}

txEnv, err := transactions.ComputeTxEnv_ZkEvm(ctx, engine, block, chainConfig, api._blockReader, tx, 0, api.historyV3(tx))
if err != nil {
Expand Down

0 comments on commit 0792a9c

Please sign in to comment.