Skip to content

Commit c7cd509

Browse files
committed
fix issues: discord retry, event state dedup, missing abi, config alert error handling, initial rule load req
1 parent 42828e1 commit c7cd509

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/alert-config/config-loader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,22 @@ export const getAlertRules = async (): Promise<AlertRule[]> => {
138138

139139
/**
140140
* Refresh alert rules periodically. Changes take effect without redeploy.
141+
* First load must succeed or the process exits — we can't run without rules.
141142
*/
142143
const refreshRulesIfStale = async (): Promise<void> => {
143144
if (Date.now() - lastRuleRefresh < REFRESH_INTERVAL_MS) return
144145
if (!process.env.ALERT_CONFIG_DB_URL) return
146+
const isFirstLoad = lastRuleRefresh === 0
145147
try {
146148
cachedRules = await loadRules()
147149
lastRuleRefresh = Date.now()
148150
console.log(`Alert config: loaded ${cachedRules.length} rules`)
149151
} catch (err) {
150-
console.error('Failed to load alert rules:', err)
152+
if (isFirstLoad) {
153+
console.error('FATAL: Failed to load alert rules on startup:', err)
154+
process.exit(1)
155+
}
156+
console.error('Failed to refresh alert rules (using cached):', err)
151157
}
152158
}
153159

src/notify/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const sendMessage = async (topic: Topic, message: WebhookMessageCreateOpt
6060
await clients[topic]?.send(message)
6161
} catch (err) {
6262
if (retries > 0) {
63-
await sendMessage(topic, message, retries - 1)
63+
return await sendMessage(topic, message, retries - 1)
6464
}
6565
throw err
6666
}

src/notify/event/event.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ export const registerDiscordRenderer = <const T extends EventArgs>(
6464
export const useEventState = (ctx: Context) => {
6565
const state = useProcessorState(ctx, 'eventState', {
6666
eventsHandled: new Set<string>(),
67-
isEventHandled: (log: Log) => state.eventsHandled.has(log.topics[0]),
68-
markEventHandled: (log: Log) => state.eventsHandled.add(log.topics[0]),
67+
isEventHandled: (log: Log) =>
68+
state.eventsHandled.has(`${log.block.height}:${log.transactionIndex}:${log.logIndex}`),
69+
markEventHandled: (log: Log) =>
70+
state.eventsHandled.add(`${log.block.height}:${log.transactionIndex}:${log.logIndex}`),
6971
})[0]
7072
return state
7173
}

src/processors/config-alert.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ export const createConfigAlertProcessor = async (chainId: number) => {
8787

8888
// Find the ABI event for notification
8989
const abiEvent = abiRegistry.getEvent(topic0)
90-
if (!abiEvent) continue
91-
9290
const eventInfo = abiRegistry.getEventInfo(topic0)
9391
const eventName = eventInfo?.name ?? topic0.slice(0, 10)
9492

93+
if (!abiEvent) {
94+
console.warn(`ConfigAlert: No ABI for topic0 ${topic0} (rule ${rule.id}), sending raw notification`)
95+
}
96+
9597
await notifyForEvent({
9698
ctx,
9799
name: rule.displayName ?? rule.topic,
98100
eventName,
99101
block,
100102
log,
101-
event: abiEvent,
103+
event: abiEvent ?? { topic: topic0, decode: () => undefined },
102104
topic: rule.topic,
103105
severity: rule.severity === 'low' ? undefined : rule.severity,
104106
notifyTarget: rule.notifyTargets ?? undefined,
105-
}).catch((e) => {
106-
console.error('ConfigAlert: Error notifying for event', eventName, e)
107107
})
108108
}
109109
}

0 commit comments

Comments
 (0)