@xyo-network/chain-services 1.15.2 → 1.15.4
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/README.md +5302 -2235
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +3 -5
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +3 -6
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +3 -3
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +3 -3
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +3 -2
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts +4 -4
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +15 -13
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +2 -2
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +3 -3
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/index.mjs +118 -151
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +40 -40
- package/src/AccountBalance/BaseAccountBalanceService.ts +6 -8
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +22 -33
- package/src/AccountTransfers/BaseAccountTransfersService.ts +4 -12
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +22 -35
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +62 -8
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +11 -11
- package/src/ChainBlockNumberIteration/model/Params.ts +3 -2
- package/src/ChainService/Evm/Evm.ts +8 -8
- package/src/ChainService/Memory/Memory.ts +1 -1
- package/src/ChainValidator/XyoValidator.ts +2 -2
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +24 -14
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +4 -2
- package/src/StepStake/BaseStepStakeService.ts +3 -3
package/dist/neutral/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { ZERO_HASH } from "@xylabs/hex";
|
|
6
|
+
import { LruCacheMap } from "@xyo-network/chain-protocol";
|
|
7
|
+
import { StepSizes } from "@xyo-network/xl1-protocol";
|
|
8
|
+
import { readPayloadMapFromStore } from "@xyo-network/xl1-protocol-sdk";
|
|
9
|
+
import { Semaphore } from "async-mutex";
|
|
9
10
|
|
|
10
11
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
11
12
|
import { creatable as creatable2 } from "@xylabs/creatable";
|
|
@@ -80,11 +81,7 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
80
81
|
}
|
|
81
82
|
async balances(head, address) {
|
|
82
83
|
return await spanRootAsync2("balances", async () => {
|
|
83
|
-
const summary = await balancesSummary(
|
|
84
|
-
chainArchivist: this.params.chainArchivist,
|
|
85
|
-
summaryRepository: this.params.summaryRepository,
|
|
86
|
-
head
|
|
87
|
-
});
|
|
84
|
+
const summary = await balancesSummary(this.params.context);
|
|
88
85
|
const result = {};
|
|
89
86
|
for (const addr of address) {
|
|
90
87
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -99,46 +96,34 @@ BaseAccountBalanceService = _ts_decorate2([
|
|
|
99
96
|
], BaseAccountBalanceService);
|
|
100
97
|
|
|
101
98
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
102
|
-
var
|
|
103
|
-
const
|
|
99
|
+
var accountBalancesServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
100
|
+
const summaryMap = new LruCacheMap({
|
|
104
101
|
max: 1e5,
|
|
105
102
|
allowStale: true,
|
|
106
103
|
noDisposeOnSet: false,
|
|
107
104
|
updateAgeOnGet: true
|
|
108
105
|
});
|
|
109
|
-
const
|
|
110
|
-
get: /* @__PURE__ */ __name((hashes) => {
|
|
111
|
-
const results = hashes.map((hash) => {
|
|
112
|
-
return summaryArchivistCache.get(hash);
|
|
113
|
-
}).filter(exists);
|
|
114
|
-
return results;
|
|
115
|
-
}, "get"),
|
|
116
|
-
insert: /* @__PURE__ */ __name(async (payloads) => {
|
|
117
|
-
const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
|
|
118
|
-
const hash = asHash(payload.hash);
|
|
119
|
-
if (isHash(hash)) {
|
|
120
|
-
summaryArchivistCache.set(hash, payload);
|
|
121
|
-
return payload;
|
|
122
|
-
}
|
|
123
|
-
}).filter(exists);
|
|
124
|
-
return results;
|
|
125
|
-
}, "insert"),
|
|
126
|
-
next: /* @__PURE__ */ __name(() => {
|
|
127
|
-
throw new Error("Not implemented");
|
|
128
|
-
}, "next")
|
|
129
|
-
};
|
|
106
|
+
const chainMap = readPayloadMapFromStore(archivist);
|
|
130
107
|
const service = await BaseAccountBalanceService.create({
|
|
131
|
-
|
|
132
|
-
|
|
108
|
+
context: {
|
|
109
|
+
chainId,
|
|
110
|
+
store: {
|
|
111
|
+
chainMap
|
|
112
|
+
},
|
|
113
|
+
stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
114
|
+
summaryMap,
|
|
115
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH, "head")
|
|
116
|
+
}
|
|
133
117
|
});
|
|
134
118
|
return service;
|
|
135
|
-
}, "
|
|
119
|
+
}, "accountBalancesServiceFromArchivist");
|
|
136
120
|
|
|
137
121
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
138
|
-
import {
|
|
139
|
-
import {
|
|
140
|
-
import {
|
|
141
|
-
import {
|
|
122
|
+
import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
123
|
+
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/chain-protocol";
|
|
124
|
+
import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
125
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
126
|
+
import { Semaphore as Semaphore2 } from "async-mutex";
|
|
142
127
|
|
|
143
128
|
// src/AccountTransfers/BaseAccountTransfersService.ts
|
|
144
129
|
import { creatable as creatable3 } from "@xylabs/creatable";
|
|
@@ -163,13 +148,7 @@ var BaseAccountTransfersService = class extends BaseService {
|
|
|
163
148
|
}
|
|
164
149
|
async transfers(head, addresses) {
|
|
165
150
|
return await spanRootAsync3("transfers", async () => {
|
|
166
|
-
const
|
|
167
|
-
const summary = await transfersSummary({
|
|
168
|
-
chainArchivist,
|
|
169
|
-
summaryRepository,
|
|
170
|
-
head,
|
|
171
|
-
account
|
|
172
|
-
});
|
|
151
|
+
const summary = await transfersSummary(this.params.context);
|
|
173
152
|
const result = {};
|
|
174
153
|
for (const addr of addresses) {
|
|
175
154
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -184,65 +163,51 @@ BaseAccountTransfersService = _ts_decorate3([
|
|
|
184
163
|
], BaseAccountTransfersService);
|
|
185
164
|
|
|
186
165
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
187
|
-
var
|
|
188
|
-
const
|
|
166
|
+
var accountTransfersServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
167
|
+
const summaryMap = new LruCacheMap2({
|
|
189
168
|
max: 1e5,
|
|
190
169
|
allowStale: true,
|
|
191
170
|
noDisposeOnSet: false,
|
|
192
171
|
updateAgeOnGet: true
|
|
193
172
|
});
|
|
194
|
-
const
|
|
195
|
-
get: /* @__PURE__ */ __name((hashes) => {
|
|
196
|
-
const results = hashes.map((hash) => {
|
|
197
|
-
return summaryArchivistCache.get(hash);
|
|
198
|
-
}).filter(exists2);
|
|
199
|
-
return results;
|
|
200
|
-
}, "get"),
|
|
201
|
-
insert: /* @__PURE__ */ __name(async (payloads) => {
|
|
202
|
-
const results = (await PayloadBuilder2.addStorageMeta(payloads)).map((payload) => {
|
|
203
|
-
const hash = asHash2(payload.hash);
|
|
204
|
-
if (isHash2(hash)) {
|
|
205
|
-
summaryArchivistCache.set(hash, payload);
|
|
206
|
-
return payload;
|
|
207
|
-
}
|
|
208
|
-
}).filter(exists2);
|
|
209
|
-
return results;
|
|
210
|
-
}, "insert"),
|
|
211
|
-
next: /* @__PURE__ */ __name(() => {
|
|
212
|
-
throw new Error("Not implemented");
|
|
213
|
-
}, "next")
|
|
214
|
-
};
|
|
173
|
+
const chainMap = readPayloadMapFromStore2(archivist);
|
|
215
174
|
const service = await BaseAccountTransfersService.create({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
175
|
+
context: {
|
|
176
|
+
chainId,
|
|
177
|
+
store: {
|
|
178
|
+
chainMap
|
|
179
|
+
},
|
|
180
|
+
stepSemaphores: StepSizes2.map(() => new Semaphore2(20)),
|
|
181
|
+
summaryMap,
|
|
182
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH2, "head")
|
|
183
|
+
}
|
|
219
184
|
});
|
|
220
185
|
return service;
|
|
221
|
-
}, "
|
|
186
|
+
}, "accountTransfersServiceFromArchivist");
|
|
222
187
|
|
|
223
188
|
// src/BlockProducer/BaseBlockProducerService.ts
|
|
224
189
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
225
190
|
import { creatable as creatable4 } from "@xylabs/creatable";
|
|
226
|
-
import { exists
|
|
191
|
+
import { exists } from "@xylabs/exists";
|
|
227
192
|
import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
228
193
|
import { isDefined } from "@xylabs/typeof";
|
|
229
194
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
230
195
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
231
|
-
import { PayloadBuilder as
|
|
196
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
232
197
|
import { asBlockBoundWitness, AttoXL1 as AttoXL13, BlockNumberSchema, defaultRewardRatio, TimeSchema, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
233
198
|
|
|
234
199
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
235
200
|
import { assertEx } from "@xylabs/assert";
|
|
236
201
|
import { hexFromBigInt } from "@xylabs/hex";
|
|
237
|
-
import { PayloadBuilder
|
|
202
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
238
203
|
import { TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
239
204
|
import { transactionRequiredGas } from "@xyo-network/xl1-protocol-sdk";
|
|
240
205
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
241
206
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
242
207
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
243
208
|
return HydratedTransactionWrapper.parse([
|
|
244
|
-
await
|
|
245
|
-
await
|
|
209
|
+
await PayloadBuilder.addStorageMeta(tx[0]),
|
|
210
|
+
await PayloadBuilder.addStorageMeta(tx[1])
|
|
246
211
|
]);
|
|
247
212
|
}));
|
|
248
213
|
const txBaseFeeCosts = {};
|
|
@@ -369,7 +334,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
369
334
|
});
|
|
370
335
|
}
|
|
371
336
|
const blockHex = assertEx2(toHex(block), () => "Failed to convert block to hex");
|
|
372
|
-
const blockId = new
|
|
337
|
+
const blockId = new PayloadBuilder2({
|
|
373
338
|
schema: BlockNumberSchema
|
|
374
339
|
}).fields({
|
|
375
340
|
block: blockHex
|
|
@@ -454,7 +419,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
454
419
|
fundedTransfers.push(transfer);
|
|
455
420
|
return tx;
|
|
456
421
|
}
|
|
457
|
-
}))).filter(
|
|
422
|
+
}))).filter(exists);
|
|
458
423
|
this.logger?.info(`Filtered ${txs.length} transactions to ${fundedTransactions.length} funded transactions in ${Date.now() - start}ms`);
|
|
459
424
|
return [
|
|
460
425
|
fundedTransactions,
|
|
@@ -618,33 +583,31 @@ MemoryBlockRewardService = _ts_decorate7([
|
|
|
618
583
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
619
584
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
620
585
|
import { isDefined as isDefined2, isNull, isUndefined } from "@xylabs/typeof";
|
|
621
|
-
import { PayloadBuilder as
|
|
586
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
622
587
|
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashStorageMeta } from "@xyo-network/xl1-protocol";
|
|
623
|
-
import { LRUCache
|
|
588
|
+
import { LRUCache } from "lru-cache";
|
|
624
589
|
var ChainBlockNumberIterationService = class extends BaseService {
|
|
625
590
|
static {
|
|
626
591
|
__name(this, "ChainBlockNumberIterationService");
|
|
627
592
|
}
|
|
628
|
-
_blocksByBlockNumber = new
|
|
593
|
+
_blocksByBlockNumber = new LRUCache({
|
|
629
594
|
max: 1e4
|
|
630
595
|
});
|
|
631
596
|
_currentHead;
|
|
632
|
-
get chainArchivist() {
|
|
633
|
-
return assertEx5(this.params.chainArchivist);
|
|
634
|
-
}
|
|
635
597
|
get chainId() {
|
|
636
598
|
return assertEx5(this._currentHead?.chain ?? this.params?.head?.chain, () => "Current head is not set");
|
|
637
599
|
}
|
|
600
|
+
get chainMap() {
|
|
601
|
+
return assertEx5(this.params.chainMap);
|
|
602
|
+
}
|
|
638
603
|
async get(block) {
|
|
639
604
|
const head = await this.head();
|
|
640
605
|
assertEx5(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
|
|
641
606
|
const cached = this._blocksByBlockNumber.get(block);
|
|
642
607
|
if (cached) return cached;
|
|
643
608
|
const startingBlock = head;
|
|
644
|
-
const currentBlockHash = await
|
|
645
|
-
let currentBlock =
|
|
646
|
-
currentBlockHash
|
|
647
|
-
])).at(0);
|
|
609
|
+
const currentBlockHash = await PayloadBuilder3.hash(startingBlock);
|
|
610
|
+
let currentBlock = await this.chainMap.get(currentBlockHash);
|
|
648
611
|
while (isDefined2(currentBlock)) {
|
|
649
612
|
assertEx5(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
|
|
650
613
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
@@ -654,9 +617,7 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
654
617
|
}
|
|
655
618
|
const { previous } = currentBlock;
|
|
656
619
|
if (isNull(previous)) break;
|
|
657
|
-
currentBlock =
|
|
658
|
-
previous
|
|
659
|
-
])).at(0);
|
|
620
|
+
currentBlock = await this.chainMap.get(previous);
|
|
660
621
|
}
|
|
661
622
|
}
|
|
662
623
|
throw new Error(`Block not found: ${block}`);
|
|
@@ -680,17 +641,15 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
680
641
|
async previous(block = void 0, count = 1) {
|
|
681
642
|
const results = [];
|
|
682
643
|
let currentBlock = isDefined2(block) ? await this.get(block) : await this.head();
|
|
683
|
-
while (currentBlock && results.length < count) {
|
|
644
|
+
while (isDefined2(currentBlock) && results.length < count) {
|
|
684
645
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
685
646
|
results.push(currentBlock);
|
|
686
647
|
const { previous } = currentBlock;
|
|
687
648
|
if (isNull(previous)) break;
|
|
688
|
-
const nextBlock = await this.
|
|
689
|
-
|
|
690
|
-
]);
|
|
691
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0]);
|
|
649
|
+
const nextBlock = await this.chainMap.get(previous);
|
|
650
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock);
|
|
692
651
|
} else {
|
|
693
|
-
const hash =
|
|
652
|
+
const hash = PayloadBuilder3.hash(currentBlock);
|
|
694
653
|
assertEx5(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
|
|
695
654
|
}
|
|
696
655
|
}
|
|
@@ -706,10 +665,8 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
706
665
|
});
|
|
707
666
|
}
|
|
708
667
|
async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head) {
|
|
709
|
-
const hash = await
|
|
710
|
-
const stored =
|
|
711
|
-
hash
|
|
712
|
-
])).at(-1);
|
|
668
|
+
const hash = await PayloadBuilder3.hash(head);
|
|
669
|
+
const stored = await this.chainMap.get(hash);
|
|
713
670
|
const newHead = asBlockBoundWitnessWithStorageMeta(stored);
|
|
714
671
|
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`);
|
|
715
672
|
return newHead;
|
|
@@ -740,14 +697,14 @@ var EvmChainService = class extends BaseService {
|
|
|
740
697
|
async active() {
|
|
741
698
|
return await this.contract.active();
|
|
742
699
|
}
|
|
743
|
-
async
|
|
744
|
-
return await this.contract.activeByAddressStaked(getAddress(
|
|
700
|
+
async activeByStaked(staked) {
|
|
701
|
+
return await this.contract.activeByAddressStaked(getAddress(toEthAddress2(staked)));
|
|
745
702
|
}
|
|
746
703
|
async activeByStaker(address) {
|
|
747
|
-
return await this.contract.activeByStaker(getAddress(address));
|
|
704
|
+
return await this.contract.activeByStaker(getAddress(toEthAddress2(address)));
|
|
748
705
|
}
|
|
749
706
|
async addStake(staked, amount) {
|
|
750
|
-
const result = await this.contract.addStake(getAddress(staked), amount);
|
|
707
|
+
const result = await this.contract.addStake(getAddress(toEthAddress2(staked)), amount);
|
|
751
708
|
await result.wait();
|
|
752
709
|
return true;
|
|
753
710
|
}
|
|
@@ -767,7 +724,7 @@ var EvmChainService = class extends BaseService {
|
|
|
767
724
|
return await this.contract.pending();
|
|
768
725
|
}
|
|
769
726
|
async pendingByStaker(staker) {
|
|
770
|
-
return await this.contract.pendingByStaker(getAddress(staker));
|
|
727
|
+
return await this.contract.pendingByStaker(getAddress(toEthAddress2(staker)));
|
|
771
728
|
}
|
|
772
729
|
async removeStake(slot) {
|
|
773
730
|
const result = await this.contract.removeStake(slot);
|
|
@@ -806,7 +763,7 @@ var MemoryChainService = class extends BaseService {
|
|
|
806
763
|
async active() {
|
|
807
764
|
return await Promise.resolve(this._simulatedStake);
|
|
808
765
|
}
|
|
809
|
-
async
|
|
766
|
+
async activeByStaked(_staked) {
|
|
810
767
|
return await Promise.resolve(this._simulatedStake);
|
|
811
768
|
}
|
|
812
769
|
async activeByStaker(_address) {
|
|
@@ -912,7 +869,7 @@ XyoValidator = _ts_decorate8([
|
|
|
912
869
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
913
870
|
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
914
871
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
915
|
-
import { PayloadBuilder as
|
|
872
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
916
873
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
917
874
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
918
875
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -937,7 +894,7 @@ var BaseElectionService = class extends BaseService {
|
|
|
937
894
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
938
895
|
const nextBlock = current.block + 1;
|
|
939
896
|
const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
|
|
940
|
-
const previousBlockHash = await
|
|
897
|
+
const previousBlockHash = await PayloadBuilder4.hash(current);
|
|
941
898
|
return this.generateCreatorCommittee(candidates, previousBlockHash);
|
|
942
899
|
});
|
|
943
900
|
}
|
|
@@ -965,43 +922,49 @@ var BaseNetworkStakeStepRewardService = class extends BaseService {
|
|
|
965
922
|
static {
|
|
966
923
|
__name(this, "BaseNetworkStakeStepRewardService");
|
|
967
924
|
}
|
|
968
|
-
|
|
925
|
+
networkStakeStepRewardAddressHistory(_address) {
|
|
969
926
|
throw new Error("Method not implemented.");
|
|
970
927
|
}
|
|
971
|
-
|
|
928
|
+
networkStakeStepRewardAddressReward(_context, _address) {
|
|
972
929
|
throw new Error("Method not implemented.");
|
|
973
930
|
}
|
|
974
|
-
|
|
931
|
+
networkStakeStepRewardAddressShare(_context, _address) {
|
|
975
932
|
throw new Error("Method not implemented.");
|
|
976
933
|
}
|
|
977
|
-
|
|
934
|
+
networkStakeStepRewardClaimedByAddress(_address) {
|
|
978
935
|
throw new Error("Method not implemented.");
|
|
979
936
|
}
|
|
980
|
-
|
|
937
|
+
networkStakeStepRewardForPosition(_position, _range) {
|
|
938
|
+
throw new Error("Method not implemented.");
|
|
939
|
+
}
|
|
940
|
+
networkStakeStepRewardForStep(_context) {
|
|
981
941
|
throw new Error("Method not implemented.");
|
|
982
942
|
}
|
|
983
|
-
|
|
943
|
+
networkStakeStepRewardForStepForPosition(_context, _position) {
|
|
984
944
|
throw new Error("Method not implemented.");
|
|
985
945
|
}
|
|
986
|
-
|
|
946
|
+
networkStakeStepRewardPoolRewards(_context) {
|
|
987
947
|
throw new Error("Method not implemented.");
|
|
988
948
|
}
|
|
989
|
-
|
|
949
|
+
networkStakeStepRewardPoolShares(_context) {
|
|
990
950
|
throw new Error("Method not implemented.");
|
|
991
951
|
}
|
|
992
|
-
|
|
952
|
+
networkStakeStepRewardPositionWeight(_context, _position) {
|
|
993
953
|
throw new Error("Method not implemented.");
|
|
994
954
|
}
|
|
995
|
-
|
|
955
|
+
networkStakeStepRewardPotentialPositionLoss(_context, _position) {
|
|
996
956
|
throw new Error("Method not implemented.");
|
|
997
957
|
}
|
|
998
|
-
|
|
958
|
+
networkStakeStepRewardRandomizer(_context) {
|
|
999
959
|
throw new Error("Method not implemented.");
|
|
1000
960
|
}
|
|
1001
|
-
|
|
961
|
+
networkStakeStepRewardStakerCount(_context) {
|
|
1002
962
|
throw new Error("Method not implemented.");
|
|
1003
963
|
}
|
|
1004
|
-
|
|
964
|
+
networkStakeStepRewardUnclaimedByAddress(_address) {
|
|
965
|
+
throw new Error("Method not implemented.");
|
|
966
|
+
}
|
|
967
|
+
networkStakeStepRewardWeightForAddress(_context, _address) {
|
|
1005
968
|
throw new Error("Method not implemented.");
|
|
1006
969
|
}
|
|
1007
970
|
};
|
|
@@ -1014,7 +977,7 @@ import { ValueType } from "@opentelemetry/api";
|
|
|
1014
977
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
1015
978
|
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
1016
979
|
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1017
|
-
import { exists as
|
|
980
|
+
import { exists as exists2 } from "@xylabs/exists";
|
|
1018
981
|
import { forget } from "@xylabs/forget";
|
|
1019
982
|
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1020
983
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
@@ -1024,10 +987,10 @@ import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-networ
|
|
|
1024
987
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
1025
988
|
|
|
1026
989
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
1027
|
-
import { PayloadBuilder as
|
|
990
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1028
991
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1029
992
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
1030
|
-
const withStorageMeta = await
|
|
993
|
+
const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
|
|
1031
994
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
1032
995
|
if (tx) {
|
|
1033
996
|
return [
|
|
@@ -1038,7 +1001,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
1038
1001
|
}, "bundledPayloadToHydratedTransaction");
|
|
1039
1002
|
|
|
1040
1003
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
1041
|
-
import { PayloadBuilder as
|
|
1004
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1042
1005
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1043
1006
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1044
1007
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -1046,8 +1009,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
1046
1009
|
return bundle(root, transaction);
|
|
1047
1010
|
}, "hydratedTransactionToPayloadBundle");
|
|
1048
1011
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
1049
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
1050
|
-
return new
|
|
1012
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
|
|
1013
|
+
return new PayloadBuilder6({
|
|
1051
1014
|
schema: PayloadBundleSchema
|
|
1052
1015
|
}).fields({
|
|
1053
1016
|
payloads,
|
|
@@ -1169,7 +1132,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1169
1132
|
if (pendingBundledTransactions.length === 0) break;
|
|
1170
1133
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1171
1134
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1172
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1135
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1173
1136
|
const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1));
|
|
1174
1137
|
foundPendingTransactions.push(...activeTransactions);
|
|
1175
1138
|
}
|
|
@@ -1210,7 +1173,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1210
1173
|
const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
|
|
1211
1174
|
const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
|
|
1212
1175
|
return await bundledPayloadToHydratedTransaction(tx);
|
|
1213
|
-
}))).filter(
|
|
1176
|
+
}))).filter(exists2);
|
|
1214
1177
|
const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
|
|
1215
1178
|
const errors = await validateTransaction(tx, this.chainId, [
|
|
1216
1179
|
TransactionJsonSchemaValidator
|
|
@@ -1257,14 +1220,14 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1257
1220
|
}
|
|
1258
1221
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1259
1222
|
const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
|
|
1260
|
-
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(
|
|
1223
|
+
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists2));
|
|
1261
1224
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1262
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1225
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1263
1226
|
const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1));
|
|
1264
1227
|
const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
|
|
1265
1228
|
// Find the corresponding payload bundle hash for the expired transaction
|
|
1266
1229
|
pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
|
|
1267
|
-
)).filter(
|
|
1230
|
+
)).filter(exists2);
|
|
1268
1231
|
foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
|
|
1269
1232
|
}
|
|
1270
1233
|
const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
|
|
@@ -1288,7 +1251,7 @@ var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf
|
|
|
1288
1251
|
|
|
1289
1252
|
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
1290
1253
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
1291
|
-
import { exists as
|
|
1254
|
+
import { exists as exists3 } from "@xylabs/exists";
|
|
1292
1255
|
import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
|
|
1293
1256
|
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
1294
1257
|
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
@@ -1299,7 +1262,7 @@ var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archi
|
|
|
1299
1262
|
const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
|
|
1300
1263
|
const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
|
|
1301
1264
|
return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
|
|
1302
|
-
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(
|
|
1265
|
+
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists3);
|
|
1303
1266
|
const payloads = await archivist.get(stakeIntentHashes);
|
|
1304
1267
|
const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
|
|
1305
1268
|
return stakeIntents;
|
|
@@ -1321,10 +1284,11 @@ import { asAddress } from "@xylabs/hex";
|
|
|
1321
1284
|
import { isUndefined as isUndefined3 } from "@xylabs/typeof";
|
|
1322
1285
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1323
1286
|
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
1324
|
-
import { PayloadBuilder as
|
|
1287
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1325
1288
|
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1289
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore3 } from "@xyo-network/xl1-protocol-sdk";
|
|
1326
1290
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1327
|
-
import { LRUCache as
|
|
1291
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
1328
1292
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
1329
1293
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1330
1294
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1349,7 +1313,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1349
1313
|
// in performance for small sets, and (most importantly) easily
|
|
1350
1314
|
// persisted so we can recover state on restart.
|
|
1351
1315
|
_producers = new IntervalMap();
|
|
1352
|
-
_stakeCache = new
|
|
1316
|
+
_stakeCache = new LRUCache2({
|
|
1353
1317
|
max: STAKE_CACHE_MAX_ENTRIES
|
|
1354
1318
|
});
|
|
1355
1319
|
_updateMutex = new Mutex3();
|
|
@@ -1371,7 +1335,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1371
1335
|
});
|
|
1372
1336
|
const head = await this.chainIterator.head();
|
|
1373
1337
|
if (isUndefined3(head)) return;
|
|
1374
|
-
const headHash = await
|
|
1338
|
+
const headHash = await PayloadBuilder7.hash(head);
|
|
1375
1339
|
await this.recoverState(headHash);
|
|
1376
1340
|
}
|
|
1377
1341
|
async getDeclaredCandidateRanges(address, intent) {
|
|
@@ -1411,7 +1375,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1411
1375
|
const candidatesWithStake = await Promise.all(candidates.map(async (candidate) => {
|
|
1412
1376
|
const stake = this._stakeCache.get(candidate);
|
|
1413
1377
|
if (stake === void 0) {
|
|
1414
|
-
const activeStake = await chainStakeViewer.
|
|
1378
|
+
const activeStake = await chainStakeViewer.activeByStaked(candidate);
|
|
1415
1379
|
if (activeStake > 0n) {
|
|
1416
1380
|
this._stakeCache.set(candidate, activeStake, {
|
|
1417
1381
|
ttl: ACTIVE_STAKE_TTL
|
|
@@ -1436,7 +1400,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1436
1400
|
}
|
|
1437
1401
|
async persistState(current) {
|
|
1438
1402
|
const state = this._producers.serialize();
|
|
1439
|
-
const payload = new
|
|
1403
|
+
const payload = new PayloadBuilder7({
|
|
1440
1404
|
schema: ChainIndexingServiceStateSchema
|
|
1441
1405
|
}).fields({
|
|
1442
1406
|
endBlockHash: current,
|
|
@@ -1488,8 +1452,11 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1488
1452
|
return await this.spanAsync("updateIndex", async () => {
|
|
1489
1453
|
const currentHead = await this.chainIterator.head();
|
|
1490
1454
|
if (isUndefined3(currentHead)) return;
|
|
1491
|
-
const currentHeadHash = await
|
|
1492
|
-
const
|
|
1455
|
+
const currentHeadHash = await PayloadBuilder7.hash(currentHead);
|
|
1456
|
+
const chainMap = readPayloadMapFromStore3(this.chainArchivist);
|
|
1457
|
+
const result = await analyzeChain({
|
|
1458
|
+
chainMap
|
|
1459
|
+
}, [
|
|
1493
1460
|
new ChainStakeIntentAnalyzer("producer")
|
|
1494
1461
|
], currentHeadHash, this._lastIndexedBlockHash);
|
|
1495
1462
|
const signedDeclarations = filterAs3(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent2);
|
|
@@ -1541,8 +1508,8 @@ BaseStepStakeService = _ts_decorate13([
|
|
|
1541
1508
|
// src/Time/BaseTimeSyncService.ts
|
|
1542
1509
|
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1543
1510
|
import { creatable as creatable14 } from "@xylabs/creatable";
|
|
1544
|
-
import { asHash
|
|
1545
|
-
import { PayloadBuilder as
|
|
1511
|
+
import { asHash } from "@xylabs/hex";
|
|
1512
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1546
1513
|
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1547
1514
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
1548
1515
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1626,7 +1593,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1626
1593
|
const head = await this.chainIterator.head();
|
|
1627
1594
|
return [
|
|
1628
1595
|
head.block,
|
|
1629
|
-
await
|
|
1596
|
+
await PayloadBuilder8.hash(head)
|
|
1630
1597
|
];
|
|
1631
1598
|
}
|
|
1632
1599
|
case "epoch": {
|
|
@@ -1639,7 +1606,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1639
1606
|
const provider = assertEx11(this.ethProvider, () => "Ethereum provider not configured");
|
|
1640
1607
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
1641
1608
|
const block = await provider.getBlock(blockNumber);
|
|
1642
|
-
const blockHash =
|
|
1609
|
+
const blockHash = asHash(assertEx11(block?.hash, () => "Block hash not found"), true);
|
|
1643
1610
|
return [
|
|
1644
1611
|
blockNumber,
|
|
1645
1612
|
blockHash
|
|
@@ -1679,8 +1646,8 @@ export {
|
|
|
1679
1646
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1680
1647
|
XyoStakeIntentService,
|
|
1681
1648
|
XyoValidator,
|
|
1682
|
-
|
|
1683
|
-
|
|
1649
|
+
accountBalancesServiceFromArchivist,
|
|
1650
|
+
accountTransfersServiceFromArchivist,
|
|
1684
1651
|
creatableService,
|
|
1685
1652
|
getBlockSignedStakeDeclarations
|
|
1686
1653
|
};
|