channeldb/db: check for db reversions on startup

This commit is contained in:
Conner Fromknecht 2018-08-02 16:46:17 -07:00
parent ee34b9c7b0
commit e23fc40d63
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -663,12 +663,24 @@ func (d *DB) syncVersions(versions []version) error {
}
}
// If the current database version matches the latest version number,
// then we don't need to perform any migrations.
latestVersion := getLatestDBVersion(versions)
log.Infof("Checking for schema update: latest_version=%v, "+
"db_version=%v", latestVersion, meta.DbVersionNumber)
if meta.DbVersionNumber == latestVersion {
switch {
// If the database reports a higher version that we are aware of, the
// user is probably trying to revert to a prior version of lnd. We fail
// here to prevent reversions and unintended corruption.
case meta.DbVersionNumber > latestVersion:
log.Errorf("Refusing to revert from db_version=%d to "+
"lower version=%d", meta.DbVersionNumber,
latestVersion)
return ErrDBReversion
// If the current database version matches the latest version number,
// then we don't need to perform any migrations.
case meta.DbVersionNumber == latestVersion:
return nil
}