Skip to content

Commit fb95458

Browse files
committed
htlcswitch: skip checking replays for reforwarded packets
We now rely on the forwarding package's state to decide whether a given packet is a reforwarding or not. If we know it's a reforwarding packet, there's no need to check for replays in the `sharedHashes` bucket, which behaves the same as if we are querying the `batchReplayBkt`.
1 parent a5c4a7c commit fb95458

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

htlcswitch/hop/iterator.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ func (r *DecodeHopIteratorResponse) Result() (Iterator, lnwire.FailCode) {
745745
// the presented readers and rhashes *NEVER* deviate across invocations for the
746746
// same id.
747747
func (p *OnionProcessor) DecodeHopIterators(id []byte,
748-
reqs []DecodeHopIteratorRequest) ([]DecodeHopIteratorResponse, error) {
748+
reqs []DecodeHopIteratorRequest,
749+
reforward bool) ([]DecodeHopIteratorResponse, error) {
749750

750751
var (
751752
batchSize = len(reqs)
@@ -864,11 +865,12 @@ func (p *OnionProcessor) DecodeHopIterators(id []byte,
864865
continue
865866
}
866867

867-
// If this index is contained in the replay set, mark it with a
868-
// temporary channel failure error code. We infer that the
869-
// offending error was due to a replayed packet because this
870-
// index was found in the replay set.
871-
if replays.Contains(uint16(i)) {
868+
// If this index is contained in the replay set, and it is not a
869+
// reforwarding on startup, mark it with a permanent channel
870+
// failure error code. We infer that the offending error was due
871+
// to a replayed packet because this index was found in the
872+
// replay set.
873+
if !reforward && replays.Contains(uint16(i)) {
872874
log.Errorf("unable to process onion packet: %v",
873875
sphinx.ErrReplayedPacket)
874876

htlcswitch/link.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ type ChannelLinkConfig struct {
108108
// blobs, which are then used to inform how to forward an HTLC.
109109
//
110110
// NOTE: This function assumes the same set of readers and preimages
111-
// are always presented for the same identifier.
112-
DecodeHopIterators func([]byte, []hop.DecodeHopIteratorRequest) (
111+
// are always presented for the same identifier. The last boolean is
112+
// used to decide whether this is a reforwarding or not - when it's
113+
// reforwarding, we skip the replay check enforced in our decay log.
114+
DecodeHopIterators func([]byte, []hop.DecodeHopIteratorRequest, bool) (
113115
[]hop.DecodeHopIteratorResponse, error)
114116

115117
// ExtractErrorEncrypter function is responsible for decoding HTLC
@@ -3764,12 +3766,14 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg) {
37643766
}
37653767
}
37663768

3769+
reforward := fwdPkg.State != channeldb.FwdStateLockedIn
3770+
37673771
// Atomically decode the incoming htlcs, simultaneously checking for
37683772
// replay attempts. A particular index in the returned, spare list of
37693773
// channel iterators should only be used if the failure code at the
37703774
// same index is lnwire.FailCodeNone.
37713775
decodeResps, sphinxErr := l.cfg.DecodeHopIterators(
3772-
fwdPkg.ID(), decodeReqs,
3776+
fwdPkg.ID(), decodeReqs, reforward,
37733777
)
37743778
if sphinxErr != nil {
37753779
l.failf(LinkFailureError{code: ErrInternalError},
@@ -4120,17 +4124,15 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg) {
41204124
return
41214125
}
41224126

4123-
replay := fwdPkg.State != channeldb.FwdStateLockedIn
4124-
4125-
l.log.Debugf("forwarding %d packets to switch: replay=%v",
4126-
len(switchPackets), replay)
4127+
l.log.Debugf("forwarding %d packets to switch: reforward=%v",
4128+
len(switchPackets), reforward)
41274129

41284130
// NOTE: This call is made synchronous so that we ensure all circuits
41294131
// are committed in the exact order that they are processed in the link.
41304132
// Failing to do this could cause reorderings/gaps in the range of
41314133
// opened circuits, which violates assumptions made by the circuit
41324134
// trimming.
4133-
l.forwardBatch(replay, switchPackets...)
4135+
l.forwardBatch(reforward, switchPackets...)
41344136
}
41354137

41364138
// experimentalEndorsement returns the value to set for our outgoing

htlcswitch/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func (p *mockIteratorDecoder) DecodeHopIterator(r io.Reader, rHash []byte,
522522
}
523523

524524
func (p *mockIteratorDecoder) DecodeHopIterators(id []byte,
525-
reqs []hop.DecodeHopIteratorRequest) (
525+
reqs []hop.DecodeHopIteratorRequest, _ bool) (
526526
[]hop.DecodeHopIteratorResponse, error) {
527527

528528
idHash := sha256.Sum256(id)

0 commit comments

Comments
 (0)