lnd: rpcServer now asynchronously handles bi-di sendpayment streams
This commit is contained in:
parent
979b43a3b8
commit
35bca369e7
16
rpcserver.go
16
rpcserver.go
@ -426,7 +426,12 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
// bi-directional stream allowing clients to rapidly send payments through the
|
// bi-directional stream allowing clients to rapidly send payments through the
|
||||||
// Lightning Network with a single persistent connection.
|
// Lightning Network with a single persistent connection.
|
||||||
func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer) error {
|
func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer) error {
|
||||||
|
errChan := make(chan error, 1)
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case err := <-errChan:
|
||||||
|
return err
|
||||||
|
default:
|
||||||
// Receive the next pending payment within the stream sent by
|
// Receive the next pending payment within the stream sent by
|
||||||
// the client. If we read the EOF sentinel, then the client has
|
// the client. If we read the EOF sentinel, then the client has
|
||||||
// closed the stream, and we can exit normally.
|
// closed the stream, and we can exit normally.
|
||||||
@ -453,18 +458,25 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer)
|
|||||||
msg: htlcAdd,
|
msg: htlcAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): semaphore to limit num outstanding
|
||||||
|
// goroutines.
|
||||||
|
go func() {
|
||||||
// Finally, send this next packet to the routing layer in order
|
// Finally, send this next packet to the routing layer in order
|
||||||
// to complete the next payment.
|
// to complete the next payment.
|
||||||
// TODO(roasbeef): this should go through the L3 router once
|
// TODO(roasbeef): this should go through the L3 router once
|
||||||
// multi-hop is in place.
|
// multi-hop is in place.
|
||||||
if err := r.server.htlcSwitch.SendHTLC(htlcPkt); err != nil {
|
if err := r.server.htlcSwitch.SendHTLC(htlcPkt); err != nil {
|
||||||
return err
|
errChan <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): proper responses
|
// TODO(roasbeef): proper responses
|
||||||
resp := &lnrpc.SendResponse{}
|
resp := &lnrpc.SendResponse{}
|
||||||
if err := paymentStream.Send(resp); err != nil {
|
if err := paymentStream.Send(resp); err != nil {
|
||||||
return err
|
errChan <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user