trac-msb 0.2.18 → 0.2.19
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 +52 -24
- 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
package/src/config/env.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet
|
|
1
|
+
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet';
|
|
2
2
|
import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
|
|
3
|
-
import { address } from 'trac-crypto-api';
|
|
4
3
|
import { Config } from './config.js';
|
|
4
|
+
import { address } from 'trac-crypto-api';
|
|
5
5
|
|
|
6
6
|
export const ENV = {
|
|
7
7
|
MAINNET: 'mainnet',
|
|
@@ -18,16 +18,23 @@ const configData = {
|
|
|
18
18
|
bech32mHrpLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length + 1, // len(addressPrefix + separator)
|
|
19
19
|
bootstrap: 'c184f4ad8e9cf5e911f9415b60e7dcfb30aed73ebd8a402ef68e1b154624f5ef',
|
|
20
20
|
channel: '1111trac1network1msb1testnet1111',
|
|
21
|
-
dhtBootstrap: ['116.202.214.149:10001',
|
|
21
|
+
dhtBootstrap: ['116.202.214.149:10001','157.180.12.214:10001','node1.hyperdht.org:49737','node2.hyperdht.org:49737','node3.hyperdht.org:49737'], // these are used to peer discovery
|
|
22
22
|
derivationPath: address.TESNET_DERIVATION_PATH,
|
|
23
|
+
enableValidatorObserver: true,
|
|
24
|
+
pollInterval: 500, // Validator observer poll interval
|
|
25
|
+
adminCacheTTL: 10_000, // Admin cache TTL ms
|
|
26
|
+
validatorConnectionAttemptDelay: 5, // Delay between validator connection attempts (ms)
|
|
27
|
+
bootstrapTimeout: 60_000, // time used (ms) to connect to new validators at bootstrap
|
|
28
|
+
writersShortCacheTTL: 10_000, // short TTL during bootstrap
|
|
29
|
+
writersLongCacheTTL: 120_000, // long TTL after bootstrap
|
|
30
|
+
maxValidators: 50,
|
|
31
|
+
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
23
32
|
disableRateLimit: false,
|
|
24
33
|
enableErrorApplyLogs: true,
|
|
25
34
|
enableInteractiveMode: true,
|
|
26
35
|
enableRoleRequester: false,
|
|
27
36
|
enableTxApplyLogs: true,
|
|
28
|
-
enableValidatorObserver: true,
|
|
29
37
|
enableWallet: true,
|
|
30
|
-
maxValidators: 50,
|
|
31
38
|
maxRetries: 3,
|
|
32
39
|
messageThreshold: 3,
|
|
33
40
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
@@ -39,7 +46,6 @@ const configData = {
|
|
|
39
46
|
maxParallel: 64, // Connectivity constants
|
|
40
47
|
maxServerConnections: Infinity, // Connectivity constants
|
|
41
48
|
maxClientConnections: Infinity, // Connectivity constants
|
|
42
|
-
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
43
49
|
processIntervalMs: 50, // Pool constants
|
|
44
50
|
transactionPoolSize: 1000, // Operation handler constants
|
|
45
51
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
@@ -61,16 +67,23 @@ const configData = {
|
|
|
61
67
|
bech32mHrpLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length + 1, // len(addressPrefix + separator)
|
|
62
68
|
bootstrap: 'acbc3a4344d3a804101d40e53db1dda82b767646425af73599d4cd6577d69685',
|
|
63
69
|
channel: '0000trac0network0msb0mainnet0000',
|
|
64
|
-
dhtBootstrap: ['116.202.214.149:10001',
|
|
70
|
+
dhtBootstrap: ['116.202.214.149:10001','157.180.12.214:10001','node1.hyperdht.org:49737','node2.hyperdht.org:49737','node3.hyperdht.org:49737'],
|
|
65
71
|
derivationPath: address.MAINNET_DERIVATION_PATH,
|
|
72
|
+
enableValidatorObserver: true,
|
|
73
|
+
pollInterval: 500, // Validator observer poll interval
|
|
74
|
+
adminCacheTTL: 3_600_000, // Admin cache TTL ms
|
|
75
|
+
validatorConnectionAttemptDelay: 5, // Delay between validator connection attempts (ms)
|
|
76
|
+
bootstrapTimeout: 120_000, // time used (ms) to connect to new validators at bootstrap
|
|
77
|
+
writersShortCacheTTL: 2_000, // short TTL during bootstrap
|
|
78
|
+
writersLongCacheTTL: 120_000, // long TTL after bootstrap
|
|
79
|
+
maxValidators: 50,
|
|
80
|
+
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
66
81
|
disableRateLimit: false,
|
|
67
82
|
enableErrorApplyLogs: false,
|
|
68
83
|
enableInteractiveMode: true,
|
|
69
84
|
enableRoleRequester: false,
|
|
70
85
|
enableTxApplyLogs: false,
|
|
71
|
-
enableValidatorObserver: true,
|
|
72
86
|
enableWallet: true,
|
|
73
|
-
maxValidators: 50,
|
|
74
87
|
maxRetries: 3,
|
|
75
88
|
messageThreshold: 3,
|
|
76
89
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
@@ -82,7 +95,6 @@ const configData = {
|
|
|
82
95
|
maxParallel: 64, // Connectivity constants
|
|
83
96
|
maxServerConnections: Infinity, // Connectivity constants
|
|
84
97
|
maxClientConnections: Infinity, // Connectivity constants
|
|
85
|
-
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
86
98
|
processIntervalMs: 50, // Pool constants
|
|
87
99
|
transactionPoolSize: 1000, // Operation handler constants
|
|
88
100
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
@@ -97,23 +109,30 @@ const configData = {
|
|
|
97
109
|
storeName: 'mainnet',
|
|
98
110
|
},
|
|
99
111
|
[ENV.DEVELOPMENT]: {
|
|
100
|
-
debug:
|
|
112
|
+
debug: false,
|
|
101
113
|
addressLength: 63,
|
|
102
114
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
103
115
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
104
116
|
bech32mHrpLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length + 1, // len(addressPrefix + separator)
|
|
105
|
-
bootstrap: '
|
|
117
|
+
bootstrap: '12f7f1668eac2e691e17cbc6a53e509c5cee78cdcac562313091c64e5fd077d6',
|
|
106
118
|
channel: '12312313123123',
|
|
107
|
-
dhtBootstrap: ['116.202.214.149:10001',
|
|
119
|
+
dhtBootstrap: ['116.202.214.149:10001','157.180.12.214:10001','node1.hyperdht.org:49737','node2.hyperdht.org:49737','node3.hyperdht.org:49737'],
|
|
108
120
|
derivationPath: address.MAINNET_DERIVATION_PATH,
|
|
121
|
+
enableValidatorObserver: true,
|
|
122
|
+
pollInterval: 500, // Validator observer poll interval
|
|
123
|
+
adminCacheTTL: 60_000, // Admin cache TTL ms
|
|
124
|
+
validatorConnectionAttemptDelay: 5, // Delay between validator connection attempts (ms)
|
|
125
|
+
bootstrapTimeout: 30_000, // time used (ms) to connect to new validators at bootstrap
|
|
126
|
+
writersShortCacheTTL: 1_000, // short TTL during bootstrap
|
|
127
|
+
writersLongCacheTTL: 2_000, // long TTL after bootstrap
|
|
128
|
+
maxValidators: 10,
|
|
129
|
+
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
109
130
|
disableRateLimit: false,
|
|
110
131
|
enableErrorApplyLogs: true,
|
|
111
132
|
enableInteractiveMode: true,
|
|
112
133
|
enableRoleRequester: false,
|
|
113
134
|
enableTxApplyLogs: true,
|
|
114
|
-
enableValidatorObserver: true,
|
|
115
135
|
enableWallet: true,
|
|
116
|
-
maxValidators: 6,
|
|
117
136
|
maxRetries: 3,
|
|
118
137
|
messageThreshold: 1000,
|
|
119
138
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
@@ -125,7 +144,6 @@ const configData = {
|
|
|
125
144
|
maxParallel: 64, // Connectivity constants
|
|
126
145
|
maxServerConnections: Infinity, // Connectivity constants
|
|
127
146
|
maxClientConnections: Infinity, // Connectivity constants
|
|
128
|
-
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
129
147
|
processIntervalMs: 50, // Pool constants
|
|
130
148
|
transactionPoolSize: 1000, // Operation handler constants
|
|
131
149
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
@@ -135,7 +153,7 @@ const configData = {
|
|
|
135
153
|
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
136
154
|
txCommitTimeout: 2200,
|
|
137
155
|
txPoolSize: 1000, // size of transaction pool
|
|
138
|
-
validatorHealthCheckInterval:
|
|
156
|
+
validatorHealthCheckInterval: 1_000, // How often to check validator health (ms)
|
|
139
157
|
storesDirectory: 'stores/',
|
|
140
158
|
storeName: 'development',
|
|
141
159
|
}
|
|
@@ -143,4 +161,4 @@ const configData = {
|
|
|
143
161
|
|
|
144
162
|
export const createConfig = (environment, options) => {
|
|
145
163
|
return new Config(options, configData[environment])
|
|
146
|
-
}
|
|
164
|
+
}
|
|
@@ -8,16 +8,17 @@ import NetworkMessages from './protocols/NetworkMessages.js';
|
|
|
8
8
|
import { sleep } from '../../utils/helpers.js';
|
|
9
9
|
import {
|
|
10
10
|
TRAC_NAMESPACE,
|
|
11
|
-
EventType
|
|
11
|
+
EventType,
|
|
12
|
+
CONNECTION_STATUS
|
|
12
13
|
} from '../../utils/constants.js';
|
|
13
14
|
import ConnectionManager from './services/ConnectionManager.js';
|
|
14
15
|
import MessageOrchestrator from './services/MessageOrchestrator.js';
|
|
15
|
-
import NetworkWalletFactory from './identity/NetworkWalletFactory.js';
|
|
16
16
|
import TransactionRateLimiterService from './services/TransactionRateLimiterService.js';
|
|
17
17
|
import PendingRequestService from './services/PendingRequestService.js';
|
|
18
18
|
import TransactionCommitService from "./services/TransactionCommitService.js";
|
|
19
19
|
import ValidatorHealthCheckService from './services/ValidatorHealthCheckService.js';
|
|
20
20
|
import { Logger } from '../../utils/logger.js';
|
|
21
|
+
import { WalletProvider } from 'trac-wallet';
|
|
21
22
|
|
|
22
23
|
const wakeup = new w();
|
|
23
24
|
|
|
@@ -29,7 +30,6 @@ class Network extends ReadyResource {
|
|
|
29
30
|
#validatorConnectionManager;
|
|
30
31
|
#validatorMessageOrchestrator;
|
|
31
32
|
#config;
|
|
32
|
-
#identityProvider = null;
|
|
33
33
|
#pendingConnections;
|
|
34
34
|
#connectTimeoutMs;
|
|
35
35
|
#maxPendingConnections;
|
|
@@ -126,7 +126,7 @@ class Network extends ReadyResource {
|
|
|
126
126
|
|
|
127
127
|
if (type === 'validator') {
|
|
128
128
|
try {
|
|
129
|
-
await connection.protocolSession.probe();
|
|
129
|
+
if (!connection.protocolSession.isProbed()) await connection.protocolSession.probe();
|
|
130
130
|
} catch (err) {
|
|
131
131
|
this.#logger.debug(`failed to probe peer with publicKey ${publicKey}: ${err?.message ?? err}`);
|
|
132
132
|
}
|
|
@@ -168,8 +168,8 @@ class Network extends ReadyResource {
|
|
|
168
168
|
wallet,
|
|
169
169
|
) {
|
|
170
170
|
if (!this.#swarm) {
|
|
171
|
-
const keyPair = await this
|
|
172
|
-
this.#wallet =
|
|
171
|
+
const { wallet: wrappedWallet, keyPair } = await this.#getOrGenerateWallet(store, wallet);
|
|
172
|
+
this.#wallet = wrappedWallet
|
|
173
173
|
this.#validatorMessageOrchestrator.setWallet(this.#wallet);
|
|
174
174
|
|
|
175
175
|
this.#swarm = new Hyperswarm({
|
|
@@ -255,14 +255,36 @@ class Network extends ReadyResource {
|
|
|
255
255
|
return this.#pendingConnections.size;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
|
|
258
|
+
disconnectValidatorPeer(publicKey, reason = 'validator peer invalidated') {
|
|
259
|
+
const publicKeyHex = this.#normalizePublicKey(publicKey);
|
|
260
|
+
if (!publicKeyHex) return false;
|
|
261
|
+
|
|
262
|
+
const hadPendingValidatorConnection = this.#clearPendingValidatorConnection(publicKeyHex);
|
|
263
|
+
const isTrackedValidator = this.#validatorConnectionManager.exists(publicKeyHex);
|
|
264
|
+
|
|
265
|
+
const shouldLeavePeer = hadPendingValidatorConnection || isTrackedValidator;
|
|
266
|
+
|
|
267
|
+
if (shouldLeavePeer && this.#swarm?.peers?.has(publicKeyHex)) {
|
|
268
|
+
this.#logger.debug(`Network.disconnectValidatorPeer: leaving peer ${publicKeyHex}. Reason: ${reason}`);
|
|
269
|
+
this.#swarm.leavePeer(b4a.from(publicKeyHex, 'hex'));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (isTrackedValidator) {
|
|
273
|
+
this.#logger.debug(`Network.disconnectValidatorPeer: detaching tracked validator ${publicKeyHex}. Reason: ${reason}`);
|
|
274
|
+
this.#validatorConnectionManager.remove(publicKeyHex, { endConnection: false });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return hadPendingValidatorConnection || isTrackedValidator;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async #getOrGenerateWallet(store, wallet) {
|
|
259
281
|
if (!this.#config.enableWallet) {
|
|
260
|
-
|
|
282
|
+
const keyPair = await store.createKeyPair(TRAC_NAMESPACE);
|
|
283
|
+
const wallet = await new WalletProvider(this.#config).fromSecretKey(keyPair.secretKey)
|
|
284
|
+
return { keyPair, wallet }
|
|
261
285
|
} else {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
secretKey: wallet.secretKey
|
|
265
|
-
};
|
|
286
|
+
const keyPair = { publicKey: wallet.publicKey, secretKey: wallet.secretKey }
|
|
287
|
+
return { keyPair, wallet }
|
|
266
288
|
}
|
|
267
289
|
}
|
|
268
290
|
|
|
@@ -270,7 +292,7 @@ class Network extends ReadyResource {
|
|
|
270
292
|
if (this.#swarm === null) throw new Error('Network swarm is not initialized');
|
|
271
293
|
if (this.#pendingConnections.has(publicKey) || this.#pendingConnections.size >= this.#maxPendingConnections) {
|
|
272
294
|
this.#logger.debug(`Network.tryConnect: Connection to peer: ${publicKey} as type: ${type} is already pending or max pending connections reached.`);
|
|
273
|
-
return;
|
|
295
|
+
return CONNECTION_STATUS.IGNORED;
|
|
274
296
|
}
|
|
275
297
|
|
|
276
298
|
const timeoutId = setTimeout(() => {
|
|
@@ -290,12 +312,14 @@ class Network extends ReadyResource {
|
|
|
290
312
|
|
|
291
313
|
if (connection &&
|
|
292
314
|
connection.protocolSession &&
|
|
293
|
-
!connection.protocolSession.isProbed() &&
|
|
294
315
|
!this.#pendingRequestsService.isProbePending(connection.remotePublicKey.toString('hex'))
|
|
295
316
|
) {
|
|
296
317
|
await this.#finalizeConnection(publicKey, type, connection);
|
|
318
|
+
return CONNECTION_STATUS.CONNECTED;
|
|
297
319
|
}
|
|
298
320
|
}
|
|
321
|
+
|
|
322
|
+
return CONNECTION_STATUS.PENDING;
|
|
299
323
|
}
|
|
300
324
|
|
|
301
325
|
async #finalizeConnection(publicKey, type, connection) {
|
|
@@ -304,18 +328,22 @@ class Network extends ReadyResource {
|
|
|
304
328
|
this.#logger.debug(`Network.finalizeConnection: Connected to peer: ${publicKey} as type: ${type}`);
|
|
305
329
|
}
|
|
306
330
|
|
|
307
|
-
#
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
wallet,
|
|
312
|
-
keyPair,
|
|
313
|
-
networkPrefix: this.#config.addressPrefix
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
return this.#identityProvider;
|
|
331
|
+
#normalizePublicKey(publicKey) {
|
|
332
|
+
if (typeof publicKey === 'string') return publicKey;
|
|
333
|
+
if (b4a.isBuffer(publicKey)) return b4a.toString(publicKey, 'hex');
|
|
334
|
+
return null;
|
|
317
335
|
}
|
|
318
336
|
|
|
337
|
+
#clearPendingValidatorConnection(publicKeyHex) {
|
|
338
|
+
if (!this.#pendingConnections.has(publicKeyHex)) return false;
|
|
339
|
+
|
|
340
|
+
const { timeoutId, type } = this.#pendingConnections.get(publicKeyHex);
|
|
341
|
+
if (type !== 'validator') return false;
|
|
342
|
+
|
|
343
|
+
clearTimeout(timeoutId);
|
|
344
|
+
this.#pendingConnections.delete(publicKeyHex);
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
319
347
|
}
|
|
320
348
|
|
|
321
349
|
export default Network;
|
|
@@ -6,30 +6,30 @@
|
|
|
6
6
|
class ProtocolInterface {
|
|
7
7
|
|
|
8
8
|
// TODO: Refactor this so we don't need to pass a reference for the whole network instance
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(_router, _connection, _pendingRequestService, _config) {
|
|
10
10
|
if (new.target === ProtocolInterface) {
|
|
11
11
|
throw new Error('ProtocolInterface cannot be instantiated directly');
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
init(
|
|
15
|
+
init(_connection) {
|
|
16
16
|
// Abstract method. Need to be implemented by subclasses.
|
|
17
17
|
throw new Error('init() method must be implemented by subclass');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// TODO: This method is only kept here because of v1, but it should be probably removed from the interface
|
|
21
21
|
// Remove it after we finish refactoring v1 protocol
|
|
22
|
-
decode(
|
|
22
|
+
decode(_message) {
|
|
23
23
|
// Abstract method. Need to be implemented by subclasses.
|
|
24
24
|
throw new Error('decode() method must be implemented by subclass');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async send(
|
|
27
|
+
async send(_message) {
|
|
28
28
|
// Abstract method. Need to be implemented by subclasses.
|
|
29
29
|
throw new Error('send() method must be implemented by subclass');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
sendAndForget(
|
|
32
|
+
sendAndForget(_message) {
|
|
33
33
|
// Abstract method. Need to be implemented by subclasses.
|
|
34
34
|
throw new Error('sendAndForget() method must be implemented by subclass');
|
|
35
35
|
}
|
|
@@ -2,6 +2,11 @@ import { ResultCode } from '../../../utils/constants.js';
|
|
|
2
2
|
|
|
3
3
|
// TODO: Consider how to behave with ResultCode.UNSPECIFIED
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Sender actions are consumed by the message orchestrator after a validator responds.
|
|
7
|
+
* They define whether the validator should be treated as successful, rotated out, or kept
|
|
8
|
+
* in the pool without rotation for the current result code.
|
|
9
|
+
*/
|
|
5
10
|
export const SENDER_ACTION = Object.freeze({
|
|
6
11
|
UNDEFINED: 'UNDEFINED',
|
|
7
12
|
SUCCESS: 'SUCCESS',
|
|
@@ -9,10 +14,14 @@ export const SENDER_ACTION = Object.freeze({
|
|
|
9
14
|
NO_ROTATE: 'NO_ROTATE',
|
|
10
15
|
});
|
|
11
16
|
|
|
17
|
+
// Result codes that mean the validator completed the request successfully.
|
|
12
18
|
const SUCCESS_CODES = new Set([
|
|
13
19
|
ResultCode.OK,
|
|
14
20
|
]);
|
|
15
21
|
|
|
22
|
+
// Result codes that should rotate the validator out of the sender pool after the response.
|
|
23
|
+
// In practice these are transport, protocol, validation, or validator-side failures that make
|
|
24
|
+
// the current peer unsuitable to keep as the next sender candidate.
|
|
16
25
|
const ROTATE_CODES = new Set([
|
|
17
26
|
ResultCode.UNSPECIFIED,
|
|
18
27
|
ResultCode.INVALID_PAYLOAD,
|
|
@@ -86,3 +95,80 @@ export function resultToValidatorAction(resultCode) {
|
|
|
86
95
|
if (NO_ROTATE_CODES.has(resultCode)) return SENDER_ACTION.NO_ROTATE;
|
|
87
96
|
return SENDER_ACTION.UNDEFINED;
|
|
88
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Keep connection result codes:
|
|
101
|
+
* - ResultCode.OK
|
|
102
|
+
* - ResultCode.TIMEOUT
|
|
103
|
+
* - ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE
|
|
104
|
+
* - ResultCode.TX_ALREADY_PENDING
|
|
105
|
+
* - ResultCode.TX_HASH_INVALID_FORMAT
|
|
106
|
+
* - ResultCode.INTERNAL_ENQUEUE_VALIDATION_FAILED
|
|
107
|
+
* - ResultCode.TX_COMMITTED_RECEIPT_MISSING
|
|
108
|
+
* - ResultCode.VALIDATOR_RESPONSE_TX_TYPE_INVALID
|
|
109
|
+
* - ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN
|
|
110
|
+
* - ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED
|
|
111
|
+
* - ResultCode.VALIDATOR_RESPONSE_SCHEMA_INVALID
|
|
112
|
+
* - ResultCode.PENDING_REQUEST_MISSING_TX_DATA
|
|
113
|
+
* - ResultCode.PROOF_PAYLOAD_MISMATCH
|
|
114
|
+
* - ResultCode.VALIDATOR_WRITER_KEY_NOT_REGISTERED
|
|
115
|
+
* - ResultCode.VALIDATOR_ADDRESS_MISMATCH
|
|
116
|
+
* - ResultCode.VALIDATOR_NODE_ENTRY_NOT_FOUND
|
|
117
|
+
* - ResultCode.VALIDATOR_NODE_NOT_WRITER
|
|
118
|
+
* - ResultCode.VALIDATOR_WRITER_KEY_MISMATCH
|
|
119
|
+
* - ResultCode.VALIDATOR_TX_OBJECT_INVALID
|
|
120
|
+
* - ResultCode.VALIDATOR_VA_MISSING
|
|
121
|
+
*/
|
|
122
|
+
const VALIDATOR_SIDE_END_CONNECTION_CODES = new Set([
|
|
123
|
+
// BASE_TRANSPORT_AND_VALIDATOR_STATUS
|
|
124
|
+
ResultCode.UNSPECIFIED,
|
|
125
|
+
ResultCode.INVALID_PAYLOAD,
|
|
126
|
+
ResultCode.RATE_LIMITED,
|
|
127
|
+
ResultCode.SIGNATURE_INVALID,
|
|
128
|
+
ResultCode.UNEXPECTED_ERROR,
|
|
129
|
+
ResultCode.NODE_HAS_NO_WRITE_ACCESS,
|
|
130
|
+
ResultCode.NODE_OVERLOADED,
|
|
131
|
+
|
|
132
|
+
// SHARED_VALIDATORS_REQUEST_PAYLOAD
|
|
133
|
+
ResultCode.OPERATION_TYPE_UNKNOWN,
|
|
134
|
+
ResultCode.SCHEMA_VALIDATION_FAILED,
|
|
135
|
+
ResultCode.REQUESTER_ADDRESS_INVALID,
|
|
136
|
+
ResultCode.REQUESTER_PUBLIC_KEY_INVALID,
|
|
137
|
+
ResultCode.TX_HASH_MISMATCH,
|
|
138
|
+
ResultCode.TX_SIGNATURE_INVALID,
|
|
139
|
+
ResultCode.TX_EXPIRED,
|
|
140
|
+
ResultCode.TX_ALREADY_EXISTS,
|
|
141
|
+
ResultCode.OPERATION_ALREADY_COMPLETED,
|
|
142
|
+
ResultCode.REQUESTER_NOT_FOUND,
|
|
143
|
+
ResultCode.INSUFFICIENT_FEE_BALANCE,
|
|
144
|
+
ResultCode.EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP,
|
|
145
|
+
ResultCode.SELF_VALIDATION_FORBIDDEN,
|
|
146
|
+
ResultCode.ROLE_NODE_ENTRY_NOT_FOUND,
|
|
147
|
+
ResultCode.ROLE_NODE_ALREADY_WRITER,
|
|
148
|
+
ResultCode.ROLE_NODE_NOT_WHITELISTED,
|
|
149
|
+
ResultCode.ROLE_NODE_NOT_WRITER,
|
|
150
|
+
ResultCode.ROLE_NODE_IS_INDEXER,
|
|
151
|
+
ResultCode.ROLE_ADMIN_ENTRY_MISSING,
|
|
152
|
+
ResultCode.ROLE_INVALID_RECOVERY_CASE,
|
|
153
|
+
ResultCode.ROLE_UNKNOWN_OPERATION,
|
|
154
|
+
ResultCode.ROLE_INVALID_WRITER_KEY,
|
|
155
|
+
ResultCode.ROLE_INSUFFICIENT_FEE_BALANCE,
|
|
156
|
+
ResultCode.MSB_BOOTSTRAP_MISMATCH,
|
|
157
|
+
ResultCode.EXTERNAL_BOOTSTRAP_NOT_DEPLOYED,
|
|
158
|
+
ResultCode.EXTERNAL_BOOTSTRAP_TX_MISSING,
|
|
159
|
+
ResultCode.EXTERNAL_BOOTSTRAP_MISMATCH,
|
|
160
|
+
ResultCode.BOOTSTRAP_ALREADY_EXISTS,
|
|
161
|
+
ResultCode.TRANSFER_RECIPIENT_ADDRESS_INVALID,
|
|
162
|
+
ResultCode.TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID,
|
|
163
|
+
ResultCode.TRANSFER_AMOUNT_TOO_LARGE,
|
|
164
|
+
ResultCode.TRANSFER_SENDER_NOT_FOUND,
|
|
165
|
+
ResultCode.TRANSFER_INSUFFICIENT_BALANCE,
|
|
166
|
+
ResultCode.TRANSFER_RECIPIENT_BALANCE_OVERFLOW,
|
|
167
|
+
|
|
168
|
+
// VALIDATOR_RESPONSE_PROOF_AND_IDENTITY_VALIDATION
|
|
169
|
+
ResultCode.TX_INVALID_PAYLOAD,
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
export function shouldEndConnection(resultCode) {
|
|
173
|
+
return VALIDATOR_SIDE_END_CONNECTION_CODES.has(resultCode);
|
|
174
|
+
}
|
|
@@ -14,7 +14,7 @@ class NetworkMessageRouter {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {State} state
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {IWallet} wallet
|
|
18
18
|
* @param {TransactionRateLimiterService} rateLimiterService
|
|
19
19
|
* @param {TransactionPoolService} txPoolService
|
|
20
20
|
* @param {Config} config
|
|
@@ -10,7 +10,7 @@ class BaseStateOperationHandler {
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @param {State} state
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {IWallet} wallet
|
|
14
14
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
15
15
|
* @param {TransactionPoolService} txPoolService
|
|
16
16
|
* @param {Config} config
|
|
@@ -69,7 +69,7 @@ class BaseStateOperationHandler {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async handleOperation(
|
|
72
|
+
async handleOperation(_payload, _connection) {
|
|
73
73
|
throw new Error('handleOperation must be implemented by child class');
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NETWORK_MESSAGE_TYPES } from '../../../../../utils/constants.js';
|
|
2
|
-
import
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
3
3
|
import b4a from 'b4a';
|
|
4
4
|
|
|
5
5
|
class LegacyGetRequestHandler {
|
|
@@ -26,7 +26,7 @@ class LegacyGetRequestHandler {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async handleGetValidatorResponse(connection, channelString) {
|
|
29
|
-
const nonce =
|
|
29
|
+
const nonce = b4a.toString(tracCryptoApi.nonce.generate(), 'hex');
|
|
30
30
|
const payload = {
|
|
31
31
|
op: 'validatorResponse',
|
|
32
32
|
wk: this.state.writingKey.toString('hex'),
|
|
@@ -39,7 +39,7 @@ class LegacyGetRequestHandler {
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
const hashInput = b4a.from(JSON.stringify(payload), 'utf8');
|
|
42
|
-
const hash = await
|
|
42
|
+
const hash = await tracCryptoApi.hash.blake3(hashInput);
|
|
43
43
|
const sig = this.#wallet.sign(hash);
|
|
44
44
|
|
|
45
45
|
const responseMessage = {
|
|
@@ -14,7 +14,7 @@ class LegacyRoleOperationHandler extends BaseStateOperationHandler {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {State} state
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {IWallet} wallet
|
|
18
18
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
19
19
|
* @param {TransactionPoolService} txPoolService
|
|
20
20
|
* @param {Config} config
|
|
@@ -22,7 +22,7 @@ class LegacySubnetworkOperationHandler extends BaseStateOperationHandler {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @param {State} state
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {IWallet} wallet
|
|
26
26
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
27
27
|
* @param {TransactionPoolService} txPoolService
|
|
28
28
|
* @param {Config} config
|
|
@@ -14,7 +14,7 @@ class LegacyTransferOperationHandler extends BaseStateOperationHandler {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {State} state
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {IWallet} wallet
|
|
18
18
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
19
19
|
* @param {TransactionPoolService} txPoolService
|
|
20
20
|
* @param {Config} config
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import State from '../../../../../state/State.js';
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
BaseResponse class for handling common validation logic for network responses.
|
|
@@ -9,18 +8,16 @@ import State from '../../../../../state/State.js';
|
|
|
9
8
|
class BaseResponse {
|
|
10
9
|
#wallet;
|
|
11
10
|
#state;
|
|
12
|
-
#config
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
*
|
|
16
14
|
* @param {State} state
|
|
17
|
-
* @param {
|
|
15
|
+
* @param {IWallet} wallet
|
|
18
16
|
* @param {Config} config
|
|
19
17
|
*/
|
|
20
|
-
constructor(state, wallet,
|
|
18
|
+
constructor(state, wallet, _config) {
|
|
21
19
|
this.#state = state;
|
|
22
20
|
this.#wallet = wallet;
|
|
23
|
-
this.#config = config;
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
get state() {
|
|
@@ -66,11 +63,11 @@ class BaseResponse {
|
|
|
66
63
|
switch (type) {
|
|
67
64
|
case 'admin':
|
|
68
65
|
const adminEntry = await this.state.getAdminEntry();
|
|
69
|
-
publicKey =
|
|
66
|
+
publicKey = tracCryptoApi.address.decode(adminEntry.address);
|
|
70
67
|
|
|
71
68
|
break;
|
|
72
69
|
default:
|
|
73
|
-
publicKey =
|
|
70
|
+
publicKey = tracCryptoApi.address.decode(message.address);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
if (!publicKey) {
|
|
@@ -80,7 +77,7 @@ class BaseResponse {
|
|
|
80
77
|
const messageWithoutSig = { ...message };
|
|
81
78
|
delete messageWithoutSig.sig;
|
|
82
79
|
const hashInput = b4a.from(JSON.stringify(messageWithoutSig), 'utf8');
|
|
83
|
-
const hash = await
|
|
80
|
+
const hash = await tracCryptoApi.hash.blake3(hashInput);
|
|
84
81
|
const signature = b4a.from(message.sig, 'hex');
|
|
85
82
|
const verified = this.#wallet.verify(signature, hash, publicKey);
|
|
86
83
|
|
|
@@ -91,4 +88,4 @@ class BaseResponse {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
export default BaseResponse;
|
|
91
|
+
export default BaseResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
2
2
|
import {ResultCode} from "../../../../../utils/constants.js";
|
|
3
|
-
import
|
|
3
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
4
4
|
|
|
5
5
|
class PartialBootstrapDeploymentValidator extends PartialOperationValidator {
|
|
6
6
|
constructor(state, selfAddress , config) {
|
|
@@ -28,7 +28,7 @@ class PartialBootstrapDeploymentValidator extends PartialOperationValidator {
|
|
|
28
28
|
async validateBootstrapRegistration(payload) {
|
|
29
29
|
const bootstrapString = payload.bdo.bs.toString('hex');
|
|
30
30
|
if (null !== await this.state.getRegisteredBootstrapEntryUnsigned(bootstrapString)) {
|
|
31
|
-
throw new
|
|
31
|
+
throw new V1ProtocolError(
|
|
32
32
|
ResultCode.BOOTSTRAP_ALREADY_EXISTS,
|
|
33
33
|
`Bootstrap with hash ${bootstrapString} already exists in the state. Bootstrap must be unique.`
|
|
34
34
|
);
|