Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clightning: add shutdown hook for plugin #318

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func NewClightningClient(ctx context.Context) (*ClightningClient, <-chan interfa
return nil, nil, err
}
cl.Plugin.SubscribeConnect(cl.OnConnect)
cl.Plugin.SubscribeShutdown(cl.OnShutdown)

cl.glightning = glightning.NewLightning()
cl.glightning.SetTimeout(40)
Expand Down Expand Up @@ -352,7 +353,7 @@ func (cl *ClightningClient) SetPeerswapConfig(config *Config) {
LiquidRpcHost: config.Liquid.RpcHost,
LiquidRpcPort: config.Liquid.RpcPort,
LiquidRpcWallet: config.Liquid.RpcWallet,
LiquidSwaps: *config.Liquid.LiquidSwaps,
LiquidSwaps: *config.Liquid.LiquidSwaps,
PeerswapDir: config.PeerswapDir,
}
if config.LWK != nil {
Expand Down Expand Up @@ -547,6 +548,10 @@ func (cl *ClightningClient) OnConnect(connectEvent *glightning.ConnectEvent) {
}()
}

func (cl *ClightningClient) OnShutdown() {
cl.Plugin.Stop()
}

// RegisterMethods registeres rpc methods to c-lightning
func (cl *ClightningClient) RegisterMethods() error {
for _, v := range methods {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/btcsuite/btcd/btcutil/psbt v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a
github.com/elementsproject/glightning v0.0.0-20241118233744-055205379e1d
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
github.com/jessevdk/go-flags v1.5.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6 h1:sE4tvxWw01v7K3M
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a h1:xnVQmVqGmSs3m8zPQF4iYEYiUAmJx8MlT9vJ3lAaOjc=
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/elementsproject/glightning v0.0.0-20240922021749-3b572176aa14 h1:Q23txNJKtdTSXDoN4wF72bopQ0F0RyEkWL3nnoxfV/w=
github.com/elementsproject/glightning v0.0.0-20240922021749-3b572176aa14/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/elementsproject/glightning v0.0.0-20241118233744-055205379e1d h1:FVMwlIlOdhe4/eORWS8Gu9M+BtZscx0X6Qg6aeRzMWs=
github.com/elementsproject/glightning v0.0.0-20241118233744-055205379e1d/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
30 changes: 30 additions & 0 deletions test/bitcoin_cln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,3 +1218,33 @@ func Test_ClnCln_StuckChannels(t *testing.T) {
err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: 100, ShortChannelId: params.scid, Asset: "btc"}, &response)
assert.Error(t, err)
}

func Test_Cln_shutdown(t *testing.T) {
IsIntegrationTest(t)
t.Parallel()
require := require.New(t)
bitcoind, lightningds, _ := clnclnSetup(t, uint64(math.Pow10(9)))
defer func() {
if t.Failed() {
filter := os.Getenv("PEERSWAP_TEST_FILTER")
pprintFail(
tailableProcess{
p: bitcoind.DaemonProcess,
lines: defaultLines,
},
tailableProcess{
p: lightningds[0].DaemonProcess,
filter: filter,
lines: defaultLines,
},
tailableProcess{
p: lightningds[1].DaemonProcess,
lines: defaultLines,
},
)
}
}()
lightningds[0].Shutdown()
require.NoError(lightningds[0].WaitForLog(
"plugin-peerswap: Killing plugin: exited during normal operation", 30))
}
Loading