From 6c0ef3706ebae8059b9ff554f45c2dcad00c0535 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 Jan 2025 08:41:07 +0800 Subject: [PATCH] feat(taiko-client): build blob transactions when gas estimation failed (#18712) --- .../proposer/transaction_builder/fallback.go | 14 ++++++++------ .../proposer/transaction_builder/fallback_test.go | 3 --- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/taiko-client/proposer/transaction_builder/fallback.go b/packages/taiko-client/proposer/transaction_builder/fallback.go index ff4a32adf2e..222b9d50738 100644 --- a/packages/taiko-client/proposer/transaction_builder/fallback.go +++ b/packages/taiko-client/proposer/transaction_builder/fallback.go @@ -90,7 +90,7 @@ func (b *TxBuilderWithFallback) BuildOntake( return b.calldataTransactionBuilder.BuildOntake(ctx, txListBytesArray) } // If blob is enabled, and fallback is not enabled, just build a blob transaction. - if !b.fallback { + if !b.fallback || len(txListBytesArray) > 1 { return b.blobTransactionBuilder.BuildOntake(ctx, txListBytesArray) } @@ -106,25 +106,27 @@ func (b *TxBuilderWithFallback) BuildOntake( g.Go(func() error { if txWithCalldata, err = b.calldataTransactionBuilder.BuildOntake(ctx, txListBytesArray); err != nil { - return err + return fmt.Errorf("failed to build type-2 transaction: %w", err) } if costCalldata, err = b.estimateCandidateCost(ctx, txWithCalldata); err != nil { - return err + return fmt.Errorf("failed to estimate type-2 transaction cost: %w", err) } return nil }) g.Go(func() error { if txWithBlob, err = b.blobTransactionBuilder.BuildOntake(ctx, txListBytesArray); err != nil { - return err + return fmt.Errorf("failed to build type-3 transaction: %w", err) } if costBlob, err = b.estimateCandidateCost(ctx, txWithBlob); err != nil { - return err + return fmt.Errorf("failed to estimate type-3 transaction cost: %w", err) } return nil }) if err = g.Wait(); err != nil { - return nil, err + log.Error("Failed to estimate transactions cost, will build a type-3 transaction", "error", err) + // If there is an error, just build a blob transaction. + return b.blobTransactionBuilder.BuildOntake(ctx, txListBytesArray) } metrics.ProposerEstimatedCostCalldata.Set(float64(costCalldata.Uint64())) diff --git a/packages/taiko-client/proposer/transaction_builder/fallback_test.go b/packages/taiko-client/proposer/transaction_builder/fallback_test.go index cbf1fd7ed26..c64e3544c46 100644 --- a/packages/taiko-client/proposer/transaction_builder/fallback_test.go +++ b/packages/taiko-client/proposer/transaction_builder/fallback_test.go @@ -45,7 +45,6 @@ func (s *TransactionBuilderTestSuite) TestFallback() { 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)) @@ -63,7 +62,6 @@ func (s *TransactionBuilderTestSuite) TestFallback() { 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)) @@ -81,7 +79,6 @@ func (s *TransactionBuilderTestSuite) TestFallback() { 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))