Skip to content

Commit f1b6fcf

Browse files
committed
sphinx: rename incomingCltv to replayData in ProcessOnionPacket
Rename the parameter to be more generic since it is passed to the ReplayLog and can store any auxiliary data, not just CLTV values. Update godoc to explain usage with and without replay protection.
1 parent 743401e commit f1b6fcf

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

sphinx.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,17 @@ func WithTLVPayloadOnly() ProcessOnionOpt {
606606
// in the onion packet to derive the shared secret. Finally, if the MAC doesn't
607607
// check the packet is again rejected.
608608
//
609-
// In the case of a successful packet processing, and ProcessedPacket struct is
609+
// The replayData parameter is passed to the ReplayLog and can be used by
610+
// implementations to store auxiliary data alongside the packet hash. For
611+
// example, in HTLC forwarding this could be the incoming CLTV value. When using
612+
// NoOpReplayLog (no replay protection), this value is ignored and can be set
613+
// to 0.
614+
//
615+
// In the case of a successful packet processing, a ProcessedPacket struct is
610616
// returned which houses the newly parsed packet, along with instructions on
611617
// what to do next.
612618
func (r *Router) ProcessOnionPacket(onionPkt *OnionPacket, assocData []byte,
613-
incomingCltv uint32, opts ...ProcessOnionOpt) (*ProcessedPacket,
619+
replayData uint32, opts ...ProcessOnionOpt) (*ProcessedPacket,
614620
error) {
615621

616622
cfg := &processOnionCfg{}
@@ -642,7 +648,8 @@ func (r *Router) ProcessOnionPacket(onionPkt *OnionPacket, assocData []byte,
642648

643649
// Atomically compare this hash prefix with the contents of the on-disk
644650
// log, persisting it only if this entry was not detected as a replay.
645-
if err := r.log.Put(hashPrefix, incomingCltv); err != nil {
651+
err = r.log.Put(hashPrefix, replayData)
652+
if err != nil {
646653
return nil, err
647654
}
648655

@@ -853,11 +860,17 @@ func (r *Router) BeginTxn(id []byte, nels int) *Tx {
853860
// in the onion packet to derive the shared secret. Finally, if the MAC doesn't
854861
// check the packet is again rejected.
855862
//
856-
// In the case of a successful packet processing, and ProcessedPacket struct is
863+
// The replayData parameter is passed to the ReplayLog and can be used by
864+
// implementations to store auxiliary data alongside the packet hash. For
865+
// example, in HTLC forwarding this could be the incoming CLTV value. When using
866+
// NoOpReplayLog (no replay protection), this value is ignored and can be set
867+
// to 0.
868+
//
869+
// In the case of a successful packet processing, a ProcessedPacket struct is
857870
// returned which houses the newly parsed packet, along with instructions on
858871
// what to do next.
859872
func (t *Tx) ProcessOnionPacket(seqNum uint16, onionPkt *OnionPacket,
860-
assocData []byte, incomingCltv uint32, opts ...ProcessOnionOpt) error {
873+
assocData []byte, replayData uint32, opts ...ProcessOnionOpt) error {
861874

862875
cfg := &processOnionCfg{}
863876
for _, o := range opts {
@@ -891,7 +904,7 @@ func (t *Tx) ProcessOnionPacket(seqNum uint16, onionPkt *OnionPacket,
891904

892905
// Add the hash prefix to pending batch of shared secrets that will be
893906
// written later via Commit().
894-
err = t.batch.Put(seqNum, hashPrefix, incomingCltv)
907+
err = t.batch.Put(seqNum, hashPrefix, replayData)
895908
if err != nil {
896909
return err
897910
}

0 commit comments

Comments
 (0)