Vixen
c7401864
csharp
public readonly record struct KeyHorizon

How long an applied idempotency key goes on being remembered.

Read the guide page for this →

Remarks

A ledger's key set is the only unbounded thing in a realm that cannot simply be cleared. It is what makes a retried trade write nothing the second time, so every key it drops is a retry it will silently apply twice — and a shard that runs for a week otherwise keeps every key of that week. Samples/14-Mmo's soak measured it as roughly a megabyte a minute, for ever.

⚠ The two failure modes are not comparable, and that asymmetry is the whole design. A horizon that is too long costs memory, which is visible in a graph and recoverable by restarting. A horizon that is too short duplicates an item, which is invisible, permanent, and indistinguishable from a duplication exploit when a player reports it. So there is no default horizon and Never is what a ledger is built with: leaking is the safe wrong answer, and a number nobody chose is not.

⚠ Which is why the only number a caller gives is the retry window, not the horizon. A retry window is a real quantity somebody knows — how long a client goes on resending an unacknowledged claim, how long an operator's replay tool reaches back. A horizon is that number times a margin, and letting it be written directly is letting somebody write one shorter than the window it has to outlive, which is the one mistake this type exists to make unrepresentable.

⚠ Guaranteed is the number that matters, and it is not Length. Forgetting happens a bucket at a time, so a key added just after a rotation is dropped nearly a full Length later and one added just before it is dropped one Interval sooner. The worst case is what a safety argument is made of, and it is the one asserted against the retry window.

Fields and properties (8)

  • public const int Buckets

    How many generations a bounded horizon is swept in.

  • public const int Windows

    How many retry windows the nominal horizon is.

  • public static KeyHorizon Never

    Forget nothing. What a ledger has until somebody says otherwise.

  • public TimeSpan RetryWindow

    The longest retry this horizon undertakes to survive.

  • public bool IsBounded

    Whether anything is ever forgotten.

  • public TimeSpan Length

    The nominal age at which a key stops being remembered.

  • public TimeSpan Interval

    How much of the horizon one generation covers.

  • public TimeSpan Guaranteed

    The shortest time any key is remembered for. The number the safety argument is about.

Methods (2)

  • public static KeyHorizon Outliving(TimeSpan retryWindow)

    A horizon that outlives a stated retry window.

  • public override string ToString()

    Returns the fully qualified type name of this instance.

Used by (4)

  • ShardMmo.Soak
  • HousekeepingTestsVixen.Live.Gameplay.Tests
  • KeyHorizonTestsVixen.Gameplay.Economy.Tests
  • MemoryEconomyLedgerVixen.Gameplay.Economy