Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/migration30"
"github.com/lightningnetwork/lnd/channeldb/migration31"
"github.com/lightningnetwork/lnd/channeldb/migration32"
"github.com/lightningnetwork/lnd/channeldb/migration33"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/invoices"
Expand Down Expand Up @@ -291,6 +292,10 @@ var (
number: 32,
migration: migration32.MigrateMCRouteSerialisation,
},
{
number: 33,
migration: migration33.MigrateMCStoreNameSpacedResults,
},
}

// optionalVersions stores all optional migrations that are applied
Expand Down
2 changes: 2 additions & 0 deletions channeldb/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/migration30"
"github.com/lightningnetwork/lnd/channeldb/migration31"
"github.com/lightningnetwork/lnd/channeldb/migration32"
"github.com/lightningnetwork/lnd/channeldb/migration33"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/kvdb"
)
Expand Down Expand Up @@ -44,5 +45,6 @@ func UseLogger(logger btclog.Logger) {
migration30.UseLogger(logger)
migration31.UseLogger(logger)
migration32.UseLogger(logger)
migration33.UseLogger(logger)
kvdb.UseLogger(logger)
}
14 changes: 14 additions & 0 deletions channeldb/migration33/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package migration33

import (
"github.com/btcsuite/btclog"
)

// log is a logger that is initialized as disabled. This means the package will
// not perform any logging by default until a logger is set.
var log = btclog.Disabled

// UseLogger uses a specified Logger to output package logging info.
func UseLogger(logger btclog.Logger) {
log = logger
}
69 changes: 69 additions & 0 deletions channeldb/migration33/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package migration33

import (
"bytes"

"github.com/lightningnetwork/lnd/kvdb"
)

var (
// resultsKey is the fixed key under which the attempt results are
// stored.
resultsKey = []byte("missioncontrol-results")

// defaultMCNamespaceKey is the key of the default mission control store
// namespace.
defaultMCNamespaceKey = []byte("default")
)

// MigrateMCStoreNameSpacedResults reads in all the current mission control
// entries and re-writes them under a new default namespace.
func MigrateMCStoreNameSpacedResults(tx kvdb.RwTx) error {
log.Infof("Migrating Mission Control store to use namespaced results")

// Get the top level bucket. All the MC results are currently stored
// as KV pairs in this bucket
topLevelBucket := tx.ReadWriteBucket(resultsKey)

// If the results bucket does not exist then there are no entries in
// the mission control store yet and so there is nothing to migrate.
if topLevelBucket == nil {
return nil
}

// Create a new default namespace bucket under the top-level bucket.
defaultNSBkt, err := topLevelBucket.CreateBucket(defaultMCNamespaceKey)
if err != nil {
return err
}

// Iterate through each of the existing result pairs, write them to the
// new namespaced bucket. Also collect the set of keys so that we can
// later delete them from the top level bucket.
var keys [][]byte
err = topLevelBucket.ForEach(func(k, v []byte) error {
// Skip the new default namespace key.
if bytes.Equal(k, defaultMCNamespaceKey) {
return nil
}

// Collect the key.
keys = append(keys, k)

// Write the pair under the default namespace.
return defaultNSBkt.Put(k, v)
})
if err != nil {
return err
}

// Finally, iterate through the set of keys and delete them from the
// top level bucket.
for _, k := range keys {
if err := topLevelBucket.Delete(k); err != nil {
return err
}
}

return err
}
41 changes: 41 additions & 0 deletions channeldb/migration33/migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package migration33

import (
"testing"

"github.com/lightningnetwork/lnd/channeldb/migtest"
"github.com/lightningnetwork/lnd/kvdb"
)

var (
// before represents the structure of the MC store before the migration.
before = map[string]interface{}{
"key1": "result1",
"key2": "result2",
"key3": "result3",
"key4": "result4",
}

// after represents the expected structure of the store after the
// migration. It should be identical to before except all the kv pairs
// are now under a new default namespace key.
after = map[string]interface{}{
string(defaultMCNamespaceKey): before,
}
)

// TestMigrateMCStoreNameSpacedResults tests that the MC store results are
// correctly moved to be under a new default namespace bucket.
func TestMigrateMCStoreNameSpacedResults(t *testing.T) {
before := func(tx kvdb.RwTx) error {
return migtest.RestoreDB(tx, resultsKey, before)
}

after := func(tx kvdb.RwTx) error {
return migtest.VerifyDB(tx, resultsKey, after)
}

migtest.ApplyMigration(
t, before, after, MigrateMCStoreNameSpacedResults, false,
)
}
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
store](https://github.com/lightningnetwork/lnd/pull/8911) to use a more
minimal encoding for payment attempt routes.

* [Migrate the mission control
store](https://github.com/lightningnetwork/lnd/pull/9001) so that results are
namespaced. All existing results are written to the "default" namespace.

## Code Health

## Tooling and Documentation
Expand Down
13 changes: 8 additions & 5 deletions routing/integrated_routing_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,15 @@ func (c *integratedRoutingContext) testPayment(maxParts uint32,
}
})

// Instantiate a new mission control with the current configuration
// Instantiate a new mission controller with the current configuration
// values.
mc, err := NewMissionControl(db, c.source.pubkey, &c.mcCfg)
if err != nil {
c.t.Fatal(err)
}
mcController, err := NewMissionController(db, c.source.pubkey, &c.mcCfg)
require.NoError(c.t, err)

mc, err := mcController.GetNamespacedStore(
DefaultMissionControlNamespace,
)
require.NoError(c.t, err)

getBandwidthHints := func(_ Graph) (bandwidthHints, error) {
// Create bandwidth hints based on local channel balances.
Expand Down
Loading