@xyo-network/chain-services 1.19.14 → 1.19.16
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/Election/BaseElectionService.d.ts +1 -1
- package/dist/neutral/Election/BaseElectionService.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +32 -578
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +8 -6
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +31 -28
- package/src/Election/BaseElectionService.ts +1 -1
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +1 -1
- package/src/StepStake/BaseStepStakeService.ts +1 -1
- package/src/index.ts +0 -2
- package/src/simple/block/runner/SimpleBlockRunner.ts +12 -13
- package/src/simple/block/runner/generateTransactionFeeTransfers.ts +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +0 -64
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +0 -1
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts +0 -4
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +0 -1
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts +0 -4
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +0 -1
- package/dist/neutral/PendingTransactions/index.d.ts +0 -2
- package/dist/neutral/PendingTransactions/index.d.ts.map +0 -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/PendingTransactions/BasePendingTransactions.ts +0 -382
- package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +0 -14
- package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +0 -18
- package/src/PendingTransactions/index.ts +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
package/dist/neutral/index.mjs
CHANGED
|
@@ -236,321 +236,24 @@ BaseNetworkStakeStepRewardService = _ts_decorate3([
|
|
|
236
236
|
creatableProvider2()
|
|
237
237
|
], BaseNetworkStakeStepRewardService);
|
|
238
238
|
|
|
239
|
-
// src/PendingTransactions/BasePendingTransactions.ts
|
|
240
|
-
import { ValueType } from "@opentelemetry/api";
|
|
241
|
-
import { assertEx as assertEx3, exists, filterAs, filterAsync, forget, isDefined, isUndefined } from "@xylabs/sdk-js";
|
|
242
|
-
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
243
|
-
import { AbstractCreatableProvider as AbstractCreatableProvider4, asBlockBoundWitnessWithHashMeta, asXL1BlockNumber, creatableProvider as creatableProvider3, findMostRecentBlock, isTransactionBoundWitnessWithStorageMeta, MempoolViewerMoniker, TransactionJsonSchemaValidator, validateTransaction } from "@xyo-network/xl1-sdk";
|
|
244
|
-
import { Mutex } from "async-mutex";
|
|
245
|
-
|
|
246
|
-
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
247
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
248
|
-
import { asSignedTransactionBoundWitnessWithHashMeta } from "@xyo-network/xl1-sdk";
|
|
249
|
-
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
250
|
-
const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads);
|
|
251
|
-
const tx = asSignedTransactionBoundWitnessWithHashMeta(withHashMeta.find((p) => p._hash === payload.root));
|
|
252
|
-
if (tx) {
|
|
253
|
-
return [
|
|
254
|
-
tx,
|
|
255
|
-
withHashMeta.filter((p) => p._hash !== payload.root)
|
|
256
|
-
];
|
|
257
|
-
}
|
|
258
|
-
}, "bundledPayloadToHydratedTransaction");
|
|
259
|
-
|
|
260
|
-
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
261
|
-
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
262
|
-
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
263
|
-
import { flattenHydratedTransaction } from "@xyo-network/xl1-sdk";
|
|
264
|
-
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
265
|
-
const root = transaction[0]._hash;
|
|
266
|
-
return bundle(root, transaction);
|
|
267
|
-
}, "hydratedTransactionToPayloadBundle");
|
|
268
|
-
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
269
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder2.omitStorageMeta(p));
|
|
270
|
-
return new PayloadBuilder2({
|
|
271
|
-
schema: PayloadBundleSchema
|
|
272
|
-
}).fields({
|
|
273
|
-
payloads,
|
|
274
|
-
root
|
|
275
|
-
}).build();
|
|
276
|
-
}, "bundle");
|
|
277
|
-
|
|
278
|
-
// src/PendingTransactions/BasePendingTransactions.ts
|
|
279
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
280
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
281
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
282
|
-
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;
|
|
283
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
284
|
-
}
|
|
285
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
286
|
-
var BasePendingTransactionsService = class _BasePendingTransactionsService extends AbstractCreatableProvider4 {
|
|
287
|
-
static {
|
|
288
|
-
__name(this, "BasePendingTransactionsService");
|
|
289
|
-
}
|
|
290
|
-
static defaultMoniker = MempoolViewerMoniker;
|
|
291
|
-
static dependencies = [];
|
|
292
|
-
static monikers = [
|
|
293
|
-
MempoolViewerMoniker
|
|
294
|
-
];
|
|
295
|
-
static MutexPriority = {
|
|
296
|
-
/**
|
|
297
|
-
* Priority for inserting new transactions
|
|
298
|
-
*/
|
|
299
|
-
InsertNewTransactions: 5,
|
|
300
|
-
/**
|
|
301
|
-
* Priority for reading pending transactions
|
|
302
|
-
*/
|
|
303
|
-
ReadTransactions: 3,
|
|
304
|
-
/**
|
|
305
|
-
* Priority for removing finalized/expired/rejected transactions
|
|
306
|
-
*/
|
|
307
|
-
PurgeTransactions: 1
|
|
308
|
-
};
|
|
309
|
-
moniker = _BasePendingTransactionsService.defaultMoniker;
|
|
310
|
-
/**
|
|
311
|
-
* A mutex to ensure that the counting the number of pending transactions is
|
|
312
|
-
* not called concurrently
|
|
313
|
-
*/
|
|
314
|
-
_countPendingTransactionsMutex = new Mutex();
|
|
315
|
-
/**
|
|
316
|
-
* A local Archivist optimized for fast retrieval that stores only validated
|
|
317
|
-
* pending transactions
|
|
318
|
-
*/
|
|
319
|
-
_curatedPendingBundledTransactionsArchivist;
|
|
320
|
-
/**
|
|
321
|
-
* The last count of total pending transactions
|
|
322
|
-
*/
|
|
323
|
-
_pendingTransactionsCount = 0;
|
|
324
|
-
/**
|
|
325
|
-
* A set of transaction hashes that are pending removal from the
|
|
326
|
-
* curated pending transactions archivist. This is used to track
|
|
327
|
-
* which transactions need to be removed from the archivist.
|
|
328
|
-
*/
|
|
329
|
-
_removablePendingTransactionHashes = /* @__PURE__ */ new Set();
|
|
330
|
-
/**
|
|
331
|
-
* A mutex to ensure that the curated pending transactions archivist is
|
|
332
|
-
* updated in a thread-safe manner
|
|
333
|
-
*/
|
|
334
|
-
_updateCuratedPendingTransactionsArchivistMutex = new Mutex();
|
|
335
|
-
get additionalPendingTransactionValidators() {
|
|
336
|
-
return this.params.additionalPendingTransactionValidators ?? [];
|
|
337
|
-
}
|
|
338
|
-
get chainArchivist() {
|
|
339
|
-
return assertEx3(this.params.chainArchivist, () => "No completed blocks with data archivist");
|
|
340
|
-
}
|
|
341
|
-
get pendingBundledTransactionsArchivist() {
|
|
342
|
-
return assertEx3(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
|
|
343
|
-
}
|
|
344
|
-
get pendingBundledTransactionsLocalArchivist() {
|
|
345
|
-
return assertEx3(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
|
|
346
|
-
}
|
|
347
|
-
get pendingTransactionsCount() {
|
|
348
|
-
forget(this.countPendingTransactions());
|
|
349
|
-
return this._pendingTransactionsCount;
|
|
350
|
-
}
|
|
351
|
-
get rejectedTransactionsArchivist() {
|
|
352
|
-
return assertEx3(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
|
|
353
|
-
}
|
|
354
|
-
async createHandler() {
|
|
355
|
-
await super.createHandler();
|
|
356
|
-
this._curatedPendingBundledTransactionsArchivist = await MemoryArchivist.create({
|
|
357
|
-
account: "random"
|
|
358
|
-
});
|
|
359
|
-
this.pendingBundledTransactionsArchivist.on("inserted", ({ payloads }) => {
|
|
360
|
-
forget(this.insertNewTransactions(payloads));
|
|
361
|
-
});
|
|
362
|
-
this.chainArchivist.on("inserted", ({ payloads }) => {
|
|
363
|
-
this.markAnyIncludedTransactionsForRemoval(payloads);
|
|
364
|
-
forget(this.cleanupWorker());
|
|
365
|
-
});
|
|
366
|
-
this.rejectedTransactionsArchivist.on("inserted", ({ payloads }) => {
|
|
367
|
-
this.markAnyIncludedTransactionsForRemoval(payloads);
|
|
368
|
-
forget(this.cleanupWorker());
|
|
369
|
-
});
|
|
370
|
-
const pendingTransactionsCounter = this.meter?.createObservableUpDownCounter("xyo_pending_transactions_counter", {
|
|
371
|
-
description: "The current number of pending transactions",
|
|
372
|
-
valueType: ValueType.INT,
|
|
373
|
-
unit: "1"
|
|
374
|
-
});
|
|
375
|
-
pendingTransactionsCounter?.addCallback((observer) => {
|
|
376
|
-
observer.observe(this.pendingTransactionsCount);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
pendingBlocks(_options) {
|
|
380
|
-
throw new Error("Method [pendingBlocks] not implemented.");
|
|
381
|
-
}
|
|
382
|
-
async pendingTransactions({ limit = 100 } = {}) {
|
|
383
|
-
return await this.spanAsync("getPendingTransactions", async () => {
|
|
384
|
-
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
385
|
-
let lastHead = filterAs(await this.chainArchivist.next({
|
|
386
|
-
limit: 100
|
|
387
|
-
}), (x) => asBlockBoundWitnessWithHashMeta(x)).at(-1);
|
|
388
|
-
if (isUndefined(lastHead)) return [];
|
|
389
|
-
await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
390
|
-
const foundPendingTransactions = [];
|
|
391
|
-
let cursor;
|
|
392
|
-
while (foundPendingTransactions.length < limit) {
|
|
393
|
-
const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
|
|
394
|
-
limit: 100,
|
|
395
|
-
order: "asc",
|
|
396
|
-
cursor
|
|
397
|
-
});
|
|
398
|
-
if (pendingBundledTransactions.length === 0) break;
|
|
399
|
-
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
400
|
-
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
401
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists);
|
|
402
|
-
const activeTransactions = transactions.filter(isTransactionActive(asXL1BlockNumber(lastHead.block + 1, true)));
|
|
403
|
-
const txValidationResults = await Promise.all(activeTransactions.map(async (tx) => [
|
|
404
|
-
tx,
|
|
405
|
-
await validateTransaction({
|
|
406
|
-
...this.context,
|
|
407
|
-
chainId: this.params.chainId
|
|
408
|
-
}, tx, this.additionalPendingTransactionValidators)
|
|
409
|
-
]));
|
|
410
|
-
const validTransactions = txValidationResults.filter(([, errors]) => errors.length === 0).map(([tx]) => tx);
|
|
411
|
-
const invalidTransactions = txValidationResults.filter(([, errors]) => errors.length > 0).map(([tx]) => tx);
|
|
412
|
-
if (invalidTransactions.length > 0) {
|
|
413
|
-
this.logger?.warn(`getPendingTransactions: Found ${invalidTransactions.length} invalid pending transactions`);
|
|
414
|
-
for (const tx of invalidTransactions) {
|
|
415
|
-
this.logger?.warn(tx[0]._hash);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
foundPendingTransactions.push(...validTransactions);
|
|
419
|
-
}
|
|
420
|
-
if (foundPendingTransactions.length > 0) {
|
|
421
|
-
this.logger?.log(`getPendingTransactions: Found ${foundPendingTransactions.length} pending transactions`);
|
|
422
|
-
for (const tx of foundPendingTransactions) {
|
|
423
|
-
this.logger?.log(tx[0]._hash);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return foundPendingTransactions;
|
|
427
|
-
}, _BasePendingTransactionsService.MutexPriority.ReadTransactions);
|
|
428
|
-
}, this.context);
|
|
429
|
-
}
|
|
430
|
-
async cleanupWorker() {
|
|
431
|
-
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
432
|
-
const lastHead = await findMostRecentBlock(this.chainArchivist);
|
|
433
|
-
if (isDefined(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
434
|
-
}, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
|
|
435
|
-
}
|
|
436
|
-
async countPendingTransactions() {
|
|
437
|
-
if (this._countPendingTransactionsMutex.isLocked()) return;
|
|
438
|
-
await this._countPendingTransactionsMutex.runExclusive(async () => {
|
|
439
|
-
const payloads = await this._curatedPendingBundledTransactionsArchivist?.all() ?? [];
|
|
440
|
-
this._pendingTransactionsCount = payloads.length;
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
async filterAlreadyFinalizedTransactions(incomingTransactions) {
|
|
444
|
-
const incomingTransactionHashes = incomingTransactions.map((payload) => payload.root);
|
|
445
|
-
const finalizedTransactions = await this.chainArchivist.get(incomingTransactionHashes);
|
|
446
|
-
const finalizedTransactionHashes = new Set(finalizedTransactions.map((item) => item._hash));
|
|
447
|
-
const nonFinalizedTransactions = incomingTransactions.filter((item) => !finalizedTransactionHashes.has(item._hash));
|
|
448
|
-
return nonFinalizedTransactions;
|
|
449
|
-
}
|
|
450
|
-
async insertNewTransactions(payloads) {
|
|
451
|
-
if (payloads.length === 0) return;
|
|
452
|
-
return await this.spanAsync("InsertNewTransactions", async () => {
|
|
453
|
-
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
454
|
-
const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
|
|
455
|
-
const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
|
|
456
|
-
return await bundledPayloadToHydratedTransaction(tx);
|
|
457
|
-
}))).filter(exists);
|
|
458
|
-
const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
|
|
459
|
-
const errors = await validateTransaction({
|
|
460
|
-
...this.context,
|
|
461
|
-
chainId: this.params.chainId
|
|
462
|
-
}, tx, [
|
|
463
|
-
TransactionJsonSchemaValidator
|
|
464
|
-
]);
|
|
465
|
-
if (errors.length > 0) {
|
|
466
|
-
this.logger?.warn("validateTransaction", errors);
|
|
467
|
-
}
|
|
468
|
-
return errors.length > 0 ? false : true;
|
|
469
|
-
});
|
|
470
|
-
if (validTransactions.length > 0) {
|
|
471
|
-
const bundledTransactions = validTransactions.map((tx) => hydratedTransactionToPayloadBundle(tx));
|
|
472
|
-
await this.pendingBundledTransactionsLocalArchivist.insert(bundledTransactions);
|
|
473
|
-
}
|
|
474
|
-
}, _BasePendingTransactionsService.MutexPriority.InsertNewTransactions);
|
|
475
|
-
}, this.context);
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Marks any included transactions in the provided payloads for removal preventing them
|
|
479
|
-
* from being included in the curated pending transactions archivist and from being offered
|
|
480
|
-
* during the next retrieval of pending transactions.
|
|
481
|
-
* @param payloads An array of payloads that may contain transactions.
|
|
482
|
-
*/
|
|
483
|
-
markAnyIncludedTransactionsForRemoval(payloads) {
|
|
484
|
-
const hashes = payloads.filter(isTransactionBoundWitnessWithStorageMeta).map((p) => p._hash);
|
|
485
|
-
for (const hash of hashes) {
|
|
486
|
-
this._removablePendingTransactionHashes.add(hash);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
async pruneCuratedPendingTransactionsArchivist(head) {
|
|
490
|
-
return await this.spanAsync("pruneCuratedPendingTransactionsArchivist", async () => {
|
|
491
|
-
const foundPendingTransactionsToDeleteHashes = [];
|
|
492
|
-
let cursor;
|
|
493
|
-
let [lastHead] = filterAs(await this.chainArchivist.get([
|
|
494
|
-
head
|
|
495
|
-
]), (x) => asBlockBoundWitnessWithHashMeta(x));
|
|
496
|
-
while (isDefined(lastHead)) {
|
|
497
|
-
const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
|
|
498
|
-
limit: 100,
|
|
499
|
-
order: "asc",
|
|
500
|
-
cursor
|
|
501
|
-
});
|
|
502
|
-
if (pendingBundledTransactions.length === 0) {
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
506
|
-
const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
|
|
507
|
-
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists));
|
|
508
|
-
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
509
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists);
|
|
510
|
-
const expiredTransactions = transactions.filter(isTransactionExpired(asXL1BlockNumber(lastHead.block + 1, true)));
|
|
511
|
-
const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
|
|
512
|
-
// Find the corresponding payload bundle hash for the expired transaction
|
|
513
|
-
pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
|
|
514
|
-
)).filter(exists);
|
|
515
|
-
foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
|
|
516
|
-
}
|
|
517
|
-
const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
|
|
518
|
-
for (const payload of deletedHashes) {
|
|
519
|
-
this._removablePendingTransactionHashes.delete(payload._hash);
|
|
520
|
-
}
|
|
521
|
-
if (deletedHashes.length > 0) {
|
|
522
|
-
this.logger?.log(`foundPendingTransactionsToDeleteHashes: Found ${deletedHashes.length} deletable transactions`);
|
|
523
|
-
for (const payload of deletedHashes) {
|
|
524
|
-
this.logger?.log(payload._hash);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}, this.context);
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
BasePendingTransactionsService = _ts_decorate4([
|
|
531
|
-
creatableProvider3()
|
|
532
|
-
], BasePendingTransactionsService);
|
|
533
|
-
var isTransactionExpired = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.exp < block, "isTransactionExpired");
|
|
534
|
-
var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf <= block && txBw.exp >= block, "isTransactionActive");
|
|
535
|
-
|
|
536
239
|
// src/simple/block/runner/SimpleBlockRunner.ts
|
|
537
|
-
import { assertEx as
|
|
538
|
-
import { MemoryArchivist
|
|
240
|
+
import { assertEx as assertEx4, exists, hexToBigInt, isDefined } from "@xylabs/sdk-js";
|
|
241
|
+
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
539
242
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
540
243
|
import { buildNextBlock as buildNextBlock2 } from "@xyo-network/chain-protocol";
|
|
541
|
-
import { PayloadBuilder as
|
|
542
|
-
import { AbstractCreatableProvider as
|
|
244
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
245
|
+
import { AbstractCreatableProvider as AbstractCreatableProvider4, AccountBalanceViewerMoniker, asBlockBoundWitness, AttoXL1, BlockNumberSchema, BlockRewardViewerMoniker as BlockRewardViewerMoniker2, BlockRunnerMoniker, BlockValidationViewerMoniker, creatableProvider as creatableProvider3, createDeclarationIntent as createDeclarationIntent2, defaultRewardRatio, isSignedHydratedBlockWithHashMeta, MempoolRunnerMoniker, MempoolViewerMoniker, TimeSyncViewerMoniker, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-sdk";
|
|
543
246
|
|
|
544
247
|
// src/simple/block/runner/generateTransactionFeeTransfers.ts
|
|
545
248
|
import { hexFromBigInt } from "@xylabs/sdk-js";
|
|
546
|
-
import { assertEx as
|
|
547
|
-
import { PayloadBuilder
|
|
249
|
+
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
250
|
+
import { PayloadBuilder } from "@xyo-network/sdk-js";
|
|
548
251
|
import { HydratedTransactionWrapper, transactionRequiredGas, TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-sdk";
|
|
549
252
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
550
253
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
551
254
|
return HydratedTransactionWrapper.parse([
|
|
552
|
-
await
|
|
553
|
-
await
|
|
255
|
+
await PayloadBuilder.addStorageMeta(tx[0]),
|
|
256
|
+
await PayloadBuilder.addStorageMeta(tx[1])
|
|
554
257
|
]);
|
|
555
258
|
}));
|
|
556
259
|
const txBaseFeeCosts = {};
|
|
@@ -576,7 +279,7 @@ async function generateTransactionFeeTransfers(address, transactions) {
|
|
|
576
279
|
return payload;
|
|
577
280
|
});
|
|
578
281
|
for (const [from, amount] of Object.entries(txGasCosts)) {
|
|
579
|
-
const fromPayload =
|
|
282
|
+
const fromPayload = assertEx3(payloads.find((p) => p.from === from), () => "from payload not found");
|
|
580
283
|
fromPayload.transfers[address] = hexFromBigInt(amount);
|
|
581
284
|
}
|
|
582
285
|
return payloads;
|
|
@@ -584,17 +287,17 @@ async function generateTransactionFeeTransfers(address, transactions) {
|
|
|
584
287
|
__name(generateTransactionFeeTransfers, "generateTransactionFeeTransfers");
|
|
585
288
|
|
|
586
289
|
// src/simple/block/runner/SimpleBlockRunner.ts
|
|
587
|
-
function
|
|
290
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
588
291
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
589
292
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
590
293
|
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;
|
|
591
294
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
592
295
|
}
|
|
593
|
-
__name(
|
|
296
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
594
297
|
var DEFAULT_BLOCK_SIZE = 10;
|
|
595
298
|
var XYO_PRODUCER_REDECLARATION_DURATION = 1e4;
|
|
596
299
|
var XYO_PRODUCER_REDECLARATION_WINDOW = 500;
|
|
597
|
-
var SimpleBlockRunner = class _SimpleBlockRunner extends
|
|
300
|
+
var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvider4 {
|
|
598
301
|
static {
|
|
599
302
|
__name(this, "SimpleBlockRunner");
|
|
600
303
|
}
|
|
@@ -604,7 +307,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
604
307
|
BlockRewardViewerMoniker2,
|
|
605
308
|
BlockValidationViewerMoniker,
|
|
606
309
|
MempoolRunnerMoniker,
|
|
607
|
-
|
|
310
|
+
MempoolViewerMoniker,
|
|
608
311
|
TimeSyncViewerMoniker
|
|
609
312
|
];
|
|
610
313
|
static monikers = [
|
|
@@ -662,9 +365,9 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
662
365
|
get chainId() {
|
|
663
366
|
return this._chainId;
|
|
664
367
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
368
|
+
get heartbeatInterval() {
|
|
369
|
+
return this.params.heartbeatInterval ?? 36e5;
|
|
370
|
+
}
|
|
668
371
|
get mempoolRunner() {
|
|
669
372
|
return this._mempoolRunner;
|
|
670
373
|
}
|
|
@@ -690,16 +393,16 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
690
393
|
// return assertEx(this.params.validateHydratedBlockState, () => 'validateHydratedBlockState is required')
|
|
691
394
|
// }
|
|
692
395
|
async createHandler() {
|
|
693
|
-
this._rejectedTransactionsArchivist = this.params.rejectedTransactionsArchivist ?? await
|
|
694
|
-
this._account =
|
|
396
|
+
this._rejectedTransactionsArchivist = this.params.rejectedTransactionsArchivist ?? await MemoryArchivist.create();
|
|
397
|
+
this._account = assertEx4(this.params.account, () => "Account is required");
|
|
695
398
|
this._address = this.account.address;
|
|
696
399
|
this._accountBalanceViewer = await this.locateAndCreate(AccountBalanceViewerMoniker);
|
|
697
400
|
this._blockRewardViewer = await this.locateAndCreate(BlockRewardViewerMoniker2);
|
|
698
401
|
this._blockValidationViewer = await this.locator.getInstance(BlockValidationViewerMoniker);
|
|
699
402
|
this._chainId = this.context.config.chain.id;
|
|
700
403
|
this._mempoolRunner = await this.locateAndCreate(MempoolRunnerMoniker);
|
|
701
|
-
this._mempoolViewer = await this.locateAndCreate(
|
|
702
|
-
this._rewardAddress = this.params.rewardAddress
|
|
404
|
+
this._mempoolViewer = await this.locateAndCreate(MempoolViewerMoniker);
|
|
405
|
+
this._rewardAddress = this.params.rewardAddress;
|
|
703
406
|
this._timeSyncViewer = await this.locateAndCreate(TimeSyncViewerMoniker);
|
|
704
407
|
}
|
|
705
408
|
async next(head) {
|
|
@@ -707,7 +410,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
707
410
|
}
|
|
708
411
|
async produceNextBlock(head, force) {
|
|
709
412
|
const result = await this.proposeNextValidBlock(head);
|
|
710
|
-
return force ?
|
|
413
|
+
return force ? assertEx4(result, () => "Failed to produce next block") : result;
|
|
711
414
|
}
|
|
712
415
|
async getBlockRewardTransfers(block) {
|
|
713
416
|
if (!this._blockRewardDiviner) {
|
|
@@ -721,7 +424,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
721
424
|
}
|
|
722
425
|
});
|
|
723
426
|
}
|
|
724
|
-
const blockId = new
|
|
427
|
+
const blockId = new PayloadBuilder2({
|
|
725
428
|
schema: BlockNumberSchema
|
|
726
429
|
}).fields({
|
|
727
430
|
block
|
|
@@ -737,14 +440,14 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
737
440
|
* @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
|
|
738
441
|
*/
|
|
739
442
|
getProducerRedeclaration(head) {
|
|
740
|
-
if (this.params.
|
|
443
|
+
if (this.params.disableIntentRedeclaration) return;
|
|
741
444
|
const currentBlock = head.block;
|
|
742
445
|
return createDeclarationIntent2(this.address, "producer", currentBlock, currentBlock + _SimpleBlockRunner.RedeclarationDuration);
|
|
743
446
|
}
|
|
744
447
|
async proposeNextValidBlock(head, validateBalances = false, force = false) {
|
|
745
448
|
return await this.spanAsync("proposeNextValidBlock", async () => {
|
|
746
449
|
try {
|
|
747
|
-
const { block: previousBlock } =
|
|
450
|
+
const { block: previousBlock } = assertEx4(asBlockBoundWitness(head), () => "Invalid head block");
|
|
748
451
|
const nextBlock = previousBlock + 1;
|
|
749
452
|
const nextBlockTransactions = await this.mempoolViewer.pendingTransactions({
|
|
750
453
|
limit: _SimpleBlockRunner.DefaultBlockSize
|
|
@@ -816,7 +519,7 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
816
519
|
fundedTransfers.push(transfer);
|
|
817
520
|
return tx;
|
|
818
521
|
}
|
|
819
|
-
}))).filter(
|
|
522
|
+
}))).filter(exists);
|
|
820
523
|
return [
|
|
821
524
|
fundedTransactions,
|
|
822
525
|
fundedTransfers
|
|
@@ -832,265 +535,19 @@ var SimpleBlockRunner = class _SimpleBlockRunner extends AbstractCreatableProvid
|
|
|
832
535
|
*/
|
|
833
536
|
heartbeatRequired(head) {
|
|
834
537
|
const epoch = head.$epoch;
|
|
835
|
-
if (
|
|
836
|
-
|
|
837
|
-
if (Date.now() - epoch > heartbeatInterval) {
|
|
838
|
-
return true;
|
|
839
|
-
}
|
|
538
|
+
if (isDefined(epoch) && Date.now() - epoch > this.heartbeatInterval) {
|
|
539
|
+
return true;
|
|
840
540
|
}
|
|
841
541
|
return false;
|
|
842
542
|
}
|
|
843
543
|
};
|
|
844
|
-
SimpleBlockRunner =
|
|
845
|
-
|
|
544
|
+
SimpleBlockRunner = _ts_decorate4([
|
|
545
|
+
creatableProvider3()
|
|
846
546
|
], SimpleBlockRunner);
|
|
847
547
|
|
|
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
548
|
// src/StepStake/BaseStepStakeService.ts
|
|
1092
|
-
import { AbstractCreatableProvider as
|
|
1093
|
-
var AbstractStepStakeService = class _AbstractStepStakeService extends
|
|
549
|
+
import { AbstractCreatableProvider as AbstractCreatableProvider5, StepStakeViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
550
|
+
var AbstractStepStakeService = class _AbstractStepStakeService extends AbstractCreatableProvider5 {
|
|
1094
551
|
static {
|
|
1095
552
|
__name(this, "AbstractStepStakeService");
|
|
1096
553
|
}
|
|
@@ -1110,15 +567,12 @@ export {
|
|
|
1110
567
|
AbstractStepStakeService,
|
|
1111
568
|
BaseElectionService,
|
|
1112
569
|
BaseNetworkStakeStepRewardService,
|
|
1113
|
-
BasePendingTransactionsService,
|
|
1114
570
|
DEFAULT_BLOCK_SIZE,
|
|
1115
571
|
EvmBlockRewardViewer,
|
|
1116
572
|
SimpleBlockRunner,
|
|
1117
573
|
XYO_PRODUCER_REDECLARATION_DURATION,
|
|
1118
574
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1119
|
-
XyoStakeIntentService,
|
|
1120
575
|
XyoValidator,
|
|
1121
|
-
createBootstrapHead
|
|
1122
|
-
getBlockSignedStakeDeclarations
|
|
576
|
+
createBootstrapHead
|
|
1123
577
|
};
|
|
1124
578
|
//# sourceMappingURL=index.mjs.map
|