mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
wtdb: export versions of wtclient.db
We now make it possible to get the current db version of the wtclient.db. Moreover we can now fetch the latest available migration version for the client db. This allows us to compare whether the client.db has all the expected migrations applied.
This commit is contained in:
parent
d14f4c7e1f
commit
aaa0abc8a9
1 changed files with 27 additions and 0 deletions
|
@ -78,6 +78,12 @@ func getLatestDBVersion(versions []version) uint32 {
|
|||
return uint32(len(versions))
|
||||
}
|
||||
|
||||
// LatestDBMigrationVersion returns the number of the latest existing database
|
||||
// migration version available.
|
||||
func LatestDBMigrationVersion() uint32 {
|
||||
return getLatestDBVersion(clientDBVersions)
|
||||
}
|
||||
|
||||
// getMigrations returns a slice of all updates with a greater number that
|
||||
// curVersion that need to be applied to sync up with the latest version.
|
||||
func getMigrations(versions []version, curVersion uint32) []version {
|
||||
|
@ -91,6 +97,27 @@ func getMigrations(versions []version, curVersion uint32) []version {
|
|||
return updates
|
||||
}
|
||||
|
||||
// CurrentDatabaseVersion reads the current database version from the database
|
||||
// and returns it.
|
||||
func CurrentDatabaseVersion(db kvdb.Backend) (uint32, error) {
|
||||
var (
|
||||
version uint32
|
||||
err error
|
||||
)
|
||||
|
||||
err = kvdb.View(db, func(tx kvdb.RTx) error {
|
||||
version, err = getDBVersion(tx)
|
||||
return err
|
||||
}, func() {
|
||||
version = 0
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return version, nil
|
||||
}
|
||||
|
||||
// getDBVersion retrieves the current database version from the metadata bucket
|
||||
// using the dbVersionKey.
|
||||
func getDBVersion(tx kvdb.RTx) (uint32, error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue