diff --git a/bridge/docs/observability.md b/bridge/docs/observability.md index 59b41eec4..0288a8205 100644 --- a/bridge/docs/observability.md +++ b/bridge/docs/observability.md @@ -66,7 +66,8 @@ For example, if a customer is complaining that their deposit never bridged, you - `event_burn_tx_ready_received`: The bridge instance has received TFChain `BurnTransactionReady` event which means all bridge validators signed a withdraw transaction. - `event_burn_tx_expired_received`: The bridge instance has received TFChain `BurnTransactionExpired` event. - `withdraw_skipped`: a refund request skipped by the bridge instance as it has already been refunded. -- `withdraw_proposed`: a withdraw has proposed or signed by the bridge instance. +- `withdraw_proposed`: a withdraw has proposed or signed by the bridge instance. +- `withdraw_postponed`: a withdraw has postponed due to a problem in sending this transaction to the stellar network and will be retried later. - `withdraw_completed`: a withdraw has completed and received on the target stellar account. ##### Bridge vault account related @@ -787,6 +788,32 @@ the source field set contains all fields which are included in the source object +##### withdraw_postponed + +- kind: event + +- category: withdraw + + + + + + + + + + + + + + + + + + + +
withdraw_postponed Event Properties
PropertyTypeRequiredDescription
reasonstringyesThe reason behind the postponed of this transfer.
+ ##### withdraw_completed - kind: event diff --git a/bridge/tfchain_bridge/pkg/bridge/bridge.go b/bridge/tfchain_bridge/pkg/bridge/bridge.go index 85c233b6c..28f17ab25 100644 --- a/bridge/tfchain_bridge/pkg/bridge/bridge.go +++ b/bridge/tfchain_bridge/pkg/bridge/bridge.go @@ -2,6 +2,7 @@ package bridge import ( "context" + "strconv" "time" "github.com/pkg/errors" @@ -13,7 +14,8 @@ import ( ) const ( - BridgeNetwork = "stellar" + BridgeNetwork = "stellar" + MinimumBalance = 0 ) // Bridge is a high lvl structure which listens on contract events and bridge-related @@ -73,7 +75,29 @@ func NewBridge(ctx context.Context, cfg pkg.BridgeConfig) (*Bridge, string, erro return bridge, wallet.GetKeypair().Address(), nil } +func (bridge *Bridge) preCheckBalance(ctx context.Context) error { + balance, err := bridge.wallet.StatBridgeAccount() + + if err != nil { + return errors.Wrap(err, "can't retrieve the wallet balance at the moment") + } + s, err := strconv.ParseFloat(balance, 64) + if err != nil { + return errors.Wrap(err, "can't parse the wallet balance") + } + + if s < MinimumBalance { + return errors.Errorf("wallet balance insufficient: %s", balance) + } + return nil +} + func (bridge *Bridge) Start(ctx context.Context) error { + // pre-check wallet balance + if err := bridge.preCheckBalance(ctx); err != nil { + return err + } + log.Info(). Str("event_action", "bridge_started"). Str("event_kind", "event"). diff --git a/bridge/tfchain_bridge/pkg/bridge/withdraw.go b/bridge/tfchain_bridge/pkg/bridge/withdraw.go index 177faeacb..e5c43afd3 100644 --- a/bridge/tfchain_bridge/pkg/bridge/withdraw.go +++ b/bridge/tfchain_bridge/pkg/bridge/withdraw.go @@ -116,7 +116,16 @@ func (bridge *Bridge) handleWithdrawReady(ctx context.Context, withdrawReady sub // todo add memo hash err = bridge.wallet.CreatePaymentWithSignaturesAndSubmit(ctx, burnTx.Target, uint64(burnTx.Amount), fmt.Sprint(withdrawReady.ID), burnTx.Signatures, int64(burnTx.SequenceNumber)) if err != nil { - return err + // we can log and skip here as we could depend on tfcahin retry mechanism + // to notify us again about related burn tx + logger.Info(). + Str("event_action", "withdraw_postponed"). + Str("event_kind", "event"). + Str("category", "withdraw"). + Dict("metadata", zerolog.Dict(). + Str("reason", err.Error())). + Msgf("the withdraw has been postponed due to a problem in sending this transaction to the stellar network. error was %s", err.Error()) + return nil } logger.Info(). Str("event_action", "withdraw_completed"). diff --git a/bridge/tfchain_bridge/pkg/stellar/stellar.go b/bridge/tfchain_bridge/pkg/stellar/stellar.go index 6acb1e02d..4c9c1cb21 100644 --- a/bridge/tfchain_bridge/pkg/stellar/stellar.go +++ b/bridge/tfchain_bridge/pkg/stellar/stellar.go @@ -579,5 +579,5 @@ func (w *StellarWallet) StatBridgeAccount() (string, error) { return balance.Balance, nil } } - return "", nil + return "", errors.New("source account does not have trustline") }