Skip to content

Commit 404d40c

Browse files
committed
(temp)build: bump lightning-onion
1 parent 6609bc0 commit 404d40c

File tree

13 files changed

+55
-39
lines changed

13 files changed

+55
-39
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,7 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
222222
// well).
223223
go 1.24.6
224224

225+
// Temporary replace until dependent PR is merged in lightning-onion.
226+
replace github.com/lightningnetwork/lightning-onion => github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e
227+
225228
retract v0.0.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR
306306
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
307307
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
308308
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
309+
github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e h1:kwxUmYn+qyX4olGy7TxgUeXpmnaMjf4+/bn9Ke9w0GU=
310+
github.com/joostjager/lightning-onion v0.0.0-20250630141312-2898b9c46c4e/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w=
309311
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
310312
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
311313
github.com/jrick/logrotate v1.1.2 h1:6ePk462NCX7TfKtNp5JJ7MbA2YIslkpfgP03TlTYMN0=
@@ -368,8 +370,6 @@ github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3
368370
github.com/lightninglabs/neutrino/cache v1.1.2/go.mod h1:XJNcgdOw1LQnanGjw8Vj44CvguYA25IMKjWFZczwZuo=
369371
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS/00EiEg0qp0FhehxnQfk3vv8U6Xt3nN+rTY=
370372
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
371-
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 h1:6D3LrdagJweLLdFm1JNodZsBk6iU4TTsBBFLQ4yiXfI=
372-
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w=
373373
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
374374
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
375375
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/failure_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func TestLongFailureMessage(t *testing.T) {
5252
}
5353

5454
errorDecryptor := &SphinxErrorDecrypter{
55-
OnionErrorDecrypter: sphinx.NewOnionErrorDecrypter(circuit),
55+
OnionErrorDecrypter: sphinx.NewOnionErrorDecrypter(
56+
circuit, nil,
57+
),
5658
}
5759

5860
// Assert that the failure message can still be extracted.

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
@@ -3532,7 +3532,7 @@ func (l *channelLink) sendHTLCError(add lnwire.UpdateAddHTLC,
35323532
sourceRef channeldb.AddRef, failure *LinkError,
35333533
e hop.ErrorEncrypter, isReceive bool) {
35343534

3535-
reason, err := e.EncryptFirstHop(failure.WireMessage())
3535+
reason, _, err := e.EncryptFirstHop(failure.WireMessage())
35363536
if err != nil {
35373537
l.log.Errorf("unable to obfuscate error: %v", err)
35383538
return
@@ -3634,7 +3634,7 @@ func (l *channelLink) sendIncomingHTLCFailureMsg(htlcIndex uint64,
36343634
failureMsg := lnwire.NewInvalidBlinding(
36353635
fn.None[[lnwire.OnionPacketSize]byte](),
36363636
)
3637-
reason, err := e.EncryptFirstHop(failureMsg)
3637+
reason, _, err := e.EncryptFirstHop(failureMsg)
36383638
if err != nil {
36393639
return err
36403640
}

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: 14 additions & 9 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
@@ -1139,8 +1144,8 @@ type mockOnionErrorDecryptor struct {
11391144
err error
11401145
}
11411146

1142-
func (m *mockOnionErrorDecryptor) DecryptError(encryptedData []byte) (
1143-
*sphinx.DecryptedError, error) {
1147+
func (m *mockOnionErrorDecryptor) DecryptError(encryptedData, _ []byte,
1148+
_ bool) (*sphinx.DecryptedError, error) {
11441149

11451150
return &sphinx.DecryptedError{
11461151
SenderIdx: m.sourceIdx,

0 commit comments

Comments
 (0)