lnwallet: refactor commit keys to use lntypes.Dual
This commit is contained in:
2 files changed
+15
-17
No files matched your search
+14
-16
@@ -575,9 +575,8 @@ func (c *commitment) toDiskCommit(
|
|||||||
// restore commitment state written to disk back into memory once we need to
|
// restore commitment state written to disk back into memory once we need to
|
||||||
// restart a channel session.
|
// restart a channel session.
|
||||||
func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||||
htlc *channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
|
htlc *channeldb.HTLC, commitKeys lntypes.Dual[*CommitmentKeyRing],
|
||||||
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
|
whoseCommit lntypes.ChannelParty) (PaymentDescriptor, error) {
|
||||||
) (PaymentDescriptor, error) {
|
|
||||||
|
|
||||||
// The proper pkScripts for this PaymentDescriptor must be
|
// The proper pkScripts for this PaymentDescriptor must be
|
||||||
// generated so we can easily locate them within the commitment
|
// generated so we can easily locate them within the commitment
|
||||||
@@ -598,6 +597,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
|||||||
chanType, htlc.Incoming, lntypes.Local, feeRate,
|
chanType, htlc.Incoming, lntypes.Local, feeRate,
|
||||||
htlc.Amt.ToSatoshis(), lc.channelState.LocalChanCfg.DustLimit,
|
htlc.Amt.ToSatoshis(), lc.channelState.LocalChanCfg.DustLimit,
|
||||||
)
|
)
|
||||||
|
localCommitKeys := commitKeys.GetForParty(lntypes.Local)
|
||||||
if !isDustLocal && localCommitKeys != nil {
|
if !isDustLocal && localCommitKeys != nil {
|
||||||
scriptInfo, err := genHtlcScript(
|
scriptInfo, err := genHtlcScript(
|
||||||
chanType, htlc.Incoming, lntypes.Local,
|
chanType, htlc.Incoming, lntypes.Local,
|
||||||
@@ -613,6 +613,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
|||||||
chanType, htlc.Incoming, lntypes.Remote, feeRate,
|
chanType, htlc.Incoming, lntypes.Remote, feeRate,
|
||||||
htlc.Amt.ToSatoshis(), lc.channelState.RemoteChanCfg.DustLimit,
|
htlc.Amt.ToSatoshis(), lc.channelState.RemoteChanCfg.DustLimit,
|
||||||
)
|
)
|
||||||
|
remoteCommitKeys := commitKeys.GetForParty(lntypes.Remote)
|
||||||
if !isDustRemote && remoteCommitKeys != nil {
|
if !isDustRemote && remoteCommitKeys != nil {
|
||||||
scriptInfo, err := genHtlcScript(
|
scriptInfo, err := genHtlcScript(
|
||||||
chanType, htlc.Incoming, lntypes.Remote,
|
chanType, htlc.Incoming, lntypes.Remote,
|
||||||
@@ -665,9 +666,9 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
|||||||
// these payment descriptors can be re-inserted into the in-memory updateLog
|
// these payment descriptors can be re-inserted into the in-memory updateLog
|
||||||
// for each side.
|
// for each side.
|
||||||
func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
|
func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
|
||||||
htlcs []channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
|
htlcs []channeldb.HTLC, commitKeys lntypes.Dual[*CommitmentKeyRing],
|
||||||
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
|
whoseCommit lntypes.ChannelParty) ([]PaymentDescriptor,
|
||||||
) ([]PaymentDescriptor, []PaymentDescriptor, error) {
|
[]PaymentDescriptor, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
incomingHtlcs []PaymentDescriptor
|
incomingHtlcs []PaymentDescriptor
|
||||||
@@ -685,9 +686,7 @@ func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
|
|||||||
htlc := htlc
|
htlc := htlc
|
||||||
|
|
||||||
payDesc, err := lc.diskHtlcToPayDesc(
|
payDesc, err := lc.diskHtlcToPayDesc(
|
||||||
feeRate, &htlc,
|
feeRate, &htlc, commitKeys, whoseCommit,
|
||||||
localCommitKeys, remoteCommitKeys,
|
|
||||||
whoseCommit,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return incomingHtlcs, outgoingHtlcs, err
|
return incomingHtlcs, outgoingHtlcs, err
|
||||||
@@ -716,22 +715,22 @@ func (lc *LightningChannel) diskCommitToMemCommit(
|
|||||||
// (we extended but weren't able to complete the commitment dance
|
// (we extended but weren't able to complete the commitment dance
|
||||||
// before shutdown), then the localCommitPoint won't be set as we
|
// before shutdown), then the localCommitPoint won't be set as we
|
||||||
// haven't yet received a responding commitment from the remote party.
|
// haven't yet received a responding commitment from the remote party.
|
||||||
var localCommitKeys, remoteCommitKeys *CommitmentKeyRing
|
var commitKeys lntypes.Dual[*CommitmentKeyRing]
|
||||||
if localCommitPoint != nil {
|
if localCommitPoint != nil {
|
||||||
localCommitKeys = DeriveCommitmentKeys(
|
commitKeys.SetForParty(lntypes.Local, DeriveCommitmentKeys(
|
||||||
localCommitPoint, lntypes.Local,
|
localCommitPoint, lntypes.Local,
|
||||||
lc.channelState.ChanType,
|
lc.channelState.ChanType,
|
||||||
&lc.channelState.LocalChanCfg,
|
&lc.channelState.LocalChanCfg,
|
||||||
&lc.channelState.RemoteChanCfg,
|
&lc.channelState.RemoteChanCfg,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
if remoteCommitPoint != nil {
|
if remoteCommitPoint != nil {
|
||||||
remoteCommitKeys = DeriveCommitmentKeys(
|
commitKeys.SetForParty(lntypes.Remote, DeriveCommitmentKeys(
|
||||||
remoteCommitPoint, lntypes.Remote,
|
remoteCommitPoint, lntypes.Remote,
|
||||||
lc.channelState.ChanType,
|
lc.channelState.ChanType,
|
||||||
&lc.channelState.LocalChanCfg,
|
&lc.channelState.LocalChanCfg,
|
||||||
&lc.channelState.RemoteChanCfg,
|
&lc.channelState.RemoteChanCfg,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the key rings re-created, we'll now convert all the on-disk
|
// With the key rings re-created, we'll now convert all the on-disk
|
||||||
@@ -739,8 +738,7 @@ func (lc *LightningChannel) diskCommitToMemCommit(
|
|||||||
// update log.
|
// update log.
|
||||||
incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs(
|
incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs(
|
||||||
chainfee.SatPerKWeight(diskCommit.FeePerKw),
|
chainfee.SatPerKWeight(diskCommit.FeePerKw),
|
||||||
diskCommit.Htlcs, localCommitKeys, remoteCommitKeys,
|
diskCommit.Htlcs, commitKeys, whoseCommit,
|
||||||
whoseCommit,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -10416,7 +10416,7 @@ func TestExtractPayDescs(t *testing.T) {
|
|||||||
// NOTE: we use nil commitment key rings to avoid checking the htlc
|
// NOTE: we use nil commitment key rings to avoid checking the htlc
|
||||||
// scripts(`genHtlcScript`) as it should be tested independently.
|
// scripts(`genHtlcScript`) as it should be tested independently.
|
||||||
incomingPDs, outgoingPDs, err := lnChan.extractPayDescs(
|
incomingPDs, outgoingPDs, err := lnChan.extractPayDescs(
|
||||||
0, htlcs, nil, nil, lntypes.Local,
|
0, htlcs, lntypes.Dual[*CommitmentKeyRing]{}, lntypes.Local,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user