Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions service/app/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/onflow/flow-go-sdk"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -94,7 +95,7 @@ func sendableTransactionPoller(app *App) {

// transactionPoller is responsible for sending flow transactions and check transaction status
func sentTransactionsPoller(app *App) {
ticker := time.NewTicker(3*time.Second) // TODO (latenssi): configurable?
ticker := time.NewTicker(3 * time.Second) // TODO (latenssi): configurable?
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
for {
Expand Down Expand Up @@ -350,9 +351,22 @@ func processSendableTransaction(ctx context.Context, app *App, logger *log.Entry
if err = app.service.flowClient.SendTransaction(ctx, *tx); err != nil {
err = fmt.Errorf("error while sending transaction: %w", err)

t.State = common.TransactionStateFailed
t.Error = err.Error()

if strings.Contains(t.Error, common.TransactionRPCErrorString) {
logger.WithFields(log.Fields{
"tx_hash": t.TransactionID,
"id": t.ID,
"name": t.Name,
"distribution_id": t.DistributionID,
"retry_count": t.RetryCount,
}).Warn("retrying transaction due to rpc error")
t.State = common.TransactionStateRetry
t.RetryCount = t.RetryCount + 1
} else {
t.State = common.TransactionStateFailed
}

if err = t.Save(dbtx); err != nil {
return fmt.Errorf("error while saving transaction: %w", err)
}
Expand Down Expand Up @@ -409,9 +423,8 @@ func handleSentTransactions(ctx context.Context, app *App) error {
return nil
})


if err != nil && !errors.Is(err, gorm.ErrRecordNotFound){
return err
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions service/common/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ const (
TransactionStateFailed TransactionState = "failed"
TransactionStateComplete TransactionState = "complete"
)

const TransactionRPCErrorString string = "rpc error"