@xyo-network/xl1-cli-lib 1.14.1 → 1.14.3
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/dist/node/index.mjs +255 -51
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts +1 -1
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts +1 -1
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts +1 -1
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts.map +1 -1
- package/dist/node/orchestration/archivists/lib/localPersistentArchivist.d.ts +1 -1
- package/dist/node/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +1 -1
- package/dist/node/orchestration/initServices.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/head/createBootstrapHead.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/head/createBootstrapHead.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts +18 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts +14 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/index.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/createForkedHead.d.ts +5 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/createForkedHead.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts +10 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.d.ts +10 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts +10 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts +12 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/index.d.ts +2 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/getForkFromBlock.d.ts +12 -0
- package/dist/node/orchestration/services/implementation/head/getForkFromBlock.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/{head.d.ts → head/head.d.ts} +2 -1
- package/dist/node/orchestration/services/implementation/head/head.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/index.d.ts +2 -0
- package/dist/node/orchestration/services/implementation/head/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/submitNewChain.d.ts +10 -0
- package/dist/node/orchestration/services/implementation/head/submitNewChain.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/index.d.ts +1 -1
- package/dist/node/orchestration/services/implementation/index.d.ts.map +1 -1
- package/dist/node/xl1.mjs +253 -49
- package/dist/node/xl1.mjs.map +1 -1
- package/package.json +13 -13
- package/src/orchestration/actor/implementation/BalanceActor.ts +2 -2
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +2 -2
- package/src/orchestration/actor/implementation/ProducerActor.ts +4 -4
- package/src/orchestration/actor/implementation/ValidatorActor.ts +4 -4
- package/src/orchestration/actor/model/Actor.ts +2 -2
- package/src/orchestration/archivists/ChainFinalized/local.ts +1 -1
- package/src/orchestration/archivists/StakeIntentState/local.ts +1 -1
- package/src/orchestration/archivists/lib/localPersistentArchivist.ts +8 -1
- package/src/orchestration/initServices.ts +11 -7
- package/src/orchestration/services/implementation/head/createBootstrapHead.ts +8 -0
- package/src/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts +27 -0
- package/src/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts +18 -0
- package/src/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.ts +10 -0
- package/src/orchestration/services/implementation/head/createForkedHead/config/index.ts +3 -0
- package/src/orchestration/services/implementation/head/createForkedHead/createForkedHead.ts +31 -0
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.ts +38 -0
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.ts +50 -0
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.ts +43 -0
- package/src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts +42 -0
- package/src/orchestration/services/implementation/head/createForkedHead/index.ts +1 -0
- package/src/orchestration/services/implementation/head/getForkFromBlock.ts +42 -0
- package/src/orchestration/services/implementation/head/head.ts +52 -0
- package/src/orchestration/services/implementation/head/index.ts +1 -0
- package/src/orchestration/services/implementation/head/submitNewChain.ts +27 -0
- package/src/orchestration/services/implementation/index.ts +1 -1
- package/src/spec/BootstrapChain.spec.ts +2 -2
- package/dist/node/orchestration/services/implementation/head.d.ts.map +0 -1
- package/src/orchestration/services/implementation/head.ts +0 -44
package/dist/node/xl1.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { config as config2 } from "dotenv";
|
|
|
6
6
|
|
|
7
7
|
// src/runCLI.ts
|
|
8
8
|
import { deepMerge } from "@xylabs/object";
|
|
9
|
-
import { isDefined as
|
|
9
|
+
import { isDefined as isDefined14 } from "@xylabs/typeof";
|
|
10
10
|
import { ConfigZod } from "@xyo-network/xl1-protocol-sdk";
|
|
11
11
|
import yargs from "yargs";
|
|
12
12
|
import { hideBin } from "yargs/helpers";
|
|
@@ -27,7 +27,7 @@ import { Mutex } from "async-mutex";
|
|
|
27
27
|
// src/orchestration/actor/model/Actor.ts
|
|
28
28
|
import { Base } from "@xylabs/base";
|
|
29
29
|
import { IdLogger } from "@xylabs/logger";
|
|
30
|
-
import { span,
|
|
30
|
+
import { span, spanRootAsync } from "@xylabs/telemetry";
|
|
31
31
|
var Actor = class extends Base {
|
|
32
32
|
static {
|
|
33
33
|
__name(this, "Actor");
|
|
@@ -86,7 +86,7 @@ var Actor = class extends Base {
|
|
|
86
86
|
return span(`${this.name}:${name}`, fn, this.tracer);
|
|
87
87
|
}
|
|
88
88
|
async spanAsync(name, fn) {
|
|
89
|
-
return await
|
|
89
|
+
return await spanRootAsync(`${this.name}:${name}`, fn, this.tracer);
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Called by the Orchestrator when the actor is activated.
|
|
@@ -184,7 +184,7 @@ var BalanceActor = class _BalanceActor extends Actor {
|
|
|
184
184
|
super("BalanceActor", "Balance", params);
|
|
185
185
|
}
|
|
186
186
|
get balanceService() {
|
|
187
|
-
return assertEx(this.params.
|
|
187
|
+
return assertEx(this.params.balance, () => "balanceService not set");
|
|
188
188
|
}
|
|
189
189
|
get chainIterator() {
|
|
190
190
|
return assertEx(this.params.chainIterator, () => "chainIterator not set");
|
|
@@ -254,9 +254,9 @@ var ChainHeadUpdateActor = class _ChainHeadUpdateActor extends Actor {
|
|
|
254
254
|
const candidateBlockNumberDisplay = `0x${toHex(candidateBlockNumber)}`;
|
|
255
255
|
const currentBlockNumber = currentHead?.block ?? -1;
|
|
256
256
|
if (candidateBlockNumber > currentBlockNumber) {
|
|
257
|
-
this.logger?.log("Found more recent head:", candidateBlockNumberDisplay);
|
|
257
|
+
this.logger?.log("Found more recent head:", candidateBlockNumber, candidateBlockNumberDisplay);
|
|
258
258
|
await this.chainIterator.updateHead(candidateBlock);
|
|
259
|
-
this.logger?.log("Updated head:", candidateBlockNumberDisplay);
|
|
259
|
+
this.logger?.log("Updated head:", candidateBlockNumber, candidateBlockNumberDisplay);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
};
|
|
@@ -284,7 +284,7 @@ var ProducerActor = class _ProducerActor extends Actor {
|
|
|
284
284
|
return assertEx3(this.params.account, () => "account not set");
|
|
285
285
|
}
|
|
286
286
|
get balanceService() {
|
|
287
|
-
return assertEx3(this.params.
|
|
287
|
+
return assertEx3(this.params.balance, () => "balanceService not set");
|
|
288
288
|
}
|
|
289
289
|
get chainIterator() {
|
|
290
290
|
return assertEx3(this.params.chainIterator, () => "chainIterator not set");
|
|
@@ -302,7 +302,7 @@ var ProducerActor = class _ProducerActor extends Actor {
|
|
|
302
302
|
return assertEx3(this.params.producer, () => "producer not set");
|
|
303
303
|
}
|
|
304
304
|
get stakeIntentService() {
|
|
305
|
-
return assertEx3(this.params.
|
|
305
|
+
return assertEx3(this.params.stakeIntent, () => "stakeIntentService not set");
|
|
306
306
|
}
|
|
307
307
|
static create(params) {
|
|
308
308
|
return new _ProducerActor(params);
|
|
@@ -470,10 +470,10 @@ var initHealthEndpoints = /* @__PURE__ */ __name((params) => {
|
|
|
470
470
|
}, "initHealthEndpoints");
|
|
471
471
|
|
|
472
472
|
// src/orchestration/initServices.ts
|
|
473
|
-
import { assertEx as
|
|
473
|
+
import { assertEx as assertEx17 } from "@xylabs/assert";
|
|
474
474
|
import { asAddress as asAddress2 } from "@xylabs/hex";
|
|
475
|
-
import { isDefined as
|
|
476
|
-
import { balanceSummaryRepositoryFromMap, initTelemetry, startupSpanAsync as startupSpanAsync7, validateHydratedBlockState } from "@xyo-network/chain-sdk";
|
|
475
|
+
import { isDefined as isDefined11 } from "@xylabs/typeof";
|
|
476
|
+
import { balanceSummaryRepositoryFromMap, BaseTimeSyncService, initTelemetry, startupSpanAsync as startupSpanAsync7, validateHydratedBlockState } from "@xyo-network/chain-sdk";
|
|
477
477
|
|
|
478
478
|
// src/orchestration/archivists/ChainFinalized/archivist.ts
|
|
479
479
|
import { initArchivistSync, startupSpanAsync } from "@xyo-network/chain-sdk";
|
|
@@ -495,13 +495,14 @@ var getStoreDirectory = /* @__PURE__ */ __name((name, storageRoot, kind) => {
|
|
|
495
495
|
|
|
496
496
|
// src/orchestration/archivists/lib/localPersistentArchivist.ts
|
|
497
497
|
var DEFAULT_STORAGE_ROOT = Path2.join(process.cwd(), ".store");
|
|
498
|
-
var getLocalPersistentArchivist = /* @__PURE__ */ __name((dbName, storeName, storageRoot, kind = "lmdb") => {
|
|
498
|
+
var getLocalPersistentArchivist = /* @__PURE__ */ __name((name, dbName, storeName, storageRoot, kind = "lmdb") => {
|
|
499
499
|
switch (kind) {
|
|
500
500
|
case "lmdb": {
|
|
501
501
|
const root = storageRoot ?? DEFAULT_STORAGE_ROOT;
|
|
502
502
|
return LmdbArchivist.create({
|
|
503
503
|
account: "random",
|
|
504
504
|
config: {
|
|
505
|
+
name,
|
|
505
506
|
clearStoreOnStart: false,
|
|
506
507
|
dbName,
|
|
507
508
|
location: getStoreDirectory(dbName, root, "lmdb"),
|
|
@@ -520,7 +521,7 @@ var initLocalChainFinalizedArchivist = /* @__PURE__ */ __name(async ({ config: c
|
|
|
520
521
|
return await mutex.runExclusive(async () => {
|
|
521
522
|
if (singleton) return singleton;
|
|
522
523
|
const { root } = config3.storage;
|
|
523
|
-
singleton = await getLocalPersistentArchivist("chain", "finalized", root);
|
|
524
|
+
singleton = await getLocalPersistentArchivist("local-finalized-chain", "chain", "finalized", root);
|
|
524
525
|
return singleton;
|
|
525
526
|
});
|
|
526
527
|
}, "initLocalChainFinalizedArchivist");
|
|
@@ -725,7 +726,7 @@ var initLocalStakeIntentStateArchivist = /* @__PURE__ */ __name(async ({ config:
|
|
|
725
726
|
return await mutex11.runExclusive(async () => {
|
|
726
727
|
if (singleton11) return singleton11;
|
|
727
728
|
const { root } = config3.storage;
|
|
728
|
-
singleton11 = await getLocalPersistentArchivist("stakeIntent", "state", root);
|
|
729
|
+
singleton11 = await getLocalPersistentArchivist("local-stake-intent-state", "stakeIntent", "state", root);
|
|
729
730
|
return assertEx8(singleton11, () => new Error("Failed to initialize stake intent state archivist"));
|
|
730
731
|
});
|
|
731
732
|
}, "initLocalStakeIntentStateArchivist");
|
|
@@ -1032,30 +1033,227 @@ var init = /* @__PURE__ */ __name((params) => {
|
|
|
1032
1033
|
return chainStakeServiceSingleton2;
|
|
1033
1034
|
}, "init");
|
|
1034
1035
|
|
|
1035
|
-
// src/orchestration/services/implementation/head.ts
|
|
1036
|
-
import {
|
|
1036
|
+
// src/orchestration/services/implementation/head/head.ts
|
|
1037
|
+
import { assertEx as assertEx15 } from "@xylabs/assert";
|
|
1038
|
+
import { isDefined as isDefined10 } from "@xylabs/typeof";
|
|
1039
|
+
import { findMostRecentBlock as findMostRecentBlock2 } from "@xyo-network/chain-sdk";
|
|
1040
|
+
|
|
1041
|
+
// src/orchestration/services/implementation/head/createBootstrapHead.ts
|
|
1037
1042
|
import { ZERO_ADDRESS as ZERO_ADDRESS2 } from "@xylabs/hex";
|
|
1038
|
-
import { createGenesisBlock
|
|
1043
|
+
import { createGenesisBlock } from "@xyo-network/chain-sdk";
|
|
1044
|
+
var createBootstrapHead = /* @__PURE__ */ __name(async (account) => {
|
|
1045
|
+
return await createGenesisBlock(account, ZERO_ADDRESS2, 10000000n, account.address);
|
|
1046
|
+
}, "createBootstrapHead");
|
|
1047
|
+
|
|
1048
|
+
// src/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.ts
|
|
1049
|
+
import { BridgeDestinationObservationSchema, buildNextBlock } from "@xyo-network/chain-sdk";
|
|
1050
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
1051
|
+
|
|
1052
|
+
// src/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts
|
|
1053
|
+
import { toHex as toHex4 } from "@xylabs/hex";
|
|
1054
|
+
|
|
1055
|
+
// src/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.ts
|
|
1056
|
+
import { toHex as toHex3 } from "@xylabs/hex";
|
|
1057
|
+
import { AttoXL1ConvertFactor } from "@xyo-network/xl1-protocol";
|
|
1058
|
+
var getForkBlockReward = /* @__PURE__ */ __name(() => {
|
|
1059
|
+
return 18000000000n * AttoXL1ConvertFactor.xl1;
|
|
1060
|
+
}, "getForkBlockReward");
|
|
1061
|
+
var getForkBlockRewardHex = /* @__PURE__ */ __name(() => {
|
|
1062
|
+
return toHex3(getForkBlockReward());
|
|
1063
|
+
}, "getForkBlockRewardHex");
|
|
1064
|
+
|
|
1065
|
+
// src/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts
|
|
1066
|
+
var ethChainId = toHex4("0x1");
|
|
1067
|
+
var bridgeableTokenContract = toHex4("0x7789e11BB83b398A8Cca8E8D582B33F91499D6f5");
|
|
1068
|
+
var bridgeDestAddress = toHex4("0xe53218d47913b5f9E58bb74F0a0eD790bbF21972");
|
|
1069
|
+
var destConfirmation = toHex4("0x772ee028f9ad291ec692912c1a33ecd4409e71383fe06f6ebf39f7cdbb779069");
|
|
1070
|
+
var getBridgeDestChainId = /* @__PURE__ */ __name(() => ethChainId, "getBridgeDestChainId");
|
|
1071
|
+
var getBridgeDestToken = /* @__PURE__ */ __name(() => bridgeableTokenContract, "getBridgeDestToken");
|
|
1072
|
+
var getBridgeDestAddress = /* @__PURE__ */ __name(() => bridgeDestAddress, "getBridgeDestAddress");
|
|
1073
|
+
var getBridgeDestAmount = /* @__PURE__ */ __name(() => getForkBlockRewardHex(), "getBridgeDestAmount");
|
|
1074
|
+
var getBridgeDestConfirmation = /* @__PURE__ */ __name(() => destConfirmation, "getBridgeDestConfirmation");
|
|
1075
|
+
var getBridgeDestinationDetails = /* @__PURE__ */ __name(() => {
|
|
1076
|
+
return {
|
|
1077
|
+
dest: getBridgeDestChainId(),
|
|
1078
|
+
destToken: getBridgeDestToken(),
|
|
1079
|
+
destAddress: getBridgeDestAddress(),
|
|
1080
|
+
destAmount: getBridgeDestAmount()
|
|
1081
|
+
};
|
|
1082
|
+
}, "getBridgeDestinationDetails");
|
|
1083
|
+
|
|
1084
|
+
// src/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts
|
|
1085
|
+
var getBridgeSrcChainId = /* @__PURE__ */ __name((chainService) => chainService.chainId, "getBridgeSrcChainId");
|
|
1086
|
+
var getBridgeSrcAddress = /* @__PURE__ */ __name((account) => account.address, "getBridgeSrcAddress");
|
|
1087
|
+
var getBridgeSrcToken = /* @__PURE__ */ __name((chainService) => chainService.chainId, "getBridgeSrcToken");
|
|
1088
|
+
var getBridgeSrcAmount = /* @__PURE__ */ __name(() => getForkBlockRewardHex(), "getBridgeSrcAmount");
|
|
1089
|
+
var getBridgeSourceDetails = /* @__PURE__ */ __name((account, chainService) => {
|
|
1090
|
+
return {
|
|
1091
|
+
src: getBridgeSrcChainId(chainService),
|
|
1092
|
+
srcAddress: getBridgeSrcAddress(account),
|
|
1093
|
+
srcToken: getBridgeSrcToken(chainService),
|
|
1094
|
+
srcAmount: getBridgeSrcAmount()
|
|
1095
|
+
};
|
|
1096
|
+
}, "getBridgeSourceDetails");
|
|
1097
|
+
|
|
1098
|
+
// src/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.ts
|
|
1099
|
+
var getBridgeDestinationObservation = /* @__PURE__ */ __name(async (previousBlock, account, chainService) => {
|
|
1100
|
+
const bridgeDestinationObservationFields = {
|
|
1101
|
+
...getBridgeSourceDetails(account, chainService),
|
|
1102
|
+
...getBridgeDestinationDetails(),
|
|
1103
|
+
destConfirmation: getBridgeDestConfirmation()
|
|
1104
|
+
};
|
|
1105
|
+
const bridgeDestinationObservation = new PayloadBuilder3({
|
|
1106
|
+
schema: BridgeDestinationObservationSchema
|
|
1107
|
+
}).fields(bridgeDestinationObservationFields).build();
|
|
1108
|
+
return await buildNextBlock(previousBlock[0], [], [
|
|
1109
|
+
bridgeDestinationObservation
|
|
1110
|
+
], [
|
|
1111
|
+
account
|
|
1112
|
+
]);
|
|
1113
|
+
}, "getBridgeDestinationObservation");
|
|
1114
|
+
|
|
1115
|
+
// src/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.ts
|
|
1116
|
+
import { BridgeIntentSchema, buildNextBlock as buildNextBlock2, createTransferPayload, XYO_BRIDGE_ADDRESS } from "@xyo-network/chain-sdk";
|
|
1117
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
1118
|
+
var getBridgeIntent = /* @__PURE__ */ __name(async (previousBlock, account, chainService) => {
|
|
1119
|
+
const transferPayload = createTransferPayload(account.address, {
|
|
1120
|
+
[XYO_BRIDGE_ADDRESS]: getForkBlockReward()
|
|
1121
|
+
});
|
|
1122
|
+
const nonce = `${Date.now()}`;
|
|
1123
|
+
const bridgeIntentFields = {
|
|
1124
|
+
...getBridgeSourceDetails(account, chainService),
|
|
1125
|
+
...getBridgeDestinationDetails(),
|
|
1126
|
+
nonce
|
|
1127
|
+
};
|
|
1128
|
+
const bridgeIntent = new PayloadBuilder4({
|
|
1129
|
+
schema: BridgeIntentSchema
|
|
1130
|
+
}).fields(bridgeIntentFields).build();
|
|
1131
|
+
return await buildNextBlock2(previousBlock[0], [], [
|
|
1132
|
+
bridgeIntent,
|
|
1133
|
+
transferPayload
|
|
1134
|
+
], [
|
|
1135
|
+
account
|
|
1136
|
+
]);
|
|
1137
|
+
}, "getBridgeIntent");
|
|
1138
|
+
|
|
1139
|
+
// src/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.ts
|
|
1140
|
+
import { BridgeSourceObservationSchema, buildNextBlock as buildNextBlock3 } from "@xyo-network/chain-sdk";
|
|
1141
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1142
|
+
var getBridgeSourceObservation = /* @__PURE__ */ __name(async (previousBlock, account, chainService) => {
|
|
1143
|
+
const srcTxHash = previousBlock[0]._hash;
|
|
1144
|
+
const bridgeSourceObservationFields = {
|
|
1145
|
+
...getBridgeSourceDetails(account, chainService),
|
|
1146
|
+
...getBridgeDestinationDetails(),
|
|
1147
|
+
// Observation
|
|
1148
|
+
srcConfirmation: srcTxHash
|
|
1149
|
+
};
|
|
1150
|
+
const bridgeSourceObservation = new PayloadBuilder5({
|
|
1151
|
+
schema: BridgeSourceObservationSchema
|
|
1152
|
+
}).fields(bridgeSourceObservationFields).build();
|
|
1153
|
+
return await buildNextBlock3(previousBlock[0], [], [
|
|
1154
|
+
bridgeSourceObservation
|
|
1155
|
+
], [
|
|
1156
|
+
account
|
|
1157
|
+
]);
|
|
1158
|
+
}, "getBridgeSourceObservation");
|
|
1159
|
+
|
|
1160
|
+
// src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts
|
|
1161
|
+
import { buildBlock } from "@xyo-network/chain-sdk";
|
|
1162
|
+
var getFirstBlockForNewChain = /* @__PURE__ */ __name(async (forkBlock, account, chainService) => {
|
|
1163
|
+
const { _hash: previousBlockHash, block: previousBlockNumber, step_hashes: previousStepHashes, protocol } = forkBlock;
|
|
1164
|
+
const chainId = chainService.chainId;
|
|
1165
|
+
const forkBlockReward = getForkBlockReward();
|
|
1166
|
+
const options = {
|
|
1167
|
+
blockPayloads: [],
|
|
1168
|
+
chainId,
|
|
1169
|
+
previousBlockHash,
|
|
1170
|
+
previousBlockNumber,
|
|
1171
|
+
previousStepHashes,
|
|
1172
|
+
signers: [
|
|
1173
|
+
account
|
|
1174
|
+
],
|
|
1175
|
+
txs: [],
|
|
1176
|
+
protocol,
|
|
1177
|
+
reward: forkBlockReward,
|
|
1178
|
+
rewardAddress: account.address
|
|
1179
|
+
};
|
|
1180
|
+
return await buildBlock(options);
|
|
1181
|
+
}, "getFirstBlockForNewChain");
|
|
1182
|
+
|
|
1183
|
+
// src/orchestration/services/implementation/head/createForkedHead/createForkedHead.ts
|
|
1184
|
+
var createForkedHead = /* @__PURE__ */ __name(async (forkFromBlock, account, chainService) => {
|
|
1185
|
+
const chain = [];
|
|
1186
|
+
const firstBlockForNewChain = await getFirstBlockForNewChain(forkFromBlock, account, chainService);
|
|
1187
|
+
chain.push(firstBlockForNewChain);
|
|
1188
|
+
const bridgeIntent = await getBridgeIntent(firstBlockForNewChain, account, chainService);
|
|
1189
|
+
chain.push(bridgeIntent);
|
|
1190
|
+
const bridgeSourceObservation = await getBridgeSourceObservation(bridgeIntent, account, chainService);
|
|
1191
|
+
chain.push(bridgeSourceObservation);
|
|
1192
|
+
const bridgeDestinationObservation = await getBridgeDestinationObservation(bridgeSourceObservation, account, chainService);
|
|
1193
|
+
chain.push(bridgeDestinationObservation);
|
|
1194
|
+
return chain;
|
|
1195
|
+
}, "createForkedHead");
|
|
1196
|
+
|
|
1197
|
+
// src/orchestration/services/implementation/head/getForkFromBlock.ts
|
|
1198
|
+
import { asHash, hexFromBigInt } from "@xylabs/hex";
|
|
1199
|
+
import { isDefined as isDefined9 } from "@xylabs/typeof";
|
|
1200
|
+
import { isBlockBoundWitnessWithHashStorageMeta } from "@xyo-network/chain-sdk";
|
|
1201
|
+
var getForkFromBlock = /* @__PURE__ */ __name(async (head, chainService, chainArchivist) => {
|
|
1202
|
+
if (head.chain !== chainService.chainId) {
|
|
1203
|
+
const forkedAtBigInt = await chainService.forkedAtHash();
|
|
1204
|
+
const forkedAtHex = hexFromBigInt(forkedAtBigInt);
|
|
1205
|
+
const forkedAtHash = asHash(forkedAtHex);
|
|
1206
|
+
if (isDefined9(forkedAtHash)) {
|
|
1207
|
+
const [forkedAtBlock] = await chainArchivist.get([
|
|
1208
|
+
forkedAtHash
|
|
1209
|
+
]);
|
|
1210
|
+
const forkedChainId = await chainService.forkedChainId();
|
|
1211
|
+
const forkedAtBlockNumber = Number(await chainService.forkedAtBlockNumber());
|
|
1212
|
+
if (isBlockBoundWitnessWithHashStorageMeta(forkedAtBlock) && forkedAtBlock.chain === forkedChainId && forkedAtBlock.block === forkedAtBlockNumber) {
|
|
1213
|
+
return forkedAtBlock;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}, "getForkFromBlock");
|
|
1218
|
+
|
|
1219
|
+
// src/orchestration/services/implementation/head/submitNewChain.ts
|
|
1220
|
+
import { delay } from "@xylabs/delay";
|
|
1039
1221
|
import { flattenHydratedBlock as flattenHydratedBlock2 } from "@xyo-network/xl1-protocol-sdk";
|
|
1040
|
-
var
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1222
|
+
var submitNewChain = /* @__PURE__ */ __name(async (chain, chainArchivist, chainSubmissionsArchivistWrite) => {
|
|
1223
|
+
for (const block of chain) {
|
|
1224
|
+
const [bw] = block;
|
|
1225
|
+
await chainSubmissionsArchivistWrite.insert(flattenHydratedBlock2(block));
|
|
1226
|
+
while (true) {
|
|
1227
|
+
const result = await chainArchivist.get([
|
|
1228
|
+
bw._hash
|
|
1229
|
+
]);
|
|
1230
|
+
if (result.length > 0) break;
|
|
1231
|
+
await delay(1e3);
|
|
1232
|
+
}
|
|
1051
1233
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1234
|
+
}, "submitNewChain");
|
|
1235
|
+
|
|
1236
|
+
// src/orchestration/services/implementation/head/head.ts
|
|
1237
|
+
var headSingleton;
|
|
1054
1238
|
var initHead = /* @__PURE__ */ __name(async (params) => {
|
|
1055
|
-
const { account, chainArchivist, chainSubmissionsArchivistWrite } = params;
|
|
1239
|
+
const { account, chainArchivist, chainSubmissionsArchivistWrite, chainService } = params;
|
|
1056
1240
|
if (headSingleton) return headSingleton;
|
|
1057
1241
|
let head = await findMostRecentBlock2(chainArchivist);
|
|
1058
|
-
if (
|
|
1242
|
+
if (head) {
|
|
1243
|
+
const forkFromBlock = await getForkFromBlock(head, chainService, chainArchivist);
|
|
1244
|
+
if (isDefined10(forkFromBlock)) {
|
|
1245
|
+
const chain = await createForkedHead(forkFromBlock, account, chainService);
|
|
1246
|
+
await submitNewChain(chain, chainArchivist, chainSubmissionsArchivistWrite);
|
|
1247
|
+
const newBlock = assertEx15(chain.at(-1), () => new Error("Failed to get new head after forking"));
|
|
1248
|
+
head = newBlock[0];
|
|
1249
|
+
}
|
|
1250
|
+
} else {
|
|
1251
|
+
const genesisBlock = await createBootstrapHead(account);
|
|
1252
|
+
await submitNewChain([
|
|
1253
|
+
genesisBlock
|
|
1254
|
+
], chainArchivist, chainSubmissionsArchivistWrite);
|
|
1255
|
+
head = genesisBlock[0];
|
|
1256
|
+
}
|
|
1059
1257
|
headSingleton = head;
|
|
1060
1258
|
return headSingleton;
|
|
1061
1259
|
}, "initHead");
|
|
@@ -1100,7 +1298,7 @@ var initBlockProducer = /* @__PURE__ */ __name(async (params) => {
|
|
|
1100
1298
|
}, "initBlockProducer");
|
|
1101
1299
|
|
|
1102
1300
|
// src/orchestration/services/implementation/reward.ts
|
|
1103
|
-
import { assertEx as
|
|
1301
|
+
import { assertEx as assertEx16 } from "@xylabs/assert";
|
|
1104
1302
|
import { EvmBlockRewardService, MemoryBlockRewardService } from "@xyo-network/chain-sdk";
|
|
1105
1303
|
var rewardServiceSingleton;
|
|
1106
1304
|
var initBlockRewardService = /* @__PURE__ */ __name((params) => {
|
|
@@ -1122,8 +1320,8 @@ var canUseEvmBlockRewardService = /* @__PURE__ */ __name((params) => canUseEvmPr
|
|
|
1122
1320
|
var initEvmBlockRewardService = /* @__PURE__ */ __name(async (params) => {
|
|
1123
1321
|
if (rewardServiceSingleton) return rewardServiceSingleton;
|
|
1124
1322
|
const { account: paramsAccount } = params;
|
|
1125
|
-
const account =
|
|
1126
|
-
const provider2 =
|
|
1323
|
+
const account = assertEx16(paramsAccount, () => "Error: Account is required");
|
|
1324
|
+
const provider2 = assertEx16(await initEvmProvider(params));
|
|
1127
1325
|
const evmBlockRewardServiceParams = {
|
|
1128
1326
|
...params,
|
|
1129
1327
|
provider: provider2,
|
|
@@ -1225,7 +1423,7 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
1225
1423
|
|
|
1226
1424
|
// src/orchestration/initServices.ts
|
|
1227
1425
|
var isStartable = /* @__PURE__ */ __name((value) => {
|
|
1228
|
-
return
|
|
1426
|
+
return isDefined11(value.start) && typeof value.start === "function";
|
|
1229
1427
|
}, "isStartable");
|
|
1230
1428
|
var initServices = /* @__PURE__ */ __name(async (context) => {
|
|
1231
1429
|
const { config: config3, logger } = context;
|
|
@@ -1289,7 +1487,8 @@ var initServices = /* @__PURE__ */ __name(async (context) => {
|
|
|
1289
1487
|
...initParams,
|
|
1290
1488
|
account,
|
|
1291
1489
|
chainArchivist,
|
|
1292
|
-
chainSubmissionsArchivistWrite
|
|
1490
|
+
chainSubmissionsArchivistWrite,
|
|
1491
|
+
chainService
|
|
1293
1492
|
}));
|
|
1294
1493
|
const [pendingTransactionsService, rewardService, chainIterator, balanceService] = await Promise.all([
|
|
1295
1494
|
startupSpanAsync7("PendingTransactions", () => initPendingTransactions({
|
|
@@ -1346,7 +1545,11 @@ var initServices = /* @__PURE__ */ __name(async (context) => {
|
|
|
1346
1545
|
validateHydratedBlockState,
|
|
1347
1546
|
...initParams
|
|
1348
1547
|
};
|
|
1349
|
-
const
|
|
1548
|
+
const time = await BaseTimeSyncService.create({
|
|
1549
|
+
chainArchivist,
|
|
1550
|
+
chainIterator
|
|
1551
|
+
});
|
|
1552
|
+
const rewardAddress = isDefined11(config3.producer.rewardAddress) ? assertEx17(asAddress2(config3.producer.rewardAddress), () => "Invalid block reward address provided") : account.address;
|
|
1350
1553
|
const producerParams = {
|
|
1351
1554
|
...validatorParams,
|
|
1352
1555
|
name: "Producer",
|
|
@@ -1356,24 +1559,25 @@ var initServices = /* @__PURE__ */ __name(async (context) => {
|
|
|
1356
1559
|
pendingTransactionsService,
|
|
1357
1560
|
rejectedTransactionsArchivist,
|
|
1358
1561
|
rewardAddress,
|
|
1562
|
+
time,
|
|
1359
1563
|
...initParams
|
|
1360
1564
|
};
|
|
1361
1565
|
const producer = await startupSpanAsync7("Producer", () => initBlockProducer(producerParams));
|
|
1362
1566
|
const result = {
|
|
1363
1567
|
account,
|
|
1364
|
-
balanceService,
|
|
1568
|
+
balance: balanceService,
|
|
1365
1569
|
chainArchivist,
|
|
1366
1570
|
chainContractViewer,
|
|
1367
1571
|
chainIterator,
|
|
1368
1572
|
chainStaker,
|
|
1369
1573
|
chainStakeViewer,
|
|
1370
1574
|
chainSubmissionsArchivistWrite,
|
|
1371
|
-
electionService,
|
|
1575
|
+
election: electionService,
|
|
1372
1576
|
pendingBundledTransactionsArchivistWrite,
|
|
1373
|
-
pendingTransactionsService,
|
|
1577
|
+
pendingTransactions: pendingTransactionsService,
|
|
1374
1578
|
producer,
|
|
1375
|
-
rewardService,
|
|
1376
|
-
stakeIntentService
|
|
1579
|
+
reward: rewardService,
|
|
1580
|
+
stakeIntent: stakeIntentService
|
|
1377
1581
|
};
|
|
1378
1582
|
logger?.log("All services created. Starting...");
|
|
1379
1583
|
const startableServices = [
|
|
@@ -1431,16 +1635,16 @@ var XL1LogoColorizedAscii = `\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\
|
|
|
1431
1635
|
// src/initLogger.ts
|
|
1432
1636
|
import { Base as Base2 } from "@xylabs/base";
|
|
1433
1637
|
import { ConsoleLogger, LogLevel, SilentLogger } from "@xylabs/logger";
|
|
1434
|
-
import { isDefined as
|
|
1638
|
+
import { isDefined as isDefined12 } from "@xylabs/typeof";
|
|
1435
1639
|
var initLogger = /* @__PURE__ */ __name((config3) => {
|
|
1436
1640
|
let logger;
|
|
1437
1641
|
if (config3.silent) {
|
|
1438
1642
|
logger = new SilentLogger();
|
|
1439
1643
|
} else {
|
|
1440
1644
|
let level;
|
|
1441
|
-
if (
|
|
1645
|
+
if (isDefined12(config3.logLevel)) {
|
|
1442
1646
|
const parsed = LogLevel[config3.logLevel.toLowerCase()];
|
|
1443
|
-
if (
|
|
1647
|
+
if (isDefined12(parsed)) level = parsed;
|
|
1444
1648
|
}
|
|
1445
1649
|
logger = new ConsoleLogger(level);
|
|
1446
1650
|
}
|
|
@@ -1466,7 +1670,7 @@ var optionsFromGlobalZodRegistry = /* @__PURE__ */ __name(() => {
|
|
|
1466
1670
|
}, "optionsFromGlobalZodRegistry");
|
|
1467
1671
|
|
|
1468
1672
|
// src/tryParseConfig.ts
|
|
1469
|
-
import { isDefined as
|
|
1673
|
+
import { isDefined as isDefined13, isNull } from "@xylabs/typeof";
|
|
1470
1674
|
import { cosmiconfigSync } from "cosmiconfig";
|
|
1471
1675
|
var configName = "xyo";
|
|
1472
1676
|
var configSection = "xl1";
|
|
@@ -1475,7 +1679,7 @@ var tryParseConfig = /* @__PURE__ */ __name(() => {
|
|
|
1475
1679
|
const result = explorer.search();
|
|
1476
1680
|
if (!isNull(result)) {
|
|
1477
1681
|
const section = result?.config?.[configSection];
|
|
1478
|
-
if (
|
|
1682
|
+
if (isDefined13(section) && typeof section === "object") {
|
|
1479
1683
|
return section;
|
|
1480
1684
|
}
|
|
1481
1685
|
}
|
|
@@ -1505,7 +1709,7 @@ var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
|
|
|
1505
1709
|
|
|
1506
1710
|
// src/runCLI.ts
|
|
1507
1711
|
var config;
|
|
1508
|
-
var version =
|
|
1712
|
+
var version = isDefined14("1.14.2") ? "1.14.2" : "unknown";
|
|
1509
1713
|
var getContextFromConfig = /* @__PURE__ */ __name((config3) => {
|
|
1510
1714
|
const logger = initLogger(config3);
|
|
1511
1715
|
const orchestrator = new Orchestrator(logger);
|