@activeledger/activeprotocol 5.0.1 → 5.1.0
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/es/protocol/adopt.d.ts +23 -0
- package/es/protocol/adopt.d.ts.map +1 -0
- package/es/protocol/adopt.js +154 -0
- package/es/protocol/adopt.js.map +1 -0
- package/es/protocol/attest.d.ts +16 -0
- package/es/protocol/attest.d.ts.map +1 -0
- package/es/protocol/attest.js +58 -0
- package/es/protocol/attest.js.map +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -1
- package/es/protocol/index.js +3 -0
- package/es/protocol/index.js.map +1 -1
- package/es/protocol/interfaces/process.interface.d.ts +29 -0
- package/es/protocol/interfaces/process.interface.d.ts.map +1 -1
- package/es/protocol/interfaces/vm.interface.d.ts +17 -2
- package/es/protocol/interfaces/vm.interface.d.ts.map +1 -1
- package/es/protocol/process.d.ts +8 -1
- package/es/protocol/process.d.ts.map +1 -1
- package/es/protocol/process.js +142 -11
- package/es/protocol/process.js.map +1 -1
- package/es/protocol/sandbox.d.ts +10 -0
- package/es/protocol/sandbox.d.ts.map +1 -0
- package/es/protocol/sandbox.js +52 -0
- package/es/protocol/sandbox.js.map +1 -0
- package/es/protocol/streamUpdater.d.ts.map +1 -1
- package/es/protocol/streamUpdater.js +21 -0
- package/es/protocol/streamUpdater.js.map +1 -1
- package/es/protocol/vm.d.ts +11 -2
- package/es/protocol/vm.d.ts.map +1 -1
- package/es/protocol/vm.js +105 -20
- package/es/protocol/vm.js.map +1 -1
- package/lib/protocol/adopt.d.ts +23 -0
- package/lib/protocol/adopt.d.ts.map +1 -0
- package/lib/protocol/adopt.js +160 -0
- package/lib/protocol/adopt.js.map +1 -0
- package/lib/protocol/attest.d.ts +16 -0
- package/lib/protocol/attest.d.ts.map +1 -0
- package/lib/protocol/attest.js +62 -0
- package/lib/protocol/attest.js.map +1 -0
- package/lib/protocol/index.d.ts +4 -0
- package/lib/protocol/index.d.ts.map +1 -1
- package/lib/protocol/index.js +5 -0
- package/lib/protocol/index.js.map +1 -1
- package/lib/protocol/interfaces/process.interface.d.ts +29 -0
- package/lib/protocol/interfaces/process.interface.d.ts.map +1 -1
- package/lib/protocol/interfaces/vm.interface.d.ts +17 -2
- package/lib/protocol/interfaces/vm.interface.d.ts.map +1 -1
- package/lib/protocol/process.d.ts +8 -1
- package/lib/protocol/process.d.ts.map +1 -1
- package/lib/protocol/process.js +142 -11
- package/lib/protocol/process.js.map +1 -1
- package/lib/protocol/sandbox.d.ts +10 -0
- package/lib/protocol/sandbox.d.ts.map +1 -0
- package/lib/protocol/sandbox.js +59 -0
- package/lib/protocol/sandbox.js.map +1 -0
- package/lib/protocol/streamUpdater.d.ts.map +1 -1
- package/lib/protocol/streamUpdater.js +21 -0
- package/lib/protocol/streamUpdater.js.map +1 -1
- package/lib/protocol/vm.d.ts +11 -2
- package/lib/protocol/vm.d.ts.map +1 -1
- package/lib/protocol/vm.js +105 -20
- package/lib/protocol/vm.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Attestation = void 0;
|
|
4
|
+
const activecrypto_1 = require("@activeledger/activecrypto");
|
|
5
|
+
const activeoptions_1 = require("@activeledger/activeoptions");
|
|
6
|
+
const activelogger_1 = require("@activeledger/activelogger");
|
|
7
|
+
class Attestation {
|
|
8
|
+
static BUILD = 40300;
|
|
9
|
+
static key;
|
|
10
|
+
static enabled() {
|
|
11
|
+
return (!!Attestation.key &&
|
|
12
|
+
activeoptions_1.ActiveOptions.get("build", 0) >= Attestation.BUILD);
|
|
13
|
+
}
|
|
14
|
+
static signVote(umid, revs, node) {
|
|
15
|
+
if (!Attestation.enabled() || !node)
|
|
16
|
+
return;
|
|
17
|
+
try {
|
|
18
|
+
node.sig = activecrypto_1.ActiveCrypto.signDigest(Attestation.key, activecrypto_1.ActiveCrypto.voteDigest(umid, !!node.vote, revs));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
activelogger_1.ActiveLogger.error(e, `Vote attestation failed for ${umid}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
static async commit(db, events, reference, entry, docs) {
|
|
25
|
+
if (!Attestation.enabled())
|
|
26
|
+
return;
|
|
27
|
+
try {
|
|
28
|
+
const sha = (doc) => activecrypto_1.ActiveCrypto.Hash.getHash(activecrypto_1.ActiveCrypto.canonicalJson(doc));
|
|
29
|
+
const outputIds = docs
|
|
30
|
+
.map((d) => d._id)
|
|
31
|
+
.filter((id) => id && !id.endsWith(":volatile") && !id.endsWith(":umid"));
|
|
32
|
+
const revsOut = {};
|
|
33
|
+
for (const id of outputIds) {
|
|
34
|
+
const stored = await db.get(id);
|
|
35
|
+
revsOut[id] = { rev: stored._rev, sha256: sha(stored) };
|
|
36
|
+
}
|
|
37
|
+
const umidDocHash = sha(await db.get(`${entry.$umid}:umid`));
|
|
38
|
+
const digest = activecrypto_1.ActiveCrypto.commitDigest(entry.$umid, "committed", entry.$revs, revsOut, umidDocHash);
|
|
39
|
+
const attestation = {
|
|
40
|
+
node: reference,
|
|
41
|
+
umid: entry.$umid,
|
|
42
|
+
outcome: "committed",
|
|
43
|
+
revsOut,
|
|
44
|
+
umidDocHash,
|
|
45
|
+
sig: activecrypto_1.ActiveCrypto.signDigest(Attestation.key, digest),
|
|
46
|
+
};
|
|
47
|
+
const nodes = {};
|
|
48
|
+
for (const ref of Object.keys(entry.$nodes || {})) {
|
|
49
|
+
const n = entry.$nodes[ref];
|
|
50
|
+
if (n && typeof n.vote === "boolean") {
|
|
51
|
+
nodes[ref] = { vote: n.vote, ...(n.sig ? { sig: n.sig } : {}) };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await events.post({ _id: `attest:${entry.$umid}`, ...attestation, nodes });
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
activelogger_1.ActiveLogger.error(e, `Commit attestation failed for ${entry.$umid}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Attestation = Attestation;
|
|
62
|
+
//# sourceMappingURL=attest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attest.js","sourceRoot":"","sources":["../../src/protocol/attest.ts"],"names":[],"mappings":";;;AAuBA,6DAA0D;AAC1D,+DAA4D;AAC5D,6DAA0D;AAO1D;IAMS,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC;IAG9B,MAAM,CAAC,GAAG,CAAwB;IAElC,MAAM,CAAC,OAAO;QACnB,OAAO,CACL,CAAC,CAAC,WAAW,CAAC,GAAG;YACjB,6BAAa,CAAC,GAAG,CAAS,OAAO,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC,KAAK,CAC3D,CAAC;IACJ,CAAC;IAMM,MAAM,CAAC,QAAQ,CACpB,IAAY,EACZ,IAAkC,EAClC,IAAqC;QAErC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI;YAAE,OAAO;QAC5C,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,GAAG,2BAAY,CAAC,UAAU,CAChC,WAAW,CAAC,GAA2B,EACvC,2BAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAW,CAAC,CACxD,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YAEX,2BAAY,CAAC,KAAK,CAAC,CAAC,EAAE,+BAA+B,IAAI,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAcM,MAAM,CAAC,KAAK,CAAC,MAAM,CACxB,EAAqC,EACrC,MAAwC,EACxC,SAAiB,EACjB,KAAoC,EACpC,IAAwB;QAExB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YAAE,OAAO;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAA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AI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;gBAClD,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;oBACrC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;gBAClE,CAAC;YACH,CAAC;YACD,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,2BAAY,CAAC,KAAK,CAAC,CAAC,EAAE,iCAAiC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF"}
|
package/lib/protocol/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from "./process";
|
|
2
|
+
export * from "./attest";
|
|
3
|
+
export * from "./adopt";
|
|
4
|
+
export { SupernodeOnlyError } from "./sandbox";
|
|
5
|
+
export type { TProcessMode, IProcessOptions, IDryRunOptions, IExecutionResult, } from "./interfaces/process.interface";
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAuBA,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAuBA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,YAAY,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,gCAAgC,CAAA"}
|
package/lib/protocol/index.js
CHANGED
|
@@ -14,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SupernodeOnlyError = void 0;
|
|
17
18
|
__exportStar(require("./process"), exports);
|
|
19
|
+
__exportStar(require("./attest"), exports);
|
|
20
|
+
__exportStar(require("./adopt"), exports);
|
|
21
|
+
var sandbox_1 = require("./sandbox");
|
|
22
|
+
Object.defineProperty(exports, "SupernodeOnlyError", { enumerable: true, get: function () { return sandbox_1.SupernodeOnlyError; } });
|
|
18
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuBA,4CAAyB;AACzB,2CAAwB;AACxB,0CAAuB;AACvB,qCAA8C;AAArC,6GAAA,kBAAkB,OAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IAdoptDeclaration } from "@activeledger/activecontracts";
|
|
1
2
|
interface ISecurityNamespaceData {
|
|
2
3
|
std: string[];
|
|
3
4
|
external: string[];
|
|
@@ -15,5 +16,33 @@ export interface IReferenceStreams {
|
|
|
15
16
|
new: any[];
|
|
16
17
|
updated: any[];
|
|
17
18
|
}
|
|
19
|
+
export type TProcessMode = "supernode" | "hybrid";
|
|
20
|
+
export interface IProcessOptions {
|
|
21
|
+
mode?: TProcessMode;
|
|
22
|
+
volatileHeld?: (streamId: string) => boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface IDryRunOptions extends Omit<IProcessOptions, "mode"> {
|
|
25
|
+
reference?: string;
|
|
26
|
+
selfHost?: string;
|
|
27
|
+
contractVersion?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface IExecutionResult {
|
|
30
|
+
umid: string;
|
|
31
|
+
vote: boolean;
|
|
32
|
+
committed: boolean;
|
|
33
|
+
error?: string;
|
|
34
|
+
documents: {
|
|
35
|
+
[id: string]: any;
|
|
36
|
+
};
|
|
37
|
+
volatile: {
|
|
38
|
+
[id: string]: any;
|
|
39
|
+
};
|
|
40
|
+
umidDoc?: any;
|
|
41
|
+
return?: unknown;
|
|
42
|
+
events: any[];
|
|
43
|
+
supernodeDependent: boolean;
|
|
44
|
+
dependence: string[];
|
|
45
|
+
adopt: IAdoptDeclaration[];
|
|
46
|
+
}
|
|
18
47
|
export {};
|
|
19
48
|
//# sourceMappingURL=process.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.interface.d.ts","sourceRoot":"","sources":["../../../src/protocol/interfaces/process.interface.ts"],"names":[],"mappings":"AAuBA,UAAU,sBAAsB;IAC9B,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,UAAU,mBAAmB;IAC3B,CAAC,SAAS,EAAE,MAAM,GAAG,sBAAsB,CAAC;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,GAAG,EAAE,CAAC;IACX,OAAO,EAAE,GAA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,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAEhC,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,MAAM,EAAE,GAAG,EAAE,CAAC;IAEd,kBAAkB,EAAE,OAAO,CAAC;IAE5B,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B"}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { ActiveDefinitions } from "@activeledger/activedefinitions";
|
|
2
|
-
import { Standard, Activity, PostProcessEvent } from "@activeledger/activecontracts";
|
|
2
|
+
import { Standard, Activity, PostProcessEvent, IAdoptDeclaration } from "@activeledger/activecontracts";
|
|
3
3
|
import { EventEngine } from "@activeledger/activequery";
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
|
+
export interface IVMExecution {
|
|
6
|
+
supernode: boolean;
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
db?: {
|
|
9
|
+
get(id: string): Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
volatileHeld?: (streamId: string) => boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface IVMExecutionReport {
|
|
14
|
+
supernodeDependent: boolean;
|
|
15
|
+
dependence: string[];
|
|
16
|
+
adopt: IAdoptDeclaration[];
|
|
17
|
+
}
|
|
5
18
|
export interface IVMObject {
|
|
6
19
|
initialiseContract(payload: IVMDataPayload, event: EventEngine, emitter: EventEmitter): void;
|
|
7
20
|
getActivityStreams(umid: string): {
|
|
@@ -63,7 +76,8 @@ export interface IVirtualMachine {
|
|
|
63
76
|
getEvents(umid: string): any[];
|
|
64
77
|
destroy(umid: string): void;
|
|
65
78
|
getInputs(umid: string): ActiveDefinitions.LedgerStream[];
|
|
66
|
-
initialise(payload: IVMDataPayload, contractName: string): Promise<void>;
|
|
79
|
+
initialise(payload: IVMDataPayload, contractName: string, execution?: IVMExecution): Promise<void>;
|
|
80
|
+
getExecutionReport(umid: string): IVMExecutionReport;
|
|
67
81
|
read(umid: string, readMethod: string): Promise<unknown>;
|
|
68
82
|
verify(sigless: boolean, umid: string): Promise<boolean>;
|
|
69
83
|
vote(nodes: ActiveDefinitions.INodes, umid: string): Promise<boolean | {
|
|
@@ -71,6 +85,7 @@ export interface IVirtualMachine {
|
|
|
71
85
|
}>;
|
|
72
86
|
commit(nodes: ActiveDefinitions.INodes, possibleTerritoriality: boolean, umid: string): Promise<boolean>;
|
|
73
87
|
postProcess(territoriality: boolean, who: string, umid: string): Promise<any>;
|
|
88
|
+
takeReloadRequest(umid: string): boolean;
|
|
74
89
|
reconcile(nodes: ActiveDefinitions.INodes, umid: string): Promise<any>;
|
|
75
90
|
}
|
|
76
91
|
export interface IContractIsolateBackend {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vm.interface.d.ts","sourceRoot":"","sources":["../../../src/protocol/interfaces/vm.interface.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,
|
|
1
|
+
{"version":3,"file":"vm.interface.d.ts","sourceRoot":"","sources":["../../../src/protocol/interfaces/vm.interface.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,MAAM,WAAW,YAAY;IAE3B,SAAS,EAAE,OAAO,CAAC;IAEnB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC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KAAK,EAAE,iBAAiB,CAAC,MAAM,EAC/B,sBAAsB,EAAE,OAAO,EAC/B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB,WAAW,CAAC,cAAc,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9E,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAEzC,SAAS,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACxE;AAoBD,MAAM,WAAW,uBAAuB;IAEtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,IAAI,CACF,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAAC;CACjE;AAGD,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,eAAe,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACrE"}
|
|
@@ -2,6 +2,7 @@ import { EventEmitter } from "events";
|
|
|
2
2
|
import { ActiveDSConnect } from "@activeledger/activeoptions";
|
|
3
3
|
import { ActiveCrypto } from "@activeledger/activecrypto";
|
|
4
4
|
import { ActiveDefinitions } from "@activeledger/activedefinitions";
|
|
5
|
+
import { IProcessOptions, IDryRunOptions, IExecutionResult } from "./interfaces/process.interface";
|
|
5
6
|
import { LedgerEntry } from "@activeledger/activedefinitions/lib/definitions";
|
|
6
7
|
export declare class Process extends EventEmitter {
|
|
7
8
|
private entry;
|
|
@@ -31,8 +32,14 @@ export declare class Process extends EventEmitter {
|
|
|
31
32
|
private permissionChecker;
|
|
32
33
|
private willEmit;
|
|
33
34
|
private willEmitData;
|
|
34
|
-
|
|
35
|
+
private localOnly;
|
|
36
|
+
private execution;
|
|
37
|
+
private written;
|
|
38
|
+
constructor(entry: ActiveDefinitions.LedgerEntry, selfHost: string, reference: string, right: ActiveDefinitions.INeighbourBase, db: ActiveDSConnect, dbe: ActiveDSConnect, dbev: ActiveDSConnect, secured: ActiveCrypto.Secured, options?: IProcessOptions);
|
|
35
39
|
destroy(umid: string): void;
|
|
40
|
+
private static captureWrites;
|
|
41
|
+
dryRun(contractVersion?: string, contractData?: ActiveDefinitions.IContractData | undefined | null): Promise<IExecutionResult>;
|
|
42
|
+
static dryRunHybrid(entry: ActiveDefinitions.LedgerEntry, db: ActiveDSConnect, options?: IDryRunOptions): Promise<IExecutionResult>;
|
|
36
43
|
private sortVersions;
|
|
37
44
|
private static contractPathCache;
|
|
38
45
|
static clearContractPathCache(contractId?: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/protocol/process.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/protocol/process.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAiB,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAMpE,OAAO,EAEL,eAAe,EACf,cAAc,EACd,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAe9E,qBAAa,OAAQ,SAAQ,YAAY;IAsOrC,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IAnOjB,OAAO,CAAC,MAAM,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AAC,CA0D3B;IAcD,OAAc,YAAY,CACxB,KAAK,EAAE,iBAAiB,CAAC,WAAW,EACpC,EAAE,EAAE,eAAe,EACnB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAwB3B;IAUD,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAEzB;IAKP,OAAc,sBAAsB,CAAC,UAAU,CAAC,EAAE,MAAM,QAUvD;IAMY,KAAK,CAChB,eAAe,CAAC,EAAE,MAAM,EACxB,YAAY,CAAC,EAAE,iBAAiB,CAAC,aAAa,GAAG,SAAS,GAAG,IAAI,iBAoXlE;IAQM,oBAAoB,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAqE5C;IAOM,WAAW,IAAI,OAAO,CAE5B;YASa,eAAe;YAkFf,QAAQ;YA+IR,OAAO;IA2ErB,OAAO,CAAC,QAAQ;IA2KT,UAAU,CACf,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;QAAC,KAAK,CAAC,EAAE,WAAW,CAAA;KAAE,EACrE,MAAM,CAAC,EAAE,OAAO,QAuBjB;IAQD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,qBAAqB;YAsBf,cAAc;IA2B5B,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,SAAS;YAwCH,MAAM;IAySpB,OAAO,CAAC,kBAAkB;IA6D1B,OAAO,CAAC,UAAU;CAsBnB"}
|
package/lib/protocol/process.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Process = void 0;
|
|
4
|
+
const attest_1 = require("./attest");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const events_1 = require("events");
|
|
6
7
|
const vm_1 = require("./vm");
|
|
@@ -44,7 +45,10 @@ class Process extends events_1.EventEmitter {
|
|
|
44
45
|
permissionChecker;
|
|
45
46
|
willEmit;
|
|
46
47
|
willEmitData;
|
|
47
|
-
|
|
48
|
+
localOnly = false;
|
|
49
|
+
execution;
|
|
50
|
+
written;
|
|
51
|
+
constructor(entry, selfHost, reference, right, db, dbe, dbev, secured, options = {}) {
|
|
48
52
|
super();
|
|
49
53
|
this.entry = entry;
|
|
50
54
|
this.selfHost = selfHost;
|
|
@@ -54,6 +58,19 @@ class Process extends events_1.EventEmitter {
|
|
|
54
58
|
this.dbe = dbe;
|
|
55
59
|
this.dbev = dbev;
|
|
56
60
|
this.secured = secured;
|
|
61
|
+
if (options.mode === "hybrid") {
|
|
62
|
+
this.localOnly = true;
|
|
63
|
+
this.written = { db: [], dbe: [], dbev: [] };
|
|
64
|
+
this.db = Process.captureWrites(this.db, this.written.db);
|
|
65
|
+
this.dbe = Process.captureWrites(this.dbe, this.written.dbe);
|
|
66
|
+
this.dbev = Process.captureWrites(this.dbev, this.written.dbev);
|
|
67
|
+
this.execution = {
|
|
68
|
+
supernode: false,
|
|
69
|
+
dryRun: true,
|
|
70
|
+
db: this.db,
|
|
71
|
+
volatileHeld: options.volatileHeld,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
57
74
|
this.shared = new shared_1.Shared(this.storeSingleError, this.entry, this.dbe, this);
|
|
58
75
|
this.nodeResponse = entry.$nodes[reference];
|
|
59
76
|
Process.networkNodeLength = activeoptions_1.ActiveOptions.get("neighbourhood", []).length;
|
|
@@ -70,7 +87,10 @@ class Process extends events_1.EventEmitter {
|
|
|
70
87
|
this.permissionChecker = new permissionsChecker_1.PermissionsChecker(this.entry, this.db, this.securityCache, this.shared);
|
|
71
88
|
}
|
|
72
89
|
destroy(umid) {
|
|
73
|
-
if (this.
|
|
90
|
+
if (this.localOnly) {
|
|
91
|
+
Process.generalContractVM.destroy(umid);
|
|
92
|
+
}
|
|
93
|
+
else if (this.entry.$broadcast) {
|
|
74
94
|
clearTimeout(this.broadcastTimeout);
|
|
75
95
|
Process.generalContractVM.destroy(umid);
|
|
76
96
|
delete this.entry;
|
|
@@ -82,6 +102,97 @@ class Process extends events_1.EventEmitter {
|
|
|
82
102
|
}, 60000);
|
|
83
103
|
}
|
|
84
104
|
}
|
|
105
|
+
static captureWrites(db, written) {
|
|
106
|
+
const record = (...docs) => {
|
|
107
|
+
for (const doc of docs)
|
|
108
|
+
written.push(JSON.parse(JSON.stringify(doc)));
|
|
109
|
+
};
|
|
110
|
+
const writes = {
|
|
111
|
+
bulkDocs: (docs) => (record(...docs), Promise.resolve({ ok: true })),
|
|
112
|
+
post: (doc) => (record(doc), Promise.resolve({ ok: true })),
|
|
113
|
+
put: (doc) => (record(doc), Promise.resolve({ ok: true })),
|
|
114
|
+
purge: () => Promise.resolve({ ok: true }),
|
|
115
|
+
drop: () => Promise.resolve({ ok: true }),
|
|
116
|
+
createIndex: () => Promise.resolve({ ok: true }),
|
|
117
|
+
};
|
|
118
|
+
return new Proxy(db || {}, {
|
|
119
|
+
get(target, prop) {
|
|
120
|
+
if (typeof prop === "string" && writes[prop])
|
|
121
|
+
return writes[prop];
|
|
122
|
+
const value = target[prop];
|
|
123
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
dryRun(contractVersion, contractData) {
|
|
128
|
+
if (!this.localOnly) {
|
|
129
|
+
return Promise.reject(new Error("dryRun needs a Process in hybrid mode"));
|
|
130
|
+
}
|
|
131
|
+
const umid = this.entry.$umid;
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
let done = false;
|
|
134
|
+
const finish = (error) => {
|
|
135
|
+
if (done)
|
|
136
|
+
return;
|
|
137
|
+
done = true;
|
|
138
|
+
this.removeListener("commited", onCommited);
|
|
139
|
+
this.removeListener("failed", onFailed);
|
|
140
|
+
const vm = Process.generalContractVM;
|
|
141
|
+
const report = vm.getExecutionReport(umid);
|
|
142
|
+
const node = this.nodeResponse || {};
|
|
143
|
+
const reason = error || node.error;
|
|
144
|
+
const documents = {};
|
|
145
|
+
const volatile = {};
|
|
146
|
+
let umidDoc;
|
|
147
|
+
for (const doc of this.written.db) {
|
|
148
|
+
const id = doc?._id || "";
|
|
149
|
+
if (id.endsWith(":umid"))
|
|
150
|
+
umidDoc = doc;
|
|
151
|
+
else if (id.endsWith(":volatile"))
|
|
152
|
+
volatile[id] = doc;
|
|
153
|
+
else if (id)
|
|
154
|
+
documents[id] = doc;
|
|
155
|
+
}
|
|
156
|
+
const result = {
|
|
157
|
+
umid,
|
|
158
|
+
vote: !!node.vote,
|
|
159
|
+
committed: !!node.commit && !reason,
|
|
160
|
+
documents,
|
|
161
|
+
volatile,
|
|
162
|
+
umidDoc,
|
|
163
|
+
return: node.return,
|
|
164
|
+
events: vm.getEvents(umid),
|
|
165
|
+
supernodeDependent: report.supernodeDependent,
|
|
166
|
+
dependence: report.dependence,
|
|
167
|
+
adopt: report.adopt,
|
|
168
|
+
};
|
|
169
|
+
if (reason) {
|
|
170
|
+
result.error =
|
|
171
|
+
reason.message || reason.reason || String(reason);
|
|
172
|
+
}
|
|
173
|
+
this.destroy(umid);
|
|
174
|
+
resolve(result);
|
|
175
|
+
};
|
|
176
|
+
const onCommited = () => finish();
|
|
177
|
+
const onFailed = (data) => finish(data?.error || "Failed");
|
|
178
|
+
this.on("commited", onCommited);
|
|
179
|
+
this.on("failed", onFailed);
|
|
180
|
+
this.start(contractVersion, contractData).catch(finish);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
static dryRunHybrid(entry, db, options = {}) {
|
|
184
|
+
const reference = options.reference || "hybrid";
|
|
185
|
+
const local = {
|
|
186
|
+
...entry,
|
|
187
|
+
$revs: entry.$revs ? JSON.parse(JSON.stringify(entry.$revs)) : entry.$revs,
|
|
188
|
+
$nodes: { [reference]: {} },
|
|
189
|
+
$broadcast: false,
|
|
190
|
+
$instant: false,
|
|
191
|
+
};
|
|
192
|
+
delete local.$territoriality;
|
|
193
|
+
const process = new Process(local, options.selfHost || "hybrid", reference, { reference: "", knock: () => Promise.reject(new Error("hybrid")) }, db, {}, {}, undefined, { mode: "hybrid", volatileHeld: options.volatileHeld });
|
|
194
|
+
return process.dryRun(options.contractVersion);
|
|
195
|
+
}
|
|
85
196
|
sortVersions(a, b) {
|
|
86
197
|
const padSorting = (v) => {
|
|
87
198
|
return v
|
|
@@ -173,16 +284,21 @@ class Process extends events_1.EventEmitter {
|
|
|
173
284
|
refresh: false,
|
|
174
285
|
});
|
|
175
286
|
}
|
|
176
|
-
if (await fs_1.promises.stat(`${namespacePath}/_LOCK.${this.contractId}`).catch(() => false)) {
|
|
177
|
-
throw new Error("Contract Global Lock");
|
|
178
|
-
}
|
|
179
|
-
if (await fs_1.promises.stat(`${namespacePath}/_LOCK.${contract}`).catch(() => false)) {
|
|
180
|
-
throw new Error(`Contract Version Lock ${contract.substring(contract.indexOf("@") + 1)}`);
|
|
181
|
-
}
|
|
182
287
|
Process.contractPathCache[this.entry.$tx.$contract] = await fs_1.promises.realpath(`${namespacePath}/${contract}.js`);
|
|
183
288
|
}
|
|
184
289
|
this.contractLocation =
|
|
185
290
|
Process.contractPathCache[this.entry.$tx.$contract];
|
|
291
|
+
const dir = this.contractLocation.slice(0, this.contractLocation.lastIndexOf("/"));
|
|
292
|
+
const file = this.contractLocation.slice(this.contractLocation.lastIndexOf("/") + 1).replace(/\.js$/, "");
|
|
293
|
+
const ids = new Set([this.contractId, file.split("@")[0]]);
|
|
294
|
+
for (const id of ids) {
|
|
295
|
+
if (await fs_1.promises.stat(`${dir}/_LOCK.${id}`).catch(() => false)) {
|
|
296
|
+
throw new Error("Contract Global Lock");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (await fs_1.promises.stat(`${dir}/_LOCK.${file}`).catch(() => false)) {
|
|
300
|
+
throw new Error(`Contract Version Lock ${file.substring(file.indexOf("@") + 1)}`);
|
|
301
|
+
}
|
|
186
302
|
}
|
|
187
303
|
catch (e) {
|
|
188
304
|
throw e;
|
|
@@ -396,7 +512,7 @@ class Process extends events_1.EventEmitter {
|
|
|
396
512
|
};
|
|
397
513
|
let continueProcessing = true;
|
|
398
514
|
try {
|
|
399
|
-
await virtualMachine.initialise(payload, contractName);
|
|
515
|
+
await virtualMachine.initialise(payload, contractName, this.execution);
|
|
400
516
|
}
|
|
401
517
|
catch (error) {
|
|
402
518
|
activelogger_1.ActiveLogger.debug(error, "VM initialisation failed");
|
|
@@ -420,6 +536,7 @@ class Process extends events_1.EventEmitter {
|
|
|
420
536
|
const vote = await virtualMachine.vote(this.entry.$nodes, payload.umid);
|
|
421
537
|
if (typeof vote !== "boolean" && vote.leader) {
|
|
422
538
|
this.nodeResponse.vote = this.nodeResponse.leader = true;
|
|
539
|
+
attest_1.Attestation.signVote(this.entry.$umid, this.entry.$revs, this.nodeResponse);
|
|
423
540
|
this.commit(virtualMachine);
|
|
424
541
|
return;
|
|
425
542
|
}
|
|
@@ -454,7 +571,7 @@ class Process extends events_1.EventEmitter {
|
|
|
454
571
|
}
|
|
455
572
|
async process(inputs, outputs = [], contractData = undefined) {
|
|
456
573
|
try {
|
|
457
|
-
if (this.entry.$broadcast && !this.entry.$wait) {
|
|
574
|
+
if (!this.localOnly && this.entry.$broadcast && !this.entry.$wait) {
|
|
458
575
|
if (this.entry.$origin === this.reference) {
|
|
459
576
|
this.emit("broadcast", true);
|
|
460
577
|
}
|
|
@@ -501,6 +618,19 @@ class Process extends events_1.EventEmitter {
|
|
|
501
618
|
activelogger_1.ActiveLogger.debug(`postVote entry is missing?`);
|
|
502
619
|
return;
|
|
503
620
|
}
|
|
621
|
+
if (this.localOnly) {
|
|
622
|
+
if (error) {
|
|
623
|
+
this.entry.$nodes[this.reference].error = error.reason
|
|
624
|
+
? error.reason
|
|
625
|
+
: error;
|
|
626
|
+
this.shared.raiseLedgerError(error.code || 1000, error.reason || error);
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
this.commit(virtualMachine);
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
attest_1.Attestation.signVote(this.entry.$umid, this.entry.$revs, this.nodeResponse);
|
|
504
634
|
if (!error && this.entry.$instant) {
|
|
505
635
|
this.emit("commited", { instant: true });
|
|
506
636
|
this.entry.$instant = false;
|
|
@@ -633,7 +763,7 @@ class Process extends events_1.EventEmitter {
|
|
|
633
763
|
async commit(virtualMachine, earlyCommit) {
|
|
634
764
|
if (!this.nodeResponse.commit && !this.isCommiting()) {
|
|
635
765
|
if (this.nodeResponse.vote &&
|
|
636
|
-
(this.nodeResponse.leader || this.canCommit())) {
|
|
766
|
+
(this.nodeResponse.leader || this.localOnly || this.canCommit())) {
|
|
637
767
|
activelogger_1.ActiveTiming.mark(this.entry.$umid, "proto.commitBegin");
|
|
638
768
|
this.commiting = true;
|
|
639
769
|
clearTimeout(this.broadcastTimeout);
|
|
@@ -653,6 +783,7 @@ class Process extends events_1.EventEmitter {
|
|
|
653
783
|
if (earlyCommit)
|
|
654
784
|
earlyCommit();
|
|
655
785
|
activelogger_1.ActiveLogger.debug(error, "VM Commit Failure");
|
|
786
|
+
activelogger_1.ActiveLogger.error(`Commit failed for ${this.entry.$umid} (${this.contractId}) - ${error?.message || error}`);
|
|
656
787
|
activeoptions_1.ActiveOptions.get("debug", false)
|
|
657
788
|
? this.shared.raiseLedgerError(1302, new Error("Commit Failure - " + JSON.stringify(error.message || error)))
|
|
658
789
|
: this.shared.raiseLedgerError(1301, new Error("Failed Commit Transaction"));
|