mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-13 18:10:25 +02:00
channeldb: Serialize/deserialize AMP struct in hop
The AMP struct in a hop was never being set when deserizlied. Also, the AMP TLV record was not being added when the hop was serialized. This sets the TLV record when serializing and correctly sets the AMP struct on the hop when that record is present. Co-authored-by: BitcoinCoderBob <90647227+BitcoinCoderBob@users.noreply.github.com> Co-authored-by: Tee8z <tee8z@protonmail.com>
This commit is contained in:
@@ -1157,6 +1157,10 @@ func serializeHop(w io.Writer, h *route.Hop) error {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if h.AMP != nil {
|
||||||
|
records = append(records, h.AMP.Record())
|
||||||
|
}
|
||||||
|
|
||||||
if h.Metadata != nil {
|
if h.Metadata != nil {
|
||||||
records = append(records, record.NewMetadataRecord(&h.Metadata))
|
records = append(records, record.NewMetadataRecord(&h.Metadata))
|
||||||
}
|
}
|
||||||
@@ -1301,7 +1305,23 @@ func deserializeHop(r io.Reader) (*route.Hop, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the metatdata type is present, remove it from the tlv map and
|
ampType := uint64(record.AMPOnionType)
|
||||||
|
if ampBytes, ok := tlvMap[ampType]; ok {
|
||||||
|
delete(tlvMap, ampType)
|
||||||
|
|
||||||
|
var (
|
||||||
|
amp = &record.AMP{}
|
||||||
|
ampRec = amp.Record()
|
||||||
|
r = bytes.NewReader(ampBytes)
|
||||||
|
)
|
||||||
|
err := ampRec.Decode(r, uint64(len(ampBytes)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h.AMP = amp
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the metadata type is present, remove it from the tlv map and
|
||||||
// populate directly on the hop.
|
// populate directly on the hop.
|
||||||
metadataType := uint64(record.MetadataOnionType)
|
metadataType := uint64(record.MetadataOnionType)
|
||||||
if metadata, ok := tlvMap[metadataType]; ok {
|
if metadata, ok := tlvMap[metadataType]; ok {
|
||||||
|
@@ -44,11 +44,25 @@ var (
|
|||||||
LegacyPayload: true,
|
LegacyPayload: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testHop3 = &route.Hop{
|
||||||
|
PubKeyBytes: route.NewVertex(pub),
|
||||||
|
ChannelID: 12345,
|
||||||
|
OutgoingTimeLock: 111,
|
||||||
|
AmtToForward: 555,
|
||||||
|
CustomRecords: record.CustomSet{
|
||||||
|
65536: []byte{},
|
||||||
|
80001: []byte{},
|
||||||
|
},
|
||||||
|
AMP: record.NewAMP([32]byte{0x69}, [32]byte{0x42}, 1),
|
||||||
|
Metadata: []byte{1, 2, 3},
|
||||||
|
}
|
||||||
|
|
||||||
testRoute = route.Route{
|
testRoute = route.Route{
|
||||||
TotalTimeLock: 123,
|
TotalTimeLock: 123,
|
||||||
TotalAmount: 1234567,
|
TotalAmount: 1234567,
|
||||||
SourcePubKey: vertex,
|
SourcePubKey: vertex,
|
||||||
Hops: []*route.Hop{
|
Hops: []*route.Hop{
|
||||||
|
testHop3,
|
||||||
testHop2,
|
testHop2,
|
||||||
testHop1,
|
testHop1,
|
||||||
},
|
},
|
||||||
|
@@ -53,6 +53,8 @@
|
|||||||
walletrpc endpoint `RemoveTransaction` is introduced which let one easily
|
walletrpc endpoint `RemoveTransaction` is introduced which let one easily
|
||||||
remove unconfirmed transaction manually.
|
remove unconfirmed transaction manually.
|
||||||
|
|
||||||
|
* The AMP struct in payment hops will [now be populated](https://github.com/lightningnetwork/lnd/pull/7976) when the AMP TLV is set.
|
||||||
|
|
||||||
# New Features
|
# New Features
|
||||||
## Functional Enhancements
|
## Functional Enhancements
|
||||||
|
|
||||||
@@ -203,6 +205,7 @@
|
|||||||
|
|
||||||
* Amin Bashiri
|
* Amin Bashiri
|
||||||
* Andras Banki-Horvath
|
* Andras Banki-Horvath
|
||||||
|
* BitcoinerCoderBob
|
||||||
* Carla Kirk-Cohen
|
* Carla Kirk-Cohen
|
||||||
* Elle Mouton
|
* Elle Mouton
|
||||||
* ErikEk
|
* ErikEk
|
||||||
@@ -210,6 +213,8 @@
|
|||||||
* Marcos Fernandez Perez
|
* Marcos Fernandez Perez
|
||||||
* Matt Morehouse
|
* Matt Morehouse
|
||||||
* Slyghtning
|
* Slyghtning
|
||||||
|
* Tee8z
|
||||||
* Turtle
|
* Turtle
|
||||||
* Ononiwu Maureen Chiamaka
|
* Ononiwu Maureen Chiamaka
|
||||||
|
* w3irdrobot
|
||||||
* Yong Yu
|
* Yong Yu
|
||||||
|
Reference in New Issue
Block a user