2018-02-27 18:31:05 +01:00
|
|
|
package lnwallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
"github.com/btcsuite/btcutil"
|
2018-07-31 09:17:17 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2018-02-27 18:31:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReservationError wraps certain errors returned during channel reservation
|
|
|
|
// that can be sent across the wire to the remote peer. Errors not being
|
|
|
|
// ReservationErrors will not be sent to the remote in case of a failed channel
|
|
|
|
// reservation, as they may contain private information.
|
|
|
|
type ReservationError struct {
|
|
|
|
error
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure ReservationError implements the error
|
|
|
|
// interface.
|
|
|
|
var _ error = (*ReservationError)(nil)
|
|
|
|
|
|
|
|
// ErrZeroCapacity returns an error indicating the funder attempted to put zero
|
|
|
|
// funds into the channel.
|
|
|
|
func ErrZeroCapacity() ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
errors.New("zero channel funds"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrChainMismatch returns an error indicating that the initiator tried to
|
|
|
|
// open a channel for an unknown chain.
|
|
|
|
func ErrChainMismatch(knownChain,
|
|
|
|
unknownChain *chainhash.Hash) ReservationError {
|
|
|
|
return ReservationError{
|
2020-04-14 19:56:05 +02:00
|
|
|
fmt.Errorf("unknown chain=%v, supported chain=%v",
|
2018-02-27 18:31:05 +01:00
|
|
|
unknownChain, knownChain),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrFunderBalanceDust returns an error indicating the initial balance of the
|
|
|
|
// funder is considered dust at the current commitment fee.
|
|
|
|
func ErrFunderBalanceDust(commitFee, funderBalance,
|
|
|
|
minBalance int64) ReservationError {
|
|
|
|
return ReservationError{
|
2020-04-14 19:56:05 +02:00
|
|
|
fmt.Errorf("funder balance too small (%v) with fee=%v sat, "+
|
2018-02-27 18:31:05 +01:00
|
|
|
"minimum=%v sat required", funderBalance,
|
|
|
|
commitFee, minBalance),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrCsvDelayTooLarge returns an error indicating that the CSV delay was to
|
|
|
|
// large to be accepted, along with the current max.
|
|
|
|
func ErrCsvDelayTooLarge(remoteDelay, maxDelay uint16) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("CSV delay too large: %v, max is %v",
|
|
|
|
remoteDelay, maxDelay),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 20:04:34 +02:00
|
|
|
// ErrChanReserveTooSmall returns an error indicating that the channel reserve
|
|
|
|
// the remote is requiring is too small to be accepted.
|
|
|
|
func ErrChanReserveTooSmall(reserve, dustLimit btcutil.Amount) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("channel reserve of %v sat is too small, min is %v "+
|
|
|
|
"sat", int64(reserve), int64(dustLimit)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:31:05 +01:00
|
|
|
// ErrChanReserveTooLarge returns an error indicating that the chan reserve the
|
|
|
|
// remote is requiring, is too large to be accepted.
|
|
|
|
func ErrChanReserveTooLarge(reserve,
|
|
|
|
maxReserve btcutil.Amount) ReservationError {
|
|
|
|
return ReservationError{
|
2020-04-14 19:56:05 +02:00
|
|
|
fmt.Errorf("channel reserve is too large: %v sat, max "+
|
2018-02-27 18:31:05 +01:00
|
|
|
"is %v sat", int64(reserve), int64(maxReserve)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 10:28:39 +02:00
|
|
|
// ErrNonZeroPushAmount is returned by a remote peer that receives a
|
|
|
|
// FundingOpen request for a channel with non-zero push amount while
|
|
|
|
// they have 'rejectpush' enabled.
|
|
|
|
func ErrNonZeroPushAmount() ReservationError {
|
2020-04-14 19:56:05 +02:00
|
|
|
return ReservationError{errors.New("non-zero push amounts are disabled")}
|
2018-10-10 10:28:39 +02:00
|
|
|
}
|
|
|
|
|
2018-02-27 18:31:05 +01:00
|
|
|
// ErrMinHtlcTooLarge returns an error indicating that the MinHTLC value the
|
|
|
|
// remote required is too large to be accepted.
|
|
|
|
func ErrMinHtlcTooLarge(minHtlc,
|
|
|
|
maxMinHtlc lnwire.MilliSatoshi) ReservationError {
|
|
|
|
return ReservationError{
|
2020-04-14 19:56:05 +02:00
|
|
|
fmt.Errorf("minimum HTLC value is too large: %v, max is %v",
|
2018-02-27 18:31:05 +01:00
|
|
|
minHtlc, maxMinHtlc),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrMaxHtlcNumTooLarge returns an error indicating that the 'max HTLCs in
|
|
|
|
// flight' value the remote required is too large to be accepted.
|
|
|
|
func ErrMaxHtlcNumTooLarge(maxHtlc, maxMaxHtlc uint16) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("maxHtlcs is too large: %d, max is %d",
|
|
|
|
maxHtlc, maxMaxHtlc),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrMaxHtlcNumTooSmall returns an error indicating that the 'max HTLCs in
|
|
|
|
// flight' value the remote required is too small to be accepted.
|
|
|
|
func ErrMaxHtlcNumTooSmall(maxHtlc, minMaxHtlc uint16) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("maxHtlcs is too small: %d, min is %d",
|
|
|
|
maxHtlc, minMaxHtlc),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrMaxValueInFlightTooSmall returns an error indicating that the 'max HTLC
|
|
|
|
// value in flight' the remote required is too small to be accepted.
|
|
|
|
func ErrMaxValueInFlightTooSmall(maxValInFlight,
|
|
|
|
minMaxValInFlight lnwire.MilliSatoshi) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("maxValueInFlight too small: %v, min is %v",
|
|
|
|
maxValInFlight, minMaxValInFlight),
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 01:17:50 +02:00
|
|
|
|
2019-01-12 02:02:11 +01:00
|
|
|
// ErrNumConfsTooLarge returns an error indicating that the number of
|
|
|
|
// confirmations required for a channel is too large.
|
|
|
|
func ErrNumConfsTooLarge(numConfs, maxNumConfs uint32) error {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("minimum depth of %d is too large, max is %d",
|
|
|
|
numConfs, maxNumConfs),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 01:17:50 +02:00
|
|
|
// ErrChanTooSmall returns an error indicating that an incoming channel request
|
|
|
|
// was too small. We'll reject any incoming channels if they're below our
|
|
|
|
// configured value for the min channel size we'll accept.
|
|
|
|
func ErrChanTooSmall(chanSize, minChanSize btcutil.Amount) ReservationError {
|
|
|
|
return ReservationError{
|
|
|
|
fmt.Errorf("chan size of %v is below min chan size of %v",
|
|
|
|
chanSize, minChanSize),
|
|
|
|
}
|
|
|
|
}
|
2018-08-08 05:12:31 +02:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|