Skip to content

Commit

Permalink
cln+lnd: liveness check on swapout
Browse files Browse the repository at this point in the history
This change causes the liquid daemon to be monitored
for dead or alive at the start of the swapout execution.
Previously, at the start of a swapout,
it would succeed even if the liquid daemon was not running,
If a subsequent process required the liquid daemon,
 an error would occur.

In addition, cross-checking by interceptors and hooks
 has been discontinued.
This is because hooks by glightning are unstable and currently only
 swapout needs to be monitored for life and death.
  • Loading branch information
YusukeShimizu committed Jun 16, 2024
1 parent 1d98fe2 commit cd24c35
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
20 changes: 0 additions & 20 deletions clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func NewClightningClient(ctx context.Context) (*ClightningClient, <-chan interfa
cl.Plugin = glightning.NewPlugin(cl.onInit)
err := cl.Plugin.RegisterHooks(&glightning.Hooks{
CustomMsgReceived: cl.OnCustomMsg,
RpcCommand: cl.OnRPCCommand,
})
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -413,25 +412,6 @@ type Message struct {
Message string `json:"message"`
}

func (cl *ClightningClient) OnRPCCommand(event *glightning.RpcCommandEvent) (*glightning.RpcCommandResponse, error) {
if cl.gbitcoin != nil {
ok, err := cl.gbitcoin.Ping()
if err != nil || !ok {
log.Infof("trying to send command %s, but failed to connect: %v", event.Cmd.MethodName, err)
return event.ReturnError("bitcoin_unavailable", -1)
}
}

if cl.liquidWallet != nil {
ok, err := cl.liquidWallet.Ping()
if err != nil || !ok {
log.Infof("trying to send command %s, but failed to connect: %v", event.Cmd.MethodName, err)
return event.ReturnError("liquid_unavailable", -1)
}
}
return event.Continue(), nil
}

// AddMessageHandler adds a listener for incoming peermessages
func (cl *ClightningClient) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error) {
cl.msgHandlers = append(cl.msgHandlers, f)
Expand Down
3 changes: 3 additions & 0 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ func (l *SwapOut) Call() (jrpc2.Result, error) {
if !l.cl.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if ok, perr := l.cl.liquidWallet.Ping(); perr != nil || !ok {
return nil, fmt.Errorf("liquid wallet not reachable: %v", perr)
}

} else if strings.Compare(l.Asset, "btc") == 0 {
if !l.cl.swaps.BitcoinEnabled {
Expand Down
21 changes: 1 addition & 20 deletions cmd/peerswaplnd/peerswapd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ func run() error {
}
defer lis.Close()

grpcSrv := grpc.NewServer(
grpc.UnaryInterceptor(livenessCheckInterceptor(liquidRpcWallet)),
)
grpcSrv := grpc.NewServer()

peerswaprpc.RegisterPeerSwapServer(grpcSrv, peerswaprpcServer)

Expand Down Expand Up @@ -441,23 +439,6 @@ func run() error {
return nil
}

func livenessCheckInterceptor(liquidWallet wallet.Wallet) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
if liquidWallet != nil {
ok, err := liquidWallet.Ping()
if err != nil {
log.Infof("trying to send command %s, but failed to connect: %v", info.FullMethod, err)
return nil, fmt.Errorf("liquid backend not reachable: %v", err)
}
if !ok {
log.Infof("trying to send command %s, but failed to connect", info.FullMethod)
return nil, errors.New("liquid backend not reachable")
}
}
return handler(ctx, req)
}
}

func getBitcoinChain(ctx context.Context, li lnrpc.LightningClient) (*chaincfg.Params, error) {
gi, err := li.GetInfo(ctx, &lnrpc.GetInfoRequest{})
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions peerswaprpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (p *PeerswapServer) SwapOut(ctx context.Context, request *SwapOutRequest) (
if !p.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if ok, perr := p.liquidWallet.Ping(); perr != nil || !ok {
return nil, fmt.Errorf("liquid wallet not reachable: %v", perr)
}

} else if strings.Compare(request.Asset, "btc") == 0 {
if !p.swaps.BitcoinEnabled {
Expand Down

0 comments on commit cd24c35

Please sign in to comment.