@xyo-network/chain-services 1.15.1 → 1.15.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/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/ChainBlockIteration/ChainBlockNumberIterationService.d.ts +20 -0
- package/dist/neutral/ChainBlockIteration/ChainBlockNumberIterationService.d.ts.map +1 -0
- package/dist/neutral/ChainBlockIteration/index.d.ts +3 -0
- package/dist/neutral/ChainBlockIteration/index.d.ts.map +1 -0
- package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts +7 -0
- package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts.map +1 -0
- package/dist/neutral/ChainBlockIteration/model/Params.d.ts +8 -0
- package/dist/neutral/ChainBlockIteration/model/Params.d.ts.map +1 -0
- package/dist/neutral/ChainBlockIteration/model/index.d.ts +3 -0
- package/dist/neutral/ChainBlockIteration/model/index.d.ts.map +1 -0
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +10 -7
- 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/ChainValidator/XyoValidator.d.ts +2 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +15 -14
- 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/index.mjs +131 -157
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +41 -41
- package/src/AccountBalance/BaseAccountBalanceService.ts +6 -8
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +18 -33
- package/src/AccountTransfers/BaseAccountTransfersService.ts +4 -13
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +18 -35
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +62 -8
- package/src/ChainBlockIteration/ChainBlockNumberIterationService.ts +108 -0
- package/src/ChainBlockIteration/index.ts +2 -0
- package/src/ChainBlockIteration/model/BlockNumberIteration.ts +7 -0
- package/src/ChainBlockIteration/model/Params.ts +9 -0
- package/src/ChainBlockIteration/model/index.ts +2 -0
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +44 -30
- package/src/ChainBlockNumberIteration/model/Params.ts +3 -2
- package/src/ChainValidator/XyoValidator.ts +2 -2
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +20 -14
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +3 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -2,10 +2,9 @@ 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 { LRUCache } from "lru-cache";
|
|
5
|
+
import { ZERO_HASH } from "@xylabs/hex";
|
|
6
|
+
import { LruCacheMap } from "@xyo-network/chain-protocol";
|
|
7
|
+
import { readPayloadMapFromStore } from "@xyo-network/xl1-protocol-sdk";
|
|
9
8
|
|
|
10
9
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
11
10
|
import { creatable as creatable2 } from "@xylabs/creatable";
|
|
@@ -80,11 +79,7 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
80
79
|
}
|
|
81
80
|
async balances(head, address) {
|
|
82
81
|
return await spanRootAsync2("balances", async () => {
|
|
83
|
-
const summary = await balancesSummary(
|
|
84
|
-
chainArchivist: this.params.chainArchivist,
|
|
85
|
-
summaryRepository: this.params.summaryRepository,
|
|
86
|
-
head
|
|
87
|
-
});
|
|
82
|
+
const summary = await balancesSummary(this.params.context);
|
|
88
83
|
const result = {};
|
|
89
84
|
for (const addr of address) {
|
|
90
85
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -99,46 +94,31 @@ BaseAccountBalanceService = _ts_decorate2([
|
|
|
99
94
|
], BaseAccountBalanceService);
|
|
100
95
|
|
|
101
96
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
102
|
-
var
|
|
103
|
-
const
|
|
97
|
+
var accountBalancesServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
98
|
+
const summaryMap = new LruCacheMap({
|
|
104
99
|
max: 1e5,
|
|
105
100
|
allowStale: true,
|
|
106
101
|
noDisposeOnSet: false,
|
|
107
102
|
updateAgeOnGet: true
|
|
108
103
|
});
|
|
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
|
-
};
|
|
104
|
+
const chainMap = readPayloadMapFromStore(archivist);
|
|
130
105
|
const service = await BaseAccountBalanceService.create({
|
|
131
|
-
|
|
132
|
-
|
|
106
|
+
context: {
|
|
107
|
+
chainId,
|
|
108
|
+
store: {
|
|
109
|
+
chainMap
|
|
110
|
+
},
|
|
111
|
+
summaryMap,
|
|
112
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH, "head")
|
|
113
|
+
}
|
|
133
114
|
});
|
|
134
115
|
return service;
|
|
135
|
-
}, "
|
|
116
|
+
}, "accountBalancesServiceFromArchivist");
|
|
136
117
|
|
|
137
118
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
138
|
-
import {
|
|
139
|
-
import {
|
|
140
|
-
import {
|
|
141
|
-
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
119
|
+
import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
120
|
+
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/chain-protocol";
|
|
121
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
142
122
|
|
|
143
123
|
// src/AccountTransfers/BaseAccountTransfersService.ts
|
|
144
124
|
import { creatable as creatable3 } from "@xylabs/creatable";
|
|
@@ -163,13 +143,7 @@ var BaseAccountTransfersService = class extends BaseService {
|
|
|
163
143
|
}
|
|
164
144
|
async transfers(head, addresses) {
|
|
165
145
|
return await spanRootAsync3("transfers", async () => {
|
|
166
|
-
const
|
|
167
|
-
const summary = await transfersSummary({
|
|
168
|
-
chainArchivist,
|
|
169
|
-
summaryRepository,
|
|
170
|
-
head,
|
|
171
|
-
account
|
|
172
|
-
});
|
|
146
|
+
const summary = await transfersSummary(this.params.context);
|
|
173
147
|
const result = {};
|
|
174
148
|
for (const addr of addresses) {
|
|
175
149
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -184,65 +158,50 @@ BaseAccountTransfersService = _ts_decorate3([
|
|
|
184
158
|
], BaseAccountTransfersService);
|
|
185
159
|
|
|
186
160
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
187
|
-
var
|
|
188
|
-
const
|
|
161
|
+
var accountTransfersServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
162
|
+
const summaryMap = new LruCacheMap2({
|
|
189
163
|
max: 1e5,
|
|
190
164
|
allowStale: true,
|
|
191
165
|
noDisposeOnSet: false,
|
|
192
166
|
updateAgeOnGet: true
|
|
193
167
|
});
|
|
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
|
-
};
|
|
168
|
+
const chainMap = readPayloadMapFromStore2(archivist);
|
|
215
169
|
const service = await BaseAccountTransfersService.create({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
170
|
+
context: {
|
|
171
|
+
chainId,
|
|
172
|
+
store: {
|
|
173
|
+
chainMap
|
|
174
|
+
},
|
|
175
|
+
summaryMap,
|
|
176
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH2, "head")
|
|
177
|
+
}
|
|
219
178
|
});
|
|
220
179
|
return service;
|
|
221
|
-
}, "
|
|
180
|
+
}, "accountTransfersServiceFromArchivist");
|
|
222
181
|
|
|
223
182
|
// src/BlockProducer/BaseBlockProducerService.ts
|
|
224
183
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
225
184
|
import { creatable as creatable4 } from "@xylabs/creatable";
|
|
226
|
-
import { exists
|
|
185
|
+
import { exists } from "@xylabs/exists";
|
|
227
186
|
import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
228
187
|
import { isDefined } from "@xylabs/typeof";
|
|
229
188
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
230
189
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
231
|
-
import { PayloadBuilder as
|
|
190
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
232
191
|
import { asBlockBoundWitness, AttoXL1 as AttoXL13, BlockNumberSchema, defaultRewardRatio, TimeSchema, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
233
192
|
|
|
234
193
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
235
194
|
import { assertEx } from "@xylabs/assert";
|
|
236
195
|
import { hexFromBigInt } from "@xylabs/hex";
|
|
237
|
-
import { PayloadBuilder
|
|
196
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
238
197
|
import { TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
239
198
|
import { transactionRequiredGas } from "@xyo-network/xl1-protocol-sdk";
|
|
240
199
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
241
200
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
242
201
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
243
202
|
return HydratedTransactionWrapper.parse([
|
|
244
|
-
await
|
|
245
|
-
await
|
|
203
|
+
await PayloadBuilder.addStorageMeta(tx[0]),
|
|
204
|
+
await PayloadBuilder.addStorageMeta(tx[1])
|
|
246
205
|
]);
|
|
247
206
|
}));
|
|
248
207
|
const txBaseFeeCosts = {};
|
|
@@ -369,7 +328,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
369
328
|
});
|
|
370
329
|
}
|
|
371
330
|
const blockHex = assertEx2(toHex(block), () => "Failed to convert block to hex");
|
|
372
|
-
const blockId = new
|
|
331
|
+
const blockId = new PayloadBuilder2({
|
|
373
332
|
schema: BlockNumberSchema
|
|
374
333
|
}).fields({
|
|
375
334
|
block: blockHex
|
|
@@ -454,7 +413,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
454
413
|
fundedTransfers.push(transfer);
|
|
455
414
|
return tx;
|
|
456
415
|
}
|
|
457
|
-
}))).filter(
|
|
416
|
+
}))).filter(exists);
|
|
458
417
|
this.logger?.info(`Filtered ${txs.length} transactions to ${fundedTransactions.length} funded transactions in ${Date.now() - start}ms`);
|
|
459
418
|
return [
|
|
460
419
|
fundedTransactions,
|
|
@@ -617,22 +576,23 @@ MemoryBlockRewardService = _ts_decorate7([
|
|
|
617
576
|
|
|
618
577
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
619
578
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
620
|
-
import { isDefined as isDefined2, isNull } from "@xylabs/typeof";
|
|
621
|
-
import { PayloadBuilder as
|
|
622
|
-
import { asBlockBoundWitness as asBlockBoundWitness2,
|
|
623
|
-
import { LRUCache
|
|
579
|
+
import { isDefined as isDefined2, isNull, isUndefined } from "@xylabs/typeof";
|
|
580
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
581
|
+
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashStorageMeta } from "@xyo-network/xl1-protocol";
|
|
582
|
+
import { LRUCache } from "lru-cache";
|
|
624
583
|
var ChainBlockNumberIterationService = class extends BaseService {
|
|
625
584
|
static {
|
|
626
585
|
__name(this, "ChainBlockNumberIterationService");
|
|
627
586
|
}
|
|
628
|
-
_blocksByBlockNumber = new
|
|
587
|
+
_blocksByBlockNumber = new LRUCache({
|
|
629
588
|
max: 1e4
|
|
630
589
|
});
|
|
631
|
-
|
|
632
|
-
return assertEx5(this.params.chainArchivist);
|
|
633
|
-
}
|
|
590
|
+
_currentHead;
|
|
634
591
|
get chainId() {
|
|
635
|
-
return assertEx5(this.params
|
|
592
|
+
return assertEx5(this._currentHead?.chain ?? this.params?.head?.chain, () => "Current head is not set");
|
|
593
|
+
}
|
|
594
|
+
get chainMap() {
|
|
595
|
+
return assertEx5(this.params.chainMap);
|
|
636
596
|
}
|
|
637
597
|
async get(block) {
|
|
638
598
|
const head = await this.head();
|
|
@@ -640,28 +600,30 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
640
600
|
const cached = this._blocksByBlockNumber.get(block);
|
|
641
601
|
if (cached) return cached;
|
|
642
602
|
const startingBlock = head;
|
|
643
|
-
const currentBlockHash = await
|
|
644
|
-
let currentBlock =
|
|
645
|
-
currentBlockHash
|
|
646
|
-
])).at(0);
|
|
603
|
+
const currentBlockHash = await PayloadBuilder3.hash(startingBlock);
|
|
604
|
+
let currentBlock = await this.chainMap.get(currentBlockHash);
|
|
647
605
|
while (isDefined2(currentBlock)) {
|
|
648
606
|
assertEx5(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
|
|
649
|
-
if (
|
|
607
|
+
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
650
608
|
this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
|
|
651
609
|
if (currentBlock.block === block) {
|
|
652
610
|
return currentBlock;
|
|
653
611
|
}
|
|
654
612
|
const { previous } = currentBlock;
|
|
655
613
|
if (isNull(previous)) break;
|
|
656
|
-
currentBlock =
|
|
657
|
-
previous
|
|
658
|
-
])).at(0);
|
|
614
|
+
currentBlock = await this.chainMap.get(previous);
|
|
659
615
|
}
|
|
660
616
|
}
|
|
661
617
|
throw new Error(`Block not found: ${block}`);
|
|
662
618
|
}
|
|
663
619
|
async head() {
|
|
664
|
-
|
|
620
|
+
if (isDefined2(this._currentHead)) return this._currentHead;
|
|
621
|
+
if (isDefined2(this.params.head)) {
|
|
622
|
+
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head);
|
|
623
|
+
this._currentHead = newHead;
|
|
624
|
+
return newHead;
|
|
625
|
+
}
|
|
626
|
+
throw new Error("Head is not set");
|
|
665
627
|
}
|
|
666
628
|
async next(block) {
|
|
667
629
|
const currentBlock = block;
|
|
@@ -673,31 +635,36 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
673
635
|
async previous(block = void 0, count = 1) {
|
|
674
636
|
const results = [];
|
|
675
637
|
let currentBlock = isDefined2(block) ? await this.get(block) : await this.head();
|
|
676
|
-
while (currentBlock && results.length < count) {
|
|
677
|
-
if (
|
|
638
|
+
while (isDefined2(currentBlock) && results.length < count) {
|
|
639
|
+
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
678
640
|
results.push(currentBlock);
|
|
679
641
|
const { previous } = currentBlock;
|
|
680
642
|
if (isNull(previous)) break;
|
|
681
|
-
const nextBlock = await this.
|
|
682
|
-
|
|
683
|
-
]);
|
|
684
|
-
currentBlock = asBlockBoundWitness2(nextBlock[0]);
|
|
643
|
+
const nextBlock = await this.chainMap.get(previous);
|
|
644
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock);
|
|
685
645
|
} else {
|
|
686
|
-
const hash =
|
|
687
|
-
assertEx5(
|
|
646
|
+
const hash = PayloadBuilder3.hash(currentBlock);
|
|
647
|
+
assertEx5(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
|
|
688
648
|
}
|
|
689
649
|
}
|
|
690
650
|
return results;
|
|
691
651
|
}
|
|
692
652
|
async updateHead(head) {
|
|
693
|
-
await
|
|
694
|
-
this.
|
|
653
|
+
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head);
|
|
654
|
+
this._currentHead = newHead;
|
|
695
655
|
void this.emit("headUpdated", {
|
|
696
656
|
blocks: [
|
|
697
|
-
|
|
657
|
+
newHead
|
|
698
658
|
]
|
|
699
659
|
});
|
|
700
660
|
}
|
|
661
|
+
async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head) {
|
|
662
|
+
const hash = await PayloadBuilder3.hash(head);
|
|
663
|
+
const stored = await this.chainMap.get(hash);
|
|
664
|
+
const newHead = asBlockBoundWitnessWithStorageMeta(stored);
|
|
665
|
+
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`);
|
|
666
|
+
return newHead;
|
|
667
|
+
}
|
|
701
668
|
};
|
|
702
669
|
|
|
703
670
|
// src/ChainService/Evm/Evm.ts
|
|
@@ -896,7 +863,7 @@ XyoValidator = _ts_decorate8([
|
|
|
896
863
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
897
864
|
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
898
865
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
899
|
-
import { PayloadBuilder as
|
|
866
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
900
867
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
901
868
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
902
869
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -921,7 +888,7 @@ var BaseElectionService = class extends BaseService {
|
|
|
921
888
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
922
889
|
const nextBlock = current.block + 1;
|
|
923
890
|
const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
|
|
924
|
-
const previousBlockHash = await
|
|
891
|
+
const previousBlockHash = await PayloadBuilder4.hash(current);
|
|
925
892
|
return this.generateCreatorCommittee(candidates, previousBlockHash);
|
|
926
893
|
});
|
|
927
894
|
}
|
|
@@ -949,43 +916,46 @@ var BaseNetworkStakeStepRewardService = class extends BaseService {
|
|
|
949
916
|
static {
|
|
950
917
|
__name(this, "BaseNetworkStakeStepRewardService");
|
|
951
918
|
}
|
|
952
|
-
|
|
919
|
+
networkStakeStepRewardAddressHistory(_address) {
|
|
953
920
|
throw new Error("Method not implemented.");
|
|
954
921
|
}
|
|
955
|
-
|
|
922
|
+
networkStakeStepRewardAddressReward(_context, _address) {
|
|
956
923
|
throw new Error("Method not implemented.");
|
|
957
924
|
}
|
|
958
|
-
|
|
925
|
+
networkStakeStepRewardAddressShare(_context, _address) {
|
|
959
926
|
throw new Error("Method not implemented.");
|
|
960
927
|
}
|
|
961
|
-
|
|
928
|
+
networkStakeStepRewardClaimedByAddress(_address) {
|
|
962
929
|
throw new Error("Method not implemented.");
|
|
963
930
|
}
|
|
964
|
-
|
|
931
|
+
networkStakeStepRewardForStep(_context) {
|
|
965
932
|
throw new Error("Method not implemented.");
|
|
966
933
|
}
|
|
967
|
-
|
|
934
|
+
networkStakeStepRewardForStepForPosition(_context, _position) {
|
|
968
935
|
throw new Error("Method not implemented.");
|
|
969
936
|
}
|
|
970
|
-
|
|
937
|
+
networkStakeStepRewardPoolRewards(_context) {
|
|
971
938
|
throw new Error("Method not implemented.");
|
|
972
939
|
}
|
|
973
|
-
|
|
940
|
+
networkStakeStepRewardPoolShares(_context) {
|
|
974
941
|
throw new Error("Method not implemented.");
|
|
975
942
|
}
|
|
976
|
-
|
|
943
|
+
networkStakeStepRewardPositionWeight(_context, _position) {
|
|
977
944
|
throw new Error("Method not implemented.");
|
|
978
945
|
}
|
|
979
|
-
|
|
946
|
+
networkStakeStepRewardPotentialPositionLoss(_context, _position) {
|
|
980
947
|
throw new Error("Method not implemented.");
|
|
981
948
|
}
|
|
982
|
-
|
|
949
|
+
networkStakeStepRewardRandomizer(_context) {
|
|
983
950
|
throw new Error("Method not implemented.");
|
|
984
951
|
}
|
|
985
|
-
|
|
952
|
+
networkStakeStepRewardStakerCount(_context) {
|
|
986
953
|
throw new Error("Method not implemented.");
|
|
987
954
|
}
|
|
988
|
-
|
|
955
|
+
networkStakeStepRewardUnclaimedByAddress(_address) {
|
|
956
|
+
throw new Error("Method not implemented.");
|
|
957
|
+
}
|
|
958
|
+
networkStakeStepRewardWeightForAddress(_context, _address) {
|
|
989
959
|
throw new Error("Method not implemented.");
|
|
990
960
|
}
|
|
991
961
|
};
|
|
@@ -998,9 +968,9 @@ import { ValueType } from "@opentelemetry/api";
|
|
|
998
968
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
999
969
|
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
1000
970
|
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1001
|
-
import { exists as
|
|
971
|
+
import { exists as exists2 } from "@xylabs/exists";
|
|
1002
972
|
import { forget } from "@xylabs/forget";
|
|
1003
|
-
import { isDefined as isDefined3, isUndefined } from "@xylabs/typeof";
|
|
973
|
+
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1004
974
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
1005
975
|
import { findMostRecentBlock } from "@xyo-network/chain-protocol";
|
|
1006
976
|
import { asBlockBoundWitnessWithHashStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
@@ -1008,10 +978,10 @@ import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-networ
|
|
|
1008
978
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
1009
979
|
|
|
1010
980
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
1011
|
-
import { PayloadBuilder as
|
|
981
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1012
982
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1013
983
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
1014
|
-
const withStorageMeta = await
|
|
984
|
+
const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
|
|
1015
985
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
1016
986
|
if (tx) {
|
|
1017
987
|
return [
|
|
@@ -1022,7 +992,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
1022
992
|
}, "bundledPayloadToHydratedTransaction");
|
|
1023
993
|
|
|
1024
994
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
1025
|
-
import { PayloadBuilder as
|
|
995
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1026
996
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1027
997
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1028
998
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -1030,8 +1000,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
1030
1000
|
return bundle(root, transaction);
|
|
1031
1001
|
}, "hydratedTransactionToPayloadBundle");
|
|
1032
1002
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
1033
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
1034
|
-
return new
|
|
1003
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
|
|
1004
|
+
return new PayloadBuilder6({
|
|
1035
1005
|
schema: PayloadBundleSchema
|
|
1036
1006
|
}).fields({
|
|
1037
1007
|
payloads,
|
|
@@ -1140,7 +1110,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1140
1110
|
let [lastHead] = filterAs(await this.chainArchivist.get([
|
|
1141
1111
|
head
|
|
1142
1112
|
]), asBlockBoundWitnessWithHashStorageMeta);
|
|
1143
|
-
if (
|
|
1113
|
+
if (isUndefined2(lastHead)) return [];
|
|
1144
1114
|
await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
1145
1115
|
const foundPendingTransactions = [];
|
|
1146
1116
|
let cursor;
|
|
@@ -1153,7 +1123,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1153
1123
|
if (pendingBundledTransactions.length === 0) break;
|
|
1154
1124
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1155
1125
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1156
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1126
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1157
1127
|
const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1));
|
|
1158
1128
|
foundPendingTransactions.push(...activeTransactions);
|
|
1159
1129
|
}
|
|
@@ -1194,7 +1164,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1194
1164
|
const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
|
|
1195
1165
|
const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
|
|
1196
1166
|
return await bundledPayloadToHydratedTransaction(tx);
|
|
1197
|
-
}))).filter(
|
|
1167
|
+
}))).filter(exists2);
|
|
1198
1168
|
const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
|
|
1199
1169
|
const errors = await validateTransaction(tx, this.chainId, [
|
|
1200
1170
|
TransactionJsonSchemaValidator
|
|
@@ -1241,14 +1211,14 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1241
1211
|
}
|
|
1242
1212
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1243
1213
|
const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
|
|
1244
|
-
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(
|
|
1214
|
+
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists2));
|
|
1245
1215
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1246
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1216
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1247
1217
|
const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1));
|
|
1248
1218
|
const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
|
|
1249
1219
|
// Find the corresponding payload bundle hash for the expired transaction
|
|
1250
1220
|
pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
|
|
1251
|
-
)).filter(
|
|
1221
|
+
)).filter(exists2);
|
|
1252
1222
|
foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
|
|
1253
1223
|
}
|
|
1254
1224
|
const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
|
|
@@ -1272,7 +1242,7 @@ var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf
|
|
|
1272
1242
|
|
|
1273
1243
|
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
1274
1244
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
1275
|
-
import { exists as
|
|
1245
|
+
import { exists as exists3 } from "@xylabs/exists";
|
|
1276
1246
|
import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
|
|
1277
1247
|
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
1278
1248
|
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
@@ -1283,7 +1253,7 @@ var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archi
|
|
|
1283
1253
|
const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
|
|
1284
1254
|
const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
|
|
1285
1255
|
return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
|
|
1286
|
-
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(
|
|
1256
|
+
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists3);
|
|
1287
1257
|
const payloads = await archivist.get(stakeIntentHashes);
|
|
1288
1258
|
const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
|
|
1289
1259
|
return stakeIntents;
|
|
@@ -1302,13 +1272,14 @@ import { filterAs as filterAs3 } from "@xylabs/array";
|
|
|
1302
1272
|
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
1303
1273
|
import { creatable as creatable12 } from "@xylabs/creatable";
|
|
1304
1274
|
import { asAddress } from "@xylabs/hex";
|
|
1305
|
-
import { isUndefined as
|
|
1275
|
+
import { isUndefined as isUndefined3 } from "@xylabs/typeof";
|
|
1306
1276
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1307
1277
|
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
1308
|
-
import { PayloadBuilder as
|
|
1309
|
-
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1278
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1279
|
+
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1280
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore3 } from "@xyo-network/xl1-protocol-sdk";
|
|
1310
1281
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1311
|
-
import { LRUCache as
|
|
1282
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
1312
1283
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
1313
1284
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1314
1285
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1333,7 +1304,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1333
1304
|
// in performance for small sets, and (most importantly) easily
|
|
1334
1305
|
// persisted so we can recover state on restart.
|
|
1335
1306
|
_producers = new IntervalMap();
|
|
1336
|
-
_stakeCache = new
|
|
1307
|
+
_stakeCache = new LRUCache2({
|
|
1337
1308
|
max: STAKE_CACHE_MAX_ENTRIES
|
|
1338
1309
|
});
|
|
1339
1310
|
_updateMutex = new Mutex3();
|
|
@@ -1354,8 +1325,8 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1354
1325
|
await this.updateIndex();
|
|
1355
1326
|
});
|
|
1356
1327
|
const head = await this.chainIterator.head();
|
|
1357
|
-
if (
|
|
1358
|
-
const headHash = await
|
|
1328
|
+
if (isUndefined3(head)) return;
|
|
1329
|
+
const headHash = await PayloadBuilder7.hash(head);
|
|
1359
1330
|
await this.recoverState(headHash);
|
|
1360
1331
|
}
|
|
1361
1332
|
async getDeclaredCandidateRanges(address, intent) {
|
|
@@ -1420,7 +1391,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1420
1391
|
}
|
|
1421
1392
|
async persistState(current) {
|
|
1422
1393
|
const state = this._producers.serialize();
|
|
1423
|
-
const payload = new
|
|
1394
|
+
const payload = new PayloadBuilder7({
|
|
1424
1395
|
schema: ChainIndexingServiceStateSchema
|
|
1425
1396
|
}).fields({
|
|
1426
1397
|
endBlockHash: current,
|
|
@@ -1448,7 +1419,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1448
1419
|
const indexed = (await this.chainArchivist.get([
|
|
1449
1420
|
state.endBlockHash
|
|
1450
1421
|
]))?.[0];
|
|
1451
|
-
const indexedBlock =
|
|
1422
|
+
const indexedBlock = asBlockBoundWitnessWithStorageMeta2(indexed);
|
|
1452
1423
|
if (indexedBlock) {
|
|
1453
1424
|
const indexedBlockNum = indexedBlock.block;
|
|
1454
1425
|
if (indexedBlockNum <= currentBlockNum) {
|
|
@@ -1471,9 +1442,12 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1471
1442
|
await this._updateMutex.runExclusive(async () => {
|
|
1472
1443
|
return await this.spanAsync("updateIndex", async () => {
|
|
1473
1444
|
const currentHead = await this.chainIterator.head();
|
|
1474
|
-
if (
|
|
1475
|
-
const currentHeadHash = await
|
|
1476
|
-
const
|
|
1445
|
+
if (isUndefined3(currentHead)) return;
|
|
1446
|
+
const currentHeadHash = await PayloadBuilder7.hash(currentHead);
|
|
1447
|
+
const chainMap = readPayloadMapFromStore3(this.chainArchivist);
|
|
1448
|
+
const result = await analyzeChain({
|
|
1449
|
+
chainMap
|
|
1450
|
+
}, [
|
|
1477
1451
|
new ChainStakeIntentAnalyzer("producer")
|
|
1478
1452
|
], currentHeadHash, this._lastIndexedBlockHash);
|
|
1479
1453
|
const signedDeclarations = filterAs3(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent2);
|
|
@@ -1525,8 +1499,8 @@ BaseStepStakeService = _ts_decorate13([
|
|
|
1525
1499
|
// src/Time/BaseTimeSyncService.ts
|
|
1526
1500
|
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1527
1501
|
import { creatable as creatable14 } from "@xylabs/creatable";
|
|
1528
|
-
import { asHash
|
|
1529
|
-
import { PayloadBuilder as
|
|
1502
|
+
import { asHash } from "@xylabs/hex";
|
|
1503
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1530
1504
|
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1531
1505
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
1532
1506
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1610,7 +1584,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1610
1584
|
const head = await this.chainIterator.head();
|
|
1611
1585
|
return [
|
|
1612
1586
|
head.block,
|
|
1613
|
-
await
|
|
1587
|
+
await PayloadBuilder8.hash(head)
|
|
1614
1588
|
];
|
|
1615
1589
|
}
|
|
1616
1590
|
case "epoch": {
|
|
@@ -1623,7 +1597,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1623
1597
|
const provider = assertEx11(this.ethProvider, () => "Ethereum provider not configured");
|
|
1624
1598
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
1625
1599
|
const block = await provider.getBlock(blockNumber);
|
|
1626
|
-
const blockHash =
|
|
1600
|
+
const blockHash = asHash(assertEx11(block?.hash, () => "Block hash not found"), true);
|
|
1627
1601
|
return [
|
|
1628
1602
|
blockNumber,
|
|
1629
1603
|
blockHash
|
|
@@ -1663,8 +1637,8 @@ export {
|
|
|
1663
1637
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1664
1638
|
XyoStakeIntentService,
|
|
1665
1639
|
XyoValidator,
|
|
1666
|
-
|
|
1667
|
-
|
|
1640
|
+
accountBalancesServiceFromArchivist,
|
|
1641
|
+
accountTransfersServiceFromArchivist,
|
|
1668
1642
|
creatableService,
|
|
1669
1643
|
getBlockSignedStakeDeclarations
|
|
1670
1644
|
};
|