mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
c9f5912601
This introduces a BigSize migration that is used to expand the width of the ChannelStatus and ChannelType fields. Three channel "types" are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit. ScidAliasChanBit denotes that the scid-alias channel type was negotiated for the channel. ScidAliasFeatureBit denotes that the scid-alias feature bit was negotiated during the *lifetime* of the channel. Several helper functions on the OpenChannel struct are exposed to aid callers from different packages. The RefreshShortChanID has been renamed to Refresh. A new function BroadcastHeight is used to guard access to the mutable FundingBroadcastHeight member. This prevents data races.
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package migration29
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
"github.com/lightningnetwork/lnd/kvdb"
|
|
)
|
|
|
|
var (
|
|
// outpointBucket is the bucket that stores the set of outpoints we
|
|
// know about.
|
|
outpointBucket = []byte("outpoint-bucket")
|
|
|
|
// chanIDBucket is the bucket that stores the set of ChannelID's we
|
|
// know about.
|
|
chanIDBucket = []byte("chan-id-bucket")
|
|
)
|
|
|
|
// MigrateChanID populates the ChannelID index by using the set of outpoints
|
|
// retrieved from the outpoint bucket.
|
|
func MigrateChanID(tx kvdb.RwTx) error {
|
|
log.Info("Populating ChannelID index")
|
|
|
|
// First we'll retrieve the set of outpoints we know about.
|
|
ops, err := fetchOutPoints(tx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return populateChanIDIndex(tx, ops)
|
|
}
|
|
|
|
// fetchOutPoints loops through the outpointBucket and returns each stored
|
|
// outpoint.
|
|
func fetchOutPoints(tx kvdb.RwTx) ([]*wire.OutPoint, error) {
|
|
var ops []*wire.OutPoint
|
|
|
|
bucket := tx.ReadBucket(outpointBucket)
|
|
|
|
err := bucket.ForEach(func(k, _ []byte) error {
|
|
var op wire.OutPoint
|
|
r := bytes.NewReader(k)
|
|
if err := readOutpoint(r, &op); err != nil {
|
|
return err
|
|
}
|
|
|
|
ops = append(ops, &op)
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ops, nil
|
|
}
|
|
|
|
// populateChanIDIndex uses the set of retrieved outpoints and populates the
|
|
// ChannelID index.
|
|
func populateChanIDIndex(tx kvdb.RwTx, ops []*wire.OutPoint) error {
|
|
bucket := tx.ReadWriteBucket(chanIDBucket)
|
|
|
|
for _, op := range ops {
|
|
chanID := NewChanIDFromOutPoint(op)
|
|
|
|
if err := bucket.Put(chanID[:], []byte{}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|