Skip to content

Commit

Permalink
Fix ots_searchTransactions* rpc-tests (#12357)
Browse files Browse the repository at this point in the history
fixes #12248

This PR retrofits the receipts generator and remove lots of custom code
in order to fix the tests.

However it should be noticed that the receipts generator currently
replays the entire block and doesn't consume the receipts domain, i.e.,
eth_getTransactionReceipt still suffers from the same issue.

From our conversation on Discord, Illya is working on it, so let's wait
for his work be finished and we can retrofit his optimizations if
needed.

Also, I'm reenabling all `ots_searchTransactions*` rpc-tests, leaving
only `ots_searchTransactionsBefore/test_13.json` out. From my analysis
so far, that one is breaking because of another unrelated exception, so
I need more time to debug separately.
  • Loading branch information
wmitsuda authored Oct 18, 2024
1 parent 2f9180a commit 3126c30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 58 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/qa-rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,6 @@ jobs:
trace_replayTransaction/test_23.tar,\
trace_replayTransaction/test_24.json,\
trace_replayTransaction/test_29.tar,\
ots_searchTransactionsAfter/test_01.json,\
ots_searchTransactionsAfter/test_03.json,\
ots_searchTransactionsAfter/test_04.json,\
ots_searchTransactionsAfter/test_06.json,\
ots_searchTransactionsAfter/test_08.json,\
ots_searchTransactionsAfter/test_09.json,\
ots_searchTransactionsAfter/test_10.json,\
ots_searchTransactionsAfter/test_11.json,\
ots_searchTransactionsAfter/test_12.json,\
ots_searchTransactionsAfter/test_13.json,\
ots_searchTransactionsBefore/test_01.json,\
ots_searchTransactionsBefore/test_03.json,\
ots_searchTransactionsBefore/test_04.json,\
ots_searchTransactionsBefore/test_06.json,\
ots_searchTransactionsBefore/test_09.json,\
ots_searchTransactionsBefore/test_10.json,\
ots_searchTransactionsBefore/test_11.json,\
ots_searchTransactionsBefore/test_12.json,\
admin_nodeInfo/test_01.json,\
admin_peers/test_01.json,\
erigon_nodeInfo/test_1.json,\
Expand Down Expand Up @@ -260,9 +242,7 @@ jobs:
ots_getBlockTransactions/test_03.json,\
ots_getBlockTransactions/test_04.json,\
ots_getBlockTransactions/test_05.json,\
ots_searchTransactionsAfter/test_14.json,\
ots_searchTransactionsBefore/test_13.json,\
ots_searchTransactionsBefore/test_14.json,\
trace_call/test_05.json,\
trace_call/test_07.json,\
trace_call/test_12.json,\
Expand Down
55 changes: 17 additions & 38 deletions turbo/jsonrpc/otterscan_search_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/erigontech/erigon-lib/kv/rawdbv3"
"github.com/erigontech/erigon-lib/kv/stream"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/cmd/state/exec3"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/eth/ethutils"
"github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks"
Expand All @@ -45,20 +44,16 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo
return nil, nil, false, err
}

exec := exec3.NewTraceWorker(tx, chainConfig, api.engine(), api._blockReader, nil)
defer exec.Close()

var blockHash common.Hash
var header *types.Header
var block *types.Block
txs := make([]*RPCTransaction, 0, pageSize)
receipts := make([]map[string]interface{}, 0, pageSize)
resultCount := uint16(0)

mustReadHeader := true
mustReadBlock := true
reachedPageSize := false
hasMore := false
for txNumsIter.HasNext() {
txNum, blockNum, txIndex, isFinalTxn, blockNumChanged, err := txNumsIter.Next()
_, blockNum, txIndex, isFinalTxn, blockNumChanged, err := txNumsIter.Next()
if err != nil {
return nil, nil, false, err
}
Expand All @@ -71,25 +66,23 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo
break
}

// Avoid reading the same block multiple times; multiple matches in the same block
// may be common.
mustReadBlock = mustReadBlock || blockNumChanged

// it is necessary to track dirty/lazy-must-read block headers
// because we skip system txs like rewards (which are not "real" txs
// for this rpc purposes)
mustReadHeader = mustReadHeader || blockNumChanged
if isFinalTxn {
continue
}

if mustReadHeader {
if header, err = api._blockReader.HeaderByNumber(ctx, tx, blockNum); err != nil {
if mustReadBlock {
block, err = api.blockByNumberWithSenders(ctx, tx, blockNum)
if err != nil {
return nil, nil, false, err
}
if header == nil {
log.Warn("[rpc] header is nil", "blockNum", blockNum)
continue
}
blockHash = header.Hash()
exec.ChangeBlock(header)
mustReadHeader = false
mustReadBlock = false
}

txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, txIndex)
Expand All @@ -100,30 +93,16 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo
log.Warn("[rpc] txn not found", "blockNum", blockNum, "txIndex", txIndex)
continue
}
res, err := exec.ExecTxn(txNum, txIndex, txn, true)
rpcTx := NewRPCTransaction(txn, block.Hash(), blockNum, uint64(txIndex), block.BaseFee())
txs = append(txs, rpcTx)

receipt, err := api.receiptsGenerator.GetReceipt(ctx, chainConfig, tx, block, txIndex, false)
if err != nil {
return nil, nil, false, err
}
rawLogs := exec.GetLogs(txIndex, txn.Hash(), blockNum, blockHash)
rpcTx := NewRPCTransaction(txn, blockHash, blockNum, uint64(txIndex), header.BaseFee)
txs = append(txs, rpcTx)
receipt := &types.Receipt{
Type: txn.Type(),
GasUsed: res.UsedGas,
CumulativeGasUsed: res.UsedGas, // TODO: cumulative gas is wrong, wait for cumulative gas index fix
TransactionIndex: uint(txIndex),
BlockNumber: header.Number,
BlockHash: blockHash,
Logs: rawLogs,
}
if res.Failed() {
receipt.Status = types.ReceiptStatusFailed
} else {
receipt.Status = types.ReceiptStatusSuccessful
}

mReceipt := ethutils.MarshalReceipt(receipt, txn, chainConfig, header, txn.Hash(), true)
mReceipt["timestamp"] = header.Time
mReceipt := ethutils.MarshalReceipt(receipt, txn, chainConfig, block.HeaderNoCopy(), txn.Hash(), true)
mReceipt["timestamp"] = block.Time()
receipts = append(receipts, mReceipt)

resultCount++
Expand Down

0 comments on commit 3126c30

Please sign in to comment.