e3: eth_getLogs simplify (#6660)

This commit is contained in:
Alex Sharov 2023-01-22 16:48:54 +07:00 committed by GitHub
parent 0ee8c175d9
commit 5a7e0eb5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -358,35 +358,24 @@ func (api *APIImpl) getLogsV3(ctx context.Context, tx kv.TemporalTx, begin, end
} }
exec := newIntraBlockExec(tx, chainConfig, api.engine()) exec := newIntraBlockExec(tx, chainConfig, api.engine())
var lastBlockNum uint64
var blockHash libcommon.Hash var blockHash libcommon.Hash
var header *types.Header var header *types.Header
var minTxNumInBlock, maxTxNumInBlock uint64 // end is an inclusive bound
var blockNum uint64
var ok bool
iter := txNumbers.Iterator() iter := MapTxNum2BlockNum(tx, bitmapdb.ToIter(txNumbers.Iterator()))
for iter.HasNext() { for iter.HasNext() {
if err = ctx.Err(); err != nil { if err = ctx.Err(); err != nil {
return nil, err return nil, err
} }
txNum := iter.Next() txNum, blockNum, txIndex, isFinalTxn, blockNumChanged, err := iter.Next()
if err != nil {
// txNums are sorted, it means blockNum will not change until `txNum < maxTxNum` return nil, err
if maxTxNumInBlock == 0 || txNum > maxTxNumInBlock {
// Find block number
ok, blockNum, err = rawdb.TxNums.FindBlockNum(tx, txNum)
if err != nil {
return nil, err
}
} }
if !ok { if isFinalTxn {
break continue
} }
// if block number changed, calculate all related field // if block number changed, calculate all related field
if blockNum > lastBlockNum { if blockNumChanged {
if header, err = api._blockReader.HeaderByNumber(ctx, tx, blockNum); err != nil { if header, err = api._blockReader.HeaderByNumber(ctx, tx, blockNum); err != nil {
return nil, err return nil, err
} }
@ -394,20 +383,10 @@ func (api *APIImpl) getLogsV3(ctx context.Context, tx kv.TemporalTx, begin, end
log.Warn("header is nil", "blockNum", blockNum) log.Warn("header is nil", "blockNum", blockNum)
continue continue
} }
lastBlockNum = blockNum
blockHash = header.Hash() blockHash = header.Hash()
exec.changeBlock(header) exec.changeBlock(header)
minTxNumInBlock, err = rawdb.TxNums.Min(tx, blockNum)
if err != nil {
return nil, err
}
maxTxNumInBlock, err = rawdb.TxNums.Max(tx, blockNum)
if err != nil {
return nil, err
}
} }
txIndex := int(txNum) - int(minTxNumInBlock) - 1
//fmt.Printf("txNum=%d, blockNum=%d, txIndex=%d, maxTxNumInBlock=%d,mixTxNumInBlock=%d\n", txNum, blockNum, txIndex, maxTxNumInBlock, minTxNumInBlock) //fmt.Printf("txNum=%d, blockNum=%d, txIndex=%d, maxTxNumInBlock=%d,mixTxNumInBlock=%d\n", txNum, blockNum, txIndex, maxTxNumInBlock, minTxNumInBlock)
txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, txIndex) txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, txIndex)
if err != nil { if err != nil {