@typeberry/lib 0.10.0-5a5e4ab → 0.10.0-9e3af22

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 (110) hide show
  1. package/package.json +3 -3
  2. package/packages/configs/index.d.ts +9 -0
  3. package/packages/configs/index.d.ts.map +1 -1
  4. package/packages/configs/typeberry-default.json +4 -1
  5. package/packages/configs/typeberry-dev-full.json +3 -0
  6. package/packages/configs/typeberry-dev-tiny.json +3 -0
  7. package/packages/jam/config-node/index.d.ts +1 -0
  8. package/packages/jam/config-node/index.d.ts.map +1 -1
  9. package/packages/jam/config-node/index.js +1 -0
  10. package/packages/jam/config-node/node-config.d.ts +5 -1
  11. package/packages/jam/config-node/node-config.d.ts.map +1 -1
  12. package/packages/jam/config-node/node-config.js +9 -3
  13. package/packages/jam/config-node/node-config.test.js +9 -0
  14. package/packages/jam/config-node/rpc.d.ts +11 -0
  15. package/packages/jam/config-node/rpc.d.ts.map +1 -0
  16. package/packages/jam/config-node/rpc.js +16 -0
  17. package/packages/jam/node/jam-config.d.ts +5 -1
  18. package/packages/jam/node/jam-config.d.ts.map +1 -1
  19. package/packages/jam/node/jam-config.js +6 -2
  20. package/packages/jam/node/main-fuzz.d.ts.map +1 -1
  21. package/packages/jam/node/main-fuzz.js +30 -15
  22. package/packages/jam/node/main-importer.d.ts.map +1 -1
  23. package/packages/jam/node/main-importer.js +1 -1
  24. package/packages/jam/rpc/index.d.ts +3 -0
  25. package/packages/jam/rpc/index.d.ts.map +1 -0
  26. package/packages/jam/rpc/index.js +2 -0
  27. package/packages/jam/rpc/src/handlers/best-block.d.ts +6 -0
  28. package/packages/jam/rpc/src/handlers/best-block.d.ts.map +1 -0
  29. package/packages/jam/rpc/src/handlers/best-block.js +15 -0
  30. package/packages/jam/rpc/src/handlers/finalized-block.d.ts +6 -0
  31. package/packages/jam/rpc/src/handlers/finalized-block.d.ts.map +1 -0
  32. package/packages/jam/rpc/src/handlers/finalized-block.js +7 -0
  33. package/packages/jam/rpc/src/handlers/list-services.d.ts +6 -0
  34. package/packages/jam/rpc/src/handlers/list-services.d.ts.map +1 -0
  35. package/packages/jam/rpc/src/handlers/list-services.js +15 -0
  36. package/packages/jam/rpc/src/handlers/not-implemented.d.ts +4 -0
  37. package/packages/jam/rpc/src/handlers/not-implemented.d.ts.map +1 -0
  38. package/packages/jam/rpc/src/handlers/not-implemented.js +4 -0
  39. package/packages/jam/rpc/src/handlers/parameters.d.ts +7 -0
  40. package/packages/jam/rpc/src/handlers/parameters.d.ts.map +1 -0
  41. package/packages/jam/rpc/src/handlers/parameters.js +53 -0
  42. package/packages/jam/rpc/src/handlers/parent.d.ts +6 -0
  43. package/packages/jam/rpc/src/handlers/parent.d.ts.map +1 -0
  44. package/packages/jam/rpc/src/handlers/parent.js +25 -0
  45. package/packages/jam/rpc/src/handlers/service-data.d.ts +6 -0
  46. package/packages/jam/rpc/src/handlers/service-data.d.ts.map +1 -0
  47. package/packages/jam/rpc/src/handlers/service-data.js +21 -0
  48. package/packages/jam/rpc/src/handlers/service-preimage.d.ts +6 -0
  49. package/packages/jam/rpc/src/handlers/service-preimage.d.ts.map +1 -0
  50. package/packages/jam/rpc/src/handlers/service-preimage.js +23 -0
  51. package/packages/jam/rpc/src/handlers/service-request.d.ts +6 -0
  52. package/packages/jam/rpc/src/handlers/service-request.d.ts.map +1 -0
  53. package/packages/jam/rpc/src/handlers/service-request.js +23 -0
  54. package/packages/jam/rpc/src/handlers/service-value.d.ts +6 -0
  55. package/packages/jam/rpc/src/handlers/service-value.d.ts.map +1 -0
  56. package/packages/jam/rpc/src/handlers/service-value.js +23 -0
  57. package/packages/jam/rpc/src/handlers/state-root.d.ts +6 -0
  58. package/packages/jam/rpc/src/handlers/state-root.d.ts.map +1 -0
  59. package/packages/jam/rpc/src/handlers/state-root.js +14 -0
  60. package/packages/jam/rpc/src/handlers/statistics.d.ts +6 -0
  61. package/packages/jam/rpc/src/handlers/statistics.d.ts.map +1 -0
  62. package/packages/jam/rpc/src/handlers/statistics.js +16 -0
  63. package/packages/jam/rpc/src/handlers/subscribe-best-block.d.ts +6 -0
  64. package/packages/jam/rpc/src/handlers/subscribe-best-block.d.ts.map +1 -0
  65. package/packages/jam/rpc/src/handlers/subscribe-best-block.js +8 -0
  66. package/packages/jam/rpc/src/handlers/subscribe-finalized-block.d.ts +6 -0
  67. package/packages/jam/rpc/src/handlers/subscribe-finalized-block.d.ts.map +1 -0
  68. package/packages/jam/rpc/src/handlers/subscribe-finalized-block.js +8 -0
  69. package/packages/jam/rpc/src/handlers/subscribe-service-data.d.ts +6 -0
  70. package/packages/jam/rpc/src/handlers/subscribe-service-data.d.ts.map +1 -0
  71. package/packages/jam/rpc/src/handlers/subscribe-service-data.js +13 -0
  72. package/packages/jam/rpc/src/handlers/subscribe-service-preimage.d.ts +6 -0
  73. package/packages/jam/rpc/src/handlers/subscribe-service-preimage.d.ts.map +1 -0
  74. package/packages/jam/rpc/src/handlers/subscribe-service-preimage.js +13 -0
  75. package/packages/jam/rpc/src/handlers/subscribe-service-request.d.ts +6 -0
  76. package/packages/jam/rpc/src/handlers/subscribe-service-request.d.ts.map +1 -0
  77. package/packages/jam/rpc/src/handlers/subscribe-service-request.js +13 -0
  78. package/packages/jam/rpc/src/handlers/subscribe-service-value.d.ts +6 -0
  79. package/packages/jam/rpc/src/handlers/subscribe-service-value.d.ts.map +1 -0
  80. package/packages/jam/rpc/src/handlers/subscribe-service-value.js +13 -0
  81. package/packages/jam/rpc/src/handlers/subscribe-statistics.d.ts +6 -0
  82. package/packages/jam/rpc/src/handlers/subscribe-statistics.d.ts.map +1 -0
  83. package/packages/jam/rpc/src/handlers/subscribe-statistics.js +13 -0
  84. package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.d.ts +8 -0
  85. package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.d.ts.map +1 -0
  86. package/packages/jam/rpc/src/handlers/typeberry/refine-work-package.js +68 -0
  87. package/packages/jam/rpc/src/handlers/unsubscribe.d.ts +4 -0
  88. package/packages/jam/rpc/src/handlers/unsubscribe.d.ts.map +1 -0
  89. package/packages/jam/rpc/src/handlers/unsubscribe.js +3 -0
  90. package/packages/jam/rpc/src/handlers.d.ts +3 -0
  91. package/packages/jam/rpc/src/handlers.d.ts.map +1 -0
  92. package/packages/jam/rpc/src/handlers.js +60 -0
  93. package/packages/jam/rpc/src/server.d.ts +31 -0
  94. package/packages/jam/rpc/src/server.d.ts.map +1 -0
  95. package/packages/jam/rpc/src/server.js +179 -0
  96. package/packages/jam/rpc/src/subscription-manager.d.ts +20 -0
  97. package/packages/jam/rpc/src/subscription-manager.d.ts.map +1 -0
  98. package/packages/jam/rpc/src/subscription-manager.js +74 -0
  99. package/packages/jam/rpc/test/e2e-server.d.ts +3 -0
  100. package/packages/jam/rpc/test/e2e-server.d.ts.map +1 -0
  101. package/packages/jam/rpc/test/e2e-server.js +32 -0
  102. package/packages/jam/rpc/test/e2e-setup.d.ts +2 -0
  103. package/packages/jam/rpc/test/e2e-setup.d.ts.map +1 -0
  104. package/packages/jam/rpc/test/e2e-setup.js +126 -0
  105. package/packages/jam/rpc/test/e2e.d.ts +2 -0
  106. package/packages/jam/rpc/test/e2e.d.ts.map +1 -0
  107. package/packages/jam/rpc/test/e2e.js +326 -0
  108. package/packages/workers/importer/main.d.ts +2 -0
  109. package/packages/workers/importer/main.d.ts.map +1 -1
  110. package/packages/workers/importer/main.js +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAEL,KAAK,cAAc,EAGnB,KAAK,UAAU,EAWf,KAAK,SAAS,EAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAqBzB,qBAAa,SAAS;IAqBlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAzB1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAsB;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,MAAM,CAAC,GAAG,CACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAC5C,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,SAAS;IAKpB,OAAO;IAoBP,OAAO,CAAC,cAAc;YA+DR,aAAa;YAiCb,cAAc;IAY5B,OAAO,CAAC,YAAY;IASd,WAAW,CAAC,CAAC,EAAE,CAAC,EACpB,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC7B,eAAe,EAAE,CAAC,EAClB,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAC1B,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC;IAiBnB,SAAS,IAAI,MAAM;IAKnB,WAAW,IAAI,UAAU;IAInB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAW7B"}
@@ -0,0 +1,179 @@
1
+ import { Logger } from "#@typeberry/logger";
2
+ import { JSON_RPC_VERSION, RpcError, validation, } from "#@typeberry/rpc-validation";
3
+ import { WebSocketServer } from "ws";
4
+ import { SubscriptionManager } from "./subscription-manager.js";
5
+ const PING_INTERVAL_MS = 30000;
6
+ function createErrorResponse(error, id) {
7
+ return {
8
+ jsonrpc: JSON_RPC_VERSION,
9
+ error: {
10
+ code: error.code,
11
+ message: error.message,
12
+ data: error.data,
13
+ },
14
+ id,
15
+ };
16
+ }
17
+ function createParamsParseErrorMessage(error) {
18
+ return `Invalid params:\n${error.issues.map((issue) => `[${issue.path.join(".")}] ${issue.message}`).join(",\n")}`;
19
+ }
20
+ export class RpcServer {
21
+ rootDb;
22
+ chainSpec;
23
+ blake2b;
24
+ pvmBackend;
25
+ handlers;
26
+ schemas;
27
+ wss;
28
+ blocks;
29
+ states;
30
+ subscriptionManager;
31
+ logger;
32
+ static new(port, rootDb, chainSpec, blake2b, pvmBackend, handlers, schemas) {
33
+ return new RpcServer(port, rootDb, chainSpec, blake2b, pvmBackend, handlers, schemas);
34
+ }
35
+ constructor(port, rootDb, chainSpec, blake2b, pvmBackend, handlers, schemas) {
36
+ this.rootDb = rootDb;
37
+ this.chainSpec = chainSpec;
38
+ this.blake2b = blake2b;
39
+ this.pvmBackend = pvmBackend;
40
+ this.handlers = handlers;
41
+ this.schemas = schemas;
42
+ this.logger = Logger.new(import.meta.filename, "rpc");
43
+ this.blocks = this.rootDb.getBlocksDb();
44
+ this.states = this.rootDb.getStatesDb();
45
+ this.wss = new WebSocketServer({ port });
46
+ this.setupWebSocket();
47
+ this.subscriptionManager = SubscriptionManager.new(this.callHandler.bind(this));
48
+ }
49
+ setupWebSocket() {
50
+ this.wss.on("error", (error) => {
51
+ this.logger.error `Server error: ${error}`;
52
+ });
53
+ this.wss.on("listening", () => {
54
+ this.logger.info `Server listening on port ${this.wss.options.port}`;
55
+ });
56
+ this.wss.on("connection", (ws) => {
57
+ let isAlive = true;
58
+ ws.on("pong", () => {
59
+ isAlive = true;
60
+ });
61
+ const pingInterval = setInterval(() => {
62
+ if (!isAlive) {
63
+ ws.terminate();
64
+ }
65
+ isAlive = false;
66
+ ws.ping();
67
+ this.logger.info `Pinging client`;
68
+ }, PING_INTERVAL_MS);
69
+ ws.on("close", () => {
70
+ clearInterval(pingInterval);
71
+ });
72
+ ws.on("message", async (data) => {
73
+ let rawRequest;
74
+ try {
75
+ rawRequest = JSON.parse(data);
76
+ }
77
+ catch {
78
+ ws.send(JSON.stringify(createErrorResponse(new RpcError(-32700, "Parse error"), null)));
79
+ return;
80
+ }
81
+ if (Array.isArray(rawRequest)) {
82
+ if (rawRequest.length === 0) {
83
+ ws.send(JSON.stringify(createErrorResponse(new RpcError(-32600, "Array must contain requests."), null)));
84
+ return;
85
+ }
86
+ const responses = (await Promise.all(rawRequest.map((request) => this.handleRequest(request, ws)))).filter((response) => response !== null);
87
+ if (responses.length > 0) {
88
+ ws.send(JSON.stringify(responses));
89
+ }
90
+ return;
91
+ }
92
+ const response = await this.handleRequest(rawRequest, ws);
93
+ if (response !== null) {
94
+ ws.send(JSON.stringify(response));
95
+ }
96
+ });
97
+ });
98
+ }
99
+ async handleRequest(request, ws) {
100
+ const requestParseResult = validation.jsonRpcRequest.safeParse(request);
101
+ if (requestParseResult.success === true) {
102
+ try {
103
+ return {
104
+ jsonrpc: JSON_RPC_VERSION,
105
+ result: await this.fulfillRequest(requestParseResult.data, ws),
106
+ id: requestParseResult.data.id,
107
+ };
108
+ }
109
+ catch (error) {
110
+ const rpcError = error instanceof RpcError
111
+ ? error
112
+ : new RpcError(-32603, error instanceof Error ? error.message : "Internal error");
113
+ return createErrorResponse(rpcError, requestParseResult.data.id);
114
+ }
115
+ }
116
+ const notificationParseResult = validation.jsonRpcNotification.safeParse(request);
117
+ if (notificationParseResult.success === true) {
118
+ try {
119
+ await this.fulfillRequest(notificationParseResult.data, ws);
120
+ }
121
+ catch (error) {
122
+ const msg = error instanceof Error ? error.message : "Unknown error";
123
+ this.logger.error `Notification ${JSON.stringify(notificationParseResult.data)} caused an error: ${msg}`;
124
+ }
125
+ return null;
126
+ }
127
+ return createErrorResponse(new RpcError(-32600, `Invalid request: ${JSON.stringify(request)}`), null);
128
+ }
129
+ async fulfillRequest(request, ws) {
130
+ const { method, params } = request;
131
+ if (!(method in this.schemas)) {
132
+ throw new RpcError(-32601, `Method not found: ${method}`);
133
+ }
134
+ const methodName = method;
135
+ const handler = this.handlers[methodName];
136
+ const validatedParams = this.validateCall(methodName, params ?? []);
137
+ return this.callHandler(handler, validatedParams, this.schemas[methodName].output, ws);
138
+ }
139
+ validateCall(method, params) {
140
+ const { input } = this.schemas[method];
141
+ const parseResult = input.safeParse(params);
142
+ if (parseResult.error !== undefined) {
143
+ throw new RpcError(-32602, createParamsParseErrorMessage(parseResult.error));
144
+ }
145
+ return parseResult.data;
146
+ }
147
+ async callHandler(handler, validatedParams, outputSchema, ws) {
148
+ const db = {
149
+ blocks: this.blocks,
150
+ states: this.states,
151
+ };
152
+ const context = {
153
+ db,
154
+ chainSpec: this.chainSpec,
155
+ pvmBackend: this.pvmBackend,
156
+ blake2b: this.blake2b,
157
+ subscription: this.subscriptionManager.getHandlerApi(ws),
158
+ };
159
+ return outputSchema.encode(await handler(validatedParams, context));
160
+ }
161
+ getLogger() {
162
+ return this.logger;
163
+ }
164
+ // for testing only
165
+ getHandlers() {
166
+ return this.handlers;
167
+ }
168
+ async close() {
169
+ this.logger.info `Cleaning up...`;
170
+ await new Promise((resolve) => {
171
+ for (const ws of this.wss.clients) {
172
+ ws.terminate();
173
+ }
174
+ this.wss.close(() => resolve());
175
+ });
176
+ this.subscriptionManager.destroy();
177
+ await this.rootDb.close();
178
+ }
179
+ }
@@ -0,0 +1,20 @@
1
+ import { type GenericHandler, type SubscriptionHandlerApi } from "#@typeberry/rpc-validation";
2
+ import type WebSocket from "ws";
3
+ import type z from "zod";
4
+ type CallHandler = <I, O>(handler: GenericHandler<I, O>, validatedParams: I, outputSchema: z.ZodType<O>, ws: WebSocket) => Promise<unknown>;
5
+ export declare class SubscriptionManager {
6
+ private callHandler;
7
+ private subscriptions;
8
+ private lastResults;
9
+ private pollInterval;
10
+ private nextId;
11
+ static new(callHandler: CallHandler): SubscriptionManager;
12
+ private constructor();
13
+ private pollSubscriptions;
14
+ private subscribe;
15
+ private unsubscribe;
16
+ getHandlerApi(ws: WebSocket): SubscriptionHandlerApi;
17
+ destroy(): void;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=subscription-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/src/subscription-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAOnB,KAAK,sBAAsB,EAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,SAAS,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,KAAK,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EACtB,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC7B,eAAe,EAAE,CAAC,EAClB,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAC1B,EAAE,EAAE,SAAS,KACV,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,qBAAa,mBAAmB;IAWV,OAAO,CAAC,WAAW;IATvC,OAAO,CAAC,aAAa,CAA8C;IACnE,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,MAAM,CAAS;IAEvB,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW;IAInC,OAAO;YAOO,iBAAiB;IAqC/B,OAAO,CAAC,SAAS;IAqBjB,OAAO,CAAC,WAAW;IAQnB,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,sBAAsB;IAOpD,OAAO,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,74 @@
1
+ import { JSON_RPC_VERSION, RpcError, RpcErrorCode, } from "#@typeberry/rpc-validation";
2
+ const POLL_INTERVAL_MS = 1000;
3
+ export class SubscriptionManager {
4
+ callHandler;
5
+ // biome-ignore lint/suspicious/noExplicitAny: subscriptions must accept generic handlers
6
+ subscriptions;
7
+ lastResults;
8
+ pollInterval;
9
+ nextId;
10
+ static new(callHandler) {
11
+ return new SubscriptionManager(callHandler);
12
+ }
13
+ constructor(callHandler) {
14
+ this.callHandler = callHandler;
15
+ this.subscriptions = new Map();
16
+ this.lastResults = new Map();
17
+ this.pollInterval = setInterval(() => this.pollSubscriptions(), POLL_INTERVAL_MS);
18
+ this.nextId = 0;
19
+ }
20
+ async pollSubscriptions() {
21
+ for (const [subscriptionId, subscription] of this.subscriptions) {
22
+ const lastResult = this.lastResults.get(subscriptionId);
23
+ let notificationString;
24
+ try {
25
+ const result = await this.callHandler(subscription.handler, subscription.params, subscription.outputSchema, subscription.ws);
26
+ const notification = {
27
+ jsonrpc: JSON_RPC_VERSION,
28
+ method: subscription.method,
29
+ params: { subscriptionId, result },
30
+ };
31
+ notificationString = JSON.stringify(notification);
32
+ }
33
+ catch (error) {
34
+ const notification = {
35
+ jsonrpc: JSON_RPC_VERSION,
36
+ method: subscription.method,
37
+ params: { subscriptionId, error: `${error}` },
38
+ };
39
+ notificationString = JSON.stringify(notification);
40
+ }
41
+ if (notificationString !== lastResult) {
42
+ subscription.ws.send(notificationString);
43
+ this.lastResults.set(subscriptionId, notificationString);
44
+ }
45
+ }
46
+ }
47
+ subscribe(ws, method, handler, outputSchema, params) {
48
+ const id = this.nextId++;
49
+ const idHex = `0x${id.toString(16)}`;
50
+ this.subscriptions.set(idHex, { ws, method, handler, outputSchema, params });
51
+ ws.on("close", () => {
52
+ if (this.subscriptions.has(idHex)) {
53
+ this.unsubscribe(ws, idHex);
54
+ }
55
+ });
56
+ return idHex;
57
+ }
58
+ unsubscribe(ws, id) {
59
+ if (this.subscriptions.get(id)?.ws !== ws) {
60
+ throw new RpcError(RpcErrorCode.Other, "Subscription not found.");
61
+ }
62
+ this.lastResults.delete(id);
63
+ return this.subscriptions.delete(id);
64
+ }
65
+ getHandlerApi(ws) {
66
+ return {
67
+ subscribe: (method, handler, outputSchema, params) => this.subscribe(ws, method, handler, outputSchema, params),
68
+ unsubscribe: (id) => this.unsubscribe(ws, id),
69
+ };
70
+ }
71
+ destroy() {
72
+ clearInterval(this.pollInterval);
73
+ }
74
+ }
@@ -0,0 +1,3 @@
1
+ import { RpcServer } from "../src/server.js";
2
+ export declare function startTestRpcServer(configPath: string, port?: number): Promise<RpcServer>;
3
+ //# sourceMappingURL=e2e-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e2e-server.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/test/e2e-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM7C,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,SAAe,sBA6B/E"}
@@ -0,0 +1,32 @@
1
+ import { PvmBackend } from "#@typeberry/config";
2
+ import { loadConfig, NODE_DEFAULTS, RegularStateBackend } from "#@typeberry/config-node";
3
+ import { Blake2b } from "#@typeberry/hash";
4
+ import { getChainSpec, getDatabasePath } from "#@typeberry/node";
5
+ import { validation } from "#@typeberry/rpc-validation";
6
+ import { workspacePathFix } from "#@typeberry/utils";
7
+ import { FjallWorkerConfig, LmdbWorkerConfig } from "#@typeberry/workers-api-node";
8
+ import { handlers } from "../src/handlers.js";
9
+ import { RpcServer } from "../src/server.js";
10
+ const DEFAULT_PORT = 19800;
11
+ const withRelPath = workspacePathFix(`${import.meta.dirname}/../../../..`);
12
+ export async function startTestRpcServer(configPath, port = DEFAULT_PORT) {
13
+ const blake2b = await Blake2b.createHasher();
14
+ const nodeName = NODE_DEFAULTS.name;
15
+ const nodeConfig = loadConfig([configPath], withRelPath);
16
+ const spec = getChainSpec(nodeConfig.flavor);
17
+ if (nodeConfig.databaseBasePath === undefined) {
18
+ throw new Error("RPC server requires a persistent database path.");
19
+ }
20
+ const { dbPath } = getDatabasePath(blake2b, nodeName, nodeConfig.chainSpec.genesisHeader, withRelPath(nodeConfig.databaseBasePath));
21
+ const dbConfigParams = {
22
+ nodeName,
23
+ chainSpec: spec,
24
+ workerParams: undefined,
25
+ dbPath,
26
+ blake2b,
27
+ };
28
+ const rootDb = nodeConfig.stateBackend === RegularStateBackend.Fjall
29
+ ? await FjallWorkerConfig.new(dbConfigParams).openDatabase({ readonly: true })
30
+ : await LmdbWorkerConfig.new(dbConfigParams).openDatabase({ readonly: true });
31
+ return RpcServer.new(port, rootDb, spec, blake2b, PvmBackend.Ananas, handlers, validation.schemas);
32
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=e2e-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e2e-setup.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/test/e2e-setup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,126 @@
1
+ // biome-ignore-all lint/suspicious/noConsole: bin file
2
+ import { loadConfig, NODE_DEFAULTS } from "#@typeberry/config-node";
3
+ import { Level, Logger } from "#@typeberry/logger";
4
+ import { importBlocks, JamConfig, main as node } from "#@typeberry/node";
5
+ import { workspacePathFix } from "#@typeberry/utils";
6
+ Logger.configureAll(process.env.JAM_LOG ?? "", Level.LOG);
7
+ const withRelPath = workspacePathFix(`${import.meta.dirname}/../../../..`);
8
+ async function main() {
9
+ const nodeConfig = loadConfig([`${import.meta.dirname}/e2e.config.json`], withRelPath);
10
+ const jamConfig = JamConfig.new({
11
+ nodeName: NODE_DEFAULTS.name,
12
+ nodeConfig,
13
+ pvmBackend: NODE_DEFAULTS.pvm,
14
+ });
15
+ try {
16
+ const api = await node(jamConfig, withRelPath, null);
17
+ await importBlocks(api, blocksToImport);
18
+ }
19
+ catch (e) {
20
+ console.error(`${e}`);
21
+ process.exit(-1);
22
+ }
23
+ }
24
+ const blocksToImport = [
25
+ "test-vectors/w3f-davxy_072/traces/storage/00000001.json",
26
+ "test-vectors/w3f-davxy_072/traces/storage/00000002.json",
27
+ "test-vectors/w3f-davxy_072/traces/storage/00000003.json",
28
+ "test-vectors/w3f-davxy_072/traces/storage/00000004.json",
29
+ "test-vectors/w3f-davxy_072/traces/storage/00000005.json",
30
+ "test-vectors/w3f-davxy_072/traces/storage/00000006.json",
31
+ "test-vectors/w3f-davxy_072/traces/storage/00000007.json",
32
+ "test-vectors/w3f-davxy_072/traces/storage/00000008.json",
33
+ "test-vectors/w3f-davxy_072/traces/storage/00000009.json",
34
+ "test-vectors/w3f-davxy_072/traces/storage/00000010.json",
35
+ "test-vectors/w3f-davxy_072/traces/storage/00000011.json",
36
+ "test-vectors/w3f-davxy_072/traces/storage/00000012.json",
37
+ "test-vectors/w3f-davxy_072/traces/storage/00000013.json",
38
+ "test-vectors/w3f-davxy_072/traces/storage/00000014.json",
39
+ "test-vectors/w3f-davxy_072/traces/storage/00000015.json",
40
+ "test-vectors/w3f-davxy_072/traces/storage/00000016.json",
41
+ "test-vectors/w3f-davxy_072/traces/storage/00000017.json",
42
+ "test-vectors/w3f-davxy_072/traces/storage/00000018.json",
43
+ "test-vectors/w3f-davxy_072/traces/storage/00000019.json",
44
+ "test-vectors/w3f-davxy_072/traces/storage/00000020.json",
45
+ "test-vectors/w3f-davxy_072/traces/storage/00000021.json",
46
+ "test-vectors/w3f-davxy_072/traces/storage/00000022.json",
47
+ "test-vectors/w3f-davxy_072/traces/storage/00000023.json",
48
+ "test-vectors/w3f-davxy_072/traces/storage/00000024.json",
49
+ "test-vectors/w3f-davxy_072/traces/storage/00000025.json",
50
+ "test-vectors/w3f-davxy_072/traces/storage/00000026.json",
51
+ "test-vectors/w3f-davxy_072/traces/storage/00000027.json",
52
+ "test-vectors/w3f-davxy_072/traces/storage/00000028.json",
53
+ "test-vectors/w3f-davxy_072/traces/storage/00000029.json",
54
+ "test-vectors/w3f-davxy_072/traces/storage/00000030.json",
55
+ "test-vectors/w3f-davxy_072/traces/storage/00000031.json",
56
+ "test-vectors/w3f-davxy_072/traces/storage/00000032.json",
57
+ "test-vectors/w3f-davxy_072/traces/storage/00000033.json",
58
+ "test-vectors/w3f-davxy_072/traces/storage/00000034.json",
59
+ "test-vectors/w3f-davxy_072/traces/storage/00000035.json",
60
+ "test-vectors/w3f-davxy_072/traces/storage/00000036.json",
61
+ "test-vectors/w3f-davxy_072/traces/storage/00000037.json",
62
+ "test-vectors/w3f-davxy_072/traces/storage/00000038.json",
63
+ "test-vectors/w3f-davxy_072/traces/storage/00000039.json",
64
+ "test-vectors/w3f-davxy_072/traces/storage/00000040.json",
65
+ "test-vectors/w3f-davxy_072/traces/storage/00000041.json",
66
+ "test-vectors/w3f-davxy_072/traces/storage/00000042.json",
67
+ "test-vectors/w3f-davxy_072/traces/storage/00000043.json",
68
+ "test-vectors/w3f-davxy_072/traces/storage/00000044.json",
69
+ "test-vectors/w3f-davxy_072/traces/storage/00000045.json",
70
+ "test-vectors/w3f-davxy_072/traces/storage/00000046.json",
71
+ "test-vectors/w3f-davxy_072/traces/storage/00000047.json",
72
+ "test-vectors/w3f-davxy_072/traces/storage/00000048.json",
73
+ "test-vectors/w3f-davxy_072/traces/storage/00000049.json",
74
+ "test-vectors/w3f-davxy_072/traces/storage/00000050.json",
75
+ "test-vectors/w3f-davxy_072/traces/storage/00000051.json",
76
+ "test-vectors/w3f-davxy_072/traces/storage/00000052.json",
77
+ "test-vectors/w3f-davxy_072/traces/storage/00000053.json",
78
+ "test-vectors/w3f-davxy_072/traces/storage/00000054.json",
79
+ "test-vectors/w3f-davxy_072/traces/storage/00000055.json",
80
+ "test-vectors/w3f-davxy_072/traces/storage/00000056.json",
81
+ "test-vectors/w3f-davxy_072/traces/storage/00000057.json",
82
+ "test-vectors/w3f-davxy_072/traces/storage/00000058.json",
83
+ "test-vectors/w3f-davxy_072/traces/storage/00000059.json",
84
+ "test-vectors/w3f-davxy_072/traces/storage/00000060.json",
85
+ "test-vectors/w3f-davxy_072/traces/storage/00000061.json",
86
+ "test-vectors/w3f-davxy_072/traces/storage/00000062.json",
87
+ "test-vectors/w3f-davxy_072/traces/storage/00000063.json",
88
+ "test-vectors/w3f-davxy_072/traces/storage/00000064.json",
89
+ "test-vectors/w3f-davxy_072/traces/storage/00000065.json",
90
+ "test-vectors/w3f-davxy_072/traces/storage/00000066.json",
91
+ "test-vectors/w3f-davxy_072/traces/storage/00000067.json",
92
+ "test-vectors/w3f-davxy_072/traces/storage/00000068.json",
93
+ "test-vectors/w3f-davxy_072/traces/storage/00000069.json",
94
+ "test-vectors/w3f-davxy_072/traces/storage/00000070.json",
95
+ "test-vectors/w3f-davxy_072/traces/storage/00000071.json",
96
+ "test-vectors/w3f-davxy_072/traces/storage/00000072.json",
97
+ "test-vectors/w3f-davxy_072/traces/storage/00000073.json",
98
+ "test-vectors/w3f-davxy_072/traces/storage/00000074.json",
99
+ "test-vectors/w3f-davxy_072/traces/storage/00000075.json",
100
+ "test-vectors/w3f-davxy_072/traces/storage/00000076.json",
101
+ "test-vectors/w3f-davxy_072/traces/storage/00000077.json",
102
+ "test-vectors/w3f-davxy_072/traces/storage/00000078.json",
103
+ "test-vectors/w3f-davxy_072/traces/storage/00000079.json",
104
+ "test-vectors/w3f-davxy_072/traces/storage/00000080.json",
105
+ "test-vectors/w3f-davxy_072/traces/storage/00000081.json",
106
+ "test-vectors/w3f-davxy_072/traces/storage/00000082.json",
107
+ "test-vectors/w3f-davxy_072/traces/storage/00000083.json",
108
+ "test-vectors/w3f-davxy_072/traces/storage/00000084.json",
109
+ "test-vectors/w3f-davxy_072/traces/storage/00000085.json",
110
+ "test-vectors/w3f-davxy_072/traces/storage/00000086.json",
111
+ "test-vectors/w3f-davxy_072/traces/storage/00000087.json",
112
+ "test-vectors/w3f-davxy_072/traces/storage/00000088.json",
113
+ "test-vectors/w3f-davxy_072/traces/storage/00000089.json",
114
+ "test-vectors/w3f-davxy_072/traces/storage/00000090.json",
115
+ "test-vectors/w3f-davxy_072/traces/storage/00000091.json",
116
+ "test-vectors/w3f-davxy_072/traces/storage/00000092.json",
117
+ "test-vectors/w3f-davxy_072/traces/storage/00000093.json",
118
+ "test-vectors/w3f-davxy_072/traces/storage/00000094.json",
119
+ "test-vectors/w3f-davxy_072/traces/storage/00000095.json",
120
+ "test-vectors/w3f-davxy_072/traces/storage/00000096.json",
121
+ "test-vectors/w3f-davxy_072/traces/storage/00000097.json",
122
+ "test-vectors/w3f-davxy_072/traces/storage/00000098.json",
123
+ "test-vectors/w3f-davxy_072/traces/storage/00000099.json",
124
+ "test-vectors/w3f-davxy_072/traces/storage/00000100.json",
125
+ ].map(withRelPath);
126
+ main();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=e2e.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e2e.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/rpc/test/e2e.ts"],"names":[],"mappings":""}