Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(taiko-client): add more fallback proposing tests #18705

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ services:
- "32301"
- --host
- "0.0.0.0"
- --hardfork
- cancun

l2_geth:
container_name: l2_geth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
105 changes: 80 additions & 25 deletions packages/taiko-client/proposer/transaction_builder/fallback_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package builder

import (
"bytes"
"context"
"math/big"
"os"
"time"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
"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"
Expand All @@ -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)

Expand All @@ -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)
Expand Down
Loading