lnwallet+channeldb: use BigSizeT to save space
This commit is contained in:
3 files changed
+36
-28
No files matched your search
@@ -165,7 +165,7 @@ type HTLCEntry struct {
|
|||||||
CustomBlob tlv.OptionalRecordT[tlv.TlvType5, tlv.Blob]
|
CustomBlob tlv.OptionalRecordT[tlv.TlvType5, tlv.Blob]
|
||||||
|
|
||||||
// HtlcIndex is the index of the HTLC in the channel.
|
// HtlcIndex is the index of the HTLC in the channel.
|
||||||
HtlcIndex tlv.OptionalRecordT[tlv.TlvType6, uint16]
|
HtlcIndex tlv.OptionalRecordT[tlv.TlvType6, tlv.BigSizeT[uint64]]
|
||||||
}
|
}
|
||||||
|
|
||||||
// toTlvStream converts an HTLCEntry record into a tlv representation.
|
// toTlvStream converts an HTLCEntry record into a tlv representation.
|
||||||
@@ -182,7 +182,9 @@ func (h *HTLCEntry) toTlvStream() (*tlv.Stream, error) {
|
|||||||
records = append(records, r.Record())
|
records = append(records, r.Record())
|
||||||
})
|
})
|
||||||
|
|
||||||
h.HtlcIndex.WhenSome(func(r tlv.RecordT[tlv.TlvType6, uint16]) {
|
h.HtlcIndex.WhenSome(func(r tlv.RecordT[tlv.TlvType6,
|
||||||
|
tlv.BigSizeT[uint64]]) {
|
||||||
|
|
||||||
records = append(records, r.Record())
|
records = append(records, r.Record())
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -207,8 +209,8 @@ func NewHTLCEntryFromHTLC(htlc HTLC) (*HTLCEntry, error) {
|
|||||||
Amt: tlv.NewRecordT[tlv.TlvType4](
|
Amt: tlv.NewRecordT[tlv.TlvType4](
|
||||||
tlv.NewBigSizeT(htlc.Amt.ToSatoshis()),
|
tlv.NewBigSizeT(htlc.Amt.ToSatoshis()),
|
||||||
),
|
),
|
||||||
HtlcIndex: tlv.SomeRecordT(tlv.NewPrimitiveRecord[tlv.TlvType6](
|
HtlcIndex: tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType6](
|
||||||
uint16(htlc.HtlcIndex),
|
tlv.NewBigSizeT(htlc.HtlcIndex),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,13 +59,13 @@ var (
|
|||||||
CustomBlob: tlv.SomeRecordT(
|
CustomBlob: tlv.SomeRecordT(
|
||||||
tlv.NewPrimitiveRecord[tlv.TlvType5](blobBytes),
|
tlv.NewPrimitiveRecord[tlv.TlvType5](blobBytes),
|
||||||
),
|
),
|
||||||
HtlcIndex: tlv.SomeRecordT(
|
HtlcIndex: tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType6](
|
||||||
tlv.NewPrimitiveRecord[tlv.TlvType6, uint16](0x33),
|
tlv.NewBigSizeT(uint64(0x33)),
|
||||||
),
|
)),
|
||||||
}
|
}
|
||||||
testHTLCEntryBytes = []byte{
|
testHTLCEntryBytes = []byte{
|
||||||
// Body length 45.
|
// Body length 44.
|
||||||
0x2d,
|
0x2c,
|
||||||
// Rhash tlv.
|
// Rhash tlv.
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
// RefundTimeout tlv.
|
// RefundTimeout tlv.
|
||||||
@@ -80,7 +80,7 @@ var (
|
|||||||
0x5, 0x11, 0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73,
|
0x5, 0x11, 0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73,
|
||||||
0x74, 0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
|
0x74, 0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
|
||||||
// HLTC index tlv.
|
// HLTC index tlv.
|
||||||
0x6, 0x2, 0x0, 0x33,
|
0x6, 0x1, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
testHTLCEntryHash = HTLCEntry{
|
testHTLCEntryHash = HTLCEntry{
|
||||||
@@ -133,7 +133,7 @@ var (
|
|||||||
OutputIndex: int32(testHTLCEntry.OutputIndex.Val),
|
OutputIndex: int32(testHTLCEntry.OutputIndex.Val),
|
||||||
HtlcIndex: uint64(
|
HtlcIndex: uint64(
|
||||||
testHTLCEntry.HtlcIndex.ValOpt().
|
testHTLCEntry.HtlcIndex.ValOpt().
|
||||||
UnsafeFromSome(),
|
UnsafeFromSome().Int(),
|
||||||
),
|
),
|
||||||
Incoming: testHTLCEntry.Incoming.Val,
|
Incoming: testHTLCEntry.Incoming.Val,
|
||||||
Amt: lnwire.NewMSatFromSatoshis(
|
Amt: lnwire.NewMSatFromSatoshis(
|
||||||
@@ -303,7 +303,7 @@ func TestSerializeHTLCEntries(t *testing.T) {
|
|||||||
partialBytes := testHTLCEntryBytes[3:]
|
partialBytes := testHTLCEntryBytes[3:]
|
||||||
|
|
||||||
// Write the total length and RHash tlv.
|
// Write the total length and RHash tlv.
|
||||||
expectedBytes := []byte{0x4d, 0x0, 0x20}
|
expectedBytes := []byte{0x4c, 0x0, 0x20}
|
||||||
expectedBytes = append(expectedBytes, rHashBytes...)
|
expectedBytes = append(expectedBytes, rHashBytes...)
|
||||||
|
|
||||||
// Append the rest.
|
// Append the rest.
|
||||||
|
|||||||
+22
-16
@@ -2340,18 +2340,21 @@ func createHtlcRetribution(chanState *channeldb.OpenChannel,
|
|||||||
// We'll generate the original second level witness script now, as
|
// We'll generate the original second level witness script now, as
|
||||||
// we'll need it if we're revoking an HTLC output on the remote
|
// we'll need it if we're revoking an HTLC output on the remote
|
||||||
// commitment transaction, and *they* go to the second level.
|
// commitment transaction, and *they* go to the second level.
|
||||||
|
//nolint:ll
|
||||||
secondLevelAuxLeaf := fn.FlatMapOption(
|
secondLevelAuxLeaf := fn.FlatMapOption(
|
||||||
func(l CommitAuxLeaves) fn.Option[input.AuxTapLeaf] {
|
func(l CommitAuxLeaves) fn.Option[input.AuxTapLeaf] {
|
||||||
return fn.MapOption(func(val uint16) input.AuxTapLeaf {
|
return fn.MapOption(
|
||||||
idx := input.HtlcIndex(val)
|
func(val tlv.BigSizeT[uint64]) input.AuxTapLeaf {
|
||||||
|
idx := val.Int()
|
||||||
|
|
||||||
if htlc.Incoming.Val {
|
if htlc.Incoming.Val {
|
||||||
leaves := l.IncomingHtlcLeaves[idx]
|
leaves := l.IncomingHtlcLeaves[idx]
|
||||||
return leaves.SecondLevelLeaf
|
return leaves.SecondLevelLeaf
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.OutgoingHtlcLeaves[idx].SecondLevelLeaf
|
return l.OutgoingHtlcLeaves[idx].SecondLevelLeaf
|
||||||
})(htlc.HtlcIndex.ValOpt())
|
},
|
||||||
|
)(htlc.HtlcIndex.ValOpt())
|
||||||
},
|
},
|
||||||
)(auxLeaves)
|
)(auxLeaves)
|
||||||
secondLevelScript, err := SecondLevelHtlcScript(
|
secondLevelScript, err := SecondLevelHtlcScript(
|
||||||
@@ -2368,18 +2371,21 @@ func createHtlcRetribution(chanState *channeldb.OpenChannel,
|
|||||||
// HTLC script. Otherwise, is this was an outgoing HTLC that we sent,
|
// HTLC script. Otherwise, is this was an outgoing HTLC that we sent,
|
||||||
// then from the PoV of the remote commitment state, they're the
|
// then from the PoV of the remote commitment state, they're the
|
||||||
// receiver of this HTLC.
|
// receiver of this HTLC.
|
||||||
|
//nolint:ll
|
||||||
htlcLeaf := fn.FlatMapOption(
|
htlcLeaf := fn.FlatMapOption(
|
||||||
func(l CommitAuxLeaves) fn.Option[input.AuxTapLeaf] {
|
func(l CommitAuxLeaves) fn.Option[input.AuxTapLeaf] {
|
||||||
return fn.MapOption(func(val uint16) input.AuxTapLeaf {
|
return fn.MapOption(
|
||||||
idx := input.HtlcIndex(val)
|
func(val tlv.BigSizeT[uint64]) input.AuxTapLeaf {
|
||||||
|
idx := val.Int()
|
||||||
|
|
||||||
if htlc.Incoming.Val {
|
if htlc.Incoming.Val {
|
||||||
leaves := l.IncomingHtlcLeaves[idx]
|
leaves := l.IncomingHtlcLeaves[idx]
|
||||||
return leaves.AuxTapLeaf
|
return leaves.AuxTapLeaf
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.OutgoingHtlcLeaves[idx].AuxTapLeaf
|
return l.OutgoingHtlcLeaves[idx].AuxTapLeaf
|
||||||
})(htlc.HtlcIndex.ValOpt())
|
},
|
||||||
|
)(htlc.HtlcIndex.ValOpt())
|
||||||
},
|
},
|
||||||
)(auxLeaves)
|
)(auxLeaves)
|
||||||
scriptInfo, err := genHtlcScript(
|
scriptInfo, err := genHtlcScript(
|
||||||
|
|||||||
Reference in new issue
Block a user