Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set log index across all transactions in a block #2067

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
for i, l := range r.Logs {
l.Index = uint32(i)
}
bloom = ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: evmkeeper.GetLogsForTx(r)}})
bloom = ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: evmkeeper.GetLogsForTx(r, 0)}})
r.LogsBloom = bloom[:]
_ = app.EvmKeeper.SetTransientReceipt(wasmToEvmEventCtx, txHash, r)
} else {
Expand Down
4 changes: 3 additions & 1 deletion evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (f *LogFetcher) GetLogsForBlock(block *coretypes.ResultBlock, crit filters.

func (f *LogFetcher) FindLogsByBloom(block *coretypes.ResultBlock, filters [][]bloomIndexes) (res []*ethtypes.Log) {
ctx := f.ctxProvider(LatestCtxHeight)
totalLogs := uint(0)
for _, hash := range getTxHashesFromBlock(block, f.txConfig, f.includeSyntheticReceipts) {
receipt, err := f.k.GetReceipt(ctx, hash)
if err != nil {
Expand All @@ -436,8 +437,9 @@ func (f *LogFetcher) FindLogsByBloom(block *coretypes.ResultBlock, filters [][]b
continue
}
if len(receipt.LogsBloom) > 0 && MatchFilters(ethtypes.Bloom(receipt.LogsBloom), filters) {
res = append(res, keeper.GetLogsForTx(receipt)...)
res = append(res, keeper.GetLogsForTx(receipt, totalLogs)...)
}
totalLogs += uint(len(receipt.Logs))
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion evmrpc/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func GetEvmTxIndex(txs tmtypes.Txs, txIndex uint32, decoder sdk.TxDecoder, recei
func encodeReceipt(receipt *types.Receipt, decoder sdk.TxDecoder, block *coretypes.ResultBlock, receiptChecker func(common.Hash) bool) (map[string]interface{}, error) {
blockHash := block.BlockID.Hash
bh := common.HexToHash(blockHash.String())
logs := keeper.GetLogsForTx(receipt)
logs := keeper.GetLogsForTx(receipt, 0)
for _, log := range logs {
log.BlockHash = bh
}
Expand Down
8 changes: 4 additions & 4 deletions x/evm/keeper/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ func (k *Keeper) GetLegacyBlockBloomCutoffHeight(ctx sdk.Context) int64 {
return int64(binary.BigEndian.Uint64(bz))
}

func GetLogsForTx(receipt *types.Receipt) []*ethtypes.Log {
return utils.Map(receipt.Logs, func(l *types.Log) *ethtypes.Log { return convertLog(l, receipt) })
func GetLogsForTx(receipt *types.Receipt, logStartIndex uint) []*ethtypes.Log {
return utils.Map(receipt.Logs, func(l *types.Log) *ethtypes.Log { return convertLog(l, receipt, logStartIndex) })
}

func convertLog(l *types.Log, receipt *types.Receipt) *ethtypes.Log {
func convertLog(l *types.Log, receipt *types.Receipt, logStartIndex uint) *ethtypes.Log {
return &ethtypes.Log{
Address: common.HexToAddress(l.Address),
Topics: utils.Map(l.Topics, common.HexToHash),
Data: l.Data,
BlockNumber: receipt.BlockNumber,
TxHash: common.HexToHash(receipt.TxHashHex),
TxIndex: uint(receipt.TransactionIndex),
Index: uint(l.Index)}
Index: uint(l.Index) + logStartIndex}
}

func ConvertEthLog(l *ethtypes.Log) *types.Log {
Expand Down
9 changes: 8 additions & 1 deletion x/evm/keeper/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestGetLogsForTx(t *testing.T) {
}

// Convert the types.Receipt to a list of ethtypes.Log objects
logs := keeper.GetLogsForTx(receipt)
logs := keeper.GetLogsForTx(receipt, 0)

// Check that the fields match
require.Equal(t, len(receipt.Logs), len(logs))
Expand All @@ -82,6 +82,13 @@ func TestGetLogsForTx(t *testing.T) {
require.Equal(t, receipt.Logs[i].Data, log.Data)
require.Equal(t, uint(receipt.Logs[i].Index), log.Index)
}

// non-zero starting index
logs = keeper.GetLogsForTx(receipt, 5)
require.Equal(t, len(receipt.Logs), len(logs))
for i, log := range logs {
require.Equal(t, uint(receipt.Logs[i].Index+5), log.Index)
}
}

func TestLegacyBlockBloomCutoffHeight(t *testing.T) {
Expand Down
Loading