Skip to content

Commit

Permalink
test: force fee update
Browse files Browse the repository at this point in the history
This is a response to the fact that since v23.11+ of cln,
it is now possible to detect stuck channels
in the GetRoute phase.
The fee rate can be updated to make
a channel stuck after it has been opened.
  • Loading branch information
YusukeShimizu committed Jan 15, 2024
1 parent 4d1270b commit d0bb524
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion test/bitcoin_cln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ func Test_ClnCln_StuckChannels(t *testing.T) {
require := require.New(t)
// repro by using the push_msat in the open_channel.
// Assumption that feperkw is 253perkw in reg test.
bitcoind, lightningds, scid := clnclnSetupWithConfig(t, 3794, 3573, []string{
bitcoind, lightningds, scid := clnclnSetupWithConfig(t, 37500, 35315, []string{
"--dev-bitcoind-poll=1",
"--dev-fast-gossip",
"--large-channels",
Expand Down Expand Up @@ -1210,6 +1210,10 @@ func Test_ClnCln_StuckChannels(t *testing.T) {
swapType: swap.SWAPTYPE_IN,
}

assert.NoError(t, lightningds[0].ForceFeeUpdate(scid, "2530"))
assert.NoError(t, testframework.WaitForWithErr(func() (bool, error) {
return lightningds[1].IsChannelActive(scid)
}, testframework.TIMEOUT))
// Swap in should fail by probing payment as the channel is stuck.
var response map[string]interface{}
err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: 100, ShortChannelId: params.scid, Asset: "btc"}, &response)
Expand Down
28 changes: 27 additions & 1 deletion testframework/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (n *CLightningNode) IsChannelActive(scid string) (bool, error) {

for _, ch := range funds.Channels {
if ch.ShortChannelId == scid {
return ch.State == "CHANNELD_NORMAL", nil
return ch.State == "CHANNELD_NORMAL" && ch.Connected, nil
}
}

Expand Down Expand Up @@ -569,3 +569,29 @@ func (n *CLightningNode) SetHtlcMaximumMilliSatoshis(scid string, maxHtlcMsat ui
}
return maxHtlcMsat, err
}

// ForceFeeUpdate force a fee update by restarting the node with the new feerate.
// Up to 5 values, separated by '/' can be provided for feerates
// if fewer are provided, then the final value is used for the
// remainder. The values are in per-kw (roughly 1/4 of bitcoind's per-kb
// values), and the order is "opening", "mutual_close", "unilateral_close",
// "delayed_to_us", "htlc_resolution", and "penalty".
// ref: https://docs.corelightning.org/reference/lightningd-config
func (n *CLightningNode) ForceFeeUpdate(scid, feerates string) error {
err := n.Stop()
if err != nil {
return err
}
n.AppendCmdLine([]string{fmt.Sprintf("--force-feerates=%s", feerates)})
err = n.Run(true, true)
if err != nil {
return err
}
err = n.WaitForLog("peerswap initialized", TIMEOUT)
if err != nil {
return err
}
return WaitForWithErr(func() (bool, error) {
return n.IsChannelActive(scid)
}, TIMEOUT)
}

0 comments on commit d0bb524

Please sign in to comment.