@@ -1236,7 +1236,7 @@ func putInvoice(invoices, invoiceIndex, payAddrIndex, addIndex kvdb.RwBucket,
1236
1236
1237
1237
// recordSize returns the amount of bytes this TLV record will occupy when
1238
1238
// encoded.
1239
- func ampRecordSize (a * invpkg.AMPInvoiceState ) func () uint64 {
1239
+ func ampRecordSize (a * invpkg.AMPInvoiceState ) func () ( uint64 , error ) {
1240
1240
var (
1241
1241
b bytes.Buffer
1242
1242
buf [8 ]byte
@@ -1246,13 +1246,13 @@ func ampRecordSize(a *invpkg.AMPInvoiceState) func() uint64 {
1246
1246
// file is checked into, so we'll simplify things and simply encode it
1247
1247
// ourselves then report the total amount of bytes used.
1248
1248
if err := ampStateEncoder (& b , a , & buf ); err != nil {
1249
- // This should never error out, but we log it just in case it
1250
- // does.
1251
- log . Errorf ( "encoding the amp invoice state failed: %v" , err )
1249
+ return func () ( uint64 , error ) {
1250
+ return 0 , err
1251
+ }
1252
1252
}
1253
1253
1254
- return func () uint64 {
1255
- return uint64 (len (b .Bytes ()))
1254
+ return func () ( uint64 , error ) {
1255
+ return uint64 (len (b .Bytes ())), nil
1256
1256
}
1257
1257
}
1258
1258
@@ -1389,7 +1389,10 @@ func serializeHtlcs(w io.Writer,
1389
1389
if htlc .AMP != nil {
1390
1390
setIDRecord := tlv .MakeDynamicRecord (
1391
1391
htlcAMPType , & htlc .AMP .Record ,
1392
- htlc .AMP .Record .PayloadSize ,
1392
+ func () (uint64 , error ) {
1393
+ return htlc .AMP .Record .PayloadSize (),
1394
+ nil
1395
+ },
1393
1396
record .AMPEncoder , record .AMPDecoder ,
1394
1397
)
1395
1398
records = append (records , setIDRecord )
@@ -1892,7 +1895,7 @@ func ampStateEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
1892
1895
tlv .MakeDynamicRecord (
1893
1896
ampStateCircuitKeysType ,
1894
1897
& ampState .InvoiceKeys ,
1895
- func () uint64 {
1898
+ func () ( uint64 , error ) {
1896
1899
// The record takes 8 bytes to
1897
1900
// encode the set of circuits,
1898
1901
// 8 bytes for the scid for the
@@ -1903,7 +1906,7 @@ func ampStateEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
1903
1906
size := tlv .VarIntSize (numKeys )
1904
1907
dataSize := (numKeys * 16 )
1905
1908
1906
- return size + dataSize
1909
+ return size + dataSize , nil
1907
1910
},
1908
1911
encodeCircuitKeys , decodeCircuitKeys ,
1909
1912
),
@@ -2080,7 +2083,9 @@ func deserializeHtlcs(r io.Reader) (map[models.CircuitKey]*invpkg.InvoiceHTLC,
2080
2083
tlv .MakePrimitiveRecord (htlcStateType , & state ),
2081
2084
tlv .MakePrimitiveRecord (mppTotalAmtType , & mppTotalAmt ),
2082
2085
tlv .MakeDynamicRecord (
2083
- htlcAMPType , amp , amp .PayloadSize ,
2086
+ htlcAMPType , amp , func () (uint64 , error ) {
2087
+ return amp .PayloadSize (), nil
2088
+ },
2084
2089
record .AMPEncoder , record .AMPDecoder ,
2085
2090
),
2086
2091
tlv .MakePrimitiveRecord (htlcHashType , hash32 ),
0 commit comments