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
@@ -1,16 +0,0 @@
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
- }
@@ -1,84 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
1
- syntax = "proto3";
2
-
3
- package network.v1;
4
-
5
- message LivenessRequest {
6
- bytes nonce = 1;
7
- bytes signature = 2;
8
- }
@@ -1,11 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -1,88 +0,0 @@
1
- import { ResultCode } from '../../../utils/constants.js';
2
-
3
- // TODO: Consider how to behave with ResultCode.UNSPECIFIED
4
-
5
- export const SENDER_ACTION = Object.freeze({
6
- UNDEFINED: 'UNDEFINED',
7
- SUCCESS: 'SUCCESS',
8
- ROTATE: 'ROTATE',
9
- NO_ROTATE: 'NO_ROTATE',
10
- });
11
-
12
- const SUCCESS_CODES = new Set([
13
- ResultCode.OK,
14
- ]);
15
-
16
- const ROTATE_CODES = new Set([
17
- ResultCode.UNSPECIFIED,
18
- ResultCode.INVALID_PAYLOAD,
19
- ResultCode.RATE_LIMITED,
20
- ResultCode.SIGNATURE_INVALID,
21
- ResultCode.UNEXPECTED_ERROR,
22
- ResultCode.TIMEOUT,
23
- ResultCode.NODE_HAS_NO_WRITE_ACCESS,
24
- ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE,
25
- ResultCode.NODE_OVERLOADED,
26
- ResultCode.OPERATION_TYPE_UNKNOWN,
27
- ResultCode.SCHEMA_VALIDATION_FAILED,
28
- ResultCode.REQUESTER_ADDRESS_INVALID,
29
- ResultCode.REQUESTER_PUBLIC_KEY_INVALID,
30
- ResultCode.TX_HASH_MISMATCH,
31
- ResultCode.TX_SIGNATURE_INVALID,
32
- ResultCode.TX_EXPIRED,
33
- ResultCode.TX_ALREADY_EXISTS,
34
- ResultCode.OPERATION_ALREADY_COMPLETED,
35
- ResultCode.REQUESTER_NOT_FOUND,
36
- ResultCode.INSUFFICIENT_FEE_BALANCE,
37
- ResultCode.EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP,
38
- ResultCode.SELF_VALIDATION_FORBIDDEN,
39
- ResultCode.ROLE_NODE_ENTRY_NOT_FOUND,
40
- ResultCode.ROLE_NODE_ALREADY_WRITER,
41
- ResultCode.ROLE_NODE_NOT_WHITELISTED,
42
- ResultCode.ROLE_NODE_NOT_WRITER,
43
- ResultCode.ROLE_NODE_IS_INDEXER,
44
- ResultCode.ROLE_ADMIN_ENTRY_MISSING,
45
- ResultCode.ROLE_INVALID_RECOVERY_CASE,
46
- ResultCode.ROLE_UNKNOWN_OPERATION,
47
- ResultCode.ROLE_INVALID_WRITER_KEY,
48
- ResultCode.ROLE_INSUFFICIENT_FEE_BALANCE,
49
- ResultCode.MSB_BOOTSTRAP_MISMATCH,
50
- ResultCode.EXTERNAL_BOOTSTRAP_NOT_DEPLOYED,
51
- ResultCode.EXTERNAL_BOOTSTRAP_TX_MISSING,
52
- ResultCode.EXTERNAL_BOOTSTRAP_MISMATCH,
53
- ResultCode.BOOTSTRAP_ALREADY_EXISTS,
54
- ResultCode.TRANSFER_RECIPIENT_ADDRESS_INVALID,
55
- ResultCode.TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID,
56
- ResultCode.TRANSFER_AMOUNT_TOO_LARGE,
57
- ResultCode.TRANSFER_SENDER_NOT_FOUND,
58
- ResultCode.TRANSFER_INSUFFICIENT_BALANCE,
59
- ResultCode.TRANSFER_RECIPIENT_BALANCE_OVERFLOW,
60
- ResultCode.TX_HASH_INVALID_FORMAT,
61
- ResultCode.INTERNAL_ENQUEUE_VALIDATION_FAILED,
62
- ResultCode.TX_COMMITTED_RECEIPT_MISSING,
63
- ResultCode.VALIDATOR_RESPONSE_TX_TYPE_INVALID,
64
- ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN,
65
- ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED,
66
- ResultCode.VALIDATOR_RESPONSE_SCHEMA_INVALID,
67
- ResultCode.PENDING_REQUEST_MISSING_TX_DATA,
68
- ResultCode.PROOF_PAYLOAD_MISMATCH,
69
- ResultCode.VALIDATOR_WRITER_KEY_NOT_REGISTERED,
70
- ResultCode.VALIDATOR_ADDRESS_MISMATCH,
71
- ResultCode.VALIDATOR_NODE_ENTRY_NOT_FOUND,
72
- ResultCode.VALIDATOR_NODE_NOT_WRITER,
73
- ResultCode.VALIDATOR_WRITER_KEY_MISMATCH,
74
- ResultCode.VALIDATOR_TX_OBJECT_INVALID,
75
- ResultCode.VALIDATOR_VA_MISSING,
76
- ResultCode.TX_INVALID_PAYLOAD
77
- ]);
78
-
79
- const NO_ROTATE_CODES = new Set([
80
- ResultCode.TX_ALREADY_PENDING,
81
- ]);
82
-
83
- export function resultToValidatorAction(resultCode) {
84
- if (SUCCESS_CODES.has(resultCode)) return SENDER_ACTION.SUCCESS;
85
- if (ROTATE_CODES.has(resultCode)) return SENDER_ACTION.ROTATE;
86
- if (NO_ROTATE_CODES.has(resultCode)) return SENDER_ACTION.NO_ROTATE;
87
- return SENDER_ACTION.UNDEFINED;
88
- }
@@ -1,23 +0,0 @@
1
- import ValidatorResponse from '../validators/ValidatorResponse.js';
2
-
3
- class LegacyResponseHandler {
4
- #responseValidator;
5
-
6
- constructor(state, wallet, config) {
7
- this.#responseValidator = new ValidatorResponse(state, wallet, config);
8
-
9
- }
10
-
11
- async handle(message, channelString) {
12
- await this.#handleValidatorResponse(message, channelString);
13
- }
14
-
15
- async #handleValidatorResponse(message, channelString) {
16
- const isValid = await this.#responseValidator.validate(message, channelString);
17
- if (!isValid) {
18
- throw new Error("Validator response verification failed");
19
- }
20
- }
21
- }
22
-
23
- export default LegacyResponseHandler;
@@ -1,27 +0,0 @@
1
- import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
2
-
3
- /**
4
- * Shared validator rejection error.
5
- *
6
- * Used by shared validators in `src/core/network/protocols/shared/validators/**` so they can
7
- * reject remote peer input with a stable `resultCode`.
8
- *
9
- * Note: this currently extends `V1ProtocolError` so the v1 protocol can consistently treat shared
10
- * validator rejections as typed protocol errors. Legacy protocol codepaths remain compatible because
11
- * this is still an `Error` and preserves `.message`.
12
- *
13
- * Default `endConnection = true` because shared-validator rejections are typically triggered
14
- * by invalid/malicious peer payloads and should terminate the peer connection after responding.
15
- */
16
- export class SharedValidatorRejectionError extends V1ProtocolError {
17
- /**
18
- * @param {number} resultCode Stable rejection reason (a `ResultCode` value).
19
- * @param {string} message Human-readable error message.
20
- * @param {boolean} [endConnection=true] Whether the transport should end the connection after responding.
21
- */
22
- constructor(resultCode, message, endConnection = true) {
23
- super(resultCode, message, endConnection);
24
- }
25
- }
26
-
27
- export default SharedValidatorRejectionError;
@@ -1,91 +0,0 @@
1
- import {ResultCode} from '../../../../utils/constants.js';
2
-
3
- export function getResultCode(err) {
4
- return err instanceof V1ProtocolError ? err.resultCode : ResultCode.UNEXPECTED_ERROR;
5
- }
6
-
7
- export function shouldEndConnection(err) {
8
- return err instanceof V1ProtocolError ? Boolean(err.endConnection) : false;
9
- }
10
-
11
- /**
12
- * V1 protocol error type.
13
- *
14
- * `V1ProtocolError` is the v1 base class used by handlers/validators to attach:
15
- * - `resultCode`: a stable `ResultCode` enum value for programmatic handling
16
- * - `endConnection`: a transport hint (close peer connection after responding)
17
- */
18
- export class V1ProtocolError extends Error {
19
- /**
20
- * @param {number} resultCode Stable rejection reason (a `ResultCode` enum value).
21
- * @param {string} message Human-readable error message.
22
- * @param {boolean} [endConnection=false] Whether the transport should end the connection after responding.
23
- */
24
- constructor(resultCode, message, endConnection = false) {
25
- super(message);
26
- this.name = this.constructor.name;
27
- this.resultCode = resultCode;
28
- this.endConnection = Boolean(endConnection);
29
- }
30
- }
31
-
32
- export class V1InvalidPayloadError extends V1ProtocolError {
33
- constructor(message = 'Invalid payload', endConnection = false) {
34
- super(ResultCode.INVALID_PAYLOAD, message, endConnection);
35
- }
36
- }
37
-
38
- export class V1TxInvalidPayloadError extends V1ProtocolError {
39
- constructor(message = 'Invalid tx payload', endConnection = false) {
40
- super(ResultCode.TX_INVALID_PAYLOAD, message, endConnection);
41
- }
42
- }
43
-
44
- export class V1SignatureInvalidError extends V1ProtocolError {
45
- constructor(message = 'Signature invalid', endConnection = true) {
46
- super(ResultCode.SIGNATURE_INVALID, message, endConnection);
47
- }
48
- }
49
-
50
- export class V1RateLimitedError extends V1ProtocolError {
51
- constructor(message = 'Rate limited', endConnection = true) {
52
- super(ResultCode.RATE_LIMITED, message, endConnection);
53
- }
54
- }
55
-
56
- export class V1UnexpectedError extends V1ProtocolError {
57
- constructor(message = 'Unexpected error', endConnection = true) {
58
- super(ResultCode.UNEXPECTED_ERROR, message, endConnection);
59
- }
60
- }
61
-
62
- export class V1TimeoutError extends V1ProtocolError {
63
- constructor(message = 'Request timed out', endConnection = false) {
64
- super(ResultCode.TIMEOUT, message, endConnection);
65
- }
66
- }
67
-
68
- export class V1NodeHasNoWriteAccess extends V1ProtocolError {
69
- constructor(message = 'Node has no write access', endConnection = true) {
70
- super(ResultCode.NODE_HAS_NO_WRITE_ACCESS, message, endConnection);
71
- }
72
- }
73
-
74
- export class V1TxAcceptedProofUnavailable extends V1ProtocolError {
75
- constructor(message = 'Transaction accepted but proof is unavailable', endConnection = false, timestamp = 0) {
76
- super(ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE, message, endConnection);
77
- this.timestamp = Number.isSafeInteger(timestamp) && timestamp > 0 ? timestamp : 0;
78
- }
79
- }
80
-
81
- export class V1NodeOverloadedError extends V1ProtocolError {
82
- constructor(message = 'Commit queue is full', endConnection = true) {
83
- super(ResultCode.NODE_OVERLOADED, message, endConnection);
84
- }
85
- }
86
-
87
- export class V1TxAlreadyPendingError extends V1ProtocolError {
88
- constructor(message = 'Transaction is already pending', endConnection = false) {
89
- super(ResultCode.TX_ALREADY_PENDING, message, endConnection);
90
- }
91
- }
@@ -1,65 +0,0 @@
1
- import {publicKeyToAddress} from "../../../../../utils/helpers.js";
2
- import {V1ProtocolError, V1UnexpectedError} from "../V1ProtocolError.js";
3
-
4
- class V1BaseOperationHandler {
5
- #rateLimiterService;
6
- #pendingRequestService;
7
- #config;
8
-
9
- constructor(rateLimiterService, pendingRequestService, config) {
10
- this.#rateLimiterService = rateLimiterService;
11
- this.#pendingRequestService = pendingRequestService;
12
- this.#config = config;
13
- }
14
-
15
- get config() {
16
- return this.#config;
17
- }
18
-
19
- applyRateLimit(connection) {
20
- if (!this.#config.disableRateLimit) {
21
- this.#rateLimiterService.v1HandleRateLimit(connection);
22
- }
23
- }
24
-
25
- async resolvePendingResponse(message, connection, validator, extractResultCode) {
26
- const pendingRequestServiceEntry = this.#pendingRequestService.getPendingRequest(message.id);
27
- if (!pendingRequestServiceEntry) return false;
28
-
29
- this.#pendingRequestService.stopPendingRequestTimeout(message.id);
30
- await validator.validate(message, connection, pendingRequestServiceEntry);
31
-
32
- const resultCode = extractResultCode(message);
33
- this.#pendingRequestService.resolvePendingRequest(message.id, resultCode);
34
- return true;
35
- }
36
-
37
- handlePendingResponseError(messageId, connection, error, step) {
38
- const protocolError = this.#toProtocolError(error);
39
- const rejected = this.#pendingRequestService.rejectPendingRequest(messageId, protocolError);
40
- if (!rejected) return;
41
- this.displayError(step, connection.remotePublicKey, protocolError);
42
- }
43
-
44
- async sendResponseAndMaybeClose(connection, response, endConnection) {
45
- connection.protocolSession.sendAndForget(response);
46
- if (!endConnection) return;
47
-
48
- await connection.flush();
49
- connection.end();
50
- }
51
-
52
- displayError(step = "undefined step", senderPublicKey, error) {
53
- const errorMessage = error?.message ?? 'Unexpected error';
54
- console.error(`${this.constructor.name}: ${step} ${publicKeyToAddress(senderPublicKey, this.#config)}: ${errorMessage}`);
55
- }
56
-
57
- #toProtocolError(error) {
58
- if (error instanceof V1ProtocolError) {
59
- return error;
60
- }
61
- return new V1UnexpectedError(error?.message ?? 'Unexpected error');
62
- }
63
- }
64
-
65
- export default V1BaseOperationHandler;