trac-msb 0.2.18 → 0.2.20

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 (381) hide show
  1. package/README.md +62 -2
  2. package/SECURITY.md +9 -6
  3. package/cli/commandHandler.js +272 -0
  4. package/cli/handlers.js +210 -0
  5. package/cli/interactive.js +182 -0
  6. package/msb.mjs +7 -8
  7. package/package.json +25 -8
  8. package/rpc/create_server.js +44 -44
  9. package/rpc/handlers.js +43 -56
  10. package/rpc/routes/index.js +8 -8
  11. package/rpc/rpc_server.js +6 -2
  12. package/rpc/utils/helpers.js +46 -66
  13. package/scripts/pear-runner.js +170 -0
  14. package/src/config/args.js +60 -13
  15. package/src/config/config.js +138 -10
  16. package/src/config/env.js +36 -18
  17. package/src/core/network/Network.js +130 -34
  18. package/src/core/network/protocols/ProtocolInterface.js +5 -5
  19. package/src/core/network/protocols/connectionPolicies.js +86 -0
  20. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
  21. package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
  22. package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
  23. package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
  24. package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
  25. package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
  26. package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
  27. package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
  28. package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
  29. package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
  30. package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
  31. package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
  32. package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
  33. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
  34. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
  35. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
  36. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
  37. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
  38. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
  39. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
  40. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
  41. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
  42. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
  43. package/src/core/network/services/ConnectionManager.js +11 -10
  44. package/src/core/network/services/MessageOrchestrator.js +53 -17
  45. package/src/core/network/services/PendingRequestService.js +22 -19
  46. package/src/core/network/services/TransactionCommitService.js +36 -36
  47. package/src/core/network/services/TransactionPoolService.js +39 -39
  48. package/src/core/network/services/TransactionRateLimiterService.js +8 -4
  49. package/src/core/network/services/ValidatorObserverService.js +397 -110
  50. package/src/core/state/State.js +190 -138
  51. package/src/core/state/utils/address.js +4 -9
  52. package/src/core/state/utils/balance.js +7 -7
  53. package/src/core/state/utils/roles.js +1 -1
  54. package/src/index.js +316 -275
  55. package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
  56. package/src/messages/network/v1/networkMessageFactory.js +1 -1
  57. package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
  58. package/src/messages/state/applyStateMessageFactory.js +1 -1
  59. package/src/utils/buffer.js +1 -1
  60. package/src/utils/check.js +12 -13
  61. package/src/utils/constants.js +7 -0
  62. package/src/utils/errors.js +20 -0
  63. package/src/utils/fileUtils.js +12 -3
  64. package/src/utils/helpers.js +2 -2
  65. package/src/utils/migrationUtils.js +3 -3
  66. package/.dockerignore +0 -16
  67. package/CODE_OF_CONDUCT.md +0 -128
  68. package/docker-compose.yml +0 -17
  69. package/dockerfile +0 -41
  70. package/docs/fee_distribution.md +0 -89
  71. package/docs/trac_network_http_api.openapi.yaml +0 -889
  72. package/migration/.gitkeep +0 -0
  73. package/proto/applyOperations.proto +0 -117
  74. package/proto/network/v1/enums/message_type.proto +0 -16
  75. package/proto/network/v1/enums/result_code.proto +0 -84
  76. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  77. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  78. package/proto/network/v1/messages/liveness_request.proto +0 -8
  79. package/proto/network/v1/messages/liveness_response.proto +0 -11
  80. package/proto/network/v1/network_message.proto +0 -22
  81. package/rpc/rpc_services.js +0 -181
  82. package/scripts/generate-protobufs.js +0 -67
  83. package/src/core/network/identity/NetworkWalletFactory.js +0 -77
  84. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  85. package/src/utils/cli.js +0 -130
  86. package/src/utils/cliCommands.js +0 -280
  87. package/tests/acceptance/v1/account/account.test.mjs +0 -129
  88. package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
  89. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
  90. package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
  91. package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
  92. package/tests/acceptance/v1/health/health.test.mjs +0 -33
  93. package/tests/acceptance/v1/rpc.test.mjs +0 -95
  94. package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
  95. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
  96. package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
  97. package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
  98. package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
  99. package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
  100. package/tests/fixtures/apply.fixtures.js +0 -77
  101. package/tests/fixtures/assembleMessage.fixtures.js +0 -41
  102. package/tests/fixtures/check.fixtures.js +0 -428
  103. package/tests/fixtures/networkV1.fixtures.js +0 -59
  104. package/tests/fixtures/protobuf.fixtures.js +0 -388
  105. package/tests/helpers/StateNetworkFactory.js +0 -155
  106. package/tests/helpers/address.js +0 -6
  107. package/tests/helpers/autobaseTestHelpers.js +0 -419
  108. package/tests/helpers/config.js +0 -4
  109. package/tests/helpers/createTestSignature.js +0 -13
  110. package/tests/helpers/regexHelper.js +0 -3
  111. package/tests/helpers/setupApplyTests.js +0 -587
  112. package/tests/helpers/transactionPayloads.mjs +0 -92
  113. package/tests/helpers/wrapper.js +0 -28
  114. package/tests/unit/messages/messages.test.js +0 -12
  115. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
  116. package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
  117. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
  118. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
  119. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  120. package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
  121. package/tests/unit/network/ProtocolSession.test.js +0 -127
  122. package/tests/unit/network/networkModule.test.js +0 -13
  123. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  124. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  125. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  126. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  127. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  128. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  129. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  130. package/tests/unit/network/services/services.test.js +0 -17
  131. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  132. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  133. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  134. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  135. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  136. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  137. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  138. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  139. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  140. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  141. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  142. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  143. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  144. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  145. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  146. package/tests/unit/network/v1/v1.test.js +0 -19
  147. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  148. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  149. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  150. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  151. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  152. package/tests/unit/state/State.test.js +0 -80
  153. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
  154. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
  155. package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
  156. package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
  157. package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
  158. package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
  159. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
  160. package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
  161. package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
  162. package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
  163. package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
  164. package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
  165. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
  166. package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
  167. package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
  168. package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
  169. package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
  170. package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
  171. package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
  172. package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
  173. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
  174. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
  175. package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
  176. package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
  177. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
  178. package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
  179. package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
  180. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
  181. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
  182. package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
  183. package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
  184. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
  185. package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
  186. package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
  187. package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
  188. package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
  189. package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
  190. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
  191. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
  192. package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
  193. package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
  194. package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
  195. package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
  196. package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
  197. package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
  198. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
  199. package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
  200. package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
  201. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
  202. package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
  203. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
  204. package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
  205. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
  206. package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
  207. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
  208. package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
  209. package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
  210. package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
  211. package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
  212. package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
  213. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
  214. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
  215. package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
  216. package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
  217. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
  218. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
  219. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
  220. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
  221. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
  222. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
  223. package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
  224. package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
  225. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
  226. package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
  227. package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
  228. package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
  229. package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
  230. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
  231. package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
  232. package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
  233. package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
  234. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
  235. package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
  236. package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
  237. package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
  238. package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
  239. package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
  240. package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
  241. package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
  242. package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
  243. package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
  244. package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
  245. package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
  246. package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
  247. package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
  248. package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
  249. package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
  250. package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
  251. package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
  252. package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
  253. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
  254. package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
  255. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
  256. package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
  257. package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
  258. package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
  259. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
  260. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
  261. package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
  262. package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
  263. package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
  264. package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
  265. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
  266. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
  267. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
  268. package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
  269. package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
  270. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
  271. package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
  272. package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
  273. package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
  274. package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
  275. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
  276. package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
  277. package/tests/unit/state/apply/missing-tests.md +0 -18
  278. package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
  279. package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
  280. package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
  281. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
  282. package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
  283. package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
  284. package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
  285. package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
  286. package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
  287. package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
  288. package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
  289. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
  290. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
  291. package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
  292. package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
  293. package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
  294. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
  295. package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
  296. package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
  297. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
  298. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
  299. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
  300. package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
  301. package/tests/unit/state/apply/state.apply.test.js +0 -24
  302. package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
  303. package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
  304. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
  305. package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
  306. package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
  307. package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
  308. package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
  309. package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
  310. package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
  311. package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
  312. package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
  313. package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
  314. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
  315. package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
  316. package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
  317. package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
  318. package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
  319. package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
  320. package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
  321. package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
  322. package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
  323. package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
  324. package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
  325. package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
  326. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
  327. package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
  328. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
  329. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
  330. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
  331. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
  332. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
  333. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
  334. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
  335. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
  336. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
  337. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
  338. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
  339. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
  340. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
  341. package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
  342. package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
  343. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
  344. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
  345. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
  346. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
  347. package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
  348. package/tests/unit/state/stateModule.test.js +0 -23
  349. package/tests/unit/state/stateTestUtils.js +0 -32
  350. package/tests/unit/state/utils/address.test.js +0 -63
  351. package/tests/unit/state/utils/adminEntry.test.js +0 -52
  352. package/tests/unit/state/utils/balance.test.js +0 -320
  353. package/tests/unit/state/utils/lengthEntry.test.js +0 -54
  354. package/tests/unit/state/utils/nodeEntry.test.js +0 -298
  355. package/tests/unit/state/utils/roles.test.js +0 -44
  356. package/tests/unit/unit.test.js +0 -14
  357. package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
  358. package/tests/unit/utils/buffer/buffer.test.js +0 -251
  359. package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
  360. package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
  361. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
  362. package/tests/unit/utils/check/check.test.js +0 -17
  363. package/tests/unit/utils/check/common.test.js +0 -419
  364. package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
  365. package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
  366. package/tests/unit/utils/check/transactionOperation.test.js +0 -107
  367. package/tests/unit/utils/check/transferOperation.test.js +0 -102
  368. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
  369. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
  370. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
  371. package/tests/unit/utils/helpers/helpers.test.js +0 -11
  372. package/tests/unit/utils/helpers/isHexString.test.js +0 -12
  373. package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
  374. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
  375. package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
  376. package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
  377. package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
  378. package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
  379. package/tests/unit/utils/type/type.test.js +0 -25
  380. package/tests/unit/utils/utils.test.js +0 -21
  381. package/whitelist/.gitkeep +0 -0
@@ -1,7 +1,7 @@
1
- import { generateUUID, publicKeyToAddress, sleep } from '../../../utils/helpers.js';
1
+ import { generateUUID, publicKeyToAddress } from '../../../utils/helpers.js';
2
2
  import { operationToPayload } from '../../../utils/applyOperations.js';
3
3
  import { networkMessageFactory } from "../../../messages/network/v1/networkMessageFactory.js";
4
- import { NETWORK_CAPABILITIES } from "../../../utils/constants.js";
4
+ import { NETWORK_CAPABILITIES, ResultCode } from "../../../utils/constants.js";
5
5
  import {
6
6
  unsafeEncodeApplyOperation
7
7
  } from "../../../utils/protobuf/operationHelpers.js";
@@ -15,6 +15,10 @@ import { ConnectionManagerError } from './ConnectionManager.js';
15
15
  class MessageOrchestrator {
16
16
  #config;
17
17
  #wallet;
18
+ #idempotentSuccessCodes = new Set([
19
+ ResultCode.TX_ALREADY_EXISTS,
20
+ ResultCode.OPERATION_ALREADY_COMPLETED,
21
+ ]);
18
22
  /**
19
23
  * Attempts to send a message to validators with retries and state checks.
20
24
  * @param {ConnectionManager} connectionManager - The connection manager instance
@@ -101,7 +105,7 @@ class MessageOrchestrator {
101
105
 
102
106
  try {
103
107
  success = await this.#attemptSendMessageForLegacy(validatorPublicKey, message);
104
- } catch (error) {
108
+ } catch {
105
109
  success = await this.send(message, retries + 1);
106
110
  }
107
111
  if (!success) {
@@ -124,7 +128,12 @@ class MessageOrchestrator {
124
128
 
125
129
  await this.connectionManager.sendSingleMessage(v1Message, validatorPublicKey)
126
130
  .then(
127
- (resultCode) => {
131
+ async (resultCode) => {
132
+ if (await this.#isIdempotentSuccess(resultCode, message)) {
133
+ success = true;
134
+ return;
135
+ }
136
+
128
137
  // TODO: When we will deprecate the legacy protocol, we should refactor this scope, to propagate domain-error with result code.
129
138
  const action = resultToValidatorAction(resultCode);
130
139
  switch (action) {
@@ -168,11 +177,50 @@ class MessageOrchestrator {
168
177
  return success;
169
178
  }
170
179
 
180
+ /**
181
+ * Determines whether a non-OK result code should be treated as a success due to idempotency.
182
+ *
183
+ * This handles the retry scenario where a requester did not receive or accept the response
184
+ * from the first validator that committed the transaction. On retry, a second validator may
185
+ * return TX_ALREADY_EXISTS or OPERATION_ALREADY_COMPLETED because the tx was already
186
+ * processed. Those codes are not errors — they confirm the operation succeeded.
187
+ *
188
+ * To safely treat these as success, we check whether the local unsigned state for the tx
189
+ * has been committed. This ensures we only acknowledge idempotent success when the state
190
+ * change is actually observable locally, not just because the result code matched.
191
+ */
192
+ async #isIdempotentSuccess(resultCode, message) {
193
+ if (!this.#idempotentSuccessCodes.has(resultCode)) return false;
194
+
195
+ const txHash = this.#extractTxHash(message);
196
+ if (!txHash) return false;
197
+
198
+ // A short wait covers the race where a first validator committed the tx
199
+ // and a retried validator only observes it as "already exists/completed".
200
+ const timeout = this.#config.messageValidatorResponseTimeout ?? 2000;
201
+ return await this.waitForUnsignedState(txHash, timeout);
202
+ }
203
+
204
+ async waitForUnsignedState(txHash, timeout) {
205
+ return this.state.waitForUnsigned(txHash, timeout);
206
+ }
207
+
208
+ #extractTxHash(message) {
209
+ if (!message || !Number.isInteger(message.type)) return null;
210
+
211
+ const payloadKey = operationToPayload(message.type);
212
+ const txHash = message?.[payloadKey]?.tx;
213
+ return typeof txHash === 'string' && txHash.length > 0 ? txHash : null;
214
+ }
215
+
171
216
  // TODO: Delete this function after legacy protocol is deprecated
172
217
  async #attemptSendMessageForLegacy(validatorPublicKey, message) {
173
218
  const deductedTxType = operationToPayload(message.type);
174
219
  await this.connectionManager.sendSingleMessage(message, validatorPublicKey);
175
- const appeared = await this.waitForUnsignedState(message[deductedTxType].tx, this.#config.messageValidatorResponseTimeout);
220
+ const appeared = await this.state.waitForUnsigned(
221
+ message[deductedTxType].tx,
222
+ this.#config.messageValidatorResponseTimeout
223
+ );
176
224
  if (appeared) {
177
225
  this.incrementSentCount(validatorPublicKey);
178
226
  if (this.shouldRemove(validatorPublicKey)) {
@@ -183,18 +231,6 @@ class MessageOrchestrator {
183
231
  return false;
184
232
  }
185
233
 
186
- async waitForUnsignedState(txHash, timeout) {
187
- // Polls state for the transaction hash for up to timeout ms
188
- const start = Date.now();
189
- let entry = null;
190
- while (Date.now() - start < timeout) {
191
- await sleep(200);
192
- entry = await this.state.get(txHash)
193
- if (entry) return true;
194
- }
195
- return false;
196
- }
197
-
198
234
  incrementSentCount(validatorPubKey) {
199
235
  this.connectionManager.incrementSentCount(validatorPubKey);
200
236
  }
@@ -1,12 +1,18 @@
1
1
  import {NetworkOperationType, ResultCode} from '../../../utils/constants.js';
2
- import {isHexString} from '../../../utils/helpers.js';
3
- import {V1ProtocolError, V1TimeoutError, V1UnexpectedError} from "../protocols/v1/V1ProtocolError.js";
4
- import {Config} from '../../../config/config.js';
2
+ import {isHexString, publicKeyToAddress} from '../../../utils/helpers.js';
3
+ import {V1ProtocolError} from "../protocols/v1/V1ProtocolError.js";
5
4
  import b4a from 'b4a';
6
5
 
7
6
  const PEER_PUBLIC_KEY_HEX_LENGTH = 64;
8
7
 
9
- class PendingRequestService {
8
+ export class PendingRequestServiceTimeoutError extends Error {
9
+ constructor(requestId, peerAddress, timeoutMs) {
10
+ super(`Pending request ${requestId} to peer ${peerAddress} timed out after ${timeoutMs} ms.`);
11
+ this.name = this.constructor.name;
12
+ }
13
+ }
14
+
15
+ export default class PendingRequestService {
10
16
  #pendingRequests;
11
17
  #requestMessageTypes = [NetworkOperationType.LIVENESS_REQUEST, NetworkOperationType.BROADCAST_TRANSACTION_REQUEST];
12
18
  #config;
@@ -53,6 +59,7 @@ class PendingRequestService {
53
59
  registerPendingRequest(peerPubKeyHex, message) {
54
60
  this.#validateRegisterInput(peerPubKeyHex, message);
55
61
  const id = message.id;
62
+ const peerAddress = publicKeyToAddress(peerPubKeyHex, this.#config);
56
63
  if (this.#pendingRequests.size >= this.#config.maxPendingRequestsInPendingRequestsService) {
57
64
  throw new Error('Maximum number of pending requests reached.');
58
65
  }
@@ -66,7 +73,6 @@ class PendingRequestService {
66
73
  requestType: message.type,
67
74
  requestTxData: this.#extractRequestTxData(message),
68
75
  requestedTo: peerPubKeyHex,
69
- timeoutMs: this.#config.pendingRequestTimeout,
70
76
  timeoutId: null,
71
77
  resolve: null,
72
78
  reject: null,
@@ -80,12 +86,14 @@ class PendingRequestService {
80
86
  entry.timeoutId = setTimeout(() => {
81
87
  this.rejectPendingRequest(
82
88
  id,
83
- new V1TimeoutError(
84
- `Pending request with ID ${id} from peer ${peerPubKeyHex} timed out after ${entry.timeoutMs} ms.`,
85
- true
86
- ));
89
+ new PendingRequestServiceTimeoutError(
90
+ id,
91
+ peerAddress,
92
+ this.#config.pendingRequestTimeout
93
+ )
94
+ );
87
95
 
88
- }, entry.timeoutMs);
96
+ }, this.#config.pendingRequestTimeout);
89
97
 
90
98
  this.#pendingRequests.set(id, entry);
91
99
  return promise;
@@ -123,10 +131,7 @@ class PendingRequestService {
123
131
  rejectPendingRequest(id, error) {
124
132
  const entry = this.getAndDeletePendingRequest(id);
125
133
  if (!entry) return false;
126
- const err = error instanceof V1ProtocolError
127
- ? error
128
- : new V1UnexpectedError(error?.message ?? 'Unexpected error');
129
- entry.reject(err);
134
+ entry.reject(error instanceof Error ? error : new Error(error?.message ?? 'Unexpected error'));
130
135
  return true;
131
136
  }
132
137
 
@@ -157,9 +162,9 @@ class PendingRequestService {
157
162
  clearTimeout(entry.timeoutId);
158
163
  try {
159
164
  entry.reject(
160
- new V1UnexpectedError(
161
- `Pending request ${id} cancelled (shutdown).`,
162
- false)
165
+ new V1ProtocolError(
166
+ ResultCode.UNEXPECTED_ERROR,
167
+ `Pending request ${id} cancelled (shutdown).`)
163
168
  );
164
169
  } catch (error) {
165
170
  console.error(`PendingRequestService.close: failed to reject pending request ${id}:`, error);
@@ -168,5 +173,3 @@ class PendingRequestService {
168
173
  this.#pendingRequests.clear();
169
174
  }
170
175
  }
171
-
172
- export default PendingRequestService;
@@ -3,6 +3,42 @@ import {TRANSACTION_COMMIT_SERVICE_BUFFER_SIZE} from '../../../utils/constants.j
3
3
 
4
4
  const TX_HASH_HEX_STRING_LENGTH = 64;
5
5
 
6
+ export class PendingCommitInvalidTxHashError extends Error {
7
+ constructor(txHash) {
8
+ super(`Invalid txHash format: ${txHash}`);
9
+ }
10
+ }
11
+
12
+ export class PendingCommitBufferFullError extends Error {
13
+ constructor(limit) {
14
+ super(`Maximum number of pending commits reached (limit=${limit}).`);
15
+ }
16
+ }
17
+
18
+ export class PendingCommitAlreadyExistsError extends Error {
19
+ constructor(txHash) {
20
+ super(`Pending commit for txHash ${txHash} already exists.`);
21
+ }
22
+ }
23
+
24
+ export class PendingCommitTimeoutError extends Error {
25
+ constructor(txHash, timeoutMs) {
26
+ super(`Pending commit for txHash ${txHash} timed out after ${timeoutMs} ms.`);
27
+ }
28
+ }
29
+
30
+ export class PendingCommitCancelledError extends Error {
31
+ constructor(txHash) {
32
+ super(`Pending commit ${txHash} cancelled (shutdown).`);
33
+ }
34
+ }
35
+
36
+ export class PendingCommitUnexpectedError extends Error {
37
+ constructor(message = 'Unexpected commit error') {
38
+ super(message);
39
+ }
40
+ }
41
+
6
42
  class TransactionCommitService {
7
43
  #pendingCommits;
8
44
  #config;
@@ -111,39 +147,3 @@ class TransactionCommitService {
111
147
  }
112
148
 
113
149
  export default TransactionCommitService;
114
-
115
- export class PendingCommitInvalidTxHashError extends Error {
116
- constructor(txHash) {
117
- super(`Invalid txHash format: ${txHash}`);
118
- }
119
- }
120
-
121
- export class PendingCommitBufferFullError extends Error {
122
- constructor(limit) {
123
- super(`Maximum number of pending commits reached (limit=${limit}).`);
124
- }
125
- }
126
-
127
- export class PendingCommitAlreadyExistsError extends Error {
128
- constructor(txHash) {
129
- super(`Pending commit for txHash ${txHash} already exists.`);
130
- }
131
- }
132
-
133
- export class PendingCommitTimeoutError extends Error {
134
- constructor(txHash, timeoutMs) {
135
- super(`Pending commit for txHash ${txHash} timed out after ${timeoutMs} ms.`);
136
- }
137
- }
138
-
139
- export class PendingCommitCancelledError extends Error {
140
- constructor(txHash) {
141
- super(`Pending commit ${txHash} cancelled (shutdown).`);
142
- }
143
- }
144
-
145
- export class PendingCommitUnexpectedError extends Error {
146
- constructor(message = 'Unexpected commit error') {
147
- super(message);
148
- }
149
- }
@@ -4,6 +4,45 @@ import Scheduler from '../../../utils/Scheduler.js';
4
4
  import Denque from "denque";
5
5
  import b4a from "b4a";
6
6
 
7
+ export class TransactionPoolProofUnavailableError extends Error {
8
+ constructor(txHash, blockNumber, reason = 'unknown', timestamp = 0) {
9
+ const timestampValue = timestamp instanceof Date ? timestamp.getTime() : timestamp;
10
+ const safeTimestamp = Number.isSafeInteger(timestampValue) ? timestampValue : 0;
11
+ super(`Proof unavailable for txHash ${txHash} at block ${blockNumber} at ${safeTimestamp}. Reason: ${reason}`);
12
+ this.txHash = txHash;
13
+ this.blockNumber = blockNumber;
14
+ this.timestamp = safeTimestamp;
15
+ this.reason = reason;
16
+ }
17
+ }
18
+
19
+ export class TransactionPoolMissingCommitReceiptError extends Error {
20
+ constructor(txHash) {
21
+ super(`Missing commit receipt for txHash ${txHash}`);
22
+ this.txHash = txHash;
23
+ }
24
+ }
25
+
26
+ export class TransactionPoolInvalidIncomingDataError extends Error {
27
+ constructor(message = 'Invalid transaction pool incoming data') {
28
+ super(message);
29
+ }
30
+ }
31
+
32
+ export class TransactionPoolFullError extends Error {
33
+ constructor(maxSize) {
34
+ super(`Transaction pool is full. Maximum size of ${maxSize} reached.`);
35
+ this.maxSize = maxSize
36
+ }
37
+
38
+ }
39
+
40
+ export class TransactionPoolAlreadyQueuedError extends Error {
41
+ constructor(txHash) {
42
+ super(`Transaction with hash ${txHash} is already queued in the transaction pool.`);
43
+ }
44
+ }
45
+
7
46
  class TransactionPoolService {
8
47
  #state;
9
48
  #address;
@@ -168,43 +207,4 @@ class TransactionPoolService {
168
207
  }
169
208
  }
170
209
 
171
- export class TransactionPoolProofUnavailableError extends Error {
172
- constructor(txHash, blockNumber, reason = 'unknown', timestamp = 0) {
173
- const timestampValue = timestamp instanceof Date ? timestamp.getTime() : timestamp;
174
- const safeTimestamp = Number.isSafeInteger(timestampValue) ? timestampValue : 0;
175
- super(`Proof unavailable for txHash ${txHash} at block ${blockNumber} at ${safeTimestamp}. Reason: ${reason}`);
176
- this.txHash = txHash;
177
- this.blockNumber = blockNumber;
178
- this.timestamp = safeTimestamp;
179
- this.reason = reason;
180
- }
181
- }
182
-
183
- export class TransactionPoolMissingCommitReceiptError extends Error {
184
- constructor(txHash) {
185
- super(`Missing commit receipt for txHash ${txHash}`);
186
- this.txHash = txHash;
187
- }
188
- }
189
-
190
- export class TransactionPoolInvalidIncomingDataError extends Error {
191
- constructor(message = 'Invalid transaction pool incoming data') {
192
- super(message);
193
- }
194
- }
195
-
196
- export class TransactionPoolFullError extends Error {
197
- constructor(maxSize) {
198
- super(`Transaction pool is full. Maximum size of ${maxSize} reached.`);
199
- this.maxSize = maxSize
200
- }
201
-
202
- }
203
-
204
- export class TransactionPoolAlreadyQueuedError extends Error {
205
- constructor(txHash) {
206
- super(`Transaction with hash ${txHash} is already queued in the transaction pool.`);
207
- }
208
- }
209
-
210
210
  export default TransactionPoolService;
@@ -1,5 +1,6 @@
1
1
  import b4a from 'b4a';
2
- import {V1RateLimitedError} from "../protocols/v1/V1ProtocolError.js";
2
+ import {V1ProtocolError} from "../protocols/v1/V1ProtocolError.js";
3
+ import {ResultCode} from "../../../utils/constants.js";
3
4
  import {publicKeyToAddress} from "../../../utils/helpers.js";
4
5
 
5
6
  class TransactionRateLimiterService {
@@ -64,7 +65,7 @@ class TransactionRateLimiterService {
64
65
 
65
66
  /*
66
67
  Handles rate limiting for a peer connection (v1 protocol).
67
- If the peer has exceeded the rate limit, it throws RateLimitedError.
68
+ If the peer has exceeded the rate limit, it throws V1ProtocolError with RATE_LIMITED result code.
68
69
  Otherwise, it updates the connection info with the current timestamp.
69
70
  */
70
71
  v1HandleRateLimit(connection) {
@@ -75,7 +76,10 @@ class TransactionRateLimiterService {
75
76
  this.#initializePeerConnectionInfoEntry(peer, currentTime);
76
77
 
77
78
  if (this.#hasExceededRateLimit(peer, currentTime)) {
78
- throw new V1RateLimitedError(`Rate limit exceeded for peer ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`);
79
+ throw new V1ProtocolError(
80
+ ResultCode.RATE_LIMITED,
81
+ `Rate limit exceeded for peer ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
82
+ );
79
83
  }
80
84
  this.#updatePeerConnectionInfo(peer, currentTime);
81
85
  }
@@ -93,7 +97,7 @@ class TransactionRateLimiterService {
93
97
  return;
94
98
  }
95
99
 
96
- for (const [peer, _] of this.#connectionsStatistics.entries()) {
100
+ for (const [peer] of this.#connectionsStatistics.entries()) {
97
101
  if (this.#isConnectionExpired(peer, currentTime)) {
98
102
  this.#connectionsStatistics.delete(peer);
99
103
  }