Skip to content

Commit 3ff0717

Browse files
committed
(temp)build: bump lightning-onion
1 parent 477da6e commit 3ff0717

File tree

11 files changed

+49
-35
lines changed

11 files changed

+49
-35
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,7 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
218218
// well).
219219
go 1.23.6
220220

221+
// Temporary replace until dependent PR is merged in lightning-onion.
222+
replace github.com/lightningnetwork/lightning-onion => github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e
223+
221224
retract v0.0.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR
297297
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
298298
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
299299
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
300+
github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e h1:kwxUmYn+qyX4olGy7TxgUeXpmnaMjf4+/bn9Ke9w0GU=
301+
github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w=
300302
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
301303
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
302304
github.com/jrick/logrotate v1.1.2 h1:6ePk462NCX7TfKtNp5JJ7MbA2YIslkpfgP03TlTYMN0=
@@ -359,8 +361,6 @@ github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3
359361
github.com/lightninglabs/neutrino/cache v1.1.2/go.mod h1:XJNcgdOw1LQnanGjw8Vj44CvguYA25IMKjWFZczwZuo=
360362
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wleRN1L2fJXd6ZoQ9ZegVFTAb2bOQfruJPKcY=
361363
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
362-
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 h1:6D3LrdagJweLLdFm1JNodZsBk6iU4TTsBBFLQ4yiXfI=
363-
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w=
364364
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
365365
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
366366
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=

htlcswitch/failure.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type OnionErrorDecrypter interface {
160160
// node where error have occurred. As a result, in order to decrypt the
161161
// error we need get all shared secret and apply decryption in the
162162
// reverse order.
163-
DecryptError(encryptedData []byte) (*sphinx.DecryptedError, error)
163+
DecryptError(encryptedData, _ []byte, _ bool) (*sphinx.DecryptedError, error)
164164
}
165165

166166
// SphinxErrorDecrypter wraps the sphinx data SphinxErrorDecrypter and maps the
@@ -177,7 +177,7 @@ type SphinxErrorDecrypter struct {
177177
func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (
178178
*ForwardingError, error) {
179179

180-
failure, err := s.OnionErrorDecrypter.DecryptError(reason)
180+
failure, err := s.OnionErrorDecrypter.DecryptError(reason, nil, false)
181181
if err != nil {
182182
return nil, err
183183
}

htlcswitch/hop/error_encryptor.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,22 @@ type ErrorEncrypter interface {
5858
// encrypted opaque failure reason. This method will be used at the
5959
// source that the error occurs. It differs from IntermediateEncrypt
6060
// slightly, in that it computes a proper MAC over the error.
61-
EncryptFirstHop(lnwire.FailureMessage) (lnwire.OpaqueReason, error)
61+
EncryptFirstHop(lnwire.FailureMessage) (lnwire.OpaqueReason, []byte,
62+
error)
6263

6364
// EncryptMalformedError is similar to EncryptFirstHop (it adds the
6465
// MAC), but it accepts an opaque failure reason rather than a failure
6566
// message. This method is used when we receive an
6667
// UpdateFailMalformedHTLC from the remote peer and then need to
6768
// convert that into a proper error from only the raw bytes.
68-
EncryptMalformedError(lnwire.OpaqueReason) (lnwire.OpaqueReason, error)
69+
EncryptMalformedError(lnwire.OpaqueReason) (lnwire.OpaqueReason, []byte,
70+
error)
6971

7072
// IntermediateEncrypt wraps an already encrypted opaque reason error
7173
// in an additional layer of onion encryption. This process repeats
7274
// until the error arrives at the source of the payment.
73-
IntermediateEncrypt(lnwire.OpaqueReason) (lnwire.OpaqueReason, error)
75+
IntermediateEncrypt(lnwire.OpaqueReason, []byte) (lnwire.OpaqueReason,
76+
[]byte, error)
7477

7578
// Type returns an enum indicating the underlying concrete instance
7679
// backing this interface.
@@ -123,16 +126,16 @@ func NewSphinxErrorEncrypter() *SphinxErrorEncrypter {
123126
//
124127
// NOTE: Part of the ErrorEncrypter interface.
125128
func (s *SphinxErrorEncrypter) EncryptFirstHop(
126-
failure lnwire.FailureMessage) (lnwire.OpaqueReason, error) {
129+
failure lnwire.FailureMessage) (lnwire.OpaqueReason, []byte, error) {
127130

128131
var b bytes.Buffer
129132
if err := lnwire.EncodeFailure(&b, failure, 0); err != nil {
130-
return nil, err
133+
return nil, nil, err
131134
}
132135

133136
// We pass a true as the first parameter to indicate that a MAC should
134137
// be added.
135-
return s.EncryptError(true, b.Bytes()), nil
138+
return s.EncryptError(true, b.Bytes(), nil, 0)
136139
}
137140

138141
// EncryptMalformedError is similar to EncryptFirstHop (it adds the MAC), but
@@ -143,9 +146,9 @@ func (s *SphinxErrorEncrypter) EncryptFirstHop(
143146
//
144147
// NOTE: Part of the ErrorEncrypter interface.
145148
func (s *SphinxErrorEncrypter) EncryptMalformedError(
146-
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
149+
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, []byte, error) {
147150

148-
return s.EncryptError(true, reason), nil
151+
return s.EncryptError(true, reason, nil, 0)
149152
}
150153

151154
// IntermediateEncrypt wraps an already encrypted opaque reason error in an
@@ -156,9 +159,10 @@ func (s *SphinxErrorEncrypter) EncryptMalformedError(
156159
//
157160
// NOTE: Part of the ErrorEncrypter interface.
158161
func (s *SphinxErrorEncrypter) IntermediateEncrypt(
159-
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
162+
reason lnwire.OpaqueReason, _ []byte) (lnwire.OpaqueReason, []byte,
163+
error) {
160164

161-
return s.EncryptError(false, reason), nil
165+
return s.EncryptError(false, reason, nil, 0)
162166
}
163167

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

htlcswitch/hop/iterator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,7 @@ func (p *OnionProcessor) DecodeHopIterators(id []byte,
909909
func (p *OnionProcessor) ExtractErrorEncrypter(ephemeralKey *btcec.PublicKey) (
910910
ErrorEncrypter, lnwire.FailCode) {
911911

912-
onionObfuscator, err := sphinx.NewOnionErrorEncrypter(
913-
p.router, ephemeralKey,
914-
)
912+
sharedSecret, err := p.router.GenerateSharedSecret(ephemeralKey, nil)
915913
if err != nil {
916914
switch err {
917915
case sphinx.ErrInvalidOnionVersion:
@@ -926,6 +924,8 @@ func (p *OnionProcessor) ExtractErrorEncrypter(ephemeralKey *btcec.PublicKey) (
926924
}
927925
}
928926

927+
onionObfuscator := sphinx.NewOnionErrorEncrypter(sharedSecret, nil)
928+
929929
return &SphinxErrorEncrypter{
930930
OnionErrorEncrypter: onionObfuscator,
931931
EphemeralKey: ephemeralKey,

htlcswitch/interceptable_switch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ 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, err := f.packet.obfuscator.IntermediateEncrypt(reason)
741+
obfuscatedReason, _, err := f.packet.obfuscator.IntermediateEncrypt(
742+
reason, nil,
743+
)
742744
if err != nil {
743745
return err
744746
}
@@ -807,7 +809,7 @@ func (f *interceptedForward) FailWithCode(code lnwire.FailCode) error {
807809

808810
// Encrypt the failure for the first hop. This node will be the origin
809811
// of the failure.
810-
reason, err := f.packet.obfuscator.EncryptFirstHop(failureMsg)
812+
reason, _, err := f.packet.obfuscator.EncryptFirstHop(failureMsg)
811813
if err != nil {
812814
return fmt.Errorf("failed to encrypt failure reason %w", err)
813815
}

htlcswitch/link.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ func (l *channelLink) sendHTLCError(add lnwire.UpdateAddHTLC,
43674367
sourceRef channeldb.AddRef, failure *LinkError,
43684368
e hop.ErrorEncrypter, isReceive bool) {
43694369

4370-
reason, err := e.EncryptFirstHop(failure.WireMessage())
4370+
reason, _, err := e.EncryptFirstHop(failure.WireMessage())
43714371
if err != nil {
43724372
l.log.Errorf("unable to obfuscate error: %v", err)
43734373
return
@@ -4469,7 +4469,7 @@ func (l *channelLink) sendIncomingHTLCFailureMsg(htlcIndex uint64,
44694469
failureMsg := lnwire.NewInvalidBlinding(
44704470
fn.None[[lnwire.OnionPacketSize]byte](),
44714471
)
4472-
reason, err := e.EncryptFirstHop(failureMsg)
4472+
reason, _, err := e.EncryptFirstHop(failureMsg)
44734473
if err != nil {
44744474
return err
44754475
}

htlcswitch/mailbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ func (m *memoryMailBox) FailAdd(pkt *htlcPacket) {
721721
// If the packet is part of a forward, (identified by a non-nil
722722
// obfuscator) we need to encrypt the error back to the source.
723723
var err error
724-
reason, err = pkt.obfuscator.EncryptFirstHop(failure)
724+
reason, _, err = pkt.obfuscator.EncryptFirstHop(failure)
725725
if err != nil {
726726
log.Errorf("Unable to obfuscate error: %v", err)
727727
return

htlcswitch/mock.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,30 +421,35 @@ func (o *mockObfuscator) Reextract(
421421
var fakeHmac = []byte("hmachmachmachmachmachmachmachmac")
422422

423423
func (o *mockObfuscator) EncryptFirstHop(failure lnwire.FailureMessage) (
424-
lnwire.OpaqueReason, error) {
424+
lnwire.OpaqueReason, []byte, error) {
425425

426426
o.failure = failure
427427

428428
var b bytes.Buffer
429429
b.Write(fakeHmac)
430430

431431
if err := lnwire.EncodeFailure(&b, failure, 0); err != nil {
432-
return nil, err
432+
return nil, nil, err
433433
}
434-
return b.Bytes(), nil
434+
435+
return b.Bytes(), nil, nil
435436
}
436437

437-
func (o *mockObfuscator) IntermediateEncrypt(reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
438-
return reason, nil
438+
func (o *mockObfuscator) IntermediateEncrypt(reason lnwire.OpaqueReason,
439+
attrData []byte) (lnwire.OpaqueReason, []byte, error) {
440+
441+
return reason, nil, nil
439442
}
440443

441-
func (o *mockObfuscator) EncryptMalformedError(reason lnwire.OpaqueReason) (lnwire.OpaqueReason, error) {
444+
func (o *mockObfuscator) EncryptMalformedError(
445+
reason lnwire.OpaqueReason) (lnwire.OpaqueReason, []byte, error) {
446+
442447
var b bytes.Buffer
443448
b.Write(fakeHmac)
444449

445450
b.Write(reason)
446451

447-
return b.Bytes(), nil
452+
return b.Bytes(), nil, nil
448453
}
449454

450455
// mockDeobfuscator mock implementation of the failure deobfuscator which

htlcswitch/switch.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ func (s *Switch) failAddPacket(packet *htlcPacket, failure *LinkError) error {
12271227
// Encrypt the failure so that the sender will be able to read the error
12281228
// message. Since we failed this packet, we use EncryptFirstHop to
12291229
// obfuscate the failure for their eyes only.
1230-
reason, err := packet.obfuscator.EncryptFirstHop(failure.WireMessage())
1230+
reason, _, err := packet.obfuscator.EncryptFirstHop(failure.WireMessage())
12311231
if err != nil {
12321232
err := fmt.Errorf("unable to obfuscate "+
12331233
"error: %v", err)
@@ -3155,7 +3155,7 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
31553155
var err error
31563156
// TODO(roasbeef): don't need to pass actually?
31573157
failure := &lnwire.FailPermanentChannelFailure{}
3158-
htlc.Reason, err = circuit.ErrorEncrypter.EncryptFirstHop(
3158+
htlc.Reason, _, err = circuit.ErrorEncrypter.EncryptFirstHop(
31593159
failure,
31603160
)
31613161
if err != nil {
@@ -3173,7 +3173,7 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
31733173
packet.incomingChanID, packet.incomingHTLCID,
31743174
packet.outgoingChanID, packet.outgoingHTLCID)
31753175

3176-
htlc.Reason, err = circuit.ErrorEncrypter.EncryptMalformedError(
3176+
htlc.Reason, _, err = circuit.ErrorEncrypter.EncryptMalformedError(
31773177
htlc.Reason,
31783178
)
31793179
if err != nil {
@@ -3183,8 +3183,8 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
31833183
default:
31843184
// Otherwise, it's a forwarded error, so we'll perform a
31853185
// wrapper encryption as normal.
3186-
htlc.Reason, err = circuit.ErrorEncrypter.IntermediateEncrypt(
3187-
htlc.Reason,
3186+
htlc.Reason, _, err = circuit.ErrorEncrypter.IntermediateEncrypt(
3187+
htlc.Reason, nil,
31883188
)
31893189
if err != nil {
31903190
return err

0 commit comments

Comments
 (0)