Skip to content

Commit 51c85c0

Browse files
authored
Revert "core/types: un-ssz blob txs, add json marshalling and tweaks (ethereum#27256)"
This reverts commit cd548dc.
1 parent 0278d53 commit 51c85c0

File tree

5 files changed

+62
-138
lines changed

5 files changed

+62
-138
lines changed

core/types/gen_access_tuple.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/transaction.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
198198
return &inner, err
199199
case BlobTxType:
200200
var inner BlobTx
201-
err := rlp.DecodeBytes(b[1:], &inner)
201+
err := rlp.DecodeBytes(b[1:], &inner) // TODO(karalabe): This needs to be ssz
202202
return &inner, err
203203
default:
204204
return nil, ErrTxTypeNotSupported
@@ -417,7 +417,11 @@ func (tx *Transaction) Size() uint64 {
417417
return size.(uint64)
418418
}
419419
c := writeCounter(0)
420-
rlp.Encode(&c, &tx.inner)
420+
if tx.Type() == BlobTxType {
421+
rlp.Encode(&c, &tx.inner) // TODO(karalabe): Replace with SSZ encoding
422+
} else {
423+
rlp.Encode(&c, &tx.inner)
424+
}
421425

422426
size := uint64(c)
423427
if tx.Type() != LegacyTxType {

core/types/transaction_marshalling.go

Lines changed: 49 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/common/hexutil"
26-
"github.com/holiman/uint256"
2726
)
2827

2928
// txJSON is the JSON representation of transactions.
3029
type txJSON struct {
3130
Type hexutil.Uint64 `json:"type"`
3231

33-
ChainID *hexutil.Big `json:"chainId,omitempty"`
32+
// Common transaction fields:
3433
Nonce *hexutil.Uint64 `json:"nonce"`
35-
To *common.Address `json:"to"`
36-
Gas *hexutil.Uint64 `json:"gas"`
3734
GasPrice *hexutil.Big `json:"gasPrice"`
3835
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
3936
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
40-
MaxFeePerDataGas *hexutil.Big `json:"maxFeePerDataGas,omitempty"`
37+
Gas *hexutil.Uint64 `json:"gas"`
4138
Value *hexutil.Big `json:"value"`
42-
Input *hexutil.Bytes `json:"input"`
43-
AccessList *AccessList `json:"accessList,omitempty"`
44-
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
39+
Data *hexutil.Bytes `json:"input"`
4540
V *hexutil.Big `json:"v"`
4641
R *hexutil.Big `json:"r"`
4742
S *hexutil.Big `json:"s"`
43+
To *common.Address `json:"to"`
44+
45+
// Access list transaction fields:
46+
ChainID *hexutil.Big `json:"chainId,omitempty"`
47+
AccessList *AccessList `json:"accessList,omitempty"`
4848

4949
// Only used for encoding:
5050
Hash common.Hash `json:"hash"`
@@ -61,57 +61,39 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
6161
switch itx := tx.inner.(type) {
6262
case *LegacyTx:
6363
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
64-
enc.To = tx.To()
6564
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
6665
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
6766
enc.Value = (*hexutil.Big)(itx.Value)
68-
enc.Input = (*hexutil.Bytes)(&itx.Data)
67+
enc.Data = (*hexutil.Bytes)(&itx.Data)
68+
enc.To = tx.To()
6969
enc.V = (*hexutil.Big)(itx.V)
7070
enc.R = (*hexutil.Big)(itx.R)
7171
enc.S = (*hexutil.Big)(itx.S)
72-
7372
case *AccessListTx:
7473
enc.ChainID = (*hexutil.Big)(itx.ChainID)
74+
enc.AccessList = &itx.AccessList
7575
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
76-
enc.To = tx.To()
7776
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
7877
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
7978
enc.Value = (*hexutil.Big)(itx.Value)
80-
enc.Input = (*hexutil.Bytes)(&itx.Data)
81-
enc.AccessList = &itx.AccessList
79+
enc.Data = (*hexutil.Bytes)(&itx.Data)
80+
enc.To = tx.To()
8281
enc.V = (*hexutil.Big)(itx.V)
8382
enc.R = (*hexutil.Big)(itx.R)
8483
enc.S = (*hexutil.Big)(itx.S)
85-
8684
case *DynamicFeeTx:
8785
enc.ChainID = (*hexutil.Big)(itx.ChainID)
86+
enc.AccessList = &itx.AccessList
8887
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
89-
enc.To = tx.To()
9088
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
9189
enc.MaxFeePerGas = (*hexutil.Big)(itx.GasFeeCap)
9290
enc.MaxPriorityFeePerGas = (*hexutil.Big)(itx.GasTipCap)
9391
enc.Value = (*hexutil.Big)(itx.Value)
94-
enc.Input = (*hexutil.Bytes)(&itx.Data)
95-
enc.AccessList = &itx.AccessList
92+
enc.Data = (*hexutil.Bytes)(&itx.Data)
93+
enc.To = tx.To()
9694
enc.V = (*hexutil.Big)(itx.V)
9795
enc.R = (*hexutil.Big)(itx.R)
9896
enc.S = (*hexutil.Big)(itx.S)
99-
100-
case *BlobTx:
101-
enc.ChainID = (*hexutil.Big)(itx.ChainID.ToBig())
102-
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
103-
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
104-
enc.MaxFeePerGas = (*hexutil.Big)(itx.GasFeeCap.ToBig())
105-
enc.MaxPriorityFeePerGas = (*hexutil.Big)(itx.GasTipCap.ToBig())
106-
enc.MaxFeePerDataGas = (*hexutil.Big)(itx.BlobFeeCap.ToBig())
107-
enc.Value = (*hexutil.Big)(itx.Value.ToBig())
108-
enc.Input = (*hexutil.Bytes)(&itx.Data)
109-
enc.AccessList = &itx.AccessList
110-
enc.BlobVersionedHashes = itx.BlobHashes
111-
enc.To = tx.To()
112-
enc.V = (*hexutil.Big)(itx.V.ToBig())
113-
enc.R = (*hexutil.Big)(itx.R.ToBig())
114-
enc.S = (*hexutil.Big)(itx.S.ToBig())
11597
}
11698
return json.Marshal(&enc)
11799
}
@@ -129,29 +111,29 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
129111
case LegacyTxType:
130112
var itx LegacyTx
131113
inner = &itx
114+
if dec.To != nil {
115+
itx.To = dec.To
116+
}
132117
if dec.Nonce == nil {
133118
return errors.New("missing required field 'nonce' in transaction")
134119
}
135120
itx.Nonce = uint64(*dec.Nonce)
136-
if dec.To != nil {
137-
itx.To = dec.To
121+
if dec.GasPrice == nil {
122+
return errors.New("missing required field 'gasPrice' in transaction")
138123
}
124+
itx.GasPrice = (*big.Int)(dec.GasPrice)
139125
if dec.Gas == nil {
140126
return errors.New("missing required field 'gas' in transaction")
141127
}
142128
itx.Gas = uint64(*dec.Gas)
143-
if dec.GasPrice == nil {
144-
return errors.New("missing required field 'gasPrice' in transaction")
145-
}
146-
itx.GasPrice = (*big.Int)(dec.GasPrice)
147129
if dec.Value == nil {
148130
return errors.New("missing required field 'value' in transaction")
149131
}
150132
itx.Value = (*big.Int)(dec.Value)
151-
if dec.Input == nil {
133+
if dec.Data == nil {
152134
return errors.New("missing required field 'input' in transaction")
153135
}
154-
itx.Data = *dec.Input
136+
itx.Data = *dec.Data
155137
if dec.V == nil {
156138
return errors.New("missing required field 'v' in transaction")
157139
}
@@ -174,39 +156,40 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
174156
case AccessListTxType:
175157
var itx AccessListTx
176158
inner = &itx
159+
// Access list is optional for now.
160+
if dec.AccessList != nil {
161+
itx.AccessList = *dec.AccessList
162+
}
177163
if dec.ChainID == nil {
178164
return errors.New("missing required field 'chainId' in transaction")
179165
}
180166
itx.ChainID = (*big.Int)(dec.ChainID)
167+
if dec.To != nil {
168+
itx.To = dec.To
169+
}
181170
if dec.Nonce == nil {
182171
return errors.New("missing required field 'nonce' in transaction")
183172
}
184173
itx.Nonce = uint64(*dec.Nonce)
185-
if dec.To != nil {
186-
itx.To = dec.To
174+
if dec.GasPrice == nil {
175+
return errors.New("missing required field 'gasPrice' in transaction")
187176
}
177+
itx.GasPrice = (*big.Int)(dec.GasPrice)
188178
if dec.Gas == nil {
189179
return errors.New("missing required field 'gas' in transaction")
190180
}
191181
itx.Gas = uint64(*dec.Gas)
192-
if dec.GasPrice == nil {
193-
return errors.New("missing required field 'gasPrice' in transaction")
194-
}
195-
itx.GasPrice = (*big.Int)(dec.GasPrice)
196182
if dec.Value == nil {
197183
return errors.New("missing required field 'value' in transaction")
198184
}
199185
itx.Value = (*big.Int)(dec.Value)
200-
if dec.Input == nil {
186+
if dec.Data == nil {
201187
return errors.New("missing required field 'input' in transaction")
202188
}
203-
itx.Data = *dec.Input
189+
itx.Data = *dec.Data
204190
if dec.V == nil {
205191
return errors.New("missing required field 'v' in transaction")
206192
}
207-
if dec.AccessList != nil {
208-
itx.AccessList = *dec.AccessList
209-
}
210193
itx.V = (*big.Int)(dec.V)
211194
if dec.R == nil {
212195
return errors.New("missing required field 'r' in transaction")
@@ -226,21 +209,21 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
226209
case DynamicFeeTxType:
227210
var itx DynamicFeeTx
228211
inner = &itx
212+
// Access list is optional for now.
213+
if dec.AccessList != nil {
214+
itx.AccessList = *dec.AccessList
215+
}
229216
if dec.ChainID == nil {
230217
return errors.New("missing required field 'chainId' in transaction")
231218
}
232219
itx.ChainID = (*big.Int)(dec.ChainID)
233-
if dec.Nonce == nil {
234-
return errors.New("missing required field 'nonce' in transaction")
235-
}
236-
itx.Nonce = uint64(*dec.Nonce)
237220
if dec.To != nil {
238221
itx.To = dec.To
239222
}
240-
if dec.Gas == nil {
241-
return errors.New("missing required field 'gas' for txdata")
223+
if dec.Nonce == nil {
224+
return errors.New("missing required field 'nonce' in transaction")
242225
}
243-
itx.Gas = uint64(*dec.Gas)
226+
itx.Nonce = uint64(*dec.Nonce)
244227
if dec.MaxPriorityFeePerGas == nil {
245228
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
246229
}
@@ -249,20 +232,21 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
249232
return errors.New("missing required field 'maxFeePerGas' for txdata")
250233
}
251234
itx.GasFeeCap = (*big.Int)(dec.MaxFeePerGas)
235+
if dec.Gas == nil {
236+
return errors.New("missing required field 'gas' for txdata")
237+
}
238+
itx.Gas = uint64(*dec.Gas)
252239
if dec.Value == nil {
253240
return errors.New("missing required field 'value' in transaction")
254241
}
255242
itx.Value = (*big.Int)(dec.Value)
256-
if dec.Input == nil {
243+
if dec.Data == nil {
257244
return errors.New("missing required field 'input' in transaction")
258245
}
259-
itx.Data = *dec.Input
246+
itx.Data = *dec.Data
260247
if dec.V == nil {
261248
return errors.New("missing required field 'v' in transaction")
262249
}
263-
if dec.AccessList != nil {
264-
itx.AccessList = *dec.AccessList
265-
}
266250
itx.V = (*big.Int)(dec.V)
267251
if dec.R == nil {
268252
return errors.New("missing required field 'r' in transaction")
@@ -279,70 +263,6 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
279263
}
280264
}
281265

282-
case BlobTxType:
283-
var itx BlobTx
284-
inner = &itx
285-
if dec.ChainID == nil {
286-
return errors.New("missing required field 'chainId' in transaction")
287-
}
288-
itx.ChainID = uint256.MustFromBig((*big.Int)(dec.ChainID))
289-
if dec.Nonce == nil {
290-
return errors.New("missing required field 'nonce' in transaction")
291-
}
292-
itx.Nonce = uint64(*dec.Nonce)
293-
if dec.To != nil {
294-
itx.To = dec.To
295-
}
296-
if dec.Gas == nil {
297-
return errors.New("missing required field 'gas' for txdata")
298-
}
299-
itx.Gas = uint64(*dec.Gas)
300-
if dec.MaxPriorityFeePerGas == nil {
301-
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
302-
}
303-
itx.GasTipCap = uint256.MustFromBig((*big.Int)(dec.MaxPriorityFeePerGas))
304-
if dec.MaxFeePerGas == nil {
305-
return errors.New("missing required field 'maxFeePerGas' for txdata")
306-
}
307-
itx.GasFeeCap = uint256.MustFromBig((*big.Int)(dec.MaxFeePerGas))
308-
if dec.MaxFeePerDataGas == nil {
309-
return errors.New("missing required field 'maxFeePerDataGas' for txdata")
310-
}
311-
itx.BlobFeeCap = uint256.MustFromBig((*big.Int)(dec.MaxFeePerDataGas))
312-
if dec.Value == nil {
313-
return errors.New("missing required field 'value' in transaction")
314-
}
315-
itx.Value = uint256.MustFromBig((*big.Int)(dec.Value))
316-
if dec.Input == nil {
317-
return errors.New("missing required field 'input' in transaction")
318-
}
319-
itx.Data = *dec.Input
320-
if dec.V == nil {
321-
return errors.New("missing required field 'v' in transaction")
322-
}
323-
if dec.AccessList != nil {
324-
itx.AccessList = *dec.AccessList
325-
}
326-
if dec.BlobVersionedHashes == nil {
327-
return errors.New("missing required field 'blobVersionedHashes' in transaction")
328-
}
329-
itx.BlobHashes = dec.BlobVersionedHashes
330-
itx.V = uint256.MustFromBig((*big.Int)(dec.V))
331-
if dec.R == nil {
332-
return errors.New("missing required field 'r' in transaction")
333-
}
334-
itx.R = uint256.MustFromBig((*big.Int)(dec.R))
335-
if dec.S == nil {
336-
return errors.New("missing required field 's' in transaction")
337-
}
338-
itx.S = uint256.MustFromBig((*big.Int)(dec.S))
339-
withSignature := itx.V.Sign() != 0 || itx.R.Sign() != 0 || itx.S.Sign() != 0
340-
if withSignature {
341-
if err := sanityCheckSignature(itx.V.ToBig(), itx.R.ToBig(), itx.S.ToBig(), false); err != nil {
342-
return err
343-
}
344-
}
345-
346266
default:
347267
return ErrTxTypeNotSupported
348268
}

core/types/tx_access_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type AccessList []AccessTuple
2929

3030
// AccessTuple is the element type of an access list.
3131
type AccessTuple struct {
32-
Address common.Address `json:"address" gencodec:"required"`
33-
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
32+
Address common.Address `json:"address" gencodec:"required"`
33+
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
3434
}
3535

3636
// StorageKeys returns the total number of storage keys in the access list.

core/types/tx_blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BlobTx struct {
3131
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
3232
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
3333
Gas uint64
34-
To *common.Address `rlp:"nil"` // nil means contract creation
34+
To *common.Address // `rlp:"nil"` // nil means contract creation
3535
Value *uint256.Int
3636
Data []byte
3737
AccessList AccessList

0 commit comments

Comments
 (0)