trac-msb 0.2.17 → 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 +33 -11
- 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 +163 -14
- package/src/config/env.js +57 -25
- package/src/core/network/Network.js +121 -56
- package/src/core/network/protocols/LegacyProtocol.js +21 -11
- package/src/core/network/protocols/NetworkMessages.js +38 -17
- package/src/core/network/protocols/ProtocolInterface.js +15 -3
- package/src/core/network/protocols/ProtocolSession.js +144 -17
- package/src/core/network/protocols/V1Protocol.js +37 -18
- package/src/core/network/protocols/connectionPolicies.js +174 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
- package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
- package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
- package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
- package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
- 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 +212 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
- package/src/core/network/services/ConnectionManager.js +149 -96
- package/src/core/network/services/MessageOrchestrator.js +197 -37
- package/src/core/network/services/PendingRequestService.js +175 -0
- package/src/core/network/services/TransactionCommitService.js +149 -0
- package/src/core/network/services/TransactionPoolService.js +129 -18
- package/src/core/network/services/TransactionRateLimiterService.js +57 -35
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +400 -121
- package/src/core/state/State.js +259 -156
- 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 +320 -278
- package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- 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/Scheduler.js +0 -8
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +78 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- package/src/utils/migrationUtils.js +3 -3
- package/src/utils/normalizers.js +38 -0
- package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
- package/src/utils/protobuf/operationHelpers.js +24 -3
- package/.dockerignore +0 -16
- package/.github/workflows/acceptance-tests.yml +0 -38
- package/.github/workflows/lint-pr-title.yml +0 -26
- package/.github/workflows/publish.yml +0 -33
- package/.github/workflows/unit-tests.yml +0 -34
- 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.proto +0 -74
- package/rpc/rpc_services.js +0 -163
- package/scripts/generate-protobufs.js +0 -42
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/acceptance/v1/account/account.test.mjs +0 -123
- 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 -111
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
- 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 -85
- 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 -276
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
- 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/ConnectionManager.test.js +0 -191
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/networkModule.test.js +0 -10
- 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/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 -305
- 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 -20
- package/whitelist/.gitkeep +0 -0
package/src/config/env.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet
|
|
2
|
-
import { Config } from './config.js';
|
|
1
|
+
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet';
|
|
3
2
|
import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
|
|
3
|
+
import { Config } from './config.js';
|
|
4
4
|
import { address } from 'trac-crypto-api';
|
|
5
5
|
|
|
6
6
|
export const ENV = {
|
|
@@ -8,28 +8,35 @@ export const ENV = {
|
|
|
8
8
|
DEVELOPMENT: 'development',
|
|
9
9
|
TESTNET1: 'testnet1'
|
|
10
10
|
}
|
|
11
|
-
// TODO: CREATE TEST ENV CONFIG SIMILAR TO MAINNET AND USE IT IN TESTS.
|
|
12
11
|
|
|
13
12
|
const configData = {
|
|
14
13
|
[ENV.TESTNET1]: {
|
|
14
|
+
debug: false,
|
|
15
15
|
addressLength: 67,
|
|
16
16
|
addressPrefix: TRAC_NETWORK_MSB_TESTNET1_PREFIX,
|
|
17
17
|
addressPrefixLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length,
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
messageThreshold: 1000,
|
|
38
|
+
maxRetries: 3,
|
|
39
|
+
messageThreshold: 3,
|
|
33
40
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
34
41
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
35
42
|
host: 'localhost',
|
|
@@ -39,33 +46,44 @@ 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
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
45
50
|
transactionPoolSize: 1000, // Operation handler constants
|
|
46
51
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
47
52
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
48
53
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
49
|
-
|
|
54
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
55
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
56
|
+
txCommitTimeout: 2200,
|
|
57
|
+
txPoolSize: 1000, // size of transaction pool
|
|
58
|
+
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
59
|
+
storesDirectory: 'stores/',
|
|
50
60
|
storeName: 'testnet',
|
|
51
61
|
},
|
|
52
62
|
[ENV.MAINNET]: {
|
|
63
|
+
debug: false,
|
|
53
64
|
addressLength: 63,
|
|
54
65
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
55
66
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
56
67
|
bech32mHrpLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length + 1, // len(addressPrefix + separator)
|
|
57
68
|
bootstrap: 'acbc3a4344d3a804101d40e53db1dda82b767646425af73599d4cd6577d69685',
|
|
58
69
|
channel: '0000trac0network0msb0mainnet0000',
|
|
59
|
-
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'],
|
|
60
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
|
|
61
81
|
disableRateLimit: false,
|
|
62
82
|
enableErrorApplyLogs: false,
|
|
63
83
|
enableInteractiveMode: true,
|
|
64
84
|
enableRoleRequester: false,
|
|
65
85
|
enableTxApplyLogs: false,
|
|
66
|
-
enableValidatorObserver: true,
|
|
67
86
|
enableWallet: true,
|
|
68
|
-
maxValidators: 50,
|
|
69
87
|
maxRetries: 3,
|
|
70
88
|
messageThreshold: 3,
|
|
71
89
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
@@ -77,34 +95,45 @@ const configData = {
|
|
|
77
95
|
maxParallel: 64, // Connectivity constants
|
|
78
96
|
maxServerConnections: Infinity, // Connectivity constants
|
|
79
97
|
maxClientConnections: Infinity, // Connectivity constants
|
|
80
|
-
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
81
98
|
processIntervalMs: 50, // Pool constants
|
|
82
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
83
99
|
transactionPoolSize: 1000, // Operation handler constants
|
|
84
100
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
85
101
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
86
102
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
103
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
104
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
105
|
+
txCommitTimeout: 2200,
|
|
106
|
+
txPoolSize: 1000, // size of transaction pool
|
|
107
|
+
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
87
108
|
storesDirectory: 'stores/',
|
|
88
109
|
storeName: 'mainnet',
|
|
89
110
|
},
|
|
90
111
|
[ENV.DEVELOPMENT]: {
|
|
112
|
+
debug: false,
|
|
91
113
|
addressLength: 63,
|
|
92
114
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
93
115
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
94
116
|
bech32mHrpLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length + 1, // len(addressPrefix + separator)
|
|
95
|
-
bootstrap: '
|
|
117
|
+
bootstrap: '12f7f1668eac2e691e17cbc6a53e509c5cee78cdcac562313091c64e5fd077d6',
|
|
96
118
|
channel: '12312313123123',
|
|
97
|
-
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'],
|
|
98
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
|
|
99
130
|
disableRateLimit: false,
|
|
100
131
|
enableErrorApplyLogs: true,
|
|
101
132
|
enableInteractiveMode: true,
|
|
102
133
|
enableRoleRequester: false,
|
|
103
134
|
enableTxApplyLogs: true,
|
|
104
|
-
enableValidatorObserver: true,
|
|
105
135
|
enableWallet: true,
|
|
106
|
-
|
|
107
|
-
maxRetries: 0,
|
|
136
|
+
maxRetries: 3,
|
|
108
137
|
messageThreshold: 1000,
|
|
109
138
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
110
139
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
@@ -115,18 +144,21 @@ const configData = {
|
|
|
115
144
|
maxParallel: 64, // Connectivity constants
|
|
116
145
|
maxServerConnections: Infinity, // Connectivity constants
|
|
117
146
|
maxClientConnections: Infinity, // Connectivity constants
|
|
118
|
-
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
119
147
|
processIntervalMs: 50, // Pool constants
|
|
120
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
121
148
|
transactionPoolSize: 1000, // Operation handler constants
|
|
122
149
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
123
150
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
124
151
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
125
|
-
|
|
152
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
153
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
154
|
+
txCommitTimeout: 2200,
|
|
155
|
+
txPoolSize: 1000, // size of transaction pool
|
|
156
|
+
validatorHealthCheckInterval: 1_000, // How often to check validator health (ms)
|
|
157
|
+
storesDirectory: 'stores/',
|
|
126
158
|
storeName: 'development',
|
|
127
159
|
}
|
|
128
160
|
}
|
|
129
161
|
|
|
130
162
|
export const createConfig = (environment, options) => {
|
|
131
163
|
return new Config(options, configData[environment])
|
|
132
|
-
}
|
|
164
|
+
}
|
|
@@ -8,22 +8,17 @@ import NetworkMessages from './protocols/NetworkMessages.js';
|
|
|
8
8
|
import { sleep } from '../../utils/helpers.js';
|
|
9
9
|
import {
|
|
10
10
|
TRAC_NAMESPACE,
|
|
11
|
-
|
|
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
|
-
import { EventType } from '../../utils/constants.js';
|
|
17
|
-
import { networkMessageFactory } from '../../messages/network/v1/networkMessageFactory.js';
|
|
18
16
|
import TransactionRateLimiterService from './services/TransactionRateLimiterService.js';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
console.log('DEBUG [Network] ==> ', ...args);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
17
|
+
import PendingRequestService from './services/PendingRequestService.js';
|
|
18
|
+
import TransactionCommitService from "./services/TransactionCommitService.js";
|
|
19
|
+
import ValidatorHealthCheckService from './services/ValidatorHealthCheckService.js';
|
|
20
|
+
import { Logger } from '../../utils/logger.js';
|
|
21
|
+
import { WalletProvider } from 'trac-wallet';
|
|
27
22
|
|
|
28
23
|
const wakeup = new w();
|
|
29
24
|
|
|
@@ -35,11 +30,15 @@ class Network extends ReadyResource {
|
|
|
35
30
|
#validatorConnectionManager;
|
|
36
31
|
#validatorMessageOrchestrator;
|
|
37
32
|
#config;
|
|
38
|
-
#identityProvider = null;
|
|
39
33
|
#pendingConnections;
|
|
40
34
|
#connectTimeoutMs;
|
|
41
35
|
#maxPendingConnections;
|
|
42
36
|
#rateLimiter;
|
|
37
|
+
#pendingRequestsService;
|
|
38
|
+
#transactionCommitService;
|
|
39
|
+
#wallet;
|
|
40
|
+
#validatorHealthCheckService;
|
|
41
|
+
#logger;
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* @param {State} state
|
|
@@ -52,11 +51,13 @@ class Network extends ReadyResource {
|
|
|
52
51
|
this.#connectTimeoutMs = config.connectTimeoutMs || 5000;
|
|
53
52
|
this.#maxPendingConnections = config.maxPendingConnections || 50;
|
|
54
53
|
this.#pendingConnections = new Map();
|
|
55
|
-
this.#
|
|
54
|
+
this.#transactionCommitService = new TransactionCommitService(this.#config);
|
|
55
|
+
this.#transactionPoolService = new TransactionPoolService(state, address, this.#transactionCommitService ,this.#config);
|
|
56
56
|
this.#validatorObserverService = new ValidatorObserverService(this, state, address, this.#config);
|
|
57
57
|
this.#validatorConnectionManager = new ConnectionManager(this.#config);
|
|
58
58
|
this.#validatorMessageOrchestrator = new MessageOrchestrator(this.#validatorConnectionManager, state, this.#config);
|
|
59
|
-
|
|
59
|
+
this.#pendingRequestsService = new PendingRequestService(this.#config);
|
|
60
|
+
this.#logger = new Logger(this.#config);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
get swarm() {
|
|
@@ -80,7 +81,7 @@ class Network extends ReadyResource {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
async _open() {
|
|
83
|
-
|
|
84
|
+
this.#logger.info('Network initialization...');
|
|
84
85
|
|
|
85
86
|
this.setupNetworkListeners();
|
|
86
87
|
|
|
@@ -89,15 +90,19 @@ class Network extends ReadyResource {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
async _close() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.transactionPoolService.stopPool();
|
|
93
|
+
this.#logger.info('Network: closing gracefully...');
|
|
94
|
+
await this.transactionPoolService.stopPool();
|
|
95
95
|
await sleep(100);
|
|
96
|
-
this.#validatorObserverService.stopValidatorObserver();
|
|
96
|
+
await this.#validatorObserverService.stopValidatorObserver();
|
|
97
97
|
await sleep(5_000);
|
|
98
|
+
if (this.#validatorHealthCheckService) {
|
|
99
|
+
await this.#validatorHealthCheckService.close();
|
|
100
|
+
}
|
|
98
101
|
|
|
99
102
|
this.cleanupNetworkListeners();
|
|
100
103
|
this.cleanupPendingConnections();
|
|
104
|
+
this.#pendingRequestsService.close();
|
|
105
|
+
this.#transactionCommitService.close();
|
|
101
106
|
|
|
102
107
|
if (this.#swarm !== null) {
|
|
103
108
|
this.#swarm.destroy();
|
|
@@ -105,23 +110,41 @@ class Network extends ReadyResource {
|
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
setupNetworkListeners() {
|
|
108
|
-
// VALIDATOR_CONNECTION_TIMEOUT
|
|
109
113
|
this.on(EventType.VALIDATOR_CONNECTION_TIMEOUT, ({ publicKey, type, timeoutMs }) => {
|
|
110
|
-
|
|
114
|
+
this.#logger.debug(`Network Event: VALIDATOR_CONNECTION_TIMEOUT | PublicKey: ${publicKey} | Type: ${type} | TimeoutMs: ${timeoutMs}`);
|
|
111
115
|
this.#pendingConnections.delete(publicKey);
|
|
112
116
|
});
|
|
113
117
|
|
|
114
|
-
// VALIDATOR_CONNECTION_READY
|
|
115
118
|
this.on(EventType.VALIDATOR_CONNECTION_READY, async ({ publicKey, type, connection }) => {
|
|
116
|
-
|
|
119
|
+
this.#logger.debug(`Network Event: VALIDATOR_CONNECTION_READY | PublicKey: ${publicKey} | Type: ${type}`);
|
|
117
120
|
const { timeoutId } = this.#pendingConnections.get(publicKey);
|
|
121
|
+
|
|
118
122
|
if (!timeoutId) return;
|
|
119
123
|
|
|
120
124
|
clearTimeout(timeoutId);
|
|
121
125
|
this.#pendingConnections.delete(publicKey);
|
|
122
126
|
|
|
123
127
|
if (type === 'validator') {
|
|
124
|
-
|
|
128
|
+
try {
|
|
129
|
+
if (!connection.protocolSession.isProbed()) await connection.protocolSession.probe();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
this.#logger.debug(`failed to probe peer with publicKey ${publicKey}: ${err?.message ?? err}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.#validatorConnectionManager.addValidator(publicKey, connection);
|
|
135
|
+
|
|
136
|
+
let healthCheckSupported = false;
|
|
137
|
+
try {
|
|
138
|
+
healthCheckSupported = connection.protocolSession.isHealthCheckSupported();
|
|
139
|
+
} catch (err) {
|
|
140
|
+
this.#logger.debug(`health check support unknown for peer with publicKey ${publicKey}: ${err?.message ?? err}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (healthCheckSupported) {
|
|
144
|
+
this.#validatorHealthCheckService.start(publicKey);
|
|
145
|
+
} else {
|
|
146
|
+
this.#validatorHealthCheckService.stop(publicKey);
|
|
147
|
+
}
|
|
125
148
|
}
|
|
126
149
|
|
|
127
150
|
});
|
|
@@ -145,8 +168,10 @@ class Network extends ReadyResource {
|
|
|
145
168
|
wallet,
|
|
146
169
|
) {
|
|
147
170
|
if (!this.#swarm) {
|
|
148
|
-
const keyPair = await this
|
|
149
|
-
|
|
171
|
+
const { wallet: wrappedWallet, keyPair } = await this.#getOrGenerateWallet(store, wallet);
|
|
172
|
+
this.#wallet = wrappedWallet
|
|
173
|
+
this.#validatorMessageOrchestrator.setWallet(this.#wallet);
|
|
174
|
+
|
|
150
175
|
this.#swarm = new Hyperswarm({
|
|
151
176
|
keyPair,
|
|
152
177
|
bootstrap: this.#config.dhtBootstrap,
|
|
@@ -159,14 +184,18 @@ class Network extends ReadyResource {
|
|
|
159
184
|
this.#rateLimiter = new TransactionRateLimiterService(this.#swarm, this.#config);
|
|
160
185
|
this.#networkMessages = new NetworkMessages(
|
|
161
186
|
state,
|
|
162
|
-
|
|
187
|
+
this.#wallet,
|
|
163
188
|
this.#rateLimiter,
|
|
164
189
|
this.#transactionPoolService,
|
|
165
|
-
this.#
|
|
190
|
+
this.#pendingRequestsService,
|
|
191
|
+
this.#transactionCommitService,
|
|
166
192
|
this.#config
|
|
167
193
|
);
|
|
194
|
+
this.#validatorHealthCheckService = new ValidatorHealthCheckService(this.#config);
|
|
195
|
+
await this.#validatorHealthCheckService.ready();
|
|
196
|
+
this.#validatorConnectionManager.subscribeToHealthChecks(this.#validatorHealthCheckService);
|
|
168
197
|
|
|
169
|
-
|
|
198
|
+
this.#logger.info(`Channel: ${b4a.toString(this.#config.channel)}`);
|
|
170
199
|
|
|
171
200
|
this.#swarm.on('connection', async (connection) => {
|
|
172
201
|
// Per-peer connection initialization:
|
|
@@ -185,12 +214,20 @@ class Network extends ReadyResource {
|
|
|
185
214
|
}
|
|
186
215
|
|
|
187
216
|
connection.on('close', () => {
|
|
217
|
+
this.#pendingRequestsService.rejectPendingRequestsForPeer(
|
|
218
|
+
publicKey,
|
|
219
|
+
new Error('Connection closed before response')
|
|
220
|
+
);
|
|
188
221
|
this.#swarm.leavePeer(connection.remotePublicKey);
|
|
189
222
|
this.#validatorConnectionManager.remove(publicKey);
|
|
190
223
|
connection.protocolSession.close();
|
|
191
224
|
});
|
|
192
225
|
|
|
193
226
|
connection.on('error', (error) => {
|
|
227
|
+
this.#pendingRequestsService.rejectPendingRequestsForPeer(
|
|
228
|
+
publicKey,
|
|
229
|
+
error ?? new Error('Connection error before response')
|
|
230
|
+
);
|
|
194
231
|
if (
|
|
195
232
|
error && error.message && (
|
|
196
233
|
error.message.includes('connection reset by peer') ||
|
|
@@ -200,7 +237,7 @@ class Network extends ReadyResource {
|
|
|
200
237
|
// TODO: decide if we want to handle this error in a specific way. It generates a lot of logs.
|
|
201
238
|
return;
|
|
202
239
|
}
|
|
203
|
-
|
|
240
|
+
this.#logger.error(error?.message ?? 'Unknown network connection error');
|
|
204
241
|
});
|
|
205
242
|
|
|
206
243
|
});
|
|
@@ -218,22 +255,44 @@ class Network extends ReadyResource {
|
|
|
218
255
|
return this.#pendingConnections.size;
|
|
219
256
|
}
|
|
220
257
|
|
|
221
|
-
|
|
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) {
|
|
222
281
|
if (!this.#config.enableWallet) {
|
|
223
|
-
|
|
282
|
+
const keyPair = await store.createKeyPair(TRAC_NAMESPACE);
|
|
283
|
+
const wallet = await new WalletProvider(this.#config).fromSecretKey(keyPair.secretKey)
|
|
284
|
+
return { keyPair, wallet }
|
|
224
285
|
} else {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
secretKey: wallet.secretKey
|
|
228
|
-
};
|
|
286
|
+
const keyPair = { publicKey: wallet.publicKey, secretKey: wallet.secretKey }
|
|
287
|
+
return { keyPair, wallet }
|
|
229
288
|
}
|
|
230
289
|
}
|
|
231
290
|
|
|
232
291
|
async tryConnect(publicKey, type = null) {
|
|
233
292
|
if (this.#swarm === null) throw new Error('Network swarm is not initialized');
|
|
234
293
|
if (this.#pendingConnections.has(publicKey) || this.#pendingConnections.size >= this.#maxPendingConnections) {
|
|
235
|
-
|
|
236
|
-
return;
|
|
294
|
+
this.#logger.debug(`Network.tryConnect: Connection to peer: ${publicKey} as type: ${type} is already pending or max pending connections reached.`);
|
|
295
|
+
return CONNECTION_STATUS.IGNORED;
|
|
237
296
|
}
|
|
238
297
|
|
|
239
298
|
const timeoutId = setTimeout(() => {
|
|
@@ -250,35 +309,41 @@ class Network extends ReadyResource {
|
|
|
250
309
|
const peerInfo = this.#swarm.peers.get(publicKey);
|
|
251
310
|
if (peerInfo) {
|
|
252
311
|
const connection = this.#swarm._allConnections.get(peerInfo.publicKey);
|
|
253
|
-
|
|
312
|
+
|
|
313
|
+
if (connection &&
|
|
314
|
+
connection.protocolSession &&
|
|
315
|
+
!this.#pendingRequestsService.isProbePending(connection.remotePublicKey.toString('hex'))
|
|
316
|
+
) {
|
|
254
317
|
await this.#finalizeConnection(publicKey, type, connection);
|
|
318
|
+
return CONNECTION_STATUS.CONNECTED;
|
|
255
319
|
}
|
|
256
320
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
async isConnected(publicKey) {
|
|
260
|
-
return this.#swarm.peers.has(publicKey) &&
|
|
261
|
-
this.#swarm.peers.get(publicKey).connectedTime != -1
|
|
321
|
+
|
|
322
|
+
return CONNECTION_STATUS.PENDING;
|
|
262
323
|
}
|
|
263
324
|
|
|
264
325
|
async #finalizeConnection(publicKey, type, connection) {
|
|
265
326
|
if (!this.#pendingConnections.has(publicKey)) return;
|
|
266
327
|
this.emit(EventType.VALIDATOR_CONNECTION_READY, { publicKey, type, connection });
|
|
267
|
-
|
|
328
|
+
this.#logger.debug(`Network.finalizeConnection: Connected to peer: ${publicKey} as type: ${type}`);
|
|
268
329
|
}
|
|
269
330
|
|
|
270
|
-
#
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
wallet,
|
|
275
|
-
keyPair,
|
|
276
|
-
networkPrefix: this.#config.addressPrefix
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
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;
|
|
280
335
|
}
|
|
281
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
|
+
}
|
|
282
347
|
}
|
|
283
348
|
|
|
284
349
|
export default Network;
|
|
@@ -9,8 +9,8 @@ class LegacyProtocol extends ProtocolInterface {
|
|
|
9
9
|
#config;
|
|
10
10
|
#router;
|
|
11
11
|
|
|
12
|
-
constructor(router, connection, config) {
|
|
13
|
-
super(router, connection, config);
|
|
12
|
+
constructor(router, connection, pendingRequestServiceInstance = null, config) {
|
|
13
|
+
super(router, connection, pendingRequestServiceInstance, config);
|
|
14
14
|
this.#config = config;
|
|
15
15
|
this.#router = router;
|
|
16
16
|
this.init(connection);
|
|
@@ -41,20 +41,30 @@ class LegacyProtocol extends ProtocolInterface {
|
|
|
41
41
|
this.#session = this.#channel.addMessage({
|
|
42
42
|
encoding: c.json,
|
|
43
43
|
onmessage: async (incomingMessage) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
this.#router.route(incomingMessage, connection).catch((err) => {
|
|
45
|
+
console.error(`LegacyProtocol: unhandled router error: ${err.message}`);
|
|
46
|
+
try {
|
|
47
|
+
connection.end();
|
|
48
|
+
} catch {
|
|
49
49
|
}
|
|
50
|
-
}
|
|
51
|
-
console.error(`NetworkMessages: Failed to handle incoming message: ${error.message}`);
|
|
52
|
-
}
|
|
50
|
+
});
|
|
53
51
|
}
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
// TODO: Legacy protocol does not require encoding. Consider removing this method after refactoring v1 and the protocol interface
|
|
56
|
+
decode(message) {
|
|
57
|
+
// No-op for legacy protocol
|
|
58
|
+
return message;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async send(message) {
|
|
62
|
+
this.sendAndForget(message);
|
|
63
|
+
// TODO: Change 'null' to an appropriate response if needed in the future
|
|
64
|
+
return Promise.resolve(null); // This is to maintain consistency with the ProtocolInterface and v1 protocol.
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
sendAndForget(message) {
|
|
58
68
|
this.#session.send(message);
|
|
59
69
|
}
|
|
60
70
|
|
|
@@ -1,47 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import b4a from 'b4a';
|
|
3
1
|
import NetworkMessageRouter from './legacy/NetworkMessageRouter.js';
|
|
4
2
|
import NetworkMessageRouterV1 from './v1/NetworkMessageRouter.js';
|
|
5
3
|
import ProtocolSession from './ProtocolSession.js';
|
|
6
4
|
import LegacyProtocol from './LegacyProtocol.js';
|
|
7
5
|
import V1Protocol from './V1Protocol.js';
|
|
6
|
+
|
|
8
7
|
class NetworkMessages {
|
|
9
8
|
#legacyMessageRouter;
|
|
10
9
|
#v1MessageRouter;
|
|
11
10
|
#config;
|
|
11
|
+
#wallet;
|
|
12
|
+
#pendingRequestsService;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
constructor(
|
|
15
|
+
state,
|
|
16
|
+
wallet,
|
|
17
|
+
rateLimiterService,
|
|
18
|
+
txPoolService,
|
|
19
|
+
pendingRequestsService,
|
|
20
|
+
transactionCommitService,
|
|
21
|
+
config
|
|
22
|
+
) {
|
|
17
23
|
this.#config = config;
|
|
18
|
-
this.#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#initializeMessageRouter(state, wallet, rateLimiterService, txPoolService, connectionManager) {
|
|
24
|
+
this.#wallet = wallet;
|
|
25
|
+
this.#pendingRequestsService = pendingRequestsService;
|
|
22
26
|
this.#legacyMessageRouter = new NetworkMessageRouter(
|
|
23
27
|
state,
|
|
24
28
|
wallet,
|
|
25
29
|
rateLimiterService,
|
|
26
30
|
txPoolService,
|
|
27
|
-
connectionManager,
|
|
28
31
|
this.#config
|
|
29
32
|
);
|
|
30
|
-
|
|
33
|
+
|
|
34
|
+
this.#v1MessageRouter = new NetworkMessageRouterV1(
|
|
35
|
+
state,
|
|
36
|
+
wallet,
|
|
37
|
+
rateLimiterService,
|
|
38
|
+
txPoolService,
|
|
39
|
+
pendingRequestsService,
|
|
40
|
+
transactionCommitService,
|
|
41
|
+
this.#config
|
|
42
|
+
);
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
async setupProtomuxMessages(connection) {
|
|
34
46
|
// Attach a Protomux instance to this Hyperswarm connection.
|
|
35
47
|
// Protomux multiplexes multiple logical protocol channels over a single encrypted stream.
|
|
36
48
|
|
|
37
|
-
const legacyProtocol = new LegacyProtocol(
|
|
38
|
-
|
|
49
|
+
const legacyProtocol = new LegacyProtocol(
|
|
50
|
+
this.#legacyMessageRouter,
|
|
51
|
+
connection,
|
|
52
|
+
null,
|
|
53
|
+
this.#config
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const v1Protocol = new V1Protocol(
|
|
57
|
+
this.#v1MessageRouter,
|
|
58
|
+
connection,
|
|
59
|
+
this.#pendingRequestsService,
|
|
60
|
+
this.#config
|
|
61
|
+
);
|
|
39
62
|
|
|
40
63
|
// ProtocolSession is attached to the Hyperswarm connection so other parts of the system (e.g. tryConnect)
|
|
41
64
|
// can send messages without knowing how Protomux was initialized.
|
|
42
|
-
|
|
43
|
-
connection.protocolSession = protocolSession;
|
|
44
|
-
|
|
65
|
+
connection.protocolSession = new ProtocolSession(legacyProtocol, v1Protocol, this.#wallet, this.#config);
|
|
45
66
|
}
|
|
46
67
|
}
|
|
47
68
|
|