trac-msb 0.2.8 → 0.2.10
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 +7 -11
- package/.github/workflows/lint-pr-title.yml +26 -0
- package/.github/workflows/unit-tests.yml +2 -8
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +33 -18
- package/docker-compose.yml +1 -0
- package/docs/trac_network_http_api.openapi.yaml +889 -0
- package/msb.mjs +5 -22
- package/package.json +14 -10
- package/proto/network.proto +74 -0
- package/rpc/create_server.js +2 -2
- package/rpc/handlers.js +165 -92
- package/rpc/routes/v1.js +3 -1
- package/rpc/rpc_server.js +4 -4
- package/rpc/rpc_services.js +62 -25
- package/rpc/utils/helpers.js +83 -52
- package/src/config/args.js +46 -0
- package/src/config/config.js +78 -5
- package/src/config/env.js +70 -3
- package/src/core/network/Network.js +34 -70
- package/src/core/network/identity/NetworkWalletFactory.js +2 -2
- package/src/core/network/protocols/LegacyProtocol.js +67 -0
- package/src/core/network/protocols/NetworkMessages.js +48 -0
- package/src/core/network/protocols/ProtocolInterface.js +31 -0
- package/src/core/network/protocols/ProtocolSession.js +59 -0
- package/src/core/network/protocols/V1Protocol.js +64 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
- package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
- package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +2 -3
- package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
- package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
- package/src/core/network/{messaging → protocols/shared}/handlers/TransferOperationHandler.js +17 -16
- package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +10 -15
- package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +2 -2
- package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +5 -5
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +14 -12
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
- package/src/core/network/services/ConnectionManager.js +5 -5
- package/src/core/network/services/MessageOrchestrator.js +2 -2
- package/src/core/network/services/TransactionPoolService.js +5 -6
- package/src/core/network/services/TransactionRateLimiterService.js +12 -13
- package/src/core/network/services/ValidatorObserverService.js +5 -6
- package/src/core/state/State.js +3 -5
- package/src/index.js +156 -181
- package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
- package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
- package/src/messages/network/v1/networkMessageFactory.js +12 -0
- package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
- package/src/messages/state/ApplyStateMessageDirector.js +516 -0
- package/src/messages/state/applyStateMessageFactory.js +12 -0
- package/src/utils/buffer.js +53 -1
- package/src/utils/check.js +1 -1
- package/src/utils/cli.js +0 -8
- package/src/utils/constants.js +33 -30
- package/src/utils/fileUtils.js +13 -0
- package/src/utils/normalizers.js +84 -2
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +10 -0
- package/src/utils/type.js +26 -0
- package/tests/acceptance/v1/balance/balance.test.mjs +1 -2
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +26 -30
- package/tests/acceptance/v1/health/health.test.mjs +33 -0
- package/tests/acceptance/v1/rpc.test.mjs +4 -3
- package/tests/acceptance/v1/tx/tx.test.mjs +27 -16
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +26 -12
- package/tests/fixtures/check.fixtures.js +33 -32
- package/tests/fixtures/networkV1.fixtures.js +85 -0
- package/tests/fixtures/protobuf.fixtures.js +109 -25
- package/tests/helpers/StateNetworkFactory.js +2 -2
- package/tests/helpers/address.js +6 -0
- package/tests/helpers/autobaseTestHelpers.js +2 -1
- package/tests/helpers/config.js +2 -1
- package/tests/helpers/setupApplyTests.js +59 -56
- package/tests/unit/messages/messages.test.js +12 -0
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +201 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
- package/tests/unit/network/ConnectionManager.test.js +6 -5
- package/tests/unit/network/networkModule.test.js +3 -2
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +9 -6
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +10 -7
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +53 -38
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +46 -35
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +13 -16
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +11 -12
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/common/commonScenarioHelper.js +15 -14
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +9 -4
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +19 -14
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +37 -29
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +11 -9
- package/tests/unit/unit.test.js +1 -1
- package/tests/unit/utils/buffer/buffer.test.js +62 -1
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +4 -3
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +3 -2
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +3 -2
- package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
- package/tests/unit/utils/type/type.test.js +25 -0
- package/tests/unit/utils/utils.test.js +1 -0
- package/docs/networking-dualstack-plan.md +0 -75
- package/docs/networking-layer-redesign.md +0 -155
- package/src/core/network/messaging/NetworkMessages.js +0 -64
- package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -113
- package/src/core/network/messaging/handlers/ResponseHandler.js +0 -107
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -114
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -149
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -98
- package/src/core/network/messaging/validators/AdminResponse.js +0 -58
- package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
- package/src/messages/base/StateBuilder.js +0 -25
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -425
- package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -296
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
- package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -138
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -69
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -126
- package/tests/integration/apply/addIndexer.test.js +0 -239
- package/tests/integration/apply/addWhitelist.test.js +0 -53
- package/tests/integration/apply/addWriter.test.js +0 -245
- package/tests/integration/apply/apply.test.js +0 -19
- package/tests/integration/apply/banValidator.test.js +0 -116
- package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
- package/tests/integration/apply/postTx/postTx.test.js +0 -196
- package/tests/integration/apply/removeIndexer.test.js +0 -132
- package/tests/integration/apply/removeWriter.test.js +0 -168
- package/tests/integration/apply/transfer.test.js +0 -83
- package/tests/integration/integration.test.js +0 -9
- package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
- package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -68
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -424
- package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
- package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -59
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -278
- package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
- /package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +0 -0
- /package/src/utils/{operations.js → applyOperations.js} +0 -0
package/src/utils/fileUtils.js
CHANGED
|
@@ -123,6 +123,18 @@ export async function getAllMigrationFiles(migrationDirectory = BALANCE_MIGRATED
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
export async function ensureCoresStoreDir(config) {
|
|
127
|
+
try {
|
|
128
|
+
// const storesDirectoryStats = await fs.promises.stat(config.storesDirectory);
|
|
129
|
+
// if (!storesDirectoryStats.isDirectory()) {
|
|
130
|
+
// throw new Error(`Stores directory path is not a directory: ${config.storesDirectory}`);
|
|
131
|
+
// }
|
|
132
|
+
await fs.promises.mkdir(config.storesFullPath, { recursive: true });
|
|
133
|
+
} catch (err) {
|
|
134
|
+
throw new Error(`Failed to ensure corestore directory: ${err.message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
126
138
|
export async function validateBalanceMigrationData(addresses) {
|
|
127
139
|
const migrationFiles = await getAllMigrationFiles(BALANCE_MIGRATED_DIR);
|
|
128
140
|
const addressSet = new Set(addresses.map(a => a.address));
|
|
@@ -197,6 +209,7 @@ export default {
|
|
|
197
209
|
readAddressesFromWhitelistFile,
|
|
198
210
|
readBalanceMigrationFile,
|
|
199
211
|
getAllMigrationFiles,
|
|
212
|
+
ensureCoresStoreDir,
|
|
200
213
|
validateBalanceMigrationData,
|
|
201
214
|
validateWhitelistMigrationData,
|
|
202
215
|
getNextMigrationNumber,
|
package/src/utils/normalizers.js
CHANGED
|
@@ -44,6 +44,14 @@ export function normalizeTransferOperation(payload, config) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Normalizes the payload for a transaction operation.
|
|
49
|
+
* This is useful for validating and assembling a transaction operation.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} payload The raw payload for the transaction operation.
|
|
52
|
+
* @param {object} config The environment configuration object.
|
|
53
|
+
* @returns {Object} A normalized payload with addresses converted to buffers and hex values normalized.
|
|
54
|
+
*/
|
|
47
55
|
export function normalizeTransactionOperation(payload, config) {
|
|
48
56
|
if (!payload || typeof payload !== 'object' || !payload.txo) {
|
|
49
57
|
throw new Error('Invalid payload for transaction operation normalization.');
|
|
@@ -80,8 +88,9 @@ export function normalizeTransactionOperation(payload, config) {
|
|
|
80
88
|
* Normalizes an operation payload by converting any Buffer values to hex strings.
|
|
81
89
|
* This is useful for preparing a payload to be returned as a JSON response.
|
|
82
90
|
*
|
|
83
|
-
* @param {Object} payload The
|
|
84
|
-
* @
|
|
91
|
+
* @param {Object} payload The raw payload for the role access operation.
|
|
92
|
+
* @param {object} config The environment configuration object.
|
|
93
|
+
* @returns {Object} A normalized payload with addresses converted to buffers and hex values normalized.
|
|
85
94
|
*/
|
|
86
95
|
export function normalizeDecodedPayloadForJson(payload, config) {
|
|
87
96
|
if (!payload || typeof payload !== "object") {
|
|
@@ -117,3 +126,76 @@ export function normalizeDecodedPayloadForJson(payload, config) {
|
|
|
117
126
|
}
|
|
118
127
|
return newPayload;
|
|
119
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Normalizes the payload for a role access operation.
|
|
132
|
+
* This is useful for validating and assembling a role access operation.
|
|
133
|
+
*
|
|
134
|
+
* @param {Object} payload The raw payload for the role access operation.
|
|
135
|
+
* @param {object} config The environment configuration object.
|
|
136
|
+
* @returns {Object} A normalized payload with addresses converted to buffers and hex values normalized.
|
|
137
|
+
*/
|
|
138
|
+
export function normalizeRoleAccessOperation(payload, config) {
|
|
139
|
+
if (!payload || typeof payload !== 'object' || !payload.rao) {
|
|
140
|
+
throw new Error('Invalid payload for role access normalization.');
|
|
141
|
+
}
|
|
142
|
+
const { type, address, rao } = payload;
|
|
143
|
+
if (
|
|
144
|
+
!type ||
|
|
145
|
+
!address ||
|
|
146
|
+
!rao.tx || !rao.txv || !rao.iw || !rao.in || !rao.is
|
|
147
|
+
) {
|
|
148
|
+
throw new Error('Missing required fields in role access payload.');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const normalizedRao = {
|
|
152
|
+
tx: normalizeHex(rao.tx),
|
|
153
|
+
txv: normalizeHex(rao.txv),
|
|
154
|
+
iw: normalizeHex(rao.iw),
|
|
155
|
+
in: normalizeHex(rao.in),
|
|
156
|
+
is: normalizeHex(rao.is)
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
type,
|
|
161
|
+
address: addressToBuffer(address, config.addressPrefix),
|
|
162
|
+
rao: normalizedRao
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Normalizes the payload for a bootstrap deployment operation.
|
|
168
|
+
* This is useful for validating and assembling a bootstrap deployment operation.
|
|
169
|
+
*
|
|
170
|
+
* @param {Object} payload The raw payload for the bootstrap deployment operation.
|
|
171
|
+
* @param {object} config The environment configuration object.
|
|
172
|
+
* @returns {Object} A normalized payload with addresses converted to buffers and hex values normalized.
|
|
173
|
+
*/
|
|
174
|
+
export function normalizeBootstrapDeploymentOperation(payload, config) {
|
|
175
|
+
if (!payload || typeof payload !== 'object' || !payload.bdo) {
|
|
176
|
+
throw new Error('Invalid payload for bootstrap deployment normalization.');
|
|
177
|
+
}
|
|
178
|
+
const { type, address, bdo } = payload;
|
|
179
|
+
if (
|
|
180
|
+
type !== OperationType.BOOTSTRAP_DEPLOYMENT ||
|
|
181
|
+
!address ||
|
|
182
|
+
!bdo.tx || !bdo.bs || !bdo.ic || !bdo.in || !bdo.is || !bdo.txv
|
|
183
|
+
) {
|
|
184
|
+
throw new Error('Missing required fields in bootstrap deployment payload.');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const normalizedBdo = {
|
|
188
|
+
tx: normalizeHex(bdo.tx), // Transaction hash
|
|
189
|
+
txv: normalizeHex(bdo.txv), // Transaction validity
|
|
190
|
+
bs: normalizeHex(bdo.bs), // External bootstrap
|
|
191
|
+
ic: normalizeHex(bdo.ic), // Channel
|
|
192
|
+
in: normalizeHex(bdo.in), // Nonce
|
|
193
|
+
is: normalizeHex(bdo.is) // Signature
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
type,
|
|
198
|
+
address: addressToBuffer(address, config.addressPrefix),
|
|
199
|
+
bdo: normalizedBdo
|
|
200
|
+
};
|
|
201
|
+
}
|