From 755d5dc68eef9d024bcbb8996bed7b6af3d2a092 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 12 Jan 2024 11:35:42 +0100 Subject: [PATCH] loopd: new loopin state for incorrect amount sweeps --- loopd/swapclient_server.go | 3 +++ loopdb/swapstate.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/loopd/swapclient_server.go b/loopd/swapclient_server.go index a8fe10f..ce3d64a 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -306,6 +306,9 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) ( case loopdb.StateFailInsufficientConfirmedBalance: failureReason = clientrpc.FailureReason_FAILURE_REASON_INSUFFICIENT_CONFIRMED_BALANCE + case loopdb.StateFailIncorrectHtlcAmtSwept: + failureReason = clientrpc.FailureReason_FAILURE_REASON_INCORRECT_HTLC_AMT_SWEPT + default: return nil, fmt.Errorf("unknown swap state: %v", loopSwap.State) } diff --git a/loopdb/swapstate.go b/loopdb/swapstate.go index f18ca29..fe029f2 100644 --- a/loopdb/swapstate.go +++ b/loopdb/swapstate.go @@ -72,6 +72,11 @@ const ( // StateFailInsufficientConfirmedBalance indicates that the swap wasn't // published due to insufficient confirmed balance. StateFailInsufficientConfirmedBalance SwapState = 12 + + // StateFailIncorrectHtlcAmtSwept indicates that the amount of an + // externally published loop in htlc that didn't match the swap amount + // has been swept back to the user after the htlc timeout period. + StateFailIncorrectHtlcAmtSwept SwapState = 13 ) // SwapStateType defines the types of swap states that exist. Every swap state @@ -92,10 +97,7 @@ const ( // Type returns the type of the SwapState it is called on. func (s SwapState) Type() SwapStateType { - if s == StateInitiated || s == StateHtlcPublished || - s == StatePreimageRevealed || s == StateFailTemporary || - s == StateInvoiceSettled { - + if s.IsPending() { return StateTypePending } @@ -110,7 +112,7 @@ func (s SwapState) Type() SwapStateType { func (s SwapState) IsPending() bool { return s == StateInitiated || s == StateHtlcPublished || s == StatePreimageRevealed || s == StateFailTemporary || - s == StateInvoiceSettled + s == StateInvoiceSettled || s == StateFailIncorrectHtlcAmt } // IsFinal returns true if the swap is in a final state. @@ -160,6 +162,9 @@ func (s SwapState) String() string { case StateFailInsufficientConfirmedBalance: return "InsufficientConfirmedBalance" + case StateFailIncorrectHtlcAmtSwept: + return "StateFailIncorrectHtlcAmtSwept" + default: return "Unknown" }