trac-msb 0.2.4 → 0.2.6
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/.dockerignore +16 -0
- package/.github/workflows/acceptance-tests.yml +7 -0
- package/.github/workflows/publish.yml +40 -0
- package/.github/workflows/{CI.yml → unit-tests.yml} +1 -1
- package/README.md +175 -50
- package/docker-compose.yml +16 -0
- package/dockerfile +41 -0
- package/docs/fee_distribution.md +89 -0
- package/msb.mjs +12 -14
- package/package.json +8 -4
- package/rpc/constants.mjs +4 -1
- package/rpc/handlers.mjs +109 -66
- package/rpc/routes/v1.mjs +3 -1
- package/rpc/rpc_services.js +126 -0
- package/rpc/utils/confirmedParameter.mjs +17 -0
- package/rpc/utils/url.mjs +38 -0
- package/src/core/network/Network.js +27 -10
- package/src/core/network/identity/NetworkWalletFactory.js +78 -0
- package/src/core/network/services/ConnectionManager.js +2 -2
- package/src/core/network/services/ValidatorObserverService.js +7 -4
- package/src/core/state/State.js +28 -22
- package/src/index.js +197 -385
- package/src/utils/cliCommands.js +280 -0
- package/src/utils/constants.js +3 -1
- package/tests/acceptance/v1/account/account.test.mjs +123 -0
- package/tests/acceptance/v1/balance/balance.test.mjs +55 -0
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +111 -0
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +19 -0
- package/tests/acceptance/v1/fee/fee.test.mjs +11 -0
- package/tests/acceptance/v1/rpc.test.mjs +62 -291
- package/tests/acceptance/v1/tx/tx.test.mjs +98 -0
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +195 -0
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +72 -0
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +27 -0
- package/tests/acceptance/v1/txv/txv.test.mjs +11 -0
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +11 -0
- package/tests/helpers/StateNetworkFactory.js +157 -0
- package/tests/helpers/autobaseTestHelpers.js +369 -0
- package/tests/helpers/createTestSignature.js +12 -0
- package/tests/helpers/transactionPayloads.mjs +78 -0
- package/tests/unit/network/NetworkWalletFactory.test.js +156 -0
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +38 -0
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +273 -0
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +30 -0
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +78 -0
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +30 -0
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +68 -0
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +155 -0
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +39 -0
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +167 -0
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +21 -0
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +21 -0
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +186 -0
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +445 -0
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +32 -0
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +297 -0
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +41 -0
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +32 -0
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +149 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +757 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +50 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +37 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +42 -0
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +105 -0
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +54 -0
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +54 -0
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +309 -0
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +30 -0
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +866 -0
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +439 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +78 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +98 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +66 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +55 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +103 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +60 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +191 -0
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +220 -0
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +82 -0
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +106 -0
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +45 -0
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +81 -0
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +189 -0
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +155 -0
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +36 -0
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +534 -0
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +74 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +32 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +38 -0
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +91 -0
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +266 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +142 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +26 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +94 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +37 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +86 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +344 -0
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +57 -0
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +429 -0
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +119 -0
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +130 -0
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +93 -0
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +108 -0
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +126 -0
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +120 -0
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +50 -0
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +56 -0
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +52 -0
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +197 -0
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +52 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +15 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +15 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +40 -0
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +114 -0
- package/tests/unit/state/apply/common/commonScenarioHelper.js +103 -0
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +36 -0
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +36 -0
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +29 -0
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +66 -0
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +84 -0
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +47 -0
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +85 -0
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +52 -0
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +49 -0
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +73 -0
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +71 -0
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +31 -0
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +142 -0
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +87 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +70 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +72 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +36 -0
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +44 -0
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +25 -0
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +98 -0
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +201 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +17 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +44 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +19 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +18 -0
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +314 -0
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +18 -0
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +43 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +53 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +24 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +197 -0
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +161 -0
- package/tests/unit/state/apply/missing-tests.md +18 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +58 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +98 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +167 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +428 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +22 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +20 -0
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +291 -0
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +87 -0
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +38 -0
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +32 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +344 -0
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +113 -0
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +33 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +26 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +22 -0
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +307 -0
- package/tests/unit/state/apply/state.apply.test.js +24 -0
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +819 -0
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +22 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +137 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +63 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +67 -0
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +22 -0
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +8 -0
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +66 -0
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +1167 -0
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +38 -0
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +318 -0
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +70 -0
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +23 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +48 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +39 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +46 -0
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +21 -0
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +429 -0
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +21 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +27 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +18 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +17 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +31 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +49 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +92 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +28 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +29 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +28 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +17 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +33 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +18 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +27 -0
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +21 -0
- package/tests/unit/state/stateModule.test.js +1 -0
- package/tests/unit/state/stateTestUtils.js +5 -1
- package/.env +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_VALIDATORS } from "../../../utils/constants.js"
|
|
1
|
+
import { MAX_VALIDATORS, MAX_REQUEST_COUNT } from "../../../utils/constants.js"
|
|
2
2
|
import b4a from 'b4a'
|
|
3
3
|
import PeerWallet from "trac-wallet"
|
|
4
4
|
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
@@ -19,7 +19,7 @@ class ConnectionManager {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
send(message, retries = 3) {
|
|
22
|
-
if (this.#requestCount >=
|
|
22
|
+
if (this.#requestCount >= MAX_REQUEST_COUNT) {
|
|
23
23
|
this.#requestCount = 0
|
|
24
24
|
this.#updateNext()
|
|
25
25
|
}
|
|
@@ -10,7 +10,6 @@ const DELAY_INTERVAL = 250
|
|
|
10
10
|
|
|
11
11
|
class ValidatorObserverService {
|
|
12
12
|
#enable_validator_observer;
|
|
13
|
-
#enable_wallet;
|
|
14
13
|
#state;
|
|
15
14
|
#network;
|
|
16
15
|
#scheduler;
|
|
@@ -18,7 +17,7 @@ class ValidatorObserverService {
|
|
|
18
17
|
#isInterrupted
|
|
19
18
|
|
|
20
19
|
constructor(network, state, address, options = {}) {
|
|
21
|
-
this.#
|
|
20
|
+
this.#enable_validator_observer = options.enable_validator_observer !== false;
|
|
22
21
|
this.#network = network;
|
|
23
22
|
this.#state = state;
|
|
24
23
|
this.#address = address;
|
|
@@ -34,7 +33,7 @@ class ValidatorObserverService {
|
|
|
34
33
|
// OS CALLS, ACCUMULATORS, MAYBE THIS IS POSSIBLE TO CHECK I/O QUEUE IF IT COINTAIN IT. FOR NOW WE ARE USING SLEEP.
|
|
35
34
|
async start() {
|
|
36
35
|
if (!this.#shouldRun()) {
|
|
37
|
-
console.info('ValidatorObserverService can not start.
|
|
36
|
+
console.info('ValidatorObserverService can not start. Disabled by configuration.');
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
39
|
if (this.#scheduler && this.#scheduler.isRunning) {
|
|
@@ -111,7 +110,11 @@ class ValidatorObserverService {
|
|
|
111
110
|
};
|
|
112
111
|
|
|
113
112
|
#shouldRun() {
|
|
114
|
-
|
|
113
|
+
if (!this.#enable_validator_observer || this.#isInterrupted) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return true;
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
async #lengthEntry() {
|
package/src/core/state/State.js
CHANGED
|
@@ -74,7 +74,7 @@ class State extends ReadyResource {
|
|
|
74
74
|
bigBatches: false,
|
|
75
75
|
optimistic: false,
|
|
76
76
|
open: this.#setupHyperbee.bind(this),
|
|
77
|
-
apply: this
|
|
77
|
+
apply: this.applyHandler,
|
|
78
78
|
})
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -90,6 +90,10 @@ class State extends ReadyResource {
|
|
|
90
90
|
return this.#bootstrap;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
get applyHandler() {
|
|
94
|
+
return this.#apply.bind(this);
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
async _open() {
|
|
94
98
|
console.log("State initialization...")
|
|
95
99
|
await this.#base.ready();
|
|
@@ -259,7 +263,7 @@ class State extends ReadyResource {
|
|
|
259
263
|
// Retrieve the flag to verify if initialization is allowed
|
|
260
264
|
let initialization = await this.getSigned(EntryType.INITIALIZATION);
|
|
261
265
|
|
|
262
|
-
if (
|
|
266
|
+
if (initialization === null) {
|
|
263
267
|
return false
|
|
264
268
|
} else {
|
|
265
269
|
return b4a.equals(initialization, safeWriteUInt32BE(0, 0))
|
|
@@ -397,7 +401,7 @@ class State extends ReadyResource {
|
|
|
397
401
|
}
|
|
398
402
|
if (invalidOperations > 0) {
|
|
399
403
|
await this.#validatorPenaltyApply(batchInvoker, batch, base, invalidOperations);
|
|
400
|
-
|
|
404
|
+
this.#safeLogApply(`Applied with ${invalidOperations} invalid operations.`)
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
await batch.flush();
|
|
@@ -999,7 +1003,7 @@ class State extends ReadyResource {
|
|
|
999
1003
|
// charging fee from the requester (admin)
|
|
1000
1004
|
const decodedAdminNodeEntry = nodeEntryUtils.decode(newAdminNodeEntry)
|
|
1001
1005
|
if (decodedAdminNodeEntry === null) {
|
|
1002
|
-
this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode
|
|
1006
|
+
this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode node entry.", node.from.key)
|
|
1003
1007
|
return Status.FAILURE;
|
|
1004
1008
|
}
|
|
1005
1009
|
|
|
@@ -1532,7 +1536,7 @@ class State extends ReadyResource {
|
|
|
1532
1536
|
// Charging fee from the requester
|
|
1533
1537
|
const requesterBalance = toBalance(decodedRequesterNodeEntry.balance)
|
|
1534
1538
|
if (requesterBalance === null) {
|
|
1535
|
-
this.#safeLogApply(OperationType.ADD_WRITER, "
|
|
1539
|
+
this.#safeLogApply(OperationType.ADD_WRITER, "Invalid requester balance.", node.from.key)
|
|
1536
1540
|
return null;
|
|
1537
1541
|
};
|
|
1538
1542
|
|
|
@@ -1543,7 +1547,7 @@ class State extends ReadyResource {
|
|
|
1543
1547
|
|
|
1544
1548
|
const updatedBalance = requesterBalance.sub(BALANCE_FEE) // Remove the fee
|
|
1545
1549
|
if (updatedBalance === null) {
|
|
1546
|
-
this.#safeLogApply(OperationType.ADD_WRITER, "Failed to apply fee to
|
|
1550
|
+
this.#safeLogApply(OperationType.ADD_WRITER, "Failed to apply fee to requester balance.", node.from.key)
|
|
1547
1551
|
return null;
|
|
1548
1552
|
};
|
|
1549
1553
|
|
|
@@ -1834,7 +1838,7 @@ class State extends ReadyResource {
|
|
|
1834
1838
|
};
|
|
1835
1839
|
const chargedNodeEntry = updatedBalance.update(updatedNodeEntry);
|
|
1836
1840
|
if (chargedNodeEntry === null) {
|
|
1837
|
-
this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to update node
|
|
1841
|
+
this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to update node balance.", node.from.key)
|
|
1838
1842
|
return null;
|
|
1839
1843
|
};
|
|
1840
1844
|
|
|
@@ -2009,7 +2013,7 @@ class State extends ReadyResource {
|
|
|
2009
2013
|
|
|
2010
2014
|
const pretenderNodeEntry = await this.#getEntryApply(pretendingAddressString, batch);
|
|
2011
2015
|
if (pretenderNodeEntry === null) {
|
|
2012
|
-
this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to verify
|
|
2016
|
+
this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to verify target indexer entry.", node.from.key)
|
|
2013
2017
|
return null;
|
|
2014
2018
|
};
|
|
2015
2019
|
|
|
@@ -2074,7 +2078,7 @@ class State extends ReadyResource {
|
|
|
2074
2078
|
// 100% fee charged from admin will be burned
|
|
2075
2079
|
const newAdminBalance = adminBalance.sub(feeAmount);
|
|
2076
2080
|
if (newAdminBalance === null) {
|
|
2077
|
-
this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to apply fee to requester balance", node.from.key)
|
|
2081
|
+
this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to apply fee to requester balance.", node.from.key)
|
|
2078
2082
|
return null;
|
|
2079
2083
|
};
|
|
2080
2084
|
|
|
@@ -2280,7 +2284,7 @@ class State extends ReadyResource {
|
|
|
2280
2284
|
// 100% fee will be burned
|
|
2281
2285
|
const newAdminBalance = adminBalance.sub(BALANCE_FEE)
|
|
2282
2286
|
if (newAdminBalance === null) {
|
|
2283
|
-
this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to apply fee to requester balance", node.from.key)
|
|
2287
|
+
this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to apply fee to requester balance.", node.from.key)
|
|
2284
2288
|
return null;
|
|
2285
2289
|
};
|
|
2286
2290
|
|
|
@@ -2793,13 +2797,13 @@ class State extends ReadyResource {
|
|
|
2793
2797
|
// validate invoker signature
|
|
2794
2798
|
const requesterAddressBuffer = op.address;
|
|
2795
2799
|
const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
2796
|
-
if (
|
|
2800
|
+
if (requesterAddressString === null) {
|
|
2797
2801
|
this.#safeLogApply(OperationType.TX, "Invalid requester address.", node.from.key)
|
|
2798
2802
|
return Status.FAILURE;
|
|
2799
2803
|
};
|
|
2800
2804
|
|
|
2801
2805
|
const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
|
|
2802
|
-
if (
|
|
2806
|
+
if (requesterPublicKey === null) {
|
|
2803
2807
|
this.#safeLogApply(OperationType.TX, "Failed to decode requester public key.", node.from.key)
|
|
2804
2808
|
return Status.FAILURE;
|
|
2805
2809
|
};
|
|
@@ -2834,13 +2838,13 @@ class State extends ReadyResource {
|
|
|
2834
2838
|
//second signature
|
|
2835
2839
|
const validatorAddressBuffer = op.txo.va;
|
|
2836
2840
|
const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer);
|
|
2837
|
-
if (
|
|
2841
|
+
if (validatorAddressString === null) {
|
|
2838
2842
|
this.#safeLogApply(OperationType.TX, "Invalid validator address.", node.from.key)
|
|
2839
2843
|
return Status.FAILURE;
|
|
2840
2844
|
};
|
|
2841
2845
|
|
|
2842
2846
|
const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
|
|
2843
|
-
if (
|
|
2847
|
+
if (validatorPublicKey === null) {
|
|
2844
2848
|
this.#safeLogApply(OperationType.TX, "Failed to decode validator public key.", node.from.key)
|
|
2845
2849
|
return Status.FAILURE;
|
|
2846
2850
|
};
|
|
@@ -2899,7 +2903,7 @@ class State extends ReadyResource {
|
|
|
2899
2903
|
// point to payload, which is pointing to the txHash.
|
|
2900
2904
|
const bootstrapHasBeenRegistered = await this.#getDeploymentEntryApply(op.txo.bs.toString('hex'), batch);
|
|
2901
2905
|
if (bootstrapHasBeenRegistered === null) {
|
|
2902
|
-
this.#safeLogApply(OperationType.TX, "Bootstrap
|
|
2906
|
+
this.#safeLogApply(OperationType.TX, "Bootstrap has not been registered.", node.from.key)
|
|
2903
2907
|
return Status.FAILURE;
|
|
2904
2908
|
};
|
|
2905
2909
|
|
|
@@ -2931,7 +2935,8 @@ class State extends ReadyResource {
|
|
|
2931
2935
|
batch,
|
|
2932
2936
|
node
|
|
2933
2937
|
);
|
|
2934
|
-
|
|
2938
|
+
|
|
2939
|
+
// TODO: cover next 4 guards below with tests
|
|
2935
2940
|
if (transferFeeTxOperationResult === null) {
|
|
2936
2941
|
this.#safeLogApply(OperationType.TX, "Fee transfer operation failed completely.", node.from.key);
|
|
2937
2942
|
return Status.FAILURE;
|
|
@@ -3148,7 +3153,7 @@ class State extends ReadyResource {
|
|
|
3148
3153
|
};
|
|
3149
3154
|
|
|
3150
3155
|
if (!isSelfTransfer) {
|
|
3151
|
-
if (
|
|
3156
|
+
if (transferResult.recipientEntry === null) {
|
|
3152
3157
|
this.#safeLogApply(OperationType.TRANSFER, "Invalid recipient entry.", node.from.key)
|
|
3153
3158
|
return Status.FAILURE;
|
|
3154
3159
|
};
|
|
@@ -3401,7 +3406,7 @@ class State extends ReadyResource {
|
|
|
3401
3406
|
async #isApplyInitalizationDisabled(batch) {
|
|
3402
3407
|
// Retrieve the flag to verify if initialization is allowed
|
|
3403
3408
|
let initialization = await this.#getEntryApply(EntryType.INITIALIZATION, batch);
|
|
3404
|
-
if (
|
|
3409
|
+
if (initialization === null) {
|
|
3405
3410
|
return false
|
|
3406
3411
|
} else {
|
|
3407
3412
|
return b4a.equals(initialization, safeWriteUInt32BE(0, 0))
|
|
@@ -3412,7 +3417,7 @@ class State extends ReadyResource {
|
|
|
3412
3417
|
// Retrieve and increment the writers length entry
|
|
3413
3418
|
let length = await this.#getEntryApply(EntryType.WRITERS_LENGTH, batch);
|
|
3414
3419
|
let incrementedLength = null;
|
|
3415
|
-
if (
|
|
3420
|
+
if (length === null) {
|
|
3416
3421
|
// Initialize the writers length entry if it does not exist
|
|
3417
3422
|
const bufferedLength = lengthEntryUtils.init(0);
|
|
3418
3423
|
length = lengthEntryUtils.decodeBE(bufferedLength);
|
|
@@ -3596,8 +3601,8 @@ class State extends ReadyResource {
|
|
|
3596
3601
|
return;
|
|
3597
3602
|
}
|
|
3598
3603
|
|
|
3599
|
-
const deductedStakedBalance = penalty.greaterThanOrEquals(stakedBalance) ? BALANCE_ZERO : stakedBalance.sub(penalty);
|
|
3600
|
-
|
|
3604
|
+
const deductedStakedBalance = penalty.greaterThanOrEquals(stakedBalance) ? BALANCE_ZERO : stakedBalance.sub(penalty);
|
|
3605
|
+
|
|
3601
3606
|
if (deductedStakedBalance === null) {
|
|
3602
3607
|
this.#safeLogApply("ValidatorPenalty", `Failed to subtract penalty from staked balance for validator address: ${validatorAddressString}`, writingKeyBuffer);
|
|
3603
3608
|
return;
|
|
@@ -3668,7 +3673,7 @@ class State extends ReadyResource {
|
|
|
3668
3673
|
async #applyAssignNewLicense(batch) {
|
|
3669
3674
|
let licenseCount = await this.#applyGetLicenseCount(batch)
|
|
3670
3675
|
let newLicenseLength;
|
|
3671
|
-
if (
|
|
3676
|
+
if (licenseCount === null) {
|
|
3672
3677
|
// Initialize the writers length entry if it does not exist
|
|
3673
3678
|
const bufferedLength = lengthEntryUtils.init(0);
|
|
3674
3679
|
licenseCount = lengthEntryUtils.decodeBE(bufferedLength);
|
|
@@ -3841,6 +3846,7 @@ class State extends ReadyResource {
|
|
|
3841
3846
|
subnetworkCreatorEntry: updatedSubnetworkCreatorNodeEntry
|
|
3842
3847
|
};
|
|
3843
3848
|
}
|
|
3849
|
+
|
|
3844
3850
|
}
|
|
3845
3851
|
|
|
3846
3852
|
export default State;
|