trac-msb 0.2.24 → 0.3.0-beta.1
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/SECURITY.md +2 -2
- package/cli/commandHandler.js +317 -20
- package/cli/handlers.js +9 -1
- package/cli/interactive.js +4 -3
- package/cli/tokenSupplyAudit.js +90 -0
- package/msb.mjs +1 -0
- package/package.json +15 -6
- package/rpc/create_server.js +12 -3
- package/rpc/handlers.js +103 -0
- package/rpc/routes/v1.js +8 -0
- package/src/codecs/apply/applyOperationCodec.js +334 -0
- package/src/codecs/apply/applyOperations.generated.cjs +6380 -0
- package/src/codecs/consensus/v1/consensusV1.generated.cjs +3508 -0
- package/src/codecs/consensus/v1/consensusV1OperationCodec.js +161 -0
- package/src/codecs/consensus/v1/vdfConfigCodec.js +83 -0
- package/src/{utils/protobuf → codecs/network/v1}/networkV1.generated.cjs +664 -393
- package/src/codecs/network/v1/networkV1OperationCodec.js +25 -0
- package/src/codecs/protobufRuntime.cjs +95 -0
- package/src/codecs/state/escrowEntryCodec.js +45 -0
- package/src/codecs/state/state.generated.cjs +659 -0
- package/src/config/args.js +0 -1
- package/src/config/config.js +46 -7
- package/src/config/env.js +33 -6
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelectionError.js +55 -0
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelectionOperations.js +118 -0
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelector.js +1042 -0
- package/src/core/consensus/epochAppenderSelection/createEpochAppenderSelector.js +23 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionLedgerReader.js +274 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionState.js +488 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionStorage.js +93 -0
- package/src/core/consensus/quorum.js +11 -0
- package/src/core/consensus/services/EpochCoordinationRound.js +839 -0
- package/src/core/consensus/services/EpochCoordinatorOperations.js +211 -0
- package/src/core/consensus/services/EpochCoordinatorService.js +335 -0
- package/src/core/consensus/services/EpochRoundListeners.js +116 -0
- package/src/core/consensus/services/EpochStateMachine.js +141 -0
- package/src/core/consensus/services/VDFBare.js +291 -0
- package/src/core/consensus/services/VDFNode.js +111 -0
- package/src/core/consensus/services/VDFProgressWatchdog.js +79 -0
- package/src/core/consensus/services/VDFService.js +87 -0
- package/src/core/consensus/services/VDFServiceManager.js +147 -0
- package/src/core/consensus/services/createVDFService.js +16 -0
- package/src/core/consensus/services/vdf-guardian.js +32 -0
- package/src/core/consensus/services/vdf-worker.js +90 -0
- package/src/core/network/Network.js +327 -238
- package/src/core/network/protocols/consensus/IndexerMessages.js +72 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1ConnectionPolicy.js +57 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1MessageRouter.js +147 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1Protocol.js +72 -0
- package/src/core/network/protocols/consensus/v1/IndexerPendingRequestService.js +108 -0
- package/src/core/network/protocols/consensus/v1/V1ConsensusProtocolError.js +29 -0
- package/src/core/network/protocols/consensus/v1/handlers/V1EpochAppendOperationHandler.js +68 -0
- package/src/core/network/protocols/consensus/v1/handlers/V1EpochProofProposalOperationHandler.js +226 -0
- package/src/core/network/protocols/consensus/v1/validators/ConsensusValidationSchema.js +192 -0
- package/src/core/network/protocols/consensus/v1/validators/V1BaseConsensusOperation.js +428 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochAppendReply.js +47 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochAppendRequest.js +17 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochProofProposalApproval.js +116 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochProofProposalRequest.js +152 -0
- package/src/core/network/protocols/consensus/v1/validators/consensusValidationSchemaHelpers.js +145 -0
- package/src/core/network/protocols/shared/ConnectionOperationHandler.js +27 -0
- package/src/core/network/protocols/{NetworkMessages.js → validators/ValidatorMessages.js} +24 -14
- package/src/core/network/protocols/{ProtocolSession.js → validators/ValidatorProtocolSession.js} +22 -25
- package/src/core/network/protocols/{legacy/NetworkMessageRouter.js → validators/legacy/ValidatorLegacyMessageRouter.js} +6 -6
- package/src/core/network/protocols/{LegacyProtocol.js → validators/legacy/ValidatorLegacyProtocol.js} +9 -7
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/BaseStateOperationHandler.js +1 -1
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyGetRequestHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyRoleOperationHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacySubnetworkOperationHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyTransferOperationHandler.js +5 -5
- package/src/core/network/protocols/{ProtocolInterface.js → validators/shared/ValidatorProtocolInterface.js} +5 -5
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialBootstrapDeploymentValidator.js +1 -1
- package/src/core/network/protocols/validators/shared/validators/PartialHtlcValidator.js +325 -0
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialOperationValidator.js +44 -21
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialRoleAccessValidator.js +3 -3
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialTransactionValidator.js +3 -3
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialTransferValidator.js +4 -4
- package/src/core/network/protocols/{v1 → validators/v1}/V1ProtocolError.js +1 -1
- package/src/core/network/{services/PendingRequestService.js → protocols/validators/v1/ValidatorPendingRequestService.js} +19 -82
- package/src/core/network/protocols/{v1/NetworkMessageRouter.js → validators/v1/ValidatorV1MessageRouter.js} +9 -9
- package/src/core/network/protocols/{V1Protocol.js → validators/v1/ValidatorV1Protocol.js} +10 -8
- package/src/core/network/protocols/{connectionPolicies.js → validators/v1/connectionPolicies.js} +1 -1
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1BaseOperationHandler.js +6 -23
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1BroadcastTransactionOperationHandler.js +14 -9
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1LivenessOperationHandler.js +5 -4
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +3 -3
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +44 -1
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +1 -1
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BaseOperation.js +19 -15
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BroadcastTransactionRequest.js +2 -2
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BroadcastTransactionResponse.js +34 -18
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1ValidationSchema.js +3 -3
- package/src/core/network/services/IndexerConnectionManager.js +88 -0
- package/src/core/network/services/TransactionPoolService.js +11 -18
- package/src/core/network/services/TransactionRateLimiterService.js +1 -1
- package/src/core/network/services/ValidatorConnectionManager.js +163 -0
- package/src/core/network/services/{MessageOrchestrator.js → ValidatorMessageOrchestrator.js} +34 -42
- package/src/core/network/services/ValidatorObserverService.js +21 -36
- package/src/core/network/shared/BasePendingRequestService.js +67 -0
- package/src/core/network/shared/PeerConnectionManager.js +185 -0
- package/src/core/state/ConfirmationWatch.js +82 -0
- package/src/core/state/State.js +1794 -173
- package/src/core/state/StateEventQueue.js +69 -0
- package/src/core/state/utils/address.js +10 -6
- package/src/core/state/utils/epochProof.js +109 -0
- package/src/core/state/utils/escrowEntry.js +178 -0
- package/src/core/state/validators/StateValidationSchema.js +757 -0
- package/src/core/state/validators/stateValidationRules.js +312 -0
- package/src/index.js +255 -65
- package/src/messages/consensus/v1/ConsensusMessageBuilder.js +368 -0
- package/src/messages/consensus/v1/ConsensusMessageDirector.js +142 -0
- package/src/messages/consensus/v1/consensusMessageFactory.js +12 -0
- package/src/messages/consensus/v1/epochAppendMessage.js +58 -0
- package/src/messages/network/v1/NetworkMessageBuilder.js +15 -7
- package/src/messages/state/ApplyStateMessageBuilder.js +499 -13
- package/src/messages/state/ApplyStateMessageDirector.js +261 -2
- package/src/utils/StateMachine.js +125 -0
- package/src/utils/applyOperations.js +45 -2
- package/src/utils/buffer.js +239 -59
- package/src/utils/consensusConfig.js +76 -0
- package/src/utils/constants.js +174 -73
- package/src/utils/helpers.js +0 -25
- package/src/utils/htlcLock.js +122 -0
- package/src/utils/logger.js +10 -4
- package/src/utils/migrationUtils.js +2 -1
- package/src/utils/normalizers.js +113 -0
- package/src/utils/scheduler/SchedulableService.js +107 -0
- package/src/utils/{Scheduler.js → scheduler/Scheduler.js} +56 -17
- package/src/core/network/services/ConnectionManager.js +0 -406
- package/src/utils/check.js +0 -525
- package/src/utils/protobuf/applyOperations.cjs +0 -1373
- package/src/utils/protobuf/operationHelpers.js +0 -81
- /package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyResponseHandler.js +0 -0
- /package/src/core/network/protocols/{legacy → validators/legacy}/validators/ValidatorResponse.js +0 -0
- /package/src/core/network/protocols/{legacy → validators/legacy}/validators/base/BaseResponse.js +0 -0
- /package/src/core/network/protocols/{v1 → validators/v1}/validators/V1LivenessRequest.js +0 -0
- /package/src/core/network/protocols/{v1 → validators/v1}/validators/V1LivenessResponse.js +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import networkV1Generated from './networkV1.generated.cjs';
|
|
3
|
+
|
|
4
|
+
const networkV1Operations = networkV1Generated.network.v1;
|
|
5
|
+
|
|
6
|
+
// Options for converting protobuf messages to plain objects, ensuring that bytes are returned as Buffers and enums as numbers.
|
|
7
|
+
|
|
8
|
+
const NETWORK_TO_OBJECT_OPTIONS = Object.freeze({
|
|
9
|
+
enums: Number,
|
|
10
|
+
longs: Number,
|
|
11
|
+
defaults: true,
|
|
12
|
+
arrays: true,
|
|
13
|
+
oneofs: false
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const encodeV1networkOperation = (payload) => {
|
|
17
|
+
return b4a.from(networkV1Operations.MessageHeader.encode(payload).finish());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const decodeV1networkOperation = (payload) => {
|
|
21
|
+
return networkV1Operations.MessageHeader.toObject(
|
|
22
|
+
networkV1Operations.MessageHeader.decode(payload),
|
|
23
|
+
NETWORK_TO_OBJECT_OPTIONS
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// protobufjs looks for `self` when running outside Node.js and browsers.
|
|
4
|
+
if (typeof globalThis.self === 'undefined') {
|
|
5
|
+
globalThis.self = globalThis;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const b4a = require('b4a');
|
|
9
|
+
const protobuf = require('protobufjs/minimal');
|
|
10
|
+
|
|
11
|
+
function isBytes(value) {
|
|
12
|
+
return b4a.isBuffer(value) || Array.isArray(value) || protobuf.util.isString(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function bytesFrom(value) {
|
|
16
|
+
if (b4a.isBuffer(value)) return b4a.toBuffer(value);
|
|
17
|
+
if (Array.isArray(value)) return b4a.from(value);
|
|
18
|
+
if (protobuf.util.isString(value)) return b4a.from(String(value), 'base64');
|
|
19
|
+
throw TypeError('bytes must be a buffer, array or base64 string');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function bytesTo(value, options) {
|
|
23
|
+
const bytes = bytesFrom(value);
|
|
24
|
+
if (options.bytes === String) return b4a.toString(bytes, 'base64');
|
|
25
|
+
if (options.bytes === Array) return Array.from(bytes);
|
|
26
|
+
return bytes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class Reader extends protobuf.Reader {
|
|
30
|
+
constructor(buffer) {
|
|
31
|
+
if (!b4a.isBuffer(buffer) && !Array.isArray(buffer)) {
|
|
32
|
+
throw TypeError('illegal buffer');
|
|
33
|
+
}
|
|
34
|
+
super(bytesFrom(buffer));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static create(buffer) {
|
|
38
|
+
// Keep a caller-supplied reader's position and length semantics.
|
|
39
|
+
return buffer instanceof protobuf.Reader ? buffer : new Reader(buffer);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
bytes() {
|
|
43
|
+
const length = this.uint32();
|
|
44
|
+
const start = this.pos;
|
|
45
|
+
const end = start + length;
|
|
46
|
+
if (end > this.len) {
|
|
47
|
+
throw RangeError(`index out of range: ${start} + ${length} > ${this.len}`);
|
|
48
|
+
}
|
|
49
|
+
this.pos = end;
|
|
50
|
+
return b4a.toBuffer(this.buf.subarray(start, end));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const adaptedWriters = new WeakSet();
|
|
55
|
+
|
|
56
|
+
class Writer extends protobuf.Writer {
|
|
57
|
+
static alloc(size) {
|
|
58
|
+
return b4a.allocUnsafe(size);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static create(writer) {
|
|
62
|
+
if (!writer) return new Writer();
|
|
63
|
+
if (writer instanceof Writer || adaptedWriters.has(writer)) return writer;
|
|
64
|
+
|
|
65
|
+
// Adapt only the supplied instance, never protobufjs's shared prototypes.
|
|
66
|
+
const bytes = writer.bytes;
|
|
67
|
+
const finish = writer.finish;
|
|
68
|
+
writer.bytes = function (value) {
|
|
69
|
+
return bytes.call(this, bytesFrom(value));
|
|
70
|
+
};
|
|
71
|
+
writer.finish = function () {
|
|
72
|
+
return bytesFrom(finish.call(this));
|
|
73
|
+
};
|
|
74
|
+
adaptedWriters.add(writer);
|
|
75
|
+
return writer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
bytes(value) {
|
|
79
|
+
return super.bytes(bytesFrom(value));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Each generated module uses this facade; other protobufjs consumers are unchanged.
|
|
84
|
+
module.exports = {
|
|
85
|
+
...protobuf,
|
|
86
|
+
Reader,
|
|
87
|
+
Writer,
|
|
88
|
+
util: {
|
|
89
|
+
...protobuf.util,
|
|
90
|
+
newBuffer: value => typeof value === 'number' ? b4a.alloc(value) : bytesFrom(value),
|
|
91
|
+
isBytes,
|
|
92
|
+
bytesFrom,
|
|
93
|
+
bytesTo
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import stateGenerated from './state.generated.cjs';
|
|
4
|
+
|
|
5
|
+
const {EscrowEntry} = stateGenerated.state;
|
|
6
|
+
const TO_OBJECT_OPTIONS = Object.freeze({
|
|
7
|
+
enums: Number,
|
|
8
|
+
defaults: false,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// These wrappers validate protobuf structure; settlement rules remain in the state helper.
|
|
12
|
+
export const encodeEscrowEntry = entry => {
|
|
13
|
+
if (!_.isPlainObject(entry)) throw new Error('Escrow entry must be an object.');
|
|
14
|
+
const error = EscrowEntry.verify(entry);
|
|
15
|
+
if (error) throw new Error(error);
|
|
16
|
+
return b4a.from(EscrowEntry.encode(entry).finish());
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const decodeEscrowEntry = encoded => {
|
|
20
|
+
if (!b4a.isBuffer(encoded) || encoded.length === 0) {
|
|
21
|
+
throw new Error('Encoded escrow entry must be a non-empty buffer.');
|
|
22
|
+
}
|
|
23
|
+
const decoded = EscrowEntry.toObject(EscrowEntry.decode(encoded), TO_OBJECT_OPTIONS);
|
|
24
|
+
// Generated byte fields may alias the input; return independent buffers.
|
|
25
|
+
for (const [field, value] of Object.entries(decoded)) {
|
|
26
|
+
if (b4a.isBuffer(value)) decoded[field] = b4a.from(value);
|
|
27
|
+
}
|
|
28
|
+
return decoded;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const safeEncodeEscrowEntry = entry => {
|
|
32
|
+
try {
|
|
33
|
+
return encodeEscrowEntry(entry);
|
|
34
|
+
} catch {
|
|
35
|
+
return b4a.alloc(0);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const safeDecodeEscrowEntry = encoded => {
|
|
40
|
+
try {
|
|
41
|
+
return decodeEscrowEntry(encoded);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|