diff --git a/Aetheria.State.AuthoritySmoke/Program.cs b/Aetheria.State.AuthoritySmoke/Program.cs index d9b2d3efc..245e42e61 100644 --- a/Aetheria.State.AuthoritySmoke/Program.cs +++ b/Aetheria.State.AuthoritySmoke/Program.cs @@ -1006,7 +1006,10 @@ internal sealed class AuthoritySmokeChecks runtimeId, startServer: false, enableDurableShardLogs: false).ConfigureAwait(false); - return node.ReadCommittedCommandFacts(); + return node.Documents() + .OrderBy(fact => fact.CommittedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(fact => fact.FactId ?? "", StringComparer.Ordinal) + .ToArray(); } private static void TrustedCommittedFactsConvergeLocalRuns() diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index b740c9d97..3ac0fa722 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -129,7 +129,10 @@ static async Task TickAsync( .GetAll() .Select(ToLoadoutTemplateCommit) .ToArray(); - var observedCommands = node.ReadObservedDaemonCommands(); + var observedCommands = node.Documents() + .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) + .ToArray(); var accountedCommandIds = new HashSet( currentFrame?.AccountedCommandIds ?? Array.Empty(), StringComparer.Ordinal); @@ -140,7 +143,7 @@ static async Task TickAsync( var authorityPolicy = await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy).ReadAsync().ConfigureAwait(false); var starbridgeScenario = await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest).ReadAsync().ConfigureAwait(false); var starbridgeSession = await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest).ReadAsync().ConfigureAwait(false); - var authorityLeases = node.ReadAuthorityLeases(); + var authorityLeases = node.Documents(); var authorizedCommands = AetheriaRuntimeAuthorityRouter.AuthorizedCommands( pendingObservedCommands, authorityPolicy, @@ -510,7 +513,9 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost( .ToArray(); } - var factPuts = node.ReadCommittedCommandFacts() + var factPuts = node.Documents() + .OrderBy(fact => fact.CommittedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(fact => fact.FactId ?? "", StringComparer.Ordinal) .Select(fact => new { Fact = fact, @@ -793,7 +798,7 @@ static async Task PublishDaemonApiDocumentsAsync( static async Task AcceptEveCommandsAsync(AetheriaStateNode node, AetheriaDaemonHostOptions options) { - var commandCountBefore = node.ReadObservedEveCommands().Count; + var commandCountBefore = node.Documents().Count; var now = DateTimeOffset.UtcNow.ToString("O"); try { diff --git a/Aetheria.State.Smoke/Program.cs b/Aetheria.State.Smoke/Program.cs index dfafad4d4..ea154edc1 100644 --- a/Aetheria.State.Smoke/Program.cs +++ b/Aetheria.State.Smoke/Program.cs @@ -162,7 +162,10 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s statePath, "aetheria-state-smoke-command-check")) { - if (commandVerifyNode.ReadObservedDaemonCommands().All(command => + if (commandVerifyNode.Documents() + .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) + .All(command => command.Kind != AetheriaRuntimeDaemonCommandKinds.SensorPing || command.ClientId != "aetheria-state-smoke-command-client")) { @@ -555,7 +558,11 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s statePath, "aetheria-state-smoke-eve-command-check")) { - if (commandVerifyNode.ReadObservedEveCommands().All(command => + if (commandVerifyNode.Documents() + .Select(AetheriaRuntimeEveCommandClient.NormalizeDocument) + .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) + .All(command => command.Kind != AetheriaRuntimeEveCommandKind.SetBindingOverride || command.ClientId != "aetheria-state-smoke-eve-command-client")) { diff --git a/Aetheria.State.Unity.Smoke/Program.cs b/Aetheria.State.Unity.Smoke/Program.cs index d9cc4565c..75ad5d08d 100644 --- a/Aetheria.State.Unity.Smoke/Program.cs +++ b/Aetheria.State.Unity.Smoke/Program.cs @@ -198,8 +198,16 @@ try Enabled = eveCommand.InputSettings.Enabled } }); - var eveSubmitted = eveCommandNode.ReadObservedEveCommands(); - if (eveSubmitted.Count != 1 || + await eveCommandNode.FlushAsync(); + await using var eveCommandCheckNode = await AetheriaStateNode.OpenAsync( + commitSmokeStatePath, + "aetheria-unity-runtime-eve-command-check"); + var eveSubmitted = eveCommandCheckNode.Documents() + .Select(AetheriaRuntimeEveCommandClient.NormalizeDocument) + .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) + .ToArray(); + if (eveSubmitted.Length != 1 || eveSubmitted[0].Schema != AetheriaRuntimeEveCommandClient.CommandSchema || eveSubmitted[0].CommandId != eveCommand.CommandId || eveSubmitted[0].ProviderId != "aetheria" || @@ -209,7 +217,18 @@ try eveSubmitted[0].PlayerSettings == null || eveSubmitted[0].InputSettings == null) { - throw new InvalidOperationException("Runtime Eve command state record did not preserve typed command envelopes separately from state commits."); + var submitted = eveSubmitted.Length > 0 ? eveSubmitted[0] : null; + throw new InvalidOperationException( + "Runtime Eve command state record did not preserve typed command envelopes separately from state commits. " + + $"Count={eveSubmitted.Length}, " + + $"Schema={submitted?.Schema ?? ""}, " + + $"CommandId={submitted?.CommandId ?? ""} expected {eveCommand.CommandId}, " + + $"ProviderId={submitted?.ProviderId ?? ""}, " + + $"SurfaceId={submitted?.SurfaceId ?? ""}, " + + $"Command={submitted?.Command ?? ""}, " + + $"Kind={submitted?.Kind.ToString() ?? ""}, " + + $"PlayerSettings={(submitted?.PlayerSettings == null ? "null" : "present")}, " + + $"InputSettings={(submitted?.InputSettings == null ? "null" : "present")}."); } } finally diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 479b110a5..4a3544ba4 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -10059,7 +10059,6 @@ static void RequireTypedDaemonCommandPayloads(string root) "public const string DefaultClientId = \"aetheria-daemon-client\"", "ClientId = string.IsNullOrWhiteSpace(clientId) ? DefaultClientId : clientId", "private AetheriaRuntimeDaemonCommandEnvelope Send(AetheriaRuntimeDaemonCommandDocument command)", - "ReadObservedDaemonCommands()", "Func submit", "return Submit((client, frame) => client.SetTarget(frame, targetEntityKey));", "return Send((client, frame) => client.TransferCargoItem(", @@ -10393,6 +10392,7 @@ static void RequireAetheriaStateNodeUsesManagedPointers(string root) "public static CultRecordKey MigrationLedgerKey { get; }", "public static CultRecordKey LegacyCatalogQuarantineKey { get; }", "public CultMeshMutableStatePointer MutableDocument(CultRecordKey key)", + "public IReadOnlyList Documents()", "private CultMeshMutableStatePointer MutableDocumentPointer(CultRecordKey key)", "CultMesh.MutableStatePointer(" }; @@ -10472,7 +10472,11 @@ static void RequireAetheriaStateNodeUsesManagedPointers(string root) "public CultMeshMutableStatePointer DaemonGameSurface()", "public CultMeshMutableStatePointer DaemonGameTuiSurface()", "public CultMeshMutableStatePointer DaemonEditorSurface()", - "public CultMeshMutableStatePointer DaemonEditorTuiSurface()" + "public CultMeshMutableStatePointer DaemonEditorTuiSurface()", + "ReadObservedDaemonCommands(", + "ReadCommittedCommandFacts(", + "ReadAuthorityLeases(", + "ReadObservedEveCommands(" }; var survivingSymbols = forbiddenSymbols .Where(symbol => stateNode.Contains(symbol, StringComparison.Ordinal)) @@ -11044,7 +11048,7 @@ static void RequireDaemonVersePublication(string root) "AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface", "AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface", "AetheriaEveCommandBridge.AcceptObservedAsync(", - "ReadObservedDaemonCommands()", + "node.Documents()", "currentFrame?.AccountedCommandIds ?? Array.Empty()", "AetheriaRuntimeDaemonTickRunner.Tick(", "node.MutableDocument(AetheriaStateNode.EveCommandAcceptanceStatusKey).ReadAsync()", @@ -11168,7 +11172,7 @@ static void RequireDaemonVersePublication(string root) "server.OnCultNet", StringComparison.Ordinal); var snapshotHandlerEnd = snapshotHandlerStart >= 0 - ? daemonHostSource.IndexOf("var factPuts = node.ReadCommittedCommandFacts()", snapshotHandlerStart, StringComparison.Ordinal) + ? daemonHostSource.IndexOf("var factPuts = node.Documents()", snapshotHandlerStart, StringComparison.Ordinal) : -1; var snapshotHandler = snapshotHandlerStart >= 0 && snapshotHandlerEnd > snapshotHandlerStart ? daemonHostSource.Substring(snapshotHandlerStart, snapshotHandlerEnd - snapshotHandlerStart) @@ -12373,10 +12377,10 @@ static void RequireTypedEveCommandBodies(string root) "ToDocument(", "AcceptObservedAsync(", "switch (command.Kind)", - "node.ReadObservedEveCommands()", + "node.Documents()", + "AetheriaRuntimeEveCommandClient.NormalizeDocument", "AccountedCommandIds", "SubmitEveCommandAsync(", - "ReadObservedEveCommands(", "EveCommandKey(", "typeof(AetheriaRuntimeEveCommandDocument)", "SubmitPlayerSettingsCommand(", diff --git a/Aetheria.State/AetheriaEveCommandBridge.cs b/Aetheria.State/AetheriaEveCommandBridge.cs index 81128ca20..639e6a1de 100644 --- a/Aetheria.State/AetheriaEveCommandBridge.cs +++ b/Aetheria.State/AetheriaEveCommandBridge.cs @@ -33,7 +33,10 @@ public static class AetheriaEveCommandBridge var accepted = new List(); var rejected = new List(); var accounted = new HashSet(accountedCommandIds ?? Array.Empty(), StringComparer.Ordinal); - foreach (var command in node.ReadObservedEveCommands() + foreach (var command in node.Documents() + .Select(AetheriaRuntimeEveCommandClient.NormalizeDocument) + .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) + .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) .Where(command => !string.IsNullOrWhiteSpace(command.CommandId)) .Where(command => !accounted.Contains(command.CommandId))) { diff --git a/Aetheria.State/AetheriaStateNode.cs b/Aetheria.State/AetheriaStateNode.cs index f43eb1073..63885c056 100644 --- a/Aetheria.State/AetheriaStateNode.cs +++ b/Aetheria.State/AetheriaStateNode.cs @@ -96,6 +96,12 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return MutableDocumentPointer(key); } + public IReadOnlyList Documents() + where TDocument : class + { + return Cache.GetAll().ToArray(); + } + public CultMeshDocumentHandle RuntimeCatalog() { return _runtimeCatalog ??= CultMesh.Document( @@ -159,15 +165,6 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return Database.PutAsync(DaemonCommandKey(command.CommandId), command); } - public IReadOnlyList ReadObservedDaemonCommands() - { - return Cache - .GetAll() - .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) - .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) - .ToArray(); - } - public Task> PutCommittedCommandFactAsync( AetheriaRuntimeCommittedCommandFactDocument fact) { @@ -183,20 +180,6 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable fact); } - public IReadOnlyList ReadCommittedCommandFacts() - { - return Cache - .GetAll() - .OrderBy(fact => fact.CommittedAtUtc ?? "", StringComparer.Ordinal) - .ThenBy(fact => fact.FactId ?? "", StringComparer.Ordinal) - .ToArray(); - } - - public IReadOnlyList ReadAuthorityLeases() - { - return Cache.GetAll().ToArray(); - } - private static CultRecordKey DaemonCommandKey(string commandId) { return new CultRecordKey($"daemon:commands:{StableToken(commandId)}:gamecult.aetheria.daemon_command.v1"); @@ -216,16 +199,6 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return Database.PutAsync(EveCommandKey(command.CommandId), command); } - public IReadOnlyList ReadObservedEveCommands() - { - return Cache - .GetAll() - .Select(AetheriaRuntimeEveCommandClient.NormalizeDocument) - .OrderBy(command => command.IssuedAtUtc ?? "", StringComparer.Ordinal) - .ThenBy(command => command.CommandId ?? "", StringComparer.Ordinal) - .ToArray(); - } - private static CultRecordKey EveCommandKey(string commandId) { return new CultRecordKey($"eve:commands:{StableToken(commandId)}:gamecult.eve.command.v1");