1
1
package builder
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
6
+ "math/big"
5
7
"os"
6
8
"time"
7
9
8
10
"github.com/ethereum-optimism/optimism/op-service/txmgr"
9
11
"github.com/ethereum/go-ethereum/common"
10
12
"github.com/ethereum/go-ethereum/crypto"
11
13
"github.com/ethereum/go-ethereum/log"
14
+ "github.com/ethereum/go-ethereum/params"
12
15
13
16
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics"
14
17
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
@@ -17,27 +20,78 @@ import (
17
20
)
18
21
19
22
func (s * TransactionBuilderTestSuite ) TestBuildCalldataOnly () {
20
- builder := s .newTestBuilderWithFallback (false , false )
23
+ builder := s .newTestBuilderWithFallback (false , false , nil )
21
24
candidate , err := builder .BuildOntake (context .Background (), [][]byte {{1 }, {2 }})
22
25
s .Nil (err )
23
26
s .Zero (len (candidate .Blobs ))
24
27
}
25
28
26
29
func (s * TransactionBuilderTestSuite ) TestBuildCalldataWithBlobAllowed () {
27
- builder := s .newTestBuilderWithFallback (true , false )
30
+ builder := s .newTestBuilderWithFallback (true , false , nil )
28
31
candidate , err := builder .BuildOntake (context .Background (), [][]byte {{1 }, {2 }})
29
32
s .Nil (err )
30
33
s .NotZero (len (candidate .Blobs ))
31
34
}
32
35
33
36
func (s * TransactionBuilderTestSuite ) TestBlobAllowed () {
34
- builder := s .newTestBuilderWithFallback (false , false )
37
+ builder := s .newTestBuilderWithFallback (false , false , nil )
35
38
s .False (builder .BlobAllow ())
36
- builder = s .newTestBuilderWithFallback (true , false )
39
+ builder = s .newTestBuilderWithFallback (true , false , nil )
37
40
s .True (builder .BlobAllow ())
38
41
}
39
42
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 {
41
95
l1ProposerPrivKey , err := crypto .ToECDSA (common .FromHex (os .Getenv ("L1_PROPOSER_PRIVATE_KEY" )))
42
96
s .Nil (err )
43
97
@@ -46,27 +100,28 @@ func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(blobAllowed, fa
46
100
47
101
chainConfig := config .NewChainConfig (& protocolConfigs )
48
102
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
+ }
69
123
124
+ txMgr , err := txmgr .NewSimpleTxManagerFromConfig ("tx_builder_test" , log .Root (), & metrics .TxMgrMetrics , cfg )
70
125
s .Nil (err )
71
126
72
127
txmgrSelector := utils .NewTxMgrSelector (txMgr , nil , nil )
0 commit comments