htlcswitch: add ClearTextError interface

This commit adds a ClearTextError interface
which is implemented by non-opaque errors that
we know the underlying wire failure message for.
This interface is implemented by ForwardingErrors,
because we can fully decrypt the onion blob to
obtain the underlying failure reason. This interface
will also be implemented by errors which originate
at our node in following commits, because we know
the failure reason when we fail the htlc.

The lnwire interface is un-embedded in the
ForwardingError struct in favour of implementing
this interface. This change is made to protect
against accidental passing of a ForwardingError
to the wire, where the embedded FailureMessage
interface will present as wire failure but
will not serialize properly.
This commit is contained in:
carla
2020-01-14 15:07:41 +02:00
parent 6f0a342f92
commit 102f9b003f
6 changed files with 54 additions and 27 deletions

View File

@@ -579,7 +579,7 @@ func TestExitNodeTimelockPayloadMismatch(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailFinalIncorrectCltvExpiry:
default:
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
@@ -679,7 +679,7 @@ func TestLinkForwardTimelockPolicyMismatch(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailIncorrectCltvExpiry:
default:
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
@@ -737,7 +737,7 @@ func TestLinkForwardFeePolicyMismatch(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailFeeInsufficient:
default:
t.Fatalf("incorrect error, expected fee insufficient, "+
@@ -795,7 +795,7 @@ func TestLinkForwardMinHTLCPolicyMismatch(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailAmountBelowMinimum:
default:
t.Fatalf("incorrect error, expected amount below minimum, "+
@@ -862,7 +862,7 @@ func TestLinkForwardMaxHTLCPolicyMismatch(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailTemporaryChannelFailure:
default:
t.Fatalf("incorrect error, expected temporary channel failure, "+
@@ -968,7 +968,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
if !ok {
t.Fatalf("expected a ForwardingError, instead got (%T): %v", err, err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailFeeInsufficient:
default:
t.Fatalf("expected FailFeeInsufficient instead got: %v", err)
@@ -1008,7 +1008,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got (%T): %v",
err, err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailTemporaryChannelFailure:
default:
t.Fatalf("expected TemporaryChannelFailure, instead got: %v",
@@ -1253,9 +1253,9 @@ func TestChannelLinkMultiHopUnknownNextHop(t *testing.T) {
if !ok {
t.Fatalf("expected ForwardingError")
}
if _, ok = fErr.FailureMessage.(*lnwire.FailUnknownNextPeer); !ok {
if _, ok = fErr.WireMessage().(*lnwire.FailUnknownNextPeer); !ok {
t.Fatalf("wrong error has been received: %T",
fErr.FailureMessage)
fErr.WireMessage())
}
// Wait for Alice to receive the revocation.
@@ -1369,7 +1369,7 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailInvalidOnionVersion:
default:
t.Fatalf("wrong error have been received: %v", err)
@@ -1462,7 +1462,7 @@ func TestChannelLinkExpiryTooSoonExitNode(t *testing.T) {
err, err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailIncorrectDetails:
default:
t.Fatalf("expected incorrect_or_unknown_payment_details, "+
@@ -1524,7 +1524,7 @@ func TestChannelLinkExpiryTooSoonMidNode(t *testing.T) {
t.Fatalf("expected a ForwardingError, instead got: %T: %v", err, err)
}
switch ferr.FailureMessage.(type) {
switch ferr.WireMessage().(type) {
case *lnwire.FailExpiryTooSoon:
default:
t.Fatalf("incorrect error, expected final time lock too "+
@@ -5636,7 +5636,7 @@ func TestChannelLinkCanceledInvoice(t *testing.T) {
if !ok {
t.Fatalf("expected ForwardingError, but got %v", err)
}
_, ok = fErr.FailureMessage.(*lnwire.FailIncorrectDetails)
_, ok = fErr.WireMessage().(*lnwire.FailIncorrectDetails)
if !ok {
t.Fatalf("expected unknown payment hash, but got %v", err)
}
@@ -6221,8 +6221,8 @@ func assertFailureCode(t *testing.T, err error, code lnwire.FailCode) {
t.Fatalf("expected ForwardingError but got %T", err)
}
if fErr.FailureMessage.Code() != code {
if fErr.WireMessage().Code() != code {
t.Fatalf("expected %v but got %v",
code, fErr.FailureMessage.Code())
code, fErr.WireMessage().Code())
}
}