Skip to content

Commit 36513aa

Browse files
committed
config+itest: move custom message override
It turns out the custom message override that should've allowed tapd to send custom p2p wire messages never worked, because we set the value after calling into lnd.ValidateConfig() which actually injects the value into the lnwire package. We now move the code and also create an itest for it (we should be able to try funding multiple times after each other, as each attempt should be cleaned up by the receiver when they receive the error message).
1 parent 340f5c0 commit 36513aa

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,6 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
400400
cfg.Lnd.RPCMiddleware.Enable = true
401401
}
402402

403-
// For the integration of tapd with lnd, we need to allow tapd to send
404-
// custom error messages to peers through the SendCustomMessage RPC in
405-
// lnd. Since the error messages aren't in the custom range, we
406-
// explicitly need to allow them. This isn't currently needed in remote
407-
// mode, because custom channels are only available if both lnd and tapd
408-
// are running in integrated mode.
409-
if !cfg.lndRemote {
410-
cfg.Lnd.ProtocolOptions.CustomMessage = append(
411-
cfg.Lnd.ProtocolOptions.CustomMessage,
412-
lnwire.MsgError,
413-
)
414-
}
415-
416403
// Validate the lightning-terminal config options.
417404
litDir := lnd.CleanAndExpandPath(preCfg.LitDir)
418405
cfg.LetsEncryptDir = lncfg.CleanAndExpandPath(cfg.LetsEncryptDir)
@@ -620,6 +607,19 @@ func loadConfigFile(preCfg *Config, interceptor signal.Interceptor) (*Config,
620607
// configuration is fully valid. This also sets up the main logger that
621608
// logs to a sub-directory in the .lnd folder.
622609
case ModeIntegrated:
610+
// For the integration of tapd with lnd, we need to allow tapd
611+
// to send custom error messages to peers through the
612+
// SendCustomMessage RPC in lnd. Since the error messages aren't
613+
// in the custom range, we explicitly need to allow them. This
614+
// isn't currently needed in remote mode, because custom
615+
// channels are only available if both lnd and tapd are running
616+
// in integrated mode. We need to set this value before we call
617+
// lnd.ValidateConfig() below, because that's what's going to
618+
// inject these values into the lnwire package.
619+
cfg.Lnd.ProtocolOptions.CustomMessage = append(
620+
cfg.Lnd.ProtocolOptions.CustomMessage, lnwire.MsgError,
621+
)
622+
623623
var err error
624624
cfg.Lnd, err = lnd.ValidateConfig(
625625
*cfg.Lnd, interceptor, fileParser, flagParser,

itest/litd_custom_channels_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"time"
88

9+
"github.com/btcsuite/btcd/btcutil"
910
"github.com/btcsuite/btcd/chaincfg/chainhash"
1011
"github.com/lightninglabs/taproot-assets/itest"
1112
"github.com/lightninglabs/taproot-assets/proof"
@@ -1160,6 +1161,36 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
11601161
syncUniverses(t.t, charlieTap, dave)
11611162
t.Logf("Universes synced between all nodes, distributing assets...")
11621163

1164+
// Before we actually create the asset channel, we want to make sure
1165+
// that failed attempts of creating a channel (e.g. due to insufficient
1166+
// on-chain funds) are cleaned up properly on the recipient side.
1167+
// We do this by sending all of Charlie's coins to a burn address then
1168+
// just sending him 50k sats, which isn't enough to fund a channel.
1169+
_, err = charlie.LightningClient.SendCoins(
1170+
ctxb, &lnrpc.SendCoinsRequest{
1171+
Addr: burnAddr,
1172+
SendAll: true,
1173+
MinConfs: 0,
1174+
SpendUnconfirmed: true,
1175+
},
1176+
)
1177+
require.NoError(t.t, err)
1178+
net.SendCoins(t.t, 50_000, charlie)
1179+
1180+
// The attempt should fail. But the recipient should receive the error,
1181+
// clean up the state and allow Charlie to try again after acquiring
1182+
// more funds.
1183+
_, err = charlieTap.FundChannel(ctxb, &tchrpc.FundChannelRequest{
1184+
AssetAmount: fundingAmount,
1185+
AssetId: assetID,
1186+
PeerPubkey: dave.PubKey[:],
1187+
FeeRateSatPerVbyte: 5,
1188+
})
1189+
require.ErrorContains(t.t, err, "not enough witness outputs to create")
1190+
1191+
// Now we'll fund the channel with the correct amount.
1192+
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, charlie)
1193+
11631194
// Next we can open an asset channel from Charlie -> Dave, then kick
11641195
// off the main scenario.
11651196
t.Logf("Opening asset channels...")

0 commit comments

Comments
 (0)