trac-msb 0.2.11 → 0.2.12
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/.github/workflows/acceptance-tests.yml +38 -0
- package/.github/workflows/lint-pr-title.yml +26 -0
- package/.github/workflows/publish.yml +33 -0
- package/.github/workflows/unit-tests.yml +34 -0
- package/package.json +5 -10
- package/proto/network.proto +74 -0
- package/rpc/rpc_services.js +4 -22
- package/scripts/generate-protobufs.js +12 -37
- package/src/config/config.js +5 -26
- package/src/config/env.js +11 -25
- package/src/core/network/Network.js +36 -73
- package/src/core/network/protocols/LegacyProtocol.js +11 -21
- package/src/core/network/protocols/NetworkMessages.js +17 -38
- package/src/core/network/protocols/ProtocolInterface.js +2 -14
- package/src/core/network/protocols/ProtocolSession.js +17 -144
- package/src/core/network/protocols/V1Protocol.js +18 -37
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +19 -25
- package/src/core/network/protocols/legacy/handlers/{LegacyGetRequestHandler.js → GetRequestHandler.js} +6 -6
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
- package/src/core/network/protocols/{legacy/handlers/LegacyRoleOperationHandler.js → shared/handlers/RoleOperationHandler.js} +11 -18
- package/src/core/network/protocols/{legacy/handlers/LegacySubnetworkOperationHandler.js → shared/handlers/SubnetworkOperationHandler.js} +17 -28
- package/src/core/network/protocols/{legacy/handlers/LegacyTransferOperationHandler.js → shared/handlers/TransferOperationHandler.js} +11 -17
- package/src/core/network/protocols/{legacy/handlers/BaseStateOperationHandler.js → shared/handlers/base/BaseOperationHandler.js} +12 -23
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeploymentValidator.js → PartialBootstrapDeployment.js} +4 -9
- package/src/core/network/protocols/shared/validators/{PartialRoleAccessValidator.js → PartialRoleAccess.js} +17 -51
- package/src/core/network/protocols/shared/validators/{PartialTransactionValidator.js → PartialTransaction.js} +7 -21
- package/src/core/network/protocols/shared/validators/{PartialTransferValidator.js → PartialTransfer.js} +9 -26
- package/src/core/network/protocols/shared/validators/{PartialOperationValidator.js → base/PartialOperation.js} +25 -47
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +7 -91
- package/src/core/network/services/ConnectionManager.js +94 -146
- package/src/core/network/services/MessageOrchestrator.js +27 -151
- package/src/core/network/services/TransactionPoolService.js +18 -129
- package/src/core/network/services/TransactionRateLimiterService.js +34 -52
- package/src/core/network/services/ValidatorObserverService.js +26 -18
- package/src/core/state/State.js +19 -70
- package/src/index.js +4 -5
- package/src/messages/network/v1/NetworkMessageBuilder.js +79 -59
- package/src/messages/network/v1/NetworkMessageDirector.js +50 -16
- package/src/utils/Scheduler.js +8 -0
- package/src/utils/constants.js +5 -71
- package/src/utils/helpers.js +1 -10
- package/src/utils/normalizers.js +0 -38
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +3 -24
- package/tests/acceptance/v1/account/account.test.mjs +2 -8
- package/tests/acceptance/v1/tx/tx.test.mjs +1 -23
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +6 -34
- package/tests/fixtures/networkV1.fixtures.js +28 -2
- package/tests/helpers/transactionPayloads.mjs +2 -2
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +79 -239
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +77 -223
- package/tests/unit/network/ConnectionManager.test.js +191 -0
- package/tests/unit/network/networkModule.test.js +1 -4
- package/tests/unit/unit.test.js +2 -2
- package/tests/unit/utils/protobuf/operationHelpers.test.js +4 -2
- package/tests/unit/utils/utils.test.js +0 -1
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/src/core/network/protocols/connectionPolicies.js +0 -88
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +0 -23
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/core/network/protocols/v1/V1ProtocolError.js +0 -91
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +0 -65
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +0 -389
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +0 -87
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +0 -211
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +0 -26
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +0 -276
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +0 -15
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +0 -17
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +0 -210
- package/src/core/network/services/PendingRequestService.js +0 -172
- package/src/core/network/services/TransactionCommitService.js +0 -149
- package/src/core/network/services/ValidatorHealthCheckService.js +0 -127
- package/src/utils/deepEqualApplyPayload.js +0 -40
- package/src/utils/logger.js +0 -25
- package/src/utils/protobuf/networkV1.generated.cjs +0 -2460
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: MSB-Acceptance-Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
workflow_run:
|
|
6
|
+
workflows: ["MSB-Unit-Tests"]
|
|
7
|
+
types:
|
|
8
|
+
- completed
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
integration-tests:
|
|
16
|
+
name: Acceptance Tests
|
|
17
|
+
runs-on: [self-hosted, Linux, X64]
|
|
18
|
+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
|
19
|
+
strategy:
|
|
20
|
+
matrix:
|
|
21
|
+
node-version: [ lts/* ]
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
27
|
+
uses: actions/setup-node@v3
|
|
28
|
+
with:
|
|
29
|
+
node-version: ${{ matrix.node-version }}
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: npm ci
|
|
33
|
+
|
|
34
|
+
- name: Install bare
|
|
35
|
+
run: npm i -g bare
|
|
36
|
+
|
|
37
|
+
- name: Run Integration Tests
|
|
38
|
+
run: npm run test:acceptance
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Lint PR title
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request_target:
|
|
5
|
+
types: [opened, reopened, edited, synchronize]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
main:
|
|
9
|
+
name: Validate PR title convention
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
pull-requests: read
|
|
13
|
+
steps:
|
|
14
|
+
- uses: amannn/action-semantic-pull-request@v6.1.1
|
|
15
|
+
env:
|
|
16
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
17
|
+
with:
|
|
18
|
+
# Allow optional scopes like feat(ui): ...
|
|
19
|
+
# By default scopes are allowed (no restriction) and are optional.
|
|
20
|
+
requireScope: false
|
|
21
|
+
|
|
22
|
+
# Optional: require a non-empty subject after ": "
|
|
23
|
+
subjectPattern: ^.+$
|
|
24
|
+
subjectPatternError: |
|
|
25
|
+
The pull request title must have a non-empty subject after ": ".
|
|
26
|
+
Example: "feat: add new command"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish trac-msb to npm on release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write # Required for OIDC
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout release tag
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
ref: ${{ github.event.release.tag_name }}
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: '24'
|
|
24
|
+
registry-url: 'https://registry.npmjs.org'
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: npm ci
|
|
27
|
+
|
|
28
|
+
# unit tests are temporarily disabled because they lost stability on GH runners.
|
|
29
|
+
#- name: Run unit tests
|
|
30
|
+
# run: npm run test:unit:all
|
|
31
|
+
|
|
32
|
+
- name: Publish to npm
|
|
33
|
+
run: npm publish --access public
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: MSB-Unit-Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- '*'
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
tests:
|
|
18
|
+
runs-on: [self-hosted, Linux, X64]
|
|
19
|
+
|
|
20
|
+
strategy:
|
|
21
|
+
matrix:
|
|
22
|
+
node-version: [lts/*]
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: ${{ matrix.node-version }}
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: npm ci
|
|
31
|
+
- name: Install bare
|
|
32
|
+
run: npm i -g bare
|
|
33
|
+
- name: Run all tests
|
|
34
|
+
run: npm run test:unit:all
|
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.12",
|
|
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",
|
|
22
21
|
"test:unit:all": "(npm run test:unit:node && npm run test:unit:bare) || exit 1",
|
|
23
|
-
"test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js"
|
|
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"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"autobase": "7.20.1",
|
|
@@ -35,7 +35,6 @@
|
|
|
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",
|
|
39
38
|
"fastest-validator": "1.19.0",
|
|
40
39
|
"http": "npm:bare-node-http",
|
|
41
40
|
"hyperbee": "2.26.5",
|
|
@@ -44,25 +43,21 @@
|
|
|
44
43
|
"hyperdht": "6.27.0",
|
|
45
44
|
"hyperswarm": "4.14.2",
|
|
46
45
|
"lodash": "^4.17.23",
|
|
47
|
-
"p-queue": "^9.1.0",
|
|
48
|
-
"protobufjs": "^7.5.4",
|
|
49
46
|
"protocol-buffers-encodings": "1.2.0",
|
|
50
47
|
"protomux": "3.10.1",
|
|
51
48
|
"protomux-wakeup": "2.4.0",
|
|
52
49
|
"readline": "npm:bare-node-readline",
|
|
53
50
|
"ready-resource": "1.1.2",
|
|
54
|
-
"trac-wallet": "1.0.
|
|
51
|
+
"trac-wallet": "1.0.3",
|
|
55
52
|
"tty": "npm:bare-node-tty",
|
|
56
53
|
"uuid": "^13.0.0"
|
|
57
54
|
},
|
|
58
55
|
"devDependencies": {
|
|
59
|
-
"bare-module": "^6.1.3",
|
|
60
56
|
"bare-os": "^3.6.1",
|
|
61
57
|
"bip39-mnemonic": "^2.4.0",
|
|
62
|
-
"brittle": "^3.
|
|
58
|
+
"brittle": "^3.17.1",
|
|
63
59
|
"esmock": "^2.7.2",
|
|
64
60
|
"jest": "^30.1.3",
|
|
65
|
-
"protobufjs-cli": "^1.2.0",
|
|
66
61
|
"protocol-buffers": "^4.2.0",
|
|
67
62
|
"sinon": "^21.0.0",
|
|
68
63
|
"supertest": "^7.1.4",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package network.v1;
|
|
4
|
+
|
|
5
|
+
enum MessageType {
|
|
6
|
+
MESSAGE_TYPE_UNSPECIFIED = 0;
|
|
7
|
+
MESSAGE_TYPE_VALIDATOR_CONNECTION_REQUEST = 1;
|
|
8
|
+
MESSAGE_TYPE_VALIDATOR_CONNECTION_RESPONSE = 2;
|
|
9
|
+
MESSAGE_TYPE_LIVENESS_REQUEST = 3;
|
|
10
|
+
MESSAGE_TYPE_LIVENESS_RESPONSE = 4;
|
|
11
|
+
MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST = 5;
|
|
12
|
+
MESSAGE_TYPE_BROADCAST_TRANSACTION_RESPONSE = 6;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
enum ResultCode {
|
|
16
|
+
RESULT_CODE_UNSPECIFIED = 0;
|
|
17
|
+
RESULT_CODE_OK = 1;
|
|
18
|
+
RESULT_CODE_INVALID_PAYLOAD = 2;
|
|
19
|
+
RESULT_CODE_UNSUPPORTED_VERSION = 3;
|
|
20
|
+
RESULT_CODE_RATE_LIMITED = 4;
|
|
21
|
+
RESULT_CODE_TIMEOUT = 5;
|
|
22
|
+
RESULT_CODE_SIGNATURE_INVALID = 6;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
message ValidatorConnectionRequest {
|
|
26
|
+
string issuer_address = 1;
|
|
27
|
+
bytes nonce = 2;
|
|
28
|
+
bytes signature = 3;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
message ValidatorConnectionResponse {
|
|
32
|
+
string issuer_address = 1;
|
|
33
|
+
bytes nonce = 2;
|
|
34
|
+
bytes signature = 3;
|
|
35
|
+
ResultCode result = 4;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
message LivenessRequest {
|
|
39
|
+
bytes nonce = 1;
|
|
40
|
+
bytes signature = 2;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
message LivenessResponse {
|
|
44
|
+
bytes nonce = 1;
|
|
45
|
+
bytes signature = 2;
|
|
46
|
+
ResultCode result = 3;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
message BroadcastTransactionRequest {
|
|
50
|
+
bytes data = 1; // binary encoded payload
|
|
51
|
+
bytes nonce = 2;
|
|
52
|
+
bytes signature = 3;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
message BroadcastTransactionResponse {
|
|
56
|
+
bytes nonce = 1;
|
|
57
|
+
bytes signature = 2;
|
|
58
|
+
ResultCode result = 3;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
message MessageHeader {
|
|
62
|
+
MessageType type = 1;
|
|
63
|
+
string id = 2;
|
|
64
|
+
uint64 timestamp = 3;
|
|
65
|
+
oneof field {
|
|
66
|
+
ValidatorConnectionRequest validator_connection_request = 4;
|
|
67
|
+
ValidatorConnectionResponse validator_connection_response = 5;
|
|
68
|
+
LivenessRequest liveness_request = 6;
|
|
69
|
+
LivenessResponse liveness_response = 7;
|
|
70
|
+
BroadcastTransactionRequest broadcast_transaction_request = 8;
|
|
71
|
+
BroadcastTransactionResponse broadcast_transaction_response = 9;
|
|
72
|
+
}
|
|
73
|
+
repeated string capabilities = 10;
|
|
74
|
+
}
|
package/rpc/rpc_services.js
CHANGED
|
@@ -6,23 +6,10 @@ 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";
|
|
10
9
|
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";
|
|
11
12
|
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
|
-
};
|
|
26
13
|
|
|
27
14
|
export async function getBalance(msbInstance, address, confirmed) {
|
|
28
15
|
const state = msbInstance.state;
|
|
@@ -67,8 +54,8 @@ export async function broadcastTransaction(msbInstance, config, payload) {
|
|
|
67
54
|
let isValid = false;
|
|
68
55
|
let hash;
|
|
69
56
|
|
|
70
|
-
const partialTransferValidator = new
|
|
71
|
-
const partialTransactionValidator = new
|
|
57
|
+
const partialTransferValidator = new PartialTransfer(msbInstance.state, null, config);
|
|
58
|
+
const partialTransactionValidator = new PartialTransaction(msbInstance.state, null, config);
|
|
72
59
|
|
|
73
60
|
if (payload.type === OperationType.TRANSFER) {
|
|
74
61
|
normalizedPayload = normalizeTransferOperation(payload, config);
|
|
@@ -90,11 +77,6 @@ export async function broadcastTransaction(msbInstance, config, payload) {
|
|
|
90
77
|
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
91
78
|
}
|
|
92
79
|
|
|
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
|
-
|
|
98
80
|
const signedLength = msbInstance.state.getSignedLength();
|
|
99
81
|
const unsignedLength = msbInstance.state.getUnsignedLength();
|
|
100
82
|
|
|
@@ -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 { execSync } from 'child_process';
|
|
6
6
|
|
|
7
7
|
function generateCJSFromProto(inputPath, outputPath) {
|
|
8
|
-
|
|
8
|
+
execSync(`protocol-buffers "${inputPath}" -o "${outputPath}"`);
|
|
9
9
|
console.log(`${outputPath} has been generated.`);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -17,51 +17,26 @@ 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
|
-
}
|
|
46
20
|
|
|
47
21
|
function main() {
|
|
48
22
|
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
|
49
23
|
|
|
50
24
|
const inputDir = path.join(directoryName, '../proto');
|
|
51
25
|
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');
|
|
57
26
|
|
|
58
27
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
59
28
|
|
|
60
|
-
|
|
61
|
-
transformToUseB4a(applyOutputPath);
|
|
29
|
+
const files = fs.readdirSync(inputDir).filter(f => f.endsWith('.proto'));
|
|
62
30
|
|
|
63
|
-
|
|
64
|
-
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
const name = path.basename(file, '.proto');
|
|
33
|
+
const inputPath = path.join(inputDir, file);
|
|
34
|
+
const outputPath = path.join(outputDir, `${name}.cjs`);
|
|
35
|
+
|
|
36
|
+
generateCJSFromProto(inputPath, outputPath);
|
|
37
|
+
transformToUseB4a(outputPath);
|
|
38
|
+
}
|
|
65
39
|
}
|
|
66
40
|
|
|
67
41
|
main();
|
|
42
|
+
|
package/src/config/config.js
CHANGED
|
@@ -129,6 +129,11 @@ export class Config {
|
|
|
129
129
|
return this.#config.processIntervalMs
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
get maxPartialTxPayloadByteSize() {
|
|
133
|
+
if (this.#isOverriden('maxPartialTxPayloadByteSize')) return this.#options.maxPartialTxPayloadByteSize
|
|
134
|
+
return this.#config.maxPartialTxPayloadByteSize
|
|
135
|
+
}
|
|
136
|
+
|
|
132
137
|
get transactionPoolSize() {
|
|
133
138
|
if (this.#isOverriden('transactionPoolSize')) return this.#options.transactionPoolSize
|
|
134
139
|
return this.#config.transactionPoolSize
|
|
@@ -189,31 +194,6 @@ export class Config {
|
|
|
189
194
|
if (this.#isOverriden('rateLimitMaxTransactionsPerSecond')) return this.#options.rateLimitMaxTransactionsPerSecond
|
|
190
195
|
return this.#config.rateLimitMaxTransactionsPerSecond
|
|
191
196
|
}
|
|
192
|
-
|
|
193
|
-
get pendingRequestTimeout() {
|
|
194
|
-
return this.#config.pendingRequestTimeout
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
get txCommitTimeout() {
|
|
198
|
-
return this.#config.txCommitTimeout
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
get txPoolSize() {
|
|
202
|
-
return this.#config.txPoolSize
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
get validatorHealthCheckInterval() {
|
|
206
|
-
if (this.#isOverriden('validatorHealthCheckInterval')) return this.#options.validatorHealthCheckInterval
|
|
207
|
-
return this.#config.validatorHealthCheckInterval
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
get maxPendingRequestsInPendingRequestsService() {
|
|
211
|
-
return this.#config.maxPendingRequestsInPendingRequestsService
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
get debug() {
|
|
215
|
-
return this.#config.debug
|
|
216
|
-
}
|
|
217
197
|
|
|
218
198
|
// Most of these properties are boolean
|
|
219
199
|
#isOverriden(prop) {
|
|
@@ -227,5 +207,4 @@ export class Config {
|
|
|
227
207
|
);
|
|
228
208
|
}
|
|
229
209
|
}
|
|
230
|
-
|
|
231
210
|
}
|
package/src/config/env.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { TRAC_NETWORK_MSB_MAINNET_PREFIX, TRAC_NETWORK_MSB_TESTNET1_PREFIX } from 'trac-wallet/constants.js';
|
|
2
|
-
import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
|
|
3
2
|
import { Config } from './config.js';
|
|
3
|
+
import { TRAC_NETWORK_TESTNET_ID, TRAC_NETWORK_MAINNET_ID } from 'trac-crypto-api/constants.js';
|
|
4
4
|
|
|
5
5
|
export const ENV = {
|
|
6
6
|
MAINNET: 'mainnet',
|
|
7
7
|
DEVELOPMENT: 'development',
|
|
8
8
|
TESTNET1: 'testnet1'
|
|
9
9
|
}
|
|
10
|
+
// TODO: CREATE TEST ENV CONFIG SIMILAR TO MAINNET AND USE IT IN TESTS.
|
|
10
11
|
|
|
11
12
|
const configData = {
|
|
12
13
|
[ENV.TESTNET1]: {
|
|
13
|
-
debug: false,
|
|
14
14
|
addressLength: 67,
|
|
15
15
|
addressPrefix: TRAC_NETWORK_MSB_TESTNET1_PREFIX,
|
|
16
16
|
addressPrefixLength: TRAC_NETWORK_MSB_TESTNET1_PREFIX.length,
|
|
@@ -25,9 +25,9 @@ const configData = {
|
|
|
25
25
|
enableTxApplyLogs: true,
|
|
26
26
|
enableValidatorObserver: true,
|
|
27
27
|
enableWallet: true,
|
|
28
|
-
maxValidators:
|
|
29
|
-
maxRetries:
|
|
30
|
-
messageThreshold:
|
|
28
|
+
maxValidators: 6,
|
|
29
|
+
maxRetries: 1,
|
|
30
|
+
messageThreshold: 1000,
|
|
31
31
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
32
32
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
33
33
|
host: 'localhost',
|
|
@@ -39,20 +39,15 @@ const configData = {
|
|
|
39
39
|
maxClientConnections: Infinity, // Connectivity constants
|
|
40
40
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
41
41
|
processIntervalMs: 50, // Pool constants
|
|
42
|
+
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
42
43
|
transactionPoolSize: 1000, // Operation handler constants
|
|
43
44
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
44
45
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
45
46
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
46
|
-
|
|
47
|
-
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
48
|
-
txCommitTimeout: 2200,
|
|
49
|
-
txPoolSize: 1000, // size of transaction pool
|
|
50
|
-
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
51
|
-
storesDirectory: 'stores/',
|
|
47
|
+
storesDirectory : 'stores/',
|
|
52
48
|
storeName: 'testnet',
|
|
53
49
|
},
|
|
54
50
|
[ENV.MAINNET]: {
|
|
55
|
-
debug: false,
|
|
56
51
|
addressLength: 63,
|
|
57
52
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
58
53
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
@@ -81,20 +76,15 @@ const configData = {
|
|
|
81
76
|
maxClientConnections: Infinity, // Connectivity constants
|
|
82
77
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
83
78
|
processIntervalMs: 50, // Pool constants
|
|
79
|
+
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
84
80
|
transactionPoolSize: 1000, // Operation handler constants
|
|
85
81
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
86
82
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
87
83
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
88
|
-
maxPendingRequestsInPendingRequestsService: 50_000, // Maximum number of pending requests in PendingRequestService (This value should not exceed 256MB)
|
|
89
|
-
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
90
|
-
txCommitTimeout: 2200,
|
|
91
|
-
txPoolSize: 1000, // size of transaction pool
|
|
92
|
-
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
93
84
|
storesDirectory: 'stores/',
|
|
94
85
|
storeName: 'mainnet',
|
|
95
86
|
},
|
|
96
87
|
[ENV.DEVELOPMENT]: {
|
|
97
|
-
debug: true,
|
|
98
88
|
addressLength: 63,
|
|
99
89
|
addressPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX,
|
|
100
90
|
addressPrefixLength: TRAC_NETWORK_MSB_MAINNET_PREFIX.length,
|
|
@@ -110,7 +100,7 @@ const configData = {
|
|
|
110
100
|
enableValidatorObserver: true,
|
|
111
101
|
enableWallet: true,
|
|
112
102
|
maxValidators: 6,
|
|
113
|
-
maxRetries:
|
|
103
|
+
maxRetries: 0,
|
|
114
104
|
messageThreshold: 1000,
|
|
115
105
|
messageValidatorRetryDelay: 1000, //How long to wait before retrying (ms) MESSAGE_VALIDATOR_RETRY_DELAY_MS
|
|
116
106
|
messageValidatorResponseTimeout: 3 * 3 * 1000, //Overall timeout for sending a message (ms). This is 3 * maxRetries * messageValidatorRetryDelay;
|
|
@@ -123,16 +113,12 @@ const configData = {
|
|
|
123
113
|
maxClientConnections: Infinity, // Connectivity constants
|
|
124
114
|
maxWritersForAdminIndexerConnection: 10, // Connectivity constants
|
|
125
115
|
processIntervalMs: 50, // Pool constants
|
|
116
|
+
maxPartialTxPayloadByteSize: 3072, // Operation handler constants
|
|
126
117
|
transactionPoolSize: 1000, // Operation handler constants
|
|
127
118
|
rateLimitCleanupIntervalMs: 120_000, // Rate limiting constants
|
|
128
119
|
rateLimitConnectionTimeoutMs: 60_000, // Rate limiting constants
|
|
129
120
|
rateLimitMaxTransactionsPerSecond: 50, // Rate limiting constants
|
|
130
|
-
|
|
131
|
-
pendingRequestTimeout: 3000, // constant after which time the transaction will be considered invalid
|
|
132
|
-
txCommitTimeout: 2200,
|
|
133
|
-
txPoolSize: 1000, // size of transaction pool
|
|
134
|
-
validatorHealthCheckInterval: 5 * 60 * 1000, // How often to check validator health (ms)
|
|
135
|
-
storesDirectory: 'stores/',
|
|
121
|
+
storesDirectory : 'stores/',
|
|
136
122
|
storeName: 'development',
|
|
137
123
|
}
|
|
138
124
|
}
|