Skip to content

Commit 6609bc0

Browse files
htlcswitch: return error from all encrypt methods
Co-authored-by: Joost Jager <[email protected]>
1 parent 5082566 commit 6609bc0

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

htlcswitch/hop/error_encryptor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ type ErrorEncrypter interface {
6565
// message. This method is used when we receive an
6666
// UpdateFailMalformedHTLC from the remote peer and then need to
6767
// convert that into a proper error from only the raw bytes.
68-
EncryptMalformedError(lnwire.OpaqueReason) lnwire.OpaqueReason
68+
EncryptMalformedError(lnwire.OpaqueReason) (lnwire.OpaqueReason, error)
6969

7070
// IntermediateEncrypt wraps an already encrypted opaque reason error
7171
// in an additional layer of onion encryption. This process repeats
7272
// until the error arrives at the source of the payment.
73-
IntermediateEncrypt(lnwire.OpaqueReason) lnwire.OpaqueReason
73+
IntermediateEncrypt(lnwire.OpaqueReason) (lnwire.OpaqueReason, error)
7474

7575
// Type returns an enum indicating the underlying concrete instance
7676
// backing this interface.
@@ -143,9 +143,9 @@ func (s *SphinxErrorEncrypter) EncryptFirstHop(
143143
//
144144
// NOTE: Part of the ErrorEncrypter interface.
145145
func (s *SphinxErrorEncrypter) EncryptMalformedError(
146-
reason lnwire.OpaqueReason) lnwire.OpaqueReason {
146+
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
147147

148-
return s.EncryptError(true, reason)
148+
return s.EncryptError(true, reason), nil
149149
}
150150

151151
// IntermediateEncrypt wraps an already encrypted opaque reason error in an
@@ -156,9 +156,9 @@ func (s *SphinxErrorEncrypter) EncryptMalformedError(
156156
//
157157
// NOTE: Part of the ErrorEncrypter interface.
158158
func (s *SphinxErrorEncrypter) IntermediateEncrypt(
159-
reason lnwire.OpaqueReason) lnwire.OpaqueReason {
159+
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
160160

161-
return s.EncryptError(false, reason)
161+
return s.EncryptError(false, reason), nil
162162
}
163163

164164
// Type returns the identifier for a sphinx error encrypter.

htlcswitch/interceptable_switch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,10 @@ func (f *interceptedForward) ResumeModified(
738738
// Fail notifies the intention to Fail an existing hold forward with an
739739
// encrypted failure reason.
740740
func (f *interceptedForward) Fail(reason []byte) error {
741-
obfuscatedReason := f.packet.obfuscator.IntermediateEncrypt(reason)
741+
obfuscatedReason, err := f.packet.obfuscator.IntermediateEncrypt(reason)
742+
if err != nil {
743+
return err
744+
}
742745

743746
return f.resolve(&lnwire.UpdateFailHTLC{
744747
Reason: obfuscatedReason,

htlcswitch/mock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,17 @@ func (o *mockObfuscator) EncryptFirstHop(failure lnwire.FailureMessage) (
434434
return b.Bytes(), nil
435435
}
436436

437-
func (o *mockObfuscator) IntermediateEncrypt(reason lnwire.OpaqueReason) lnwire.OpaqueReason {
438-
return reason
437+
func (o *mockObfuscator) IntermediateEncrypt(reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
438+
return reason, nil
439439
}
440440

441-
func (o *mockObfuscator) EncryptMalformedError(reason lnwire.OpaqueReason) lnwire.OpaqueReason {
441+
func (o *mockObfuscator) EncryptMalformedError(reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
442442
var b bytes.Buffer
443443
b.Write(fakeHmac)
444444

445445
b.Write(reason)
446446

447-
return b.Bytes()
447+
return b.Bytes(), nil
448448
}
449449

450450
// mockDeobfuscator mock implementation of the failure deobfuscator which

htlcswitch/switch.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,16 +3181,22 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
31813181
packet.incomingChanID, packet.incomingHTLCID,
31823182
packet.outgoingChanID, packet.outgoingHTLCID)
31833183

3184-
htlc.Reason = circuit.ErrorEncrypter.EncryptMalformedError(
3184+
htlc.Reason, err = circuit.ErrorEncrypter.EncryptMalformedError(
31853185
htlc.Reason,
31863186
)
3187+
if err != nil {
3188+
return err
3189+
}
31873190

31883191
default:
31893192
// Otherwise, it's a forwarded error, so we'll perform a
31903193
// wrapper encryption as normal.
3191-
htlc.Reason = circuit.ErrorEncrypter.IntermediateEncrypt(
3194+
htlc.Reason, err = circuit.ErrorEncrypter.IntermediateEncrypt(
31923195
htlc.Reason,
31933196
)
3197+
if err != nil {
3198+
return err
3199+
}
31943200
}
31953201

31963202
// Deliver this packet.

0 commit comments

Comments
 (0)