@acala-network/chopsticks 0.7.3 → 0.8.0-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/lib/cli-options.d.ts +40 -0
- package/lib/cli-options.js +43 -0
- package/lib/cli.js +19 -146
- package/lib/context.d.ts +5 -0
- package/lib/context.js +37 -0
- package/lib/index.d.ts +2 -7
- package/lib/index.js +2 -13
- package/lib/logger.d.ts +1 -7
- package/lib/logger.js +3 -38
- package/lib/plugins/decode-key/index.d.ts +2 -0
- package/lib/plugins/decode-key/index.js +27 -0
- package/lib/plugins/dry-run/cli.d.ts +2 -0
- package/lib/plugins/dry-run/cli.js +46 -0
- package/lib/plugins/dry-run/dry-run-extrinsic.d.ts +2 -0
- package/lib/{dry-run.js → plugins/dry-run/dry-run-extrinsic.js} +8 -8
- package/lib/{dry-run-preimage.d.ts → plugins/dry-run/dry-run-preimage.d.ts} +1 -1
- package/lib/{dry-run-preimage.js → plugins/dry-run/dry-run-preimage.js} +10 -12
- package/lib/plugins/dry-run/index.d.ts +2 -0
- package/lib/plugins/dry-run/index.js +18 -0
- package/lib/plugins/dry-run/rpc.d.ts +3 -0
- package/lib/{rpc/dev/dry-run.js → plugins/dry-run/rpc.js} +10 -7
- package/lib/plugins/index.d.ts +4 -0
- package/lib/plugins/index.js +52 -0
- package/lib/plugins/new-block/index.d.ts +2 -0
- package/lib/plugins/new-block/index.js +28 -0
- package/lib/plugins/run-block/index.d.ts +2 -0
- package/lib/plugins/run-block/index.js +67 -0
- package/lib/plugins/set-block-build-mode/index.d.ts +2 -0
- package/lib/plugins/set-block-build-mode/index.js +14 -0
- package/lib/plugins/set-head/index.d.ts +2 -0
- package/lib/plugins/set-head/index.js +20 -0
- package/lib/plugins/set-storage/index.d.ts +2 -0
- package/lib/plugins/set-storage/index.js +18 -0
- package/lib/plugins/time-travel/index.d.ts +2 -0
- package/lib/plugins/time-travel/index.js +13 -0
- package/lib/plugins/try-runtime/index.d.ts +2 -0
- package/lib/plugins/try-runtime/index.js +58 -0
- package/lib/rpc/index.d.ts +1 -1
- package/lib/rpc/index.js +11 -4
- package/lib/rpc/shared.d.ts +1 -1
- package/lib/rpc/shared.js +1 -1
- package/lib/rpc/substrate/author.js +3 -3
- package/lib/schema/index.d.ts +8 -66
- package/lib/schema/index.js +7 -18
- package/lib/server.js +2 -1
- package/lib/setup-with-server.d.ts +1 -3
- package/lib/setup-with-server.js +2 -2
- package/lib/utils/decoder.d.ts +1 -1
- package/lib/utils/generate-html-diff.d.ts +1 -1
- package/lib/utils/override.d.ts +4 -0
- package/lib/utils/{import-storage.js → override.js} +6 -6
- package/package.json +13 -16
- package/lib/api.d.ts +0 -43
- package/lib/api.js +0 -79
- package/lib/blockchain/block-builder.d.ts +0 -10
- package/lib/blockchain/block-builder.js +0 -297
- package/lib/blockchain/block.d.ts +0 -45
- package/lib/blockchain/block.js +0 -194
- package/lib/blockchain/head-state.d.ts +0 -15
- package/lib/blockchain/head-state.js +0 -71
- package/lib/blockchain/index.d.ts +0 -64
- package/lib/blockchain/index.js +0 -243
- package/lib/blockchain/inherent/index.d.ts +0 -19
- package/lib/blockchain/inherent/index.js +0 -36
- package/lib/blockchain/inherent/para-enter.d.ts +0 -7
- package/lib/blockchain/inherent/para-enter.js +0 -33
- package/lib/blockchain/inherent/parachain/babe-randomness.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/babe-randomness.js +0 -15
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -7
- package/lib/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -15
- package/lib/blockchain/inherent/parachain/validation-data.d.ts +0 -19
- package/lib/blockchain/inherent/parachain/validation-data.js +0 -172
- package/lib/blockchain/storage-layer.d.ts +0 -32
- package/lib/blockchain/storage-layer.js +0 -200
- package/lib/blockchain/txpool.d.ts +0 -45
- package/lib/blockchain/txpool.js +0 -184
- package/lib/db/entities.d.ts +0 -5
- package/lib/db/entities.js +0 -33
- package/lib/db/index.d.ts +0 -3
- package/lib/db/index.js +0 -41
- package/lib/dry-run.d.ts +0 -2
- package/lib/executor.d.ts +0 -40
- package/lib/executor.js +0 -131
- package/lib/genesis-provider.d.ts +0 -44
- package/lib/genesis-provider.js +0 -155
- package/lib/offchain.d.ts +0 -10
- package/lib/offchain.js +0 -37
- package/lib/rpc/dev/dry-run.d.ts +0 -2
- package/lib/rpc/dev/index.d.ts +0 -3
- package/lib/rpc/dev/index.js +0 -75
- package/lib/run-block.d.ts +0 -2
- package/lib/run-block.js +0 -51
- package/lib/setup.d.ts +0 -11
- package/lib/setup.js +0 -86
- package/lib/try-runtime.d.ts +0 -2
- package/lib/try-runtime.js +0 -36
- package/lib/utils/import-storage.d.ts +0 -5
- package/lib/utils/index.d.ts +0 -16
- package/lib/utils/index.js +0 -59
- package/lib/utils/key-cache.d.ts +0 -10
- package/lib/utils/key-cache.js +0 -66
- package/lib/utils/proof.d.ts +0 -15
- package/lib/utils/proof.js +0 -41
- package/lib/utils/set-storage.d.ts +0 -7
- package/lib/utils/set-storage.js +0 -59
- package/lib/utils/time-travel.d.ts +0 -5
- package/lib/utils/time-travel.js +0 -65
- package/lib/xcm/downward.d.ts +0 -2
- package/lib/xcm/downward.js +0 -29
- package/lib/xcm/horizontal.d.ts +0 -2
- package/lib/xcm/horizontal.js +0 -29
- package/lib/xcm/index.d.ts +0 -9
- package/lib/xcm/index.js +0 -25
- package/lib/xcm/upward.d.ts +0 -2
- package/lib/xcm/upward.js +0 -21
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Block } from '../../block';
|
|
3
|
-
import { BuildBlockParams } from '../../txpool';
|
|
4
|
-
import { CreateInherents } from '..';
|
|
5
|
-
export declare class SetBabeRandomness implements CreateInherents {
|
|
6
|
-
createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetBabeRandomness = void 0;
|
|
4
|
-
const types_1 = require("@polkadot/types");
|
|
5
|
-
// Support for Moonbeam pallet-randomness mandatory inherent
|
|
6
|
-
class SetBabeRandomness {
|
|
7
|
-
async createInherents(parent, _params) {
|
|
8
|
-
const meta = await parent.meta;
|
|
9
|
-
if (!meta.tx.randomness?.setBabeRandomnessResults) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
return [new types_1.GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.SetBabeRandomness = SetBabeRandomness;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Block } from '../../block';
|
|
3
|
-
import { BuildBlockParams } from '../../txpool';
|
|
4
|
-
import { CreateInherents } from '..';
|
|
5
|
-
export declare class SetNimbusAuthorInherent implements CreateInherents {
|
|
6
|
-
createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetNimbusAuthorInherent = void 0;
|
|
4
|
-
const types_1 = require("@polkadot/types");
|
|
5
|
-
// Support for Nimbus Author Inherent
|
|
6
|
-
class SetNimbusAuthorInherent {
|
|
7
|
-
async createInherents(parent, _params) {
|
|
8
|
-
const meta = await parent.meta;
|
|
9
|
-
if (!meta.tx.authorInherent?.kickOffAuthorshipValidation) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
return [new types_1.GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.SetNimbusAuthorInherent = SetNimbusAuthorInherent;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HexString } from '@polkadot/util/types';
|
|
2
|
-
import { Block } from '../../block';
|
|
3
|
-
import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool';
|
|
4
|
-
import { CreateInherents } from '..';
|
|
5
|
-
export type ValidationData = {
|
|
6
|
-
downwardMessages: DownwardMessage[];
|
|
7
|
-
horizontalMessages: Record<number, HorizontalMessage[]>;
|
|
8
|
-
validationData: {
|
|
9
|
-
relayParentNumber: number;
|
|
10
|
-
relayParentStorageRoot: HexString;
|
|
11
|
-
maxPovSize: number;
|
|
12
|
-
};
|
|
13
|
-
relayChainState: {
|
|
14
|
-
trieNodes: HexString[];
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export declare class SetValidationData implements CreateInherents {
|
|
18
|
-
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
19
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SetValidationData = void 0;
|
|
7
|
-
const types_1 = require("@polkadot/types");
|
|
8
|
-
const util_1 = require("@polkadot/util");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const proof_1 = require("../../../utils/proof");
|
|
11
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
12
|
-
const utils_1 = require("../../../utils");
|
|
13
|
-
const executor_1 = require("../../../executor");
|
|
14
|
-
const MOCK_VALIDATION_DATA = {
|
|
15
|
-
validationData: {
|
|
16
|
-
relayParentNumber: 1000,
|
|
17
|
-
relayParentStorageRoot: '0x49416764844ff0d8bad851e8abe686dff9dd2de78621180ef8e9f99bb7a480f1',
|
|
18
|
-
maxPovSize: 5242880,
|
|
19
|
-
},
|
|
20
|
-
relayChainState: {
|
|
21
|
-
trieNodes: [
|
|
22
|
-
'0x5f04b49d95320d9021994c850f25b8e385f902000030000080000008000000000010000000100005000000050000000a0000000a000000000050000000100000e8764817000000040000000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000400000000001000b0040000000000000000000014000000040000000400000000000000010100000000060000006400000002000000c8000000020000001900000000000000020000000200000000c817a804000000',
|
|
23
|
-
'0x80011080ace5323aee784b03389c0e2cc68d81973f8fa26d395f333ecad7399271c781e1808e5db75be813c05205986cbd6fdede707a4d26816063a41eb42ebc262c734fad',
|
|
24
|
-
'0x8004648086a9239b72237f5bf119e2a880c32f5866460632700509cb874c60f67fe815ea80f6f6801e4b41e2e6d8ec194dba122bfb9eb33feb2545ef5144cea79551f7cc5280c629a7e712d763fe83b35d2a082430af6737a89f23219c0eb3051c83bc5af5ad80fed5ecd6097308a6540f8cf31aeaad186e6898d2ecc0e623767c521c70e39953',
|
|
25
|
-
'0x800804809f3ada68c357b5e0a3ebb39ef181acfa9943af4725c244330a4b2c60837612e88082ad3fbdf392429afeacc70177704b760bb145547c1f152e1fcf651916b43820',
|
|
26
|
-
'0x8008208042793f557c1d003b647e2eda79c2b5088c7d8cab2e82c1dcc87f4343cca91ae4485ead6eef5c4b1c68eaa71ea17a02d9de0400',
|
|
27
|
-
'0x80210280de38445d825563f8e218255a417c16971afa85b4f2ef18fbe08fbc5b976dc0d6801a2ff24096295cfccf1adda80b8dfffe380b9f3b54d7a3cdb67864a4655e62968022a699b2cc90a6654c84163d2a498506b192afe7cd9777227e5288e8ff069c0f',
|
|
28
|
-
'0x80400180ebebd1a1cd0bbc6714b7fb0ac854cca5a4c4e34e69485da48be3c8087b56e09b80128645c79ca6581c248a412fd7b8bc532a187600e6e1cc20c915538ba4df6a79',
|
|
29
|
-
'0x80ffbe80d9302a505e2b1ac931f539aed33bf791d1982906ae64c7197324044f191e9bca80972cd2f703f9c94fd516e14b7013c6f1545095855b6c4b36f21d89dad30aa54d80b2495ce4d07001927bb0857611f8d3a1449e791d0b010e3861c32dec0c44179680f5929c8ef9b0ac6ec8a529c91348d8cd6c169920dd37d055544a6c31c53b11e380402a0bf7ff07cee790d9cc065fc138ff6afa7db016d898d65b2b716af354c6f68042aef1dafffd1d9debbb8e6c4eb48b5c141ddf0aad2b0f3f4ddf53e6b38e65c080b31fa0392c1abdce1aa29d1544c94634ecab87ecaba6409db33aaa7621992a8280b1f4de7c3ac5665016d561a60659cd2d8f2d3e0a97e2ea9749279bd8e35eb1f180816ac87a2893694016b21768137a76ea459190ea0fc3c645d85e1a3d4eb194fe802e563b43e7334454c841953424be8c2b7a1c3295dbc391045cb6b88388ad5e7080b1ed3b02e5989b7d134ca056c778f1f5b6ffd377b2d8064483da6e94b82b0e40800cb3299c44a5db8fdcb4932e1b6ab0385d6ef1c9f8d85e0a75b787b6f4fd6c3c805a44c30e2676dc2d4c17451f51d9502e85064387999f366e6f3d404509a7780f80d6788ca71c6aabe421c352027acdb9532563dc5f1b25e6154b721f431e9990ed',
|
|
30
|
-
'0x9d0da05ca59913bc38a8630590f2627c154080834dda0ba5adf00d798e981a28a13e728cf83e35aefc87318440a61869f724474c5f0a351b6a99a5b21324516e668bb86a570400505f0e7b9012096b41c4eb3aaf947f6ea4290800007c7700e67da63472835bb0b737093a19ad4c63f5a4efb16ffa83d00700000400',
|
|
31
|
-
'0x9e207f03cfdce586301014700e2c25931040505f0e7b9012096b41c4eb3aaf947f6ea4290800004c5f0ec2d17a76153ff51817f12d9cfc3c7f0400',
|
|
32
|
-
'0x9e710b30bd2eab0352ddcc26417aa1945fc180699a53b51a9709a3a86039c49b5ef278e9fc244dae27e1a0380c91bff5b0488580c0d4096d94e724b8e86f952e5456c7253776de04c405582d2c350ee172d3eaa77c77081e0bfde17b36573208a06cb5cfba6b63f5a4efb16ffa83d00700000402803d0ae0b8f6832e8fabf0ec62521c2487c58b69eb97060faa8059b00ff6b7262d505f0e7b9012096b41c4eb3aaf947f6ea4290800004c5f03c716fb8fff3de61a883bb76adb34a20400806c8122e0f7f786071d6a51b330d612eccdcbe8d8f79936accabd640506dffdf380a6abfb72ed49b586829cca4ce631c092d45a017ab0d68288d308873025cfe5d280521b868fc212b25f021984cf02ced547cd45952b88360766839dfde7d4683e61',
|
|
33
|
-
'0x9ede3d8a54d27e44a9d5ce189618f22d1008505f0e7b9012096b41c4eb3aaf947f6ea42908010080c74756edffa217dfb07ab596d82753deff985ac215e5cc2997d29afe1d397c16',
|
|
34
|
-
'0x9ef78c98723ddc9073523ef3beefda0c1004505f0e7b9012096b41c4eb3aaf947f6ea4290800007c77095dac46c07a40d91506e7637ec4ba5763f5a4efb16ffa83d00700000400',
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
class SetValidationData {
|
|
39
|
-
async createInherents(parent, params) {
|
|
40
|
-
const meta = await parent.meta;
|
|
41
|
-
if (!meta.tx.parachainSystem?.setValidationData) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const extrinsics = await parent.extrinsics;
|
|
45
|
-
let newData;
|
|
46
|
-
if (parent.number === 0) {
|
|
47
|
-
// chain started with genesis, mock 1st validationData
|
|
48
|
-
newData = MOCK_VALIDATION_DATA;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const validationDataExtrinsic = extrinsics.find((extrinsic) => {
|
|
52
|
-
const firstArg = meta.registry.createType('GenericExtrinsic', extrinsic)?.args?.[0];
|
|
53
|
-
return firstArg && 'validationData' in firstArg;
|
|
54
|
-
});
|
|
55
|
-
if (!validationDataExtrinsic) {
|
|
56
|
-
throw new Error('Missing validation data from block');
|
|
57
|
-
}
|
|
58
|
-
const extrinsic = meta.registry
|
|
59
|
-
.createType('GenericExtrinsic', validationDataExtrinsic)
|
|
60
|
-
.args[0].toJSON();
|
|
61
|
-
const newEntries = [];
|
|
62
|
-
const downwardMessages = [];
|
|
63
|
-
const horizontalMessages = {};
|
|
64
|
-
const paraId = await (0, utils_1.getParaId)(parent.chain);
|
|
65
|
-
const dmqMqcHeadKey = (0, proof_1.dmqMqcHead)(paraId);
|
|
66
|
-
const hrmpIngressChannelIndexKey = (0, proof_1.hrmpIngressChannelIndex)(paraId);
|
|
67
|
-
const hrmpEgressChannelIndexKey = (0, proof_1.hrmpEgressChannelIndex)(paraId);
|
|
68
|
-
// TODO: refactor this to have a single decodeProof
|
|
69
|
-
const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [...Object.values(proof_1.WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
|
|
70
|
-
for (const key of Object.values(proof_1.WELL_KNOWN_KEYS)) {
|
|
71
|
-
newEntries.push([key, decoded[key]]);
|
|
72
|
-
}
|
|
73
|
-
newEntries.push([hrmpIngressChannelIndexKey, decoded[hrmpIngressChannelIndexKey]]);
|
|
74
|
-
newEntries.push([hrmpEgressChannelIndexKey, decoded[hrmpEgressChannelIndexKey]]);
|
|
75
|
-
// inject downward messages
|
|
76
|
-
let dmqMqcHeadHash = decoded[dmqMqcHeadKey];
|
|
77
|
-
if (dmqMqcHeadHash) {
|
|
78
|
-
for (const { msg, sentAt } of params.downwardMessages) {
|
|
79
|
-
// calculate new hash
|
|
80
|
-
dmqMqcHeadHash = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', dmqMqcHeadHash).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(meta.registry.createType('Bytes', msg).toU8a(), 256)), 256);
|
|
81
|
-
downwardMessages.push({
|
|
82
|
-
msg,
|
|
83
|
-
sentAt,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
newEntries.push([dmqMqcHeadKey, dmqMqcHeadHash]);
|
|
87
|
-
}
|
|
88
|
-
const hrmpIngressChannels = meta.registry
|
|
89
|
-
.createType('Vec<ParaId>', decoded[hrmpIngressChannelIndexKey])
|
|
90
|
-
.toJSON();
|
|
91
|
-
const hrmpEgressChannels = meta.registry
|
|
92
|
-
.createType('Vec<ParaId>', decoded[hrmpEgressChannelIndexKey])
|
|
93
|
-
.toJSON();
|
|
94
|
-
const hrmpMessages = {
|
|
95
|
-
// reset values, we just need the keys
|
|
96
|
-
...lodash_1.default.mapValues(extrinsic.horizontalMessages, () => []),
|
|
97
|
-
...params.horizontalMessages,
|
|
98
|
-
};
|
|
99
|
-
// inject horizontal messages
|
|
100
|
-
for (const id of hrmpIngressChannels) {
|
|
101
|
-
const messages = hrmpMessages[id];
|
|
102
|
-
const sender = Number(id);
|
|
103
|
-
const channelId = meta.registry.createType('HrmpChannelId', {
|
|
104
|
-
sender,
|
|
105
|
-
receiver: paraId.toNumber(),
|
|
106
|
-
});
|
|
107
|
-
const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
|
|
108
|
-
const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
|
|
109
|
-
const abridgedHrmpRaw = decoded[hrmpChannelKey];
|
|
110
|
-
if (!abridgedHrmpRaw)
|
|
111
|
-
throw new Error('Canoot find hrmp channels from validation data');
|
|
112
|
-
const abridgedHrmp = meta.registry
|
|
113
|
-
.createType('AbridgedHrmpChannel', (0, util_1.hexToU8a)(abridgedHrmpRaw))
|
|
114
|
-
.toJSON();
|
|
115
|
-
const paraMessages = [];
|
|
116
|
-
for (const { data, sentAt } of messages) {
|
|
117
|
-
// calculate new hash
|
|
118
|
-
const bytes = meta.registry.createType('Bytes', data);
|
|
119
|
-
abridgedHrmp.mqcHead = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(bytes.toU8a(), 256)), 256);
|
|
120
|
-
abridgedHrmp.msgCount = abridgedHrmp.msgCount + 1;
|
|
121
|
-
abridgedHrmp.totalSize = abridgedHrmp.totalSize + bytes.length;
|
|
122
|
-
paraMessages.push({
|
|
123
|
-
data,
|
|
124
|
-
sentAt,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
horizontalMessages[sender] = paraMessages;
|
|
128
|
-
newEntries.push([hrmpChannelKey, meta.registry.createType('AbridgedHrmpChannel', abridgedHrmp).toHex()]);
|
|
129
|
-
}
|
|
130
|
-
// inject hrmpEgressChannels proof
|
|
131
|
-
for (const id of hrmpEgressChannels) {
|
|
132
|
-
// const messages = hrmpMessages[id]
|
|
133
|
-
const receiver = Number(id);
|
|
134
|
-
const channelId = meta.registry.createType('HrmpChannelId', {
|
|
135
|
-
sender: paraId.toNumber(),
|
|
136
|
-
receiver,
|
|
137
|
-
});
|
|
138
|
-
const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
|
|
139
|
-
const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
|
|
140
|
-
newEntries.push([hrmpChannelKey, decoded[hrmpChannelKey]]);
|
|
141
|
-
}
|
|
142
|
-
const upgradeKey = (0, proof_1.upgradeGoAheadSignal)(paraId);
|
|
143
|
-
const pendingUpgrade = await parent.get((0, utils_1.compactHex)(meta.query.parachainSystem.pendingValidationCode()));
|
|
144
|
-
if (pendingUpgrade) {
|
|
145
|
-
// send goAhead signal
|
|
146
|
-
const goAhead = meta.registry.createType('UpgradeGoAhead', 'GoAhead');
|
|
147
|
-
newEntries.push([upgradeKey, goAhead.toHex()]);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
// make sure previous goAhead is removed
|
|
151
|
-
newEntries.push([upgradeKey, null]);
|
|
152
|
-
}
|
|
153
|
-
const { trieRootHash, nodes } = await (0, executor_1.createProof)(extrinsic.relayChainState.trieNodes, newEntries);
|
|
154
|
-
newData = {
|
|
155
|
-
...extrinsic,
|
|
156
|
-
downwardMessages,
|
|
157
|
-
horizontalMessages,
|
|
158
|
-
validationData: {
|
|
159
|
-
...extrinsic.validationData,
|
|
160
|
-
relayParentStorageRoot: trieRootHash,
|
|
161
|
-
relayParentNumber: extrinsic.validationData.relayParentNumber + 2,
|
|
162
|
-
},
|
|
163
|
-
relayChainState: {
|
|
164
|
-
trieNodes: nodes,
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const inherent = new types_1.GenericExtrinsic(meta.registry, meta.tx.parachainSystem.setValidationData(newData));
|
|
169
|
-
return [inherent.toHex()];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.SetValidationData = SetValidationData;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
2
|
-
import { Api } from '../api';
|
|
3
|
-
export declare const enum StorageValueKind {
|
|
4
|
-
Deleted = "Deleted",
|
|
5
|
-
DeletedPrefix = "DeletedPrefix"
|
|
6
|
-
}
|
|
7
|
-
export type StorageValue = string | StorageValueKind | undefined;
|
|
8
|
-
export interface StorageLayerProvider {
|
|
9
|
-
get(key: string, cache: boolean): Promise<StorageValue>;
|
|
10
|
-
foldInto(into: StorageLayer): Promise<StorageLayerProvider | undefined>;
|
|
11
|
-
fold(): Promise<void>;
|
|
12
|
-
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
13
|
-
}
|
|
14
|
-
export declare class RemoteStorageLayer implements StorageLayerProvider {
|
|
15
|
-
#private;
|
|
16
|
-
constructor(api: Api, at: string, db: DataSource | undefined);
|
|
17
|
-
get(key: string): Promise<StorageValue>;
|
|
18
|
-
foldInto(_into: StorageLayer): Promise<StorageLayerProvider>;
|
|
19
|
-
fold(): Promise<void>;
|
|
20
|
-
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
21
|
-
}
|
|
22
|
-
export declare class StorageLayer implements StorageLayerProvider {
|
|
23
|
-
#private;
|
|
24
|
-
constructor(parent?: StorageLayerProvider);
|
|
25
|
-
get(key: string, cache: boolean): Promise<StorageValue | undefined>;
|
|
26
|
-
set(key: string, value: StorageValue): void;
|
|
27
|
-
setAll(values: Record<string, StorageValue | null> | [string, StorageValue | null][]): void;
|
|
28
|
-
foldInto(into: StorageLayer): Promise<StorageLayerProvider | undefined>;
|
|
29
|
-
fold(): Promise<void>;
|
|
30
|
-
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
31
|
-
mergeInto(into: Record<string, string | null>): Promise<void>;
|
|
32
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.StorageLayer = exports.RemoteStorageLayer = void 0;
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const logger_1 = require("../logger");
|
|
9
|
-
const key_cache_1 = __importDefault(require("../utils/key-cache"));
|
|
10
|
-
const logger = logger_1.defaultLogger.child({ name: 'layer' });
|
|
11
|
-
const BATCH_SIZE = 1000;
|
|
12
|
-
class RemoteStorageLayer {
|
|
13
|
-
#api;
|
|
14
|
-
#at;
|
|
15
|
-
#db;
|
|
16
|
-
#keyCache = new key_cache_1.default();
|
|
17
|
-
constructor(api, at, db) {
|
|
18
|
-
this.#api = api;
|
|
19
|
-
this.#at = at;
|
|
20
|
-
this.#db = db;
|
|
21
|
-
}
|
|
22
|
-
async get(key) {
|
|
23
|
-
if (this.#db) {
|
|
24
|
-
const res = await this.#db.getRepository('KeyValuePair').findOne({ where: { key, blockHash: this.#at } });
|
|
25
|
-
if (res) {
|
|
26
|
-
return res.value;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
logger.trace({ at: this.#at, key }, 'RemoteStorageLayer get');
|
|
30
|
-
const data = await this.#api.getStorage(key, this.#at);
|
|
31
|
-
this.#db?.getRepository('KeyValuePair').upsert({ key, blockHash: this.#at, value: data }, ['key', 'blockHash']);
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
async foldInto(_into) {
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
async fold() { }
|
|
38
|
-
async getKeysPaged(prefix, pageSize, startKey) {
|
|
39
|
-
if (pageSize > BATCH_SIZE)
|
|
40
|
-
throw new Error(`pageSize must be less or equal to ${BATCH_SIZE}`);
|
|
41
|
-
logger.trace({ at: this.#at, prefix, pageSize, startKey }, 'RemoteStorageLayer getKeysPaged');
|
|
42
|
-
// can't handle keyCache without prefix
|
|
43
|
-
if (prefix.length < 66) {
|
|
44
|
-
return this.#api.getKeysPaged(prefix, pageSize, startKey, this.#at);
|
|
45
|
-
}
|
|
46
|
-
let batchComplete = false;
|
|
47
|
-
const keysPaged = [];
|
|
48
|
-
while (keysPaged.length < pageSize) {
|
|
49
|
-
const nextKey = await this.#keyCache.next(startKey);
|
|
50
|
-
if (nextKey) {
|
|
51
|
-
keysPaged.push(nextKey);
|
|
52
|
-
startKey = nextKey;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
// batch fetch was completed
|
|
56
|
-
if (batchComplete) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
// fetch a batch of keys
|
|
60
|
-
const batch = await this.#api.getKeysPaged(prefix, BATCH_SIZE, startKey, this.#at);
|
|
61
|
-
batchComplete = batch.length < BATCH_SIZE;
|
|
62
|
-
// feed the key cache
|
|
63
|
-
if (batch.length > 0) {
|
|
64
|
-
this.#keyCache.feed([startKey, ...batch]);
|
|
65
|
-
}
|
|
66
|
-
if (batch.length === 0) {
|
|
67
|
-
// no more keys were found
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return keysPaged;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.RemoteStorageLayer = RemoteStorageLayer;
|
|
75
|
-
class StorageLayer {
|
|
76
|
-
#store = {};
|
|
77
|
-
#keys = [];
|
|
78
|
-
#deletedPrefix = [];
|
|
79
|
-
#parent;
|
|
80
|
-
constructor(parent) {
|
|
81
|
-
this.#parent = parent;
|
|
82
|
-
}
|
|
83
|
-
#addKey(key) {
|
|
84
|
-
const idx = lodash_1.default.sortedIndex(this.#keys, key);
|
|
85
|
-
const key2 = this.#keys[idx];
|
|
86
|
-
if (key === key2) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.#keys.splice(idx, 0, key);
|
|
90
|
-
}
|
|
91
|
-
#removeKey(key) {
|
|
92
|
-
const idx = lodash_1.default.sortedIndex(this.#keys, key);
|
|
93
|
-
const key2 = this.#keys[idx];
|
|
94
|
-
if (key === key2) {
|
|
95
|
-
this.#keys.splice(idx, 1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async get(key, cache) {
|
|
99
|
-
if (key in this.#store) {
|
|
100
|
-
return this.#store[key];
|
|
101
|
-
}
|
|
102
|
-
if (this.#deletedPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
103
|
-
return "Deleted" /* StorageValueKind.Deleted */;
|
|
104
|
-
}
|
|
105
|
-
if (this.#parent) {
|
|
106
|
-
const val = this.#parent.get(key, false);
|
|
107
|
-
if (cache) {
|
|
108
|
-
this.#store[key] = val;
|
|
109
|
-
}
|
|
110
|
-
return val;
|
|
111
|
-
}
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
set(key, value) {
|
|
115
|
-
switch (value) {
|
|
116
|
-
case "Deleted" /* StorageValueKind.Deleted */:
|
|
117
|
-
this.#store[key] = value;
|
|
118
|
-
this.#removeKey(key);
|
|
119
|
-
break;
|
|
120
|
-
case "DeletedPrefix" /* StorageValueKind.DeletedPrefix */:
|
|
121
|
-
this.#deletedPrefix.push(key);
|
|
122
|
-
for (const k of this.#keys) {
|
|
123
|
-
if (k.startsWith(key)) {
|
|
124
|
-
this.#store[k] = "Deleted" /* StorageValueKind.Deleted */;
|
|
125
|
-
this.#removeKey(k);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
case undefined:
|
|
130
|
-
delete this.#store[key];
|
|
131
|
-
this.#removeKey(key);
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
this.#store[key] = value;
|
|
135
|
-
this.#addKey(key);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
setAll(values) {
|
|
140
|
-
if (!Array.isArray(values)) {
|
|
141
|
-
values = Object.entries(values);
|
|
142
|
-
}
|
|
143
|
-
for (const [key, value] of values) {
|
|
144
|
-
this.set(key, value || "Deleted" /* StorageValueKind.Deleted */);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async foldInto(into) {
|
|
148
|
-
const newParent = await this.#parent?.foldInto(into);
|
|
149
|
-
for (const deletedPrefix of this.#deletedPrefix) {
|
|
150
|
-
into.set(deletedPrefix, "DeletedPrefix" /* StorageValueKind.DeletedPrefix */);
|
|
151
|
-
}
|
|
152
|
-
for (const key of this.#keys) {
|
|
153
|
-
const value = await this.#store[key];
|
|
154
|
-
into.set(key, value);
|
|
155
|
-
}
|
|
156
|
-
return newParent;
|
|
157
|
-
}
|
|
158
|
-
async fold() {
|
|
159
|
-
if (this.#parent) {
|
|
160
|
-
this.#parent = await this.#parent.foldInto(this);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async getKeysPaged(prefix, pageSize, startKey) {
|
|
164
|
-
if (!this.#deletedPrefix.some((prefix) => startKey.startsWith(prefix))) {
|
|
165
|
-
const remote = (await this.#parent?.getKeysPaged(prefix, pageSize, startKey)) ?? [];
|
|
166
|
-
for (const key of remote) {
|
|
167
|
-
if (this.#deletedPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
this.#addKey(key);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
let idx = lodash_1.default.sortedIndex(this.#keys, startKey);
|
|
174
|
-
if (this.#keys[idx] === startKey) {
|
|
175
|
-
++idx;
|
|
176
|
-
}
|
|
177
|
-
const res = [];
|
|
178
|
-
while (res.length < pageSize) {
|
|
179
|
-
const key = this.#keys[idx];
|
|
180
|
-
if (!key || !key.startsWith(prefix)) {
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
res.push(key);
|
|
184
|
-
++idx;
|
|
185
|
-
}
|
|
186
|
-
return res;
|
|
187
|
-
}
|
|
188
|
-
async mergeInto(into) {
|
|
189
|
-
for (const [key, maybeValue] of Object.entries(this.#store)) {
|
|
190
|
-
const value = await maybeValue;
|
|
191
|
-
if (value === "Deleted" /* StorageValueKind.Deleted */) {
|
|
192
|
-
into[key] = null;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
into[key] = value;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
exports.StorageLayer = StorageLayer;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'node:stream';
|
|
3
|
-
import { HexString } from '@polkadot/util/types';
|
|
4
|
-
import { Blockchain } from '.';
|
|
5
|
-
import { InherentProvider } from './inherent';
|
|
6
|
-
export declare const APPLY_EXTRINSIC_ERROR = "TxPool::ApplyExtrinsicError";
|
|
7
|
-
export declare enum BuildBlockMode {
|
|
8
|
-
Batch = 0,
|
|
9
|
-
Instant = 1,
|
|
10
|
-
Manual = 2
|
|
11
|
-
}
|
|
12
|
-
export interface DownwardMessage {
|
|
13
|
-
sentAt: number;
|
|
14
|
-
msg: HexString;
|
|
15
|
-
}
|
|
16
|
-
export interface HorizontalMessage {
|
|
17
|
-
sentAt: number;
|
|
18
|
-
data: HexString;
|
|
19
|
-
}
|
|
20
|
-
export interface BuildBlockParams {
|
|
21
|
-
downwardMessages: DownwardMessage[];
|
|
22
|
-
upwardMessages: Record<number, HexString[]>;
|
|
23
|
-
horizontalMessages: Record<number, HorizontalMessage[]>;
|
|
24
|
-
transactions: HexString[];
|
|
25
|
-
}
|
|
26
|
-
export declare class TxPool {
|
|
27
|
-
#private;
|
|
28
|
-
readonly event: EventEmitter;
|
|
29
|
-
constructor(chain: Blockchain, inherentProvider: InherentProvider, mode?: BuildBlockMode);
|
|
30
|
-
get pendingExtrinsics(): HexString[];
|
|
31
|
-
get ump(): Record<number, HexString[]>;
|
|
32
|
-
get dmp(): DownwardMessage[];
|
|
33
|
-
get hrmp(): Record<number, HorizontalMessage[]>;
|
|
34
|
-
get mode(): BuildBlockMode;
|
|
35
|
-
set mode(mode: BuildBlockMode);
|
|
36
|
-
clear(): void;
|
|
37
|
-
pendingExtrinsicsBy(address: string): HexString[];
|
|
38
|
-
submitExtrinsic(extrinsic: HexString): Promise<void>;
|
|
39
|
-
submitUpwardMessages(id: number, ump: HexString[]): void;
|
|
40
|
-
submitDownwardMessages(dmp: DownwardMessage[]): void;
|
|
41
|
-
submitHorizontalMessages(id: number, hrmp: HorizontalMessage[]): void;
|
|
42
|
-
buildBlockWithParams(params: BuildBlockParams): Promise<void>;
|
|
43
|
-
buildBlock(params?: Partial<BuildBlockParams>): Promise<void>;
|
|
44
|
-
upcomingBlocks(): Promise<number>;
|
|
45
|
-
}
|