htlcswitch: encapsulate exposed packet info
This commit is contained in:
parent
607927634d
commit
74db43282c
@ -115,15 +115,15 @@ type interceptedForward struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Packet returns the intercepted htlc packet.
|
// Packet returns the intercepted htlc packet.
|
||||||
func (f *interceptedForward) Packet() lnwire.UpdateAddHTLC {
|
func (f *interceptedForward) Packet() InterceptedPacket {
|
||||||
return *f.htlc
|
return InterceptedPacket{
|
||||||
}
|
IncomingCircuit: channeldb.CircuitKey{
|
||||||
|
ChanID: f.packet.incomingChanID,
|
||||||
// CircuitKey returns the circuit key for the intercepted htlc.
|
HtlcID: f.packet.incomingHTLCID,
|
||||||
func (f *interceptedForward) CircuitKey() channeldb.CircuitKey {
|
},
|
||||||
return channeldb.CircuitKey{
|
Hash: f.htlc.PaymentHash,
|
||||||
ChanID: f.packet.incomingChanID,
|
OutgoingExpiry: f.htlc.Expiry,
|
||||||
HtlcID: f.packet.incomingHTLCID,
|
OutgoingAmount: f.htlc.Amount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,17 +200,32 @@ type InterceptableHtlcForwarder interface {
|
|||||||
// and resolve it later or let the switch execute its default behavior.
|
// and resolve it later or let the switch execute its default behavior.
|
||||||
type ForwardInterceptor func(InterceptedForward) bool
|
type ForwardInterceptor func(InterceptedForward) bool
|
||||||
|
|
||||||
|
// InterceptedPacket contains the relevant information for the interceptor about
|
||||||
|
// an htlc.
|
||||||
|
type InterceptedPacket struct {
|
||||||
|
// IncomingCircuit contains the incoming channel and htlc id of the
|
||||||
|
// packet.
|
||||||
|
IncomingCircuit channeldb.CircuitKey
|
||||||
|
|
||||||
|
// Hash is the payment hash of the htlc.
|
||||||
|
Hash lntypes.Hash
|
||||||
|
|
||||||
|
// OutgoingExpiry is the absolute block height at which the outgoing
|
||||||
|
// htlc expires.
|
||||||
|
OutgoingExpiry uint32
|
||||||
|
|
||||||
|
// OutgoingAmount is the amount to forward.
|
||||||
|
OutgoingAmount lnwire.MilliSatoshi
|
||||||
|
}
|
||||||
|
|
||||||
// InterceptedForward is passed to the ForwardInterceptor for every forwarded
|
// InterceptedForward is passed to the ForwardInterceptor for every forwarded
|
||||||
// htlc. It contains all the information about the packet which accordingly
|
// htlc. It contains all the information about the packet which accordingly
|
||||||
// the interceptor decides if to hold or not.
|
// the interceptor decides if to hold or not.
|
||||||
// In addition this interface allows a later resolution by calling either
|
// In addition this interface allows a later resolution by calling either
|
||||||
// Resume, Settle or Fail.
|
// Resume, Settle or Fail.
|
||||||
type InterceptedForward interface {
|
type InterceptedForward interface {
|
||||||
// CircuitKey returns the intercepted packet.
|
|
||||||
CircuitKey() channeldb.CircuitKey
|
|
||||||
|
|
||||||
// Packet returns the intercepted packet.
|
// Packet returns the intercepted packet.
|
||||||
Packet() lnwire.UpdateAddHTLC
|
Packet() InterceptedPacket
|
||||||
|
|
||||||
// Resume notifies the intention to resume an existing hold forward. This
|
// Resume notifies the intention to resume an existing hold forward. This
|
||||||
// basically means the caller wants to resume with the default behavior for
|
// basically means the caller wants to resume with the default behavior for
|
||||||
|
@ -148,18 +148,18 @@ func (r *forwardInterceptor) holdAndForwardToClient(
|
|||||||
forward htlcswitch.InterceptedForward) error {
|
forward htlcswitch.InterceptedForward) error {
|
||||||
|
|
||||||
htlc := forward.Packet()
|
htlc := forward.Packet()
|
||||||
inKey := forward.CircuitKey()
|
inKey := htlc.IncomingCircuit
|
||||||
|
|
||||||
// First hold the forward, then send to client.
|
// First hold the forward, then send to client.
|
||||||
r.holdForwards[forward.CircuitKey()] = forward
|
r.holdForwards[inKey] = forward
|
||||||
interceptionRequest := &ForwardHtlcInterceptRequest{
|
interceptionRequest := &ForwardHtlcInterceptRequest{
|
||||||
IncomingCircuitKey: &CircuitKey{
|
IncomingCircuitKey: &CircuitKey{
|
||||||
ChanId: inKey.ChanID.ToUint64(),
|
ChanId: inKey.ChanID.ToUint64(),
|
||||||
HtlcId: inKey.HtlcID,
|
HtlcId: inKey.HtlcID,
|
||||||
},
|
},
|
||||||
PaymentHash: htlc.PaymentHash[:],
|
PaymentHash: htlc.Hash[:],
|
||||||
OutgoingAmountMsat: uint64(htlc.Amount),
|
OutgoingAmountMsat: uint64(htlc.OutgoingAmount),
|
||||||
OutgoingExpiry: htlc.Expiry,
|
OutgoingExpiry: htlc.OutgoingExpiry,
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.stream.Send(interceptionRequest)
|
return r.stream.Send(interceptionRequest)
|
||||||
|
Loading…
Reference in New Issue
Block a user