@xyo-network/chain-services 1.8.3 → 1.9.0
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/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/DataLake/AbstractXyoDataLake.d.ts +10 -0
- package/dist/neutral/DataLake/AbstractXyoDataLake.d.ts.map +1 -0
- package/dist/neutral/DataLake/ArchivistXyoDataLake.d.ts +11 -0
- package/dist/neutral/DataLake/ArchivistXyoDataLake.d.ts.map +1 -0
- package/dist/neutral/{XyoDataLake.d.ts → DataLake/HttpXyoDataLake.d.ts} +4 -5
- package/dist/neutral/DataLake/HttpXyoDataLake.d.ts.map +1 -0
- package/dist/neutral/DataLake/index.d.ts +4 -0
- package/dist/neutral/DataLake/index.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +1 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +222 -174
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +38 -38
- package/src/BlockReward/EvmBlockRewardService.ts +1 -1
- package/src/ChainService/Evm/Evm.ts +1 -2
- package/src/DataLake/AbstractXyoDataLake.ts +38 -0
- package/src/DataLake/ArchivistXyoDataLake.ts +26 -0
- package/src/{XyoDataLake.ts → DataLake/HttpXyoDataLake.ts} +5 -19
- package/src/DataLake/index.ts +3 -0
- package/src/index.ts +1 -1
- package/dist/neutral/XyoDataLake.d.ts.map +0 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -370,7 +370,7 @@ BaseBlockRewardService = _ts_decorate4([
|
|
|
370
370
|
// src/BlockReward/EvmBlockRewardService.ts
|
|
371
371
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
372
372
|
import { creatable as creatable5 } from "@xylabs/creatable";
|
|
373
|
-
import { toEthAddress } from "@
|
|
373
|
+
import { toEthAddress } from "@xylabs/hex";
|
|
374
374
|
import { XyoChainRewards__factory as XyoChainRewardsFactory } from "@xyo-network/typechain";
|
|
375
375
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
376
376
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -552,8 +552,7 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
552
552
|
|
|
553
553
|
// src/ChainService/Evm/Evm.ts
|
|
554
554
|
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
555
|
-
import { toAddress } from "@xylabs/hex";
|
|
556
|
-
import { toEthAddress as toEthAddress2 } from "@xyo-network/chain-ethereum";
|
|
555
|
+
import { toAddress, toEthAddress as toEthAddress2 } from "@xylabs/hex";
|
|
557
556
|
import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
|
|
558
557
|
import { getAddress } from "ethers/address";
|
|
559
558
|
var EvmChainService = class extends BaseService {
|
|
@@ -743,11 +742,188 @@ XyoValidator = _ts_decorate7([
|
|
|
743
742
|
creatable7()
|
|
744
743
|
], XyoValidator);
|
|
745
744
|
|
|
746
|
-
// src/
|
|
745
|
+
// src/DataLake/AbstractXyoDataLake.ts
|
|
746
|
+
import { ObjectHasher } from "@xyo-network/hash";
|
|
747
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
748
|
+
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
749
|
+
import { isHashPayload } from "@xyo-network/xl1-protocol";
|
|
750
|
+
var AbstractXyoDataLake = class {
|
|
751
|
+
static {
|
|
752
|
+
__name(this, "AbstractXyoDataLake");
|
|
753
|
+
}
|
|
754
|
+
async fetch(hashes, maxDepth = 10) {
|
|
755
|
+
const results = await this.get(hashes);
|
|
756
|
+
if (maxDepth > 0) {
|
|
757
|
+
const hashPayloads = results.filter(isHashPayload);
|
|
758
|
+
const otherPayloads = results.filter((item) => !isHashPayload(item));
|
|
759
|
+
const found = await this.fetch(hashPayloads.map((item) => item.hash), maxDepth - 1);
|
|
760
|
+
const foundHashes = await Promise.all(found.map(async (item) => isAnyPayload(item) ? await PayloadBuilder4.hash(item) : ObjectHasher.hashBytes(item)));
|
|
761
|
+
const notFound = hashPayloads.filter((item) => !foundHashes.includes(item.hash));
|
|
762
|
+
return [
|
|
763
|
+
...otherPayloads,
|
|
764
|
+
...found,
|
|
765
|
+
...notFound
|
|
766
|
+
];
|
|
767
|
+
}
|
|
768
|
+
return results;
|
|
769
|
+
}
|
|
770
|
+
async trace(hash) {
|
|
771
|
+
const [result] = await this.get([
|
|
772
|
+
hash
|
|
773
|
+
]);
|
|
774
|
+
if (isHashPayload(result)) {
|
|
775
|
+
const [payload, route] = await this.trace(result.hash);
|
|
776
|
+
return [
|
|
777
|
+
payload,
|
|
778
|
+
[
|
|
779
|
+
result,
|
|
780
|
+
...route
|
|
781
|
+
]
|
|
782
|
+
];
|
|
783
|
+
}
|
|
784
|
+
return [
|
|
785
|
+
result,
|
|
786
|
+
[]
|
|
787
|
+
];
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/DataLake/ArchivistXyoDataLake.ts
|
|
747
792
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
793
|
+
import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
|
|
794
|
+
var ArchivistXyoDataLake = class extends AbstractXyoDataLake {
|
|
795
|
+
static {
|
|
796
|
+
__name(this, "ArchivistXyoDataLake");
|
|
797
|
+
}
|
|
798
|
+
_archivist;
|
|
799
|
+
constructor(archivist) {
|
|
800
|
+
super();
|
|
801
|
+
this._archivist = archivist;
|
|
802
|
+
}
|
|
803
|
+
async add(items) {
|
|
804
|
+
const payloads = items.filter(isAnyPayload2);
|
|
805
|
+
assertEx8(payloads.length === items.length, () => "Some items are not payloads");
|
|
806
|
+
return await this._archivist.insert(payloads);
|
|
807
|
+
}
|
|
808
|
+
async get(hashes) {
|
|
809
|
+
return await this._archivist.get(hashes);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
// src/DataLake/HttpXyoDataLake.ts
|
|
814
|
+
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
815
|
+
import { AxiosJson } from "@xylabs/axios";
|
|
816
|
+
import { exists as exists3 } from "@xylabs/exists";
|
|
817
|
+
import { isArrayBuffer, isDefined as isDefined2 } from "@xylabs/typeof";
|
|
818
|
+
import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
|
|
819
|
+
import { isHashPayload as isHashPayload2 } from "@xyo-network/xl1-protocol";
|
|
820
|
+
import { Axios } from "axios";
|
|
821
|
+
var HttpXyoDataLake = class extends AbstractXyoDataLake {
|
|
822
|
+
static {
|
|
823
|
+
__name(this, "HttpXyoDataLake");
|
|
824
|
+
}
|
|
825
|
+
_axiosGet;
|
|
826
|
+
_axiosInsertBlob;
|
|
827
|
+
_axiosInsertJson;
|
|
828
|
+
_endpoint;
|
|
829
|
+
constructor(endpoint) {
|
|
830
|
+
super();
|
|
831
|
+
this._endpoint = endpoint;
|
|
832
|
+
this._axiosInsertJson = new AxiosJson({
|
|
833
|
+
baseURL: endpoint
|
|
834
|
+
});
|
|
835
|
+
this._axiosInsertBlob = new Axios({
|
|
836
|
+
baseURL: endpoint,
|
|
837
|
+
headers: {
|
|
838
|
+
"Content-Type": "application/octet-stream",
|
|
839
|
+
"Accept": "application/octet-stream"
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
this._axiosGet = new Axios({
|
|
843
|
+
baseURL: endpoint,
|
|
844
|
+
headers: {
|
|
845
|
+
"Content-Type": "application/json",
|
|
846
|
+
"Accept": "application/octet-stream, application/json"
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
get endpoint() {
|
|
851
|
+
return this._endpoint;
|
|
852
|
+
}
|
|
853
|
+
async add(items) {
|
|
854
|
+
const results = [];
|
|
855
|
+
for (const item of items) {
|
|
856
|
+
if (isAnyPayload3(item)) {
|
|
857
|
+
const result = await this.addPayload(item);
|
|
858
|
+
if (isAnyPayload3(result)) {
|
|
859
|
+
results.push(result);
|
|
860
|
+
} else if (isDefined2(result)) {
|
|
861
|
+
assertEx9(false, () => "Expected result to be a Payload");
|
|
862
|
+
}
|
|
863
|
+
} else if (isArrayBuffer(item)) {
|
|
864
|
+
const result = await this.addArrayBuffer(item);
|
|
865
|
+
if (isAnyPayload3(result)) {
|
|
866
|
+
results.push(result);
|
|
867
|
+
} else if (isDefined2(result)) {
|
|
868
|
+
assertEx9(false, () => "Expected result to be a Payload");
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return results;
|
|
873
|
+
}
|
|
874
|
+
async get(hashes) {
|
|
875
|
+
return (await Promise.all(hashes.map(async (hash) => {
|
|
876
|
+
return await this.getOne(hash);
|
|
877
|
+
}))).filter(exists3);
|
|
878
|
+
}
|
|
879
|
+
async addArrayBuffer(item) {
|
|
880
|
+
const result = await this._axiosInsertBlob.post("/insert", item);
|
|
881
|
+
if (result.status < 200 || result.status >= 300) {
|
|
882
|
+
throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
|
|
883
|
+
}
|
|
884
|
+
if (!isArrayBuffer(result.data)) {
|
|
885
|
+
throw new Error("Invalid response from server (expected a ArrayBuffer)");
|
|
886
|
+
}
|
|
887
|
+
return result.data;
|
|
888
|
+
}
|
|
889
|
+
async addPayload(item) {
|
|
890
|
+
const result = await this._axiosInsertJson.post("/insert", item);
|
|
891
|
+
if (result.status < 200 || result.status >= 300) {
|
|
892
|
+
throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
|
|
893
|
+
}
|
|
894
|
+
if (!isAnyPayload3(result.data)) {
|
|
895
|
+
throw new Error("Invalid response from server (expected a Payload)");
|
|
896
|
+
}
|
|
897
|
+
return result.data;
|
|
898
|
+
}
|
|
899
|
+
async fetchOne(hash, maxDepth = Number.MAX_SAFE_INTEGER) {
|
|
900
|
+
if (maxDepth <= 0) {
|
|
901
|
+
return void 0;
|
|
902
|
+
}
|
|
903
|
+
const result = await this.getOne(hash);
|
|
904
|
+
if (isHashPayload2(result)) {
|
|
905
|
+
return await this.fetchOne(result.hash, maxDepth - 1);
|
|
906
|
+
}
|
|
907
|
+
return result;
|
|
908
|
+
}
|
|
909
|
+
getOne(hash) {
|
|
910
|
+
return this._axiosGet.get(`/get/${hash}`).then((response) => {
|
|
911
|
+
if (response.status < 200 || response.status >= 300) {
|
|
912
|
+
throw new Error(`Failed to get item [${response.status}]: ${response.statusText}`);
|
|
913
|
+
}
|
|
914
|
+
if (!isAnyPayload3(response.data)) {
|
|
915
|
+
throw new Error("Invalid response from server (expected a Payload)");
|
|
916
|
+
}
|
|
917
|
+
return response.data;
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// src/Election/BaseElectionService.ts
|
|
923
|
+
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
748
924
|
import { creatable as creatable8 } from "@xylabs/creatable";
|
|
749
925
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
750
|
-
import { PayloadBuilder as
|
|
926
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
751
927
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
752
928
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
753
929
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -760,19 +936,19 @@ var BaseElectionService = class extends BaseService {
|
|
|
760
936
|
__name(this, "BaseElectionService");
|
|
761
937
|
}
|
|
762
938
|
get chainIterator() {
|
|
763
|
-
return
|
|
939
|
+
return assertEx10(this.params.chainIterator, () => "No chain iterator");
|
|
764
940
|
}
|
|
765
941
|
get chainStakeViewer() {
|
|
766
|
-
return
|
|
942
|
+
return assertEx10(this.params.chainStakeViewer, () => "No chain stake viewer");
|
|
767
943
|
}
|
|
768
944
|
get stakeIntentService() {
|
|
769
|
-
return
|
|
945
|
+
return assertEx10(this.params.stakeIntentService, () => "No staked intent service");
|
|
770
946
|
}
|
|
771
947
|
async getCreatorCommitteeForNextBlock(current) {
|
|
772
948
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
773
949
|
const nextBlock = current.block + 1;
|
|
774
950
|
const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
|
|
775
|
-
const previousBlockHash = await
|
|
951
|
+
const previousBlockHash = await PayloadBuilder5.hash(current);
|
|
776
952
|
return this.generateCreatorCommittee(candidates, previousBlockHash);
|
|
777
953
|
});
|
|
778
954
|
}
|
|
@@ -790,11 +966,11 @@ BaseElectionService = _ts_decorate8([
|
|
|
790
966
|
// src/PendingTransactions/BasePendingTransactions.ts
|
|
791
967
|
import { ValueType } from "@opentelemetry/api";
|
|
792
968
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
793
|
-
import { assertEx as
|
|
969
|
+
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
794
970
|
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
795
|
-
import { exists as
|
|
971
|
+
import { exists as exists4 } from "@xylabs/exists";
|
|
796
972
|
import { forget } from "@xylabs/forget";
|
|
797
|
-
import { isDefined as
|
|
973
|
+
import { isDefined as isDefined3, isUndefined } from "@xylabs/typeof";
|
|
798
974
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
799
975
|
import { findMostRecentBlock } from "@xyo-network/chain-protocol";
|
|
800
976
|
import { asBlockBoundWitnessWithHashStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
@@ -802,10 +978,10 @@ import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-networ
|
|
|
802
978
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
803
979
|
|
|
804
980
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
805
|
-
import { PayloadBuilder as
|
|
981
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
806
982
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
807
983
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
808
|
-
const withStorageMeta = await
|
|
984
|
+
const withStorageMeta = await PayloadBuilder6.addStorageMeta(payload.payloads);
|
|
809
985
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
810
986
|
if (tx) {
|
|
811
987
|
return [
|
|
@@ -816,7 +992,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
816
992
|
}, "bundledPayloadToHydratedTransaction");
|
|
817
993
|
|
|
818
994
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
819
|
-
import { PayloadBuilder as
|
|
995
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
820
996
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
821
997
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
822
998
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -824,8 +1000,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
824
1000
|
return bundle(root, transaction);
|
|
825
1001
|
}, "hydratedTransactionToPayloadBundle");
|
|
826
1002
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
827
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
828
|
-
return new
|
|
1003
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder7.omitStorageMeta(p));
|
|
1004
|
+
return new PayloadBuilder7({
|
|
829
1005
|
schema: PayloadBundleSchema
|
|
830
1006
|
}).fields({
|
|
831
1007
|
payloads,
|
|
@@ -885,23 +1061,23 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
885
1061
|
*/
|
|
886
1062
|
_updateCuratedPendingTransactionsArchivistMutex = new Mutex2();
|
|
887
1063
|
get chainArchivist() {
|
|
888
|
-
return
|
|
1064
|
+
return assertEx11(this.params.chainArchivist, () => "No completed blocks with data archivist");
|
|
889
1065
|
}
|
|
890
1066
|
get chainId() {
|
|
891
|
-
return
|
|
1067
|
+
return assertEx11(this.params.chainId, () => "No chain id");
|
|
892
1068
|
}
|
|
893
1069
|
get pendingBundledTransactionsArchivist() {
|
|
894
|
-
return
|
|
1070
|
+
return assertEx11(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
|
|
895
1071
|
}
|
|
896
1072
|
get pendingBundledTransactionsLocalArchivist() {
|
|
897
|
-
return
|
|
1073
|
+
return assertEx11(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
|
|
898
1074
|
}
|
|
899
1075
|
get pendingTransactionsCount() {
|
|
900
1076
|
forget(this.countPendingTransactions());
|
|
901
1077
|
return this._pendingTransactionsCount;
|
|
902
1078
|
}
|
|
903
1079
|
get rejectedTransactionsArchivist() {
|
|
904
|
-
return
|
|
1080
|
+
return assertEx11(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
|
|
905
1081
|
}
|
|
906
1082
|
async createHandler() {
|
|
907
1083
|
await super.createHandler();
|
|
@@ -947,7 +1123,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
947
1123
|
if (pendingBundledTransactions.length === 0) break;
|
|
948
1124
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
949
1125
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
950
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1126
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists4);
|
|
951
1127
|
const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1));
|
|
952
1128
|
foundPendingTransactions.push(...activeTransactions);
|
|
953
1129
|
}
|
|
@@ -964,7 +1140,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
964
1140
|
async cleanupWorker() {
|
|
965
1141
|
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
966
1142
|
const lastHead = await findMostRecentBlock(this.chainArchivist);
|
|
967
|
-
if (
|
|
1143
|
+
if (isDefined3(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
968
1144
|
}, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
|
|
969
1145
|
}
|
|
970
1146
|
async countPendingTransactions() {
|
|
@@ -988,7 +1164,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
988
1164
|
const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
|
|
989
1165
|
const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
|
|
990
1166
|
return await bundledPayloadToHydratedTransaction(tx);
|
|
991
|
-
}))).filter(
|
|
1167
|
+
}))).filter(exists4);
|
|
992
1168
|
const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
|
|
993
1169
|
const errors = await validateTransaction(tx, this.chainId, [
|
|
994
1170
|
TransactionJsonSchemaValidator
|
|
@@ -1024,7 +1200,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1024
1200
|
let [lastHead] = filterAs(await this.chainArchivist.get([
|
|
1025
1201
|
head
|
|
1026
1202
|
]), asBlockBoundWitnessWithHashStorageMeta);
|
|
1027
|
-
while (
|
|
1203
|
+
while (isDefined3(lastHead)) {
|
|
1028
1204
|
const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
|
|
1029
1205
|
limit: 100,
|
|
1030
1206
|
order: "asc",
|
|
@@ -1035,14 +1211,14 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1035
1211
|
}
|
|
1036
1212
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1037
1213
|
const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
|
|
1038
|
-
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(
|
|
1214
|
+
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists4));
|
|
1039
1215
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1040
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1216
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists4);
|
|
1041
1217
|
const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1));
|
|
1042
1218
|
const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
|
|
1043
1219
|
// Find the corresponding payload bundle hash for the expired transaction
|
|
1044
1220
|
pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
|
|
1045
|
-
)).filter(
|
|
1221
|
+
)).filter(exists4);
|
|
1046
1222
|
foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
|
|
1047
1223
|
}
|
|
1048
1224
|
const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
|
|
@@ -1066,7 +1242,7 @@ var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf
|
|
|
1066
1242
|
|
|
1067
1243
|
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
1068
1244
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
1069
|
-
import { exists as
|
|
1245
|
+
import { exists as exists5 } from "@xylabs/exists";
|
|
1070
1246
|
import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
|
|
1071
1247
|
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
1072
1248
|
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
@@ -1077,7 +1253,7 @@ var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archi
|
|
|
1077
1253
|
const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
|
|
1078
1254
|
const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
|
|
1079
1255
|
return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
|
|
1080
|
-
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(
|
|
1256
|
+
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists5);
|
|
1081
1257
|
const payloads = await archivist.get(stakeIntentHashes);
|
|
1082
1258
|
const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
|
|
1083
1259
|
return stakeIntents;
|
|
@@ -1093,13 +1269,13 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
|
|
|
1093
1269
|
|
|
1094
1270
|
// src/StakeIntent/XyoStakeIntentService.ts
|
|
1095
1271
|
import { filterAs as filterAs3 } from "@xylabs/array";
|
|
1096
|
-
import { assertEx as
|
|
1272
|
+
import { assertEx as assertEx12 } from "@xylabs/assert";
|
|
1097
1273
|
import { creatable as creatable10 } from "@xylabs/creatable";
|
|
1098
1274
|
import { asAddress } from "@xylabs/hex";
|
|
1099
1275
|
import { isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1100
1276
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1101
1277
|
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
1102
|
-
import { PayloadBuilder as
|
|
1278
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1103
1279
|
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1104
1280
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1105
1281
|
import { LRUCache as LRUCache3 } from "lru-cache";
|
|
@@ -1132,16 +1308,16 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1132
1308
|
});
|
|
1133
1309
|
_updateMutex = new Mutex3();
|
|
1134
1310
|
get chainArchivist() {
|
|
1135
|
-
return
|
|
1311
|
+
return assertEx12(this.params.chainArchivist, () => "chainArchivist not set");
|
|
1136
1312
|
}
|
|
1137
1313
|
get chainIterator() {
|
|
1138
|
-
return
|
|
1314
|
+
return assertEx12(this.params.chainIterator, () => "chainIterator not set");
|
|
1139
1315
|
}
|
|
1140
1316
|
get chainStakeViewer() {
|
|
1141
|
-
return
|
|
1317
|
+
return assertEx12(this.params.chainStakeViewer, () => "chainStakeViewer not set");
|
|
1142
1318
|
}
|
|
1143
1319
|
get stakeIntentStateArchivist() {
|
|
1144
|
-
return
|
|
1320
|
+
return assertEx12(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
|
|
1145
1321
|
}
|
|
1146
1322
|
async createHandler() {
|
|
1147
1323
|
this.chainIterator.on("headUpdated", async () => {
|
|
@@ -1149,18 +1325,18 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1149
1325
|
});
|
|
1150
1326
|
const head = await this.chainIterator.head();
|
|
1151
1327
|
if (isUndefined2(head)) return;
|
|
1152
|
-
const headHash = await
|
|
1328
|
+
const headHash = await PayloadBuilder8.hash(head);
|
|
1153
1329
|
await this.recoverState(headHash);
|
|
1154
1330
|
}
|
|
1155
1331
|
async getDeclaredCandidateRanges(address, intent) {
|
|
1156
1332
|
await Promise.resolve();
|
|
1157
|
-
|
|
1333
|
+
assertEx12(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
|
|
1158
1334
|
const results = this._producers.get(address);
|
|
1159
1335
|
return results ?? [];
|
|
1160
1336
|
}
|
|
1161
1337
|
async getDeclaredCandidatesForBlock(block, intent) {
|
|
1162
1338
|
return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
|
|
1163
|
-
|
|
1339
|
+
assertEx12(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
|
|
1164
1340
|
const results = this._producers.findAllContaining(block);
|
|
1165
1341
|
const candidates = [
|
|
1166
1342
|
...results
|
|
@@ -1214,7 +1390,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1214
1390
|
}
|
|
1215
1391
|
async persistState(current) {
|
|
1216
1392
|
const state = this._producers.serialize();
|
|
1217
|
-
const payload = new
|
|
1393
|
+
const payload = new PayloadBuilder8({
|
|
1218
1394
|
schema: ChainIndexingServiceStateSchema
|
|
1219
1395
|
}).fields({
|
|
1220
1396
|
endBlockHash: current,
|
|
@@ -1225,7 +1401,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1225
1401
|
]);
|
|
1226
1402
|
}
|
|
1227
1403
|
async recoverState(current) {
|
|
1228
|
-
const currentBlock =
|
|
1404
|
+
const currentBlock = assertEx12(asBlockBoundWitness3((await this.chainArchivist.get([
|
|
1229
1405
|
current
|
|
1230
1406
|
]))?.[0]), () => `Block ${current} not found`);
|
|
1231
1407
|
const currentBlockNum = currentBlock.block;
|
|
@@ -1266,7 +1442,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1266
1442
|
return await this.spanAsync("updateIndex", async () => {
|
|
1267
1443
|
const currentHead = await this.chainIterator.head();
|
|
1268
1444
|
if (isUndefined2(currentHead)) return;
|
|
1269
|
-
const currentHeadHash = await
|
|
1445
|
+
const currentHeadHash = await PayloadBuilder8.hash(currentHead);
|
|
1270
1446
|
const result = await analyzeChain(this.chainArchivist, [
|
|
1271
1447
|
new ChainStakeIntentAnalyzer("producer")
|
|
1272
1448
|
], currentHeadHash, this._lastIndexedBlockHash);
|
|
@@ -1291,137 +1467,9 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1291
1467
|
XyoStakeIntentService = _ts_decorate10([
|
|
1292
1468
|
creatable10()
|
|
1293
1469
|
], XyoStakeIntentService);
|
|
1294
|
-
|
|
1295
|
-
// src/XyoDataLake.ts
|
|
1296
|
-
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1297
|
-
import { AxiosJson } from "@xylabs/axios";
|
|
1298
|
-
import { exists as exists5 } from "@xylabs/exists";
|
|
1299
|
-
import { isArrayBuffer, isDefined as isDefined3 } from "@xylabs/typeof";
|
|
1300
|
-
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
1301
|
-
import { isHashPayload } from "@xyo-network/xl1-protocol";
|
|
1302
|
-
import { Axios } from "axios";
|
|
1303
|
-
var XyoDataLake = class {
|
|
1304
|
-
static {
|
|
1305
|
-
__name(this, "XyoDataLake");
|
|
1306
|
-
}
|
|
1307
|
-
_axiosGet;
|
|
1308
|
-
_axiosInsertBlob;
|
|
1309
|
-
_axiosInsertJson;
|
|
1310
|
-
_endpoint;
|
|
1311
|
-
constructor(endpoint) {
|
|
1312
|
-
this._endpoint = endpoint;
|
|
1313
|
-
this._axiosInsertJson = new AxiosJson({
|
|
1314
|
-
baseURL: endpoint
|
|
1315
|
-
});
|
|
1316
|
-
this._axiosInsertBlob = new Axios({
|
|
1317
|
-
baseURL: endpoint,
|
|
1318
|
-
headers: {
|
|
1319
|
-
"Content-Type": "application/octet-stream",
|
|
1320
|
-
"Accept": "application/octet-stream"
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
this._axiosGet = new Axios({
|
|
1324
|
-
baseURL: endpoint,
|
|
1325
|
-
headers: {
|
|
1326
|
-
"Content-Type": "application/json",
|
|
1327
|
-
"Accept": "application/octet-stream, application/json"
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
get endpoint() {
|
|
1332
|
-
return this._endpoint;
|
|
1333
|
-
}
|
|
1334
|
-
async add(items) {
|
|
1335
|
-
const results = [];
|
|
1336
|
-
for (const item of items) {
|
|
1337
|
-
if (isAnyPayload(item)) {
|
|
1338
|
-
const result = await this.addPayload(item);
|
|
1339
|
-
if (isAnyPayload(result)) {
|
|
1340
|
-
results.push(result);
|
|
1341
|
-
} else if (isDefined3(result)) {
|
|
1342
|
-
assertEx11(false, () => "Expected result to be a Payload");
|
|
1343
|
-
}
|
|
1344
|
-
} else if (isArrayBuffer(item)) {
|
|
1345
|
-
const result = await this.addArrayBuffer(item);
|
|
1346
|
-
if (isAnyPayload(result)) {
|
|
1347
|
-
results.push(result);
|
|
1348
|
-
} else if (isDefined3(result)) {
|
|
1349
|
-
assertEx11(false, () => "Expected result to be a Payload");
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
return results;
|
|
1354
|
-
}
|
|
1355
|
-
async fetch(hashes, maxDepth) {
|
|
1356
|
-
return (await Promise.all(hashes.map(async (hash) => {
|
|
1357
|
-
return await this.fetchOne(hash, maxDepth);
|
|
1358
|
-
}))).filter(exists5);
|
|
1359
|
-
}
|
|
1360
|
-
async get(hashes) {
|
|
1361
|
-
return (await Promise.all(hashes.map(async (hash) => {
|
|
1362
|
-
return await this.getOne(hash);
|
|
1363
|
-
}))).filter(exists5);
|
|
1364
|
-
}
|
|
1365
|
-
async trace(hash) {
|
|
1366
|
-
const result = await this.getOne(hash);
|
|
1367
|
-
if (isHashPayload(result)) {
|
|
1368
|
-
const [payload, route] = await this.trace(result.hash);
|
|
1369
|
-
return [
|
|
1370
|
-
payload,
|
|
1371
|
-
[
|
|
1372
|
-
result,
|
|
1373
|
-
...route
|
|
1374
|
-
]
|
|
1375
|
-
];
|
|
1376
|
-
}
|
|
1377
|
-
return [
|
|
1378
|
-
result,
|
|
1379
|
-
[]
|
|
1380
|
-
];
|
|
1381
|
-
}
|
|
1382
|
-
async addArrayBuffer(item) {
|
|
1383
|
-
const result = await this._axiosInsertBlob.post("/insert", item);
|
|
1384
|
-
if (result.status < 200 || result.status >= 300) {
|
|
1385
|
-
throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
|
|
1386
|
-
}
|
|
1387
|
-
if (!isArrayBuffer(result.data)) {
|
|
1388
|
-
throw new Error("Invalid response from server (expected a ArrayBuffer)");
|
|
1389
|
-
}
|
|
1390
|
-
return result.data;
|
|
1391
|
-
}
|
|
1392
|
-
async addPayload(item) {
|
|
1393
|
-
const result = await this._axiosInsertJson.post("/insert", item);
|
|
1394
|
-
if (result.status < 200 || result.status >= 300) {
|
|
1395
|
-
throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
|
|
1396
|
-
}
|
|
1397
|
-
if (!isAnyPayload(result.data)) {
|
|
1398
|
-
throw new Error("Invalid response from server (expected a Payload)");
|
|
1399
|
-
}
|
|
1400
|
-
return result.data;
|
|
1401
|
-
}
|
|
1402
|
-
async fetchOne(hash, maxDepth = Number.MAX_SAFE_INTEGER) {
|
|
1403
|
-
if (maxDepth <= 0) {
|
|
1404
|
-
return void 0;
|
|
1405
|
-
}
|
|
1406
|
-
const result = await this.getOne(hash);
|
|
1407
|
-
if (isHashPayload(result)) {
|
|
1408
|
-
return await this.fetchOne(result.hash, maxDepth - 1);
|
|
1409
|
-
}
|
|
1410
|
-
return result;
|
|
1411
|
-
}
|
|
1412
|
-
getOne(hash) {
|
|
1413
|
-
return this._axiosGet.get(`/get/${hash}`).then((response) => {
|
|
1414
|
-
if (response.status < 200 || response.status >= 300) {
|
|
1415
|
-
throw new Error(`Failed to get item [${response.status}]: ${response.statusText}`);
|
|
1416
|
-
}
|
|
1417
|
-
if (!isAnyPayload(response.data)) {
|
|
1418
|
-
throw new Error("Invalid response from server (expected a Payload)");
|
|
1419
|
-
}
|
|
1420
|
-
return response.data;
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
};
|
|
1424
1470
|
export {
|
|
1471
|
+
AbstractXyoDataLake,
|
|
1472
|
+
ArchivistXyoDataLake,
|
|
1425
1473
|
BaseAccountBalanceService,
|
|
1426
1474
|
BaseAccountableService,
|
|
1427
1475
|
BaseBlockProducerService,
|
|
@@ -1433,11 +1481,11 @@ export {
|
|
|
1433
1481
|
DEFAULT_BLOCK_SIZE,
|
|
1434
1482
|
EvmBlockRewardService,
|
|
1435
1483
|
EvmChainService,
|
|
1484
|
+
HttpXyoDataLake,
|
|
1436
1485
|
MemoryBlockRewardService,
|
|
1437
1486
|
MemoryChainService,
|
|
1438
1487
|
XYO_PRODUCER_REDECLARATION_DURATION,
|
|
1439
1488
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1440
|
-
XyoDataLake,
|
|
1441
1489
|
XyoStakeIntentService,
|
|
1442
1490
|
XyoValidator,
|
|
1443
1491
|
accountBalanceServiceFromArchivist,
|