trac-msb 0.2.15 → 0.2.16
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/package.json +9 -4
- package/proto/network/v1/enums/message_type.proto +16 -0
- package/proto/network/v1/enums/result_code.proto +84 -0
- package/proto/network/v1/messages/broadcast_transaction_request.proto +9 -0
- package/proto/network/v1/messages/broadcast_transaction_response.proto +13 -0
- package/proto/network/v1/messages/liveness_request.proto +8 -0
- package/proto/network/v1/messages/liveness_response.proto +11 -0
- package/proto/network/v1/network_message.proto +22 -0
- package/rpc/rpc_services.js +22 -4
- package/scripts/generate-protobufs.js +37 -12
- package/src/config/config.js +26 -5
- package/src/config/env.js +25 -11
- package/src/core/network/Network.js +73 -36
- 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 +14 -2
- 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 +88 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +25 -19
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +23 -12
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +6 -6
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +18 -11
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +28 -17
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +17 -11
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +27 -0
- 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} +47 -25
- 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} +26 -9
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +91 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +65 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +389 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +87 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +211 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +276 -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 +146 -94
- package/src/core/network/services/MessageOrchestrator.js +151 -27
- package/src/core/network/services/PendingRequestService.js +172 -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 +52 -34
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +18 -26
- package/src/core/state/State.js +70 -19
- package/src/index.js +5 -4
- package/src/messages/network/v1/NetworkMessageBuilder.js +59 -79
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- package/src/utils/Scheduler.js +0 -8
- package/src/utils/constants.js +71 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- 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/tests/acceptance/v1/account/account.test.mjs +8 -2
- package/tests/acceptance/v1/tx/tx.test.mjs +23 -1
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +34 -6
- package/tests/fixtures/networkV1.fixtures.js +2 -28
- package/tests/helpers/transactionPayloads.mjs +2 -2
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +239 -79
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +223 -77
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +54 -0
- package/tests/unit/network/ProtocolSession.test.js +127 -0
- package/tests/unit/network/networkModule.test.js +4 -1
- package/tests/unit/network/services/ConnectionManager.test.js +450 -0
- package/tests/unit/network/services/MessageOrchestrator.test.js +445 -0
- package/tests/unit/network/services/PendingRequestService.test.js +431 -0
- package/tests/unit/network/services/TransactionCommitService.test.js +246 -0
- package/tests/unit/network/services/TransactionPoolService.test.js +489 -0
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +139 -0
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +115 -0
- package/tests/unit/network/services/services.test.js +17 -0
- package/tests/unit/network/utils/v1TestUtils.js +153 -0
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +151 -0
- package/tests/unit/network/v1/V1BaseOperation.test.js +356 -0
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +129 -0
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +53 -0
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +512 -0
- package/tests/unit/network/v1/V1LivenessRequest.test.js +32 -0
- package/tests/unit/network/v1/V1LivenessResponse.test.js +45 -0
- package/tests/unit/network/v1/V1ResultCode.test.js +84 -0
- package/tests/unit/network/v1/V1ValidationSchema.test.js +13 -0
- package/tests/unit/network/v1/connectionPolicies.test.js +49 -0
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +284 -0
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +794 -0
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +193 -0
- package/tests/unit/network/v1/v1.handlers.test.js +15 -0
- package/tests/unit/network/v1/v1.test.js +19 -0
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +119 -0
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +136 -0
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +308 -0
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +90 -0
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +133 -0
- package/tests/unit/unit.test.js +2 -2
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +102 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +2 -4
- package/tests/unit/utils/utils.test.js +1 -0
- 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/proto/network.proto +0 -74
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/unit/network/ConnectionManager.test.js +0 -191
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-msb",
|
|
3
3
|
"main": "msb.mjs",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.16",
|
|
5
5
|
"pear": {
|
|
6
6
|
"name": "trac-msb",
|
|
7
7
|
"type": "terminal"
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"test:integration": "brittle-node -t 1200000 tests/integration/integration.test.js",
|
|
19
19
|
"test:unit:node": "brittle-node -t 60000 tests/unit/unit.test.js",
|
|
20
20
|
"test:unit:bare": "brittle-bare -t 60000 tests/unit/unit.test.js",
|
|
21
|
+
"test:unit:pear": "BRITTLE='-t 60000' brittle-pear tests/unit/unit.test.js",
|
|
21
22
|
"test:unit:all": "(npm run test:unit:node && npm run test:unit:bare) || exit 1",
|
|
22
|
-
"test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js"
|
|
23
|
-
"test:unit:bare:cov": "brittle-bare -c -t 60000 tests/unit/unit.test.js"
|
|
23
|
+
"test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"autobase": "7.20.1",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"compact-encoding": "2.18.0",
|
|
36
36
|
"corestore": "7.5.0",
|
|
37
37
|
"crypto": "npm:bare-node-crypto",
|
|
38
|
+
"denque": "^2.1.0",
|
|
38
39
|
"fastest-validator": "1.19.0",
|
|
39
40
|
"http": "npm:bare-node-http",
|
|
40
41
|
"hyperbee": "2.26.5",
|
|
@@ -43,6 +44,8 @@
|
|
|
43
44
|
"hyperdht": "6.27.0",
|
|
44
45
|
"hyperswarm": "4.14.2",
|
|
45
46
|
"lodash": "^4.17.23",
|
|
47
|
+
"p-queue": "^9.1.0",
|
|
48
|
+
"protobufjs": "^7.5.4",
|
|
46
49
|
"protocol-buffers-encodings": "1.2.0",
|
|
47
50
|
"protomux": "3.10.1",
|
|
48
51
|
"protomux-wakeup": "2.4.0",
|
|
@@ -54,11 +57,13 @@
|
|
|
54
57
|
"uuid": "^13.0.0"
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
60
|
+
"bare-module": "^6.1.3",
|
|
57
61
|
"bare-os": "^3.6.1",
|
|
58
62
|
"bip39-mnemonic": "^2.4.0",
|
|
59
|
-
"brittle": "^3.
|
|
63
|
+
"brittle": "^3.19.1",
|
|
60
64
|
"esmock": "^2.7.2",
|
|
61
65
|
"jest": "^30.1.3",
|
|
66
|
+
"protobufjs-cli": "^1.2.0",
|
|
62
67
|
"protocol-buffers": "^4.2.0",
|
|
63
68
|
"sinon": "^21.0.0",
|
|
64
69
|
"supertest": "^7.1.4"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package network.v1;
|
|
4
|
+
|
|
5
|
+
// Warning: Do not change numeric values of existing enum fields.
|
|
6
|
+
// They are part of the public API.
|
|
7
|
+
// New values may be added, but existing values must never be renumbered or reused.
|
|
8
|
+
// Use [deprecated = true] while phasing out a value that still remains in the schema.
|
|
9
|
+
// If a value is removed, reserve its number (and preferably its name).
|
|
10
|
+
enum MessageType {
|
|
11
|
+
MESSAGE_TYPE_UNSPECIFIED = 0;
|
|
12
|
+
MESSAGE_TYPE_LIVENESS_REQUEST = 1;
|
|
13
|
+
MESSAGE_TYPE_LIVENESS_RESPONSE = 2;
|
|
14
|
+
MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST = 3;
|
|
15
|
+
MESSAGE_TYPE_BROADCAST_TRANSACTION_RESPONSE = 4;
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package network.v1;
|
|
4
|
+
|
|
5
|
+
// Warning: Do not change numeric values of existing enum fields.
|
|
6
|
+
// They are part of the public API.
|
|
7
|
+
// New values may be added, but existing values must never be renumbered or reused.
|
|
8
|
+
// Use [deprecated = true] while phasing out a value that still remains in the schema.
|
|
9
|
+
// If a value is removed, reserve its number (and preferably its name).
|
|
10
|
+
|
|
11
|
+
enum ResultCode {
|
|
12
|
+
// 0-10: [SCOPE: BASE_TRANSPORT_AND_VALIDATOR_STATUS]
|
|
13
|
+
// Generic V1 processing outcome before deeper payload/proof-specific validation branches.
|
|
14
|
+
RESULT_CODE_UNSPECIFIED = 0; // We should create an v1Error for this case, sender disconnects from the validator, add optional information to update the node verion.
|
|
15
|
+
RESULT_CODE_OK = 1;
|
|
16
|
+
RESULT_CODE_INVALID_PAYLOAD = 2;
|
|
17
|
+
RESULT_CODE_RATE_LIMITED = 3;
|
|
18
|
+
RESULT_CODE_SIGNATURE_INVALID = 4;
|
|
19
|
+
RESULT_CODE_UNEXPECTED_ERROR = 5;
|
|
20
|
+
RESULT_CODE_TIMEOUT = 6;
|
|
21
|
+
RESULT_CODE_NODE_HAS_NO_WRITE_ACCESS = 7;
|
|
22
|
+
RESULT_CODE_TX_ACCEPTED_PROOF_UNAVAILABLE = 8;
|
|
23
|
+
RESULT_CODE_NODE_OVERLOADED = 9;
|
|
24
|
+
RESULT_CODE_TX_ALREADY_PENDING = 10;
|
|
25
|
+
// 11-44: [SCOPE: SHARED_VALIDATORS_REQUEST_PAYLOAD]
|
|
26
|
+
// (incoming BROADCAST_TRANSACTION_REQUEST -> partial apply payload validation) - validator disconnects, sender rotates
|
|
27
|
+
RESULT_CODE_OPERATION_TYPE_UNKNOWN = 11;
|
|
28
|
+
RESULT_CODE_SCHEMA_VALIDATION_FAILED = 12;
|
|
29
|
+
RESULT_CODE_REQUESTER_ADDRESS_INVALID = 13;
|
|
30
|
+
RESULT_CODE_REQUESTER_PUBLIC_KEY_INVALID = 14;
|
|
31
|
+
RESULT_CODE_TX_HASH_MISMATCH = 15;
|
|
32
|
+
RESULT_CODE_TX_SIGNATURE_INVALID = 16;
|
|
33
|
+
RESULT_CODE_TX_EXPIRED = 17;
|
|
34
|
+
RESULT_CODE_TX_ALREADY_EXISTS = 18;
|
|
35
|
+
RESULT_CODE_OPERATION_ALREADY_COMPLETED = 19;
|
|
36
|
+
RESULT_CODE_REQUESTER_NOT_FOUND = 20;
|
|
37
|
+
RESULT_CODE_INSUFFICIENT_FEE_BALANCE = 21;
|
|
38
|
+
RESULT_CODE_EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP = 22;
|
|
39
|
+
RESULT_CODE_SELF_VALIDATION_FORBIDDEN = 23;
|
|
40
|
+
RESULT_CODE_ROLE_NODE_ENTRY_NOT_FOUND = 24;
|
|
41
|
+
RESULT_CODE_ROLE_NODE_ALREADY_WRITER = 25;
|
|
42
|
+
RESULT_CODE_ROLE_NODE_NOT_WHITELISTED = 26;
|
|
43
|
+
RESULT_CODE_ROLE_NODE_NOT_WRITER = 27;
|
|
44
|
+
RESULT_CODE_ROLE_NODE_IS_INDEXER = 28;
|
|
45
|
+
RESULT_CODE_ROLE_ADMIN_ENTRY_MISSING = 29;
|
|
46
|
+
RESULT_CODE_ROLE_INVALID_RECOVERY_CASE = 30;
|
|
47
|
+
RESULT_CODE_ROLE_UNKNOWN_OPERATION = 31;
|
|
48
|
+
RESULT_CODE_ROLE_INVALID_WRITER_KEY = 32;
|
|
49
|
+
RESULT_CODE_ROLE_INSUFFICIENT_FEE_BALANCE = 33;
|
|
50
|
+
RESULT_CODE_MSB_BOOTSTRAP_MISMATCH = 34;
|
|
51
|
+
RESULT_CODE_EXTERNAL_BOOTSTRAP_NOT_DEPLOYED = 35;
|
|
52
|
+
RESULT_CODE_EXTERNAL_BOOTSTRAP_TX_MISSING = 36;
|
|
53
|
+
RESULT_CODE_EXTERNAL_BOOTSTRAP_MISMATCH = 37;
|
|
54
|
+
RESULT_CODE_BOOTSTRAP_ALREADY_EXISTS = 38;
|
|
55
|
+
RESULT_CODE_TRANSFER_RECIPIENT_ADDRESS_INVALID = 39;
|
|
56
|
+
RESULT_CODE_TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID = 40;
|
|
57
|
+
RESULT_CODE_TRANSFER_AMOUNT_TOO_LARGE = 41;
|
|
58
|
+
RESULT_CODE_TRANSFER_SENDER_NOT_FOUND = 42;
|
|
59
|
+
RESULT_CODE_TRANSFER_INSUFFICIENT_BALANCE = 43;
|
|
60
|
+
RESULT_CODE_TRANSFER_RECIPIENT_BALANCE_OVERFLOW = 44;
|
|
61
|
+
|
|
62
|
+
// 45-47: [SCOPE: REQUEST_DISPATCH_TXPOOL_TXCOMMIT_PIPELINE]
|
|
63
|
+
// (dispatch/enqueue/commit handling on validator)
|
|
64
|
+
RESULT_CODE_TX_HASH_INVALID_FORMAT = 45;
|
|
65
|
+
RESULT_CODE_INTERNAL_ENQUEUE_VALIDATION_FAILED = 46;
|
|
66
|
+
RESULT_CODE_TX_COMMITTED_RECEIPT_MISSING = 47;
|
|
67
|
+
|
|
68
|
+
// 48-60: [SCOPE: VALIDATOR_RESPONSE_PROOF_AND_IDENTITY_VALIDATION]
|
|
69
|
+
// (incoming BROADCAST_TRANSACTION_RESPONSE validation on sender)
|
|
70
|
+
RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_INVALID = 48;
|
|
71
|
+
RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN = 49;
|
|
72
|
+
RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED = 50;
|
|
73
|
+
RESULT_CODE_VALIDATOR_RESPONSE_SCHEMA_INVALID = 51;
|
|
74
|
+
RESULT_CODE_PENDING_REQUEST_MISSING_TX_DATA = 52;
|
|
75
|
+
RESULT_CODE_PROOF_PAYLOAD_MISMATCH = 53;
|
|
76
|
+
RESULT_CODE_VALIDATOR_WRITER_KEY_NOT_REGISTERED = 54;
|
|
77
|
+
RESULT_CODE_VALIDATOR_ADDRESS_MISMATCH = 55;
|
|
78
|
+
RESULT_CODE_VALIDATOR_NODE_ENTRY_NOT_FOUND = 56;
|
|
79
|
+
RESULT_CODE_VALIDATOR_NODE_NOT_WRITER = 57;
|
|
80
|
+
RESULT_CODE_VALIDATOR_WRITER_KEY_MISMATCH = 58;
|
|
81
|
+
RESULT_CODE_VALIDATOR_TX_OBJECT_INVALID = 59;
|
|
82
|
+
RESULT_CODE_VALIDATOR_VA_MISSING = 60;
|
|
83
|
+
RESULT_CODE_TX_INVALID_PAYLOAD = 61;
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package network.v1;
|
|
4
|
+
|
|
5
|
+
import "network/v1/enums/message_type.proto";
|
|
6
|
+
import "network/v1/messages/liveness_request.proto";
|
|
7
|
+
import "network/v1/messages/liveness_response.proto";
|
|
8
|
+
import "network/v1/messages/broadcast_transaction_request.proto";
|
|
9
|
+
import "network/v1/messages/broadcast_transaction_response.proto";
|
|
10
|
+
|
|
11
|
+
message MessageHeader {
|
|
12
|
+
MessageType type = 1;
|
|
13
|
+
string id = 2;
|
|
14
|
+
uint64 timestamp = 3;
|
|
15
|
+
oneof field {
|
|
16
|
+
LivenessRequest liveness_request = 4;
|
|
17
|
+
LivenessResponse liveness_response = 5;
|
|
18
|
+
BroadcastTransactionRequest broadcast_transaction_request = 6;
|
|
19
|
+
BroadcastTransactionResponse broadcast_transaction_response = 7;
|
|
20
|
+
}
|
|
21
|
+
repeated string capabilities = 8;
|
|
22
|
+
}
|
package/rpc/rpc_services.js
CHANGED
|
@@ -6,10 +6,23 @@ import {
|
|
|
6
6
|
} from "../src/utils/normalizers.js";
|
|
7
7
|
import { get_confirmed_tx_info, get_unconfirmed_tx_info } from "../src/utils/cli.js";
|
|
8
8
|
import { OperationType } from "../src/utils/constants.js";
|
|
9
|
+
import { sleep } from "../src/utils/helpers.js";
|
|
9
10
|
import b4a from "b4a";
|
|
10
|
-
import PartialTransaction from "../src/core/network/protocols/shared/validators/PartialTransaction.js";
|
|
11
|
-
import PartialTransfer from "../src/core/network/protocols/shared/validators/PartialTransfer.js";
|
|
12
11
|
import { ValidationError, BroadcastError, NotFoundError } from "./utils/helpers.js";
|
|
12
|
+
import PartialTransactionValidator from "../src/core/network/protocols/shared/validators/PartialTransactionValidator.js";
|
|
13
|
+
import PartialTransferValidator from "../src/core/network/protocols/shared/validators/PartialTransferValidator.js";
|
|
14
|
+
|
|
15
|
+
// This was added because V1 is not waiting for signed/unsigned state. So to include reverse compatibility
|
|
16
|
+
// we need to slow down v1 to legacy case.
|
|
17
|
+
const waitForUnconfirmedTx = async (state, txHash, config) => {
|
|
18
|
+
const startedAt = Date.now();
|
|
19
|
+
while ((Date.now() - startedAt) < config.messageValidatorResponseTimeout) {
|
|
20
|
+
const payload = await state.get(txHash);
|
|
21
|
+
if (payload) return true;
|
|
22
|
+
await sleep(100);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
13
26
|
|
|
14
27
|
export async function getBalance(msbInstance, address, confirmed) {
|
|
15
28
|
const state = msbInstance.state;
|
|
@@ -54,8 +67,8 @@ export async function broadcastTransaction(msbInstance, config, payload) {
|
|
|
54
67
|
let isValid = false;
|
|
55
68
|
let hash;
|
|
56
69
|
|
|
57
|
-
const partialTransferValidator = new
|
|
58
|
-
const partialTransactionValidator = new
|
|
70
|
+
const partialTransferValidator = new PartialTransferValidator(msbInstance.state, null , config);
|
|
71
|
+
const partialTransactionValidator = new PartialTransactionValidator(msbInstance.state, null , config);
|
|
59
72
|
|
|
60
73
|
if (payload.type === OperationType.TRANSFER) {
|
|
61
74
|
normalizedPayload = normalizeTransferOperation(payload, config);
|
|
@@ -77,6 +90,11 @@ export async function broadcastTransaction(msbInstance, config, payload) {
|
|
|
77
90
|
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
78
91
|
}
|
|
79
92
|
|
|
93
|
+
const isConfirmed = await waitForUnconfirmedTx(msbInstance.state, hash, config);
|
|
94
|
+
if (!isConfirmed) {
|
|
95
|
+
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
const signedLength = msbInstance.state.getSignedLength();
|
|
81
99
|
const unsignedLength = msbInstance.state.getUnsignedLength();
|
|
82
100
|
|
|
@@ -2,10 +2,10 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import {
|
|
5
|
+
import { execFileSync } from 'child_process';
|
|
6
6
|
|
|
7
7
|
function generateCJSFromProto(inputPath, outputPath) {
|
|
8
|
-
|
|
8
|
+
execFileSync('protocol-buffers', [inputPath, '-o', outputPath]);
|
|
9
9
|
console.log(`${outputPath} has been generated.`);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -17,26 +17,51 @@ function transformToUseB4a(outputPath) {
|
|
|
17
17
|
console.log(`${outputPath} has been modified to use b4a.`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function generatePbjsModule(pbjsPath, protoRootPath, entryPath, outputPath) {
|
|
21
|
+
execFileSync(pbjsPath, [
|
|
22
|
+
'-t', 'static-module',
|
|
23
|
+
'-w', 'commonjs',
|
|
24
|
+
'--keep-case',
|
|
25
|
+
'-p', protoRootPath,
|
|
26
|
+
'-o', outputPath,
|
|
27
|
+
entryPath
|
|
28
|
+
]);
|
|
29
|
+
console.log(`${outputPath} has been generated.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function transformPbjsForBare(outputPath) {
|
|
33
|
+
let content = fs.readFileSync(outputPath, 'utf-8');
|
|
34
|
+
const shim = `if (typeof globalThis !== 'undefined' && typeof globalThis.self === 'undefined') {\n globalThis.self = globalThis;\n}\n`;
|
|
35
|
+
const strictDirective = '"use strict";';
|
|
36
|
+
|
|
37
|
+
if (content.includes(strictDirective)) {
|
|
38
|
+
content = content.replace(strictDirective, `${strictDirective}\n${shim}`);
|
|
39
|
+
} else {
|
|
40
|
+
content = `${strictDirective}\n${shim}${content}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fs.writeFileSync(outputPath, content, 'utf-8');
|
|
44
|
+
console.log(`${outputPath} has been modified for bare-compatible protobufjs runtime.`);
|
|
45
|
+
}
|
|
20
46
|
|
|
21
47
|
function main() {
|
|
22
48
|
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
|
23
49
|
|
|
24
50
|
const inputDir = path.join(directoryName, '../proto');
|
|
25
51
|
const outputDir = path.join(directoryName, '../src/utils/protobuf');
|
|
52
|
+
const pbjsPath = path.join(directoryName, '../node_modules/.bin/pbjs');
|
|
53
|
+
const applyInputPath = path.join(inputDir, 'applyOperations.proto');
|
|
54
|
+
const applyOutputPath = path.join(outputDir, 'applyOperations.cjs');
|
|
55
|
+
const networkEntryPath = path.join(inputDir, 'network/v1/network_message.proto');
|
|
56
|
+
const generatedNetworkOutputPath = path.join(outputDir, 'networkV1.generated.cjs');
|
|
26
57
|
|
|
27
58
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
28
59
|
|
|
29
|
-
|
|
60
|
+
generateCJSFromProto(applyInputPath, applyOutputPath);
|
|
61
|
+
transformToUseB4a(applyOutputPath);
|
|
30
62
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const inputPath = path.join(inputDir, file);
|
|
34
|
-
const outputPath = path.join(outputDir, `${name}.cjs`);
|
|
35
|
-
|
|
36
|
-
generateCJSFromProto(inputPath, outputPath);
|
|
37
|
-
transformToUseB4a(outputPath);
|
|
38
|
-
}
|
|
63
|
+
generatePbjsModule(pbjsPath, inputDir, networkEntryPath, generatedNetworkOutputPath);
|
|
64
|
+
transformPbjsForBare(generatedNetworkOutputPath);
|
|
39
65
|
}
|
|
40
66
|
|
|
41
67
|
main();
|
|
42
|
-
|
package/src/config/config.js
CHANGED
|
@@ -133,11 +133,6 @@ export class Config {
|
|
|
133
133
|
return this.#config.processIntervalMs
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
get maxPartialTxPayloadByteSize() {
|
|
137
|
-
if (this.#isOverriden('maxPartialTxPayloadByteSize')) return this.#options.maxPartialTxPayloadByteSize
|
|
138
|
-
return this.#config.maxPartialTxPayloadByteSize
|
|
139
|
-
}
|
|
140
|
-
|
|
141
136
|
get transactionPoolSize() {
|
|
142
137
|
if (this.#isOverriden('transactionPoolSize')) return this.#options.transactionPoolSize
|
|
143
138
|
return this.#config.transactionPoolSize
|
|
@@ -198,6 +193,31 @@ export class Config {
|
|
|
198
193
|
if (this.#isOverriden('rateLimitMaxTransactionsPerSecond')) return this.#options.rateLimitMaxTransactionsPerSecond
|
|
199
194
|
return this.#config.rateLimitMaxTransactionsPerSecond
|
|
200
195
|
}
|
|
196
|
+
|
|
197
|
+
get pendingRequestTimeout() {
|
|
198
|
+
return this.#config.pendingRequestTimeout
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
get txCommitTimeout() {
|
|
202
|
+
return this.#config.txCommitTimeout
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
get txPoolSize() {
|
|
206
|
+
return this.#config.txPoolSize
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
get validatorHealthCheckInterval() {
|
|
210
|
+
if (this.#isOverriden('validatorHealthCheckInterval')) return this.#options.validatorHealthCheckInterval
|
|
211
|
+
return this.#config.validatorHealthCheckInterval
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get maxPendingRequestsInPendingRequestsService() {
|
|
215
|
+
return this.#config.maxPendingRequestsInPendingRequestsService
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
get debug() {
|
|
219
|
+
return this.#config.debug
|
|
220
|
+
}
|
|
201
221
|
|
|
202
222
|
// Most of these properties are boolean
|
|
203
223
|
#isOverriden(prop) {
|
|
@@ -211,4 +231,5 @@ export class Config {
|
|
|
211
231
|
);
|
|
212
232
|
}
|
|
213
233
|
}
|
|
234
|
+
|
|
214
235
|
}
|
package/src/config/env.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet/constants.js';
|
|
2
|
-
import { Config } from './config.js';
|
|
3
2
|
import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
|
|
4
3
|
import { address } from 'trac-crypto-api';
|
|
4
|
+
import { Config } from './config.js';
|
|
5
5
|
|
|
6
6
|
export const ENV = {
|
|
7
7
|
MAINNET: 'mainnet',
|
|
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,
|
|
@@ -27,9 +27,9 @@ const configData = {
|
|
|
27
27
|
enableTxApplyLogs: true,
|
|
28
28
|
enableValidatorObserver: true,
|
|
29
29
|
enableWallet: true,
|
|
30
|
-
maxValidators:
|
|
31
|
-
maxRetries:
|
|
32
|
-
messageThreshold:
|
|
30
|
+
maxValidators: 50,
|
|
31
|
+
maxRetries: 3,
|
|
32
|
+
messageThreshold: 3,
|
|
33
33
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
34
34
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
35
35
|
host: 'localhost',
|
|
@@ -41,15 +41,20 @@ const configData = {
|
|
|
41
41
|
maxClientConnections: Infinity, // Connectivity constants
|
|
42
42
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
43
43
|
processIntervalMs: 50, // Pool constants
|
|
44
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
45
44
|
transactionPoolSize: 1000, // Operation handler constants
|
|
46
45
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
47
46
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
48
47
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
49
|
-
|
|
48
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
49
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
50
|
+
txCommitTimeout: 2200,
|
|
51
|
+
txPoolSize: 1000, // size of transaction pool
|
|
52
|
+
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
53
|
+
storesDirectory: 'stores/',
|
|
50
54
|
storeName: 'testnet',
|
|
51
55
|
},
|
|
52
56
|
[ENV.MAINNET]: {
|
|
57
|
+
debug: false,
|
|
53
58
|
addressLength: 63,
|
|
54
59
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
55
60
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
@@ -79,15 +84,20 @@ const configData = {
|
|
|
79
84
|
maxClientConnections: Infinity, // Connectivity constants
|
|
80
85
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
81
86
|
processIntervalMs: 50, // Pool constants
|
|
82
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
83
87
|
transactionPoolSize: 1000, // Operation handler constants
|
|
84
88
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
85
89
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
86
90
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
91
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
92
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
93
|
+
txCommitTimeout: 2200,
|
|
94
|
+
txPoolSize: 1000, // size of transaction pool
|
|
95
|
+
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
87
96
|
storesDirectory: 'stores/',
|
|
88
97
|
storeName: 'mainnet',
|
|
89
98
|
},
|
|
90
99
|
[ENV.DEVELOPMENT]: {
|
|
100
|
+
debug: true,
|
|
91
101
|
addressLength: 63,
|
|
92
102
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
93
103
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
@@ -104,7 +114,7 @@ const configData = {
|
|
|
104
114
|
enableValidatorObserver: true,
|
|
105
115
|
enableWallet: true,
|
|
106
116
|
maxValidators: 6,
|
|
107
|
-
maxRetries:
|
|
117
|
+
maxRetries: 3,
|
|
108
118
|
messageThreshold: 1000,
|
|
109
119
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
110
120
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
@@ -117,12 +127,16 @@ const configData = {
|
|
|
117
127
|
maxClientConnections: Infinity, // Connectivity constants
|
|
118
128
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
119
129
|
processIntervalMs: 50, // Pool constants
|
|
120
|
-
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
121
130
|
transactionPoolSize: 1000, // Operation handler constants
|
|
122
131
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
123
132
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
124
133
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
125
|
-
|
|
134
|
+
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
135
|
+
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
136
|
+
txCommitTimeout: 2200,
|
|
137
|
+
txPoolSize: 1000, // size of transaction pool
|
|
138
|
+
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
139
|
+
storesDirectory: 'stores/',
|
|
126
140
|
storeName: 'development',
|
|
127
141
|
}
|
|
128
142
|
}
|