multi: add blinding point to payment descriptor and persist
This commit adds an optional blinding point to payment descriptors and persists them in our HTLC's extra data. A get/set pattern is used to populate the ExtraData on our disk representation of the HTLC so that callers do not need to worry about the underlying storage detail.
This commit is contained in:
5 files changed
+246
-40
No files matched your search
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -10419,8 +10420,9 @@ func createRandomHTLC(t *testing.T, incoming bool) channeldb.HTLC {
|
||||
_, err = rand.Read(sig)
|
||||
require.NoError(t, err)
|
||||
|
||||
extra := make([]byte, 1000)
|
||||
_, err = rand.Read(extra)
|
||||
blinding, err := pubkeyFromHex(
|
||||
"0228f2af0abe322403480fb3ee172f7f1601e67d1da6cad40b54c4468d48236c39", //nolint:lll
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return channeldb.HTLC{
|
||||
@@ -10433,7 +10435,10 @@ func createRandomHTLC(t *testing.T, incoming bool) channeldb.HTLC {
|
||||
OnionBlob: onionBlob,
|
||||
HtlcIndex: rand.Uint64(),
|
||||
LogIndex: rand.Uint64(),
|
||||
ExtraData: extra,
|
||||
BlindingPoint: tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](blinding),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11000,3 +11005,61 @@ func TestEnforceFeeBuffer(t *testing.T) {
|
||||
|
||||
require.Equal(t, aliceBalance, expectedAmt)
|
||||
}
|
||||
|
||||
// TestBlindingPointPersistence tests persistence of blinding points attached
|
||||
// to htlcs across restarts.
|
||||
func TestBlindingPointPersistence(t *testing.T) {
|
||||
// Create a test channel which will be used for the duration of this
|
||||
// test. The channel will be funded evenly with Alice having 5 BTC,
|
||||
// and Bob having 5 BTC.
|
||||
aliceChannel, bobChannel, err := CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
require.NoError(t, err, "unable to create test channels")
|
||||
|
||||
// Send a HTLC from Alice to Bob that has a blinding point populated.
|
||||
htlc, _ := createHTLC(0, 100_000_000)
|
||||
blinding, err := pubkeyFromHex(
|
||||
"0228f2af0abe322403480fb3ee172f7f1601e67d1da6cad40b54c4468d48236c39", //nolint:lll
|
||||
)
|
||||
require.NoError(t, err)
|
||||
htlc.BlindingPoint = tlv.SomeRecordT(
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](blinding),
|
||||
)
|
||||
|
||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||
|
||||
require.NoError(t, err)
|
||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now, Alice will send a new commitment to Bob, which will persist our
|
||||
// pending HTLC to disk.
|
||||
aliceCommit, err := aliceChannel.SignNextCommitment()
|
||||
require.NoError(t, err, "unable to sign commitment")
|
||||
|
||||
// Restart alice to force fetching state from disk.
|
||||
aliceChannel, err = restartChannel(aliceChannel)
|
||||
require.NoError(t, err, "unable to restart alice")
|
||||
|
||||
// Assert that the blinding point is restored from disk.
|
||||
remoteCommit := aliceChannel.remoteCommitChain.tip()
|
||||
require.Len(t, remoteCommit.outgoingHTLCs, 1)
|
||||
require.Equal(t, blinding, remoteCommit.outgoingHTLCs[0].BlindingPoint)
|
||||
|
||||
// Next, update bob's commitment and assert that we can still retrieve
|
||||
// his incoming blinding point after restart.
|
||||
err = bobChannel.ReceiveNewCommitment(aliceCommit.CommitSigs)
|
||||
require.NoError(t, err, "bob unable to receive new commitment")
|
||||
|
||||
_, _, _, err = bobChannel.RevokeCurrentCommitment()
|
||||
require.NoError(t, err, "bob unable to revoke current commitment")
|
||||
|
||||
bobChannel, err = restartChannel(bobChannel)
|
||||
require.NoError(t, err, "unable to restart bob's channel")
|
||||
|
||||
// Assert that Bob is able to recover the blinding point from disk.
|
||||
bobCommit := bobChannel.localCommitChain.tip()
|
||||
require.Len(t, bobCommit.incomingHTLCs, 1)
|
||||
require.Equal(t, blinding, bobCommit.incomingHTLCs[0].BlindingPoint)
|
||||
}
|
||||
Reference in new issue
Block a user