channeldb: convert HTLCEntry to use tlv.RecordT
This commit is contained in:
1 parent
c1e641e9d9
commit
1b1e7a6168
5 files changed
+212
-166
No files matched your search
+6
-12
@@ -2202,8 +2202,8 @@ func createHtlcRetribution(chanState *channeldb.OpenChannel,
|
||||
// then from the PoV of the remote commitment state, they're the
|
||||
// receiver of this HTLC.
|
||||
scriptInfo, err := genHtlcScript(
|
||||
chanState.ChanType, htlc.Incoming, lntypes.Remote,
|
||||
htlc.RefundTimeout, htlc.RHash, keyRing,
|
||||
chanState.ChanType, htlc.Incoming.Val, lntypes.Remote,
|
||||
htlc.RefundTimeout.Val, htlc.RHash.Val, keyRing,
|
||||
)
|
||||
if err != nil {
|
||||
return emptyRetribution, err
|
||||
@@ -2216,7 +2216,7 @@ func createHtlcRetribution(chanState *channeldb.OpenChannel,
|
||||
WitnessScript: scriptInfo.WitnessScriptToSign(),
|
||||
Output: &wire.TxOut{
|
||||
PkScript: scriptInfo.PkScript(),
|
||||
Value: int64(htlc.Amt),
|
||||
Value: int64(htlc.Amt.Val.Int()),
|
||||
},
|
||||
HashType: sweepSigHash(chanState.ChanType),
|
||||
}
|
||||
@@ -2249,10 +2249,10 @@ func createHtlcRetribution(chanState *channeldb.OpenChannel,
|
||||
SignDesc: signDesc,
|
||||
OutPoint: wire.OutPoint{
|
||||
Hash: commitHash,
|
||||
Index: uint32(htlc.OutputIndex),
|
||||
Index: uint32(htlc.OutputIndex.Val),
|
||||
},
|
||||
SecondLevelWitnessScript: secondLevelWitnessScript,
|
||||
IsIncoming: htlc.Incoming,
|
||||
IsIncoming: htlc.Incoming.Val,
|
||||
SecondLevelTapTweak: secondLevelTapTweak,
|
||||
}, nil
|
||||
}
|
||||
@@ -2414,13 +2414,7 @@ func createBreachRetributionLegacy(revokedLog *channeldb.ChannelCommitment,
|
||||
continue
|
||||
}
|
||||
|
||||
entry := &channeldb.HTLCEntry{
|
||||
RHash: htlc.RHash,
|
||||
RefundTimeout: htlc.RefundTimeout,
|
||||
OutputIndex: uint16(htlc.OutputIndex),
|
||||
Incoming: htlc.Incoming,
|
||||
Amt: htlc.Amt.ToSatoshis(),
|
||||
}
|
||||
entry := channeldb.NewHTLCEntryFromHTLC(htlc)
|
||||
hr, err := createHtlcRetribution(
|
||||
chanState, keyRing, commitHash,
|
||||
commitmentSecret, leaseExpiry, entry,
|
||||
|
||||
+18
-11
@@ -9957,9 +9957,11 @@ func TestCreateHtlcRetribution(t *testing.T) {
|
||||
aliceChannel.channelState,
|
||||
)
|
||||
htlc := &channeldb.HTLCEntry{
|
||||
Amt: testAmt,
|
||||
Incoming: true,
|
||||
OutputIndex: 1,
|
||||
Amt: tlv.NewRecordT[tlv.TlvType4](
|
||||
tlv.NewBigSizeT(testAmt),
|
||||
),
|
||||
Incoming: tlv.NewPrimitiveRecord[tlv.TlvType3](true),
|
||||
OutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType2, uint16](1),
|
||||
}
|
||||
|
||||
// Create the htlc retribution.
|
||||
@@ -9973,8 +9975,8 @@ func TestCreateHtlcRetribution(t *testing.T) {
|
||||
// Check the fields have expected values.
|
||||
require.EqualValues(t, testAmt, hr.SignDesc.Output.Value)
|
||||
require.Equal(t, commitHash, hr.OutPoint.Hash)
|
||||
require.EqualValues(t, htlc.OutputIndex, hr.OutPoint.Index)
|
||||
require.Equal(t, htlc.Incoming, hr.IsIncoming)
|
||||
require.EqualValues(t, htlc.OutputIndex.Val, hr.OutPoint.Index)
|
||||
require.Equal(t, htlc.Incoming.Val, hr.IsIncoming)
|
||||
}
|
||||
|
||||
// TestCreateBreachRetribution checks that `createBreachRetribution` behaves as
|
||||
@@ -10014,9 +10016,13 @@ func TestCreateBreachRetribution(t *testing.T) {
|
||||
aliceChannel.channelState,
|
||||
)
|
||||
htlc := &channeldb.HTLCEntry{
|
||||
Amt: btcutil.Amount(testAmt),
|
||||
Incoming: true,
|
||||
OutputIndex: uint16(htlcIndex),
|
||||
Amt: tlv.NewRecordT[tlv.TlvType4](
|
||||
tlv.NewBigSizeT(btcutil.Amount(testAmt)),
|
||||
),
|
||||
Incoming: tlv.NewPrimitiveRecord[tlv.TlvType3](true),
|
||||
OutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType2](
|
||||
uint16(htlcIndex),
|
||||
),
|
||||
}
|
||||
|
||||
// Create a dummy revocation log.
|
||||
@@ -10143,11 +10149,12 @@ func TestCreateBreachRetribution(t *testing.T) {
|
||||
require.Equal(t, remote, br.RemoteOutpoint)
|
||||
|
||||
for _, hr := range br.HtlcRetributions {
|
||||
require.EqualValues(t, testAmt,
|
||||
hr.SignDesc.Output.Value)
|
||||
require.EqualValues(
|
||||
t, testAmt, hr.SignDesc.Output.Value,
|
||||
)
|
||||
require.Equal(t, commitHash, hr.OutPoint.Hash)
|
||||
require.EqualValues(t, htlcIndex, hr.OutPoint.Index)
|
||||
require.Equal(t, htlc.Incoming, hr.IsIncoming)
|
||||
require.Equal(t, htlc.Incoming.Val, hr.IsIncoming)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user