Merge pull request #3211 from halseth/migration-outgoing-payments-no-source
channeldb/migrations: skip migration for empty outgoing payments bucket
This commit is contained in:
commit
32d6658503
@ -746,9 +746,14 @@ func migrateGossipMessageStoreKeys(tx *bbolt.Tx) error {
|
|||||||
// payments) we delete those statuses, so only Completed payments remain in the
|
// payments) we delete those statuses, so only Completed payments remain in the
|
||||||
// new bucket structure.
|
// new bucket structure.
|
||||||
func migrateOutgoingPayments(tx *bbolt.Tx) error {
|
func migrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||||
oldPayments, err := tx.CreateBucketIfNotExists(paymentBucket)
|
log.Infof("Migrating outgoing payments to new bucket structure")
|
||||||
if err != nil {
|
|
||||||
return err
|
oldPayments := tx.Bucket(paymentBucket)
|
||||||
|
|
||||||
|
// Return early if there are no payments to migrate.
|
||||||
|
if oldPayments == nil {
|
||||||
|
log.Infof("No outgoing payments found, nothing to migrate.")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newPayments, err := tx.CreateBucket(paymentsRootBucket)
|
newPayments, err := tx.CreateBucket(paymentsRootBucket)
|
||||||
@ -756,20 +761,22 @@ func migrateOutgoingPayments(tx *bbolt.Tx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the source pubkey.
|
// Helper method to get the source pubkey. We define it such that we
|
||||||
|
// only attempt to fetch it if needed.
|
||||||
|
sourcePub := func() ([33]byte, error) {
|
||||||
|
var pub [33]byte
|
||||||
nodes := tx.Bucket(nodeBucket)
|
nodes := tx.Bucket(nodeBucket)
|
||||||
if nodes == nil {
|
if nodes == nil {
|
||||||
return ErrGraphNotFound
|
return pub, ErrGraphNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
selfPub := nodes.Get(sourceKey)
|
selfPub := nodes.Get(sourceKey)
|
||||||
if selfPub == nil {
|
if selfPub == nil {
|
||||||
return ErrSourceNodeNotSet
|
return pub, ErrSourceNodeNotSet
|
||||||
|
}
|
||||||
|
copy(pub[:], selfPub[:])
|
||||||
|
return pub, nil
|
||||||
}
|
}
|
||||||
var sourcePubKey [33]byte
|
|
||||||
copy(sourcePubKey[:], selfPub[:])
|
|
||||||
|
|
||||||
log.Infof("Migrating outgoing payments to new bucket structure")
|
|
||||||
|
|
||||||
err = oldPayments.ForEach(func(k, v []byte) error {
|
err = oldPayments.ForEach(func(k, v []byte) error {
|
||||||
// Ignores if it is sub-bucket.
|
// Ignores if it is sub-bucket.
|
||||||
@ -800,6 +807,11 @@ func migrateOutgoingPayments(tx *bbolt.Tx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourcePubKey, err := sourcePub()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Do the same for the PaymentAttemptInfo.
|
// Do the same for the PaymentAttemptInfo.
|
||||||
totalAmt := payment.Terms.Value + payment.Fee
|
totalAmt := payment.Terms.Value + payment.Fee
|
||||||
rt := route.Route{
|
rt := route.Route{
|
||||||
|
Loading…
Reference in New Issue
Block a user