This commit is contained in:
@@ -2,6 +2,7 @@ package settlement
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -41,7 +42,13 @@ func (w Worker) RunOnce(ctx context.Context, limit int) error {
|
|||||||
record.Attempts++
|
record.Attempts++
|
||||||
hash, submitErr := w.Submitter.Submit(ctx, record)
|
hash, submitErr := w.Submitter.Submit(ctx, record)
|
||||||
if submitErr != nil {
|
if submitErr != nil {
|
||||||
|
var permanent ledger.PermanentSubmissionError
|
||||||
|
if errors.As(submitErr, &permanent) {
|
||||||
|
record.Status = ledger.SettlementManualReview
|
||||||
|
record.LastError = submitErr.Error()
|
||||||
|
} else {
|
||||||
record = record.Retry(now, w.MaxAttempts, submitErr)
|
record = record.Retry(now, w.MaxAttempts, submitErr)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Horizon returns success only after the transaction is accepted into
|
// Horizon returns success only after the transaction is accepted into
|
||||||
// a ledger, so a successful response is already confirmation.
|
// a ledger, so a successful response is already confirmation.
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PermanentSubmissionError struct{ Err error }
|
||||||
|
|
||||||
|
func (e PermanentSubmissionError) Error() string { return e.Err.Error() }
|
||||||
|
func (e PermanentSubmissionError) Unwrap() error { return e.Err }
|
||||||
|
|
||||||
type SettlementStatus string
|
type SettlementStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ func (s Submitter) Submit(ctx context.Context, record ledger.Settlement) (string
|
|||||||
err := fmt.Errorf("kuknos rejected transaction: status=%d code=%s", resp.StatusCode, response.Extras.ResultCodes.Transaction)
|
err := fmt.Errorf("kuknos rejected transaction: status=%d code=%s", resp.StatusCode, response.Extras.ResultCodes.Transaction)
|
||||||
span.SetStatus(codes.Error, err.Error())
|
span.SetStatus(codes.Error, err.Error())
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
|
if response.Extras.ResultCodes.Transaction == "tx_bad_seq" {
|
||||||
|
return "", ledger.PermanentSubmissionError{Err: err}
|
||||||
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return response.Hash, nil
|
return response.Hash, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user