fix(g1): NV$ Classified-Fee vor Profilmutation pruefen (#432)

* feat(economy): add optional preflight contract for fee-based operations

* fix(economy): reject unconfigured fee destination before classified mutation

* fix(classifieds): preflight NV$ charges and report non-atomic fee failures

* test(g1): lock fee preflight and classified reconciliation behavior

* ci(g1): run paid-classified preflight regression

* docs(g1): operational fee wallet setup and non-atomic classified risk
This commit is contained in:
OpenGenesis (MPL 2.0) authored and GitHub committed 2026-11-11 18:31:18 +01:00
1 parent 34d17eeba3
commit 1dd46384d0
6 files changed
+207 -4

No files matched your search

+4
View File
@@ -440,6 +440,10 @@ jobs:
shell: bash
run: python3 tools/ci/verify_firestorm_group_land_money.py
- name: Verify NV$ classifieds fee preflight and reconciliation
shell: bash
run: python3 tools/ci/verify_g1_classified_fee_preflight.py
- name: Verify citizen world map integration
shell: bash
run: python3 tools/ci/verify_citizen_world_map.py
@@ -31,6 +31,7 @@ namespace NexVerse.RegionModules.Economy
Id = "NexVerseMoneyModule")]
public sealed class NexVerseMoneyModule :
IMoneyModule,
IMoneyChargePreflight,
INexMasterBankPayoutModule,
ISharedRegionModule
{
@@ -242,6 +243,13 @@ namespace NexVerse.RegionModules.Economy
"[NEX-ECONOMY-VIEWER]: FeeWalletId must be a UUID.");
}
if (m_FeeWalletId.IsZero())
{
m_Log.Warn("[NEX-ECONOMY-VIEWER]: FeeWalletId fehlt. " +
"Kostenpflichtige Classifieds und andere Systemgebuehren " +
"koennen erst nach Einrichtung einer separaten NV$-Gebuehrenwallet gebucht werden.");
}
if (string.IsNullOrWhiteSpace(
m_WorldApiBaseUrl))
{
@@ -518,6 +526,47 @@ namespace NexVerse.RegionModules.Economy
amount;
}
// A separate fee destination is mandatory for system charges.
// Do not change AmountCovered: land and resident-to-resident transfers
// must continue to work even when system charges are unavailable.
public bool TryPreflightCharge(
UUID agentID,
int amount,
out string reason)
{
reason = string.Empty;
if (amount < 0)
{
reason = "Invalid NV$ charge amount.";
return false;
}
if (amount == 0)
return true;
if (!m_Enabled || m_Http == null)
{
reason = "NV$ fee service is unavailable.";
return false;
}
if (m_FeeWalletId.IsZero())
{
reason = "NV$ fee wallet is not configured. Please contact grid support.";
return false;
}
if (agentID.IsZero() || agentID == m_FeeWalletId)
{
reason = "Invalid NV$ fee payer.";
return false;
}
if (!AmountCovered(agentID, amount))
{
reason = "Insufficient NV$ or balance service unavailable.";
return false;
}
// Balance and configuration can change before the final transfer.
// The ledger debit remains the final authority.
return true;
}
public void ApplyCharge(
UUID agentID,
int amount,
+10
View File
@@ -48,4 +48,14 @@ namespace OpenSim.Framework
event ObjectPaid OnObjectPaid;
}
/// <summary>
/// Optional, non-breaking preflight for charged operations. Implementations
/// validate the fee destination and the available balance before callers
/// mutate external state. A successful preflight is not a payment guarantee.
/// </summary>
public interface IMoneyChargePreflight
{
bool TryPreflightCharge(UUID agentID, int amount, out string reason);
}
}
@@ -736,15 +736,33 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
bool exists = list.Cast<OSDMap>().Where(map => map.ContainsKey("classifieduuid"))
.Any(map => map["classifieduuid"].AsUUID().Equals(queryclassifiedID));
// Never trust a negative fee from the viewer. On a newly created
// classified, validate the configured fee destination *before*
// publishing the ad in the separate profile service.
if (queryclassifiedPrice < 0)
{
remoteClient.SendAgentAlertMessage("Invalid classified price.", false);
return;
}
IMoneyModule money = null;
if (!exists)
{
money = s.RequestModuleInterface<IMoneyModule>();
if (money is not null)
{
if (!money.AmountCovered(remoteClient.AgentId, queryclassifiedPrice))
bool feeReady;
string feeError = "Insufficient NV$ or fee service unavailable.";
if (money is IMoneyChargePreflight preflight)
feeReady = preflight.TryPreflightCharge(
remoteClient.AgentId, queryclassifiedPrice, out feeError);
else
feeReady = money.AmountCovered(
remoteClient.AgentId, queryclassifiedPrice);
if (!feeReady)
{
remoteClient.SendAgentAlertMessage("You do not have enough money to create this classified.", false);
remoteClient.SendAgentAlertMessage(feeError, false);
if(uce is not null && uce.classifiedsLists is not null)
remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
return;
@@ -778,8 +796,28 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
return;
}
// only charge if it worked
money?.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge);
// The legacy profile RPC and the NV$ ledger do not share a
// transaction. Report any post-publication debit failure instead
// of letting an unhandled exception escape the viewer job worker.
// Never retry an ambiguous debit with a fresh transfer ID.
if (money is not null && queryclassifiedPrice > 0)
{
try
{
money.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice,
MoneyTransactionType.ClassifiedCharge);
}
catch (Exception feeException)
{
m_log.ErrorFormat(
"[PROFILE CLASSIFIED]: Classified {0} for {1} was saved, " +
"but NV$ fee payment could not be confirmed; ledger/manual reconciliation required: {2}",
queryclassifiedID, creatorId, feeException.Message);
remoteClient.SendAgentAlertMessage(
"Classified saved, but NV$ payment could not be confirmed. " +
"Contact grid support before retrying.", true);
}
}
// just flush cache for now
lock(m_profilesCache)
@@ -0,0 +1,71 @@
# OpenGenesisLINK Generation 1 - NV$ Classified Fee Preflight
Status: Fix-Branch, Staging-/Build- und Betreiberabnahme erforderlich.
## Ursache
Beim Neuanlegen von Classifieds fuehrte `UserProfileModule.ClassifiedInfoUpdate`
den Aufruf `classified_update` gegen den Profilservice **vor** der
nachgelagerten `ApplyCharge`-Buchung aus. Mit leerem
`[NexEconomyViewer] FeeWalletId` schlug die Belastung danach mit
`InvalidOperationException: NV$ fee wallet is not configured.` fehl.
Der Eintrag konnte bereits gespeichert sein. Dies ist ein Problem der
Reihenfolge und der fehlenden Vorabvalidierung, nicht der RPC-Job-Engine.
## Aenderung
- Optionales Framework-Interface `IMoneyChargePreflight`. Bestehende andere
`IMoneyModule`-Implementierungen bleiben unveraendert.
- `NexVerseMoneyModule`: bei positiven Gebuehren fehlende/ungueltige
Zielwallet, deaktivierten Dienst, ungueltigen Zahler oder unzureichendes
Guthaben **vor** dem `classified_update` erkennen. Negative Preise
werden abgewiesen; Nullgebuehr folgt dem bisherigen Verhalten.
- Die Pruefung `AmountCovered` bleibt fuer Landkaeufe, Objektzahlungen und
Transfers unveraendert; eine fehlende Systemgebuehrenwallet blockiert
keine sonstigen NV$-Peer-to-Peer-Buchungen.
- Unerwartete Ledgerfehler *nach* dem Speichern loesen keine ungefangene
Job-Exception mehr aus. Der Viewer erhaelt eine Warnung, das Serverlog
enthaelt Classified- und Agent-UUID zur manuellen Abgleichung. Ein
unklarer Debit wird niemals blind mit neuer Transaktions-ID wiederholt.
## Betrieb
```ini
[NexEconomyViewer]
Enabled = true
WorldApiBaseUrl = "https://world.stadt-nexverse.de"
ApiKey = "${Environment|NEXVERSE_ECONOMY_API_KEY}"
; Die UUID muss zu einem tatsaechlich eingerichteten, separaten
; empfangsbereiten Service-/Systemwallet im zentralen NV$-Ledger gehoeren.
FeeWalletId = "<SYSTEM_FEE_WALLET_UUID>"
```
**Nicht** die Avatar-UUID eines beliebigen Bewohners, nicht UUID.Zero,
kein zufaelliger Platzhalter und nicht den privaten MasterBank-Payout-Account
ohne ausdrueckliche Berechtigung verwenden. Das Ledger muss Ueberweisungen
an diese Wallet erlauben. Konfiguration pro Simulator pruefen; Aenderungen
werden erst nach dem jeweiligen Neustart aktiv.
Vor erneuter Aktivierung alle zwischenzeitlich erstellten Classifieds
auf erfolgreich gebuchte NV$-Gebuehren abgleichen. Unbezahlte Eintraege
manuell sperren oder nach Betreiberentscheidung nachberechnen. Keine
automatische Rueckbuchung auf Verdacht.
## Abnahme
1. Fehlende FeeWalletId, positiver Classified-Preis: Viewer-Warnung,
**kein** `classified_update`, keine unbezahlte neue Anzeige.
2. Ungueltige negative Preisangabe: Ablehnung ohne Datenmutation.
3. Gueltige Wallet, Deckung vorhanden: genau eine Ledger-Buchung,
Anzeige und Saldo korrekt.
4. Fehlendes Guthaben: keine Anzeige und keine Buchung.
5. Peer-to-Peer-Transfer/Landkauf bei nicht konfigurierter FeeWalletId:
fuer dieses Szenario keine Regression der `AmountCovered`-Logik.
6. Simulierter World-API-Timeout **nach** `classified_update`:
kontrollierte Meldung, Log mit IDs und manueller Ledger-Abgleich.
7. Keine automatischen Mehrfachabbuchungen nach erneuten Viewer-Anfragen.
## Verbleibendes Architektur-Risiko
Profil-RPC und Ledgerbuchung sind keine gemeinsame Datenbanktransaktion.
Die Vorabpruefung beseitigt die *bekannte, deterministische*
Fehlerursache, aber keine Verbindungsabbrueche zwischen Speichern und
Belasten. Fuer echte atomare Zahlungspflicht braucht es einen zentralen
`pending -> paid/published`-Workflow mit langlebigem
Idempotency-Key, Reconciliation und reversibler Reservierung. Bis dahin
ist eine globale "exactly once"-Garantie nicht behauptet.
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""Source regression for paid-classified preflight and non-atomic payment handling."""
from pathlib import Path
root = Path(__file__).resolve().parents[2]
contract = (root / "OpenSim/Framework/IMoneyModule.cs").read_text()
money = (root / "NexVerse/RegionModules/Economy/NexVerseMoneyModule.cs").read_text()
profile = (root / "OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs").read_text()
assert "public interface IMoneyChargePreflight" in contract
assert "TryPreflightCharge(UUID agentID, int amount, out string reason)" in contract
assert "IMoneyChargePreflight," in money
preflight = money.split("public bool TryPreflightCharge(", 1)[1].split("public void ApplyCharge(", 1)[0]
for required in ("if (amount < 0)", "if (amount == 0)",
"m_FeeWalletId.IsZero()", "AmountCovered(agentID, amount)"):
assert required in preflight, required
classified = profile.split("public void ClassifiedInfoUpdate(", 1)[1].split(
"public void ClassifiedDelete(", 1)[0]
for required in ("if (queryclassifiedPrice < 0)",
"money is IMoneyChargePreflight preflight",
"preflight.TryPreflightCharge(",
'"classified_update"',
"catch (Exception feeException)",
"ledger/manual reconciliation required"):
assert required in classified, required
assert classified.index("preflight.TryPreflightCharge(") < classified.index('"classified_update"')
assert classified.index('"classified_update"') < classified.index("money.ApplyCharge(")
assert "Never retry an ambiguous debit" in classified
assert "NoMoney" not in classified
print("G1 classified fee preflight contract OK")