Compare commits

...

15 Commits

Author SHA1 Message Date
colinlyguo
7e3cb9b0f4 chore: auto version bump [bot] 2023-08-22 07:22:14 +00:00
colin
6588c2e1c1 Merge branch 'develop' into fix-rollup-relayer-estimate-l1-commit-calldata-size 2023-08-22 15:21:48 +08:00
colinlyguo
8c2e701d60 address comments and tweak logs 2023-08-22 15:17:10 +08:00
colinlyguo
5cae76c064 add convertTxDataToRLPEncoding to reuse logic 2023-08-22 15:11:28 +08:00
colin
2d52abd97c Merge branch 'develop' into fix-rollup-relayer-estimate-l1-commit-calldata-size 2023-08-22 13:17:51 +08:00
colin
43ed48df25 Merge branch 'develop' into fix-rollup-relayer-estimate-l1-commit-calldata-size 2023-08-22 11:48:14 +08:00
colinlyguo
fed5ba309e add w.txPayloadLengthCache nil check 2023-08-22 11:46:28 +08:00
colinlyguo
9a2471a7cf chore: auto version bump [bot] 2023-08-22 03:29:24 +00:00
colinlyguo
9755019d5c use tx payload length to calculate calldata length 2023-08-22 11:28:47 +08:00
colinlyguo
748d98b460 tweak over-estimate constant length of LegacyTx 2023-08-22 10:42:15 +08:00
colinlyguo
e472a080ce trigger ci 2023-08-22 10:28:34 +08:00
Thegaram
71171bfd41 chore: auto version bump [bot] 2023-08-22 01:30:22 +00:00
Péter Garamvölgyi
6f8125058e Merge branch 'develop' into fix-rollup-relayer-estimate-l1-commit-calldata-size 2023-08-22 03:30:00 +02:00
colinlyguo
331ab673de chore: auto version bump [bot] 2023-08-21 16:30:41 +00:00
colinlyguo
d353128fef fix-rollup-relayer-estimate-l1-commit-calldata-size 2023-08-22 00:27:44 +08:00
3 changed files with 55 additions and 37 deletions

View File

@@ -3,11 +3,13 @@ package types
import (
"encoding/binary"
"errors"
"fmt"
"math"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/log"
)
// CalldataNonZeroByteGas is the gas consumption per non zero byte in calldata.
@@ -22,9 +24,10 @@ func GetKeccak256Gas(size uint64) uint64 {
type WrappedBlock struct {
Header *types.Header `json:"header"`
// Transactions is only used for recover types.Transactions, the from of types.TransactionData field is missing.
Transactions []*types.TransactionData `json:"transactions"`
WithdrawRoot common.Hash `json:"withdraw_trie_root,omitempty"`
RowConsumption *types.RowConsumption `json:"row_consumption"`
Transactions []*types.TransactionData `json:"transactions"`
WithdrawRoot common.Hash `json:"withdraw_trie_root,omitempty"`
RowConsumption *types.RowConsumption `json:"row_consumption"`
txPayloadLengthCache map[string]uint64
}
// NumL1Messages returns the number of L1 messages in this block.
@@ -95,7 +98,7 @@ func (w *WrappedBlock) EstimateL1CommitCalldataSize() uint64 {
if txData.Type == types.L1MessageTxType {
continue
}
size += uint64(len(txData.Data))
size += w.getTxPayloadLength(txData)
}
return size
}
@@ -110,20 +113,7 @@ func (w *WrappedBlock) EstimateL1CommitGas() uint64 {
continue
}
data, _ := hexutil.Decode(txData.Data)
tx := types.NewTx(&types.LegacyTx{
Nonce: txData.Nonce,
To: txData.To,
Value: txData.Value.ToInt(),
Gas: txData.Gas,
GasPrice: txData.GasPrice.ToInt(),
Data: data,
V: txData.V.ToInt(),
R: txData.R.ToInt(),
S: txData.S.ToInt(),
})
rlpTxData, _ := tx.MarshalBinary()
txPayloadLength := uint64(len(rlpTxData))
txPayloadLength := w.getTxPayloadLength(txData)
total += CalldataNonZeroByteGas * txPayloadLength // an over-estimate: treat each byte as non-zero
total += CalldataNonZeroByteGas * 4 // size of a uint32 field
total += GetKeccak256Gas(txPayloadLength) // l2 tx hash
@@ -149,3 +139,48 @@ func (w *WrappedBlock) L2TxsNum() uint64 {
}
return count
}
func (w *WrappedBlock) getTxPayloadLength(txData *types.TransactionData) uint64 {
if w.txPayloadLengthCache == nil {
w.txPayloadLengthCache = make(map[string]uint64)
}
if length, exists := w.txPayloadLengthCache[txData.TxHash]; exists {
return length
}
rlpTxData, err := convertTxDataToRLPEncoding(txData)
if err != nil {
log.Crit("convertTxDataToRLPEncoding failed, which should not happen", "hash", txData.TxHash, "err", err)
return 0
}
txPayloadLength := uint64(len(rlpTxData))
w.txPayloadLengthCache[txData.TxHash] = txPayloadLength
return txPayloadLength
}
func convertTxDataToRLPEncoding(txData *types.TransactionData) ([]byte, error) {
data, err := hexutil.Decode(txData.Data)
if err != nil {
return nil, fmt.Errorf("failed to decode txData.Data: %s, err: %w", txData.Data, err)
}
tx := types.NewTx(&types.LegacyTx{
Nonce: txData.Nonce,
To: txData.To,
Value: txData.Value.ToInt(),
Gas: txData.Gas,
GasPrice: txData.GasPrice.ToInt(),
Data: data,
V: txData.V.ToInt(),
R: txData.R.ToInt(),
S: txData.S.ToInt(),
})
rlpTxData, err := tx.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("failed to marshal binary of the tx: %+v, err: %w", tx, err)
}
return rlpTxData, nil
}

View File

@@ -8,7 +8,6 @@ import (
"strings"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/crypto"
)
@@ -65,23 +64,7 @@ func (c *Chunk) Encode(totalL1MessagePoppedBefore uint64) ([]byte, error) {
if txData.Type == types.L1MessageTxType {
continue
}
data, err := hexutil.Decode(txData.Data)
if err != nil {
return nil, err
}
// right now we only support legacy tx
tx := types.NewTx(&types.LegacyTx{
Nonce: txData.Nonce,
To: txData.To,
Value: txData.Value.ToInt(),
Gas: txData.Gas,
GasPrice: txData.GasPrice.ToInt(),
Data: data,
V: txData.V.ToInt(),
R: txData.R.ToInt(),
S: txData.S.ToInt(),
})
rlpTxData, err := tx.MarshalBinary()
rlpTxData, err := convertTxDataToRLPEncoding(txData)
if err != nil {
return nil, err
}

View File

@@ -6,7 +6,7 @@ import (
"strings"
)
var tag = "v4.1.88"
var tag = "v4.1.89"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {