channeldb+migration: export commonly used methods
This commit exports several commonly used methods that can be used by later migrations. It also adds a channel commit deserializer.
This commit is contained in:
7 files changed
+109
-20
No files matched your search
@@ -70,7 +70,7 @@ func MigrateFwdPkgCleanup(tx kvdb.RwTx) error {
|
||||
|
||||
// Iterate over all close channels and remove their forwarding packages.
|
||||
for _, summery := range chanSummaries {
|
||||
sourceBytes := makeLogKey(summery.ShortChanID.ToUint64())
|
||||
sourceBytes := MakeLogKey(summery.ShortChanID.ToUint64())
|
||||
|
||||
// First, we will try to find the corresponding bucket. If there
|
||||
// is not a nested bucket matching the ShortChanID, we will skip
|
||||
@@ -112,7 +112,7 @@ func deserializeCloseChannelSummary(
|
||||
}
|
||||
|
||||
// makeLogKey converts a uint64 into an 8 byte array.
|
||||
func makeLogKey(updateNum uint64) [8]byte {
|
||||
func MakeLogKey(updateNum uint64) [8]byte {
|
||||
var key [8]byte
|
||||
binary.BigEndian.PutUint64(key[:], updateNum)
|
||||
return key
|
||||
|
||||
@@ -187,7 +187,7 @@ func genAfterMigration(deleted, untouched []int) func(kvdb.RwTx) error {
|
||||
// Reading deleted buckets should return nil
|
||||
for _, id := range deleted {
|
||||
chanID := lnwire.NewShortChanIDFromInt(uint64(id))
|
||||
sourceKey := makeLogKey(chanID.ToUint64())
|
||||
sourceKey := MakeLogKey(chanID.ToUint64())
|
||||
sourceBkt := fwdPkgBkt.NestedReadBucket(sourceKey[:])
|
||||
if sourceBkt != nil {
|
||||
return fmt.Errorf(
|
||||
@@ -200,7 +200,7 @@ func genAfterMigration(deleted, untouched []int) func(kvdb.RwTx) error {
|
||||
// Reading untouched buckets should return not nil
|
||||
for _, id := range untouched {
|
||||
chanID := lnwire.NewShortChanIDFromInt(uint64(id))
|
||||
sourceKey := makeLogKey(chanID.ToUint64())
|
||||
sourceKey := MakeLogKey(chanID.ToUint64())
|
||||
sourceBkt := fwdPkgBkt.NestedReadBucket(sourceKey[:])
|
||||
if sourceBkt == nil {
|
||||
return fmt.Errorf(
|
||||
@@ -259,7 +259,7 @@ func createTestFwdPkgBucket(tx kvdb.RwTx, chanID lnwire.ShortChannelID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
source := makeLogKey(chanID.ToUint64())
|
||||
source := MakeLogKey(chanID.ToUint64())
|
||||
if _, err := fwdPkgBkt.CreateBucketIfNotExists(source[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user