mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
Merge pull request #4693 from joostjager/listchannels-circuits
lnrpc: expose linked htlcs in ListChannels
This commit is contained in:
commit
4adb8123af
@ -63,6 +63,18 @@ type CircuitModifier interface {
|
||||
DeleteCircuits(inKeys ...CircuitKey) error
|
||||
}
|
||||
|
||||
// CircuitLookup is a common interface used to lookup information that is stored
|
||||
// in the circuit map.
|
||||
type CircuitLookup interface {
|
||||
// LookupCircuit queries the circuit map for the circuit identified by
|
||||
// inKey.
|
||||
LookupCircuit(inKey CircuitKey) *PaymentCircuit
|
||||
|
||||
// LookupOpenCircuit queries the circuit map for a circuit identified
|
||||
// by its outgoing circuit key.
|
||||
LookupOpenCircuit(outKey CircuitKey) *PaymentCircuit
|
||||
}
|
||||
|
||||
// CircuitFwdActions represents the forwarding decision made by the circuit
|
||||
// map, and is returned from CommitCircuits. The sequence of circuits provided
|
||||
// to CommitCircuits is split into three sub-sequences, allowing the caller to
|
||||
@ -87,6 +99,8 @@ type CircuitFwdActions struct {
|
||||
type CircuitMap interface {
|
||||
CircuitModifier
|
||||
|
||||
CircuitLookup
|
||||
|
||||
// CommitCircuits attempts to add the given circuits to the circuit
|
||||
// map. The list of circuits is split into three distinct
|
||||
// sub-sequences, corresponding to adds, drops, and fails. Adds should
|
||||
@ -104,14 +118,6 @@ type CircuitMap interface {
|
||||
// settles/fails from being accepted for the same circuit.
|
||||
FailCircuit(inKey CircuitKey) (*PaymentCircuit, error)
|
||||
|
||||
// LookupCircuit queries the circuit map for the circuit identified by
|
||||
// inKey.
|
||||
LookupCircuit(inKey CircuitKey) *PaymentCircuit
|
||||
|
||||
// LookupOpenCircuit queries the circuit map for a circuit identified
|
||||
// by its outgoing circuit key.
|
||||
LookupOpenCircuit(outKey CircuitKey) *PaymentCircuit
|
||||
|
||||
// LookupByPaymentHash queries the circuit map and returns all open
|
||||
// circuits that use the given payment hash.
|
||||
LookupByPaymentHash(hash [32]byte) []*PaymentCircuit
|
||||
|
@ -2186,6 +2186,12 @@ func (s *Switch) CircuitModifier() CircuitModifier {
|
||||
return s.circuits
|
||||
}
|
||||
|
||||
// CircuitLookup returns a reference to subset of the interfaces provided by the
|
||||
// circuit map, to allow looking up circuits.
|
||||
func (s *Switch) CircuitLookup() CircuitLookup {
|
||||
return s.circuits
|
||||
}
|
||||
|
||||
// commitCircuits persistently adds a circuit to the switch's circuit map.
|
||||
func (s *Switch) commitCircuits(circuits ...*PaymentCircuit) (
|
||||
*CircuitFwdActions, error) {
|
||||
|
1564
lnrpc/rpc.pb.go
1564
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -1006,6 +1006,21 @@ message HTLC {
|
||||
int64 amount = 2;
|
||||
bytes hash_lock = 3;
|
||||
uint32 expiration_height = 4;
|
||||
|
||||
// Index identifying the htlc on the channel.
|
||||
uint64 htlc_index = 5;
|
||||
|
||||
// If this HTLC is involved in a forwarding operation, this field indicates
|
||||
// the forwarding channel. For an outgoing htlc, it is the incoming channel.
|
||||
// For an incoming htlc, it is the outgoing channel. When the htlc
|
||||
// originates from this node or this node is the final destination,
|
||||
// forwarding_channel will be zero. The forwarding channel will also be zero
|
||||
// for htlcs that need to be forwarded but don't have a forwarding decision
|
||||
// persisted yet.
|
||||
uint64 forwarding_channel = 6;
|
||||
|
||||
// Index identifying the htlc on the forwarding channel.
|
||||
uint64 forwarding_htlc_index = 7;
|
||||
}
|
||||
|
||||
enum CommitmentType {
|
||||
|
@ -3813,6 +3813,21 @@
|
||||
"expiration_height": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"htlc_index": {
|
||||
"type": "string",
|
||||
"format": "uint64",
|
||||
"description": "Index identifying the htlc on the channel."
|
||||
},
|
||||
"forwarding_channel": {
|
||||
"type": "string",
|
||||
"format": "uint64",
|
||||
"description": "If this HTLC is involved in a forwarding operation, this field indicates\nthe forwarding channel. For an outgoing htlc, it is the incoming channel.\nFor an incoming htlc, it is the outgoing channel. When the htlc\noriginates from this node or this node is the final destination,\nforwarding_channel will be zero. The forwarding channel will also be zero\nfor htlcs that need to be forwarded but don't have a forwarding decision\npersisted yet."
|
||||
},
|
||||
"forwarding_htlc_index": {
|
||||
"type": "string",
|
||||
"format": "uint64",
|
||||
"description": "Index identifying the htlc on the forwarding channel."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
52
rpcserver.go
52
rpcserver.go
@ -42,6 +42,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
@ -3572,11 +3573,54 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
|
||||
for i, htlc := range localCommit.Htlcs {
|
||||
var rHash [32]byte
|
||||
copy(rHash[:], htlc.RHash[:])
|
||||
|
||||
circuitMap := r.server.htlcSwitch.CircuitLookup()
|
||||
|
||||
var forwardingChannel, forwardingHtlcIndex uint64
|
||||
switch {
|
||||
case htlc.Incoming:
|
||||
circuit := circuitMap.LookupCircuit(
|
||||
htlcswitch.CircuitKey{
|
||||
ChanID: dbChannel.ShortChannelID,
|
||||
HtlcID: htlc.HtlcIndex,
|
||||
},
|
||||
)
|
||||
if circuit != nil && circuit.Outgoing != nil {
|
||||
forwardingChannel = circuit.Outgoing.ChanID.
|
||||
ToUint64()
|
||||
|
||||
forwardingHtlcIndex = circuit.Outgoing.HtlcID
|
||||
}
|
||||
|
||||
case !htlc.Incoming:
|
||||
circuit := circuitMap.LookupOpenCircuit(
|
||||
htlcswitch.CircuitKey{
|
||||
ChanID: dbChannel.ShortChannelID,
|
||||
HtlcID: htlc.HtlcIndex,
|
||||
},
|
||||
)
|
||||
|
||||
// If the incoming channel id is the special hop.Source
|
||||
// value, the htlc index is a local payment identifier.
|
||||
// In this case, report nothing.
|
||||
if circuit != nil &&
|
||||
circuit.Incoming.ChanID != hop.Source {
|
||||
|
||||
forwardingChannel = circuit.Incoming.ChanID.
|
||||
ToUint64()
|
||||
|
||||
forwardingHtlcIndex = circuit.Incoming.HtlcID
|
||||
}
|
||||
}
|
||||
|
||||
channel.PendingHtlcs[i] = &lnrpc.HTLC{
|
||||
Incoming: htlc.Incoming,
|
||||
Amount: int64(htlc.Amt.ToSatoshis()),
|
||||
HashLock: rHash[:],
|
||||
ExpirationHeight: htlc.RefundTimeout,
|
||||
Incoming: htlc.Incoming,
|
||||
Amount: int64(htlc.Amt.ToSatoshis()),
|
||||
HashLock: rHash[:],
|
||||
ExpirationHeight: htlc.RefundTimeout,
|
||||
HtlcIndex: htlc.HtlcIndex,
|
||||
ForwardingChannel: forwardingChannel,
|
||||
ForwardingHtlcIndex: forwardingHtlcIndex,
|
||||
}
|
||||
|
||||
// Add the Pending Htlc Amount to UnsettledBalance field.
|
||||
|
Loading…
Reference in New Issue
Block a user