mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
multi: fix newly detected linter issues
This commit is contained in:
@@ -22,77 +22,77 @@ const (
|
||||
|
||||
// fieldMismatchError returns a merge error for a named field when we get two
|
||||
// channel acceptor responses which have different values set.
|
||||
func fieldMismatchError(name string, current, new interface{}) error {
|
||||
func fieldMismatchError(name string, current, newValue interface{}) error {
|
||||
return fmt.Errorf("multiple values set for: %v, %v and %v",
|
||||
name, current, new)
|
||||
name, current, newValue)
|
||||
}
|
||||
|
||||
// mergeInt64 merges two int64 values, failing if they have different non-zero
|
||||
// values.
|
||||
func mergeInt64(name string, current, new int64) (int64, error) {
|
||||
func mergeInt64(name string, current, newValue int64) (int64, error) {
|
||||
switch {
|
||||
case current == 0:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
|
||||
case new == 0:
|
||||
case newValue == 0:
|
||||
return current, nil
|
||||
|
||||
case current != new:
|
||||
return 0, fieldMismatchError(name, current, new)
|
||||
case current != newValue:
|
||||
return 0, fieldMismatchError(name, current, newValue)
|
||||
|
||||
default:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// mergeMillisatoshi merges two msat values, failing if they have different
|
||||
// non-zero values.
|
||||
func mergeMillisatoshi(name string, current,
|
||||
new lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
|
||||
newValue lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
|
||||
|
||||
switch {
|
||||
case current == 0:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
|
||||
case new == 0:
|
||||
case newValue == 0:
|
||||
return current, nil
|
||||
|
||||
case current != new:
|
||||
return 0, fieldMismatchError(name, current, new)
|
||||
case current != newValue:
|
||||
return 0, fieldMismatchError(name, current, newValue)
|
||||
|
||||
default:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// mergeDeliveryAddress merges two delivery address values, failing if they have
|
||||
// different non-zero values.
|
||||
func mergeDeliveryAddress(name string, current,
|
||||
new lnwire.DeliveryAddress) (lnwire.DeliveryAddress, error) {
|
||||
newValue lnwire.DeliveryAddress) (lnwire.DeliveryAddress, error) {
|
||||
|
||||
switch {
|
||||
case current == nil:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
|
||||
case new == nil:
|
||||
case newValue == nil:
|
||||
return current, nil
|
||||
|
||||
case !bytes.Equal(current, new):
|
||||
return nil, fieldMismatchError(name, current, new)
|
||||
case !bytes.Equal(current, newValue):
|
||||
return nil, fieldMismatchError(name, current, newValue)
|
||||
|
||||
default:
|
||||
return new, nil
|
||||
return newValue, nil
|
||||
}
|
||||
}
|
||||
|
||||
// mergeResponse takes two channel accept responses, and attempts to merge their
|
||||
// fields, failing if any fields conflict (are non-zero and not equal). It
|
||||
// returns a new response that has all the merged fields in it.
|
||||
func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
error) {
|
||||
func mergeResponse(current,
|
||||
newValue ChannelAcceptResponse) (ChannelAcceptResponse, error) {
|
||||
|
||||
csv, err := mergeInt64(
|
||||
fieldCSV, int64(current.CSVDelay), int64(new.CSVDelay),
|
||||
fieldCSV, int64(current.CSVDelay), int64(newValue.CSVDelay),
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -101,7 +101,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
|
||||
htlcLimit, err := mergeInt64(
|
||||
fieldHtlcLimit, int64(current.HtlcLimit),
|
||||
int64(new.HtlcLimit),
|
||||
int64(newValue.HtlcLimit),
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -110,7 +110,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
|
||||
minDepth, err := mergeInt64(
|
||||
fieldMinDep, int64(current.MinAcceptDepth),
|
||||
int64(new.MinAcceptDepth),
|
||||
int64(newValue.MinAcceptDepth),
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -118,7 +118,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
current.MinAcceptDepth = uint16(minDepth)
|
||||
|
||||
reserve, err := mergeInt64(
|
||||
fieldReserve, int64(current.Reserve), int64(new.Reserve),
|
||||
fieldReserve, int64(current.Reserve), int64(newValue.Reserve),
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -126,7 +126,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
current.Reserve = btcutil.Amount(reserve)
|
||||
|
||||
current.MinHtlcIn, err = mergeMillisatoshi(
|
||||
fieldMinIn, current.MinHtlcIn, new.MinHtlcIn,
|
||||
fieldMinIn, current.MinHtlcIn, newValue.MinHtlcIn,
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -134,7 +134,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
|
||||
current.InFlightTotal, err = mergeMillisatoshi(
|
||||
fieldInFlightTotal, current.InFlightTotal,
|
||||
new.InFlightTotal,
|
||||
newValue.InFlightTotal,
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
@@ -142,7 +142,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
|
||||
|
||||
current.UpfrontShutdown, err = mergeDeliveryAddress(
|
||||
fieldUpfrontShutdown, current.UpfrontShutdown,
|
||||
new.UpfrontShutdown,
|
||||
newValue.UpfrontShutdown,
|
||||
)
|
||||
if err != nil {
|
||||
return current, err
|
||||
|
Reference in New Issue
Block a user