@mainsail/consensus 0.0.1-evm.5 → 0.0.1-evm.50
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/distribution/aggregator.d.ts +3 -4
- package/distribution/aggregator.d.ts.map +1 -1
- package/distribution/aggregator.js +11 -9
- package/distribution/aggregator.js.map +1 -1
- package/distribution/bootstrapper.d.ts +1 -1
- package/distribution/bootstrapper.d.ts.map +1 -1
- package/distribution/bootstrapper.js +15 -16
- package/distribution/bootstrapper.js.map +1 -1
- package/distribution/commit-state.d.ts +2 -3
- package/distribution/commit-state.d.ts.map +1 -1
- package/distribution/commit-state.js +21 -41
- package/distribution/commit-state.js.map +1 -1
- package/distribution/consensus.d.ts +10 -9
- package/distribution/consensus.d.ts.map +1 -1
- package/distribution/consensus.js +274 -224
- package/distribution/consensus.js.map +1 -1
- package/distribution/index.d.ts +1 -5
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +1 -30
- package/distribution/index.js.map +1 -1
- package/distribution/processors/abstract-processor.d.ts +5 -5
- package/distribution/processors/abstract-processor.d.ts.map +1 -1
- package/distribution/processors/abstract-processor.js +11 -7
- package/distribution/processors/abstract-processor.js.map +1 -1
- package/distribution/processors/commit-processor.d.ts +1 -2
- package/distribution/processors/commit-processor.d.ts.map +1 -1
- package/distribution/processors/commit-processor.js +29 -46
- package/distribution/processors/commit-processor.js.map +1 -1
- package/distribution/processors/index.d.ts +1 -2
- package/distribution/processors/index.d.ts.map +1 -1
- package/distribution/processors/index.js +1 -2
- package/distribution/processors/index.js.map +1 -1
- package/distribution/processors/message-processor.d.ts +13 -0
- package/distribution/processors/message-processor.d.ts.map +1 -0
- package/distribution/processors/message-processor.js +117 -0
- package/distribution/processors/message-processor.js.map +1 -0
- package/distribution/processors/proposal-processor.d.ts +3 -2
- package/distribution/processors/proposal-processor.d.ts.map +1 -1
- package/distribution/processors/proposal-processor.js +46 -41
- package/distribution/processors/proposal-processor.js.map +1 -1
- package/distribution/round-state-repository.d.ts +2 -2
- package/distribution/round-state-repository.d.ts.map +1 -1
- package/distribution/round-state-repository.js +13 -23
- package/distribution/round-state-repository.js.map +1 -1
- package/distribution/round-state.d.ts +14 -10
- package/distribution/round-state.d.ts.map +1 -1
- package/distribution/round-state.js +173 -153
- package/distribution/round-state.js.map +1 -1
- package/distribution/scheduler.d.ts +1 -1
- package/distribution/scheduler.d.ts.map +1 -1
- package/distribution/scheduler.js +49 -65
- package/distribution/scheduler.js.map +1 -1
- package/distribution/service-provider.d.ts +6 -0
- package/distribution/service-provider.d.ts.map +1 -0
- package/distribution/service-provider.js +42 -0
- package/distribution/service-provider.js.map +1 -0
- package/package.json +14 -11
- package/distribution/processors/precommit-processor.d.ts +0 -12
- package/distribution/processors/precommit-processor.d.ts.map +0 -1
- package/distribution/processors/precommit-processor.js +0 -77
- package/distribution/processors/precommit-processor.js.map +0 -1
- package/distribution/processors/prevote-processor.d.ts +0 -12
- package/distribution/processors/prevote-processor.d.ts.map +0 -1
- package/distribution/processors/prevote-processor.js +0 -77
- package/distribution/processors/prevote-processor.js.map +0 -1
|
@@ -7,103 +7,87 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
16
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
|
-
};
|
|
21
|
-
var _Scheduler_instances, _Scheduler_timeoutStartRound, _Scheduler_timeoutPropose, _Scheduler_timeoutPrevote, _Scheduler_timeoutPrecommit, _Scheduler_getTimeout, _Scheduler_getConsensus;
|
|
10
|
+
import { Identifiers } from "@mainsail/constants";
|
|
22
11
|
import { inject, injectable } from "@mainsail/container";
|
|
23
|
-
import {
|
|
12
|
+
import { setTimeoutAsync } from "@mainsail/utils";
|
|
24
13
|
import dayjs from "dayjs";
|
|
25
14
|
let Scheduler = class Scheduler {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
app;
|
|
16
|
+
stateStore;
|
|
17
|
+
cryptoConfiguration;
|
|
18
|
+
#timeoutStartRound;
|
|
19
|
+
#timeoutPropose;
|
|
20
|
+
#timeoutPrevote;
|
|
21
|
+
#timeoutPrecommit;
|
|
33
22
|
getNextBlockTimestamp(commitTime) {
|
|
34
|
-
return Math.max(commitTime + this.cryptoConfiguration.getMilestone().timeouts.blockPrepareTime, this.stateStore.getLastBlock().
|
|
23
|
+
return Math.max(commitTime + this.cryptoConfiguration.getMilestone().timeouts.blockPrepareTime, this.stateStore.getLastBlock().timestamp + this.cryptoConfiguration.getMilestone().timeouts.blockTime);
|
|
35
24
|
}
|
|
36
25
|
scheduleTimeoutBlockPrepare(timestamp) {
|
|
37
|
-
if (
|
|
26
|
+
if (this.#timeoutStartRound) {
|
|
38
27
|
return false;
|
|
39
28
|
}
|
|
40
29
|
const timeout = Math.max(0, timestamp - dayjs().valueOf());
|
|
41
|
-
|
|
42
|
-
await
|
|
43
|
-
|
|
44
|
-
}, timeout)
|
|
30
|
+
this.#timeoutStartRound = setTimeoutAsync(async () => {
|
|
31
|
+
await this.#getConsensus().onTimeoutStartRound();
|
|
32
|
+
this.#timeoutStartRound = undefined;
|
|
33
|
+
}, timeout);
|
|
45
34
|
return true;
|
|
46
35
|
}
|
|
47
36
|
scheduleTimeoutPropose(height, round) {
|
|
48
|
-
if (
|
|
37
|
+
if (this.#timeoutPropose) {
|
|
49
38
|
return false;
|
|
50
39
|
}
|
|
51
|
-
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
},
|
|
40
|
+
this.#timeoutPropose = setTimeoutAsync(async () => {
|
|
41
|
+
await this.#getConsensus().onTimeoutPropose(height, round);
|
|
42
|
+
this.#timeoutPropose = undefined;
|
|
43
|
+
}, this.#getTimeout(round));
|
|
55
44
|
return true;
|
|
56
45
|
}
|
|
57
46
|
scheduleTimeoutPrevote(height, round) {
|
|
58
|
-
if (
|
|
47
|
+
if (this.#timeoutPrevote) {
|
|
59
48
|
return false;
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
},
|
|
50
|
+
this.#timeoutPrevote = setTimeoutAsync(async () => {
|
|
51
|
+
await this.#getConsensus().onTimeoutPrevote(height, round);
|
|
52
|
+
this.#timeoutPrevote = undefined;
|
|
53
|
+
}, this.#getTimeout(round));
|
|
65
54
|
return true;
|
|
66
55
|
}
|
|
67
56
|
scheduleTimeoutPrecommit(height, round) {
|
|
68
|
-
if (
|
|
57
|
+
if (this.#timeoutPrecommit) {
|
|
69
58
|
return false;
|
|
70
59
|
}
|
|
71
|
-
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
},
|
|
60
|
+
this.#timeoutPrecommit = setTimeoutAsync(async () => {
|
|
61
|
+
await this.#getConsensus().onTimeoutPrecommit(height, round);
|
|
62
|
+
this.#timeoutPrecommit = undefined;
|
|
63
|
+
}, this.#getTimeout(round));
|
|
75
64
|
return true;
|
|
76
65
|
}
|
|
77
66
|
clear() {
|
|
78
|
-
if (
|
|
79
|
-
clearTimeout(
|
|
80
|
-
|
|
67
|
+
if (this.#timeoutStartRound) {
|
|
68
|
+
clearTimeout(this.#timeoutStartRound);
|
|
69
|
+
this.#timeoutStartRound = undefined;
|
|
81
70
|
}
|
|
82
|
-
if (
|
|
83
|
-
clearTimeout(
|
|
84
|
-
|
|
71
|
+
if (this.#timeoutPropose) {
|
|
72
|
+
clearTimeout(this.#timeoutPropose);
|
|
73
|
+
this.#timeoutPropose = undefined;
|
|
85
74
|
}
|
|
86
|
-
if (
|
|
87
|
-
clearTimeout(
|
|
88
|
-
|
|
75
|
+
if (this.#timeoutPrevote) {
|
|
76
|
+
clearTimeout(this.#timeoutPrevote);
|
|
77
|
+
this.#timeoutPrevote = undefined;
|
|
89
78
|
}
|
|
90
|
-
if (
|
|
91
|
-
clearTimeout(
|
|
92
|
-
|
|
79
|
+
if (this.#timeoutPrecommit) {
|
|
80
|
+
clearTimeout(this.#timeoutPrecommit);
|
|
81
|
+
this.#timeoutPrecommit = undefined;
|
|
93
82
|
}
|
|
94
83
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return (this.cryptoConfiguration.getMilestone().timeouts.stageTimeout +
|
|
103
|
-
round * this.cryptoConfiguration.getMilestone().timeouts.stageTimeoutIncrease);
|
|
104
|
-
};
|
|
105
|
-
_Scheduler_getConsensus = function _Scheduler_getConsensus() {
|
|
106
|
-
return this.app.get(Identifiers.Consensus.Service);
|
|
84
|
+
#getTimeout(round) {
|
|
85
|
+
return (this.cryptoConfiguration.getMilestone().timeouts.stageTimeout +
|
|
86
|
+
round * this.cryptoConfiguration.getMilestone().timeouts.stageTimeoutIncrease);
|
|
87
|
+
}
|
|
88
|
+
#getConsensus() {
|
|
89
|
+
return this.app.get(Identifiers.Consensus.Service);
|
|
90
|
+
}
|
|
107
91
|
};
|
|
108
92
|
__decorate([
|
|
109
93
|
inject(Identifiers.Application.Instance),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../source/scheduler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../source/scheduler.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAGnB,IAAM,SAAS,GAAf,MAAM,SAAS;IAEJ,GAAG,CAAgC;IAGnC,UAAU,CAAyB;IAGnC,mBAAmB,CAAkC;IAEtE,kBAAkB,CAAkB;IACpC,eAAe,CAAkB;IACjC,eAAe,CAAkB;IACjC,iBAAiB,CAAkB;IAE5B,qBAAqB,CAAC,UAAkB;QAC9C,OAAO,IAAI,CAAC,GAAG,CACd,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,gBAAgB,EAC9E,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,SAAS,CACrG,CAAC;IACH,CAAC;IAEM,2BAA2B,CAAC,SAAiB;QACnD,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC,kBAAkB,GAAG,eAAe,CAAC,KAAK,IAAI,EAAE;YACpD,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,mBAAmB,EAAE,CAAC;YACjD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,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;sDACuB;AAR1D,SAAS;IADrB,UAAU,EAAE;GACA,SAAS,CA4GrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-provider.d.ts","sourceRoot":"","sources":["../source/service-provider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAW7C,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Identifiers } from "@mainsail/constants";
|
|
8
|
+
import { injectable } from "@mainsail/container";
|
|
9
|
+
import { Providers } from "@mainsail/kernel";
|
|
10
|
+
import { Lock } from "@mainsail/utils";
|
|
11
|
+
import { Aggregator } from "./aggregator.js";
|
|
12
|
+
import { Bootstrapper } from "./bootstrapper.js";
|
|
13
|
+
import { CommitState } from "./commit-state.js";
|
|
14
|
+
import { Consensus } from "./consensus.js";
|
|
15
|
+
import { CommitProcessor, MessageProcessor, ProposalProcessor } from "./processors/index.js";
|
|
16
|
+
import { RoundStateRepository } from "./round-state-repository.js";
|
|
17
|
+
import { Scheduler } from "./scheduler.js";
|
|
18
|
+
let ServiceProvider = class ServiceProvider extends Providers.ServiceProvider {
|
|
19
|
+
async register() {
|
|
20
|
+
this.app.bind(Identifiers.Consensus.Aggregator).to(Aggregator).inSingletonScope();
|
|
21
|
+
this.app.bind(Identifiers.Consensus.RoundStateRepository).to(RoundStateRepository).inSingletonScope();
|
|
22
|
+
this.app.bind(Identifiers.Consensus.Scheduler).to(Scheduler).inSingletonScope();
|
|
23
|
+
this.app.bind(Identifiers.Consensus.Processor.Proposal).to(ProposalProcessor).inSingletonScope();
|
|
24
|
+
this.app.bind(Identifiers.Consensus.Processor.Message).to(MessageProcessor).inSingletonScope();
|
|
25
|
+
this.app.bind(Identifiers.Consensus.Processor.Commit).to(CommitProcessor).inSingletonScope();
|
|
26
|
+
this.app.bind(Identifiers.Consensus.CommitLock).toConstantValue(new Lock());
|
|
27
|
+
this.app
|
|
28
|
+
.bind(Identifiers.Consensus.CommitState.Factory)
|
|
29
|
+
.toFactory((context) => (commit) => context.get(CommitState, { autobind: true }).configure(commit));
|
|
30
|
+
this.app.bind(Identifiers.Consensus.Bootstrapper).to(Bootstrapper).inSingletonScope();
|
|
31
|
+
this.app.bind(Identifiers.Consensus.Service).to(Consensus).inSingletonScope();
|
|
32
|
+
}
|
|
33
|
+
async dispose() {
|
|
34
|
+
const consensus = this.app.get(Identifiers.Consensus.Service);
|
|
35
|
+
await consensus.dispose();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
ServiceProvider = __decorate([
|
|
39
|
+
injectable()
|
|
40
|
+
], ServiceProvider);
|
|
41
|
+
export { ServiceProvider };
|
|
42
|
+
//# sourceMappingURL=service-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-provider.js","sourceRoot":"","sources":["../source/service-provider.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM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
|
3
|
+
"version": "0.0.1-evm.50",
|
|
4
4
|
"description": "Consensus for the Mainsail blockchain",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"contributors": [],
|
|
@@ -11,25 +11,28 @@
|
|
|
11
11
|
"distribution"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"dayjs": "1.11.
|
|
15
|
-
"@mainsail/
|
|
16
|
-
"@mainsail/
|
|
17
|
-
"@mainsail/
|
|
14
|
+
"dayjs": "1.11.20",
|
|
15
|
+
"@mainsail/blockchain-utils": "0.0.1-evm.50",
|
|
16
|
+
"@mainsail/constants": "0.0.1-evm.50",
|
|
17
|
+
"@mainsail/container": "0.0.1-evm.50",
|
|
18
|
+
"@mainsail/kernel": "0.0.1-evm.50",
|
|
19
|
+
"@mainsail/utils": "0.0.1-evm.50"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"esmock": "2.
|
|
21
|
-
"uvu": "
|
|
22
|
+
"esmock": "2.7.5",
|
|
23
|
+
"uvu": "0.5.6",
|
|
24
|
+
"@mainsail/contracts": "0.0.1-evm.50",
|
|
25
|
+
"@mainsail/test-runner": "0.0.1-evm.50"
|
|
22
26
|
},
|
|
23
27
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
28
|
+
"node": ">=24"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
|
-
"build": "
|
|
31
|
+
"build": "tsc -b",
|
|
28
32
|
"build:watch": "pnpm run clean && tsc -w",
|
|
29
|
-
"clean": "del distribution",
|
|
30
33
|
"release": "pnpm publish --access public",
|
|
31
34
|
"test": "pnpm run uvu source .test.ts",
|
|
32
|
-
"test:coverage": "c8 pnpm run test",
|
|
35
|
+
"test:coverage": "c8 -r=text -r=lcov --all pnpm run test",
|
|
33
36
|
"test:coverage:html": "c8 -r html --all pnpm run test",
|
|
34
37
|
"test:file": "pnpm run uvu source",
|
|
35
38
|
"uvu": "tsx --tsconfig ../../tsconfig.test.json ./node_modules/uvu/bin.js"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Contracts } from "@mainsail/contracts";
|
|
2
|
-
import { AbstractProcessor } from "./abstract-processor.js";
|
|
3
|
-
export declare class PrecommitProcessor extends AbstractProcessor implements Contracts.Consensus.PrecommitProcessor {
|
|
4
|
-
#private;
|
|
5
|
-
private readonly serializer;
|
|
6
|
-
private readonly validatorSet;
|
|
7
|
-
private readonly roundStateRepo;
|
|
8
|
-
private readonly broadcaster;
|
|
9
|
-
private readonly workerPool;
|
|
10
|
-
process(precommit: Contracts.Crypto.Precommit, broadcast?: boolean): Promise<Contracts.Consensus.ProcessorResult>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=precommit-processor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precommit-processor.d.ts","sourceRoot":"","sources":["../../source/processors/precommit-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,qBACa,kBAAmB,SAAQ,iBAAkB,YAAW,SAAS,CAAC,SAAS,CAAC,kBAAkB;;IAE1G,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsC;IAGjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAG/D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4C;IAG3E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAGzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAEpD,OAAO,CACZ,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,EACrC,SAAS,UAAO,GACd,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC;CAwC/C"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _PrecommitProcessor_instances, _PrecommitProcessor_hasValidSignature;
|
|
16
|
-
import { inject, injectable } from "@mainsail/container";
|
|
17
|
-
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
18
|
-
import { AbstractProcessor } from "./abstract-processor.js";
|
|
19
|
-
let PrecommitProcessor = class PrecommitProcessor extends AbstractProcessor {
|
|
20
|
-
constructor() {
|
|
21
|
-
super(...arguments);
|
|
22
|
-
_PrecommitProcessor_instances.add(this);
|
|
23
|
-
}
|
|
24
|
-
async process(precommit, broadcast = true) {
|
|
25
|
-
return this.commitLock.runNonExclusive(async () => {
|
|
26
|
-
if (!this.hasValidHeightOrRound(precommit)) {
|
|
27
|
-
return Contracts.Consensus.ProcessorResult.Skipped;
|
|
28
|
-
}
|
|
29
|
-
if (!this.isRoundInBounds(precommit)) {
|
|
30
|
-
return Contracts.Consensus.ProcessorResult.Invalid;
|
|
31
|
-
}
|
|
32
|
-
if (!(await __classPrivateFieldGet(this, _PrecommitProcessor_instances, "m", _PrecommitProcessor_hasValidSignature).call(this, precommit))) {
|
|
33
|
-
return Contracts.Consensus.ProcessorResult.Invalid;
|
|
34
|
-
}
|
|
35
|
-
const roundState = this.roundStateRepo.getRoundState(precommit.height, precommit.round);
|
|
36
|
-
if (roundState.hasPrecommit(precommit.validatorIndex)) {
|
|
37
|
-
return Contracts.Consensus.ProcessorResult.Skipped;
|
|
38
|
-
}
|
|
39
|
-
roundState.addPrecommit(precommit);
|
|
40
|
-
if (broadcast) {
|
|
41
|
-
void this.broadcaster.broadcastPrecommit(precommit);
|
|
42
|
-
}
|
|
43
|
-
void this.getConsensus().handle(roundState);
|
|
44
|
-
return Contracts.Consensus.ProcessorResult.Accepted;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
_PrecommitProcessor_instances = new WeakSet();
|
|
49
|
-
_PrecommitProcessor_hasValidSignature = async function _PrecommitProcessor_hasValidSignature(precommit) {
|
|
50
|
-
const worker = await this.workerPool.getWorker();
|
|
51
|
-
return worker.consensusSignature("verify", Buffer.from(precommit.signature, "hex"), await this.serializer.serializePrecommitForSignature(precommit), Buffer.from(this.validatorSet.getValidator(precommit.validatorIndex).blsPublicKey, "hex"));
|
|
52
|
-
};
|
|
53
|
-
__decorate([
|
|
54
|
-
inject(Identifiers.Cryptography.Message.Serializer),
|
|
55
|
-
__metadata("design:type", Object)
|
|
56
|
-
], PrecommitProcessor.prototype, "serializer", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
inject(Identifiers.ValidatorSet.Service),
|
|
59
|
-
__metadata("design:type", Object)
|
|
60
|
-
], PrecommitProcessor.prototype, "validatorSet", void 0);
|
|
61
|
-
__decorate([
|
|
62
|
-
inject(Identifiers.Consensus.RoundStateRepository),
|
|
63
|
-
__metadata("design:type", Object)
|
|
64
|
-
], PrecommitProcessor.prototype, "roundStateRepo", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
inject(Identifiers.P2P.Broadcaster),
|
|
67
|
-
__metadata("design:type", Object)
|
|
68
|
-
], PrecommitProcessor.prototype, "broadcaster", void 0);
|
|
69
|
-
__decorate([
|
|
70
|
-
inject(Identifiers.CryptoWorker.WorkerPool),
|
|
71
|
-
__metadata("design:type", Object)
|
|
72
|
-
], PrecommitProcessor.prototype, "workerPool", void 0);
|
|
73
|
-
PrecommitProcessor = __decorate([
|
|
74
|
-
injectable()
|
|
75
|
-
], PrecommitProcessor);
|
|
76
|
-
export { PrecommitProcessor };
|
|
77
|
-
//# sourceMappingURL=precommit-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precommit-processor.js","sourceRoot":"","sources":["../../source/processors/precommit-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGrD,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,iBAAiB;IAAlD;;;IA2DP,CAAC;IA3CA,KAAK,CAAC,OAAO,CACZ,SAAqC,EACrC,SAAS,GAAG,IAAI;QAEhB,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE;YACjD,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5C,OAAO,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC;YACpD,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;gBACtC,OAAO,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC;YACpD,CAAC;Y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YAAY,CAAC,OAAO,CAAC,UAAU,CAAC;;sDACa;AAGhD;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC;;wDACsB;AAG9C;IADhB,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,oBAAoB,CAAC;;0DACwB;AAG1D;IADhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC;;uDACqB;AAGxC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;sDACc;AAd9C,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CA2D9B"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Contracts } from "@mainsail/contracts";
|
|
2
|
-
import { AbstractProcessor } from "./abstract-processor.js";
|
|
3
|
-
export declare class PrevoteProcessor extends AbstractProcessor implements Contracts.Consensus.PrevoteProcessor {
|
|
4
|
-
#private;
|
|
5
|
-
private readonly serializer;
|
|
6
|
-
private readonly validatorSet;
|
|
7
|
-
private readonly roundStateRepo;
|
|
8
|
-
private readonly broadcaster;
|
|
9
|
-
private readonly workerPool;
|
|
10
|
-
process(prevote: Contracts.Crypto.Prevote, broadcast?: boolean): Promise<Contracts.Consensus.ProcessorResult>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=prevote-processor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prevote-processor.d.ts","sourceRoot":"","sources":["../../source/processors/prevote-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,qBACa,gBAAiB,SAAQ,iBAAkB,YAAW,SAAS,CAAC,SAAS,CAAC,gBAAgB;;IAEtG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsC;IAGjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAG/D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4C;IAG3E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAGzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAEpD,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,UAAO,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC;CAwChH"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _PrevoteProcessor_instances, _PrevoteProcessor_hasValidSignature;
|
|
16
|
-
import { inject, injectable } from "@mainsail/container";
|
|
17
|
-
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
18
|
-
import { AbstractProcessor } from "./abstract-processor.js";
|
|
19
|
-
let PrevoteProcessor = class PrevoteProcessor extends AbstractProcessor {
|
|
20
|
-
constructor() {
|
|
21
|
-
super(...arguments);
|
|
22
|
-
_PrevoteProcessor_instances.add(this);
|
|
23
|
-
}
|
|
24
|
-
async process(prevote, broadcast = true) {
|
|
25
|
-
return this.commitLock.runNonExclusive(async () => {
|
|
26
|
-
if (!this.hasValidHeightOrRound(prevote)) {
|
|
27
|
-
return Contracts.Consensus.ProcessorResult.Skipped;
|
|
28
|
-
}
|
|
29
|
-
if (!this.isRoundInBounds(prevote)) {
|
|
30
|
-
return Contracts.Consensus.ProcessorResult.Invalid;
|
|
31
|
-
}
|
|
32
|
-
if (!(await __classPrivateFieldGet(this, _PrevoteProcessor_instances, "m", _PrevoteProcessor_hasValidSignature).call(this, prevote))) {
|
|
33
|
-
return Contracts.Consensus.ProcessorResult.Invalid;
|
|
34
|
-
}
|
|
35
|
-
const roundState = this.roundStateRepo.getRoundState(prevote.height, prevote.round);
|
|
36
|
-
if (roundState.hasPrevote(prevote.validatorIndex)) {
|
|
37
|
-
return Contracts.Consensus.ProcessorResult.Skipped;
|
|
38
|
-
}
|
|
39
|
-
roundState.addPrevote(prevote);
|
|
40
|
-
if (broadcast) {
|
|
41
|
-
void this.broadcaster.broadcastPrevote(prevote);
|
|
42
|
-
}
|
|
43
|
-
void this.getConsensus().handle(roundState);
|
|
44
|
-
return Contracts.Consensus.ProcessorResult.Accepted;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
_PrevoteProcessor_instances = new WeakSet();
|
|
49
|
-
_PrevoteProcessor_hasValidSignature = async function _PrevoteProcessor_hasValidSignature(prevote) {
|
|
50
|
-
const worker = await this.workerPool.getWorker();
|
|
51
|
-
return worker.consensusSignature("verify", Buffer.from(prevote.signature, "hex"), await this.serializer.serializePrevoteForSignature(prevote), Buffer.from(this.validatorSet.getValidator(prevote.validatorIndex).blsPublicKey, "hex"));
|
|
52
|
-
};
|
|
53
|
-
__decorate([
|
|
54
|
-
inject(Identifiers.Cryptography.Message.Serializer),
|
|
55
|
-
__metadata("design:type", Object)
|
|
56
|
-
], PrevoteProcessor.prototype, "serializer", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
inject(Identifiers.ValidatorSet.Service),
|
|
59
|
-
__metadata("design:type", Object)
|
|
60
|
-
], PrevoteProcessor.prototype, "validatorSet", void 0);
|
|
61
|
-
__decorate([
|
|
62
|
-
inject(Identifiers.Consensus.RoundStateRepository),
|
|
63
|
-
__metadata("design:type", Object)
|
|
64
|
-
], PrevoteProcessor.prototype, "roundStateRepo", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
inject(Identifiers.P2P.Broadcaster),
|
|
67
|
-
__metadata("design:type", Object)
|
|
68
|
-
], PrevoteProcessor.prototype, "broadcaster", void 0);
|
|
69
|
-
__decorate([
|
|
70
|
-
inject(Identifiers.CryptoWorker.WorkerPool),
|
|
71
|
-
__metadata("design:type", Object)
|
|
72
|
-
], PrevoteProcessor.prototype, "workerPool", void 0);
|
|
73
|
-
PrevoteProcessor = __decorate([
|
|
74
|
-
injectable()
|
|
75
|
-
], PrevoteProcessor);
|
|
76
|
-
export { PrevoteProcessor };
|
|
77
|
-
//# sourceMappingURL=prevote-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prevote-processor.js","sourceRoot":"","sources":["../../source/processors/prevote-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGrD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,iBAAiB;IAAhD;;;IAwDP,CAAC;IAxCA,KAAK,CAAC,OAAO,CAAC,OAAiC,EAAE,SAAS,GAAG,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