Rebuild the state from the brokers after a restore and refuse an older copy

A restore, an import or an adopted database restarts protected: the engine
stays stopped, reads from the broker what the archive does not know (orders,
stops, executions, also from the OKX history up to 89 days), cancels orders
left working, protects what it finds and waits for the user. Strategies with
real money stay exit only until confirmed again. The database of before the
restore, put back by mistake, is refused by its fingerprint.

A failed migration leaves the engine off with one backup and a way to try
again; an archive is checked whole before the database is touched; a changed
secret key no longer crashes anything, and "anubis access reset" gives the
access back to whoever holds the computer. The image runs the db and access
commands without the guard.

refs #69

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 18:52:08 +01:00
1 parent 3da9b00f44
commit 4897594b87
40 files changed
+1871 -90

No files matched your search

+20 -4
View File
@@ -173,6 +173,8 @@ internal static partial class Forms
case LoginResult.SecondFactorNeeded:
limiter.Forgive(address);
return Results.Redirect(With(With("/accesso", "fattore", "1"), "ritorno", back));
case LoginResult.UnreadableSecondFactor:
return Results.Redirect(With("/accesso", "errore", "chiave"));
case LoginResult.WrongSecondFactor:
return Results.Redirect(With(With(With("/accesso", "fattore", "1"), "errore", "codice"), "ritorno", back));
default:
@@ -590,6 +592,10 @@ internal static partial class Forms
await stages.ConfirmLiveAsync(new Anubis.Trading.LiveConfirmation(strategy, account, form["frase"].ToString(), form["password"].ToString(),
string.IsNullOrWhiteSpace(code) ? null : code.Trim(), by), ct).ConfigureAwait(false);
return Results.Redirect("/strategie?ok=reale");
case "riconferma":
var second = form["codice"].ToString();
await stages.ReconfirmAsync(strategy, form["password"].ToString(), string.IsNullOrWhiteSpace(second) ? null : second.Trim(), by, ct).ConfigureAwait(false);
return Results.Redirect("/strategie?ok=riconferma");
default:
return Results.Redirect("/strategie?errore=scelta");
}
@@ -1041,6 +1047,14 @@ internal static partial class Forms
using var exclusive = await host.ExclusiveAsync(ct).ConfigureAwait(false);
var status = host.Status;
var db = host.Database;
if (choice == "riprova" && status.Mode == HostMode.SchemaProblem)
{
host.MigrationFailed = null;
exclusive.Dispose();
host.Wake();
return Results.Redirect("/");
}
if (status.Mode != HostMode.IdentityProblem || status.Identity is null || db is null)
{
return Results.Redirect("/");
@@ -1059,7 +1073,7 @@ internal static partial class Forms
}
await Archive.ImportAsync(db, Path.Combine(backup.Folder, Backups.ArchiveFolder), clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, adoptDatabaseIdentity: false, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Salvataggio ripristinato", ct).ConfigureAwait(false);
break;
case "importa" when verdict == IdentityVerdict.EmptyDatabase:
var folder = ServiceChoices.ImportFolders(config.Data).FirstOrDefault(f => Path.GetFileName(f) == form["archivio"].ToString());
@@ -1069,13 +1083,15 @@ internal static partial class Forms
}
await Archive.ImportAsync(db, folder, clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, adoptDatabaseIdentity: false, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Archivio importato", ct).ConfigureAwait(false);
break;
case "da-capo" when verdict == IdentityVerdict.EmptyDatabase:
Installation.StartOver(config.Data, clock);
break;
case "usa-questo" when verdict is IdentityVerdict.DifferentInstallation or IdentityVerdict.StaleDatabase:
await Installation.RenewAsync(db, config.Data, clock, adoptDatabaseIdentity: true, ct).ConfigureAwait(false);
case "usa-questo" when verdict is IdentityVerdict.DifferentInstallation or IdentityVerdict.StaleDatabase or IdentityVerdict.MissingFile:
// An old copy may have an old schema: it is brought up to date, after its own backup, before it is protected.
await host.MigrateAsync(new Backups(config.Data, clock), ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Database scelto dalla pagina d'errore", ct).ConfigureAwait(false);
break;
default:
return Results.Redirect("/?errore=scelta");