From 0dca373bcd63d49df5b2a486237c8006aa2d85d4 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 7 Aug 2018 20:12:31 -0700 Subject: [PATCH] lnwallet/errors: create concrete errors for settle/fail --- lnwallet/errors.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lnwallet/errors.go b/lnwallet/errors.go index a1f83edf..f36d0b99 100644 --- a/lnwallet/errors.go +++ b/lnwallet/errors.go @@ -125,3 +125,49 @@ func ErrChanTooSmall(chanSize, minChanSize btcutil.Amount) ReservationError { chanSize, minChanSize), } } + +// ErrHtlcIndexAlreadyFailed is returned when the HTLC index has already been +// failed, but has not been committed by our commitment state. +type ErrHtlcIndexAlreadyFailed uint64 + +// Error returns a message indicating the index that had already been failed. +func (e ErrHtlcIndexAlreadyFailed) Error() string { + return fmt.Sprintf("HTLC with ID %d has already been failed", e) +} + +// ErrHtlcIndexAlreadySettled is returned when the HTLC index has already been +// settled, but has not been committed by our commitment state. +type ErrHtlcIndexAlreadySettled uint64 + +// Error returns a message indicating the index that had already been settled. +func (e ErrHtlcIndexAlreadySettled) Error() string { + return fmt.Sprintf("HTLC with ID %d has already been settled", e) +} + +// ErrInvalidSettlePreimage is returned when trying to settle an HTLC, but the +// preimage does not correspond to the payment hash. +type ErrInvalidSettlePreimage struct { + preimage []byte + rhash []byte +} + +// Error returns an error message with the offending preimage and intended +// payment hash. +func (e ErrInvalidSettlePreimage) Error() string { + return fmt.Sprintf("Invalid payment preimage %x for hash %x", + e.preimage, e.rhash) +} + +// ErrUnknownHtlcIndex is returned when locally settling or failing an HTLC, but +// the HTLC index is not known to the channel. This typically indicates that the +// HTLC was already settled in a prior commitment. +type ErrUnknownHtlcIndex struct { + chanID lnwire.ShortChannelID + index uint64 +} + +// Error returns an error logging the channel and HTLC index that was unknown. +func (e ErrUnknownHtlcIndex) Error() string { + return fmt.Sprintf("No HTLC with ID %d in channel %v", + e.index, e.chanID) +}