@@ -29,7 +29,6 @@ import (
29
29
"github.com/ethereum/go-ethereum/common/math"
30
30
"github.com/ethereum/go-ethereum/crypto"
31
31
"github.com/ethereum/go-ethereum/log"
32
- "github.com/ethereum/go-ethereum/params"
33
32
"github.com/ethereum/go-ethereum/rlp"
34
33
)
35
34
@@ -59,7 +58,7 @@ type Transaction struct {
59
58
size atomic.Value
60
59
from atomic.Value
61
60
62
- // cache how much gas the tx takes on L1 for its share of rollup data
61
+ // cache of RollupGasData details to compute the gas the tx takes on L1 for its share of rollup data
63
62
rollupGas atomic.Value
64
63
}
65
64
@@ -347,31 +346,27 @@ func (tx *Transaction) Cost() *big.Int {
347
346
}
348
347
349
348
// RollupDataGas is the amount of gas it takes to confirm the tx on L1 as a rollup
350
- func (tx * Transaction ) RollupDataGas () uint64 {
349
+ func (tx * Transaction ) RollupDataGas () RollupGasData {
351
350
if tx .Type () == DepositTxType {
352
- return 0
351
+ return RollupGasData {}
353
352
}
354
353
if v := tx .rollupGas .Load (); v != nil {
355
- return v .(uint64 )
354
+ return v .(RollupGasData )
356
355
}
357
356
data , err := tx .MarshalBinary ()
358
357
if err != nil { // Silent error, invalid txs will not be marshalled/unmarshalled for batch submission anyway.
359
358
log .Error ("failed to encode tx for L1 cost computation" , "err" , err )
360
359
}
361
- var zeroes uint64
362
- var ones uint64
360
+ var out RollupGasData
363
361
for _ , byt := range data {
364
362
if byt == 0 {
365
- zeroes ++
363
+ out . Zeroes ++
366
364
} else {
367
- ones ++
365
+ out . Ones ++
368
366
}
369
367
}
370
- zeroesGas := zeroes * params .TxDataZeroGas
371
- onesGas := (ones + 68 ) * params .TxDataNonZeroGasEIP2028
372
- total := zeroesGas + onesGas
373
- tx .rollupGas .Store (total )
374
- return total
368
+ tx .rollupGas .Store (out )
369
+ return out
375
370
}
376
371
377
372
// RawSignatureValues returns the V, R, S signature values of the transaction.
@@ -685,7 +680,7 @@ type Message struct {
685
680
isSystemTx bool
686
681
isDepositTx bool
687
682
mint * big.Int
688
- l1CostGas uint64
683
+ l1CostGas RollupGasData
689
684
}
690
685
691
686
func NewMessage (from common.Address , to * common.Address , nonce uint64 , amount * big.Int , gasLimit uint64 , gasPrice , gasFeeCap , gasTipCap * big.Int , data []byte , accessList AccessList , isFake bool ) Message {
@@ -705,7 +700,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
705
700
isSystemTx : false ,
706
701
isDepositTx : false ,
707
702
mint : nil ,
708
- l1CostGas : 0 ,
703
+ l1CostGas : RollupGasData {} ,
709
704
}
710
705
}
711
706
@@ -748,10 +743,11 @@ func (m Message) Nonce() uint64 { return m.nonce }
748
743
func (m Message ) Data () []byte { return m .data }
749
744
func (m Message ) AccessList () AccessList { return m .accessList }
750
745
func (m Message ) IsFake () bool { return m .isFake }
751
- func (m Message ) IsSystemTx () bool { return m .isSystemTx }
752
- func (m Message ) IsDepositTx () bool { return m .isDepositTx }
753
- func (m Message ) Mint () * big.Int { return m .mint }
754
- func (m Message ) RollupDataGas () uint64 { return m .l1CostGas }
746
+
747
+ func (m Message ) IsSystemTx () bool { return m .isSystemTx }
748
+ func (m Message ) IsDepositTx () bool { return m .isDepositTx }
749
+ func (m Message ) Mint () * big.Int { return m .mint }
750
+ func (m Message ) RollupDataGas () RollupGasData { return m .l1CostGas }
755
751
756
752
// copyAddressPtr copies an address.
757
753
func copyAddressPtr (a * common.Address ) * common.Address {
0 commit comments