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.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +25 -8
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +130 -34
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -59
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -21
- package/whitelist/.gitkeep +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { generateUUID, publicKeyToAddress
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
new PendingRequestServiceTimeoutError(
|
|
90
|
+
id,
|
|
91
|
+
peerAddress,
|
|
92
|
+
this.#config.pendingRequestTimeout
|
|
93
|
+
)
|
|
94
|
+
);
|
|
87
95
|
|
|
88
|
-
},
|
|
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
|
-
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
100
|
+
for (const [peer] of this.#connectionsStatistics.entries()) {
|
|
97
101
|
if (this.#isConnectionExpired(peer, currentTime)) {
|
|
98
102
|
this.#connectionsStatistics.delete(peer);
|
|
99
103
|
}
|