lnd: finish Quiesce implementation using new link op
This commit is contained in:
1 file changed
+19
-5
@@ -18,8 +18,10 @@ import (
|
|||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||||
@@ -60,6 +62,7 @@ type ServerShell struct {
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
started int32 // To be used atomically.
|
started int32 // To be used atomically.
|
||||||
shutdown int32 // To be used atomically.
|
shutdown int32 // To be used atomically.
|
||||||
|
quit chan struct{}
|
||||||
|
|
||||||
// Required by the grpc-gateway/v2 library for forward compatibility.
|
// Required by the grpc-gateway/v2 library for forward compatibility.
|
||||||
// Must be after the atomically used variables to not break struct
|
// Must be after the atomically used variables to not break struct
|
||||||
@@ -82,7 +85,8 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
// We don't create any new macaroons for this subserver, instead reuse
|
// We don't create any new macaroons for this subserver, instead reuse
|
||||||
// existing onchain/offchain permissions.
|
// existing onchain/offchain permissions.
|
||||||
server := &Server{
|
server := &Server{
|
||||||
cfg: cfg,
|
quit: make(chan struct{}),
|
||||||
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return server, macPermissions, nil
|
return server, macPermissions, nil
|
||||||
@@ -107,6 +111,8 @@ func (s *Server) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(s.quit)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,12 +365,20 @@ func (s *Server) Quiesce(_ context.Context, in *QuiescenceRequest) (
|
|||||||
|
|
||||||
op := wire.NewOutPoint(txid, in.ChanId.OutputIndex)
|
op := wire.NewOutPoint(txid, in.ChanId.OutputIndex)
|
||||||
cid := lnwire.NewChanIDFromOutPoint(*op)
|
cid := lnwire.NewChanIDFromOutPoint(*op)
|
||||||
_, err = s.cfg.Switch.GetLink(cid)
|
ln, err := s.cfg.Switch.GetLink(cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(proofofkeags): Add Link operation for initiating quiescence and
|
select {
|
||||||
// implement the rest of this in those terms
|
case result := <-ln.InitStfu():
|
||||||
return nil, fmt.Errorf("TODO(proofofkeags): Implement")
|
mkResp := func(b lntypes.ChannelParty) *QuiescenceResponse {
|
||||||
|
return &QuiescenceResponse{Initiator: b.IsLocal()}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fn.MapOk(mkResp)(result).Unpack()
|
||||||
|
|
||||||
|
case <-s.quit:
|
||||||
|
return nil, fmt.Errorf("server shutting down")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user