@senpi-ai/runtime 3.0.143 → 3.0.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/action-events.d.ts.map +1 -1
- package/dist/actions/action-events.js +2 -1
- package/dist/actions/action-events.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +3 -0
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/constants/telemetry.d.ts +17 -0
- package/dist/constants/telemetry.d.ts.map +1 -0
- package/dist/constants/telemetry.js +30 -0
- package/dist/constants/telemetry.js.map +1 -0
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +6 -2
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +0 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +4 -17
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +76 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/domain-events.d.ts.map +1 -1
- package/dist/runtime/domain-events.js +2 -0
- package/dist/runtime/domain-events.js.map +1 -1
- package/dist/runtime/events-telemetry.d.ts +120 -0
- package/dist/runtime/events-telemetry.d.ts.map +1 -0
- package/dist/runtime/events-telemetry.js +305 -0
- package/dist/runtime/events-telemetry.js.map +1 -0
- package/dist/runtime/run.d.ts +7 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +7 -0
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +21 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +51 -3
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategies-store.d.ts +26 -0
- package/dist/runtime/strategies-store.d.ts.map +1 -0
- package/dist/runtime/strategies-store.js +47 -0
- package/dist/runtime/strategies-store.js.map +1 -0
- package/dist/runtime/strategies-telemetry.d.ts +124 -0
- package/dist/runtime/strategies-telemetry.d.ts.map +1 -0
- package/dist/runtime/strategies-telemetry.js +143 -0
- package/dist/runtime/strategies-telemetry.js.map +1 -0
- package/dist/runtime-api/intake/intake-mount.d.ts +2 -0
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +6 -3
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +10 -0
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/state/state-manager.d.ts +2 -0
- package/dist/state/state-manager.d.ts.map +1 -1
- package/dist/state/state-manager.js +8 -0
- package/dist/state/state-manager.js.map +1 -1
- package/dist/telemetry/event-builders.d.ts +6 -0
- package/dist/telemetry/event-builders.d.ts.map +1 -1
- package/dist/telemetry/event-builders.js +6 -0
- package/dist/telemetry/event-builders.js.map +1 -1
- package/dist/telemetry/event-store.d.ts +6 -0
- package/dist/telemetry/event-store.d.ts.map +1 -1
- package/dist/telemetry/event-store.js +6 -6
- package/dist/telemetry/event-store.js.map +1 -1
- package/dist/telemetry/spans/redact-pii.d.ts.map +1 -1
- package/dist/telemetry/spans/redact-pii.js +13 -2
- package/dist/telemetry/spans/redact-pii.js.map +1 -1
- package/dist/utils/event-catalog.d.ts +6 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Events telemetry: the in-memory buffer of runtime event records, the tap that fills it from the
|
|
3
|
+
* per-wallet event sink, and the loop that broadcasts new records as `plugin.senpi.events`.
|
|
4
|
+
*/
|
|
5
|
+
import { EVENTS_BROADCAST_NAMES, EVENTS_CLOSED_RING_TTL_MS, EVENTS_EVENT_NAME, EVENTS_MAX_FRAME_BYTES, EVENTS_PER_STRATEGY, EVENTS_SEND_INTERVAL_MS, } from "../constants/telemetry.js";
|
|
6
|
+
import { normalizeStrategyAddress } from "../telemetry/event-store.js";
|
|
7
|
+
import { getDefaultPiiRedactor } from "../telemetry/spans/redact-pii.js";
|
|
8
|
+
import { JOIN_ATTR } from "../utils/event-catalog.js";
|
|
9
|
+
import { PROCESS_EPOCH } from "./strategies-telemetry.js";
|
|
10
|
+
const BROADCAST_NAMES = new Set(EVENTS_BROADCAST_NAMES);
|
|
11
|
+
/**
|
|
12
|
+
* One ring of `capacity` records per address. `seq` starts at 1 and counts across every address.
|
|
13
|
+
* `now` is the clock, in epoch ms, that times a closed ring.
|
|
14
|
+
*/
|
|
15
|
+
export function createEventsBuffer(capacity = EVENTS_PER_STRATEGY, now = () => Date.now()) {
|
|
16
|
+
const rings = new Map();
|
|
17
|
+
// Rings closed by `remove`, each with the time it was closed. Kept apart from `rings` so a new
|
|
18
|
+
// ring for the same address never mixes with them.
|
|
19
|
+
const closed = new Map();
|
|
20
|
+
let seq = 0;
|
|
21
|
+
let maxEvicted = 0;
|
|
22
|
+
return {
|
|
23
|
+
add(address, event) {
|
|
24
|
+
const key = normalizeStrategyAddress(address);
|
|
25
|
+
const attrs = {};
|
|
26
|
+
for (const [k, v] of Object.entries(event.attrs)) {
|
|
27
|
+
if (typeof v === "string" || typeof v === "boolean" || (typeof v === "number" && Number.isFinite(v)))
|
|
28
|
+
attrs[k] = v;
|
|
29
|
+
}
|
|
30
|
+
let ring = rings.get(key);
|
|
31
|
+
if (ring === undefined) {
|
|
32
|
+
ring = [];
|
|
33
|
+
rings.set(key, ring);
|
|
34
|
+
}
|
|
35
|
+
ring.push({ seq: ++seq, ts: event.ts, name: event.name, level: event.level, address: key, body: event.body, attrs });
|
|
36
|
+
if (ring.length > capacity)
|
|
37
|
+
maxEvicted = Math.max(maxEvicted, ring.shift().seq);
|
|
38
|
+
},
|
|
39
|
+
after(after) {
|
|
40
|
+
const out = [];
|
|
41
|
+
const collect = (ring) => {
|
|
42
|
+
let i = ring.length;
|
|
43
|
+
while (i > 0 && ring[i - 1].seq > after)
|
|
44
|
+
i--;
|
|
45
|
+
for (; i < ring.length; i++)
|
|
46
|
+
out.push(ring[i]);
|
|
47
|
+
};
|
|
48
|
+
for (const ring of rings.values())
|
|
49
|
+
collect(ring);
|
|
50
|
+
for (const ring of closed.keys())
|
|
51
|
+
collect(ring);
|
|
52
|
+
return out.sort((a, b) => a.seq - b.seq);
|
|
53
|
+
},
|
|
54
|
+
newestSeq() {
|
|
55
|
+
let newest = 0;
|
|
56
|
+
for (const ring of rings.values()) {
|
|
57
|
+
if (ring.length > 0)
|
|
58
|
+
newest = Math.max(newest, ring[ring.length - 1].seq);
|
|
59
|
+
}
|
|
60
|
+
// A closed ring is never empty.
|
|
61
|
+
for (const ring of closed.keys())
|
|
62
|
+
newest = Math.max(newest, ring[ring.length - 1].seq);
|
|
63
|
+
return newest;
|
|
64
|
+
},
|
|
65
|
+
maxEvictedSeq: () => maxEvicted,
|
|
66
|
+
remove(address) {
|
|
67
|
+
const key = normalizeStrategyAddress(address);
|
|
68
|
+
const ring = rings.get(key);
|
|
69
|
+
if (ring === undefined)
|
|
70
|
+
return;
|
|
71
|
+
rings.delete(key);
|
|
72
|
+
if (ring.length > 0)
|
|
73
|
+
closed.set(ring, now());
|
|
74
|
+
},
|
|
75
|
+
dropSent(sentSeq) {
|
|
76
|
+
const expiredAt = now() - EVENTS_CLOSED_RING_TTL_MS;
|
|
77
|
+
for (const [ring, closedAt] of closed) {
|
|
78
|
+
const newest = ring[ring.length - 1].seq;
|
|
79
|
+
if (newest > sentSeq && closedAt > expiredAt)
|
|
80
|
+
continue;
|
|
81
|
+
closed.delete(ring);
|
|
82
|
+
maxEvicted = Math.max(maxEvicted, newest);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** The process buffer. Its `seq` run belongs to `PROCESS_EPOCH`. */
|
|
88
|
+
export const eventsBuffer = createEventsBuffer();
|
|
89
|
+
/**
|
|
90
|
+
* Adds a record to `buffer` under `address` for a case that is not a runtime event. It does not go
|
|
91
|
+
* through `logger.event`, so no event sink, disk ring or OTel record receives it. A blank `address`
|
|
92
|
+
* adds nothing. Never throws.
|
|
93
|
+
*/
|
|
94
|
+
export function addEventRecord(address, event, buffer = eventsBuffer) {
|
|
95
|
+
try {
|
|
96
|
+
if (normalizeStrategyAddress(address) !== "")
|
|
97
|
+
buffer.add(address, event);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Callers are request handlers; a buffer failure must not fail the request.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Wraps a wallet's event sink. Every event goes to `sink`. An event whose name is in
|
|
105
|
+
* `EVENTS_BROADCAST_NAMES` is also added to `buffer` under `address`.
|
|
106
|
+
*/
|
|
107
|
+
export function withEventsTap(address, sink, buffer = eventsBuffer) {
|
|
108
|
+
return {
|
|
109
|
+
append(event) {
|
|
110
|
+
sink.append(event);
|
|
111
|
+
try {
|
|
112
|
+
if (BROADCAST_NAMES.has(event.name))
|
|
113
|
+
buffer.add(address, event);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// The tap runs inside `logger.event` and must not throw into it.
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
flush: () => sink.flush(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** The redacted value, or `undefined` when the redactor throws. `""` is kept as is. */
|
|
123
|
+
async function scrubString(value, redactor) {
|
|
124
|
+
if (value === "")
|
|
125
|
+
return value;
|
|
126
|
+
try {
|
|
127
|
+
const out = await redactor.redact(value);
|
|
128
|
+
return typeof out === "string" ? out : undefined;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Join-id attrs. They hold ids, never free text, and are sent as they are. */
|
|
135
|
+
const UNSCRUBBED_ATTRS = new Set([
|
|
136
|
+
...Object.values(JOIN_ATTR),
|
|
137
|
+
"senpi.strategy.address",
|
|
138
|
+
"senpi.scanner.id",
|
|
139
|
+
]);
|
|
140
|
+
/**
|
|
141
|
+
* A copy of the record with every string in `body` and `attrs` run through the redactor, except the
|
|
142
|
+
* join-id attrs in `UNSCRUBBED_ATTRS`. A string attr the redactor cannot produce is left out; such a
|
|
143
|
+
* `body` becomes `""`.
|
|
144
|
+
*/
|
|
145
|
+
export async function scrubEventRecord(record, redactor) {
|
|
146
|
+
const attrs = {};
|
|
147
|
+
for (const [key, value] of Object.entries(record.attrs)) {
|
|
148
|
+
if (typeof value !== "string" || UNSCRUBBED_ATTRS.has(key)) {
|
|
149
|
+
attrs[key] = value;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const scrubbed = await scrubString(value, redactor);
|
|
153
|
+
if (scrubbed !== undefined)
|
|
154
|
+
attrs[key] = scrubbed;
|
|
155
|
+
}
|
|
156
|
+
return { ...record, body: (await scrubString(record.body, redactor)) ?? "", attrs };
|
|
157
|
+
}
|
|
158
|
+
const bytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
159
|
+
/**
|
|
160
|
+
* Fills one frame of records: a JSON envelope of `envelopeBytes` whose `events` array holds the
|
|
161
|
+
* records, at most `maxBytes` serialized in total. `offer` answers `"added"`, `"full"` (the record
|
|
162
|
+
* does not fit what is already in the frame; it is not added) or `"oversize"` (the record does not
|
|
163
|
+
* fit an empty frame; it is not added). `take` returns the frame and starts an empty one.
|
|
164
|
+
*/
|
|
165
|
+
function createFramePacker(envelopeBytes, maxBytes) {
|
|
166
|
+
let frame = [];
|
|
167
|
+
let used = envelopeBytes;
|
|
168
|
+
return {
|
|
169
|
+
offer(record) {
|
|
170
|
+
const size = bytes(record);
|
|
171
|
+
if (envelopeBytes + size > maxBytes)
|
|
172
|
+
return { result: "oversize", bytes: size };
|
|
173
|
+
// One comma between two records.
|
|
174
|
+
const added = size + (frame.length > 0 ? 1 : 0);
|
|
175
|
+
if (used + added > maxBytes)
|
|
176
|
+
return { result: "full", bytes: size };
|
|
177
|
+
used += added;
|
|
178
|
+
frame.push(record);
|
|
179
|
+
return { result: "added", bytes: size };
|
|
180
|
+
},
|
|
181
|
+
take() {
|
|
182
|
+
const out = frame;
|
|
183
|
+
frame = [];
|
|
184
|
+
used = envelopeBytes;
|
|
185
|
+
return out;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The events part of the subscribe reply. A cursor whose `afterEpoch` is `epoch` selects the held
|
|
191
|
+
* records after `afterSeq`; any other cursor, or none, selects every held record. The newest
|
|
192
|
+
* selected records that fit `maxBytes` are served, scrubbed, in `seq` order. `truncated` is `true`
|
|
193
|
+
* when a record owed to the cursor was evicted, or a selected record was not served. A cursor of
|
|
194
|
+
* the current epoch is owed the records after `afterSeq`; a cursor of another epoch is owed every
|
|
195
|
+
* record of the current epoch; no cursor is owed nothing. Without a redactor no record is served.
|
|
196
|
+
*/
|
|
197
|
+
export async function buildEventsReplay(input) {
|
|
198
|
+
const buffer = input.buffer ?? eventsBuffer;
|
|
199
|
+
const epoch = input.epoch ?? PROCESS_EPOCH;
|
|
200
|
+
const maxBytes = input.maxBytes ?? EVENTS_MAX_FRAME_BYTES;
|
|
201
|
+
const redactor = input.redactor;
|
|
202
|
+
const afterSeq = input.cursor?.afterEpoch === epoch ? input.cursor.afterSeq : undefined;
|
|
203
|
+
let truncated = input.cursor !== undefined && buffer.maxEvictedSeq() > (afterSeq ?? 0);
|
|
204
|
+
if (redactor === null)
|
|
205
|
+
return { epoch, events: [], truncated: truncated || buffer.newestSeq() > (afterSeq ?? 0) };
|
|
206
|
+
const selected = buffer.after(afterSeq ?? 0);
|
|
207
|
+
const packer = createFramePacker(bytes({ epoch, events: [], truncated: false }), maxBytes);
|
|
208
|
+
// Newest first, one record at a time, until the frame is full.
|
|
209
|
+
for (let i = selected.length - 1; i >= 0; i--) {
|
|
210
|
+
const { result } = packer.offer(await scrubEventRecord(selected[i], redactor));
|
|
211
|
+
if (result === "added")
|
|
212
|
+
continue;
|
|
213
|
+
truncated = true;
|
|
214
|
+
// An oversize record is skipped and the older records are still served. A full reply ends here.
|
|
215
|
+
if (result === "full")
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
return { epoch, events: packer.take().reverse(), truncated };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Each tick takes the records added since the previous tick. With a broadcast function, it scrubs
|
|
222
|
+
* them and broadcasts them as one or more messages of at most `maxFrameBytes` serialized bytes. A
|
|
223
|
+
* record that does not fit an empty message is dropped and passed to `warn`. Without a broadcast
|
|
224
|
+
* function, the records are not sent. While there is no redactor, the tick sends nothing and keeps
|
|
225
|
+
* the records for the first tick that has one. Each tick ends with `dropSent`: it deletes the closed
|
|
226
|
+
* rings whose records it has passed, and the closed rings held past `EVENTS_CLOSED_RING_TTL_MS`.
|
|
227
|
+
*/
|
|
228
|
+
export function createEventsPublisher(deps) {
|
|
229
|
+
const buffer = deps.buffer ?? eventsBuffer;
|
|
230
|
+
const getRedactor = deps.getRedactor ?? getDefaultPiiRedactor;
|
|
231
|
+
const epoch = deps.epoch ?? PROCESS_EPOCH;
|
|
232
|
+
const maxFrameBytes = deps.maxFrameBytes ?? EVENTS_MAX_FRAME_BYTES;
|
|
233
|
+
// Upper bound of the message without its records.
|
|
234
|
+
const envelopeBytes = bytes({ v: 1, epoch, batchSeq: Number.MAX_SAFE_INTEGER, events: [] });
|
|
235
|
+
let lastSeq = 0;
|
|
236
|
+
let batchSeq = 0;
|
|
237
|
+
let timer;
|
|
238
|
+
let inFlight = false;
|
|
239
|
+
const send = (broadcast, events) => {
|
|
240
|
+
const message = { v: 1, epoch, batchSeq: ++batchSeq, events };
|
|
241
|
+
broadcast(EVENTS_EVENT_NAME, message, { dropIfSlow: true });
|
|
242
|
+
};
|
|
243
|
+
const tick = async () => {
|
|
244
|
+
if (inFlight)
|
|
245
|
+
return;
|
|
246
|
+
inFlight = true;
|
|
247
|
+
try {
|
|
248
|
+
if (deps.getBroadcast() === undefined) {
|
|
249
|
+
lastSeq = Math.max(lastSeq, buffer.newestSeq());
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const redactor = getRedactor();
|
|
253
|
+
if (redactor === null)
|
|
254
|
+
return;
|
|
255
|
+
const records = buffer.after(lastSeq);
|
|
256
|
+
if (records.length === 0)
|
|
257
|
+
return;
|
|
258
|
+
lastSeq = records[records.length - 1].seq;
|
|
259
|
+
const scrubbed = await Promise.all(records.map((record) => scrubEventRecord(record, redactor)));
|
|
260
|
+
const broadcast = deps.getBroadcast();
|
|
261
|
+
if (broadcast === undefined || timer === undefined)
|
|
262
|
+
return;
|
|
263
|
+
const packer = createFramePacker(envelopeBytes, maxFrameBytes);
|
|
264
|
+
for (const record of scrubbed) {
|
|
265
|
+
let offered = packer.offer(record);
|
|
266
|
+
if (offered.result === "full") {
|
|
267
|
+
send(broadcast, packer.take());
|
|
268
|
+
offered = packer.offer(record);
|
|
269
|
+
}
|
|
270
|
+
if (offered.result === "oversize") {
|
|
271
|
+
deps.warn?.("[senpi-runtime] event record exceeds the events frame size; dropped", {
|
|
272
|
+
seq: record.seq,
|
|
273
|
+
name: record.name,
|
|
274
|
+
address: record.address,
|
|
275
|
+
bytes: offered.bytes,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const last = packer.take();
|
|
280
|
+
if (last.length > 0)
|
|
281
|
+
send(broadcast, last);
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
deps.onError?.(err);
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
buffer.dropSent(lastSeq);
|
|
288
|
+
inFlight = false;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
start() {
|
|
293
|
+
if (timer !== undefined)
|
|
294
|
+
return;
|
|
295
|
+
timer = setInterval(() => void tick(), EVENTS_SEND_INTERVAL_MS);
|
|
296
|
+
timer.unref?.();
|
|
297
|
+
},
|
|
298
|
+
stop() {
|
|
299
|
+
if (timer !== undefined)
|
|
300
|
+
clearInterval(timer);
|
|
301
|
+
timer = undefined;
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=events-telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-telemetry.js","sourceRoot":"","sources":["../../src/runtime/events-telemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAoC,MAAM,6BAA6B,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAoB,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAE,aAAa,EAA8B,MAAM,2BAA2B,CAAC;AAwDtF,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB,mBAAmB,EAAE,MAAoB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IAC7G,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC/C,+FAA+F;IAC/F,mDAAmD;IACnD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAChD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,OAAO;QACL,GAAG,CAAC,OAAO,EAAE,KAAK;YAChB,MAAM,GAAG,GAAG,wBAAwB,CAAC,OAAO,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 +7,7 @@ import type { ScannerDataProviders } from "../scanners/engine/data-providers.js"
|
|
|
7
7
|
import type { ExternalScannerIngestRequest, ExternalScannerIngestResult } from "../scanners/external-scanner-receiver.js";
|
|
8
8
|
import type { ScannerSupervisionSource } from "../scanners/supervision.js";
|
|
9
9
|
import type { DslPlugin } from "../dsl/plugin/index.js";
|
|
10
|
+
import type { DslState } from "../types/dsl/index.js";
|
|
10
11
|
import type { ActionExecutionRecord, ActionFilter, ActionLatestState, ReadActionHistoryOptions } from "../actions/store/index.js";
|
|
11
12
|
import type { AuditQueryArgs, AuditQueryResult } from "./audit-query.types.js";
|
|
12
13
|
import type { RuntimeConfig } from "./runtime-schema.js";
|
|
@@ -31,6 +32,12 @@ export interface RunOptions {
|
|
|
31
32
|
export interface RuntimeHandle {
|
|
32
33
|
stop(): Promise<void>;
|
|
33
34
|
dsl: DslPlugin | null;
|
|
35
|
+
/**
|
|
36
|
+
* Active DSL states from the runtime's state manager memory. Empty when the runtime is not
|
|
37
|
+
* started or its committed recipe has no DSL. Unlike `dsl`, it keeps returning the states while
|
|
38
|
+
* an in-place update has no DSL plugin installed.
|
|
39
|
+
*/
|
|
40
|
+
listActiveDslStates(): DslState[];
|
|
34
41
|
/**
|
|
35
42
|
* Swap this runtime onto a new recipe in place, without restarting it.
|
|
36
43
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/runtime/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,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;;;;;OAOG;IACH,mBAAmB,IAAI,MAAM,CAAC;IAE9B;;;;;;;;;;;OAWG;IACH,aAAa,IAAI,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAE5E;;;;;;;OAOG;IACH,oBAAoB,CAClB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAErC;;;;;;;;;;;OAWG;IACH,yBAAyB,CACvB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,wBAAwB,GAC9B,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAsB,GAAG,CACvB,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,aAAa,CAAC,CAoGxB"}
|
package/dist/runtime/run.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { getDefaultStateDir } from "./default-state-dir.js";
|
|
5
5
|
import { loadRuntimeConfigWithRaw } from "./load-runtime-config.js";
|
|
6
6
|
import { Runtime } from "./runtime.js";
|
|
7
|
+
import { strategiesStore, strategyRecordFromConfig } from "./strategies-store.js";
|
|
7
8
|
/**
|
|
8
9
|
* Load trading recipe from path or content, create Runtime, start it, and return a handle with stop().
|
|
9
10
|
* Programmatic API used by the OpenClaw adapter and standalone CLI.
|
|
@@ -29,6 +30,9 @@ export async function run(recipePathOrContent, options) {
|
|
|
29
30
|
unresolvedConfig,
|
|
30
31
|
});
|
|
31
32
|
await runtime.start();
|
|
33
|
+
if (options?.runtimeId) {
|
|
34
|
+
strategiesStore.set(options.runtimeId, strategyRecordFromConfig(config));
|
|
35
|
+
}
|
|
32
36
|
return {
|
|
33
37
|
async stop() {
|
|
34
38
|
await runtime.stop();
|
|
@@ -43,6 +47,9 @@ export async function run(recipePathOrContent, options) {
|
|
|
43
47
|
get dsl() {
|
|
44
48
|
return runtime.dsl;
|
|
45
49
|
},
|
|
50
|
+
listActiveDslStates() {
|
|
51
|
+
return runtime.listActiveDslStates();
|
|
52
|
+
},
|
|
46
53
|
applyUpdatedConfig(next) {
|
|
47
54
|
return runtime.rebuildComponents(next);
|
|
48
55
|
},
|
package/dist/runtime/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/runtime/run.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/runtime/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmBH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AA6KlF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,mBAA2B,EAC3B,OAAoB;IAEpB,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC5C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,MAAM,wBAAwB,CAAC,mBAAmB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnH,MAAM,QAAQ,GACZ,CAAC,OAAO,OAAO,EAAE,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACpE,CAAC,CAAC,OAAO,CAAC,QAAQ;QAClB,CAAC,CAAC,kBAAkB,EAAE,CAAC;IAC3B,MAAM,YAAY,GAAG,OAAO,EAAE,YA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D,OAAO,OAAO,CAAC,0BAA0B,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAChE,CAAC;QACD,uBAAuB,CAAC,MAAgC;YACtD,OAAO,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,CAAC,eAAe;YACnB,OAAO,OAAO,CAAC,eAAe,EAAE,CAAC;QACnC,CAAC;QACD,KAAK,CAAC,cAAc;YAClB,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;QAClC,CAAC;QACD,6BAA6B;YAC3B,OAAO,OAAO,CAAC,6BAA6B,EAAE,CAAC;QACjD,CAAC;QACD,UAAU,CACR,IAAoB,EACpB,IAA+B;YAE/B,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC;QACD,mBAAmB;YACjB,OAAO,OAAO,CAAC,mBAAmB,EAAE,CAAC;QACvC,CAAC;QACD,aAAa;YACX,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;QACjC,CAAC;QACD,sBAAsB,CACpB,MAAqB;YAErB,OAAO,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;QACD,oBAAoB,CAClB,OAAe,EACf,UAAkB;YAElB,OAAO,OAAO,CAAC,oBAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;QACD,yBAAyB,CACvB,OAAe,EACf,UAAkB,EAClB,IAA+B;YAE/B,OAAO,OAAO,CAAC,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -8,6 +8,7 @@ import type { ScannerSupervisionSource } from "../scanners/supervision.js";
|
|
|
8
8
|
import type { McpTransport } from "../senpi/types.js";
|
|
9
9
|
import type { ScannerDataProviders } from "../scanners/engine/data-providers.js";
|
|
10
10
|
import { DslPlugin as DslPluginClass } from "../dsl/plugin/index.js";
|
|
11
|
+
import type { DslState } from "../types/dsl/index.js";
|
|
11
12
|
import type { RuntimeHealthStatus, RuntimeSystemState } from "../health/types.js";
|
|
12
13
|
import type { ActionExecutionRecord, ActionFilter, ActionLatestState, ReadActionHistoryOptions } from "../actions/store/types.js";
|
|
13
14
|
export interface RuntimeOptions {
|
|
@@ -36,6 +37,16 @@ export declare class Runtime {
|
|
|
36
37
|
private positionIdRegistry;
|
|
37
38
|
private scannerModule;
|
|
38
39
|
private dslPlugin;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the committed recipe runs DSL. Set where `commitComponents` installs the DSL plugin or
|
|
42
|
+
* installs none, so it tracks the plugin once committed. Teardown leaves it as it is: while a
|
|
43
|
+
* rebuild has stopped the old plugin and not yet committed the next one, it still describes the
|
|
44
|
+
* recipe whose positions are open. A rollback's own commit sets it from the restored recipe.
|
|
45
|
+
* When the rollback also fails, it is set to whether a DSL plugin is installed at that point:
|
|
46
|
+
* a rollback that committed the plugin and then failed to start the scanners still leaves the
|
|
47
|
+
* plugin managing the book, while a rollback that failed before the commit leaves none.
|
|
48
|
+
*/
|
|
49
|
+
private dslCommitted;
|
|
39
50
|
private senpi;
|
|
40
51
|
private healthStateModule;
|
|
41
52
|
private domainEventSubscriber;
|
|
@@ -114,6 +125,16 @@ export declare class Runtime {
|
|
|
114
125
|
private readonly runtimeBootId;
|
|
115
126
|
constructor(config: RuntimeConfig, options: RuntimeOptions);
|
|
116
127
|
get dsl(): DslPluginClass | null;
|
|
128
|
+
/**
|
|
129
|
+
* Active DSL states, read from the state manager's memory (no disk read). Empty when the runtime
|
|
130
|
+
* is not started or the committed recipe has no DSL.
|
|
131
|
+
*
|
|
132
|
+
* Reads the state manager rather than the DSL plugin because the state manager lives for the
|
|
133
|
+
* whole runtime, while a rebuild stops the plugin and sets it to null before the next one is
|
|
134
|
+
* created. Reading through the plugin would return nothing in that window for positions that
|
|
135
|
+
* are still open and protected.
|
|
136
|
+
*/
|
|
137
|
+
listActiveDslStates(): DslState[];
|
|
117
138
|
getHealthStatus(): Promise<RuntimeHealthStatus | null>;
|
|
118
139
|
getSystemState(): Promise<RuntimeSystemState | null>;
|
|
119
140
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI/E,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI/E,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AA4CjF,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAetD,OAAO,KAAK,EAKV,mBAAmB,EAC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,CAAC,IAAI,CAAC;IA8R5B;;OAEG;IACH,uEAAuE;IACvE;;;;;;;;OAQG;YACW,eAAe;IAK7B;;;;;;;;;;;;;;;;OAgBG;YACW,mBAAmB;IAsJjC;;;;;;;;;;;;OAYG;YACW,gBAAgB;IAiF9B;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAiE9B;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,mBAAmB;IAK3B;;;;;;;;;;;;OAYG;IACG,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAgB/C,uBAAuB;IA+CrC;;;;;;;;;;;;;;;;;;OAkBG;YACW,gBAAgB;IAmB9B;;;;;;;;;;;OAWG;YACW,4BAA4B;IASpC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAStD,0FAA0F;IACpF,6BAA6B,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpD;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;OAEG;YACW,iBAAiB;IAyI/B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAO5B;;;;OAIG;YACW,oBAAoB;IAmFlC;;;OAGG;YACW,kBAAkB;IAkB1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAYb,UAAU;CAyDzB"}
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createStrategyLifecycle } from "./strategy-lifecycle.js";
|
|
|
13
13
|
// RiskGuardianService removed — gate decisions are now real-time in checkGate
|
|
14
14
|
import { createRiskAuditLog } from "../risk/risk-audit-log.js";
|
|
15
15
|
import { createEventStore, registerEventSink, unregisterEventSink, flushEventSink } from "../telemetry/event-store.js";
|
|
16
|
+
import { eventsBuffer, withEventsTap } from "./events-telemetry.js";
|
|
16
17
|
import { createNotificationService } from "./notifications.js";
|
|
17
18
|
import { resolveStrategyConfig } from "./map-strategies.js";
|
|
18
19
|
import { mapRuntimeExitToDslConfig } from "./map-exit-config.js";
|
|
@@ -69,6 +70,16 @@ export class Runtime {
|
|
|
69
70
|
positionIdRegistry;
|
|
70
71
|
scannerModule;
|
|
71
72
|
dslPlugin = null;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the committed recipe runs DSL. Set where `commitComponents` installs the DSL plugin or
|
|
75
|
+
* installs none, so it tracks the plugin once committed. Teardown leaves it as it is: while a
|
|
76
|
+
* rebuild has stopped the old plugin and not yet committed the next one, it still describes the
|
|
77
|
+
* recipe whose positions are open. A rollback's own commit sets it from the restored recipe.
|
|
78
|
+
* When the rollback also fails, it is set to whether a DSL plugin is installed at that point:
|
|
79
|
+
* a rollback that committed the plugin and then failed to start the scanners still leaves the
|
|
80
|
+
* plugin managing the book, while a rollback that failed before the commit leaves none.
|
|
81
|
+
*/
|
|
82
|
+
dslCommitted = false;
|
|
72
83
|
// riskGuardian removed — gate decisions are now real-time in checkGate
|
|
73
84
|
senpi = null;
|
|
74
85
|
healthStateModule = null;
|
|
@@ -163,6 +174,20 @@ export class Runtime {
|
|
|
163
174
|
get dsl() {
|
|
164
175
|
return this.dslPlugin;
|
|
165
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Active DSL states, read from the state manager's memory (no disk read). Empty when the runtime
|
|
179
|
+
* is not started or the committed recipe has no DSL.
|
|
180
|
+
*
|
|
181
|
+
* Reads the state manager rather than the DSL plugin because the state manager lives for the
|
|
182
|
+
* whole runtime, while a rebuild stops the plugin and sets it to null before the next one is
|
|
183
|
+
* created. Reading through the plugin would return nothing in that window for positions that
|
|
184
|
+
* are still open and protected.
|
|
185
|
+
*/
|
|
186
|
+
listActiveDslStates() {
|
|
187
|
+
if (!this.started || !this.dslCommitted)
|
|
188
|
+
return [];
|
|
189
|
+
return this.stateManager.listAllActiveDslStatesSync();
|
|
190
|
+
}
|
|
166
191
|
async getHealthStatus() {
|
|
167
192
|
return this.healthStateModule?.getHealthStatus() ?? null;
|
|
168
193
|
}
|
|
@@ -447,7 +472,8 @@ export class Runtime {
|
|
|
447
472
|
const strategyAddress = this.strategyConfig.address;
|
|
448
473
|
// Local domain-event ring. Always on (independent of the OTLP collector) so the agent can query
|
|
449
474
|
// the trade narrative locally; the singleton logger taps it by wallet via this registration.
|
|
450
|
-
|
|
475
|
+
// The tap also copies the `plugin.senpi.events` names into the process events buffer.
|
|
476
|
+
registerEventSink(strategyAddress, withEventsTap(strategyAddress, createEventStore(stateDir, strategyAddress)));
|
|
451
477
|
this.eventSinkAddress = strategyAddress;
|
|
452
478
|
// Strategy-lifecycle tracker: owns the self-pause state that RiskGuard used to hold and
|
|
453
479
|
// fires the hook + notification on a running→paused transition. RiskGuard stays stateless
|
|
@@ -834,9 +860,11 @@ export class Runtime {
|
|
|
834
860
|
reconcileGateResolve: () => this.resolveReconcileGate(),
|
|
835
861
|
identity: buildIdentityEnvelope,
|
|
836
862
|
});
|
|
863
|
+
this.dslCommitted = true;
|
|
837
864
|
}
|
|
838
865
|
else {
|
|
839
866
|
this.dslPlugin = null;
|
|
867
|
+
this.dslCommitted = false;
|
|
840
868
|
}
|
|
841
869
|
this.healthStateModule = createHealthStateModule({
|
|
842
870
|
runtimeName: config.name,
|
|
@@ -1012,6 +1040,7 @@ export class Runtime {
|
|
|
1012
1040
|
rebuildError: err,
|
|
1013
1041
|
rollbackError: rollbackErr,
|
|
1014
1042
|
});
|
|
1043
|
+
this.dslCommitted = this.dslPlugin !== null;
|
|
1015
1044
|
throw new RuntimeRebuildRollbackFailedError(this.strategyConfig.address, err, rollbackErr);
|
|
1016
1045
|
}
|
|
1017
1046
|
// The runtime is healthy again on its previous recipe; the update itself did not apply.
|
|
@@ -1263,13 +1292,28 @@ export class Runtime {
|
|
|
1263
1292
|
this.resolveReconcileGate();
|
|
1264
1293
|
return;
|
|
1265
1294
|
}
|
|
1295
|
+
// The reconcile runs inside the runtime's tracking context, like the signal consumer and the
|
|
1296
|
+
// DSL monitor tick. When the runtime identity resolves, the events it causes on the bus (e.g.
|
|
1297
|
+
// `position.closed` for an archived state) carry it and route to this wallet's event sink.
|
|
1298
|
+
const identity = this.resolveTraceIdentity();
|
|
1299
|
+
const reconcileContext = {
|
|
1300
|
+
runId: "",
|
|
1301
|
+
address,
|
|
1302
|
+
recipeName: this.config.name,
|
|
1303
|
+
runtimeId: this.options.runtimeId ?? "",
|
|
1304
|
+
runtimeVersion: VERSION,
|
|
1305
|
+
runtimeBootId: this.runtimeBootId,
|
|
1306
|
+
identityAttributes: identity
|
|
1307
|
+
? identityTraceAttributes(identity)
|
|
1308
|
+
: undefined,
|
|
1309
|
+
};
|
|
1266
1310
|
let attempt = 0;
|
|
1267
1311
|
while (!this.reconcileStopped) {
|
|
1268
1312
|
attempt++;
|
|
1269
1313
|
const t0 = Date.now();
|
|
1270
1314
|
let result;
|
|
1271
1315
|
try {
|
|
1272
|
-
result = await runReconcile({
|
|
1316
|
+
result = await trackingContext.run(reconcileContext, () => runReconcile({
|
|
1273
1317
|
address,
|
|
1274
1318
|
strategyState,
|
|
1275
1319
|
senpi: this.senpi,
|
|
@@ -1277,7 +1321,7 @@ export class Runtime {
|
|
|
1277
1321
|
adopter: this.dslPlugin,
|
|
1278
1322
|
bus: this.bus,
|
|
1279
1323
|
serialize,
|
|
1280
|
-
});
|
|
1324
|
+
}));
|
|
1281
1325
|
}
|
|
1282
1326
|
catch (err) {
|
|
1283
1327
|
logger.warn("[runtime][reconcile] runReconcile threw unexpectedly", { address, attempt, err });
|
|
@@ -1316,6 +1360,10 @@ export class Runtime {
|
|
|
1316
1360
|
// doesn't discard events that were enqueued but not yet written.
|
|
1317
1361
|
await flushEventSink(this.eventSinkAddress);
|
|
1318
1362
|
unregisterEventSink(this.eventSinkAddress);
|
|
1363
|
+
// The wallet's `plugin.senpi.events` ring closes with its sink. The events loop deletes it
|
|
1364
|
+
// once its records are passed, or once it has been closed for `EVENTS_CLOSED_RING_TTL_MS`.
|
|
1365
|
+
// A later runtime on the same wallet starts with an empty ring.
|
|
1366
|
+
eventsBuffer.remove(this.eventSinkAddress);
|
|
1319
1367
|
this.eventSinkAddress = null;
|
|
1320
1368
|
}
|
|
1321
1369
|
}
|