Merge pull request #3479 from Roasbeef/migration-9-10-fix-min-version

channeldb: fix migration bug due to interplay between migration #9 an…
This commit is contained in:
Olaoluwa Osuntokun 2019-09-09 02:20:49 -07:00 committed by GitHub
commit acb38a8b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

@ -7,6 +7,7 @@ import (
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
var (
@ -253,3 +254,50 @@ func deserializeOutgoingPayment(r io.Reader) (*outgoingPayment, error) {
return p, nil
}
// serializePaymentAttemptInfoMigration9 is the serializePaymentAttemptInfo
// version as existed when migration #9 was created. We keep this around, along
// with the methods below to ensure that clients that upgrade will use the
// correct version of this method.
func serializePaymentAttemptInfoMigration9(w io.Writer, a *PaymentAttemptInfo) error {
if err := WriteElements(w, a.PaymentID, a.SessionKey); err != nil {
return err
}
if err := serializeRouteMigration9(w, a.Route); err != nil {
return err
}
return nil
}
func serializeHopMigration9(w io.Writer, h *route.Hop) error {
if err := WriteElements(w,
h.PubKeyBytes[:], h.ChannelID, h.OutgoingTimeLock,
h.AmtToForward,
); err != nil {
return err
}
return nil
}
func serializeRouteMigration9(w io.Writer, r route.Route) error {
if err := WriteElements(w,
r.TotalTimeLock, r.TotalAmount, r.SourcePubKey[:],
); err != nil {
return err
}
if err := WriteElements(w, uint32(len(r.Hops))); err != nil {
return err
}
for _, h := range r.Hops {
if err := serializeHopMigration9(w, h); err != nil {
return err
}
}
return nil
}

@ -845,7 +845,7 @@ func migrateOutgoingPayments(tx *bbolt.Tx) error {
}
var attemptBuf bytes.Buffer
if err := serializePaymentAttemptInfo(&attemptBuf, s); err != nil {
if err := serializePaymentAttemptInfoMigration9(&attemptBuf, s); err != nil {
return err
}