Skip to content

Commit

Permalink
feat(taiko-client): build blob transactions when gas estimation failed (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jan 6, 2025
1 parent 5c248f6 commit 6c0ef37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 8 additions & 6 deletions packages/taiko-client/proposer/transaction_builder/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 6c0ef37

Please sign in to comment.