Skip to content

Commit 477da6e

Browse files
htlcswitch: return error from all encrypt methods
Co-authored-by: Joost Jager <[email protected]>
1 parent 01dfee6 commit 477da6e

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
@@ -3173,16 +3173,22 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
31733173
packet.incomingChanID, packet.incomingHTLCID,
31743174
packet.outgoingChanID, packet.outgoingHTLCID)
31753175

3176-
htlc.Reason = circuit.ErrorEncrypter.EncryptMalformedError(
3176+
htlc.Reason, err = circuit.ErrorEncrypter.EncryptMalformedError(
31773177
htlc.Reason,
31783178
)
3179+
if err != nil {
3180+
return err
3181+
}
31793182

31803183
default:
31813184
// Otherwise, it's a forwarded error, so we'll perform a
31823185
// wrapper encryption as normal.
3183-
htlc.Reason = circuit.ErrorEncrypter.IntermediateEncrypt(
3186+
htlc.Reason, err = circuit.ErrorEncrypter.IntermediateEncrypt(
31843187
htlc.Reason,
31853188
)
3189+
if err != nil {
3190+
return err
3191+
}
31863192
}
31873193

31883194
// Deliver this packet.

0 commit comments

Comments
 (0)