Skip to content

Commit

Permalink
add tx deleting in case of simulation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Dec 5, 2023
1 parent ef6e411 commit 7c3c800
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/services/broadcaster/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package broadcaster
import (
"context"
"fmt"
"gitlab.com/distributed_lab/logan/v3"
"time"

"gitlab.com/distributed_lab/logan/v3"

sdkclient "github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -81,7 +82,11 @@ func (t *broadcaster) runOnceIndexing(ctx context.Context) error {

gasUsed, err := t.simulateTx(ctx, tx)
if err != nil {
return errors.Wrap(err, "failed to simulate tx")
log.WithError(err).Error("Failed to simulate tx")

if err = t.deleteTx(ctx, log, &txRaw); err != nil {
return err
}
}

gasLimit := ApproximateGasLimit(gasUsed)
Expand All @@ -94,13 +99,11 @@ func (t *broadcaster) runOnceIndexing(ctx context.Context) error {
return errors.Wrap(err, "failed to generate tx after simulation")
}

err = t.broadcastTx(ctx, tx)
if err != nil {
if err = t.broadcastTx(ctx, tx); err != nil {
log.WithError(err).Error("Failed to broadcast tx")
}

err = t.deleteTx(ctx, log, &txRaw)
if err != nil {
if err = t.deleteTx(ctx, log, &txRaw); err != nil {
return err
}
}
Expand Down

0 comments on commit 7c3c800

Please sign in to comment.