trac-msb 0.2.10 → 0.2.11

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 (114) hide show
  1. package/package.json +9 -4
  2. package/proto/network/v1/enums/message_type.proto +16 -0
  3. package/proto/network/v1/enums/result_code.proto +84 -0
  4. package/proto/network/v1/messages/broadcast_transaction_request.proto +9 -0
  5. package/proto/network/v1/messages/broadcast_transaction_response.proto +13 -0
  6. package/proto/network/v1/messages/liveness_request.proto +8 -0
  7. package/proto/network/v1/messages/liveness_response.proto +11 -0
  8. package/proto/network/v1/network_message.proto +22 -0
  9. package/rpc/rpc_services.js +22 -4
  10. package/scripts/generate-protobufs.js +37 -12
  11. package/src/config/config.js +26 -5
  12. package/src/config/env.js +25 -11
  13. package/src/core/network/Network.js +73 -36
  14. package/src/core/network/protocols/LegacyProtocol.js +21 -11
  15. package/src/core/network/protocols/NetworkMessages.js +38 -17
  16. package/src/core/network/protocols/ProtocolInterface.js +14 -2
  17. package/src/core/network/protocols/ProtocolSession.js +144 -17
  18. package/src/core/network/protocols/V1Protocol.js +37 -18
  19. package/src/core/network/protocols/connectionPolicies.js +88 -0
  20. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +25 -19
  21. package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +23 -12
  22. package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +6 -6
  23. package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
  24. package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +18 -11
  25. package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +28 -17
  26. package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +17 -11
  27. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +27 -0
  28. package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
  29. package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +47 -25
  30. package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
  31. package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
  32. package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +26 -9
  33. package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
  34. package/src/core/network/protocols/v1/V1ProtocolError.js +91 -0
  35. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +65 -0
  36. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +389 -0
  37. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +87 -0
  38. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +211 -0
  39. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +26 -0
  40. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +276 -0
  41. package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
  42. package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
  43. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
  44. package/src/core/network/services/ConnectionManager.js +146 -94
  45. package/src/core/network/services/MessageOrchestrator.js +151 -27
  46. package/src/core/network/services/PendingRequestService.js +172 -0
  47. package/src/core/network/services/TransactionCommitService.js +149 -0
  48. package/src/core/network/services/TransactionPoolService.js +129 -18
  49. package/src/core/network/services/TransactionRateLimiterService.js +52 -34
  50. package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
  51. package/src/core/network/services/ValidatorObserverService.js +18 -26
  52. package/src/core/state/State.js +70 -19
  53. package/src/index.js +5 -4
  54. package/src/messages/network/v1/NetworkMessageBuilder.js +59 -79
  55. package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
  56. package/src/utils/Scheduler.js +0 -8
  57. package/src/utils/constants.js +71 -5
  58. package/src/utils/deepEqualApplyPayload.js +40 -0
  59. package/src/utils/helpers.js +10 -1
  60. package/src/utils/logger.js +25 -0
  61. package/src/utils/normalizers.js +38 -0
  62. package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
  63. package/src/utils/protobuf/operationHelpers.js +24 -3
  64. package/tests/acceptance/v1/account/account.test.mjs +8 -2
  65. package/tests/acceptance/v1/tx/tx.test.mjs +23 -1
  66. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +34 -6
  67. package/tests/fixtures/networkV1.fixtures.js +2 -28
  68. package/tests/helpers/transactionPayloads.mjs +2 -2
  69. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +239 -79
  70. package/tests/unit/messages/network/NetworkMessageDirector.test.js +223 -77
  71. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +54 -0
  72. package/tests/unit/network/ProtocolSession.test.js +127 -0
  73. package/tests/unit/network/networkModule.test.js +4 -1
  74. package/tests/unit/network/services/ConnectionManager.test.js +450 -0
  75. package/tests/unit/network/services/MessageOrchestrator.test.js +445 -0
  76. package/tests/unit/network/services/PendingRequestService.test.js +431 -0
  77. package/tests/unit/network/services/TransactionCommitService.test.js +246 -0
  78. package/tests/unit/network/services/TransactionPoolService.test.js +489 -0
  79. package/tests/unit/network/services/TransactionRateLimiterService.test.js +139 -0
  80. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +115 -0
  81. package/tests/unit/network/services/services.test.js +17 -0
  82. package/tests/unit/network/utils/v1TestUtils.js +153 -0
  83. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +151 -0
  84. package/tests/unit/network/v1/V1BaseOperation.test.js +356 -0
  85. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +129 -0
  86. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +53 -0
  87. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +512 -0
  88. package/tests/unit/network/v1/V1LivenessRequest.test.js +32 -0
  89. package/tests/unit/network/v1/V1LivenessResponse.test.js +45 -0
  90. package/tests/unit/network/v1/V1ResultCode.test.js +84 -0
  91. package/tests/unit/network/v1/V1ValidationSchema.test.js +13 -0
  92. package/tests/unit/network/v1/connectionPolicies.test.js +49 -0
  93. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +284 -0
  94. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +794 -0
  95. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +193 -0
  96. package/tests/unit/network/v1/v1.handlers.test.js +15 -0
  97. package/tests/unit/network/v1/v1.test.js +19 -0
  98. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +119 -0
  99. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +136 -0
  100. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +308 -0
  101. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +90 -0
  102. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +133 -0
  103. package/tests/unit/unit.test.js +2 -2
  104. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +102 -0
  105. package/tests/unit/utils/protobuf/operationHelpers.test.js +2 -4
  106. package/tests/unit/utils/utils.test.js +1 -0
  107. package/.github/workflows/acceptance-tests.yml +0 -38
  108. package/.github/workflows/lint-pr-title.yml +0 -26
  109. package/.github/workflows/publish.yml +0 -33
  110. package/.github/workflows/unit-tests.yml +0 -34
  111. package/proto/network.proto +0 -74
  112. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
  113. package/src/utils/protobuf/network.cjs +0 -840
  114. package/tests/unit/network/ConnectionManager.test.js +0 -191
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.2.10",
4
+ "version": "0.2.11",
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",
21
22
  "test:unit:all": "(npm run test:unit:node && npm run test:unit:bare) || exit 1",
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"
23
+ "test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js"
24
24
  },
25
25
  "dependencies": {
26
26
  "autobase": "7.20.1",
@@ -35,6 +35,7 @@
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",
38
39
  "fastest-validator": "1.19.0",
39
40
  "http": "npm:bare-node-http",
40
41
  "hyperbee": "2.26.5",
@@ -43,6 +44,8 @@
43
44
  "hyperdht": "6.27.0",
44
45
  "hyperswarm": "4.14.2",
45
46
  "lodash": "^4.17.23",
47
+ "p-queue": "^9.1.0",
48
+ "protobufjs": "^7.5.4",
46
49
  "protocol-buffers-encodings": "1.2.0",
47
50
  "protomux": "3.10.1",
48
51
  "protomux-wakeup": "2.4.0",
@@ -53,11 +56,13 @@
53
56
  "uuid": "^13.0.0"
54
57
  },
55
58
  "devDependencies": {
59
+ "bare-module": "^6.1.3",
56
60
  "bare-os": "^3.6.1",
57
61
  "bip39-mnemonic": "^2.4.0",
58
- "brittle": "^3.17.1",
62
+ "brittle": "^3.19.1",
59
63
  "esmock": "^2.7.2",
60
64
  "jest": "^30.1.3",
65
+ "protobufjs-cli": "^1.2.0",
61
66
  "protocol-buffers": "^4.2.0",
62
67
  "sinon": "^21.0.0",
63
68
  "supertest": "^7.1.4",
@@ -0,0 +1,16 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ // Warning: Do not change numeric values of existing enum fields.
6
+ // They are part of the public API.
7
+ // New values may be added, but existing values must never be renumbered or reused.
8
+ // Use [deprecated = true] while phasing out a value that still remains in the schema.
9
+ // If a value is removed, reserve its number (and preferably its name).
10
+ enum MessageType {
11
+ MESSAGE_TYPE_UNSPECIFIED = 0;
12
+ MESSAGE_TYPE_LIVENESS_REQUEST = 1;
13
+ MESSAGE_TYPE_LIVENESS_RESPONSE = 2;
14
+ MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST = 3;
15
+ MESSAGE_TYPE_BROADCAST_TRANSACTION_RESPONSE = 4;
16
+ }
@@ -0,0 +1,84 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ // Warning: Do not change numeric values of existing enum fields.
6
+ // They are part of the public API.
7
+ // New values may be added, but existing values must never be renumbered or reused.
8
+ // Use [deprecated = true] while phasing out a value that still remains in the schema.
9
+ // If a value is removed, reserve its number (and preferably its name).
10
+
11
+ enum ResultCode {
12
+ // 0-10: [SCOPE: BASE_TRANSPORT_AND_VALIDATOR_STATUS]
13
+ // Generic V1 processing outcome before deeper payload/proof-specific validation branches.
14
+ RESULT_CODE_UNSPECIFIED = 0; // We should create an v1Error for this case, sender disconnects from the validator, add optional information to update the node verion.
15
+ RESULT_CODE_OK = 1;
16
+ RESULT_CODE_INVALID_PAYLOAD = 2;
17
+ RESULT_CODE_RATE_LIMITED = 3;
18
+ RESULT_CODE_SIGNATURE_INVALID = 4;
19
+ RESULT_CODE_UNEXPECTED_ERROR = 5;
20
+ RESULT_CODE_TIMEOUT = 6;
21
+ RESULT_CODE_NODE_HAS_NO_WRITE_ACCESS = 7;
22
+ RESULT_CODE_TX_ACCEPTED_PROOF_UNAVAILABLE = 8;
23
+ RESULT_CODE_NODE_OVERLOADED = 9;
24
+ RESULT_CODE_TX_ALREADY_PENDING = 10;
25
+ // 11-44: [SCOPE: SHARED_VALIDATORS_REQUEST_PAYLOAD]
26
+ // (incoming BROADCAST_TRANSACTION_REQUEST -> partial apply payload validation) - validator disconnects, sender rotates
27
+ RESULT_CODE_OPERATION_TYPE_UNKNOWN = 11;
28
+ RESULT_CODE_SCHEMA_VALIDATION_FAILED = 12;
29
+ RESULT_CODE_REQUESTER_ADDRESS_INVALID = 13;
30
+ RESULT_CODE_REQUESTER_PUBLIC_KEY_INVALID = 14;
31
+ RESULT_CODE_TX_HASH_MISMATCH = 15;
32
+ RESULT_CODE_TX_SIGNATURE_INVALID = 16;
33
+ RESULT_CODE_TX_EXPIRED = 17;
34
+ RESULT_CODE_TX_ALREADY_EXISTS = 18;
35
+ RESULT_CODE_OPERATION_ALREADY_COMPLETED = 19;
36
+ RESULT_CODE_REQUESTER_NOT_FOUND = 20;
37
+ RESULT_CODE_INSUFFICIENT_FEE_BALANCE = 21;
38
+ RESULT_CODE_EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP = 22;
39
+ RESULT_CODE_SELF_VALIDATION_FORBIDDEN = 23;
40
+ RESULT_CODE_ROLE_NODE_ENTRY_NOT_FOUND = 24;
41
+ RESULT_CODE_ROLE_NODE_ALREADY_WRITER = 25;
42
+ RESULT_CODE_ROLE_NODE_NOT_WHITELISTED = 26;
43
+ RESULT_CODE_ROLE_NODE_NOT_WRITER = 27;
44
+ RESULT_CODE_ROLE_NODE_IS_INDEXER = 28;
45
+ RESULT_CODE_ROLE_ADMIN_ENTRY_MISSING = 29;
46
+ RESULT_CODE_ROLE_INVALID_RECOVERY_CASE = 30;
47
+ RESULT_CODE_ROLE_UNKNOWN_OPERATION = 31;
48
+ RESULT_CODE_ROLE_INVALID_WRITER_KEY = 32;
49
+ RESULT_CODE_ROLE_INSUFFICIENT_FEE_BALANCE = 33;
50
+ RESULT_CODE_MSB_BOOTSTRAP_MISMATCH = 34;
51
+ RESULT_CODE_EXTERNAL_BOOTSTRAP_NOT_DEPLOYED = 35;
52
+ RESULT_CODE_EXTERNAL_BOOTSTRAP_TX_MISSING = 36;
53
+ RESULT_CODE_EXTERNAL_BOOTSTRAP_MISMATCH = 37;
54
+ RESULT_CODE_BOOTSTRAP_ALREADY_EXISTS = 38;
55
+ RESULT_CODE_TRANSFER_RECIPIENT_ADDRESS_INVALID = 39;
56
+ RESULT_CODE_TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID = 40;
57
+ RESULT_CODE_TRANSFER_AMOUNT_TOO_LARGE = 41;
58
+ RESULT_CODE_TRANSFER_SENDER_NOT_FOUND = 42;
59
+ RESULT_CODE_TRANSFER_INSUFFICIENT_BALANCE = 43;
60
+ RESULT_CODE_TRANSFER_RECIPIENT_BALANCE_OVERFLOW = 44;
61
+
62
+ // 45-47: [SCOPE: REQUEST_DISPATCH_TXPOOL_TXCOMMIT_PIPELINE]
63
+ // (dispatch/enqueue/commit handling on validator)
64
+ RESULT_CODE_TX_HASH_INVALID_FORMAT = 45;
65
+ RESULT_CODE_INTERNAL_ENQUEUE_VALIDATION_FAILED = 46;
66
+ RESULT_CODE_TX_COMMITTED_RECEIPT_MISSING = 47;
67
+
68
+ // 48-60: [SCOPE: VALIDATOR_RESPONSE_PROOF_AND_IDENTITY_VALIDATION]
69
+ // (incoming BROADCAST_TRANSACTION_RESPONSE validation on sender)
70
+ RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_INVALID = 48;
71
+ RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN = 49;
72
+ RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED = 50;
73
+ RESULT_CODE_VALIDATOR_RESPONSE_SCHEMA_INVALID = 51;
74
+ RESULT_CODE_PENDING_REQUEST_MISSING_TX_DATA = 52;
75
+ RESULT_CODE_PROOF_PAYLOAD_MISMATCH = 53;
76
+ RESULT_CODE_VALIDATOR_WRITER_KEY_NOT_REGISTERED = 54;
77
+ RESULT_CODE_VALIDATOR_ADDRESS_MISMATCH = 55;
78
+ RESULT_CODE_VALIDATOR_NODE_ENTRY_NOT_FOUND = 56;
79
+ RESULT_CODE_VALIDATOR_NODE_NOT_WRITER = 57;
80
+ RESULT_CODE_VALIDATOR_WRITER_KEY_MISMATCH = 58;
81
+ RESULT_CODE_VALIDATOR_TX_OBJECT_INVALID = 59;
82
+ RESULT_CODE_VALIDATOR_VA_MISSING = 60;
83
+ RESULT_CODE_TX_INVALID_PAYLOAD = 61;
84
+ }
@@ -0,0 +1,9 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ message BroadcastTransactionRequest {
6
+ bytes data = 1;
7
+ bytes nonce = 2;
8
+ bytes signature = 3;
9
+ }
@@ -0,0 +1,13 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ import "network/v1/enums/result_code.proto";
6
+
7
+ message BroadcastTransactionResponse {
8
+ bytes nonce = 1;
9
+ bytes signature = 2;
10
+ bytes proof = 3;
11
+ uint64 timestamp = 4;
12
+ ResultCode result = 5;
13
+ }
@@ -0,0 +1,8 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ message LivenessRequest {
6
+ bytes nonce = 1;
7
+ bytes signature = 2;
8
+ }
@@ -0,0 +1,11 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ import "network/v1/enums/result_code.proto";
6
+
7
+ message LivenessResponse {
8
+ bytes nonce = 1;
9
+ bytes signature = 2;
10
+ ResultCode result = 3;
11
+ }
@@ -0,0 +1,22 @@
1
+ syntax = "proto3";
2
+
3
+ package network.v1;
4
+
5
+ import "network/v1/enums/message_type.proto";
6
+ import "network/v1/messages/liveness_request.proto";
7
+ import "network/v1/messages/liveness_response.proto";
8
+ import "network/v1/messages/broadcast_transaction_request.proto";
9
+ import "network/v1/messages/broadcast_transaction_response.proto";
10
+
11
+ message MessageHeader {
12
+ MessageType type = 1;
13
+ string id = 2;
14
+ uint64 timestamp = 3;
15
+ oneof field {
16
+ LivenessRequest liveness_request = 4;
17
+ LivenessResponse liveness_response = 5;
18
+ BroadcastTransactionRequest broadcast_transaction_request = 6;
19
+ BroadcastTransactionResponse broadcast_transaction_response = 7;
20
+ }
21
+ repeated string capabilities = 8;
22
+ }
@@ -6,10 +6,23 @@ 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";
9
10
  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";
12
11
  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
+ };
13
26
 
14
27
  export async function getBalance(msbInstance, address, confirmed) {
15
28
  const state = msbInstance.state;
@@ -54,8 +67,8 @@ export async function broadcastTransaction(msbInstance, config, payload) {
54
67
  let isValid = false;
55
68
  let hash;
56
69
 
57
- const partialTransferValidator = new PartialTransfer(msbInstance.state, null, config);
58
- const partialTransactionValidator = new PartialTransaction(msbInstance.state, null, config);
70
+ const partialTransferValidator = new PartialTransferValidator(msbInstance.state, null , config);
71
+ const partialTransactionValidator = new PartialTransactionValidator(msbInstance.state, null , config);
59
72
 
60
73
  if (payload.type === OperationType.TRANSFER) {
61
74
  normalizedPayload = normalizeTransferOperation(payload, config);
@@ -77,6 +90,11 @@ export async function broadcastTransaction(msbInstance, config, payload) {
77
90
  throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
78
91
  }
79
92
 
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
+
80
98
  const signedLength = msbInstance.state.getSignedLength();
81
99
  const unsignedLength = msbInstance.state.getUnsignedLength();
82
100
 
@@ -2,10 +2,10 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
4
  import { fileURLToPath } from 'url';
5
- import { execSync } from 'child_process';
5
+ import { execFileSync } from 'child_process';
6
6
 
7
7
  function generateCJSFromProto(inputPath, outputPath) {
8
- execSync(`protocol-buffers "${inputPath}" -o "${outputPath}"`);
8
+ execFileSync('protocol-buffers', [inputPath, '-o', outputPath]);
9
9
  console.log(`${outputPath} has been generated.`);
10
10
  }
11
11
 
@@ -17,26 +17,51 @@ 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
+ }
20
46
 
21
47
  function main() {
22
48
  const directoryName = path.dirname(fileURLToPath(import.meta.url));
23
49
 
24
50
  const inputDir = path.join(directoryName, '../proto');
25
51
  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');
26
57
 
27
58
  fs.mkdirSync(outputDir, { recursive: true });
28
59
 
29
- const files = fs.readdirSync(inputDir).filter(f => f.endsWith('.proto'));
60
+ generateCJSFromProto(applyInputPath, applyOutputPath);
61
+ transformToUseB4a(applyOutputPath);
30
62
 
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
- }
63
+ generatePbjsModule(pbjsPath, inputDir, networkEntryPath, generatedNetworkOutputPath);
64
+ transformPbjsForBare(generatedNetworkOutputPath);
39
65
  }
40
66
 
41
67
  main();
42
-
@@ -129,11 +129,6 @@ export class Config {
129
129
  return this.#config.processIntervalMs
130
130
  }
131
131
 
132
- get maxPartialTxPayloadByteSize() {
133
- if (this.#isOverriden('maxPartialTxPayloadByteSize')) return this.#options.maxPartialTxPayloadByteSize
134
- return this.#config.maxPartialTxPayloadByteSize
135
- }
136
-
137
132
  get transactionPoolSize() {
138
133
  if (this.#isOverriden('transactionPoolSize')) return this.#options.transactionPoolSize
139
134
  return this.#config.transactionPoolSize
@@ -194,6 +189,31 @@ export class Config {
194
189
  if (this.#isOverriden('rateLimitMaxTransactionsPerSecond')) return this.#options.rateLimitMaxTransactionsPerSecond
195
190
  return this.#config.rateLimitMaxTransactionsPerSecond
196
191
  }
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
+ }
197
217
 
198
218
  // Most of these properties are boolean
199
219
  #isOverriden(prop) {
@@ -207,4 +227,5 @@ export class Config {
207
227
  );
208
228
  }
209
229
  }
230
+
210
231
  }
package/src/config/env.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet/constants.js';
2
- import { Config } from './config.js';
3
2
  import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
3
+ import { Config } from './config.js';
4
4
 
5
5
  export const ENV = {
6
6
  MAINNET: 'mainnet',
7
7
  DEVELOPMENT: 'development',
8
8
  TESTNET1: 'testnet1'
9
9
  }
10
- // TODO: CREATE TEST ENV CONFIG SIMILAR TO MAINNET AND USE IT IN TESTS.
11
10
 
12
11
  const configData = {
13
12
  [ENV.TESTNET1]: {
13
+ debug: false,
14
14
  addressLength: 67,
15
15
  addressPrefix: TRAC_NETWORK_MSB_TESTNET1_PREFIX,
16
16
  addressPrefixLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length,
@@ -25,9 +25,9 @@ const configData = {
25
25
  enableTxApplyLogs: true,
26
26
  enableValidatorObserver: true,
27
27
  enableWallet: true,
28
- maxValidators: 6,
29
- maxRetries: 1,
30
- messageThreshold: 1000,
28
+ maxValidators: 50,
29
+ maxRetries: 3,
30
+ messageThreshold: 3,
31
31
  messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
32
32
  messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
33
33
  host: 'localhost',
@@ -39,15 +39,20 @@ const configData = {
39
39
  maxClientConnections: Infinity, // Connectivity constants
40
40
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
41
41
  processIntervalMs: 50, // Pool constants
42
- maxPartialTxPayloadByteSize: 3072, // Operation handler constants
43
42
  transactionPoolSize: 1000, // Operation handler constants
44
43
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
45
44
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
46
45
  rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
47
- storesDirectory : 'stores/',
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/',
48
52
  storeName: 'testnet',
49
53
  },
50
54
  [ENV.MAINNET]: {
55
+ debug: false,
51
56
  addressLength: 63,
52
57
  addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
53
58
  addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
@@ -76,15 +81,20 @@ const configData = {
76
81
  maxClientConnections: Infinity, // Connectivity constants
77
82
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
78
83
  processIntervalMs: 50, // Pool constants
79
- maxPartialTxPayloadByteSize: 3072, // Operation handler constants
80
84
  transactionPoolSize: 1000, // Operation handler constants
81
85
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
82
86
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
83
87
  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)
84
93
  storesDirectory: 'stores/',
85
94
  storeName: 'mainnet',
86
95
  },
87
96
  [ENV.DEVELOPMENT]: {
97
+ debug: true,
88
98
  addressLength: 63,
89
99
  addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
90
100
  addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
@@ -100,7 +110,7 @@ const configData = {
100
110
  enableValidatorObserver: true,
101
111
  enableWallet: true,
102
112
  maxValidators: 6,
103
- maxRetries: 0,
113
+ maxRetries: 3,
104
114
  messageThreshold: 1000,
105
115
  messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
106
116
  messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
@@ -113,12 +123,16 @@ const configData = {
113
123
  maxClientConnections: Infinity, // Connectivity constants
114
124
  maxWritersForAdminIndexerConnection: 10, // Connectivity constants
115
125
  processIntervalMs: 50, // Pool constants
116
- maxPartialTxPayloadByteSize: 3072, // Operation handler constants
117
126
  transactionPoolSize: 1000, // Operation handler constants
118
127
  rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
119
128
  rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
120
129
  rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
121
- storesDirectory : 'stores/',
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/',
122
136
  storeName: 'development',
123
137
  }
124
138
  }