Skip to content

Commit eadd4b8

Browse files
committed
Throttles Background Notary Proofs on Failure
If a user is having issues with notary proofs, this PR prevents background rollback proofs for an hour after a failure. Ref CSF-753
1 parent 7ae1fea commit eadd4b8

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/lib/alarms/rollback.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {PingRollbackTrade} from '../bridge/handlers/ping_rollback_trade';
44
import {TradeStatus} from '../types/steam_constants';
55
import {isBackgroundNotaryRollbackEnabled, proveTradesInBackground} from './notary';
66
import {reportTradeError} from './error_report';
7+
import {gStore} from '../storage/store';
8+
import {StorageKey} from '../storage/keys';
79

810
interface RollbackTradeInfo {
911
steamTrade: TradeHistoryStatus;
@@ -52,13 +54,22 @@ export async function pingRollbackTrades(pendingTrades: SlimTrade[], tradeHistor
5254
}
5355

5456
if (await isBackgroundNotaryRollbackEnabled()) {
55-
try {
56-
await proveTradesInBackground(rollbackTrades.map((r) => r.steamTrade));
57-
console.log(`proved ${rollbackTrades.length} rollback trade(s) via notary`);
58-
return;
59-
} catch (e) {
60-
console.error('notary proving failed, falling back to legacy ping', e);
61-
reportTradeError(rollbackTrades[0].csfloatTrade.id, `background extension notary failed: ${e}`);
57+
const lastFailure = await gStore.getWithStorage<number>(
58+
chrome.storage.local,
59+
StorageKey.LAST_NOTARY_BG_PROOF_FAILURE
60+
);
61+
if (lastFailure && lastFailure > Date.now() - 60 * 60 * 1000) {
62+
console.log('skipping notary proof, last failure was less than 60 minutes ago');
63+
} else {
64+
try {
65+
await proveTradesInBackground(rollbackTrades.map((r) => r.steamTrade));
66+
console.log(`proved ${rollbackTrades.length} rollback trade(s) via notary`);
67+
return;
68+
} catch (e) {
69+
console.error('notary proving failed, falling back to legacy ping', e);
70+
await gStore.setWithStorage(chrome.storage.local, StorageKey.LAST_NOTARY_BG_PROOF_FAILURE, Date.now());
71+
reportTradeError(rollbackTrades[0].csfloatTrade.id, `background extension notary failed: ${e}`);
72+
}
6273
}
6374
}
6475

src/lib/storage/keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum StorageKey {
1212
ACCESS_TOKEN = 'access_token',
1313
LAST_TRADE_PING_ATTEMPT = 'last_trade_ping_attempt',
1414
LAST_TRADE_BLOCKED_PING_ATTEMPT = 'last_trade_blocked_ping_attempt',
15+
LAST_NOTARY_BG_PROOF_FAILURE = 'last_notary_bg_proof_failure',
1516
PRICE_CACHE = 'price_cache', // Stores market hash name -> price mapping (~0.86MB)
1617
SCHEMA_CACHE = 'schema_cache', // Stores the full CSFloat schema payload
1718
}

0 commit comments

Comments
 (0)