channeldb: final htlc resolution storage opt-in

This commit is contained in:
Joost Jager committed 2023-01-26 07:02:17 +01:00
1 parent b50d59ec2e
commit 7a785c74c4
10 files changed
+85 -27

No files matched your search

+23 -7
View File
@@ -59,7 +59,9 @@ func assertOutputExistsByValue(t *testing.T, commitTx *wire.MsgTx,
// testAddSettleWorkflow tests a simple channel scenario where Alice and Bob
// add, the settle an HTLC between themselves.
func testAddSettleWorkflow(t *testing.T, tweakless bool) {
func testAddSettleWorkflow(t *testing.T, tweakless,
storeFinalHtlcResolutions bool) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
@@ -68,7 +70,12 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool) {
chanType = channeldb.SingleFunderBit
}
aliceChannel, bobChannel, err := CreateTestChannels(t, chanType)
aliceChannel, bobChannel, err := CreateTestChannels(
t, chanType,
channeldb.OptionStoreFinalHtlcResolutions(
storeFinalHtlcResolutions,
),
)
require.NoError(t, err, "unable to create test channels")
paymentPreimage := bytes.Repeat([]byte{1}, 32)
@@ -248,13 +255,18 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool) {
for htlcID, settled := range finalHtlcs {
require.True(t, settled, "final settle expected")
// Assert that final resolution was stored in Bob's database.
// Assert that final resolution was stored in Bob's database if
// storage is enabled.
finalInfo, err := bobChannel.channelState.Db.LookupFinalHtlc(
bobChannel.ShortChanID(), htlcID,
)
require.NoError(t, err)
require.True(t, finalInfo.Offchain)
require.True(t, finalInfo.Settled)
if storeFinalHtlcResolutions {
require.NoError(t, err)
require.True(t, finalInfo.Offchain)
require.True(t, finalInfo.Settled)
} else {
require.ErrorIs(t, err, channeldb.ErrHtlcUnknown)
}
}
fwdPkg, _, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation2)
@@ -339,9 +351,13 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
for _, tweakless := range []bool{true, false} {
tweakless := tweakless
t.Run(fmt.Sprintf("tweakless=%v", tweakless), func(t *testing.T) {
testAddSettleWorkflow(t, tweakless)
testAddSettleWorkflow(t, tweakless, false)
})
}
t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) {
testAddSettleWorkflow(t, false, true)
})
}
// TestChannelZeroAddLocalHeight tests that we properly set the addCommitHeightLocal
+5 -4
View File
@@ -106,8 +106,9 @@ var (
// allocated to each side. Within the channel, Alice is the initiator. If
// tweaklessCommits is true, then the commits within the channels will use the
// new format, otherwise the legacy format.
func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType) (
*LightningChannel, *LightningChannel, error) {
func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
dbModifiers ...channeldb.OptionModifier) (*LightningChannel,
*LightningChannel, error) {
channelCapacity, err := btcutil.NewAmount(testChannelCapacity)
if err != nil {
@@ -228,7 +229,7 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType) (
return nil, nil, err
}
dbAlice, err := channeldb.Open(t.TempDir())
dbAlice, err := channeldb.Open(t.TempDir(), dbModifiers...)
if err != nil {
return nil, nil, err
}
@@ -236,7 +237,7 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType) (
require.NoError(t, dbAlice.Close())
})
dbBob, err := channeldb.Open(t.TempDir())
dbBob, err := channeldb.Open(t.TempDir(), dbModifiers...)
if err != nil {
return nil, nil, err
}