@typeberry/jam 0.5.1-7188620 → 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/index.js
CHANGED
|
@@ -152591,12 +152591,7 @@ function getDatabasePath(blake2b, nodeName, genesisHeader, databaseBasePath) {
|
|
|
152591
152591
|
genesisHeaderHash,
|
|
152592
152592
|
};
|
|
152593
152593
|
}
|
|
152594
|
-
|
|
152595
|
-
* Initialize the database unless it's already initialized.
|
|
152596
|
-
*
|
|
152597
|
-
* The function checks the genesis header
|
|
152598
|
-
*/
|
|
152599
|
-
async function initializeDatabase(spec, blake2b, genesisHeaderHash, rootDb, config, ancestry) {
|
|
152594
|
+
async function initializeDatabase(spec, blake2b, genesisHeaderHash, rootDb, config, ancestry, options = {}) {
|
|
152600
152595
|
const blocks = rootDb.getBlocksDb();
|
|
152601
152596
|
const states = rootDb.getStatesDb();
|
|
152602
152597
|
const header = blocks.getBestHeaderHash();
|
|
@@ -152617,14 +152612,16 @@ async function initializeDatabase(spec, blake2b, genesisHeaderHash, rootDb, conf
|
|
|
152617
152612
|
common_logger.log `🧬 Writing genesis block #${genesisHeader.timeSlotIndex}: ${genesisHeaderHash}`;
|
|
152618
152613
|
const { genesisStateSerialized, genesisStateRootHash } = loadGenesisState(spec, blake2b, config.genesisState);
|
|
152619
152614
|
// write to db
|
|
152620
|
-
|
|
152615
|
+
// When initGenesisFromAncestry is set, use ancestry[0][0] as the initial block hash (for fuzz-target mode)
|
|
152616
|
+
const initialBlockHash = (options.initGenesisFromAncestry ?? false) && ancestry.length > 0 ? ancestry[0][0] : genesisHeaderHash;
|
|
152617
|
+
await blocks.insertBlock(new WithHash(initialBlockHash, blockView));
|
|
152621
152618
|
// insert fake blocks for ancestry data
|
|
152622
152619
|
for (const [hash, slot] of ancestry) {
|
|
152623
152620
|
await blocks.insertBlock(new WithHash(hash, reencodeAsView(Block.Codec, emptyBlock(slot), spec)));
|
|
152624
152621
|
}
|
|
152625
|
-
await states.insertInitialState(
|
|
152626
|
-
await blocks.setPostStateRoot(
|
|
152627
|
-
await blocks.setBestHeaderHash(
|
|
152622
|
+
await states.insertInitialState(initialBlockHash, genesisStateSerialized);
|
|
152623
|
+
await blocks.setPostStateRoot(initialBlockHash, genesisStateRootHash);
|
|
152624
|
+
await blocks.setBestHeaderHash(initialBlockHash);
|
|
152628
152625
|
}
|
|
152629
152626
|
function loadGenesisState(spec, blake2b, data) {
|
|
152630
152627
|
const stateEntries = state_entries_StateEntries.fromEntriesUnsafe(data.entries());
|
|
@@ -164379,6 +164376,8 @@ class BandernsatchWasm {
|
|
|
164379
164376
|
|
|
164380
164377
|
|
|
164381
164378
|
|
|
164379
|
+
|
|
164380
|
+
const safrole_logger = logger_Logger.new(import.meta.filename, "safrole");
|
|
164382
164381
|
const safrole_VALIDATOR_META_BYTES = 128;
|
|
164383
164382
|
const ticketComparator = (a, b) => bytesBlobComparator(a.id, b.id);
|
|
164384
164383
|
var SafroleErrorCode;
|
|
@@ -164466,6 +164465,14 @@ class Safrole {
|
|
|
164466
164465
|
async prepareValidatorKeysForNextEpoch(postOffenders) {
|
|
164467
164466
|
const stateEpoch = Math.floor(this.state.timeslot / this.chainSpec.epochLength);
|
|
164468
164467
|
const nextEpochStart = (stateEpoch + 1) * this.chainSpec.epochLength;
|
|
164468
|
+
/**
|
|
164469
|
+
* In real life, this would occur around ~2840,
|
|
164470
|
+
* but this scenario appears in tests, so we need to handle it.
|
|
164471
|
+
*/
|
|
164472
|
+
if (nextEpochStart >= 2 ** 32) {
|
|
164473
|
+
safrole_logger.warn `Timeslot overflow imminent, cannot prepare validator keys for next epoch.`;
|
|
164474
|
+
return result_Result.ok(null);
|
|
164475
|
+
}
|
|
164469
164476
|
return await this.getValidatorKeys(tryAsTimeSlot(nextEpochStart), postOffenders);
|
|
164470
164477
|
}
|
|
164471
164478
|
async getValidatorKeys(timeslot, postOffenders) {
|
|
@@ -166611,6 +166618,7 @@ class Importer {
|
|
|
166611
166618
|
logger;
|
|
166612
166619
|
blocks;
|
|
166613
166620
|
states;
|
|
166621
|
+
options;
|
|
166614
166622
|
verifier;
|
|
166615
166623
|
stf;
|
|
166616
166624
|
// TODO [ToDr] we cannot assume state reference does not change.
|
|
@@ -166618,11 +166626,12 @@ class Importer {
|
|
|
166618
166626
|
// Hash of the block that we have the posterior state for in `state`.
|
|
166619
166627
|
currentHash;
|
|
166620
166628
|
metrics;
|
|
166621
|
-
constructor(spec, pvm, hasher, logger, blocks, states) {
|
|
166629
|
+
constructor(spec, pvm, hasher, logger, blocks, states, options = {}) {
|
|
166622
166630
|
this.hasher = hasher;
|
|
166623
166631
|
this.logger = logger;
|
|
166624
166632
|
this.blocks = blocks;
|
|
166625
166633
|
this.states = states;
|
|
166634
|
+
this.options = options;
|
|
166626
166635
|
this.metrics = metrics_createMetrics();
|
|
166627
166636
|
const currentBestHeaderHash = this.blocks.getBestHeaderHash();
|
|
166628
166637
|
const state = states.getState(currentBestHeaderHash);
|
|
@@ -166677,7 +166686,9 @@ class Importer {
|
|
|
166677
166686
|
logger.log `🧱 Attempting to import a new block`;
|
|
166678
166687
|
const timerVerify = measure("import:verify");
|
|
166679
166688
|
const verifyStart = now();
|
|
166680
|
-
const hash = await this.verifier.verifyBlock(block
|
|
166689
|
+
const hash = await this.verifier.verifyBlock(block, {
|
|
166690
|
+
skipParentAndStateRoot: this.options.initGenesisFromAncestry ?? false,
|
|
166691
|
+
});
|
|
166681
166692
|
const verifyDuration = now() - verifyStart;
|
|
166682
166693
|
logger.log `${timerVerify()}`;
|
|
166683
166694
|
if (hash.isError) {
|
|
@@ -166780,14 +166791,14 @@ function extractTimeSlot(block) {
|
|
|
166780
166791
|
const main_logger = logger_Logger.new(import.meta.filename, "importer");
|
|
166781
166792
|
const keccakHasher = KeccakHasher.create();
|
|
166782
166793
|
const blake2b = blake2b_Blake2b.createHasher();
|
|
166783
|
-
async function createImporter(config) {
|
|
166794
|
+
async function createImporter(config, options = {}) {
|
|
166784
166795
|
const chainSpec = config.chainSpec;
|
|
166785
166796
|
const db = config.openDatabase({ readonly: false });
|
|
166786
166797
|
const pvm = config.workerParams.pvm;
|
|
166787
166798
|
const blocks = db.getBlocksDb();
|
|
166788
166799
|
const states = db.getStatesDb();
|
|
166789
166800
|
const hasher = new TransitionHasher(await keccakHasher, await blake2b);
|
|
166790
|
-
const importer = new Importer(chainSpec, pvm, hasher, main_logger, blocks, states);
|
|
166801
|
+
const importer = new Importer(chainSpec, pvm, hasher, main_logger, blocks, states, options);
|
|
166791
166802
|
return {
|
|
166792
166803
|
importer,
|
|
166793
166804
|
db,
|
|
@@ -170123,7 +170134,7 @@ const initNetwork = async (importer, rootDb, baseConfig, genesisHeaderHash, netw
|
|
|
170123
170134
|
|
|
170124
170135
|
|
|
170125
170136
|
const zeroHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
170126
|
-
async function mainImporter(config, withRelPath) {
|
|
170137
|
+
async function mainImporter(config, withRelPath, options = {}) {
|
|
170127
170138
|
await initAll();
|
|
170128
170139
|
common_logger.info `🫐 Typeberry ${node_package_namespaceObject.rE}. GP: ${CURRENT_VERSION} (${CURRENT_SUITE})`;
|
|
170129
170140
|
common_logger.info `🎸 Starting importer: ${config.nodeName}.`;
|
|
@@ -170153,9 +170164,13 @@ async function mainImporter(config, withRelPath) {
|
|
|
170153
170164
|
// Initialize the database with genesis state and block if there isn't one.
|
|
170154
170165
|
common_logger.info `🛢️ Opening database at ${dbPath}`;
|
|
170155
170166
|
const rootDb = workerConfig.openDatabase({ readonly: false });
|
|
170156
|
-
await initializeDatabase(chainSpec, blake2b, genesisHeaderHash, rootDb, config.node.chainSpec, config.ancestry
|
|
170167
|
+
await initializeDatabase(chainSpec, blake2b, genesisHeaderHash, rootDb, config.node.chainSpec, config.ancestry, {
|
|
170168
|
+
initGenesisFromAncestry: options.initGenesisFromAncestry,
|
|
170169
|
+
});
|
|
170157
170170
|
await rootDb.close();
|
|
170158
|
-
const { db, importer } = await createImporter(workerConfig
|
|
170171
|
+
const { db, importer } = await createImporter(workerConfig, {
|
|
170172
|
+
initGenesisFromAncestry: options.initGenesisFromAncestry,
|
|
170173
|
+
});
|
|
170159
170174
|
await importer.prepareForNextEpoch();
|
|
170160
170175
|
const api = {
|
|
170161
170176
|
chainSpec,
|
|
@@ -170254,7 +170269,7 @@ async function mainFuzz(fuzzConfig, withRelPath) {
|
|
|
170254
170269
|
},
|
|
170255
170270
|
ancestry,
|
|
170256
170271
|
network: null,
|
|
170257
|
-
}, withRelPath);
|
|
170272
|
+
}, withRelPath, { initGenesisFromAncestry: fuzzConfig.initGenesisFromAncestry });
|
|
170258
170273
|
runningNode = newNode;
|
|
170259
170274
|
return await newNode.getBestStateRootHash();
|
|
170260
170275
|
},
|
|
@@ -170486,6 +170501,7 @@ const jam_package_namespaceObject = {"rE":"0.5.1"};
|
|
|
170486
170501
|
|
|
170487
170502
|
|
|
170488
170503
|
|
|
170504
|
+
|
|
170489
170505
|
const HELP = `
|
|
170490
170506
|
@typeberry/jam ${jam_package_namespaceObject.rE} by Fluffy Labs.
|
|
170491
170507
|
|
|
@@ -170574,6 +170590,11 @@ function parseArgs(input, withRelPath) {
|
|
|
170574
170590
|
case Command.FuzzTarget: {
|
|
170575
170591
|
const data = parseSharedOptions(args);
|
|
170576
170592
|
const { version } = parseValueOption(args, "version", "number", parseFuzzVersion, 1);
|
|
170593
|
+
const initGenesisFromAncestry = args["init-genesis-from-ancestry"] === true;
|
|
170594
|
+
delete args["init-genesis-from-ancestry"];
|
|
170595
|
+
if (initGenesisFromAncestry) {
|
|
170596
|
+
common_logger.warn `Init genesis from ancestry is enabled. Parent hash and state root verification is skipped.`;
|
|
170597
|
+
}
|
|
170577
170598
|
const socket = args._.shift() ?? null;
|
|
170578
170599
|
assertNoMoreArgs(args);
|
|
170579
170600
|
return {
|
|
@@ -170582,6 +170603,7 @@ function parseArgs(input, withRelPath) {
|
|
|
170582
170603
|
...data,
|
|
170583
170604
|
version,
|
|
170584
170605
|
socket,
|
|
170606
|
+
initGenesisFromAncestry,
|
|
170585
170607
|
},
|
|
170586
170608
|
};
|
|
170587
170609
|
}
|
|
@@ -170781,7 +170803,8 @@ async function startNode(args, withRelPath) {
|
|
|
170781
170803
|
if (args.command === Command.FuzzTarget) {
|
|
170782
170804
|
const version = args.args.version;
|
|
170783
170805
|
const socket = args.args.socket;
|
|
170784
|
-
|
|
170806
|
+
const initGenesisFromAncestry = args.args.initGenesisFromAncestry;
|
|
170807
|
+
return mainFuzz({ jamNodeConfig, version, socket, initGenesisFromAncestry }, withRelPath);
|
|
170785
170808
|
}
|
|
170786
170809
|
// Just import a bunch of blocks
|
|
170787
170810
|
if (args.command === Command.Import) {
|