@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/index.js CHANGED
@@ -153709,6 +153709,7 @@ const DEFAULT_DEV_CONFIG = {
153709
153709
  */
153710
153710
  class JamConfig {
153711
153711
  isAuthoring;
153712
+ isFastForward;
153712
153713
  nodeName;
153713
153714
  node;
153714
153715
  pvmBackend;
@@ -153716,12 +153717,14 @@ class JamConfig {
153716
153717
  network;
153717
153718
  ancestry;
153718
153719
  devValidatorIndex;
153719
- static new({ isAuthoring, nodeName, nodeConfig, pvmBackend, devConfig = null, networkConfig = null, ancestry = [], devValidatorIndex = null, }) {
153720
- return new JamConfig(isAuthoring ?? false, nodeName, nodeConfig, pvmBackend, devConfig, networkConfig, ancestry, devValidatorIndex);
153720
+ static new({ isAuthoring, isFastForward, nodeName, nodeConfig, pvmBackend, devConfig = null, networkConfig = null, ancestry = [], devValidatorIndex = null, }) {
153721
+ return new JamConfig(isAuthoring ?? false, isFastForward ?? false, nodeName, nodeConfig, pvmBackend, devConfig, networkConfig, ancestry, devValidatorIndex);
153721
153722
  }
153722
153723
  constructor(
153723
153724
  /** Whether we should be authoring blocks. */
153724
153725
  isAuthoring,
153726
+ /** Fast forward mode - generate blocks as fast as possible without waiting for real time. */
153727
+ isFastForward,
153725
153728
  /** Node name. */
153726
153729
  nodeName,
153727
153730
  /** Node starting configuration. */
@@ -153737,6 +153740,7 @@ class JamConfig {
153737
153740
  /** Validator index for dev mode authorship. Use "all" to author as all validators. */
153738
153741
  devValidatorIndex) {
153739
153742
  this.isAuthoring = isAuthoring;
153743
+ this.isFastForward = isFastForward;
153740
153744
  this.nodeName = nodeName;
153741
153745
  this.node = node;
153742
153746
  this.pvmBackend = pvmBackend;
@@ -169931,6 +169935,8 @@ async function block_authorship_main_main(config, comms) {
169931
169935
  }
169932
169936
  return result_Result.ok(state.sealingKeySeries);
169933
169937
  }
169938
+ const isFastForward = config.workerParams.isFastForward;
169939
+ let lastGeneratedSlot = startTimeSlot;
169934
169940
  while (!isFinished) {
169935
169941
  const hash = blocks.getBestHeaderHash();
169936
169942
  const state = states.getState(hash);
@@ -169938,10 +169944,20 @@ async function block_authorship_main_main(config, comms) {
169938
169944
  if (state === null) {
169939
169945
  continue;
169940
169946
  }
169941
- const time = getTime();
169942
- /** Assuming `slotDuration` is 6 sec it is safe till year 2786. If `slotDuration` is 1 sec then it is safe till 2106 */
169943
- const timeSlot = tryAsTimeSlot(Number(time / 1000n / BigInt(chainSpec.slotDuration)));
169944
169947
  const lastTimeSlot = state.timeslot;
169948
+ /**
169949
+ * In fastForward mode, use simulated time (next slot after current state).
169950
+ * In normal mode, use wall clock time.
169951
+ * Assuming `slotDuration` is 6 sec it is safe till year 2786.
169952
+ * If `slotDuration` is 1 sec then it is safe till 2106.
169953
+ */
169954
+ const timeSlot = isFastForward === true
169955
+ ? tryAsTimeSlot(lastTimeSlot + 1)
169956
+ : tryAsTimeSlot(Number(getTime() / 1000n / BigInt(chainSpec.slotDuration)));
169957
+ // In fastForward mode, skip if we already generated for this slot (waiting for import)
169958
+ if (isFastForward === true && timeSlot <= lastGeneratedSlot) {
169959
+ continue;
169960
+ }
169945
169961
  const isNewEpoch = isEpochChanged(lastTimeSlot, timeSlot);
169946
169962
  const selingKeySeriesResult = await getSealingKeySeries(isNewEpoch, timeSlot, state);
169947
169963
  if (selingKeySeriesResult.isError) {
@@ -169958,10 +169974,17 @@ async function block_authorship_main_main(config, comms) {
169958
169974
  const sealPayload = getSealPayload(selingKeySeriesResult.ok, entropy);
169959
169975
  const newBlock = await generator.nextBlockView(validatorIndex, key.bandersnatchSecret, sealPayload, timeSlot);
169960
169976
  counter += 1;
169977
+ lastGeneratedSlot = timeSlot;
169961
169978
  block_authorship_main_logger.trace `Sending block ${counter}`;
169962
169979
  await comms.sendBlock(newBlock);
169963
169980
  }
169964
- await (0,promises_namespaceObject.setTimeout)(chainSpec.slotDuration * 1000);
169981
+ else if (isFastForward === true) {
169982
+ // In fast-forward mode, if this slot is not ours, wait briefly for other validators to produce blocks
169983
+ await (0,promises_namespaceObject.setTimeout)(10);
169984
+ }
169985
+ if (isFastForward === false) {
169986
+ await (0,promises_namespaceObject.setTimeout)(chainSpec.slotDuration * 1000);
169987
+ }
169965
169988
  }
169966
169989
  block_authorship_main_logger.info `🎁 Block Authorship finished. Closing channel.`;
169967
169990
  await db.close();
@@ -170003,14 +170026,17 @@ class ValidatorSecrets {
170003
170026
  }
170004
170027
  class BlockAuthorshipConfig {
170005
170028
  keys;
170029
+ isFastForward;
170006
170030
  static Codec = codec_codec.Class(BlockAuthorshipConfig, {
170007
170031
  keys: codec_codec.sequenceVarLen(ValidatorSecrets.Codec),
170032
+ isFastForward: codec_codec.bool,
170008
170033
  });
170009
- static create({ keys }) {
170010
- return new BlockAuthorshipConfig(keys);
170034
+ static create({ keys, isFastForward }) {
170035
+ return new BlockAuthorshipConfig(keys, isFastForward);
170011
170036
  }
170012
- constructor(keys) {
170037
+ constructor(keys, isFastForward) {
170013
170038
  this.keys = keys;
170039
+ this.isFastForward = isFastForward;
170014
170040
  }
170015
170041
  }
170016
170042
 
@@ -170191,7 +170217,7 @@ async function node_main_main(config, withRelPath, telemetry) {
170191
170217
  },
170192
170218
  ],
170193
170219
  };
170194
- const closeAuthorship = await initAuthorship(importer, config.isAuthoring, rootDb, baseConfig, authorshipKeys, isInMemory);
170220
+ const closeAuthorship = await initAuthorship(importer, config.isAuthoring, config.isFastForward, rootDb, baseConfig, authorshipKeys, isInMemory);
170195
170221
  // Networking initialization
170196
170222
  const closeNetwork = await initNetwork(importer, rootDb, baseConfig, genesisHeaderHash, config.network, bestHeader, isInMemory);
170197
170223
  const api = {
@@ -170227,22 +170253,23 @@ async function node_main_main(config, withRelPath, telemetry) {
170227
170253
  };
170228
170254
  return api;
170229
170255
  }
170230
- const initAuthorship = async (importer, isAuthoring, rootDb, baseConfig, authorshipKeys, isInMemory) => {
170256
+ const initAuthorship = async (importer, isAuthoring, isFastForward, rootDb, baseConfig, authorshipKeys, isInMemory) => {
170231
170257
  if (!isAuthoring) {
170232
170258
  common_logger.log `✍️ Authorship off: disabled`;
170233
170259
  return () => Promise.resolve();
170234
170260
  }
170235
170261
  common_logger.info `✍️ Starting block generator.`;
170262
+ const workerParams = { ...authorshipKeys, isFastForward };
170236
170263
  const { generator, finish } = isInMemory
170237
170264
  ? await startBlockGenerator(DirectWorkerConfig.new({
170238
170265
  ...baseConfig,
170239
170266
  blocksDb: rootDb.getBlocksDb(),
170240
170267
  statesDb: rootDb.getStatesDb(),
170241
- workerParams: authorshipKeys,
170268
+ workerParams,
170242
170269
  }))
170243
170270
  : await spawnBlockGeneratorWorker(config_LmdbWorkerConfig.new({
170244
170271
  ...baseConfig,
170245
- workerParams: authorshipKeys,
170272
+ workerParams,
170246
170273
  }));
170247
170274
  // relay blocks from generator to importer
170248
170275
  generator.setOnBlock(async (block) => {
@@ -170674,7 +170701,7 @@ const HELP = `
170674
170701
 
170675
170702
  Usage:
170676
170703
  jam [options]
170677
- jam [options] dev <dev-validator-index>
170704
+ jam [options] dev <dev-validator-index> [--fast-forward]
170678
170705
  jam [options] import <bin-or-json-blocks>
170679
170706
  jam [options] export <output-directory-or-file>
170680
170707
  jam [options] [--version=1] fuzz-target [socket-path=/tmp/jam_target.sock]
@@ -170694,6 +170721,7 @@ Options:
170694
170721
  [default: ${NODE_DEFAULTS.config}]
170695
170722
  --pvm PVM Backend, one of: [${PvmBackendNames.join(", ")}].
170696
170723
  [default: ${PvmBackendNames[NODE_DEFAULTS.pvm]}]
170724
+ --fast-forward (dev mode only) Generate blocks as fast as possible without waiting for real time.
170697
170725
  `;
170698
170726
  /** Command to execute. */
170699
170727
  var Command;
@@ -170744,15 +170772,18 @@ function parseArgs(input, withRelPath) {
170744
170772
  if (indexOrAll === undefined) {
170745
170773
  throw new Error("Missing dev-validator index.");
170746
170774
  }
170775
+ const isFastForward = args["fast-forward"] === true;
170776
+ delete args["fast-forward"];
170747
170777
  if (indexOrAll === "all") {
170748
- return { command: Command.Dev, args: { ...data, index: "all" } };
170778
+ assertNoMoreArgs(args);
170779
+ return { command: Command.Dev, args: { ...data, index: indexOrAll, isFastForward } };
170749
170780
  }
170750
170781
  const numIndex = Number(indexOrAll);
170751
170782
  if (!isU16(numIndex)) {
170752
170783
  throw new Error(`Invalid dev-validator index: ${numIndex}, need U16 or "all"`);
170753
170784
  }
170754
170785
  assertNoMoreArgs(args);
170755
- return { command: Command.Dev, args: { ...data, index: numIndex } };
170786
+ return { command: Command.Dev, args: { ...data, index: numIndex, isFastForward } };
170756
170787
  }
170757
170788
  case Command.FuzzTarget: {
170758
170789
  const data = parseSharedOptions(args);
@@ -170943,8 +170974,12 @@ async function prepareConfigFile(args, blake2b, withRelPath) {
170943
170974
  return new Bootnode(opaque_asOpaqueType(peerId), "127.0.0.1", port);
170944
170975
  }))
170945
170976
  : [];
170977
+ const isDevMode = args.command === Command.Dev;
170978
+ const devIndex = isDevMode ? args.args.index : null;
170979
+ const isFastForward = isDevMode ? args.args.isFastForward : false;
170946
170980
  return JamConfig.new({
170947
- isAuthoring: args.command === Command.Dev,
170981
+ isAuthoring: isDevMode,
170982
+ isFastForward,
170948
170983
  nodeName,
170949
170984
  nodeConfig,
170950
170985
  pvmBackend: args.args.pvm,
@@ -170954,7 +170989,7 @@ async function prepareConfigFile(args, blake2b, withRelPath) {
170954
170989
  port: devPort(devPortShift),
170955
170990
  bootnodes: devBootnodes.concat(nodeConfig.chainSpec.bootnodes ?? []),
170956
170991
  },
170957
- devValidatorIndex: args.command === Command.Dev ? args.args.index : null,
170992
+ devValidatorIndex: devIndex,
170958
170993
  });
170959
170994
  }
170960
170995
  async function startNode(args, withRelPath) {