@autonomys/auto-consensus 0.6.6 → 0.6.8

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/info.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { AnyTuple, Api, Codec, StorageKey } from '@autonomys/auto-utils';
1
+ import type { AnyTuple, Api, Codec, StorageKey } from '@autonomys/auto-utils';
2
+ import type { RawBlock, RawBlockHeader } from './types/block';
2
3
  export declare const rpc: <T>(api: Api, methodPath: string, params?: any[]) => Promise<T>;
3
4
  export declare const query: <T>(api: Api, methodPath: string, params?: any[]) => Promise<T>;
4
- export declare const block: <RawBlock>(api: Api) => Promise<RawBlock>;
5
+ export declare const block: (api: Api) => Promise<RawBlock>;
6
+ export declare const header: (api: Api) => Promise<RawBlockHeader>;
5
7
  export declare const blockNumber: (api: Api) => Promise<number>;
6
8
  export declare const blockHash: (api: Api) => Promise<string>;
7
9
  export declare const networkTimestamp: (api: Api) => Promise<Codec>;
@@ -15,7 +17,7 @@ export declare const shouldAdjustSolutionRange: (api: Api) => Promise<boolean>;
15
17
  export declare const segmentCommitment: (api: Api) => Promise<[StorageKey<AnyTuple>, Codec][]>;
16
18
  export declare const slotProbability: (api: Api) => [number, number];
17
19
  export declare const maxPiecesInSector: (api: Api) => bigint;
18
- export declare function solutionRangeToSectors(solutionRange: bigint, slotProbability: [bigint, bigint], piecesInSector: bigint): bigint;
20
+ export declare function solutionRangeToPieces(solutionRange: bigint, slotProbability: [bigint, bigint]): bigint;
19
21
  export declare const spacePledge: (api: Api) => Promise<bigint>;
20
22
  export declare const blockchainSize: (api: Api) => Promise<bigint>;
21
23
  //# sourceMappingURL=info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAMxE,eAA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
10
  });
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.blockchainSize = exports.spacePledge = exports.maxPiecesInSector = exports.slotProbability = exports.segmentCommitment = exports.shouldAdjustSolutionRange = exports.solutionRanges = exports.networkTimestamp = exports.blockHash = exports.blockNumber = exports.block = exports.query = exports.rpc = void 0;
14
- exports.solutionRangeToSectors = solutionRangeToSectors;
13
+ exports.blockchainSize = exports.spacePledge = exports.maxPiecesInSector = exports.slotProbability = exports.segmentCommitment = exports.shouldAdjustSolutionRange = exports.solutionRanges = exports.networkTimestamp = exports.blockHash = exports.blockNumber = exports.header = exports.block = exports.query = exports.rpc = void 0;
14
+ exports.solutionRangeToPieces = solutionRangeToPieces;
15
15
  const query_1 = require("./utils/query");
16
16
  const PIECE_SIZE = BigInt(1048576);
17
17
  const rpc = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) { return yield (0, query_1.queryMethodPath)(api, `rpc.${methodPath}`, params); });
@@ -20,6 +20,8 @@ const query = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, meth
20
20
  exports.query = query;
21
21
  const block = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getBlock', []); });
22
22
  exports.block = block;
23
+ const header = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getHeader', []); });
24
+ exports.header = header;
23
25
  const blockNumber = (api) => __awaiter(void 0, void 0, void 0, function* () {
24
26
  // Get the block
25
27
  const _block = yield (0, exports.block)(api);
@@ -46,28 +48,36 @@ const solutionRanges = (api) => __awaiter(void 0, void 0, void 0, function* () {
46
48
  exports.solutionRanges = solutionRanges;
47
49
  const shouldAdjustSolutionRange = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'subspace.shouldAdjustSolutionRange', []); });
48
50
  exports.shouldAdjustSolutionRange = shouldAdjustSolutionRange;
49
- const segmentCommitment = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'subspace.segmentCommitment', []); });
51
+ const segmentCommitment = (api) => __awaiter(void 0, void 0, void 0, function* () {
52
+ if (api.at) {
53
+ const { parentHash } = yield (0, exports.header)(api);
54
+ api = yield api.at(parentHash);
55
+ }
56
+ return yield (0, exports.query)(api, 'subspace.segmentCommitment.entries', []);
57
+ });
50
58
  exports.segmentCommitment = segmentCommitment;
51
59
  const slotProbability = (api) => api.consts.subspace.slotProbability.toPrimitive();
52
60
  exports.slotProbability = slotProbability;
53
61
  const maxPiecesInSector = (api) => BigInt(api.consts.subspace.maxPiecesInSector.toPrimitive());
54
62
  exports.maxPiecesInSector = maxPiecesInSector;
55
- function solutionRangeToSectors(solutionRange, slotProbability, piecesInSector) {
63
+ function solutionRangeToPieces(solutionRange, slotProbability) {
56
64
  const MAX_U64 = BigInt(Math.pow(2, 64) - 1);
57
65
  const RECORD_NUM_CHUNKS = BigInt(32768);
58
66
  const RECORD_NUM_S_BUCKETS = BigInt(65536);
59
- const sectors = ((MAX_U64 / slotProbability[1]) * slotProbability[0]) /
60
- ((piecesInSector * RECORD_NUM_CHUNKS) / RECORD_NUM_S_BUCKETS);
61
- return sectors / solutionRange;
67
+ const pieces = (((MAX_U64 / slotProbability[1]) * slotProbability[0]) / RECORD_NUM_CHUNKS) *
68
+ RECORD_NUM_S_BUCKETS;
69
+ return pieces / solutionRange;
62
70
  }
63
71
  const spacePledge = (api) => __awaiter(void 0, void 0, void 0, function* () {
64
72
  const _solutionRanges = yield (0, exports.solutionRanges)(api);
65
73
  const _slotProbability = (0, exports.slotProbability)(api);
66
- const _maxPiecesInSector = (0, exports.maxPiecesInSector)(api);
67
- if (!_solutionRanges.current || !_slotProbability || !_maxPiecesInSector)
74
+ if (!_solutionRanges.current || !_slotProbability)
68
75
  return BigInt(0);
69
- const sectors = solutionRangeToSectors(_solutionRanges.current, [BigInt(_slotProbability[0]), BigInt(_slotProbability[1])], _maxPiecesInSector);
70
- const totalSpacePledged = sectors * _maxPiecesInSector * PIECE_SIZE;
76
+ const pieces = solutionRangeToPieces(_solutionRanges.current, [
77
+ BigInt(_slotProbability[0]),
78
+ BigInt(_slotProbability[1]),
79
+ ]);
80
+ const totalSpacePledged = pieces * PIECE_SIZE;
71
81
  return totalSpacePledged;
72
82
  });
73
83
  exports.spacePledge = spacePledge;
@@ -12,6 +12,21 @@ export type RawBlock = {
12
12
  };
13
13
  };
14
14
  };
15
+ type DigestLog = {
16
+ preRuntime?: string[];
17
+ consensus?: string[];
18
+ other?: string;
19
+ seal?: string[];
20
+ };
21
+ export type RawBlockHeader = {
22
+ parentHash: string;
23
+ number: number;
24
+ stateRoot: string;
25
+ extrinsicsRoot: string;
26
+ digest: {
27
+ logs: DigestLog[];
28
+ };
29
+ };
15
30
  export type Block = {
16
31
  block: {
17
32
  header: {
@@ -25,4 +40,5 @@ export type Block = {
25
40
  };
26
41
  };
27
42
  };
43
+ export {};
28
44
  //# sourceMappingURL=block.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAE/C,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,EAAE,CAAA;YACV,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,MAAM,CAAA;YACd,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA"}
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAE/C,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,EAAE,CAAA;YACV,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAED,KAAK,SAAS,GAAG;IACf,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE;QACN,IAAI,EAAE,SAAS,EAAE,CAAA;KAClB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,MAAM,CAAA;YACd,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-consensus",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "url": "https://www.autonomys.net"
23
23
  },
24
24
  "dependencies": {
25
- "@autonomys/auto-utils": "^0.6.6"
25
+ "@autonomys/auto-utils": "^0.6.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/jest": "^29.5.12",
@@ -32,5 +32,5 @@
32
32
  "ts-jest": "^29.1.4",
33
33
  "typescript": "^5.4.5"
34
34
  },
35
- "gitHead": "94646ea042d018cd883558fb6ca750ed49d95dae"
35
+ "gitHead": "509bb6d337ca6c0f4da389cd342f1b58be57cb7e"
36
36
  }