Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/ava-labs/coreth/core/state/snapshot"
"github.com/ava-labs/coreth/internal/version"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/plugin/evm/customlogs"
"github.com/ava-labs/coreth/plugin/evm/customrawdb"
"github.com/ava-labs/coreth/plugin/evm/customtypes"
"github.com/ava-labs/coreth/triedb/firewood"
Expand Down Expand Up @@ -624,7 +623,7 @@ func (bc *BlockChain) startAcceptor() {
bc.acceptorTipLock.Unlock()

// Update accepted feeds
flattenedLogs := customlogs.FlattenLogs(logs)
flattenedLogs := flattenLogs(logs)
bc.chainAcceptedFeed.Send(ChainEvent{Block: next, Hash: next.Hash(), Logs: flattenedLogs})
if len(flattenedLogs) > 0 {
bc.logsAcceptedFeed.Send(flattenedLogs)
Expand Down Expand Up @@ -1474,11 +1473,20 @@ func (bc *BlockChain) collectUnflattenedLogs(b *types.Block, removed bool) [][]*
return logs
}

// flattenLogs converts a nested array of logs to a single array of logs.
func flattenLogs(list [][]*types.Log) []*types.Log {
var flat []*types.Log
for _, logs := range list {
flat = append(flat, logs...)
}
return flat
}

// collectLogs collects the logs that were generated or removed during
// the processing of a block. These logs are later announced as deleted or reborn.
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
unflattenedLogs := bc.collectUnflattenedLogs(b, removed)
return customlogs.FlattenLogs(unflattenedLogs)
return flattenLogs(unflattenedLogs)
}

// reorg takes two blocks, an old chain and a new chain and will reconstruct the
Expand Down
16 changes: 10 additions & 6 deletions eth/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"math/big"

"github.com/ava-labs/coreth/core/bloombits"
"github.com/ava-labs/coreth/plugin/evm/customlogs"
"github.com/ava-labs/coreth/rpc"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
Expand Down Expand Up @@ -343,8 +342,10 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
return nil, err
}

unfiltered := customlogs.FlattenLogs(logsList)
logs := filterLogs(unfiltered, nil, nil, f.addresses, f.topics)
var logs []*types.Log
for _, txLogs := range logsList {
logs = append(logs, filterLogs(txLogs, nil, nil, f.addresses, f.topics)...)
}
if len(logs) == 0 {
return nil, nil
}
Expand All @@ -357,11 +358,14 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
if err != nil {
return nil, err
}
unfiltered = unfiltered[:0]
var receiptLogs [][]*types.Log
for _, receipt := range receipts {
unfiltered = append(unfiltered, receipt.Logs...)
receiptLogs = append(receiptLogs, receipt.Logs)
}
logs = logs[:0] // reset the slice
Copy link
Contributor

@joshua-kim joshua-kim Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug? We're resetting the slice - so all of the txLogs that matched the filter are now gone from the slice and are replaced by things in receiptLogs that match the filter.

The old code reset the slice because it put the unfiltered receipt logs into that var - and copied over things that matched the filter in to logs. If we wanted to simplify we could get rid of unfiltered and just have a single logs var that we just add matches to like:

	for _, r := range receipts {
		logs = append(logs, filterLogs(r.Logs, nil, nil, f.addresses, f.topics)...)
	}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is significantly cleaner thank you

Copy link
Contributor

@joshua-kim joshua-kim Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still reset the slice - is this a bug?

Copy link
Member Author

@JonathanOppenheimer JonathanOppenheimer Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so. first pass: we get some logs and filter them to find matches, then we check the log to see if has a TxHash, if yes return, if not the logs are incomplete, so we get the "real" full logs from reciepts, but first we throw away the incomplete logs (logs = logs[:0]) and then replace them with the complete filtered logs from receipts.

Copy link
Contributor

@joshua-kim joshua-kim Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the difference between receipts and underived logs (the sentinel value of empty hash is confusing to me - I don't know when it's supposed to be used) - so the reviewer on EVM should double-check me here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good - I would also appreciate some clarification. My understanding is that reciepts are a superset of logs, as they're both derived from the same source but undergo varying degrees of refinement. @ceyonur do you know?

for _, txLogs := range receiptLogs {
logs = append(logs, filterLogs(txLogs, nil, nil, f.addresses, f.topics)...)
}
logs = filterLogs(unfiltered, nil, nil, f.addresses, f.topics)

return logs, nil
}
Expand Down
14 changes: 0 additions & 14 deletions plugin/evm/customlogs/log_ext.go

This file was deleted.