@xyo-network/chain-services 1.19.14 → 1.19.15
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/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +14 -262
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +4 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +27 -22
- package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +1 -1
- package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +1 -1
- package/src/index.ts +0 -1
- package/src/simple/block/runner/SimpleBlockRunner.ts +10 -11
- package/src/simple/block/runner/generateTransactionFeeTransfers.ts +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +0 -47
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +0 -1
- package/dist/neutral/StakeIntent/index.d.ts +0 -3
- package/dist/neutral/StakeIntent/index.d.ts.map +0 -1
- package/dist/neutral/StakeIntent/lib/getBlockSignedStakeDeclarations.d.ts +0 -4
- package/dist/neutral/StakeIntent/lib/getBlockSignedStakeDeclarations.d.ts.map +0 -1
- package/dist/neutral/StakeIntent/lib/index.d.ts +0 -2
- package/dist/neutral/StakeIntent/lib/index.d.ts.map +0 -1
- package/src/StakeIntent/XyoStakeIntentService.ts +0 -259
- package/src/StakeIntent/index.ts +0 -2
- package/src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts +0 -47
- package/src/StakeIntent/lib/index.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundledPayloadToHydratedTransaction.d.ts","sourceRoot":"","sources":["../../../src/PendingTransactions/bundledPayloadToHydratedTransaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundledPayloadToHydratedTransaction.d.ts","sourceRoot":"","sources":["../../../src/PendingTransactions/bundledPayloadToHydratedTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEhF,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,sBAAsB,CAAA;AAGjF,eAAO,MAAM,mCAAmC,GAC9C,SAAS,eAAe,CAAC,aAAa,CAAC,KACtC,OAAO,CAAC,qCAAqC,GAAG,SAAS,CAM3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydratedTransactionToPayloadBundle.d.ts","sourceRoot":"","sources":["../../../src/PendingTransactions/hydratedTransactionToPayloadBundle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hydratedTransactionToPayloadBundle.d.ts","sourceRoot":"","sources":["../../../src/PendingTransactions/hydratedTransactionToPayloadBundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAG/D,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,sBAAsB,CAAA;AAGjF,eAAO,MAAM,kCAAkC,GAAI,aAAa,qCAAqC,KAAG,aAGvG,CAAA"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -6,6 +6,5 @@ export * from './model/index.ts';
|
|
|
6
6
|
export * from './NetworkStakeStepReward/index.ts';
|
|
7
7
|
export * from './PendingTransactions/index.ts';
|
|
8
8
|
export * from './simple/index.ts';
|
|
9
|
-
export * from './StakeIntent/index.ts';
|
|
10
9
|
export * from './StepStake/index.ts';
|
|
11
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mBAAmB,CAAA;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -244,7 +244,7 @@ import { AbstractCreatableProvider as AbstractCreatableProvider4, asBlockBoundWi
|
|
|
244
244
|
import { Mutex } from "async-mutex";
|
|
245
245
|
|
|
246
246
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
247
|
-
import { PayloadBuilder } from "@xyo-network/
|
|
247
|
+
import { PayloadBuilder } from "@xyo-network/sdk-js";
|
|
248
248
|
import { asSignedTransactionBoundWitnessWithHashMeta } from "@xyo-network/xl1-sdk";
|
|
249
249
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
250
250
|
const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads);
|
|
@@ -258,8 +258,8 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
258
258
|
}, "bundledPayloadToHydratedTransaction");
|
|
259
259
|
|
|
260
260
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
261
|
-
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
262
261
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
262
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
263
263
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-sdk";
|
|
264
264
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
265
265
|
const root = transaction[0]._hash;
|
|
@@ -538,13 +538,13 @@ import { assertEx as assertEx5, exists as exists2, hexToBigInt, isDefined as isD
|
|
|
538
538
|
import { MemoryArchivist as MemoryArchivist2 } from "@xyo-network/archivist-memory";
|
|
539
539
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
540
540
|
import { buildNextBlock as buildNextBlock2 } from "@xyo-network/chain-protocol";
|
|
541
|
-
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/
|
|
541
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/sdk-js";
|
|
542
542
|
import { AbstractCreatableProvider as AbstractCreatableProvider5, AccountBalanceViewerMoniker, asBlockBoundWitness, AttoXL1, BlockNumberSchema, BlockRewardViewerMoniker as BlockRewardViewerMoniker2, BlockRunnerMoniker, BlockValidationViewerMoniker, creatableProvider as creatableProvider4, createDeclarationIntent as createDeclarationIntent2, defaultRewardRatio, isSignedHydratedBlockWithHashMeta, MempoolRunnerMoniker, MempoolViewerMoniker as MempoolViewerMoniker2, TimeSyncViewerMoniker, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-sdk";
|
|
543
543
|
|
|
544
544
|
// src/simple/block/runner/generateTransactionFeeTransfers.ts
|
|
545
545
|
import { hexFromBigInt } from "@xylabs/sdk-js";
|
|
546
546
|
import { assertEx as assertEx4 } from "@xylabs/sdk-js";
|
|
547
|
-
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/
|
|
547
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
548
548
|
import { HydratedTransactionWrapper, transactionRequiredGas, TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-sdk";
|
|
549
549
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
550
550
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
@@ -662,9 +662,9 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
662
662
|
get chainId() {
|
|
663
663
|
return this._chainId;
|
|
664
664
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
665
|
+
get heartbeatInterval() {
|
|
666
|
+
return this.params.heartbeatInterval ?? 36e5;
|
|
667
|
+
}
|
|
668
668
|
get mempoolRunner() {
|
|
669
669
|
return this._mempoolRunner;
|
|
670
670
|
}
|
|
@@ -699,7 +699,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
699
699
|
this._chainId = this.context.config.chain.id;
|
|
700
700
|
this._mempoolRunner = await this.locateAndCreate(MempoolRunnerMoniker);
|
|
701
701
|
this._mempoolViewer = await this.locateAndCreate(MempoolViewerMoniker2);
|
|
702
|
-
this._rewardAddress = this.params.rewardAddress
|
|
702
|
+
this._rewardAddress = this.params.rewardAddress;
|
|
703
703
|
this._timeSyncViewer = await this.locateAndCreate(TimeSyncViewerMoniker);
|
|
704
704
|
}
|
|
705
705
|
async next(head) {
|
|
@@ -737,7 +737,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
737
737
|
* @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
|
|
738
738
|
*/
|
|
739
739
|
getProducerRedeclaration(head) {
|
|
740
|
-
if (this.params.
|
|
740
|
+
if (this.params.disableIntentRedeclaration) return;
|
|
741
741
|
const currentBlock = head.block;
|
|
742
742
|
return createDeclarationIntent2(this.address, "producer", currentBlock, currentBlock + _SimpleBlockRunner.RedeclarationDuration);
|
|
743
743
|
}
|
|
@@ -832,11 +832,8 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
832
832
|
*/
|
|
833
833
|
heartbeatRequired(head) {
|
|
834
834
|
const epoch = head.$epoch;
|
|
835
|
-
if (isDefined2(epoch)) {
|
|
836
|
-
|
|
837
|
-
if (Date.now() - epoch > heartbeatInterval) {
|
|
838
|
-
return true;
|
|
839
|
-
}
|
|
835
|
+
if (isDefined2(epoch) && Date.now() - epoch > this.heartbeatInterval) {
|
|
836
|
+
return true;
|
|
840
837
|
}
|
|
841
838
|
return false;
|
|
842
839
|
}
|
|
@@ -845,252 +842,9 @@ SimpleBlockRunner = _ts_decorate5([
|
|
|
845
842
|
creatableProvider4()
|
|
846
843
|
], SimpleBlockRunner);
|
|
847
844
|
|
|
848
|
-
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
849
|
-
import { exists as exists3, filterAs as filterAs2 } from "@xylabs/sdk-js";
|
|
850
|
-
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
851
|
-
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
852
|
-
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
853
|
-
import { asChainStakeIntent, ChainStakeIntentSchema } from "@xyo-network/xl1-sdk";
|
|
854
|
-
var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archivist, intent) => {
|
|
855
|
-
const blockData = await archivist.get(block.payload_hashes);
|
|
856
|
-
const bwsFromBlock = blockData.filter((x) => isBoundWitness(x));
|
|
857
|
-
const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
|
|
858
|
-
const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
|
|
859
|
-
return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
|
|
860
|
-
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists3);
|
|
861
|
-
const payloads = await archivist.get(stakeIntentHashes);
|
|
862
|
-
const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
|
|
863
|
-
return stakeIntents;
|
|
864
|
-
}))).flat();
|
|
865
|
-
}, "getBlockSignedStakeDeclarations");
|
|
866
|
-
var filterToValidSignedBoundWitnesses = /* @__PURE__ */ __name(async (bws) => {
|
|
867
|
-
const validBwIndexes = await Promise.all(bws.map((bw) => BoundWitnessWrapper.parse(bw).getValid()));
|
|
868
|
-
return bws.filter((_, index) => validBwIndexes[index]);
|
|
869
|
-
}, "filterToValidSignedBoundWitnesses");
|
|
870
|
-
var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
|
|
871
|
-
return bw.payload_schemas.map((schema, index) => schema === ChainStakeIntentSchema ? bw.payload_hashes[index] : void 0);
|
|
872
|
-
}, "mapBoundWitnessToStakeIntentHashes");
|
|
873
|
-
|
|
874
|
-
// src/StakeIntent/XyoStakeIntentService.ts
|
|
875
|
-
import { asAddress, assertEx as assertEx6, filterAs as filterAs3, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
876
|
-
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
877
|
-
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
878
|
-
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
879
|
-
import { AbstractCreatableProvider as AbstractCreatableProvider6, asChainIndexingServiceStateWithStorageMeta, BlockViewerMoniker as BlockViewerMoniker2, ChainIndexingServiceStateSchema, ChainStakeViewerMoniker, creatableProvider as creatableProvider5, isChainIndexingServiceState, readPayloadMapFromStore, timeBudget } from "@xyo-network/xl1-sdk";
|
|
880
|
-
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, asChainStakeIntent as asChainStakeIntent2 } from "@xyo-network/xl1-sdk";
|
|
881
|
-
import { Mutex as Mutex2 } from "async-mutex";
|
|
882
|
-
import { LRUCache } from "lru-cache";
|
|
883
|
-
function _ts_decorate6(decorators, target, key, desc) {
|
|
884
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
885
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
886
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
887
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
888
|
-
}
|
|
889
|
-
__name(_ts_decorate6, "_ts_decorate");
|
|
890
|
-
var ACTIVE_STAKE_TTL = 1e3 * 60 * 60 * 2;
|
|
891
|
-
var NO_ACTIVE_STAKE_TTL = 1e3 * 2;
|
|
892
|
-
var STAKE_CACHE_MAX_ENTRIES = 1e4;
|
|
893
|
-
var XyoStakeIntentService = class _XyoStakeIntentService extends AbstractCreatableProvider6 {
|
|
894
|
-
static {
|
|
895
|
-
__name(this, "XyoStakeIntentService");
|
|
896
|
-
}
|
|
897
|
-
static defaultMoniker = "StakeIntent";
|
|
898
|
-
static dependencies = [];
|
|
899
|
-
static monikers = [
|
|
900
|
-
_XyoStakeIntentService.defaultMoniker
|
|
901
|
-
];
|
|
902
|
-
moniker = "StakeIntent";
|
|
903
|
-
// TODO: Use hash instead of block number to handle chain reorgs
|
|
904
|
-
_lastIndexedBlockHash = void 0;
|
|
905
|
-
// TODO: Interval tree per declaration (bank, validator, etc.)
|
|
906
|
-
// Ideally move to DataIntervalTree to handle declared
|
|
907
|
-
// ranges as it enables range queries in O(min(n, k * log n)) time,
|
|
908
|
-
// where k is the number of intervals in the output list time
|
|
909
|
-
// Currently using set based because it's simpler, equivalent
|
|
910
|
-
// in performance for small sets, and (most importantly) easily
|
|
911
|
-
// persisted so we can recover state on restart.
|
|
912
|
-
_producers = new IntervalMap();
|
|
913
|
-
_stakeCache = new LRUCache({
|
|
914
|
-
max: STAKE_CACHE_MAX_ENTRIES
|
|
915
|
-
});
|
|
916
|
-
_updateMutex = new Mutex2();
|
|
917
|
-
_blockViewer;
|
|
918
|
-
_chainStakeViewer;
|
|
919
|
-
get blockViewer() {
|
|
920
|
-
return this._blockViewer;
|
|
921
|
-
}
|
|
922
|
-
get chainArchivist() {
|
|
923
|
-
return assertEx6(this.params.chainArchivist, () => "chainArchivist not set");
|
|
924
|
-
}
|
|
925
|
-
get chainStakeViewer() {
|
|
926
|
-
return this._chainStakeViewer;
|
|
927
|
-
}
|
|
928
|
-
get stakeIntentStateArchivist() {
|
|
929
|
-
return assertEx6(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
|
|
930
|
-
}
|
|
931
|
-
static async paramsHandler(params) {
|
|
932
|
-
return {
|
|
933
|
-
...await super.paramsHandler(params),
|
|
934
|
-
chainArchivist: assertEx6(params?.chainArchivist, () => "chainArchivist is required"),
|
|
935
|
-
stakeIntentStateArchivist: assertEx6(params?.stakeIntentStateArchivist, () => "stakeIntentStateArchivist is required")
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
async createHandler() {
|
|
939
|
-
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker2);
|
|
940
|
-
this._chainStakeViewer = await this.locator.getInstance(ChainStakeViewerMoniker);
|
|
941
|
-
const head = await this.blockViewer.currentBlock();
|
|
942
|
-
if (isUndefined2(head)) return;
|
|
943
|
-
await this.recoverState(head[0]._hash);
|
|
944
|
-
}
|
|
945
|
-
async getDeclaredCandidateRanges(address, intent) {
|
|
946
|
-
await Promise.resolve();
|
|
947
|
-
assertEx6(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
948
|
-
const results = this._producers.get(address);
|
|
949
|
-
return results ?? [];
|
|
950
|
-
}
|
|
951
|
-
async getDeclaredCandidatesForBlock(block, intent) {
|
|
952
|
-
return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
|
|
953
|
-
assertEx6(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
954
|
-
const results = this._producers.findAllContaining(block);
|
|
955
|
-
const candidates = [
|
|
956
|
-
...results
|
|
957
|
-
];
|
|
958
|
-
const requiredMinimumStake = this.getRequiredMinimumStakeForIntent(intent);
|
|
959
|
-
const validCandidates = await this.filterToValidStake(candidates, this.chainStakeViewer, requiredMinimumStake);
|
|
960
|
-
return validCandidates;
|
|
961
|
-
}, this.context);
|
|
962
|
-
}
|
|
963
|
-
getRequiredMinimumStakeForIntent(intent) {
|
|
964
|
-
switch (intent) {
|
|
965
|
-
case "producer": {
|
|
966
|
-
const { minStake } = this.params.context.config.actors.producer;
|
|
967
|
-
return BigInt(minStake);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
async isStakedForBlock(block, intent, address) {
|
|
972
|
-
const candidates = await this.getDeclaredCandidatesForBlock(block, intent);
|
|
973
|
-
return candidates.includes(address);
|
|
974
|
-
}
|
|
975
|
-
async startHandler() {
|
|
976
|
-
await this.updateIndex(true);
|
|
977
|
-
}
|
|
978
|
-
async filterToValidStake(candidates, chainStakeViewer, requiredMinimumStake) {
|
|
979
|
-
const candidatesWithStake = await Promise.all(candidates.map(async (candidate) => {
|
|
980
|
-
const stake = this._stakeCache.get(candidate);
|
|
981
|
-
if (stake === void 0) {
|
|
982
|
-
const activeStake = await chainStakeViewer.activeByStaked(candidate);
|
|
983
|
-
if (activeStake > 0n) {
|
|
984
|
-
this._stakeCache.set(candidate, activeStake, {
|
|
985
|
-
ttl: ACTIVE_STAKE_TTL
|
|
986
|
-
});
|
|
987
|
-
} else {
|
|
988
|
-
this._stakeCache.set(candidate, activeStake, {
|
|
989
|
-
ttl: NO_ACTIVE_STAKE_TTL
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
return {
|
|
993
|
-
candidate,
|
|
994
|
-
stake: activeStake
|
|
995
|
-
};
|
|
996
|
-
} else {
|
|
997
|
-
return {
|
|
998
|
-
candidate,
|
|
999
|
-
stake
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
}));
|
|
1003
|
-
return candidatesWithStake.filter(({ stake }) => stake >= requiredMinimumStake).map(({ candidate }) => candidate);
|
|
1004
|
-
}
|
|
1005
|
-
async persistState(current) {
|
|
1006
|
-
const state = this._producers.serialize();
|
|
1007
|
-
const payload = new PayloadBuilder5({
|
|
1008
|
-
schema: ChainIndexingServiceStateSchema
|
|
1009
|
-
}).fields({
|
|
1010
|
-
endBlockHash: current,
|
|
1011
|
-
state
|
|
1012
|
-
}).build();
|
|
1013
|
-
await this.stakeIntentStateArchivist.insert([
|
|
1014
|
-
payload
|
|
1015
|
-
]);
|
|
1016
|
-
}
|
|
1017
|
-
async recoverState(current) {
|
|
1018
|
-
return await timeBudget("XyoStakeIntentService.recoverState", console, async () => {
|
|
1019
|
-
const currentBlock = assertEx6(asBlockBoundWitness2((await this.chainArchivist.get([
|
|
1020
|
-
current
|
|
1021
|
-
]))?.[0]), () => `Block ${current} not found`);
|
|
1022
|
-
const currentBlockNum = currentBlock.block;
|
|
1023
|
-
const opts = {
|
|
1024
|
-
...DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS
|
|
1025
|
-
};
|
|
1026
|
-
while (true) {
|
|
1027
|
-
const predicate = /* @__PURE__ */ __name((p) => {
|
|
1028
|
-
const state2 = asChainIndexingServiceStateWithStorageMeta(p);
|
|
1029
|
-
return state2 ? true : false;
|
|
1030
|
-
}, "predicate");
|
|
1031
|
-
const state = await findFirstMatching(this.stakeIntentStateArchivist, predicate, opts);
|
|
1032
|
-
if (isChainIndexingServiceState(state)) {
|
|
1033
|
-
const indexed = (await this.chainArchivist.get([
|
|
1034
|
-
state.endBlockHash
|
|
1035
|
-
]))?.[0];
|
|
1036
|
-
const indexedBlock = asBlockBoundWitnessWithStorageMeta(indexed);
|
|
1037
|
-
if (indexedBlock) {
|
|
1038
|
-
const indexedBlockNum = indexedBlock.block;
|
|
1039
|
-
if (indexedBlockNum <= currentBlockNum) {
|
|
1040
|
-
const data = state.state;
|
|
1041
|
-
this._producers = new IntervalMap(data);
|
|
1042
|
-
this._lastIndexedBlockHash = indexedBlock._hash;
|
|
1043
|
-
break;
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
} else {
|
|
1047
|
-
break;
|
|
1048
|
-
}
|
|
1049
|
-
opts.open = true;
|
|
1050
|
-
}
|
|
1051
|
-
}, 2e3, true);
|
|
1052
|
-
}
|
|
1053
|
-
async updateIndex(displayProgress = false) {
|
|
1054
|
-
if (this._updateMutex.isLocked()) {
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
await this._updateMutex.runExclusive(async () => {
|
|
1058
|
-
return await this.spanAsync("updateIndex", async () => {
|
|
1059
|
-
const currentHead = (await this.blockViewer.currentBlock())[0];
|
|
1060
|
-
if (isUndefined2(currentHead)) return;
|
|
1061
|
-
const currentHeadHash = currentHead._hash;
|
|
1062
|
-
const chainMap = readPayloadMapFromStore(this.chainArchivist);
|
|
1063
|
-
const result = await analyzeChain({
|
|
1064
|
-
...this.context,
|
|
1065
|
-
chainMap
|
|
1066
|
-
}, [
|
|
1067
|
-
new ChainStakeIntentAnalyzer("producer")
|
|
1068
|
-
], currentHeadHash, this._lastIndexedBlockHash);
|
|
1069
|
-
const signedDeclarations = filterAs3(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent2);
|
|
1070
|
-
if (currentHead.block === void 0) return;
|
|
1071
|
-
const currentHeadBlockNum = currentHead.block;
|
|
1072
|
-
if (displayProgress) this.logger?.log(`Updating index through 0x${currentHeadBlockNum}`);
|
|
1073
|
-
for (const signedDeclaration of signedDeclarations) {
|
|
1074
|
-
const { exp, nbf } = signedDeclaration;
|
|
1075
|
-
const start = nbf;
|
|
1076
|
-
const stop = exp;
|
|
1077
|
-
const address = asAddress(signedDeclaration?.from);
|
|
1078
|
-
if (start !== void 0 && stop !== void 0 && address !== void 0) {
|
|
1079
|
-
this._producers.insert(address, start, stop);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
this._lastIndexedBlockHash = currentHeadHash;
|
|
1083
|
-
}, this.context);
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
XyoStakeIntentService = _ts_decorate6([
|
|
1088
|
-
creatableProvider5()
|
|
1089
|
-
], XyoStakeIntentService);
|
|
1090
|
-
|
|
1091
845
|
// src/StepStake/BaseStepStakeService.ts
|
|
1092
|
-
import { AbstractCreatableProvider as
|
|
1093
|
-
var AbstractStepStakeService = class _AbstractStepStakeService extends
|
|
846
|
+
import { AbstractCreatableProvider as AbstractCreatableProvider6, StepStakeViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
847
|
+
var AbstractStepStakeService = class _AbstractStepStakeService extends AbstractCreatableProvider6 {
|
|
1094
848
|
static {
|
|
1095
849
|
__name(this, "AbstractStepStakeService");
|
|
1096
850
|
}
|
|
@@ -1116,9 +870,7 @@ export {
|
|
|
1116
870
|
SimpleBlockRunner,
|
|
1117
871
|
XYO_PRODUCER_REDECLARATION_DURATION,
|
|
1118
872
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1119
|
-
XyoStakeIntentService,
|
|
1120
873
|
XyoValidator,
|
|
1121
|
-
createBootstrapHead
|
|
1122
|
-
getBlockSignedStakeDeclarations
|
|
874
|
+
createBootstrapHead
|
|
1123
875
|
};
|
|
1124
876
|
//# sourceMappingURL=index.mjs.map
|