Skip to content

Commit 0e8ef0d

Browse files
test(taiko-client): add more fallback proposing tests (#18705)
1 parent 6ee49da commit 0e8ef0d

File tree

3 files changed

+87
-28
lines changed

3 files changed

+87
-28
lines changed

packages/taiko-client/internal/docker/nodes/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ services:
1313
- "32301"
1414
- --host
1515
- "0.0.0.0"
16-
- --hardfork
17-
- cancun
1816

1917
l2_geth:
2018
container_name: l2_geth

packages/taiko-client/proposer/transaction_builder/fallback.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ethereum/go-ethereum"
1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/log"
13+
"github.com/ethereum/go-ethereum/params"
1314
"golang.org/x/sync/errgroup"
1415

1516
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics"
@@ -184,7 +185,12 @@ func (b *TxBuilderWithFallback) estimateCandidateCost(
184185
// Otherwise, we add blob fee to the cost.
185186
return new(big.Int).Add(
186187
feeWithoutBlob,
187-
new(big.Int).Mul(new(big.Int).SetUint64(uint64(len(candidate.Blobs))), blobBaseFee),
188+
new(big.Int).Mul(
189+
new(big.Int).SetUint64(
190+
uint64(len(candidate.Blobs)*params.BlobTxBlobGasPerBlob),
191+
),
192+
blobBaseFee,
193+
),
188194
), nil
189195
}
190196

packages/taiko-client/proposer/transaction_builder/fallback_test.go

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package builder
22

33
import (
4+
"bytes"
45
"context"
6+
"math/big"
57
"os"
68
"time"
79

810
"github.com/ethereum-optimism/optimism/op-service/txmgr"
911
"github.com/ethereum/go-ethereum/common"
1012
"github.com/ethereum/go-ethereum/crypto"
1113
"github.com/ethereum/go-ethereum/log"
14+
"github.com/ethereum/go-ethereum/params"
1215

1316
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics"
1417
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
@@ -17,27 +20,78 @@ import (
1720
)
1821

1922
func (s *TransactionBuilderTestSuite) TestBuildCalldataOnly() {
20-
builder := s.newTestBuilderWithFallback(false, false)
23+
builder := s.newTestBuilderWithFallback(false, false, nil)
2124
candidate, err := builder.BuildOntake(context.Background(), [][]byte{{1}, {2}})
2225
s.Nil(err)
2326
s.Zero(len(candidate.Blobs))
2427
}
2528

2629
func (s *TransactionBuilderTestSuite) TestBuildCalldataWithBlobAllowed() {
27-
builder := s.newTestBuilderWithFallback(true, false)
30+
builder := s.newTestBuilderWithFallback(true, false, nil)
2831
candidate, err := builder.BuildOntake(context.Background(), [][]byte{{1}, {2}})
2932
s.Nil(err)
3033
s.NotZero(len(candidate.Blobs))
3134
}
3235

3336
func (s *TransactionBuilderTestSuite) TestBlobAllowed() {
34-
builder := s.newTestBuilderWithFallback(false, false)
37+
builder := s.newTestBuilderWithFallback(false, false, nil)
3538
s.False(builder.BlobAllow())
36-
builder = s.newTestBuilderWithFallback(true, false)
39+
builder = s.newTestBuilderWithFallback(true, false, nil)
3740
s.True(builder.BlobAllow())
3841
}
3942

40-
func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(blobAllowed, fallback bool) *TxBuilderWithFallback {
43+
func (s *TransactionBuilderTestSuite) TestFallback() {
44+
// By default, blob fee should be cheaper.
45+
builder := s.newTestBuilderWithFallback(true, true, nil)
46+
candidate, err := builder.BuildOntake(context.Background(), [][]byte{
47+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
48+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
49+
})
50+
s.Nil(err)
51+
s.NotZero(len(candidate.Blobs))
52+
53+
// Make blob base fee 1024 Gwei
54+
builder = s.newTestBuilderWithFallback(true, true, func(
55+
ctx context.Context,
56+
backend txmgr.ETHBackend,
57+
) (*big.Int, *big.Int, *big.Int, error) {
58+
return common.Big1,
59+
common.Big1,
60+
new(big.Int).SetUint64(1024 * params.GWei),
61+
nil
62+
})
63+
64+
candidate, err = builder.BuildOntake(context.Background(), [][]byte{
65+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
66+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
67+
})
68+
s.Nil(err)
69+
s.Zero(len(candidate.Blobs))
70+
71+
// Make block base fee 1024 Gwei too
72+
builder = s.newTestBuilderWithFallback(true, true, func(
73+
ctx context.Context,
74+
backend txmgr.ETHBackend,
75+
) (*big.Int, *big.Int, *big.Int, error) {
76+
return new(big.Int).SetUint64(1024 * params.GWei),
77+
new(big.Int).SetUint64(1024 * params.GWei),
78+
new(big.Int).SetUint64(1024 * params.GWei),
79+
nil
80+
})
81+
82+
candidate, err = builder.BuildOntake(context.Background(), [][]byte{
83+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
84+
bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)),
85+
})
86+
s.Nil(err)
87+
s.NotZero(len(candidate.Blobs))
88+
}
89+
90+
func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(
91+
blobAllowed,
92+
fallback bool,
93+
gasPriceEstimatorFn txmgr.GasPriceEstimatorFn,
94+
) *TxBuilderWithFallback {
4195
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
4296
s.Nil(err)
4397

@@ -46,27 +100,28 @@ func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(blobAllowed, fa
46100

47101
chainConfig := config.NewChainConfig(&protocolConfigs)
48102

49-
txMgr, err := txmgr.NewSimpleTxManager(
50-
"tx_builder_test",
51-
log.Root(),
52-
&metrics.TxMgrMetrics,
53-
txmgr.CLIConfig{
54-
L1RPCURL: os.Getenv("L1_WS"),
55-
NumConfirmations: 0,
56-
SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount,
57-
PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)),
58-
FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier,
59-
FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei,
60-
MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei,
61-
MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei,
62-
ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout,
63-
ReceiptQueryInterval: 1 * time.Second,
64-
NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout,
65-
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
66-
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
67-
},
68-
)
103+
cfg, err := txmgr.NewConfig(txmgr.CLIConfig{
104+
L1RPCURL: os.Getenv("L1_WS"),
105+
NumConfirmations: 0,
106+
SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount,
107+
PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)),
108+
FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier,
109+
FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei,
110+
MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei,
111+
MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei,
112+
ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout,
113+
ReceiptQueryInterval: 1 * time.Second,
114+
NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout,
115+
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
116+
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
117+
}, log.Root())
118+
s.Nil(err)
119+
120+
if gasPriceEstimatorFn != nil {
121+
cfg.GasPriceEstimatorFn = gasPriceEstimatorFn
122+
}
69123

124+
txMgr, err := txmgr.NewSimpleTxManagerFromConfig("tx_builder_test", log.Root(), &metrics.TxMgrMetrics, cfg)
70125
s.Nil(err)
71126

72127
txmgrSelector := utils.NewTxMgrSelector(txMgr, nil, nil)

0 commit comments

Comments
 (0)