@typeberry/lib 0.4.1-bb6dbac → 0.4.1-d3b18b3

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.
Files changed (4) hide show
  1. package/index.cjs +980 -104
  2. package/index.d.ts +37 -4
  3. package/index.js +980 -104
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -180,6 +180,15 @@ declare class Compatibility {
180
180
  }
181
181
 
182
182
  declare function isBrowser(): boolean;
183
+ /**
184
+ * Get current time in milliseconds (works in both Node and browser).
185
+ *
186
+ * Node.js implementation converts hrtime bigint nanoseconds to milliseconds.
187
+ * This is safe because dividing nanoseconds by 1_000_000 yields milliseconds,
188
+ * which remain well below Number.MAX_SAFE_INTEGER for practical runtimes
189
+ * (would take ~285 years to overflow).
190
+ */
191
+ declare const now: () => number;
183
192
  /**
184
193
  * A function to perform runtime assertions.
185
194
  *
@@ -212,7 +221,7 @@ declare function assertEmpty<T extends Record<string, never>>(value: T): void;
212
221
  /** Debug print an object. */
213
222
  declare function inspect<T>(val: T): string;
214
223
  /** Utility function to measure time taken for some operation [ms]. */
215
- declare const measure: (id: string) => () => string;
224
+ declare function measure(id: string): () => string;
216
225
  /** A class that adds `toString` method that prints all properties of an object. */
217
226
  declare abstract class WithDebug {
218
227
  toString(): string;
@@ -240,6 +249,8 @@ declare function lazyInspect<T>(obj: T): {
240
249
  */
241
250
  declare const workspacePathFix: (workspacePath: string) => (p: string) => string;
242
251
 
252
+ declare const env: NodeJS.ProcessEnv;
253
+
243
254
  /**
244
255
  * `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
245
256
  * specified unique token Token. It means that base type cannot be assigned to unique type by accident.
@@ -400,16 +411,18 @@ declare const index$w_assertEmpty: typeof assertEmpty;
400
411
  declare const index$w_assertNever: typeof assertNever;
401
412
  declare const index$w_check: typeof check;
402
413
  declare const index$w_deepEqual: typeof deepEqual;
414
+ declare const index$w_env: typeof env;
403
415
  declare const index$w_inspect: typeof inspect;
404
416
  declare const index$w_isBrowser: typeof isBrowser;
405
417
  declare const index$w_lazyInspect: typeof lazyInspect;
406
418
  declare const index$w_measure: typeof measure;
419
+ declare const index$w_now: typeof now;
407
420
  declare const index$w_resultToString: typeof resultToString;
408
421
  declare const index$w_safeAllocUint8Array: typeof safeAllocUint8Array;
409
422
  declare const index$w_seeThrough: typeof seeThrough;
410
423
  declare const index$w_workspacePathFix: typeof workspacePathFix;
411
424
  declare namespace index$w {
412
- export { index$w_CURRENT_SUITE as CURRENT_SUITE, index$w_CURRENT_VERSION as CURRENT_VERSION, index$w_Compatibility as Compatibility, index$w_DEFAULT_SUITE as DEFAULT_SUITE, index$w_DEFAULT_VERSION as DEFAULT_VERSION, index$w_ErrorsCollector as ErrorsCollector, index$w_GpVersion as GpVersion, index$w_MAX_LENGTH as MAX_LENGTH, index$w_Result as Result, index$w_TEST_COMPARE_USING as TEST_COMPARE_USING, index$w_TestSuite as TestSuite, index$w_WithDebug as WithDebug, index$w___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$w_asOpaqueType as asOpaqueType, index$w_assertEmpty as assertEmpty, index$w_assertNever as assertNever, index$w_check as check, index$w_deepEqual as deepEqual, index$w_inspect as inspect, index$w_isBrowser as isBrowser, index$w_lazyInspect as lazyInspect, index$w_measure as measure, index$w_resultToString as resultToString, index$w_safeAllocUint8Array as safeAllocUint8Array, index$w_seeThrough as seeThrough, index$w_workspacePathFix as workspacePathFix };
425
+ export { index$w_CURRENT_SUITE as CURRENT_SUITE, index$w_CURRENT_VERSION as CURRENT_VERSION, index$w_Compatibility as Compatibility, index$w_DEFAULT_SUITE as DEFAULT_SUITE, index$w_DEFAULT_VERSION as DEFAULT_VERSION, index$w_ErrorsCollector as ErrorsCollector, index$w_GpVersion as GpVersion, index$w_MAX_LENGTH as MAX_LENGTH, index$w_Result as Result, index$w_TEST_COMPARE_USING as TEST_COMPARE_USING, index$w_TestSuite as TestSuite, index$w_WithDebug as WithDebug, index$w___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$w_asOpaqueType as asOpaqueType, index$w_assertEmpty as assertEmpty, index$w_assertNever as assertNever, index$w_check as check, index$w_deepEqual as deepEqual, index$w_env as env, index$w_inspect as inspect, index$w_isBrowser as isBrowser, index$w_lazyInspect as lazyInspect, index$w_measure as measure, index$w_now as now, index$w_resultToString as resultToString, index$w_safeAllocUint8Array as safeAllocUint8Array, index$w_seeThrough as seeThrough, index$w_workspacePathFix as workspacePathFix };
413
426
  export type { index$w_DeepEqualOptions as DeepEqualOptions, index$w_ErrorResult as ErrorResult, index$w_OK as OK, index$w_OkResult as OkResult, index$w_Opaque as Opaque, index$w_TaggedError as TaggedError, index$w_TokenOf as TokenOf, index$w_WithOpaque as WithOpaque };
414
427
  }
415
428
 
@@ -7200,6 +7213,8 @@ declare class Channel {
7200
7213
 
7201
7214
  /** Standardized worker config. */
7202
7215
  interface WorkerConfig<TParams = void, TBlocks = BlocksDb, TStates = StatesDb> {
7216
+ /** Node name. */
7217
+ readonly nodeName: string;
7203
7218
  /** Chain spec. */
7204
7219
  readonly chainSpec: ChainSpec;
7205
7220
  /** Worker parameters. */
@@ -7213,11 +7228,13 @@ interface WorkerConfig<TParams = void, TBlocks = BlocksDb, TStates = StatesDb> {
7213
7228
  * Worker config with in-thread database.
7214
7229
  */
7215
7230
  declare class DirectWorkerConfig<TParams = void, TBlocks = BlocksDb, TStates = StatesDb> implements WorkerConfig<TParams, TBlocks, TStates> {
7231
+ readonly nodeName: string;
7216
7232
  readonly chainSpec: ChainSpec;
7217
7233
  readonly workerParams: TParams;
7218
7234
  private readonly blocksDb;
7219
7235
  private readonly statesDb;
7220
- static new<T, B, S>({ chainSpec, blocksDb, statesDb, params, }: {
7236
+ static new<T, B, S>({ nodeName, chainSpec, blocksDb, statesDb, params, }: {
7237
+ nodeName: string;
7221
7238
  chainSpec: ChainSpec;
7222
7239
  blocksDb: B;
7223
7240
  statesDb: S;
@@ -9438,6 +9455,7 @@ declare class Importer {
9438
9455
  private readonly stf;
9439
9456
  private readonly state;
9440
9457
  private currentHash;
9458
+ private readonly metrics;
9441
9459
  constructor(spec: ChainSpec, pvm: PvmBackend, hasher: TransitionHasher, logger: Logger, blocks: BlocksDb, states: StatesDb<SerializedState<LeafDb>>);
9442
9460
  /** Do some extra work for preparation for the next epoch. */
9443
9461
  prepareForNextEpoch(): Promise<void>;
@@ -9812,6 +9830,20 @@ declare function createImporter(config: Config): Promise<{
9812
9830
  */
9813
9831
  declare function main(config: Config, comms: ImporterInternal): Promise<void>;
9814
9832
 
9833
+ /**
9834
+ * Block importer metrics for JAM implementation.
9835
+ *
9836
+ * https://github.com/polkadot-fellows/JIPs/blob/main/JIP-3.md#block-authoringimporting-events
9837
+ */
9838
+ declare function createMetrics(): {
9839
+ recordBlockImportComplete(totalDurationMs: number, success: boolean): void;
9840
+ recordBlockImportingStarted(slot: number): void;
9841
+ recordBlockVerificationFailed(reason: string): void;
9842
+ recordBlockVerified(durationMs: number): void;
9843
+ recordBlockExecutionFailed(reason: string): void;
9844
+ recordBlockExecuted(durationMs: number, cost: number): void;
9845
+ };
9846
+
9815
9847
  declare const WORKER: url.URL;
9816
9848
 
9817
9849
  type index$6_Config = Config;
@@ -9821,10 +9853,11 @@ declare const index$6_ImporterConfig: typeof ImporterConfig;
9821
9853
  type index$6_ImporterInternal = ImporterInternal;
9822
9854
  declare const index$6_WORKER: typeof WORKER;
9823
9855
  declare const index$6_createImporter: typeof createImporter;
9856
+ declare const index$6_createMetrics: typeof createMetrics;
9824
9857
  declare const index$6_main: typeof main;
9825
9858
  declare const index$6_protocol: typeof protocol;
9826
9859
  declare namespace index$6 {
9827
- export { index$6_ImporterConfig as ImporterConfig, index$6_WORKER as WORKER, index$6_createImporter as createImporter, index$6_main as main, index$6_protocol as protocol };
9860
+ export { index$6_ImporterConfig as ImporterConfig, index$6_WORKER as WORKER, index$6_createImporter as createImporter, index$6_createMetrics as createMetrics, index$6_main as main, index$6_protocol as protocol };
9828
9861
  export type { index$6_Config as Config, index$6_ImporterApi as ImporterApi, index$6_ImporterInternal as ImporterInternal };
9829
9862
  }
9830
9863