@typeberry/jam 0.5.1-712b7f8 → 0.5.1-7d23ab3
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/bootstrap-generator.mjs +10 -0
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +18 -4
- package/bootstrap-importer.mjs.map +1 -1
- package/index.js +42 -19
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -25242,6 +25242,8 @@ class BandernsatchWasm {
|
|
|
25242
25242
|
|
|
25243
25243
|
|
|
25244
25244
|
|
|
25245
|
+
|
|
25246
|
+
const safrole_logger = Logger.new(import.meta.filename, "safrole");
|
|
25245
25247
|
const safrole_VALIDATOR_META_BYTES = 128;
|
|
25246
25248
|
const ticketComparator = (a, b) => bytesBlobComparator(a.id, b.id);
|
|
25247
25249
|
var SafroleErrorCode;
|
|
@@ -25329,6 +25331,14 @@ class Safrole {
|
|
|
25329
25331
|
async prepareValidatorKeysForNextEpoch(postOffenders) {
|
|
25330
25332
|
const stateEpoch = Math.floor(this.state.timeslot / this.chainSpec.epochLength);
|
|
25331
25333
|
const nextEpochStart = (stateEpoch + 1) * this.chainSpec.epochLength;
|
|
25334
|
+
/**
|
|
25335
|
+
* In real life, this would occur around ~2840,
|
|
25336
|
+
* but this scenario appears in tests, so we need to handle it.
|
|
25337
|
+
*/
|
|
25338
|
+
if (nextEpochStart >= 2 ** 32) {
|
|
25339
|
+
safrole_logger.warn `Timeslot overflow imminent, cannot prepare validator keys for next epoch.`;
|
|
25340
|
+
return Result.ok(null);
|
|
25341
|
+
}
|
|
25332
25342
|
return await this.getValidatorKeys(common_tryAsTimeSlot(nextEpochStart), postOffenders);
|
|
25333
25343
|
}
|
|
25334
25344
|
async getValidatorKeys(timeslot, postOffenders) {
|
|
@@ -29070,6 +29080,7 @@ class Importer {
|
|
|
29070
29080
|
logger;
|
|
29071
29081
|
blocks;
|
|
29072
29082
|
states;
|
|
29083
|
+
options;
|
|
29073
29084
|
verifier;
|
|
29074
29085
|
stf;
|
|
29075
29086
|
// TODO [ToDr] we cannot assume state reference does not change.
|
|
@@ -29077,11 +29088,12 @@ class Importer {
|
|
|
29077
29088
|
// Hash of the block that we have the posterior state for in `state`.
|
|
29078
29089
|
currentHash;
|
|
29079
29090
|
metrics;
|
|
29080
|
-
constructor(spec, pvm, hasher, logger, blocks, states) {
|
|
29091
|
+
constructor(spec, pvm, hasher, logger, blocks, states, options = {}) {
|
|
29081
29092
|
this.hasher = hasher;
|
|
29082
29093
|
this.logger = logger;
|
|
29083
29094
|
this.blocks = blocks;
|
|
29084
29095
|
this.states = states;
|
|
29096
|
+
this.options = options;
|
|
29085
29097
|
this.metrics = createMetrics();
|
|
29086
29098
|
const currentBestHeaderHash = this.blocks.getBestHeaderHash();
|
|
29087
29099
|
const state = states.getState(currentBestHeaderHash);
|
|
@@ -29136,7 +29148,9 @@ class Importer {
|
|
|
29136
29148
|
logger.log `🧱 Attempting to import a new block`;
|
|
29137
29149
|
const timerVerify = measure("import:verify");
|
|
29138
29150
|
const verifyStart = now();
|
|
29139
|
-
const hash = await this.verifier.verifyBlock(block
|
|
29151
|
+
const hash = await this.verifier.verifyBlock(block, {
|
|
29152
|
+
skipParentAndStateRoot: this.options.initGenesisFromAncestry ?? false,
|
|
29153
|
+
});
|
|
29140
29154
|
const verifyDuration = now() - verifyStart;
|
|
29141
29155
|
logger.log `${timerVerify()}`;
|
|
29142
29156
|
if (hash.isError) {
|
|
@@ -29239,14 +29253,14 @@ function extractTimeSlot(block) {
|
|
|
29239
29253
|
const main_logger = Logger.new(import.meta.filename, "importer");
|
|
29240
29254
|
const keccakHasher = KeccakHasher.create();
|
|
29241
29255
|
const blake2b = Blake2b.createHasher();
|
|
29242
|
-
async function createImporter(config) {
|
|
29256
|
+
async function createImporter(config, options = {}) {
|
|
29243
29257
|
const chainSpec = config.chainSpec;
|
|
29244
29258
|
const db = config.openDatabase({ readonly: false });
|
|
29245
29259
|
const pvm = config.workerParams.pvm;
|
|
29246
29260
|
const blocks = db.getBlocksDb();
|
|
29247
29261
|
const states = db.getStatesDb();
|
|
29248
29262
|
const hasher = new TransitionHasher(await keccakHasher, await blake2b);
|
|
29249
|
-
const importer = new Importer(chainSpec, pvm, hasher, main_logger, blocks, states);
|
|
29263
|
+
const importer = new Importer(chainSpec, pvm, hasher, main_logger, blocks, states, options);
|
|
29250
29264
|
return {
|
|
29251
29265
|
importer,
|
|
29252
29266
|
db,
|