Skip to content
Closed
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
42 changes: 24 additions & 18 deletions core/types/gen_log_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions core/types/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ type Log struct {
BlockHash common.Hash `json:"blockHash" rlp:"-"`
// index of the log in the block
Index uint `json:"logIndex" rlp:"-"`
// timestamp of the block in which the transaction was included
BlockTimestamp uint64 `json:"blockTimestamp" rlp:"-"`

// The Removed field is true if this log was reverted due to a chain reorganisation.
// You must pay attention to this field if you receive logs through a filter query.
Removed bool `json:"removed" rlp:"-"`
}

type logMarshaling struct {
Data hexutil.Bytes
BlockNumber hexutil.Uint64
TxIndex hexutil.Uint
Index hexutil.Uint
Data hexutil.Bytes
BlockNumber hexutil.Uint64
TxIndex hexutil.Uint
Index hexutil.Uint
BlockTimestamp hexutil.Uint64
}
1 change: 1 addition & 0 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu
rs[i].Logs[j].TxHash = rs[i].TxHash
rs[i].Logs[j].TxIndex = uint(i)
rs[i].Logs[j].Index = logIndex
rs[i].Logs[j].BlockTimestamp = time
logIndex++
}
}
Expand Down
45 changes: 25 additions & 20 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,23 @@ var (
Address: common.BytesToAddress([]byte{0x11}),
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
// derived fields:
BlockNumber: blockNumber.Uint64(),
TxHash: txs[0].Hash(),
TxIndex: 0,
BlockHash: blockHash,
Index: 0,
BlockNumber: blockNumber.Uint64(),
TxHash: txs[0].Hash(),
TxIndex: 0,
BlockHash: blockHash,
Index: 0,
BlockTimestamp: blockTime,
},
{
Address: common.BytesToAddress([]byte{0x01, 0x11}),
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
// derived fields:
BlockNumber: blockNumber.Uint64(),
TxHash: txs[0].Hash(),
TxIndex: 0,
BlockHash: blockHash,
Index: 1,
BlockNumber: blockNumber.Uint64(),
TxHash: txs[0].Hash(),
TxIndex: 0,
BlockHash: blockHash,
Index: 1,
BlockTimestamp: blockTime,
},
},
// derived fields:
Expand All @@ -199,21 +201,23 @@ var (
Address: common.BytesToAddress([]byte{0x22}),
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
// derived fields:
BlockNumber: blockNumber.Uint64(),
TxHash: txs[1].Hash(),
TxIndex: 1,
BlockHash: blockHash,
Index: 2,
BlockNumber: blockNumber.Uint64(),
TxHash: txs[1].Hash(),
TxIndex: 1,
BlockHash: blockHash,
Index: 2,
BlockTimestamp: blockTime,
},
{
Address: common.BytesToAddress([]byte{0x02, 0x22}),
Topics: []common.Hash{common.HexToHash("dead"), common.HexToHash("beef")},
// derived fields:
BlockNumber: blockNumber.Uint64(),
TxHash: txs[1].Hash(),
TxIndex: 1,
BlockHash: blockHash,
Index: 3,
BlockNumber: blockNumber.Uint64(),
TxHash: txs[1].Hash(),
TxIndex: 1,
BlockHash: blockHash,
Index: 3,
BlockTimestamp: blockTime,
},
},
// derived fields:
Expand Down Expand Up @@ -523,6 +527,7 @@ func clearComputedFieldsOnLogs(logs []*Log) []*Log {
cpy.TxHash = common.Hash{}
cpy.TxIndex = math.MaxUint32
cpy.Index = math.MaxUint32
cpy.BlockTimestamp = math.MaxUint32
l[i] = &cpy
}
return l
Expand Down
2 changes: 1 addition & 1 deletion eth/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
// such as tx index, block hash, etc.
// Notably tx hash is NOT filled in because it needs
// access to block body data.
cached, err := f.sys.cachedLogElem(ctx, hash, header.Number.Uint64())
cached, err := f.sys.cachedLogElem(ctx, hash, header.Number.Uint64(), header.Time)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion eth/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type logCacheElem struct {
}

// cachedLogElem loads block logs from the backend and caches the result.
func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Hash, number uint64) (*logCacheElem, error) {
func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Hash, number, time uint64) (*logCacheElem, error) {
cached, ok := sys.logsCache.Get(blockHash)
if ok {
return cached, nil
Expand All @@ -119,6 +119,7 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has
log.BlockNumber = number
log.TxIndex = uint(i)
log.Index = logIdx
log.BlockTimestamp = time
logIdx++
flattened = append(flattened, log)
}
Expand Down
Loading