Fix for issue 4205 (optimize eth_getLogs) (#4662)

* optimize eth_getLogs

* used the implementation from api._blockReader

* used the implementation from api._blockReader
This commit is contained in:
Leonard Chinonso 2022-07-09 14:42:57 +01:00 committed by GitHub
parent 0ca3ff3858
commit cfc051892e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -155,11 +155,11 @@ func (api *APIImpl) GetLogs(ctx context.Context, crit filters.FilterCriteria) ([
return nil, err
}
block := uint64(iter.Next())
blockNumber := uint64(iter.Next())
var logIndex uint
var txIndex uint
var blockLogs []*types.Log
err := tx.ForPrefix(kv.Log, dbutils.EncodeBlockNumber(block), func(k, v []byte) error {
err := tx.ForPrefix(kv.Log, dbutils.EncodeBlockNumber(blockNumber), func(k, v []byte) error {
var logs types.Logs
if err := cbor.Unmarshal(&logs, bytes.NewReader(v)); err != nil {
return fmt.Errorf("receipt unmarshal failed: %w", err)
@ -187,18 +187,19 @@ func (api *APIImpl) GetLogs(ctx context.Context, crit filters.FilterCriteria) ([
continue
}
b, err := api.blockByNumberWithSenders(tx, block)
blockHash, err := rawdb.ReadCanonicalHash(tx, blockNumber)
if err != nil {
return nil, err
}
if b == nil {
return nil, fmt.Errorf("block not found %d", block)
body, err := api._blockReader.BodyWithTransactions(ctx, tx, blockHash, blockNumber)
if err != nil || body == nil {
return nil, fmt.Errorf("block not found %d", blockNumber)
}
blockHash := b.Hash()
for _, log := range blockLogs {
log.BlockNumber = block
log.BlockNumber = blockNumber
log.BlockHash = blockHash
log.TxHash = b.Transactions()[log.TxIndex].Hash()
log.TxHash = body.Transactions[log.TxIndex].Hash()
}
logs = append(logs, blockLogs...)