Skip to content

Commit 7522642

Browse files
s1nafjl
andauthored
core/types: remove LogForStorage type (#23173)
The encoding of Log and LogForStorage is exactly the same now. After tracking it down it seems like #17106 changed the storage schema of logs to be the same as the consensus encoding. Support for the legacy format was dropped in #22852 and if I'm not wrong there's no reason anymore to have these two equivalent types. Since the RLP encoding simply contains the first three fields of Log, we can also avoid creating a temporary struct for encoding/decoding, and use the rlp:"-" tag in Log instead. Note: this is an API change in core/types. We decided it's OK to make this change because LogForStorage is an implementation detail of go-ethereum and the type has zero uses outside of package core/types. Co-authored-by: Felix Lange <[email protected]>
1 parent b9d4412 commit 7522642

File tree

2 files changed

+9
-67
lines changed

2 files changed

+9
-67
lines changed

core/types/log.go

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
package types
1818

1919
import (
20-
"io"
21-
2220
"github.com/ethereum/go-ethereum/common"
2321
"github.com/ethereum/go-ethereum/common/hexutil"
24-
"github.com/ethereum/go-ethereum/rlp"
2522
)
2623

2724
//go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go
@@ -40,19 +37,19 @@ type Log struct {
4037
// Derived fields. These fields are filled in by the node
4138
// but not secured by consensus.
4239
// block in which the transaction was included
43-
BlockNumber uint64 `json:"blockNumber"`
40+
BlockNumber uint64 `json:"blockNumber" rlp:"-"`
4441
// hash of the transaction
45-
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
42+
TxHash common.Hash `json:"transactionHash" gencodec:"required" rlp:"-"`
4643
// index of the transaction in the block
47-
TxIndex uint `json:"transactionIndex"`
44+
TxIndex uint `json:"transactionIndex" rlp:"-"`
4845
// hash of the block in which the transaction was included
49-
BlockHash common.Hash `json:"blockHash"`
46+
BlockHash common.Hash `json:"blockHash" rlp:"-"`
5047
// index of the log in the block
51-
Index uint `json:"logIndex"`
48+
Index uint `json:"logIndex" rlp:"-"`
5249

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

5855
type logMarshaling struct {
@@ -61,52 +58,3 @@ type logMarshaling struct {
6158
TxIndex hexutil.Uint
6259
Index hexutil.Uint
6360
}
64-
65-
type rlpLog struct {
66-
Address common.Address
67-
Topics []common.Hash
68-
Data []byte
69-
}
70-
71-
// rlpStorageLog is the storage encoding of a log.
72-
type rlpStorageLog rlpLog
73-
74-
// EncodeRLP implements rlp.Encoder.
75-
func (l *Log) EncodeRLP(w io.Writer) error {
76-
return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data})
77-
}
78-
79-
// DecodeRLP implements rlp.Decoder.
80-
func (l *Log) DecodeRLP(s *rlp.Stream) error {
81-
var dec rlpLog
82-
err := s.Decode(&dec)
83-
if err == nil {
84-
l.Address, l.Topics, l.Data = dec.Address, dec.Topics, dec.Data
85-
}
86-
return err
87-
}
88-
89-
// LogForStorage is a wrapper around a Log that flattens and parses the entire content of
90-
// a log including non-consensus fields.
91-
type LogForStorage Log
92-
93-
// EncodeRLP implements rlp.Encoder.
94-
func (l *LogForStorage) EncodeRLP(w io.Writer) error {
95-
return rlp.Encode(w, rlpStorageLog{
96-
Address: l.Address,
97-
Topics: l.Topics,
98-
Data: l.Data,
99-
})
100-
}
101-
102-
// DecodeRLP implements rlp.Decoder.
103-
//
104-
// Note some redundant fields(e.g. block number, tx hash etc) will be assembled later.
105-
func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error {
106-
var dec rlpStorageLog
107-
if err := s.Decode(&dec); err != nil {
108-
return err
109-
}
110-
*l = LogForStorage{Address: dec.Address, Topics: dec.Topics, Data: dec.Data}
111-
return nil
112-
}

core/types/receipt.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type receiptRLP struct {
9494
type storedReceiptRLP struct {
9595
PostStateOrStatus []byte
9696
CumulativeGasUsed uint64
97-
Logs []*LogForStorage
97+
Logs []*Log
9898
}
9999

100100
// NewReceipt creates a barebone transaction receipt, copying the init fields.
@@ -217,10 +217,7 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
217217
enc := &storedReceiptRLP{
218218
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
219219
CumulativeGasUsed: r.CumulativeGasUsed,
220-
Logs: make([]*LogForStorage, len(r.Logs)),
221-
}
222-
for i, log := range r.Logs {
223-
enc.Logs[i] = (*LogForStorage)(log)
220+
Logs: r.Logs,
224221
}
225222
return rlp.Encode(w, enc)
226223
}
@@ -235,10 +232,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
235232
return err
236233
}
237234
r.CumulativeGasUsed = stored.CumulativeGasUsed
238-
r.Logs = make([]*Log, len(stored.Logs))
239-
for i, log := range stored.Logs {
240-
r.Logs[i] = (*Log)(log)
241-
}
235+
r.Logs = stored.Logs
242236
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
243237
return nil
244238
}

0 commit comments

Comments
 (0)