@ddd-qc/cell-proxy 0.34.5 → 0.34.6
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/CellProxy.d.ts +1 -0
- package/dist/CellProxy.d.ts.map +1 -1
- package/dist/CellProxy.js +37 -26
- package/dist/CellProxy.js.map +1 -1
- package/package.json +1 -1
package/dist/CellProxy.d.ts
CHANGED
package/dist/CellProxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellProxy.d.ts","sourceRoot":"","sources":["../src/CellProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,eAAe,EACf,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAY,KAAK,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAEL,OAAO,EAAE,QAAQ,EAKjB,QAAQ,EACT,MAAM,SAAS,CAAC;AAEjB,OAAO,cAAc,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,QAAQ,EACR,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAC,YAAY,EAAS,MAAM,SAAS,CAAC;AAS7C,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,OAA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,OAAO,CAAC,OAAO,CAAC;IA2BvD,YAAY,CAAC,QAAQ,CAAC,EAAE,QAAQ;CAkGjC"}
|
package/dist/CellProxy.js
CHANGED
|
@@ -106,10 +106,11 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
106
106
|
async executeZomeCall(reqLog) {
|
|
107
107
|
reqLog.executionTimestamp = Date.now();
|
|
108
108
|
const requestIndex = this._requestLog.length;
|
|
109
|
-
|
|
109
|
+
this._requestLog.push(reqLog);
|
|
110
|
+
let respLog = undefined;
|
|
110
111
|
if (this._canThrottle) {
|
|
111
|
-
const isSpam = this._reqThrottle.has(reqHash);
|
|
112
|
-
if (isSpam || this._reqLive.has(reqHash)) {
|
|
112
|
+
const isSpam = this._reqThrottle.has(reqLog.reqHash);
|
|
113
|
+
if (isSpam || this._reqLive.has(reqLog.reqHash)) {
|
|
113
114
|
console.warn(`THROTTLING ${isSpam ? "SPAM" : "LIVE"} ${reqLog.request.zome_name}::${reqLog.request.fn_name}() ${prettyDate(new Date(reqLog.executionTimestamp))}`);
|
|
114
115
|
return {
|
|
115
116
|
requestIndex,
|
|
@@ -118,26 +119,27 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
118
119
|
throttled: true,
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
this._reqThrottle.add(reqHash);
|
|
122
|
+
this._reqThrottle.add(reqLog.reqHash);
|
|
122
123
|
}
|
|
123
|
-
this._reqLive.add(reqHash);
|
|
124
|
-
this._requestLog.push(reqLog);
|
|
124
|
+
this._reqLive.add(reqLog.reqHash);
|
|
125
125
|
try {
|
|
126
126
|
const response = await this._appProxy.callZome(reqLog.request, reqLog.timeout);
|
|
127
|
-
this._reqLive.delete(reqHash);
|
|
128
|
-
|
|
129
|
-
this._responseLog.push(respLog);
|
|
130
|
-
return respLog;
|
|
127
|
+
this._reqLive.delete(reqLog.reqHash);
|
|
128
|
+
respLog = { requestIndex, success: response, timestamp: Date.now() };
|
|
131
129
|
}
|
|
132
130
|
catch (e) {
|
|
133
|
-
this._reqLive.delete(reqHash);
|
|
134
|
-
|
|
131
|
+
this._reqLive.delete(reqLog.reqHash);
|
|
132
|
+
respLog = { requestIndex, failure: e, timestamp: Date.now() };
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
if (!respLog) {
|
|
136
|
+
respLog = { requestIndex, failure: "No response", timestamp: Date.now() };
|
|
137
|
+
}
|
|
135
138
|
this._responseLog.push(respLog);
|
|
136
|
-
return respLog;
|
|
137
139
|
}
|
|
140
|
+
return respLog;
|
|
138
141
|
}
|
|
139
142
|
logCallTimedOut(reqLog) {
|
|
140
|
-
reqLog.executionTimestamp = Date.now();
|
|
141
143
|
const requestIndex = this._requestLog.length;
|
|
142
144
|
this._requestLog.push(reqLog);
|
|
143
145
|
const respLog = { requestIndex, failure: "Waiting for Mutex timed-out", timestamp: Date.now() };
|
|
@@ -145,13 +147,14 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
145
147
|
return respLog;
|
|
146
148
|
}
|
|
147
149
|
async callZomeBlockPostCommit(entryType, zome_name, fn_name, payload, cap_secret, timeout) {
|
|
148
|
-
timeout = timeout
|
|
150
|
+
timeout = timeout ?? this.defaultTimeoutMs;
|
|
149
151
|
const req = {
|
|
150
152
|
cap_secret, zome_name, fn_name, payload,
|
|
151
153
|
cell_id: this.cell.address.intoId(),
|
|
152
154
|
provenance: this.cell.address.agentId.hash,
|
|
153
155
|
};
|
|
154
|
-
const
|
|
156
|
+
const reqHash = await sha256(JSON.stringify(req));
|
|
157
|
+
const log = { request: req, reqHash, timeout, requestTimestamp: Date.now(), executionTimestamp: 0 };
|
|
155
158
|
console.debug("postCommit Lock in progress...");
|
|
156
159
|
try {
|
|
157
160
|
this._postCommitRelease = await this._callMutex.acquire();
|
|
@@ -167,13 +170,14 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
167
170
|
return respLog.success;
|
|
168
171
|
}
|
|
169
172
|
async callZomeBlocking(zome_name, fn_name, payload, cap_secret, timeout) {
|
|
170
|
-
timeout = timeout
|
|
173
|
+
timeout = timeout ?? this.defaultTimeoutMs;
|
|
171
174
|
const req = {
|
|
172
175
|
cap_secret, zome_name, fn_name, payload,
|
|
173
176
|
cell_id: this.cell.address.intoId(),
|
|
174
177
|
provenance: this.cell.address.agentId.hash,
|
|
175
178
|
};
|
|
176
|
-
const
|
|
179
|
+
const reqHash = await sha256(JSON.stringify(req));
|
|
180
|
+
const log = { request: req, reqHash, timeout, requestTimestamp: Date.now(), executionTimestamp: 0 };
|
|
177
181
|
let release;
|
|
178
182
|
try {
|
|
179
183
|
release = await this._callMutex.acquire();
|
|
@@ -195,13 +199,14 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
195
199
|
return respLog.success;
|
|
196
200
|
}
|
|
197
201
|
async callZome(zome_name, fn_name, payload, cap_secret, timeoutMs) {
|
|
198
|
-
timeoutMs = timeoutMs
|
|
202
|
+
timeoutMs = timeoutMs ?? this.defaultTimeoutMs;
|
|
199
203
|
const req = {
|
|
200
204
|
cap_secret, zome_name, fn_name, payload,
|
|
201
205
|
cell_id: this.cell.address.intoId(),
|
|
202
206
|
provenance: this.cell.address.agentId.hash,
|
|
203
207
|
};
|
|
204
|
-
const
|
|
208
|
+
const reqHash = await sha256(JSON.stringify(req));
|
|
209
|
+
const log = { request: req, reqHash, timeout: timeoutMs, requestTimestamp: Date.now(), executionTimestamp: 0 };
|
|
205
210
|
try {
|
|
206
211
|
await this._callMutex.waitForUnlock();
|
|
207
212
|
}
|
|
@@ -280,6 +285,14 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
280
285
|
}
|
|
281
286
|
}
|
|
282
287
|
dumpCallLogs(zomeName) {
|
|
288
|
+
let requestTable = [];
|
|
289
|
+
for (const request of this._requestLog) {
|
|
290
|
+
const waitTime = prettyDuration(new Date(request.executionTimestamp - request.requestTimestamp));
|
|
291
|
+
const log = { timestamp: prettyDate(new Date(request.executionTimestamp)), reqHash: request.reqHash.slice(0, 8), fn: request.request.fn_name, timeout: request.timeout, waitTime };
|
|
292
|
+
requestTable.push(log);
|
|
293
|
+
}
|
|
294
|
+
console.warn(`Dumping call request logs for cell "${this._appProxy.getLocations(this.cell.address)}" for zome "${zomeName}"`);
|
|
295
|
+
console.table(requestTable);
|
|
283
296
|
let result = [];
|
|
284
297
|
let call_map = new Map();
|
|
285
298
|
for (const response of this._responseLog) {
|
|
@@ -297,8 +310,8 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
297
310
|
}
|
|
298
311
|
const output = anyToB64(response.failure ? response.failure : response.success);
|
|
299
312
|
const log = zomeName
|
|
300
|
-
? { startTime, fnName: requestLog.request.fn_name, input, output, duration, waitTime }
|
|
301
|
-
: { startTime, zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime };
|
|
313
|
+
? { reqIndex: response.requestIndex, startTime, reqHash: requestLog.reqHash.slice(0, 8), fnName: requestLog.request.fn_name, input, output, duration, waitTime }
|
|
314
|
+
: { reqIndex: response.requestIndex, startTime, reqHash: requestLog.reqHash.slice(0, 8), zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime };
|
|
302
315
|
result.push(log);
|
|
303
316
|
let maybe_value = call_map.get(requestLog.request.fn_name);
|
|
304
317
|
if (!maybe_value) {
|
|
@@ -308,10 +321,7 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
308
321
|
call_map.set(requestLog.request.fn_name, [maybe_value[0] + 1, maybe_value[1] + duration_ts]);
|
|
309
322
|
}
|
|
310
323
|
}
|
|
311
|
-
console.warn(`Dumping call logs for cell "${this._appProxy.getLocations(this.cell.address)}"`);
|
|
312
|
-
if (zomeName) {
|
|
313
|
-
console.warn(` - For zome "${zomeName}"`);
|
|
314
|
-
}
|
|
324
|
+
console.warn(`Dumping call response logs for cell "${this._appProxy.getLocations(this.cell.address)}" for zome "${zomeName}"`);
|
|
315
325
|
console.table(result);
|
|
316
326
|
let summary = [];
|
|
317
327
|
for (const [fn_name, values] of call_map) {
|
|
@@ -319,6 +329,7 @@ export class CellProxy extends CellMixin(Empty) {
|
|
|
319
329
|
summary.push(log);
|
|
320
330
|
}
|
|
321
331
|
summary.sort((a, b) => b.count - a.count);
|
|
332
|
+
console.warn(`Dumping call map for cell "${this._appProxy.getLocations(this.cell.address)}" for zome "${zomeName}"`);
|
|
322
333
|
console.table(summary);
|
|
323
334
|
const zomeSignals = this._appProxy.signalLogs.filter((log) => log.type == AppSignalType.Zome);
|
|
324
335
|
const sysSignals = zomeSignals.filter((log) => {
|
package/dist/CellProxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellProxy.js","sourceRoot":"","sources":["../src/CellProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAOG,UAAU,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,MAAM,UAAU,CAAC;AAE1C,OAAO,EAIL,aAAa,EAId,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAM/C,OAAO,EAAC,UAAU,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAe,MAAM,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAgCnC,MAAM,OAAO,SAAU,SAAQ,SAAS,CAAC,KAAK,CAAC;IAG7C,YACU,SAAmB,EAC3B,IAAU,EAEV,cAAuB;QAEvB,KAAK,EAAE,CAAC;QALA,cAAS,GAAT,SAAS,CAAU;QAqBrB,gBAAW,GAAiB,EAAE,CAAA;QAC9B,iBAAY,GAAkB,EAAE,CAAA;QAGhC,aAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;QAC7B,iBAAY,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAA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E,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;YAC5C,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;YACvC,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;YAC3D,MAAM,GAAG,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAA;YACtI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAC3B,CAAC;CAGF","sourcesContent":["import {\n AppSignal,\n SignalCb,\n CallZomeRequest,\n CapSecret,\n Timestamp,\n ZomeName,\n Signal, SignalType,\n} from \"@holochain/client\";\nimport {CellMixin, Empty} from \"./mixins\";\nimport {Cell} from \"./cell\";\nimport {\n CellIdStr,\n DnaInfo, EntryDef,\n EntryDefsCallbackResult,\n AppSignalType,\n SystemPulse,\n\n ZomeInfo\n} from \"./types\";\nimport {Mutex, withTimeout} from \"async-mutex\";\nimport MutexInterface from \"async-mutex/lib/MutexInterface\";\nimport {\n AppProxy,\n SignalUnsubscriber,\n} from \"./AppProxy\";\nimport {prettyDate, prettyDuration} from \"./pretty\";\nimport {anyToB64, intoAnyId} from \"./hash\";\nimport {MyDictionary, sha256} from \"./utils\";\nimport {TimeMap} from \"./time-map\";\nimport {\n SystemAttestationVariantPostCommitEntry,\n SystemAttestationVariantSelfCallEnd,\n SystemAttestationVariantSelfCallStart\n} from \"./zomeSignals.types\";\n\n\nexport interface RequestLog {\n request: CallZomeRequest,\n timeout: number,\n requestTimestamp: number,\n executionTimestamp: number,\n}\n\nexport interface ResponseLog {\n success?: unknown,\n failure?: unknown,\n throttled?: boolean,\n timestamp: number,\n requestIndex: number;\n}\n\n\nexport type Cb = () => Promise<unknown>\n\n/**\n * Proxy for a running DNA.\n * It logs and queues ZomeCalls.\n * It holds a reference to its AppProxy and its Cell.\n * This class is expected to be used by ZomeProxies.\n */\nexport class CellProxy extends CellMixin(Empty) {\n\n /** Ctor */\n constructor(\n private _appProxy: AppProxy,\n cell: Cell,\n //public readonly dnaDef: MyDnaDef,\n defaultTimeout?: number,\n ) {\n super();\n this._cell = cell;\n console.log(`CellProxy.ctor`, cell);\n this.defaultTimeoutMs = defaultTimeout ? defaultTimeout : 10 * 1000;\n this._callMutex = withTimeout(new Mutex(), this.defaultTimeoutMs);\n\n ///*const _unsub =*/ this.addSignalHandler((sig) => this.blockSelfCall(sig));\n /*const _unsub =*/ this.addSignalHandler((sig) => this.blockUntilPostCommit(sig));\n }\n\n /** -- Fields -- */\n\n defaultTimeoutMs: number;\n protected _callMutex: MutexInterface;\n\n /** append only logs */\n private _requestLog: RequestLog[] = []\n private _responseLog: ResponseLog[] = []\n\n /** Throttle: Don't allow the exact same call within 200ms or if the first identical call hasn't returned yet */\n private _reqLive = new Set<string>();\n private _reqThrottle = new TimeMap(200, 10);\n private _canThrottle: boolean = true;\n setCanThrottle(can: boolean) {this._canThrottle = can};\n\n /** Cache */\n private _entryDefCache: MyDictionary<MyDictionary<EntryDef>> = {};\n private _zomeInfoCache: MyDictionary<ZomeInfo> = {};\n private _dnaInfoCache?: DnaInfo;\n\n\n /** -- Methods -- */\n\n getHappShareCode(): string | null { return this._appProxy.getHappShareCode(this.cell.baseRoleName)}\n\n\n /** Have a PostCommitEntry attestation release the Mutex */\n private _postCommitRelease?: MutexInterface.Releaser;\n private _postCommitReleaseEntryType?: string;\n protected async blockUntilPostCommit(signal: Signal) {\n if (SignalType.App != signal.type) {\n return;\n }\n const appSignal: AppSignal = signal.value;\n const zomeSignal = this._appProxy.intoZomeSignal(appSignal);\n if (!zomeSignal || zomeSignal.pulses.length == 0) {\n return;\n }\n console.debug(\"blockUntilPostCommit()\", zomeSignal, this._postCommitReleaseEntryType, !!this._postCommitRelease);\n const signalType = Object.keys(zomeSignal.pulses[0]!)[0];\n if (signalType != \"System\" || !this._postCommitRelease || !this._postCommitReleaseEntryType) {\n return;\n }\n for (const pulse of zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if (sys.type !== \"PostCommitEntry\") {\n continue;\n }\n const pce = sys as SystemAttestationVariantPostCommitEntry;\n if (!pce.succeeded) {\n console.error(\"PostCommit attestations failed\");\n this.dumpCallLogs(appSignal.zome_name);\n this.dumpSignalLogs(appSignal.zome_name);\n }\n if (pce.app_entry_type !== this._postCommitReleaseEntryType) {\n continue;\n }\n /** Release */\n console.debug(\"blockUntilPostCommit() postCommit Lock RELEASE\");\n this._postCommitRelease();\n delete this._postCommitRelease;\n delete this._postCommitReleaseEntryType;\n break;\n }\n }\n\n\n /** Have a self call acquire & the call Mutex */\n private _selfCallRelease?: MutexInterface.Releaser;\n protected async blockSelfCall(signal: AppSignal) {\n const zomeSignal = this._appProxy.intoZomeSignal(signal);\n if (!zomeSignal || zomeSignal.pulses.length == 0 || Object.keys(zomeSignal.pulses[0]!)[0] != 'System') {\n return;\n }\n for (const pulse of zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if (sys.type == \"SelfCallStart\") {\n console.log(\"\")\n /** Acquire lock */\n try {\n this._callMutex.acquire().then((r) => this._selfCallRelease = r)\n } catch (e) {\n console.error(\"A Zome self call is initialized during a writing zome call\", e);\n }\n }\n if (sys.type == \"SelfCallEnd\" && this._selfCallRelease) {\n /** Release */\n this._selfCallRelease();\n delete this._selfCallRelease;\n const end = sys as SystemAttestationVariantSelfCallEnd;\n if (!end.succeeded) {\n console.error(\"Call to self failed.\")\n this.dumpCallLogs(end.zome_name);\n this.dumpSignalLogs(end.zome_name);\n }\n }\n }\n }\n\n\n /** */\n purgeLogs() {\n this._responseLog = [];\n this._requestLog = [];\n this._appProxy.purgeLogs();\n }\n\n /** */\n addSignalHandler(handler: SignalCb): SignalUnsubscriber {\n return this._appProxy.addSignalHandler(handler, this.cell.hcl().toString());\n }\n\n\n /** */\n dumpSignalLogs(zomeName?: ZomeName, canAppSignals?: boolean) {\n this._appProxy.dumpSignalLogs(canAppSignals? canAppSignals : true, this.cell.address, zomeName);\n }\n\n\n /** */\n get signalLogs() {\n return this._appProxy.signalLogs.filter((log) => log.cellAddr.equals(this.cell.address));\n }\n\n\n /** Pass the call request to the conductor proxy and log it */\n private async executeZomeCall(reqLog: RequestLog): Promise<ResponseLog> {\n //console.log(\"executeZomeCall()\", reqLog.request.zome_name, reqLog.request.fn_name);\n reqLog.executionTimestamp = Date.now();\n const requestIndex = this._requestLog.length;\n /** Throttle */\n const reqHash = await sha256(JSON.stringify(reqLog.request));\n if (this._canThrottle) {\n const isSpam = this._reqThrottle.has(reqHash);\n if (isSpam || this._reqLive.has(reqHash)) {\n console.warn(`THROTTLING ${isSpam? \"SPAM\" : \"LIVE\"} ${reqLog.request.zome_name}::${reqLog.request.fn_name}() ${prettyDate(new Date(reqLog.executionTimestamp))}`);\n return {\n requestIndex,\n timestamp: reqLog.executionTimestamp,\n failure: \"Throttled spam: \" + reqLog.request.fn_name + \"()\",\n throttled: true,\n };\n }\n this._reqThrottle.add(reqHash);\n }\n /** */\n this._reqLive.add(reqHash);\n this._requestLog.push(reqLog);\n try {\n const response = await this._appProxy.callZome(reqLog.request, reqLog.timeout);\n this._reqLive.delete(reqHash);\n const respLog = { requestIndex, success: response, timestamp: Date.now() };\n this._responseLog.push(respLog);\n return respLog;\n } catch (e) {\n this._reqLive.delete(reqHash);\n const respLog = { requestIndex, failure: e, timestamp: Date.now() }\n this._responseLog.push(respLog);\n return respLog;\n }\n }\n\n\n /** Pass the call request to conductor proxy and log it */\n logCallTimedOut(reqLog: RequestLog): ResponseLog {\n reqLog.executionTimestamp = Date.now();\n const requestIndex = this._requestLog.length;\n this._requestLog.push(reqLog);\n const respLog = { requestIndex, failure: \"Waiting for Mutex timed-out\", timestamp: Date.now() }\n this._responseLog.push(respLog);\n return respLog;\n }\n\n\n /**\n * callZome() with Mutex (for calls that writes to source-chain)\n * TODO: Implement call queue instead of mutex?\n */\n async callZomeBlockPostCommit(entryType: string, zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<unknown> {\n /** Create RequestLog */\n timeout = timeout? timeout : this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const log = { request: req, timeout, requestTimestamp: Date.now() } as RequestLog;\n /** Acquire lock */\n console.debug(\"postCommit Lock in progress...\");\n try {\n this._postCommitRelease = await this._callMutex.acquire();\n this._postCommitReleaseEntryType = entryType;\n } catch(e) {\n console.warn(\"Waiting for callZomeBlockPostCommit mutex timed-out\", e);\n this.logCallTimedOut(log)\n return Promise.reject(\"Waiting for callZomeBlockPostCommit mutex timed-out\");\n }\n console.debug(\"postCommit Lock ACQUIRED\");\n /** Execute */\n const respLog = await this.executeZomeCall(log);\n return respLog.success;\n }\n\n\n /**\n * callZome() with Mutex (for calls that writes to source-chain)\n * TODO: Implement call queue instead of mutex?\n */\n async callZomeBlocking(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<unknown> {\n /** Create RequestLog */\n timeout = timeout? timeout : this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const log = { request: req, timeout, requestTimestamp: Date.now() } as RequestLog;\n\n /** Acquire lock */\n let release;\n try {\n release = await this._callMutex.acquire();\n } catch(e) {\n console.warn(\"Waiting for callZomeBlocking mutex timed-out\", e);\n this.logCallTimedOut(log)\n return Promise.reject(\"Waiting for callZomeBlocking mutex timed-out\");\n }\n /** Execute */\n const respLog = await this.executeZomeCall(log);\n /** Release */\n release();\n if (respLog.failure) {\n if (!respLog.throttled) {\n this.dumpCallLogs(zome_name);\n this.dumpSignalLogs(zome_name);\n }\n return Promise.reject(respLog);\n }\n return respLog.success;\n }\n\n\n /** On success returns the data returned by the zome function */\n async callZome(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeoutMs?: number): Promise<unknown> {\n /** Create RequestLog */\n timeoutMs = timeoutMs? timeoutMs : this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const log = { request: req, timeout: timeoutMs, requestTimestamp: Date.now() } as RequestLog;\n /** Wait for lock */\n try {\n await this._callMutex.waitForUnlock();\n } catch(e) {\n console.warn(\"Waiting for callZome mutex timed-out\", e);\n this.logCallTimedOut(log);\n return Promise.reject(\"Waiting for callZome mutex timed-out\");\n }\n /** Execute & return response */\n const respLog = await this.executeZomeCall(log);\n if (respLog.failure) {\n if (!respLog.throttled) {\n this.dumpCallLogs(zome_name);\n this.dumpSignalLogs(zome_name);\n }\n return Promise.reject(respLog);\n }\n return respLog.success;\n }\n\n\n /**\n * Calls the `entry_defs()` zome function and\n * Returns an array of all the zome's AppEntryNames and Visibility, i.e. (AppEntryName, isPublic)[]\n */\n async callEntryDefs(zomeName: ZomeName): Promise<MyDictionary<EntryDef>> {\n console.debug(\"callEntryDefs()\", this._cell?.name, zomeName)\n /** Return cache if any */\n if (this._entryDefCache[zomeName]) {\n return this._entryDefCache[zomeName]!;\n }\n /** Call zome */\n let entryDefs;\n try {\n /* Need big timeout since Holochain is slow when receiving simultaneous calls from multiple happs */\n entryDefs = await this.callZome(zomeName, \"entry_defs\", null, null, 60 * 1000) as EntryDefsCallbackResult;\n } catch (e: any) {\n if (e && e.failure && e.failure.message && e.failure.message.includes(\"Attempted to call a zome function that doesn't exist\")) {\n console.log(`Calling \"entry_defs()\" failed on zome \"${zomeName}\" because zome does not have entry defs.`);\n this._entryDefCache[zomeName] = {};\n return {};\n }\n console.error(`Calling \"entry_defs()\" failed on zome \"${zomeName}\".`);\n return Promise.reject(e);\n }\n console.debug(\"getEntryDefs() for \" + zomeName + \" result:\", entryDefs);\n /** Map result */\n let result: MyDictionary<EntryDef> = {}\n for (const def of entryDefs.Defs) {\n let name = Object.keys(def.id)[0];\n if (\"App\" in def.id) {\n name = def.id.App;\n }\n result[name!] = def;\n }\n //console.log({result})\n this._entryDefCache[zomeName] = result;\n return result;\n }\n\n /**\n * Calls the `zome_info()` zome function\n */\n async callZomeInfo(zomeName: ZomeName): Promise<ZomeInfo> {\n //console.log(\"callZomeInfo()\", zomeName, !!this._zomeInfoCache);\n if (this._zomeInfoCache[zomeName]) {\n return this._zomeInfoCache[zomeName]!;\n }\n try {\n const zome_info = await this.callZome(zomeName, \"get_zome_info\", null, null, 10 * 1000) as ZomeInfo;\n //console.debug(\"callZomeInfo() for \" + zomeName + \" result:\")\n //console.log({zome_info})\n this._zomeInfoCache[zomeName] = zome_info;\n return zome_info;\n } catch (e) {\n console.error(\"Calling callZomeInfo() on \" + zomeName + \" failed. Make sure `get_zome_info()` is implemented in your zome code.\")\n return Promise.reject(e);\n }\n }\n\n\n /**\n * Calls the `dna_info()` zome function\n */\n async callDnaInfo(zomeName: ZomeName): Promise<DnaInfo> {\n console.log(\"callDnaInfo()\", zomeName);\n if (this._dnaInfoCache) {\n return this._dnaInfoCache;\n }\n try {\n const dna_info = await this.callZome(zomeName, \"get_dna_info\", null, null, 10 * 1000) as DnaInfo;\n //console.debug(\"callDnaInfo() for \" + zomeName + \" result:\")\n //console.log({dna_info})\n this._dnaInfoCache = dna_info;\n return dna_info;\n } catch (e) {\n console.error(\"Calling callDnaInfo() on \" + zomeName + \" failed. Make sure `get_dna_info()` is implemented in your zome code.\")\n return Promise.reject(e);\n }\n }\n\n\n // /** TODO once we have getDnaDefinition() api */\n // dumpAllZomes() {\n // // FIXME get DNA DEF\n // for (const zomeName of dnaDef) {\n // this.dumpCallLogs(zomeName)\n // }\n // }\n\n\n /** */\n dumpCallLogs(zomeName?: ZomeName) {\n let result = [];\n let call_map = new Map<string, [number, number]>(); // fn_fname, call_count, call_total_duration;\n for (const response of this._responseLog) {\n const requestLog = this._requestLog[response.requestIndex];\n if (!requestLog || (zomeName && requestLog.request.zome_name != zomeName)) {\n continue;\n }\n const startTime= prettyDate(new Date(requestLog.requestTimestamp));\n const waitTime = prettyDuration(new Date(requestLog.executionTimestamp - requestLog.requestTimestamp));\n const duration_ts = response.timestamp - requestLog.requestTimestamp;\n const duration = prettyDuration(new Date(duration_ts));\n let input = requestLog.request.payload;\n // if (requestLog.request.payload instanceof HoloHash) {\n // //console.log(\"instanceof HoloHash\", requestLog.request.payload);\n // input = intoAnyId(requestLog.request.payload.toBytes()).print();\n // } else {\n if (requestLog.request.payload instanceof Uint8Array) {\n //console.log(\"instanceof Uint8Array\", requestLog.request.payload);\n input = intoAnyId(requestLog.request.payload).print();\n }\n //}\n //const input = requestLog.request.payload instanceof Uint8Array ? enc64(requestLog.request.payload) : requestLog.request.payload;\n const output = anyToB64(response.failure ? response.failure : response.success);\n const log = zomeName\n ? { startTime, fnName: requestLog.request.fn_name, input, output, duration, waitTime }\n : { startTime, zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime }\n result.push(log);\n let maybe_value = call_map.get(requestLog.request.fn_name);\n if (!maybe_value) {\n call_map.set(requestLog.request.fn_name, [1, duration_ts]);\n } else {\n call_map.set(requestLog.request.fn_name, [maybe_value[0] + 1, maybe_value[1] + duration_ts]);\n }\n }\n console.warn(`Dumping call logs for cell \"${this._appProxy.getLocations(this.cell.address)}\"`)\n if (zomeName) {\n console.warn(` - For zome \"${zomeName}\"`);\n }\n console.table(result)\n\n /** Print call_map as Table */\n let summary: any[] = [];\n for (const [fn_name, values] of call_map) {\n const log = { fnName: fn_name, count: values[0], avgDuration: prettyDuration(new Date(values[1] / values[0])) };\n summary.push(log);\n }\n summary.sort((a, b) => b.count - a.count);\n console.table(summary);\n\n /** Parse signal self-call logs */\n //console.log(this._appProxy.signalLogs)\n\n const zomeSignals = this._appProxy.signalLogs.filter((log) => log.type == AppSignalType.Zome);\n const sysSignals = zomeSignals.filter((log) => {\n const type = Object.keys(log.zomeSignal.pulses[0]!)[0];\n type == \"System\"\n });\n\n const startCalls: [Timestamp, CellIdStr, SystemAttestationVariantSelfCallStart][] = [];\n const endCalls: [Timestamp, CellIdStr, SystemAttestationVariantSelfCallEnd][] = [];\n sysSignals.map((log) => {\n for (const pulse of log.zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if(sys.type == \"SelfCallStart\") {\n startCalls.push([log.ts, log.cellAddr.str, (sys as SystemAttestationVariantSelfCallStart)]);\n }\n if(sys.type == \"SelfCallEnd\") {\n endCalls.push([log.ts, log.cellAddr.str, (sys as SystemAttestationVariantSelfCallEnd)]);\n }\n }\n })\n\n let sigResults = [];\n for (const [startTs, startId, startSignal] of startCalls) {\n const index = endCalls.findIndex(([ts, cellId, signal]) => ts >= startTs && startId == cellId && startSignal.fn_name == signal.fn_name)\n if (index == -1) {\n continue;\n }\n const first = endCalls.splice(index, 1)[0]!;\n const [endTs, _cId, endSignal] = first;\n const duration = prettyDuration(new Date(endTs - startTs));\n const log = { startTime: startTs, zomeName: endSignal.zome_name, fnName: endSignal.fn_name, succeeded: endSignal.succeeded, duration }\n sigResults.push(log);\n }\n\n console.table(sigResults)\n }\n\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"CellProxy.js","sourceRoot":"","sources":["../src/CellProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAOG,UAAU,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,MAAM,UAAU,CAAC;AAE1C,OAAO,EAIL,aAAa,EAId,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAM/C,OAAO,EAAC,UAAU,EAAE,cAAc,EAAC,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Type,\n} from \"@holochain/client\";\nimport {CellMixin, Empty} from \"./mixins\";\nimport {Cell} from \"./cell\";\nimport {\n CellIdStr,\n DnaInfo, EntryDef,\n EntryDefsCallbackResult,\n AppSignalType,\n SystemPulse,\n\n ZomeInfo\n} from \"./types\";\nimport {Mutex, withTimeout} from \"async-mutex\";\nimport MutexInterface from \"async-mutex/lib/MutexInterface\";\nimport {\n AppProxy,\n SignalUnsubscriber,\n} from \"./AppProxy\";\nimport {prettyDate, prettyDuration} from \"./pretty\";\nimport {anyToB64, intoAnyId} from \"./hash\";\nimport {MyDictionary, sha256} from \"./utils\";\nimport {TimeMap} from \"./time-map\";\nimport {\n SystemAttestationVariantPostCommitEntry,\n SystemAttestationVariantSelfCallEnd,\n SystemAttestationVariantSelfCallStart\n} from \"./zomeSignals.types\";\n\n\nexport interface RequestLog {\n request: CallZomeRequest,\n reqHash: string,\n timeout: number,\n requestTimestamp: number,\n executionTimestamp: number,\n}\n\nexport interface ResponseLog {\n success?: unknown,\n failure?: unknown,\n throttled?: boolean,\n timestamp: number,\n requestIndex: number;\n}\n\n\nexport type Cb = () => Promise<unknown>\n\n/**\n * Proxy for a running DNA.\n * It logs and queues ZomeCalls.\n * It holds a reference to its AppProxy and its Cell.\n * This class is expected to be used by ZomeProxies.\n */\nexport class CellProxy extends CellMixin(Empty) {\n\n /** Ctor */\n constructor(\n private _appProxy: AppProxy,\n cell: Cell,\n //public readonly dnaDef: MyDnaDef,\n defaultTimeout?: number,\n ) {\n super();\n this._cell = cell;\n console.log(`CellProxy.ctor`, cell);\n this.defaultTimeoutMs = defaultTimeout ? defaultTimeout : 10 * 1000;\n this._callMutex = withTimeout(new Mutex(), this.defaultTimeoutMs);\n\n ///*const _unsub =*/ this.addSignalHandler((sig) => this.blockSelfCall(sig));\n /*const _unsub =*/ this.addSignalHandler((sig) => this.blockUntilPostCommit(sig));\n }\n\n /** -- Fields -- */\n\n defaultTimeoutMs: number;\n protected _callMutex: MutexInterface;\n\n /** append only logs */\n private _requestLog: RequestLog[] = []\n private _responseLog: ResponseLog[] = []\n\n /** Throttle: Don't allow the exact same call within 200ms or if the first identical call hasn't returned yet */\n private _reqLive = new Set<string>();\n private _reqThrottle = new TimeMap(200, 10);\n private _canThrottle: boolean = true;\n setCanThrottle(can: boolean) {this._canThrottle = can};\n\n /** Cache */\n private _entryDefCache: MyDictionary<MyDictionary<EntryDef>> = {};\n private _zomeInfoCache: MyDictionary<ZomeInfo> = {};\n private _dnaInfoCache?: DnaInfo;\n\n\n /** -- Methods -- */\n\n getHappShareCode(): string | null { return this._appProxy.getHappShareCode(this.cell.baseRoleName)}\n\n\n /** Have a PostCommitEntry attestation release the Mutex */\n private _postCommitRelease?: MutexInterface.Releaser;\n private _postCommitReleaseEntryType?: string;\n protected async blockUntilPostCommit(signal: Signal) {\n if (SignalType.App != signal.type) {\n return;\n }\n const appSignal: AppSignal = signal.value;\n const zomeSignal = this._appProxy.intoZomeSignal(appSignal);\n if (!zomeSignal || zomeSignal.pulses.length == 0) {\n return;\n }\n console.debug(\"blockUntilPostCommit()\", zomeSignal, this._postCommitReleaseEntryType, !!this._postCommitRelease);\n const signalType = Object.keys(zomeSignal.pulses[0]!)[0];\n if (signalType != \"System\" || !this._postCommitRelease || !this._postCommitReleaseEntryType) {\n return;\n }\n for (const pulse of zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if (sys.type !== \"PostCommitEntry\") {\n continue;\n }\n const pce = sys as SystemAttestationVariantPostCommitEntry;\n if (!pce.succeeded) {\n console.error(\"PostCommit attestations failed\");\n this.dumpCallLogs(appSignal.zome_name);\n this.dumpSignalLogs(appSignal.zome_name);\n }\n if (pce.app_entry_type !== this._postCommitReleaseEntryType) {\n continue;\n }\n /** Release */\n console.debug(\"blockUntilPostCommit() postCommit Lock RELEASE\");\n this._postCommitRelease();\n delete this._postCommitRelease;\n delete this._postCommitReleaseEntryType;\n break;\n }\n }\n\n\n /** Have a self call acquire & the call Mutex */\n private _selfCallRelease?: MutexInterface.Releaser;\n protected async blockSelfCall(signal: AppSignal) {\n const zomeSignal = this._appProxy.intoZomeSignal(signal);\n if (!zomeSignal || zomeSignal.pulses.length == 0 || Object.keys(zomeSignal.pulses[0]!)[0] != 'System') {\n return;\n }\n for (const pulse of zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if (sys.type == \"SelfCallStart\") {\n console.log(\"\")\n /** Acquire lock */\n try {\n this._callMutex.acquire().then((r) => this._selfCallRelease = r)\n } catch (e) {\n console.error(\"A Zome self call is initialized during a writing zome call\", e);\n }\n }\n if (sys.type == \"SelfCallEnd\" && this._selfCallRelease) {\n /** Release */\n this._selfCallRelease();\n delete this._selfCallRelease;\n const end = sys as SystemAttestationVariantSelfCallEnd;\n if (!end.succeeded) {\n console.error(\"Call to self failed.\")\n this.dumpCallLogs(end.zome_name);\n this.dumpSignalLogs(end.zome_name);\n }\n }\n }\n }\n\n\n /** */\n purgeLogs() {\n this._responseLog = [];\n this._requestLog = [];\n this._appProxy.purgeLogs();\n }\n\n /** */\n addSignalHandler(handler: SignalCb): SignalUnsubscriber {\n return this._appProxy.addSignalHandler(handler, this.cell.hcl().toString());\n }\n\n\n /** */\n dumpSignalLogs(zomeName?: ZomeName, canAppSignals?: boolean) {\n this._appProxy.dumpSignalLogs(canAppSignals? canAppSignals : true, this.cell.address, zomeName);\n }\n\n\n /** */\n get signalLogs() {\n return this._appProxy.signalLogs.filter((log) => log.cellAddr.equals(this.cell.address));\n }\n\n\n /** Pass the call request to the conductor proxy and log it */\n private async executeZomeCall(reqLog: RequestLog): Promise<ResponseLog> {\n //console.log(\"executeZomeCall()\", reqLog.request.zome_name, reqLog.request.fn_name);\n reqLog.executionTimestamp = Date.now();\n const requestIndex = this._requestLog.length;\n this._requestLog.push(reqLog);\n /** Throttle */\n let respLog: ResponseLog | undefined = undefined;\n if (this._canThrottle) {\n const isSpam = this._reqThrottle.has(reqLog.reqHash);\n if (isSpam || this._reqLive.has(reqLog.reqHash)) {\n console.warn(`THROTTLING ${isSpam? \"SPAM\" : \"LIVE\"} ${reqLog.request.zome_name}::${reqLog.request.fn_name}() ${prettyDate(new Date(reqLog.executionTimestamp))}`);\n return {\n requestIndex,\n timestamp: reqLog.executionTimestamp,\n failure: \"Throttled spam: \" + reqLog.request.fn_name + \"()\",\n throttled: true,\n };\n }\n this._reqThrottle.add(reqLog.reqHash);\n }\n /** */\n this._reqLive.add(reqLog.reqHash);\n try {\n const response = await this._appProxy.callZome(reqLog.request, reqLog.timeout);\n this._reqLive.delete(reqLog.reqHash);\n respLog = { requestIndex, success: response, timestamp: Date.now() };\n } catch (e) {\n this._reqLive.delete(reqLog.reqHash);\n respLog = {requestIndex, failure: e, timestamp: Date.now()}\n } finally {\n if (!respLog) {\n respLog = {requestIndex, failure: \"No response\", timestamp: Date.now()}\n }\n this._responseLog.push(respLog);\n }\n return respLog;\n}\n\n\n /** Pass the call request to conductor proxy and log it */\n logCallTimedOut(reqLog: RequestLog): ResponseLog {\n const requestIndex = this._requestLog.length;\n this._requestLog.push(reqLog);\n const respLog = { requestIndex, failure: \"Waiting for Mutex timed-out\", timestamp: Date.now() }\n this._responseLog.push(respLog);\n return respLog;\n }\n\n\n /**\n * callZome() with Mutex (for calls that writes to source-chain)\n * Waits for the postCommit lock to be released.\n * TODO: Implement call queue instead of mutex?\n */\n async callZomeBlockPostCommit(entryType: string, zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<unknown> {\n /** Create RequestLog */\n timeout = timeout ?? this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const reqHash = await sha256(JSON.stringify(req));\n const log: RequestLog = { request: req, reqHash, timeout, requestTimestamp: Date.now(), executionTimestamp: 0 };\n /** Acquire lock */\n console.debug(\"postCommit Lock in progress...\");\n try {\n this._postCommitRelease = await this._callMutex.acquire();\n this._postCommitReleaseEntryType = entryType;\n } catch(e) {\n console.warn(\"Waiting for callZomeBlockPostCommit mutex timed-out\", e);\n this.logCallTimedOut(log)\n return Promise.reject(\"Waiting for callZomeBlockPostCommit mutex timed-out\");\n }\n console.debug(\"postCommit Lock ACQUIRED\");\n /** Execute */\n const respLog = await this.executeZomeCall(log);\n return respLog.success;\n }\n\n\n /**\n * callZome() with Mutex (for calls that writes to source-chain)\n * TODO: Implement call queue instead of mutex?\n */\n async callZomeBlocking(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<unknown> {\n /** Create RequestLog */\n timeout = timeout ?? this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const reqHash = await sha256(JSON.stringify(req));\n const log: RequestLog = { request: req, reqHash, timeout, requestTimestamp: Date.now(), executionTimestamp: 0 };\n /** Acquire lock */\n let release;\n try {\n release = await this._callMutex.acquire();\n } catch(e) {\n console.warn(\"Waiting for callZomeBlocking mutex timed-out\", e);\n this.logCallTimedOut(log)\n return Promise.reject(\"Waiting for callZomeBlocking mutex timed-out\");\n }\n /** Execute */\n const respLog = await this.executeZomeCall(log);\n /** Release */\n release();\n if (respLog.failure) {\n if (!respLog.throttled) {\n this.dumpCallLogs(zome_name);\n this.dumpSignalLogs(zome_name);\n }\n return Promise.reject(respLog);\n }\n return respLog.success;\n }\n\n\n /** On success returns the data returned by the zome function */\n async callZome(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeoutMs?: number): Promise<unknown> {\n /** Create RequestLog */\n timeoutMs = timeoutMs ?? this.defaultTimeoutMs;\n const req = {\n cap_secret, zome_name, fn_name, payload,\n cell_id: this.cell.address.intoId(),\n provenance: this.cell.address.agentId.hash,\n } as CallZomeRequest;\n const reqHash = await sha256(JSON.stringify(req));\n const log: RequestLog = { request: req, reqHash, timeout: timeoutMs, requestTimestamp: Date.now(), executionTimestamp: 0 };\n /** Wait for lock */\n try {\n await this._callMutex.waitForUnlock();\n } catch(e) {\n console.warn(\"Waiting for callZome mutex timed-out\", e);\n this.logCallTimedOut(log);\n return Promise.reject(\"Waiting for callZome mutex timed-out\");\n }\n /** Execute & return response */\n const respLog = await this.executeZomeCall(log);\n if (respLog.failure) {\n if (!respLog.throttled) {\n this.dumpCallLogs(zome_name);\n this.dumpSignalLogs(zome_name);\n }\n return Promise.reject(respLog);\n }\n return respLog.success;\n }\n\n\n /**\n * Calls the `entry_defs()` zome function and\n * Returns an array of all the zome's AppEntryNames and Visibility, i.e. (AppEntryName, isPublic)[]\n */\n async callEntryDefs(zomeName: ZomeName): Promise<MyDictionary<EntryDef>> {\n console.debug(\"callEntryDefs()\", this._cell?.name, zomeName)\n /** Return cache if any */\n if (this._entryDefCache[zomeName]) {\n return this._entryDefCache[zomeName]!;\n }\n /** Call zome */\n let entryDefs;\n try {\n /* Need a big timeout since Holochain is slow when receiving simultaneous calls from multiple happs */\n entryDefs = await this.callZome(zomeName, \"entry_defs\", null, null, 60 * 1000) as EntryDefsCallbackResult;\n } catch (e: any) {\n if (e && e.failure && e.failure.message && e.failure.message.includes(\"Attempted to call a zome function that doesn't exist\")) {\n console.log(`Calling \"entry_defs()\" failed on zome \"${zomeName}\" because zome does not have entry defs.`);\n this._entryDefCache[zomeName] = {};\n return {};\n }\n console.error(`Calling \"entry_defs()\" failed on zome \"${zomeName}\".`);\n return Promise.reject(e);\n }\n console.debug(\"getEntryDefs() for \" + zomeName + \" result:\", entryDefs);\n /** Map result */\n let result: MyDictionary<EntryDef> = {}\n for (const def of entryDefs.Defs) {\n let name = Object.keys(def.id)[0];\n if (\"App\" in def.id) {\n name = def.id.App;\n }\n result[name!] = def;\n }\n //console.log({result})\n this._entryDefCache[zomeName] = result;\n return result;\n }\n\n /**\n * Calls the `zome_info()` zome function\n */\n async callZomeInfo(zomeName: ZomeName): Promise<ZomeInfo> {\n //console.log(\"callZomeInfo()\", zomeName, !!this._zomeInfoCache);\n if (this._zomeInfoCache[zomeName]) {\n return this._zomeInfoCache[zomeName]!;\n }\n try {\n const zome_info = await this.callZome(zomeName, \"get_zome_info\", null, null, 10 * 1000) as ZomeInfo;\n //console.debug(\"callZomeInfo() for \" + zomeName + \" result:\")\n //console.log({zome_info})\n this._zomeInfoCache[zomeName] = zome_info;\n return zome_info;\n } catch (e) {\n console.error(\"Calling callZomeInfo() on \" + zomeName + \" failed. Make sure `get_zome_info()` is implemented in your zome code.\")\n return Promise.reject(e);\n }\n }\n\n\n /**\n * Calls the `dna_info()` zome function\n */\n async callDnaInfo(zomeName: ZomeName): Promise<DnaInfo> {\n console.log(\"callDnaInfo()\", zomeName);\n if (this._dnaInfoCache) {\n return this._dnaInfoCache;\n }\n try {\n const dna_info = await this.callZome(zomeName, \"get_dna_info\", null, null, 10 * 1000) as DnaInfo;\n //console.debug(\"callDnaInfo() for \" + zomeName + \" result:\")\n //console.log({dna_info})\n this._dnaInfoCache = dna_info;\n return dna_info;\n } catch (e) {\n console.error(\"Calling callDnaInfo() on \" + zomeName + \" failed. Make sure `get_dna_info()` is implemented in your zome code.\")\n return Promise.reject(e);\n }\n }\n\n\n // /** TODO once we have getDnaDefinition() api */\n // dumpAllZomes() {\n // // FIXME get DNA DEF\n // for (const zomeName of dnaDef) {\n // this.dumpCallLogs(zomeName)\n // }\n // }\n\n /** */\n dumpCallLogs(zomeName?: ZomeName) {\n /** Print requests as Table */\n let requestTable = [];\n for (const request of this._requestLog) {\n const waitTime = prettyDuration(new Date(request.executionTimestamp - request.requestTimestamp));\n const log = { timestamp: prettyDate(new Date(request.executionTimestamp)), reqHash: request.reqHash.slice(0,8), fn: request.request.fn_name, timeout: request.timeout, waitTime }\n requestTable.push(log);\n }\n console.warn(`Dumping call request logs for cell \"${this._appProxy.getLocations(this.cell.address)}\" for zome \"${zomeName}\"`)\n console.table(requestTable)\n /** Print response logs as Table */\n let result = [];\n let call_map = new Map<string, [number, number]>(); // fn_fname, call_count, call_total_duration;\n for (const response of this._responseLog) {\n const requestLog = this._requestLog[response.requestIndex];\n if (!requestLog || (zomeName && requestLog.request.zome_name != zomeName)) {\n continue;\n }\n const startTime = prettyDate(new Date(requestLog.requestTimestamp));\n const waitTime = prettyDuration(new Date(requestLog.executionTimestamp - requestLog.requestTimestamp));\n const duration_ts = response.timestamp - requestLog.requestTimestamp;\n const duration = prettyDuration(new Date(duration_ts));\n let input = requestLog.request.payload;\n // if (requestLog.request.payload instanceof HoloHash) {\n // //console.log(\"instanceof HoloHash\", requestLog.request.payload);\n // input = intoAnyId(requestLog.request.payload.toBytes()).print();\n // } else {\n if (requestLog.request.payload instanceof Uint8Array) {\n //console.log(\"instanceof Uint8Array\", requestLog.request.payload);\n input = intoAnyId(requestLog.request.payload).print();\n }\n //}\n //const input = requestLog.request.payload instanceof Uint8Array ? enc64(requestLog.request.payload) : requestLog.request.payload;\n const output = anyToB64(response.failure ? response.failure : response.success);\n const log = zomeName\n ? { reqIndex: response.requestIndex, startTime, reqHash: requestLog.reqHash.slice(0, 8), fnName: requestLog.request.fn_name, input, output, duration, waitTime }\n : { reqIndex: response.requestIndex, startTime, reqHash: requestLog.reqHash.slice(0, 8), zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime }\n result.push(log);\n let maybe_value = call_map.get(requestLog.request.fn_name);\n if (!maybe_value) {\n call_map.set(requestLog.request.fn_name, [1, duration_ts]);\n } else {\n call_map.set(requestLog.request.fn_name, [maybe_value[0] + 1, maybe_value[1] + duration_ts]);\n }\n }\n console.warn(`Dumping call response logs for cell \"${this._appProxy.getLocations(this.cell.address)}\" for zome \"${zomeName}\"`)\n console.table(result)\n\n /** Print call_map as Table */\n let summary: any[] = [];\n for (const [fn_name, values] of call_map) {\n const log = { fnName: fn_name, count: values[0], avgDuration: prettyDuration(new Date(values[1] / values[0])) };\n summary.push(log);\n }\n summary.sort((a, b) => b.count - a.count);\n console.warn(`Dumping call map for cell \"${this._appProxy.getLocations(this.cell.address)}\" for zome \"${zomeName}\"`)\n console.table(summary);\n\n /** Parse signal self-call logs */\n //console.log(this._appProxy.signalLogs)\n\n const zomeSignals = this._appProxy.signalLogs.filter((log) => log.type == AppSignalType.Zome);\n const sysSignals = zomeSignals.filter((log) => {\n const type = Object.keys(log.zomeSignal.pulses[0]!)[0];\n type == \"System\"\n });\n\n const startCalls: [Timestamp, CellIdStr, SystemAttestationVariantSelfCallStart][] = [];\n const endCalls: [Timestamp, CellIdStr, SystemAttestationVariantSelfCallEnd][] = [];\n sysSignals.map((log) => {\n for (const pulse of log.zomeSignal.pulses) {\n const sys = (pulse as SystemPulse).System;\n if(sys.type == \"SelfCallStart\") {\n startCalls.push([log.ts, log.cellAddr.str, (sys as SystemAttestationVariantSelfCallStart)]);\n }\n if(sys.type == \"SelfCallEnd\") {\n endCalls.push([log.ts, log.cellAddr.str, (sys as SystemAttestationVariantSelfCallEnd)]);\n }\n }\n })\n\n let sigResults = [];\n for (const [startTs, startId, startSignal] of startCalls) {\n const index = endCalls.findIndex(([ts, cellId, signal]) => ts >= startTs && startId == cellId && startSignal.fn_name == signal.fn_name)\n if (index == -1) {\n continue;\n }\n const first = endCalls.splice(index, 1)[0]!;\n const [endTs, _cId, endSignal] = first;\n const duration = prettyDuration(new Date(endTs - startTs));\n const log = { startTime: startTs, zomeName: endSignal.zome_name, fnName: endSignal.fn_name, succeeded: endSignal.succeeded, duration }\n sigResults.push(log);\n }\n\n console.table(sigResults)\n }\n\n\n}\n\n"]}
|