Skip to content

Commit

Permalink
fix: exiting tx receipt wait when context times out
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosNicolau committed Oct 18, 2024
1 parent 61a64df commit 6873cbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 4 additions & 9 deletions core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/signer"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -120,7 +119,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
return nil, err
}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*10)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*36)
defer cancel()
receipt, err := utils.WaitForTransactionReceipt(w.Client, ctx, tx.Hash())

Expand All @@ -133,14 +132,10 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
}
}

// transaction not included in block, try again
if err == ethereum.NotFound {
w.logger.Infof("Transaction not included in block will try again bumping the fee")
continue
} else if err == context.DeadlineExceeded {
// this means we have reached the timeout (after three blocks it hasn't been included)
// so we try again by bumping the fee to make sure its included
if err != nil {
continue
} else {
return receipt, err
}

}
Expand Down
4 changes: 4 additions & 0 deletions core/utils/eth_client_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const sleepTime = 5 * time.Second
func WaitForTransactionReceipt(client eth.InstrumentedClient, ctx context.Context, txHash gethcommon.Hash) (*types.Receipt, error) {
for i := 0; i < maxRetries; i++ {
receipt, err := client.TransactionReceipt(ctx, txHash)
// if context has timed out, return
if ctx.Err() != nil {
return nil, ctx.Err()
}
if err != nil {
time.Sleep(sleepTime)
} else {
Expand Down

0 comments on commit 6873cbe

Please sign in to comment.