Skip to content

Commit b16ecd9

Browse files
authored
Merge pull request #1074 from lightninglabs/backward-compat-itest
custom channels: add itest to demonstrate that backward compatibility with v0.14.1-alpha is restored
2 parents c99f2dc + ac33a2a commit b16ecd9

13 files changed

+273
-49
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ jobs:
279279
matrix:
280280
include:
281281
- name: bbolt
282-
args: itest icase=terminal dbbackend=bbolt
282+
args: itest-no-backward-compat icase=terminal dbbackend=bbolt
283283
- name: sqlite
284-
args: itest icase=terminal dbbackend=sqlite
284+
args: itest-no-backward-compat icase=terminal dbbackend=sqlite
285285
- name: postgres
286-
args: itest icase=terminal dbbackend=postgres
286+
args: itest-no-backward-compat icase=terminal dbbackend=postgres
287287
- name: custom-channels
288288
args: itest-only icase=custom_channels
289289

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ litcli-debug
99
.DS_Store
1010

1111
itest/btcd-itest
12-
itest/litd-itest
12+
itest/litd-itest*
1313
itest/lnd-itest
1414
itest/itest.test
1515
itest/.logs
1616
itest/*.log
17+
itest/backward-compat
1718

1819
vendor
1920
*.idea

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ PUBLIC_URL :=
2424
# versions are checked against this version.
2525
GO_VERSION = 1.23.6
2626

27+
# LITD_COMPAT_VERSIONS is a space-separated list of litd versions that are
28+
# installed before running the integration tests which include backward
29+
# compatibility tests. The list of versions must be in sync with any version
30+
# used in the backwardCompat map in itest/litd_test_list_on_test.go.
31+
LITD_COMPAT_VERSIONS = v0.14.1-alpha
32+
2733
LOOP_COMMIT := $(shell cat go.mod | \
2834
grep $(LOOP_PKG) | \
2935
head -n1 | \
@@ -233,7 +239,11 @@ build-itest:
233239
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/btcd-itest -ldflags "$(ITEST_LDFLAGS)" $(BTCD_PKG)
234240
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/lnd-itest -ldflags "$(ITEST_LDFLAGS)" $(LND_PKG)/cmd/lnd
235241

236-
itest-only: build-itest
242+
install-backward-compat-versions:
243+
@$(call print, "Installing old versions of litd for backward compatibility tests.")
244+
scripts/install-backward-compat-versions.sh '$(LITD_COMPAT_VERSIONS)'
245+
246+
run-itest-only:
237247
@$(call print, "Building itest binary.")
238248
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/litd-itest -ldflags "$(ITEST_LDFLAGS)" $(PKG)/cmd/litd
239249
CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(ITEST_TAGS)" -c -o itest/itest.test
@@ -242,8 +252,12 @@ itest-only: build-itest
242252
rm -rf itest/*.log itest/.logs*; date
243253
scripts/itest_part.sh $(ITEST_FLAGS)
244254

255+
itest-only: build-itest install-backward-compat-versions run-itest-only
256+
245257
itest: app-build build-itest itest-only
246258

259+
itest-no-backward-compat: app-build build-itest build-itest run-itest-only
260+
247261
# =============
248262
# FLAKE HUNTING
249263
# =============

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/lightninglabs/pool v0.6.5-beta.0.20250305125211-4e860ec4e77f
3030
github.com/lightninglabs/pool/auctioneerrpc v1.1.3-0.20250305125211-4e860ec4e77f
3131
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f
32-
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515090148-95af3680134e
32+
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515215758-1660f9ccd5d4
3333
github.com/lightninglabs/taproot-assets/taprpc v1.0.3
3434
github.com/lightningnetwork/lnd v0.19.0-beta.rc3
3535
github.com/lightningnetwork/lnd/cert v1.2.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f h1:5p
506506
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f/go.mod h1:lGs2hSVZ+GFpdv3btaIl9icG5/gz7BBRfvmD2iqqNl0=
507507
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
508508
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
509-
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515090148-95af3680134e h1:l6UObl0hucKdrfdla/FC+UWON9v2VfrN3BTtHnUySo4=
510-
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515090148-95af3680134e/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
509+
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515215758-1660f9ccd5d4 h1:GOqIfTRyMRQBioFXBqL757nWXMeaHrK9Hh9HVKK8Pg0=
510+
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250515215758-1660f9ccd5d4/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
511511
github.com/lightninglabs/taproot-assets/taprpc v1.0.3 h1:Vt9vKNwAFGfJ/I29C1gSEwD0pcNeI53pFRCPf/WBgHI=
512512
github.com/lightninglabs/taproot-assets/taprpc v1.0.3/go.mod h1:Ccq0t2GsXzOtC8qF0U1ux/yTF5HcBbVrhCb0tb/jObM=
513513
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=

itest/assets_test.go

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,20 @@ func createTestAssetNetwork(t *harnessTest, net *NetworkHarness, charlieTap,
207207
erinAssetBalance := assetSendAmount - erinFundingAmount
208208

209209
// Assert that we see the funding outputs in the wallet.
210-
itest.AssertBalances(
210+
assertBalance(
211211
t.t, charlieTap, charlieFundingAmount,
212212
itest.WithAssetID(assetID),
213213
itest.WithScriptKeyType(asset.ScriptKeyScriptPathChannel),
214214
itest.WithNumUtxos(1),
215215
itest.WithScriptKey(fundingScriptKeyBytes),
216216
)
217-
itest.AssertBalances(
217+
assertBalance(
218218
t.t, daveTap, daveFundingAmount, itest.WithAssetID(assetID),
219219
itest.WithScriptKeyType(asset.ScriptKeyScriptPathChannel),
220220
itest.WithNumUtxos(1),
221221
itest.WithScriptKey(fundingScriptKeyBytes),
222222
)
223-
itest.AssertBalances(
223+
assertBalance(
224224
t.t, erinTap, erinFundingAmount, itest.WithAssetID(assetID),
225225
itest.WithScriptKeyType(asset.ScriptKeyScriptPathChannel),
226226
itest.WithNumUtxos(1),
@@ -229,14 +229,13 @@ func createTestAssetNetwork(t *harnessTest, net *NetworkHarness, charlieTap,
229229

230230
// After opening the channels, the asset balance of the funding nodes
231231
// should have been decreased with the funding amount.
232-
itest.AssertBalances(
233-
t.t, charlieTap, charlieAssetBalance,
234-
itest.WithAssetID(assetID),
232+
assertBalance(
233+
t.t, charlieTap, charlieAssetBalance, itest.WithAssetID(assetID),
235234
)
236-
itest.AssertBalances(
235+
assertBalance(
237236
t.t, daveTap, daveAssetBalance, itest.WithAssetID(assetID),
238237
)
239-
itest.AssertBalances(
238+
assertBalance(
240239
t.t, erinTap, erinAssetBalance, itest.WithAssetID(assetID),
241240
)
242241

@@ -527,6 +526,18 @@ func createTestAssetNetworkGroupKey(ctx context.Context, t *harnessTest,
527526
return chanPointCD, chanPointEF
528527
}
529528

529+
// assertBalance is a thin wrapper around itest.AssertBalances that skips the
530+
// balance check for old versions during the backward compatibility test.
531+
func assertBalance(t *testing.T, client *tapClient, balance uint64,
532+
opts ...itest.BalanceOption) {
533+
534+
if client.node.Cfg.SkipBalanceChecks {
535+
return
536+
}
537+
538+
itest.AssertBalances(t, client, balance, opts...)
539+
}
540+
530541
// sendAssetsAndAssert sends the given amount of assets to the recipient and
531542
// asserts that the transfer was successful. It also checks that the asset
532543
// balance of the sender and recipient is as expected.
@@ -718,6 +729,12 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
718729
require.NoError(t, err)
719730
require.Len(t, pendingChannelsResp.PendingOpenChannels, numChannels)
720731

732+
// For older versions (during the backward compatibility test), if the
733+
// channel custom data is in the old format, we can't do further checks.
734+
if node.Cfg.OldChannelFormat {
735+
return
736+
}
737+
721738
pendingChan := pendingChannelsResp.PendingOpenChannels[0]
722739
var pendingJSON rfqmsg.JsonAssetChannel
723740
err = json.Unmarshal(
@@ -768,6 +785,12 @@ func haveFundingAsset(assetChannel *rfqmsg.JsonAssetChannel,
768785
func assertAssetChan(t *testing.T, src, dst *HarnessNode, fundingAmount uint64,
769786
channelAssets []*taprpc.Asset) {
770787

788+
if src.Cfg.OldChannelFormat {
789+
t.Logf("Skipping asset channel check for %s->%s, old format",
790+
src.Cfg.Name, dst.Cfg.Name)
791+
return
792+
}
793+
771794
err := wait.NoError(func() error {
772795
a, err := getChannelCustomData(src, dst)
773796
if err != nil {
@@ -1822,8 +1845,12 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
18221845
)
18231846
require.NoError(t.t, err)
18241847

1825-
assertWaitingCloseChannelAssetData(t.t, local, chanPoint)
1826-
assertWaitingCloseChannelAssetData(t.t, remote, chanPoint)
1848+
if !local.Cfg.OldChannelFormat {
1849+
assertWaitingCloseChannelAssetData(t.t, local, chanPoint)
1850+
}
1851+
if !remote.Cfg.OldChannelFormat {
1852+
assertWaitingCloseChannelAssetData(t.t, remote, chanPoint)
1853+
}
18271854

18281855
mineBlocks(t, net, 1, 1)
18291856

@@ -1846,8 +1873,12 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
18461873
universeTap,
18471874
)
18481875

1849-
assertClosedChannelAssetData(t.t, local, chanPoint)
1850-
assertClosedChannelAssetData(t.t, remote, chanPoint)
1876+
if !local.Cfg.OldChannelFormat {
1877+
assertClosedChannelAssetData(t.t, local, chanPoint)
1878+
}
1879+
if !remote.Cfg.OldChannelFormat {
1880+
assertClosedChannelAssetData(t.t, remote, chanPoint)
1881+
}
18511882
}
18521883

18531884
// assertDefaultCoOpCloseBalance returns a default implementation of the co-op

itest/litd_custom_channels_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -639,20 +639,20 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
639639
erinAssetBalance += 3
640640
fabiaAssetBalance -= 3
641641
yaraAssetBalance -= 1
642-
itest.AssertBalances(
642+
assertBalance(
643643
t.t, charlieTap, charlieAssetBalance,
644644
itest.WithAssetID(assetID),
645645
)
646-
itest.AssertBalances(
646+
assertBalance(
647647
t.t, daveTap, daveAssetBalance, itest.WithAssetID(assetID),
648648
)
649-
itest.AssertBalances(
649+
assertBalance(
650650
t.t, erinTap, erinAssetBalance, itest.WithAssetID(assetID),
651651
)
652-
itest.AssertBalances(
652+
assertBalance(
653653
t.t, fabiaTap, fabiaAssetBalance, itest.WithAssetID(assetID),
654654
)
655-
itest.AssertBalances(
655+
assertBalance(
656656
t.t, yaraTap, yaraAssetBalance, itest.WithAssetID(assetID),
657657
)
658658

@@ -698,28 +698,28 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
698698
)
699699

700700
// Charlie should still have four asset pieces, two with the same size.
701-
itest.AssertBalances(
701+
assertBalance(
702702
t.t, charlieTap, charlieAssetBalance,
703703
itest.WithAssetID(assetID), itest.WithNumUtxos(2),
704704
itest.WithScriptKeyType(asset.ScriptKeyBip86),
705705
)
706706

707707
// Dave should have two outputs, one from the initial channel with Yara
708708
// and one from the remaining amount of the channel with Charlie.
709-
itest.AssertBalances(
709+
assertBalance(
710710
t.t, daveTap, daveAssetBalance, itest.WithAssetID(assetID),
711711
itest.WithNumUtxos(2),
712712
itest.WithScriptKeyType(asset.ScriptKeyBip86),
713713
)
714714

715715
// Fabia and Yara should all have a single output each, just what was
716716
// left over from the initial channel.
717-
itest.AssertBalances(
717+
assertBalance(
718718
t.t, fabiaTap, fabiaAssetBalance, itest.WithAssetID(assetID),
719719
itest.WithNumUtxos(1),
720720
itest.WithScriptKeyType(asset.ScriptKeyBip86),
721721
)
722-
itest.AssertBalances(
722+
assertBalance(
723723
t.t, yaraTap, yaraAssetBalance, itest.WithAssetID(assetID),
724724
itest.WithNumUtxos(1),
725725
itest.WithScriptKeyType(asset.ScriptKeyBip86),
@@ -728,24 +728,24 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
728728
// Erin didn't use all of his assets when opening the channel, so he
729729
// should have two outputs, the change from the channel opening and the
730730
// remaining amount after closing the channel.
731-
itest.AssertBalances(
731+
assertBalance(
732732
t.t, erinTap, erinAssetBalance, itest.WithAssetID(assetID),
733733
itest.WithNumUtxos(2),
734734
itest.WithScriptKeyType(asset.ScriptKeyBip86),
735735
)
736736

737737
// The asset balances should still remain unchanged.
738-
itest.AssertBalances(
738+
assertBalance(
739739
t.t, charlieTap, charlieAssetBalance,
740740
itest.WithAssetID(assetID),
741741
)
742-
itest.AssertBalances(
742+
assertBalance(
743743
t.t, daveTap, daveAssetBalance, itest.WithAssetID(assetID),
744744
)
745-
itest.AssertBalances(
745+
assertBalance(
746746
t.t, erinTap, erinAssetBalance, itest.WithAssetID(assetID),
747747
)
748-
itest.AssertBalances(
748+
assertBalance(
749749
t.t, fabiaTap, fabiaAssetBalance, itest.WithAssetID(assetID),
750750
)
751751
}

itest/litd_node.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ var (
6868
"litdbbackend", terminal.DatabaseBackendBbolt, "Set the "+
6969
"database backend to use when starting a LiT daemon.",
7070
)
71+
72+
// backwardCompatFlagOverride is a map of LiT versions to a map of
73+
// config file flags that need to be overwritten or added for the target
74+
// version to work. If a flag in the map is empty, it means it will be
75+
// removed from the config file of that version.
76+
backwardCompatFlagOverride = map[string]map[string]string{
77+
"v0.14.1-alpha": {
78+
"databasebackend": "",
79+
"lnd.logging.no-commit-hash": "",
80+
},
81+
}
82+
83+
// backwardCompatConfigOverride is a map of LiT versions to a map of
84+
// config file overriding functions.
85+
backwardCompatConfigOverride = map[string]func(*LitNodeConfig){
86+
"v0.14.1-alpha": func(cfg *LitNodeConfig) {
87+
cfg.OldChannelFormat = true
88+
cfg.SkipBalanceChecks = true
89+
},
90+
}
7191
)
7292

7393
// Option is a function for updating a node's configuration.
@@ -103,6 +123,14 @@ type LitNodeConfig struct {
103123
LitPort int
104124
LitRESTPort int
105125

126+
// OldChannelFormat is a flag for turning off certain checks for old
127+
// versions of litd during the backward compatibility test.
128+
OldChannelFormat bool
129+
130+
// SkipBalanceChecks is a flag for turning off certain checks for old
131+
// versions of litd during the backward compatibility test.
132+
SkipBalanceChecks bool
133+
106134
// backupDBDir is the path where a database backup is stored, if any.
107135
backupDBDir string
108136
}
@@ -616,17 +644,60 @@ func renameFile(fromFileName, toFileName string) {
616644
}
617645
}
618646

647+
// overrideFlagsAndBinary is a helper function that checks if the passed node
648+
// name needs a version downgrade and if so, it will return the new binary
649+
// name and the new arguments.
650+
func (hn *HarnessNode) overrideFlagsAndBinary(backwardCompat map[string]string,
651+
binary string, args []LitArgOption) (string, []LitArgOption) {
652+
653+
if backwardCompat == nil {
654+
return binary, args
655+
}
656+
657+
downgradeVersion, ok := backwardCompat[hn.Cfg.Name]
658+
if !ok {
659+
return binary, args
660+
}
661+
662+
newBinary := fmt.Sprintf("%s-%s", binary, downgradeVersion)
663+
664+
flagOverride, ok := backwardCompatFlagOverride[downgradeVersion]
665+
if !ok {
666+
return newBinary, args
667+
}
668+
669+
for k, v := range flagOverride {
670+
if v == "" {
671+
args = append(args, WithoutLitArg(k))
672+
} else {
673+
args = append(args, WithLitArg(k, v))
674+
}
675+
}
676+
677+
cfgOverride, ok := backwardCompatConfigOverride[downgradeVersion]
678+
if ok && cfgOverride != nil {
679+
cfgOverride(hn.Cfg)
680+
}
681+
682+
return newBinary, args
683+
}
684+
619685
// Start launches a new process running lnd. Additionally, the PID of the
620686
// launched process is saved in order to possibly kill the process forcibly
621687
// later.
622688
//
623689
// This may not clean up properly if an error is returned, so the caller should
624690
// call shutdown() regardless of the return value.
625-
func (hn *HarnessNode) Start(litdBinary string, litdError chan<- error,
691+
func (hn *HarnessNode) Start(litdBinary string,
692+
backwardCompat map[string]string, litdError chan<- error,
626693
waitForStart bool, litArgOpts ...LitArgOption) error {
627694

628695
hn.quit = make(chan struct{})
629696

697+
litdBinary, litArgOpts = hn.overrideFlagsAndBinary(
698+
backwardCompat, litdBinary, litArgOpts,
699+
)
700+
630701
args := hn.Cfg.GenArgs(litArgOpts...)
631702
hn.cmd = exec.Command(litdBinary, args...)
632703

0 commit comments

Comments
 (0)