trac-msb 0.2.13 → 0.2.15

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.
Files changed (121) hide show
  1. package/.github/workflows/acceptance-tests.yml +38 -0
  2. package/.github/workflows/lint-pr-title.yml +26 -0
  3. package/.github/workflows/publish.yml +33 -0
  4. package/.github/workflows/unit-tests.yml +34 -0
  5. package/package.json +7 -12
  6. package/proto/network.proto +74 -0
  7. package/rpc/rpc_services.js +4 -22
  8. package/scripts/generate-protobufs.js +12 -37
  9. package/src/config/config.js +9 -26
  10. package/src/config/env.js +17 -27
  11. package/src/core/network/Network.js +36 -73
  12. package/src/core/network/protocols/LegacyProtocol.js +11 -21
  13. package/src/core/network/protocols/NetworkMessages.js +17 -38
  14. package/src/core/network/protocols/ProtocolInterface.js +2 -14
  15. package/src/core/network/protocols/ProtocolSession.js +17 -144
  16. package/src/core/network/protocols/V1Protocol.js +18 -37
  17. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +19 -25
  18. package/src/core/network/protocols/legacy/handlers/{LegacyGetRequestHandler.js → GetRequestHandler.js} +6 -6
  19. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  20. package/src/core/network/protocols/{legacy/handlers/LegacyRoleOperationHandler.js → shared/handlers/RoleOperationHandler.js} +11 -18
  21. package/src/core/network/protocols/{legacy/handlers/LegacySubnetworkOperationHandler.js → shared/handlers/SubnetworkOperationHandler.js} +17 -28
  22. package/src/core/network/protocols/{legacy/handlers/LegacyTransferOperationHandler.js → shared/handlers/TransferOperationHandler.js} +11 -17
  23. package/src/core/network/protocols/{legacy/handlers/BaseStateOperationHandler.js → shared/handlers/base/BaseOperationHandler.js} +12 -23
  24. package/src/core/network/protocols/shared/validators/{PartialBootstrapDeploymentValidator.js → PartialBootstrapDeployment.js} +4 -9
  25. package/src/core/network/protocols/shared/validators/{PartialRoleAccessValidator.js → PartialRoleAccess.js} +17 -51
  26. package/src/core/network/protocols/shared/validators/{PartialTransactionValidator.js → PartialTransaction.js} +7 -21
  27. package/src/core/network/protocols/shared/validators/{PartialTransferValidator.js → PartialTransfer.js} +9 -26
  28. package/src/core/network/protocols/shared/validators/{PartialOperationValidator.js → base/PartialOperation.js} +25 -47
  29. package/src/core/network/protocols/v1/NetworkMessageRouter.js +7 -91
  30. package/src/core/network/services/ConnectionManager.js +94 -146
  31. package/src/core/network/services/MessageOrchestrator.js +27 -151
  32. package/src/core/network/services/TransactionPoolService.js +18 -129
  33. package/src/core/network/services/TransactionRateLimiterService.js +34 -52
  34. package/src/core/network/services/ValidatorObserverService.js +26 -18
  35. package/src/core/state/State.js +19 -70
  36. package/src/index.js +8 -6
  37. package/src/messages/network/v1/NetworkMessageBuilder.js +79 -59
  38. package/src/messages/network/v1/NetworkMessageDirector.js +50 -16
  39. package/src/utils/Scheduler.js +8 -0
  40. package/src/utils/constants.js +5 -71
  41. package/src/utils/helpers.js +1 -10
  42. package/src/utils/normalizers.js +0 -38
  43. package/src/utils/protobuf/network.cjs +840 -0
  44. package/src/utils/protobuf/operationHelpers.js +3 -24
  45. package/tests/acceptance/v1/account/account.test.mjs +2 -8
  46. package/tests/acceptance/v1/tx/tx.test.mjs +1 -23
  47. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +6 -34
  48. package/tests/fixtures/assembleMessage.fixtures.js +8 -7
  49. package/tests/fixtures/networkV1.fixtures.js +28 -2
  50. package/tests/helpers/autobaseTestHelpers.js +5 -2
  51. package/tests/helpers/createTestSignature.js +3 -2
  52. package/tests/helpers/transactionPayloads.mjs +2 -2
  53. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +79 -239
  54. package/tests/unit/messages/network/NetworkMessageDirector.test.js +77 -223
  55. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +5 -1
  56. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +5 -1
  57. package/tests/unit/network/ConnectionManager.test.js +191 -0
  58. package/tests/unit/network/networkModule.test.js +1 -4
  59. package/tests/unit/unit.test.js +2 -2
  60. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -2
  61. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -2
  62. package/tests/unit/utils/protobuf/operationHelpers.test.js +4 -2
  63. package/tests/unit/utils/utils.test.js +0 -1
  64. package/proto/network/v1/enums/message_type.proto +0 -16
  65. package/proto/network/v1/enums/result_code.proto +0 -84
  66. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  67. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  68. package/proto/network/v1/messages/liveness_request.proto +0 -8
  69. package/proto/network/v1/messages/liveness_response.proto +0 -11
  70. package/proto/network/v1/network_message.proto +0 -22
  71. package/src/core/network/protocols/connectionPolicies.js +0 -88
  72. package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +0 -23
  73. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  74. package/src/core/network/protocols/v1/V1ProtocolError.js +0 -91
  75. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +0 -65
  76. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +0 -389
  77. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +0 -87
  78. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +0 -211
  79. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +0 -26
  80. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +0 -276
  81. package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +0 -15
  82. package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +0 -17
  83. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +0 -210
  84. package/src/core/network/services/PendingRequestService.js +0 -172
  85. package/src/core/network/services/TransactionCommitService.js +0 -149
  86. package/src/core/network/services/ValidatorHealthCheckService.js +0 -127
  87. package/src/utils/deepEqualApplyPayload.js +0 -40
  88. package/src/utils/logger.js +0 -25
  89. package/src/utils/protobuf/networkV1.generated.cjs +0 -2460
  90. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  91. package/tests/unit/network/ProtocolSession.test.js +0 -127
  92. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  93. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  94. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  95. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  96. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  97. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  98. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  99. package/tests/unit/network/services/services.test.js +0 -17
  100. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  101. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  102. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  103. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  104. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  105. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  106. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  107. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  108. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  109. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  110. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  111. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  112. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  113. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  114. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  115. package/tests/unit/network/v1/v1.test.js +0 -19
  116. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  117. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  118. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  119. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  120. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  121. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
@@ -0,0 +1,38 @@
1
+ name: MSB-Acceptance-Tests
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ workflow_run:
6
+ workflows: ["MSB-Unit-Tests"]
7
+ types:
8
+ - completed
9
+
10
+ concurrency:
11
+ group: ${{ github.workflow }}-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ integration-tests:
16
+ name: Acceptance Tests
17
+ runs-on: [self-hosted, Linux, X64]
18
+ if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
19
+ strategy:
20
+ matrix:
21
+ node-version: [ lts/* ]
22
+
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+
26
+ - name: Use Node.js ${{ matrix.node-version }}
27
+ uses: actions/setup-node@v3
28
+ with:
29
+ node-version: ${{ matrix.node-version }}
30
+
31
+ - name: Install dependencies
32
+ run: npm ci
33
+
34
+ - name: Install bare
35
+ run: npm i -g bare
36
+
37
+ - name: Run Integration Tests
38
+ run: npm run test:acceptance
@@ -0,0 +1,26 @@
1
+ name: Lint PR title
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [opened, reopened, edited, synchronize]
6
+
7
+ jobs:
8
+ main:
9
+ name: Validate PR title convention
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ pull-requests: read
13
+ steps:
14
+ - uses: amannn/action-semantic-pull-request@v6.1.1
15
+ env:
16
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17
+ with:
18
+ # Allow optional scopes like feat(ui): ...
19
+ # By default scopes are allowed (no restriction) and are optional.
20
+ requireScope: false
21
+
22
+ # Optional: require a non-empty subject after ": "
23
+ subjectPattern: ^.+$
24
+ subjectPatternError: |
25
+ The pull request title must have a non-empty subject after ": ".
26
+ Example: "feat: add new command"
@@ -0,0 +1,33 @@
1
+ name: Publish trac-msb to npm on release
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ id-token: write # Required for OIDC
9
+ contents: read
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout release tag
16
+ uses: actions/checkout@v4
17
+ with:
18
+ ref: ${{ github.event.release.tag_name }}
19
+
20
+ - name: Use Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: '24'
24
+ registry-url: 'https://registry.npmjs.org'
25
+ - name: Install dependencies
26
+ run: npm ci
27
+
28
+ # unit tests are temporarily disabled because they lost stability on GH runners.
29
+ #- name: Run unit tests
30
+ # run: npm run test:unit:all
31
+
32
+ - name: Publish to npm
33
+ run: npm publish --access public
@@ -0,0 +1,34 @@
1
+ name: MSB-Unit-Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+ workflow_dispatch:
11
+
12
+ concurrency:
13
+ group: ${{ github.workflow }}-${{ github.ref }}
14
+ cancel-in-progress: true
15
+
16
+ jobs:
17
+ tests:
18
+ runs-on: [self-hosted, Linux, X64]
19
+
20
+ strategy:
21
+ matrix:
22
+ node-version: [lts/*]
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - name: Use Node.js ${{ matrix.node-version }}
26
+ uses: actions/setup-node@v4
27
+ with:
28
+ node-version: ${{ matrix.node-version }}
29
+ - name: Install dependencies
30
+ run: npm ci
31
+ - name: Install bare
32
+ run: npm i -g bare
33
+ - name: Run all tests
34
+ run: npm run test:unit:all
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.2.13",
4
+ "version": "0.2.15",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -18,9 +18,9 @@
18
18
  "test:integration": "brittle-node -t 1200000 tests/integration/integration.test.js",
19
19
  "test:unit:node": "brittle-node -t 60000 tests/unit/unit.test.js",
20
20
  "test:unit:bare": "brittle-bare -t 60000 tests/unit/unit.test.js",
21
- "test:unit:pear": "BRITTLE='-t 60000' brittle-pear tests/unit/unit.test.js",
22
21
  "test:unit:all": "(npm run test:unit:node && npm run test:unit:bare) || exit 1",
23
- "test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js"
22
+ "test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js",
23
+ "test:unit:bare:cov": "brittle-bare -c -t 60000 tests/unit/unit.test.js"
24
24
  },
25
25
  "dependencies": {
26
26
  "autobase": "7.20.1",
@@ -35,7 +35,6 @@
35
35
  "compact-encoding": "2.18.0",
36
36
  "corestore": "7.5.0",
37
37
  "crypto": "npm:bare-node-crypto",
38
- "denque": "^2.1.0",
39
38
  "fastest-validator": "1.19.0",
40
39
  "http": "npm:bare-node-http",
41
40
  "hyperbee": "2.26.5",
@@ -44,29 +43,25 @@
44
43
  "hyperdht": "6.27.0",
45
44
  "hyperswarm": "4.14.2",
46
45
  "lodash": "^4.17.23",
47
- "p-queue": "^9.1.0",
48
- "protobufjs": "^7.5.4",
49
46
  "protocol-buffers-encodings": "1.2.0",
50
47
  "protomux": "3.10.1",
51
48
  "protomux-wakeup": "2.4.0",
52
49
  "readline": "npm:bare-node-readline",
53
50
  "ready-resource": "1.1.2",
54
- "trac-wallet": "1.0.3",
51
+ "trac-crypto-api": "0.1.5",
52
+ "trac-wallet": "1.0.4",
55
53
  "tty": "npm:bare-node-tty",
56
54
  "uuid": "^13.0.0"
57
55
  },
58
56
  "devDependencies": {
59
- "bare-module": "^6.1.3",
60
57
  "bare-os": "^3.6.1",
61
58
  "bip39-mnemonic": "^2.4.0",
62
- "brittle": "^3.19.1",
59
+ "brittle": "^3.17.1",
63
60
  "esmock": "^2.7.2",
64
61
  "jest": "^30.1.3",
65
- "protobufjs-cli": "^1.2.0",
66
62
  "protocol-buffers": "^4.2.0",
67
63
  "sinon": "^21.0.0",
68
- "supertest": "^7.1.4",
69
- "trac-crypto-api": "^0.1.1"
64
+ "supertest": "^7.1.4"
70
65
  },
71
66
  "publishConfig": {
72
67
  "registry": "https://registry.npmjs.org",
@@ -0,0 +1,74 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ enum MessageType {
6
+ MESSAGE_TYPE_UNSPECIFIED = 0;
7
+ MESSAGE_TYPE_VALIDATOR_CONNECTION_REQUEST = 1;
8
+ MESSAGE_TYPE_VALIDATOR_CONNECTION_RESPONSE = 2;
9
+ MESSAGE_TYPE_LIVENESS_REQUEST = 3;
10
+ MESSAGE_TYPE_LIVENESS_RESPONSE = 4;
11
+ MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST = 5;
12
+ MESSAGE_TYPE_BROADCAST_TRANSACTION_RESPONSE = 6;
13
+ }
14
+
15
+ enum ResultCode {
16
+ RESULT_CODE_UNSPECIFIED = 0;
17
+ RESULT_CODE_OK = 1;
18
+ RESULT_CODE_INVALID_PAYLOAD = 2;
19
+ RESULT_CODE_UNSUPPORTED_VERSION = 3;
20
+ RESULT_CODE_RATE_LIMITED = 4;
21
+ RESULT_CODE_TIMEOUT = 5;
22
+ RESULT_CODE_SIGNATURE_INVALID = 6;
23
+ }
24
+
25
+ message ValidatorConnectionRequest {
26
+ string issuer_address = 1;
27
+ bytes nonce = 2;
28
+ bytes signature = 3;
29
+ }
30
+
31
+ message ValidatorConnectionResponse {
32
+ string issuer_address = 1;
33
+ bytes nonce = 2;
34
+ bytes signature = 3;
35
+ ResultCode result = 4;
36
+ }
37
+
38
+ message LivenessRequest {
39
+ bytes nonce = 1;
40
+ bytes signature = 2;
41
+ }
42
+
43
+ message LivenessResponse {
44
+ bytes nonce = 1;
45
+ bytes signature = 2;
46
+ ResultCode result = 3;
47
+ }
48
+
49
+ message BroadcastTransactionRequest {
50
+ bytes data = 1; // binary encoded payload
51
+ bytes nonce = 2;
52
+ bytes signature = 3;
53
+ }
54
+
55
+ message BroadcastTransactionResponse {
56
+ bytes nonce = 1;
57
+ bytes signature = 2;
58
+ ResultCode result = 3;
59
+ }
60
+
61
+ message MessageHeader {
62
+ MessageType type = 1;
63
+ string id = 2;
64
+ uint64 timestamp = 3;
65
+ oneof field {
66
+ ValidatorConnectionRequest validator_connection_request = 4;
67
+ ValidatorConnectionResponse validator_connection_response = 5;
68
+ LivenessRequest liveness_request = 6;
69
+ LivenessResponse liveness_response = 7;
70
+ BroadcastTransactionRequest broadcast_transaction_request = 8;
71
+ BroadcastTransactionResponse broadcast_transaction_response = 9;
72
+ }
73
+ repeated string capabilities = 10;
74
+ }
@@ -6,23 +6,10 @@ import {
6
6
  } from "../src/utils/normalizers.js";
7
7
  import { get_confirmed_tx_info, get_unconfirmed_tx_info } from "../src/utils/cli.js";
8
8
  import { OperationType } from "../src/utils/constants.js";
9
- import { sleep } from "../src/utils/helpers.js";
10
9
  import b4a from "b4a";
10
+ import PartialTransaction from "../src/core/network/protocols/shared/validators/PartialTransaction.js";
11
+ import PartialTransfer from "../src/core/network/protocols/shared/validators/PartialTransfer.js";
11
12
  import { ValidationError, BroadcastError, NotFoundError } from "./utils/helpers.js";
12
- import PartialTransactionValidator from "../src/core/network/protocols/shared/validators/PartialTransactionValidator.js";
13
- import PartialTransferValidator from "../src/core/network/protocols/shared/validators/PartialTransferValidator.js";
14
-
15
- // This was added because V1 is not waiting for signed/unsigned state. So to include reverse compatibility
16
- // we need to slow down v1 to legacy case.
17
- const waitForUnconfirmedTx = async (state, txHash, config) => {
18
- const startedAt = Date.now();
19
- while ((Date.now() - startedAt) < config.messageValidatorResponseTimeout) {
20
- const payload = await state.get(txHash);
21
- if (payload) return true;
22
- await sleep(100);
23
- }
24
- return false;
25
- };
26
13
 
27
14
  export async function getBalance(msbInstance, address, confirmed) {
28
15
  const state = msbInstance.state;
@@ -67,8 +54,8 @@ export async function broadcastTransaction(msbInstance, config, payload) {
67
54
  let isValid = false;
68
55
  let hash;
69
56
 
70
- const partialTransferValidator = new PartialTransferValidator(msbInstance.state, null , config);
71
- const partialTransactionValidator = new PartialTransactionValidator(msbInstance.state, null , config);
57
+ const partialTransferValidator = new PartialTransfer(msbInstance.state, null, config);
58
+ const partialTransactionValidator = new PartialTransaction(msbInstance.state, null, config);
72
59
 
73
60
  if (payload.type === OperationType.TRANSFER) {
74
61
  normalizedPayload = normalizeTransferOperation(payload, config);
@@ -90,11 +77,6 @@ export async function broadcastTransaction(msbInstance, config, payload) {
90
77
  throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
91
78
  }
92
79
 
93
- const isConfirmed = await waitForUnconfirmedTx(msbInstance.state, hash, config);
94
- if (!isConfirmed) {
95
- throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
96
- }
97
-
98
80
  const signedLength = msbInstance.state.getSignedLength();
99
81
  const unsignedLength = msbInstance.state.getUnsignedLength();
100
82
 
@@ -2,10 +2,10 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
4
  import { fileURLToPath } from 'url';
5
- import { execFileSync } from 'child_process';
5
+ import { execSync } from 'child_process';
6
6
 
7
7
  function generateCJSFromProto(inputPath, outputPath) {
8
- execFileSync('protocol-buffers', [inputPath, '-o', outputPath]);
8
+ execSync(`protocol-buffers "${inputPath}" -o "${outputPath}"`);
9
9
  console.log(`${outputPath} has been generated.`);
10
10
  }
11
11
 
@@ -17,51 +17,26 @@ function transformToUseB4a(outputPath) {
17
17
  console.log(`${outputPath} has been modified to use b4a.`);
18
18
  }
19
19
 
20
- function generatePbjsModule(pbjsPath, protoRootPath, entryPath, outputPath) {
21
- execFileSync(pbjsPath, [
22
- '-t', 'static-module',
23
- '-w', 'commonjs',
24
- '--keep-case',
25
- '-p', protoRootPath,
26
- '-o', outputPath,
27
- entryPath
28
- ]);
29
- console.log(`${outputPath} has been generated.`);
30
- }
31
-
32
- function transformPbjsForBare(outputPath) {
33
- let content = fs.readFileSync(outputPath, 'utf-8');
34
- const shim = `if (typeof globalThis !== 'undefined' && typeof globalThis.self === 'undefined') {\n globalThis.self = globalThis;\n}\n`;
35
- const strictDirective = '"use strict";';
36
-
37
- if (content.includes(strictDirective)) {
38
- content = content.replace(strictDirective, `${strictDirective}\n${shim}`);
39
- } else {
40
- content = `${strictDirective}\n${shim}${content}`;
41
- }
42
-
43
- fs.writeFileSync(outputPath, content, 'utf-8');
44
- console.log(`${outputPath} has been modified for bare-compatible protobufjs runtime.`);
45
- }
46
20
 
47
21
  function main() {
48
22
  const directoryName = path.dirname(fileURLToPath(import.meta.url));
49
23
 
50
24
  const inputDir = path.join(directoryName, '../proto');
51
25
  const outputDir = path.join(directoryName, '../src/utils/protobuf');
52
- const pbjsPath = path.join(directoryName, '../node_modules/.bin/pbjs');
53
- const applyInputPath = path.join(inputDir, 'applyOperations.proto');
54
- const applyOutputPath = path.join(outputDir, 'applyOperations.cjs');
55
- const networkEntryPath = path.join(inputDir, 'network/v1/network_message.proto');
56
- const generatedNetworkOutputPath = path.join(outputDir, 'networkV1.generated.cjs');
57
26
 
58
27
  fs.mkdirSync(outputDir, { recursive: true });
59
28
 
60
- generateCJSFromProto(applyInputPath, applyOutputPath);
61
- transformToUseB4a(applyOutputPath);
29
+ const files = fs.readdirSync(inputDir).filter(f => f.endsWith('.proto'));
62
30
 
63
- generatePbjsModule(pbjsPath, inputDir, networkEntryPath, generatedNetworkOutputPath);
64
- transformPbjsForBare(generatedNetworkOutputPath);
31
+ for (const file of files) {
32
+ const name = path.basename(file, '.proto');
33
+ const inputPath = path.join(inputDir, file);
34
+ const outputPath = path.join(outputDir, `${name}.cjs`);
35
+
36
+ generateCJSFromProto(inputPath, outputPath);
37
+ transformToUseB4a(outputPath);
38
+ }
65
39
  }
66
40
 
67
41
  main();
42
+
@@ -46,6 +46,10 @@ export class Config {
46
46
  return this.#config.dhtBootstrap
47
47
  }
48
48
 
49
+ get derivationPath() {
50
+ return this.#config.derivationPath
51
+ }
52
+
49
53
  get disableRateLimit() {
50
54
  if (this.#isOverriden('disableRateLimit')) return !!this.#options.disableRateLimit
51
55
  return !!this.#config.disableRateLimit
@@ -129,6 +133,11 @@ export class Config {
129
133
  return this.#config.processIntervalMs
130
134
  }
131
135
 
136
+ get maxPartialTxPayloadByteSize() {
137
+ if (this.#isOverriden('maxPartialTxPayloadByteSize')) return this.#options.maxPartialTxPayloadByteSize
138
+ return this.#config.maxPartialTxPayloadByteSize
139
+ }
140
+
132
141
  get transactionPoolSize() {
133
142
  if (this.#isOverriden('transactionPoolSize')) return this.#options.transactionPoolSize
134
143
  return this.#config.transactionPoolSize
@@ -189,31 +198,6 @@ export class Config {
189
198
  if (this.#isOverriden('rateLimitMaxTransactionsPerSecond')) return this.#options.rateLimitMaxTransactionsPerSecond
190
199
  return this.#config.rateLimitMaxTransactionsPerSecond
191
200
  }
192
-
193
- get pendingRequestTimeout() {
194
- return this.#config.pendingRequestTimeout
195
- }
196
-
197
- get txCommitTimeout() {
198
- return this.#config.txCommitTimeout
199
- }
200
-
201
- get txPoolSize() {
202
- return this.#config.txPoolSize
203
- }
204
-
205
- get validatorHealthCheckInterval() {
206
- if (this.#isOverriden('validatorHealthCheckInterval')) return this.#options.validatorHealthCheckInterval
207
- return this.#config.validatorHealthCheckInterval
208
- }
209
-
210
- get maxPendingRequestsInPendingRequestsService() {
211
- return this.#config.maxPendingRequestsInPendingRequestsService
212
- }
213
-
214
- get debug() {
215
- return this.#config.debug
216
- }
217
201
 
218
202
  // Most of these properties are boolean
219
203
  #isOverriden(prop) {
@@ -227,5 +211,4 @@ export class Config {
227
211
  );
228
212
  }
229
213
  }
230
-
231
214
  }
package/src/config/env.js CHANGED
@@ -1,23 +1,25 @@
1
1
  import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet/constants.js';
2
- import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
3
2
  import { Config } from './config.js';
3
+ import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
4
+ import { address } from 'trac-crypto-api';
4
5
 
5
6
  export const ENV = {
6
7
  MAINNET: 'mainnet',
7
8
  DEVELOPMENT: 'development',
8
9
  TESTNET1: 'testnet1'
9
10
  }
11
+ // TODO: CREATE TEST ENV CONFIG SIMILAR TO MAINNET AND USE IT IN TESTS.
10
12
 
11
13
  const configData = {
12
14
  [ENV.TESTNET1]: {
13
- debug: false,
14
15
  addressLength: 67,
15
16
  addressPrefix: TRAC_NETWORK_MSB_TESTNET1_PREFIX,
16
17
  addressPrefixLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length,
17
18
  bech32mHrpLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length + 1, // len(addressPrefix + separator)
18
- bootstrap: 'a7c0c2cf8e4722129097f89b2a29a092f23d6268fcca3fd9570ba5b702b99b95',
19
+ bootstrap: 'c184f4ad8e9cf5e911f9415b60e7dcfb30aed73ebd8a402ef68e1b154624f5ef',
19
20
  channel: '1111trac1network1msb1testnet1111',
20
21
  dhtBootstrap: ['116.202.214.149:10001', '157.180.12.214:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'], // these are used to peer discovery
22
+ derivationPath: address.TESNET_DERIVATION_PATH,
21
23
  disableRateLimit: false,
22
24
  enableErrorApplyLogs: true,
23
25
  enableInteractiveMode: true,
@@ -25,9 +27,9 @@ const configData = {
25
27
  enableTxApplyLogs: true,
26
28
  enableValidatorObserver: true,
27
29
  enableWallet: true,
28
- maxValidators: 50,
29
- maxRetries: 3,
30
- messageThreshold: 3,
30
+ maxValidators: 6,
31
+ maxRetries: 1,
32
+ messageThreshold: 1000,
31
33
  messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
32
34
  messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
33
35
  host: 'localhost',
@@ -39,20 +41,15 @@ const configData = {
39
41
  maxClientConnections: Infinity, // Connectivity constants
40
42
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
41
43
  processIntervalMs: 50, // Pool constants
44
+ maxPartialTxPayloadByteSize: 3072, // Operation handler constants
42
45
  transactionPoolSize: 1000, // Operation handler constants
43
46
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
44
47
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
45
48
  rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
46
- maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
47
- pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
48
- txCommitTimeout: 2200,
49
- txPoolSize: 1000, // size of transaction pool
50
- validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
51
- storesDirectory: 'stores/',
49
+ storesDirectory : 'stores/',
52
50
  storeName: 'testnet',
53
51
  },
54
52
  [ENV.MAINNET]: {
55
- debug: false,
56
53
  addressLength: 63,
57
54
  addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
58
55
  addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
@@ -60,6 +57,7 @@ const configData = {
60
57
  bootstrap: 'acbc3a4344d3a804101d40e53db1dda82b767646425af73599d4cd6577d69685',
61
58
  channel: '0000trac0network0msb0mainnet0000',
62
59
  dhtBootstrap: ['116.202.214.149:10001', '157.180.12.214:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'],
60
+ derivationPath: address.MAINNET_DERIVATION_PATH,
63
61
  disableRateLimit: false,
64
62
  enableErrorApplyLogs: false,
65
63
  enableInteractiveMode: true,
@@ -81,20 +79,15 @@ const configData = {
81
79
  maxClientConnections: Infinity, // Connectivity constants
82
80
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
83
81
  processIntervalMs: 50, // Pool constants
82
+ maxPartialTxPayloadByteSize: 3072, // Operation handler constants
84
83
  transactionPoolSize: 1000, // Operation handler constants
85
84
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
86
85
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
87
86
  rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
88
- maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
89
- pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
90
- txCommitTimeout: 2200,
91
- txPoolSize: 1000, // size of transaction pool
92
- validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
93
87
  storesDirectory: 'stores/',
94
88
  storeName: 'mainnet',
95
89
  },
96
90
  [ENV.DEVELOPMENT]: {
97
- debug: true,
98
91
  addressLength: 63,
99
92
  addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
100
93
  addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
@@ -102,6 +95,7 @@ const configData = {
102
95
  bootstrap: 'e90cca53847a12a82f3bf0f67401e45e2ccc1698ee163e61414c2894eb3c6b12',
103
96
  channel: '12312313123123',
104
97
  dhtBootstrap: ['116.202.214.149:10001', '157.180.12.214:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'],
98
+ derivationPath: address.MAINNET_DERIVATION_PATH,
105
99
  disableRateLimit: false,
106
100
  enableErrorApplyLogs: true,
107
101
  enableInteractiveMode: true,
@@ -110,29 +104,25 @@ const configData = {
110
104
  enableValidatorObserver: true,
111
105
  enableWallet: true,
112
106
  maxValidators: 6,
113
- maxRetries: 3,
107
+ maxRetries: 0,
114
108
  messageThreshold: 1000,
115
109
  messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
116
110
  messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
117
111
  host: 'localhost',
118
112
  port: 5000,
119
- networkId: TRAC_NETWORK_TESTNET_ID,
113
+ networkId: TRAC_NETWORK_MAINNET_ID,
120
114
  maxPeers: 64, // Connectivity constants
121
115
  maxParallel: 64, // Connectivity constants
122
116
  maxServerConnections: Infinity, // Connectivity constants
123
117
  maxClientConnections: Infinity, // Connectivity constants
124
118
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
125
119
  processIntervalMs: 50, // Pool constants
120
+ maxPartialTxPayloadByteSize: 3072, // Operation handler constants
126
121
  transactionPoolSize: 1000, // Operation handler constants
127
122
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
128
123
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
129
124
  rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
130
- maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
131
- pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
132
- txCommitTimeout: 2200,
133
- txPoolSize: 1000, // size of transaction pool
134
- validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
135
- storesDirectory: 'stores/',
125
+ storesDirectory : 'stores/',
136
126
  storeName: 'development',
137
127
  }
138
128
  }