diff --git a/packages/taiko-client/internal/docker/nodes/docker-compose.yml b/packages/taiko-client/internal/docker/nodes/docker-compose.yml index ff7f73ace51..3da01faf1c4 100644 --- a/packages/taiko-client/internal/docker/nodes/docker-compose.yml +++ b/packages/taiko-client/internal/docker/nodes/docker-compose.yml @@ -13,8 +13,6 @@ services: - "32301" - --host - "0.0.0.0" - - --hardfork - - cancun l2_geth: container_name: l2_geth diff --git a/packages/taiko-client/proposer/transaction_builder/fallback.go b/packages/taiko-client/proposer/transaction_builder/fallback.go index 120017b2067..ff4a32adf2e 100644 --- a/packages/taiko-client/proposer/transaction_builder/fallback.go +++ b/packages/taiko-client/proposer/transaction_builder/fallback.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" "golang.org/x/sync/errgroup" "github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics" @@ -184,7 +185,12 @@ func (b *TxBuilderWithFallback) estimateCandidateCost( // Otherwise, we add blob fee to the cost. return new(big.Int).Add( feeWithoutBlob, - new(big.Int).Mul(new(big.Int).SetUint64(uint64(len(candidate.Blobs))), blobBaseFee), + new(big.Int).Mul( + new(big.Int).SetUint64( + uint64(len(candidate.Blobs)*params.BlobTxBlobGasPerBlob), + ), + blobBaseFee, + ), ), nil } diff --git a/packages/taiko-client/proposer/transaction_builder/fallback_test.go b/packages/taiko-client/proposer/transaction_builder/fallback_test.go index 8107875b6f6..cbf1fd7ed26 100644 --- a/packages/taiko-client/proposer/transaction_builder/fallback_test.go +++ b/packages/taiko-client/proposer/transaction_builder/fallback_test.go @@ -1,7 +1,9 @@ package builder import ( + "bytes" "context" + "math/big" "os" "time" @@ -9,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" "github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics" "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config" @@ -17,27 +20,78 @@ import ( ) func (s *TransactionBuilderTestSuite) TestBuildCalldataOnly() { - builder := s.newTestBuilderWithFallback(false, false) + builder := s.newTestBuilderWithFallback(false, false, nil) candidate, err := builder.BuildOntake(context.Background(), [][]byte{{1}, {2}}) s.Nil(err) s.Zero(len(candidate.Blobs)) } func (s *TransactionBuilderTestSuite) TestBuildCalldataWithBlobAllowed() { - builder := s.newTestBuilderWithFallback(true, false) + builder := s.newTestBuilderWithFallback(true, false, nil) candidate, err := builder.BuildOntake(context.Background(), [][]byte{{1}, {2}}) s.Nil(err) s.NotZero(len(candidate.Blobs)) } func (s *TransactionBuilderTestSuite) TestBlobAllowed() { - builder := s.newTestBuilderWithFallback(false, false) + builder := s.newTestBuilderWithFallback(false, false, nil) s.False(builder.BlobAllow()) - builder = s.newTestBuilderWithFallback(true, false) + builder = s.newTestBuilderWithFallback(true, false, nil) s.True(builder.BlobAllow()) } -func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(blobAllowed, fallback bool) *TxBuilderWithFallback { +func (s *TransactionBuilderTestSuite) TestFallback() { + // By default, blob fee should be cheaper. + builder := s.newTestBuilderWithFallback(true, true, nil) + candidate, err := builder.BuildOntake(context.Background(), [][]byte{ + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + }) + s.Nil(err) + s.NotZero(len(candidate.Blobs)) + + // Make blob base fee 1024 Gwei + builder = s.newTestBuilderWithFallback(true, true, func( + ctx context.Context, + backend txmgr.ETHBackend, + ) (*big.Int, *big.Int, *big.Int, error) { + return common.Big1, + common.Big1, + new(big.Int).SetUint64(1024 * params.GWei), + nil + }) + + candidate, err = builder.BuildOntake(context.Background(), [][]byte{ + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + }) + s.Nil(err) + s.Zero(len(candidate.Blobs)) + + // Make block base fee 1024 Gwei too + builder = s.newTestBuilderWithFallback(true, true, func( + ctx context.Context, + backend txmgr.ETHBackend, + ) (*big.Int, *big.Int, *big.Int, error) { + return new(big.Int).SetUint64(1024 * params.GWei), + new(big.Int).SetUint64(1024 * params.GWei), + new(big.Int).SetUint64(1024 * params.GWei), + nil + }) + + candidate, err = builder.BuildOntake(context.Background(), [][]byte{ + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + bytes.Repeat([]byte{1}, int(rpc.BlockMaxTxListBytes)), + }) + s.Nil(err) + s.NotZero(len(candidate.Blobs)) +} + +func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback( + blobAllowed, + fallback bool, + gasPriceEstimatorFn txmgr.GasPriceEstimatorFn, +) *TxBuilderWithFallback { l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY"))) s.Nil(err) @@ -46,27 +100,28 @@ func (s *TransactionBuilderTestSuite) newTestBuilderWithFallback(blobAllowed, fa chainConfig := config.NewChainConfig(&protocolConfigs) - txMgr, err := txmgr.NewSimpleTxManager( - "tx_builder_test", - log.Root(), - &metrics.TxMgrMetrics, - txmgr.CLIConfig{ - L1RPCURL: os.Getenv("L1_WS"), - NumConfirmations: 0, - SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount, - PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)), - FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier, - FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei, - MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei, - MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei, - ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout, - ReceiptQueryInterval: 1 * time.Second, - NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout, - TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout, - TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout, - }, - ) + cfg, err := txmgr.NewConfig(txmgr.CLIConfig{ + L1RPCURL: os.Getenv("L1_WS"), + NumConfirmations: 0, + SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount, + PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)), + FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier, + FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei, + MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei, + MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei, + ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout, + ReceiptQueryInterval: 1 * time.Second, + NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout, + TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout, + TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout, + }, log.Root()) + s.Nil(err) + + if gasPriceEstimatorFn != nil { + cfg.GasPriceEstimatorFn = gasPriceEstimatorFn + } + txMgr, err := txmgr.NewSimpleTxManagerFromConfig("tx_builder_test", log.Root(), &metrics.TxMgrMetrics, cfg) s.Nil(err) txmgrSelector := utils.NewTxMgrSelector(txMgr, nil, nil)