trac-msb 0.2.12 → 0.2.13
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
|
@@ -1,38 +0,0 @@
|
|
|
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
|
|
@@ -1,26 +0,0 @@
|
|
|
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"
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
|
@@ -1,34 +0,0 @@
|
|
|
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/proto/network.proto
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import ValidatorResponse from '../validators/ValidatorResponse.js';
|
|
2
|
-
import PeerWallet from 'trac-wallet';
|
|
3
|
-
|
|
4
|
-
class ResponseHandler {
|
|
5
|
-
#responseValidator;
|
|
6
|
-
#connectionManager;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(state, wallet, connectionManager ,config) {
|
|
10
|
-
this.#responseValidator = new ValidatorResponse(state, wallet, config);
|
|
11
|
-
this.#connectionManager = connectionManager;
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async handle(message, connection, channelString) {
|
|
16
|
-
await this.#handleValidatorResponse(message, connection, channelString);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async #handleValidatorResponse(message, connection, channelString) {
|
|
20
|
-
const isValid = await this.#responseValidator.validate(message, channelString);
|
|
21
|
-
if (isValid) {
|
|
22
|
-
const validatorAddressString = message.address;
|
|
23
|
-
const validatorPublicKey = PeerWallet.decodeBech32m(validatorAddressString);
|
|
24
|
-
|
|
25
|
-
if (this.#connectionManager.connected(validatorPublicKey)) {
|
|
26
|
-
return;
|
|
27
|
-
// TODO: What we should return? Or maybe we should throw?
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.#connectionManager.addValidator(validatorPublicKey, connection)
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error("Validator response verification failed");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default ResponseHandler;
|