Skip to content

Commit

Permalink
test(taiko-client): add more fallback proposing tests (#18705)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jan 3, 2025
1 parent 6ee49da commit 0e8ef0d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 28 deletions.
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

0 comments on commit 0e8ef0d

Please sign in to comment.