@typeberry/jam 0.5.3-aa4626d → 0.5.3-edc7483
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 +29 -7
- package/bootstrap-generator.mjs.map +1 -1
- package/index.js +53 -18
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-generator.mjs
CHANGED
|
@@ -28733,6 +28733,8 @@ async function main(config, comms) {
|
|
|
28733
28733
|
}
|
|
28734
28734
|
return result_Result.ok(state.sealingKeySeries);
|
|
28735
28735
|
}
|
|
28736
|
+
const isFastForward = config.workerParams.isFastForward;
|
|
28737
|
+
let lastGeneratedSlot = startTimeSlot;
|
|
28736
28738
|
while (!isFinished) {
|
|
28737
28739
|
const hash = blocks.getBestHeaderHash();
|
|
28738
28740
|
const state = states.getState(hash);
|
|
@@ -28740,10 +28742,20 @@ async function main(config, comms) {
|
|
|
28740
28742
|
if (state === null) {
|
|
28741
28743
|
continue;
|
|
28742
28744
|
}
|
|
28743
|
-
const time = getTime();
|
|
28744
|
-
/** Assuming `slotDuration` is 6 sec it is safe till year 2786. If `slotDuration` is 1 sec then it is safe till 2106 */
|
|
28745
|
-
const timeSlot = common_tryAsTimeSlot(Number(time / 1000n / BigInt(chainSpec.slotDuration)));
|
|
28746
28745
|
const lastTimeSlot = state.timeslot;
|
|
28746
|
+
/**
|
|
28747
|
+
* In fastForward mode, use simulated time (next slot after current state).
|
|
28748
|
+
* In normal mode, use wall clock time.
|
|
28749
|
+
* Assuming `slotDuration` is 6 sec it is safe till year 2786.
|
|
28750
|
+
* If `slotDuration` is 1 sec then it is safe till 2106.
|
|
28751
|
+
*/
|
|
28752
|
+
const timeSlot = isFastForward === true
|
|
28753
|
+
? common_tryAsTimeSlot(lastTimeSlot + 1)
|
|
28754
|
+
: common_tryAsTimeSlot(Number(getTime() / 1000n / BigInt(chainSpec.slotDuration)));
|
|
28755
|
+
// In fastForward mode, skip if we already generated for this slot (waiting for import)
|
|
28756
|
+
if (isFastForward === true && timeSlot <= lastGeneratedSlot) {
|
|
28757
|
+
continue;
|
|
28758
|
+
}
|
|
28747
28759
|
const isNewEpoch = isEpochChanged(lastTimeSlot, timeSlot);
|
|
28748
28760
|
const selingKeySeriesResult = await getSealingKeySeries(isNewEpoch, timeSlot, state);
|
|
28749
28761
|
if (selingKeySeriesResult.isError) {
|
|
@@ -28760,10 +28772,17 @@ async function main(config, comms) {
|
|
|
28760
28772
|
const sealPayload = getSealPayload(selingKeySeriesResult.ok, entropy);
|
|
28761
28773
|
const newBlock = await generator.nextBlockView(validatorIndex, key.bandersnatchSecret, sealPayload, timeSlot);
|
|
28762
28774
|
counter += 1;
|
|
28775
|
+
lastGeneratedSlot = timeSlot;
|
|
28763
28776
|
main_logger.trace `Sending block ${counter}`;
|
|
28764
28777
|
await comms.sendBlock(newBlock);
|
|
28765
28778
|
}
|
|
28766
|
-
|
|
28779
|
+
else if (isFastForward === true) {
|
|
28780
|
+
// In fast-forward mode, if this slot is not ours, wait briefly for other validators to produce blocks
|
|
28781
|
+
await (0,promises_namespaceObject.setTimeout)(10);
|
|
28782
|
+
}
|
|
28783
|
+
if (isFastForward === false) {
|
|
28784
|
+
await (0,promises_namespaceObject.setTimeout)(chainSpec.slotDuration * 1000);
|
|
28785
|
+
}
|
|
28767
28786
|
}
|
|
28768
28787
|
main_logger.info `🎁 Block Authorship finished. Closing channel.`;
|
|
28769
28788
|
await db.close();
|
|
@@ -29005,14 +29024,17 @@ class ValidatorSecrets {
|
|
|
29005
29024
|
}
|
|
29006
29025
|
class BlockAuthorshipConfig {
|
|
29007
29026
|
keys;
|
|
29027
|
+
isFastForward;
|
|
29008
29028
|
static Codec = codec_codec.Class(BlockAuthorshipConfig, {
|
|
29009
29029
|
keys: codec_codec.sequenceVarLen(ValidatorSecrets.Codec),
|
|
29030
|
+
isFastForward: codec_codec.bool,
|
|
29010
29031
|
});
|
|
29011
|
-
static create({ keys }) {
|
|
29012
|
-
return new BlockAuthorshipConfig(keys);
|
|
29032
|
+
static create({ keys, isFastForward }) {
|
|
29033
|
+
return new BlockAuthorshipConfig(keys, isFastForward);
|
|
29013
29034
|
}
|
|
29014
|
-
constructor(keys) {
|
|
29035
|
+
constructor(keys, isFastForward) {
|
|
29015
29036
|
this.keys = keys;
|
|
29037
|
+
this.isFastForward = isFastForward;
|
|
29016
29038
|
}
|
|
29017
29039
|
}
|
|
29018
29040
|
|