@xyo-network/chain-producer 1.19.7 → 1.19.9
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/dist/node/ProducerActor.d.ts +436 -28
- package/dist/node/ProducerActor.d.ts.map +1 -1
- package/dist/node/index.mjs +43 -56
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/runProducer.d.ts +2 -6
- package/dist/node/runProducer.d.ts.map +1 -1
- package/package.json +10 -13
- package/src/ProducerActor.ts +50 -60
- package/src/runProducer.ts +12 -19
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { Attributes, Counter } from '@opentelemetry/api';
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
logger: Logger;
|
|
7
|
-
rewardAddress: Address;
|
|
2
|
+
import type { ActorParamsV3, ChainContractViewer, ChainStakeIntent, Config, HydratedBlockWithHashMeta, XL1BlockNumber } from '@xyo-network/xl1-sdk';
|
|
3
|
+
import { AccountBalanceViewer, ActorV3, BlockRunner, BlockViewer, MempoolRunner, MempoolViewer, StakeTotalsViewer } from '@xyo-network/xl1-sdk';
|
|
4
|
+
export type ProducerActorParams = ActorParamsV3<{
|
|
5
|
+
config: Config;
|
|
8
6
|
}>;
|
|
9
|
-
export declare class ProducerActor extends
|
|
7
|
+
export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
10
8
|
/**
|
|
11
9
|
* The interval time (in MS) between block production attempts.
|
|
12
10
|
*/
|
|
@@ -29,6 +27,7 @@ export declare class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
29
27
|
private _accountBalanceViewer?;
|
|
30
28
|
private _blockRunner?;
|
|
31
29
|
private _blockViewer?;
|
|
30
|
+
private _chainContractViewer?;
|
|
32
31
|
private _chainId?;
|
|
33
32
|
private _lastHeadChangeTime?;
|
|
34
33
|
private _lastHeadHash?;
|
|
@@ -36,35 +35,444 @@ export declare class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
36
35
|
private _mempoolViewer?;
|
|
37
36
|
private _produceBlockMutex;
|
|
38
37
|
private _stakeTotalsViewer?;
|
|
39
|
-
get logger(): Logger;
|
|
38
|
+
get logger(): import("@xylabs/sdk-js").Logger;
|
|
40
39
|
protected get accountBalanceViewer(): AccountBalanceViewer;
|
|
41
40
|
protected get blockRunner(): BlockRunner;
|
|
42
41
|
protected get blockViewer(): BlockViewer<"BlockViewer">;
|
|
42
|
+
protected get chainContractViewer(): ChainContractViewer;
|
|
43
43
|
protected get chainId(): import("@xylabs/sdk-js").BrandedHex;
|
|
44
|
+
protected get config(): {
|
|
45
|
+
chain: {
|
|
46
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
47
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
48
|
+
readonly __hex: true;
|
|
49
|
+
} & {
|
|
50
|
+
readonly __address: true;
|
|
51
|
+
}) | undefined;
|
|
52
|
+
};
|
|
53
|
+
evm: {
|
|
54
|
+
chainId?: string | undefined;
|
|
55
|
+
infura?: {
|
|
56
|
+
projectId?: string | undefined;
|
|
57
|
+
projectSecret?: string | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
jsonRpc?: {
|
|
60
|
+
url?: string | undefined;
|
|
61
|
+
} | undefined;
|
|
62
|
+
};
|
|
63
|
+
log: {
|
|
64
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
65
|
+
silent: boolean;
|
|
66
|
+
};
|
|
67
|
+
remote: {
|
|
68
|
+
rpc?: {
|
|
69
|
+
url: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
};
|
|
72
|
+
storage: {
|
|
73
|
+
mongo?: {
|
|
74
|
+
connectionString?: string | undefined;
|
|
75
|
+
database?: string | undefined;
|
|
76
|
+
domain?: string | undefined;
|
|
77
|
+
password?: string | undefined;
|
|
78
|
+
username?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
root?: string | undefined;
|
|
81
|
+
};
|
|
82
|
+
telemetry: {
|
|
83
|
+
metrics?: {
|
|
84
|
+
scrape: {
|
|
85
|
+
path: string;
|
|
86
|
+
port?: number | undefined;
|
|
87
|
+
};
|
|
88
|
+
} | undefined;
|
|
89
|
+
otel?: {
|
|
90
|
+
otlpEndpoint?: string | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
};
|
|
93
|
+
validation: {
|
|
94
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
95
|
+
readonly __hex: true;
|
|
96
|
+
} & {
|
|
97
|
+
readonly __address: true;
|
|
98
|
+
})[] | undefined;
|
|
99
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
100
|
+
readonly __hex: true;
|
|
101
|
+
} & {
|
|
102
|
+
readonly __address: true;
|
|
103
|
+
})[] | undefined;
|
|
104
|
+
};
|
|
105
|
+
actors: {
|
|
106
|
+
api: {
|
|
107
|
+
chain: {
|
|
108
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
109
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
110
|
+
readonly __hex: true;
|
|
111
|
+
} & {
|
|
112
|
+
readonly __address: true;
|
|
113
|
+
}) | undefined;
|
|
114
|
+
};
|
|
115
|
+
evm: {
|
|
116
|
+
chainId?: string | undefined;
|
|
117
|
+
infura?: {
|
|
118
|
+
projectId?: string | undefined;
|
|
119
|
+
projectSecret?: string | undefined;
|
|
120
|
+
} | undefined;
|
|
121
|
+
jsonRpc?: {
|
|
122
|
+
url?: string | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
};
|
|
125
|
+
log: {
|
|
126
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
127
|
+
silent: boolean;
|
|
128
|
+
};
|
|
129
|
+
remote: {
|
|
130
|
+
rpc?: {
|
|
131
|
+
url: string;
|
|
132
|
+
} | undefined;
|
|
133
|
+
};
|
|
134
|
+
storage: {
|
|
135
|
+
mongo?: {
|
|
136
|
+
connectionString?: string | undefined;
|
|
137
|
+
database?: string | undefined;
|
|
138
|
+
domain?: string | undefined;
|
|
139
|
+
password?: string | undefined;
|
|
140
|
+
username?: string | undefined;
|
|
141
|
+
} | undefined;
|
|
142
|
+
root?: string | undefined;
|
|
143
|
+
};
|
|
144
|
+
telemetry: {
|
|
145
|
+
metrics?: {
|
|
146
|
+
scrape: {
|
|
147
|
+
path: string;
|
|
148
|
+
port?: number | undefined;
|
|
149
|
+
};
|
|
150
|
+
} | undefined;
|
|
151
|
+
otel?: {
|
|
152
|
+
otlpEndpoint?: string | undefined;
|
|
153
|
+
} | undefined;
|
|
154
|
+
};
|
|
155
|
+
validation: {
|
|
156
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
157
|
+
readonly __hex: true;
|
|
158
|
+
} & {
|
|
159
|
+
readonly __address: true;
|
|
160
|
+
})[] | undefined;
|
|
161
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
162
|
+
readonly __hex: true;
|
|
163
|
+
} & {
|
|
164
|
+
readonly __address: true;
|
|
165
|
+
})[] | undefined;
|
|
166
|
+
};
|
|
167
|
+
host: string;
|
|
168
|
+
initRewardsCache: boolean;
|
|
169
|
+
port: number;
|
|
170
|
+
mnemonic?: string | undefined;
|
|
171
|
+
};
|
|
172
|
+
bridge: {
|
|
173
|
+
chain: {
|
|
174
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
175
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
176
|
+
readonly __hex: true;
|
|
177
|
+
} & {
|
|
178
|
+
readonly __address: true;
|
|
179
|
+
}) | undefined;
|
|
180
|
+
};
|
|
181
|
+
evm: {
|
|
182
|
+
chainId?: string | undefined;
|
|
183
|
+
infura?: {
|
|
184
|
+
projectId?: string | undefined;
|
|
185
|
+
projectSecret?: string | undefined;
|
|
186
|
+
} | undefined;
|
|
187
|
+
jsonRpc?: {
|
|
188
|
+
url?: string | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
};
|
|
191
|
+
log: {
|
|
192
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
193
|
+
silent: boolean;
|
|
194
|
+
};
|
|
195
|
+
remote: {
|
|
196
|
+
rpc?: {
|
|
197
|
+
url: string;
|
|
198
|
+
} | undefined;
|
|
199
|
+
};
|
|
200
|
+
storage: {
|
|
201
|
+
mongo?: {
|
|
202
|
+
connectionString?: string | undefined;
|
|
203
|
+
database?: string | undefined;
|
|
204
|
+
domain?: string | undefined;
|
|
205
|
+
password?: string | undefined;
|
|
206
|
+
username?: string | undefined;
|
|
207
|
+
} | undefined;
|
|
208
|
+
root?: string | undefined;
|
|
209
|
+
};
|
|
210
|
+
telemetry: {
|
|
211
|
+
metrics?: {
|
|
212
|
+
scrape: {
|
|
213
|
+
path: string;
|
|
214
|
+
port?: number | undefined;
|
|
215
|
+
};
|
|
216
|
+
} | undefined;
|
|
217
|
+
otel?: {
|
|
218
|
+
otlpEndpoint?: string | undefined;
|
|
219
|
+
} | undefined;
|
|
220
|
+
};
|
|
221
|
+
validation: {
|
|
222
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
223
|
+
readonly __hex: true;
|
|
224
|
+
} & {
|
|
225
|
+
readonly __address: true;
|
|
226
|
+
})[] | undefined;
|
|
227
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
228
|
+
readonly __hex: true;
|
|
229
|
+
} & {
|
|
230
|
+
readonly __address: true;
|
|
231
|
+
})[] | undefined;
|
|
232
|
+
};
|
|
233
|
+
chainRpcApiUrl: string;
|
|
234
|
+
feeFixed: import("@xylabs/sdk-js").BrandedHex;
|
|
235
|
+
feeRateBasisPoints: number;
|
|
236
|
+
host: string;
|
|
237
|
+
maxBridgeAmount: import("@xylabs/sdk-js").BrandedHex;
|
|
238
|
+
minBridgeAmount: import("@xylabs/sdk-js").BrandedHex;
|
|
239
|
+
port: number;
|
|
240
|
+
redisHost: string;
|
|
241
|
+
redisPort: number;
|
|
242
|
+
remoteBridgeContractAddress: Lowercase<string> & {
|
|
243
|
+
readonly __hex: true;
|
|
244
|
+
} & {
|
|
245
|
+
readonly __address: true;
|
|
246
|
+
};
|
|
247
|
+
remoteChainId: import("@xylabs/sdk-js").BrandedHex;
|
|
248
|
+
remoteTokenAddress: import("@xylabs/sdk-js").BrandedHex;
|
|
249
|
+
remoteChainWalletPrivateKey: import("@xylabs/sdk-js").BrandedHex;
|
|
250
|
+
escrowAddress?: (Lowercase<string> & {
|
|
251
|
+
readonly __hex: true;
|
|
252
|
+
} & {
|
|
253
|
+
readonly __address: true;
|
|
254
|
+
}) | undefined;
|
|
255
|
+
feesAddress?: (Lowercase<string> & {
|
|
256
|
+
readonly __hex: true;
|
|
257
|
+
} & {
|
|
258
|
+
readonly __address: true;
|
|
259
|
+
}) | undefined;
|
|
260
|
+
mnemonic?: string | undefined;
|
|
261
|
+
xl1ChainId?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
262
|
+
xl1TokenAddress?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
263
|
+
};
|
|
264
|
+
mempool: {
|
|
265
|
+
chain: {
|
|
266
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
267
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
268
|
+
readonly __hex: true;
|
|
269
|
+
} & {
|
|
270
|
+
readonly __address: true;
|
|
271
|
+
}) | undefined;
|
|
272
|
+
};
|
|
273
|
+
evm: {
|
|
274
|
+
chainId?: string | undefined;
|
|
275
|
+
infura?: {
|
|
276
|
+
projectId?: string | undefined;
|
|
277
|
+
projectSecret?: string | undefined;
|
|
278
|
+
} | undefined;
|
|
279
|
+
jsonRpc?: {
|
|
280
|
+
url?: string | undefined;
|
|
281
|
+
} | undefined;
|
|
282
|
+
};
|
|
283
|
+
log: {
|
|
284
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
285
|
+
silent: boolean;
|
|
286
|
+
};
|
|
287
|
+
remote: {
|
|
288
|
+
rpc?: {
|
|
289
|
+
url: string;
|
|
290
|
+
} | undefined;
|
|
291
|
+
};
|
|
292
|
+
storage: {
|
|
293
|
+
mongo?: {
|
|
294
|
+
connectionString?: string | undefined;
|
|
295
|
+
database?: string | undefined;
|
|
296
|
+
domain?: string | undefined;
|
|
297
|
+
password?: string | undefined;
|
|
298
|
+
username?: string | undefined;
|
|
299
|
+
} | undefined;
|
|
300
|
+
root?: string | undefined;
|
|
301
|
+
};
|
|
302
|
+
telemetry: {
|
|
303
|
+
metrics?: {
|
|
304
|
+
scrape: {
|
|
305
|
+
path: string;
|
|
306
|
+
port?: number | undefined;
|
|
307
|
+
};
|
|
308
|
+
} | undefined;
|
|
309
|
+
otel?: {
|
|
310
|
+
otlpEndpoint?: string | undefined;
|
|
311
|
+
} | undefined;
|
|
312
|
+
};
|
|
313
|
+
validation: {
|
|
314
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
315
|
+
readonly __hex: true;
|
|
316
|
+
} & {
|
|
317
|
+
readonly __address: true;
|
|
318
|
+
})[] | undefined;
|
|
319
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
320
|
+
readonly __hex: true;
|
|
321
|
+
} & {
|
|
322
|
+
readonly __address: true;
|
|
323
|
+
})[] | undefined;
|
|
324
|
+
};
|
|
325
|
+
enabled: boolean;
|
|
326
|
+
host: string;
|
|
327
|
+
port: number;
|
|
328
|
+
mnemonic?: string | undefined;
|
|
329
|
+
};
|
|
330
|
+
producer: {
|
|
331
|
+
chain: {
|
|
332
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
333
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
334
|
+
readonly __hex: true;
|
|
335
|
+
} & {
|
|
336
|
+
readonly __address: true;
|
|
337
|
+
}) | undefined;
|
|
338
|
+
};
|
|
339
|
+
evm: {
|
|
340
|
+
chainId?: string | undefined;
|
|
341
|
+
infura?: {
|
|
342
|
+
projectId?: string | undefined;
|
|
343
|
+
projectSecret?: string | undefined;
|
|
344
|
+
} | undefined;
|
|
345
|
+
jsonRpc?: {
|
|
346
|
+
url?: string | undefined;
|
|
347
|
+
} | undefined;
|
|
348
|
+
};
|
|
349
|
+
log: {
|
|
350
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
351
|
+
silent: boolean;
|
|
352
|
+
};
|
|
353
|
+
remote: {
|
|
354
|
+
rpc?: {
|
|
355
|
+
url: string;
|
|
356
|
+
} | undefined;
|
|
357
|
+
};
|
|
358
|
+
storage: {
|
|
359
|
+
mongo?: {
|
|
360
|
+
connectionString?: string | undefined;
|
|
361
|
+
database?: string | undefined;
|
|
362
|
+
domain?: string | undefined;
|
|
363
|
+
password?: string | undefined;
|
|
364
|
+
username?: string | undefined;
|
|
365
|
+
} | undefined;
|
|
366
|
+
root?: string | undefined;
|
|
367
|
+
};
|
|
368
|
+
telemetry: {
|
|
369
|
+
metrics?: {
|
|
370
|
+
scrape: {
|
|
371
|
+
path: string;
|
|
372
|
+
port?: number | undefined;
|
|
373
|
+
};
|
|
374
|
+
} | undefined;
|
|
375
|
+
otel?: {
|
|
376
|
+
otlpEndpoint?: string | undefined;
|
|
377
|
+
} | undefined;
|
|
378
|
+
};
|
|
379
|
+
validation: {
|
|
380
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
381
|
+
readonly __hex: true;
|
|
382
|
+
} & {
|
|
383
|
+
readonly __address: true;
|
|
384
|
+
})[] | undefined;
|
|
385
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
386
|
+
readonly __hex: true;
|
|
387
|
+
} & {
|
|
388
|
+
readonly __address: true;
|
|
389
|
+
})[] | undefined;
|
|
390
|
+
};
|
|
391
|
+
heartbeatInterval: number;
|
|
392
|
+
minStake: number;
|
|
393
|
+
port: number;
|
|
394
|
+
allowlist?: (Lowercase<string> & {
|
|
395
|
+
readonly __hex: true;
|
|
396
|
+
} & {
|
|
397
|
+
readonly __address: true;
|
|
398
|
+
})[] | undefined;
|
|
399
|
+
disableIntentRedeclaration?: boolean | undefined;
|
|
400
|
+
healthCheckPort?: number | undefined;
|
|
401
|
+
mnemonic?: string | undefined;
|
|
402
|
+
rewardAddress?: string | undefined;
|
|
403
|
+
};
|
|
404
|
+
rewardRedemption: {
|
|
405
|
+
chain: {
|
|
406
|
+
id?: import("@xylabs/sdk-js").BrandedHex | undefined;
|
|
407
|
+
genesisRewardAddress?: (Lowercase<string> & {
|
|
408
|
+
readonly __hex: true;
|
|
409
|
+
} & {
|
|
410
|
+
readonly __address: true;
|
|
411
|
+
}) | undefined;
|
|
412
|
+
};
|
|
413
|
+
evm: {
|
|
414
|
+
chainId?: string | undefined;
|
|
415
|
+
infura?: {
|
|
416
|
+
projectId?: string | undefined;
|
|
417
|
+
projectSecret?: string | undefined;
|
|
418
|
+
} | undefined;
|
|
419
|
+
jsonRpc?: {
|
|
420
|
+
url?: string | undefined;
|
|
421
|
+
} | undefined;
|
|
422
|
+
};
|
|
423
|
+
log: {
|
|
424
|
+
logLevel: "log" | "error" | "warn" | "info" | "debug" | "trace";
|
|
425
|
+
silent: boolean;
|
|
426
|
+
};
|
|
427
|
+
remote: {
|
|
428
|
+
rpc?: {
|
|
429
|
+
url: string;
|
|
430
|
+
} | undefined;
|
|
431
|
+
};
|
|
432
|
+
storage: {
|
|
433
|
+
mongo?: {
|
|
434
|
+
connectionString?: string | undefined;
|
|
435
|
+
database?: string | undefined;
|
|
436
|
+
domain?: string | undefined;
|
|
437
|
+
password?: string | undefined;
|
|
438
|
+
username?: string | undefined;
|
|
439
|
+
} | undefined;
|
|
440
|
+
root?: string | undefined;
|
|
441
|
+
};
|
|
442
|
+
telemetry: {
|
|
443
|
+
metrics?: {
|
|
444
|
+
scrape: {
|
|
445
|
+
path: string;
|
|
446
|
+
port?: number | undefined;
|
|
447
|
+
};
|
|
448
|
+
} | undefined;
|
|
449
|
+
otel?: {
|
|
450
|
+
otlpEndpoint?: string | undefined;
|
|
451
|
+
} | undefined;
|
|
452
|
+
};
|
|
453
|
+
validation: {
|
|
454
|
+
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
455
|
+
readonly __hex: true;
|
|
456
|
+
} & {
|
|
457
|
+
readonly __address: true;
|
|
458
|
+
})[] | undefined;
|
|
459
|
+
allowedRewardEscrowAccountSigners?: (Lowercase<string> & {
|
|
460
|
+
readonly __hex: true;
|
|
461
|
+
} & {
|
|
462
|
+
readonly __address: true;
|
|
463
|
+
})[] | undefined;
|
|
464
|
+
};
|
|
465
|
+
chainRpcApiUrl: string;
|
|
466
|
+
host: string;
|
|
467
|
+
port: number;
|
|
468
|
+
mnemonic?: string | undefined;
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
};
|
|
44
472
|
protected get mempoolRunner(): MempoolRunner;
|
|
45
473
|
protected get mempoolViewer(): MempoolViewer;
|
|
46
|
-
protected get rewardAddress(): Lowercase<string> & {
|
|
47
|
-
readonly __hex: true;
|
|
48
|
-
} & {
|
|
49
|
-
readonly __address: true;
|
|
50
|
-
};
|
|
51
474
|
protected get stakeTotalsViewer(): StakeTotalsViewer;
|
|
52
|
-
static paramsHandler<T extends ProducerActor>(params: Partial<T['params']>): Promise<{
|
|
53
|
-
rewardAddress: Lowercase<string> & {
|
|
54
|
-
readonly __hex: true;
|
|
55
|
-
} & {
|
|
56
|
-
readonly __address: true;
|
|
57
|
-
};
|
|
58
|
-
account: T["params"]["account"];
|
|
59
|
-
logger: import("@xylabs/sdk-js").IdLogger | undefined;
|
|
60
|
-
config: T["params"]["config"];
|
|
61
|
-
name?: import("@xylabs/sdk-js").CreatableName;
|
|
62
|
-
statusReporter?: import("@xylabs/sdk-js").CreatableStatusReporter<void> | undefined;
|
|
63
|
-
meterProvider?: import("@opentelemetry/api").MeterProvider;
|
|
64
|
-
traceProvider?: import("@opentelemetry/api").TracerProvider;
|
|
65
|
-
}>;
|
|
66
475
|
createHandler(): Promise<void>;
|
|
67
|
-
initLocator(): Promise<import("@xyo-network/xl1-sdk").ProviderFactoryLocatorInstance<import("@xyo-network/xl1-sdk").CreatableProviderContextType>>;
|
|
68
476
|
startHandler(): Promise<void>;
|
|
69
477
|
protected calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): number;
|
|
70
478
|
protected produceBlock(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["../../src/ProducerActor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["../../src/ProducerActor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAM7D,OAAO,KAAK,EACV,aAAa,EACkB,mBAAmB,EAAW,gBAAgB,EAAE,MAAM,EAAE,yBAAyB,EAAE,cAAc,EACjI,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,oBAAoB,EAA+B,OAAO,EAAoB,WAAW,EAAsB,WAAW,EACJ,aAAa,EACnI,aAAa,EAAwB,iBAAiB,EACvD,MAAM,sBAAsB,CAAA;AAG7B,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;IAC9C,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA;AAcF,qBACa,aAAc,SAAQ,OAAO,CAAC,mBAAmB,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,4BAA4B,QAAO;IAEnD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,yBAAyB,SAAkD;IAE3F;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,mBAAmB,SAAS;IAE5C,SAAS,CAAC,kBAAkB,CAAC,EAAE,yBAAyB,CAAA;IACxD,SAAS,CAAC,wBAAwB,CAAC,EAAE,gBAAgB,CAAA;IACrD,SAAS,CAAC,iBAAiB,CAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEnB;IAED,SAAS,KAAK,aAAa,kBAE1B;IAED,SAAS,KAAK,aAAa,kBAE1B;IAED,SAAS,KAAK,iBAAiB,sBAE9B;IAEc,aAAa;IAgFb,YAAY;IAe3B,SAAS,CAAC,iDAAiD,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;cAIzE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAgF7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;cAiEhC,yBAAyB,CAAC,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cAkB7G,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC;cAe1C,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;CAWzD"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -3,12 +3,8 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/ProducerActor.ts
|
|
5
5
|
import { assertEx, creatable, isDefined, isUndefined, toHex } from "@xylabs/sdk-js";
|
|
6
|
-
import { buildTelemetryConfig, initEvmProvidersIfAvailable } from "@xyo-network/chain-orchestration";
|
|
7
6
|
import { SimpleBlockRunner } from "@xyo-network/chain-services";
|
|
8
|
-
import {
|
|
9
|
-
import { startupSpanAsync } from "@xyo-network/chain-utils";
|
|
10
|
-
import { validateHydratedBlock, validateHydratedBlockState } from "@xyo-network/chain-validation";
|
|
11
|
-
import { AccountBalanceViewerMoniker, ActorV2, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker, buildJsonRpcProviderLocatorV2, buildTransaction, createDeclarationIntent, DefaultMetricsScrapePorts, HttpRpcTransport, MempoolRunnerMoniker, MempoolViewerMoniker, SimpleBlockRewardViewer, SimpleBlockValidationViewer, StakeTotalsViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
7
|
+
import { AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker, buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker, StakeTotalsViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
12
8
|
import { Mutex } from "async-mutex";
|
|
13
9
|
function _ts_decorate(decorators, target, key, desc) {
|
|
14
10
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -24,7 +20,7 @@ var toFormattedBlockReference = /* @__PURE__ */ __name((blockBoundWitness) => {
|
|
|
24
20
|
prefix: true
|
|
25
21
|
})}]`;
|
|
26
22
|
}, "toFormattedBlockReference");
|
|
27
|
-
var ProducerActor = class _ProducerActor extends
|
|
23
|
+
var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
28
24
|
static {
|
|
29
25
|
__name(this, "ProducerActor");
|
|
30
26
|
}
|
|
@@ -50,6 +46,7 @@ var ProducerActor = class _ProducerActor extends ActorV2 {
|
|
|
50
46
|
_accountBalanceViewer;
|
|
51
47
|
_blockRunner;
|
|
52
48
|
_blockViewer;
|
|
49
|
+
_chainContractViewer;
|
|
53
50
|
_chainId;
|
|
54
51
|
_lastHeadChangeTime;
|
|
55
52
|
_lastHeadHash;
|
|
@@ -69,34 +66,24 @@ var ProducerActor = class _ProducerActor extends ActorV2 {
|
|
|
69
66
|
get blockViewer() {
|
|
70
67
|
return this._blockViewer;
|
|
71
68
|
}
|
|
69
|
+
get chainContractViewer() {
|
|
70
|
+
return this._chainContractViewer;
|
|
71
|
+
}
|
|
72
72
|
get chainId() {
|
|
73
73
|
return this._chainId;
|
|
74
74
|
}
|
|
75
|
+
get config() {
|
|
76
|
+
return this.params.config;
|
|
77
|
+
}
|
|
75
78
|
get mempoolRunner() {
|
|
76
79
|
return this._mempoolRunner;
|
|
77
80
|
}
|
|
78
81
|
get mempoolViewer() {
|
|
79
82
|
return this._mempoolViewer;
|
|
80
83
|
}
|
|
81
|
-
get rewardAddress() {
|
|
82
|
-
return this.params.rewardAddress;
|
|
83
|
-
}
|
|
84
84
|
get stakeTotalsViewer() {
|
|
85
85
|
return this._stakeTotalsViewer;
|
|
86
86
|
}
|
|
87
|
-
static async paramsHandler(params) {
|
|
88
|
-
const superParams = await super.paramsHandler(params);
|
|
89
|
-
const { logger, account } = superParams;
|
|
90
|
-
const rewardAddress = params.rewardAddress ?? account.address;
|
|
91
|
-
logger?.info(`Using reward address ${rewardAddress}`);
|
|
92
|
-
if (rewardAddress === account.address) {
|
|
93
|
-
logger?.warn(`Using producer account address as reward address: ${account.address}`);
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
...superParams,
|
|
97
|
-
rewardAddress
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
87
|
async createHandler() {
|
|
101
88
|
await super.createHandler();
|
|
102
89
|
this._metricAttributes = {
|
|
@@ -114,34 +101,38 @@ var ProducerActor = class _ProducerActor extends ActorV2 {
|
|
|
114
101
|
this._producerActorBlocksPublished = this.meter?.createCounter("producer_actor_blocks_published", {
|
|
115
102
|
description: "Number of blocks published"
|
|
116
103
|
});
|
|
104
|
+
const final = await this.locator?.getInstance(FinalizationViewerMoniker);
|
|
105
|
+
await final.start();
|
|
117
106
|
this._accountBalanceViewer = assertEx(await this.locator?.getInstance(AccountBalanceViewerMoniker), () => "Unable to locate AccountBalanceViewer");
|
|
118
107
|
this._blockRunner = assertEx(await this.locator?.getInstance(BlockRunnerMoniker), () => "Unable to locate BlockRunner");
|
|
119
108
|
this._blockViewer = assertEx(await this.locator?.getInstance(BlockViewerMoniker), () => "Unable to locate BlockViewer");
|
|
109
|
+
this._chainContractViewer = assertEx(await this.locator?.getInstance(ChainContractViewerMoniker), () => "Unable to locate ChainContractViewer");
|
|
120
110
|
this._mempoolRunner = assertEx(await this.locator?.getInstance(MempoolRunnerMoniker), () => "Unable to locate MempoolRunner");
|
|
121
111
|
this._mempoolViewer = assertEx(await this.locator?.getInstance(MempoolViewerMoniker), () => "Unable to locate MempoolViewer");
|
|
122
112
|
this._stakeTotalsViewer = assertEx(await this.locator?.getInstance(StakeTotalsViewerMoniker), () => "Unable to locate StakeTotalsViewer");
|
|
113
|
+
this._chainId = await this.chainContractViewer.chainId();
|
|
123
114
|
}
|
|
124
|
-
async initLocator() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
115
|
+
// async initLocator() {
|
|
116
|
+
// const config = this.config
|
|
117
|
+
// const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')
|
|
118
|
+
// const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)
|
|
119
|
+
// const locator = await buildJsonRpcProviderLocatorV2(config, transportFactory)
|
|
120
|
+
// const version = '1.0.0'
|
|
121
|
+
// const telemetryConfig = buildTelemetryConfig(config, this.name, version, DefaultMetricsScrapePorts.producer)
|
|
122
|
+
// const { traceProvider, meterProvider } = await startupSpanAsync('initTelemetry', () => initTelemetry(telemetryConfig))
|
|
123
|
+
// locator.context.traceProvider = traceProvider
|
|
124
|
+
// locator.context.meterProvider = meterProvider
|
|
125
|
+
// locator.register(SimpleBlockRewardViewer.factory<SimpleBlockRewardViewer>(SimpleBlockRewardViewer.dependencies, {}))
|
|
126
|
+
// locator.register(SimpleBlockValidationViewer.factory<SimpleBlockValidationViewer>(
|
|
127
|
+
// SimpleBlockValidationViewer.dependencies,
|
|
128
|
+
// { state: validateHydratedBlockState, protocol: validateHydratedBlock },
|
|
129
|
+
// ))
|
|
130
|
+
// locator.register(SimpleBlockRunner.factory<SimpleBlockRunner>(
|
|
131
|
+
// SimpleBlockRunner.dependencies,
|
|
132
|
+
// { account: this.params.account, rewardAddress: this.params.rewardAddress },
|
|
133
|
+
// ))
|
|
134
|
+
// return await initEvmProvidersIfAvailable(locator)
|
|
135
|
+
// }
|
|
145
136
|
async startHandler() {
|
|
146
137
|
await super.startHandler();
|
|
147
138
|
this.registerTimer("BlockProductionTimer", async () => {
|
|
@@ -213,7 +204,7 @@ var ProducerActor = class _ProducerActor extends ActorV2 {
|
|
|
213
204
|
}
|
|
214
205
|
async redeclareIntent() {
|
|
215
206
|
await this.spanAsync("redeclareIntent", async () => {
|
|
216
|
-
if (this.config.producer.disableIntentRedeclaration) return;
|
|
207
|
+
if (this.config.actors.producer.disableIntentRedeclaration) return;
|
|
217
208
|
const head = (await this.blockViewer.currentBlock())[0];
|
|
218
209
|
if (isUndefined(head)) return;
|
|
219
210
|
const currentBlock = head.block;
|
|
@@ -231,7 +222,7 @@ var ProducerActor = class _ProducerActor extends ActorV2 {
|
|
|
231
222
|
return;
|
|
232
223
|
}
|
|
233
224
|
if (!await this.validateCurrentStake()) {
|
|
234
|
-
this.logger?.error(`Add stake to contract address ${this.
|
|
225
|
+
this.logger?.error(`Add stake to contract address ${this.chainId} for the producer to declare it's intent.`);
|
|
235
226
|
return;
|
|
236
227
|
}
|
|
237
228
|
this.logger?.log("Creating redeclaration intent for producer:", this.account.address);
|
|
@@ -285,22 +276,18 @@ ProducerActor = _ts_decorate([
|
|
|
285
276
|
], ProducerActor);
|
|
286
277
|
|
|
287
278
|
// src/runProducer.ts
|
|
288
|
-
import {
|
|
279
|
+
import { exists } from "@xylabs/sdk-js";
|
|
289
280
|
import { initProducerAccount } from "@xyo-network/chain-orchestration";
|
|
290
|
-
var runProducer = /* @__PURE__ */ __name(async (
|
|
291
|
-
const localLogger = logger ?? new IdLogger(logger ?? console, () => "ResolveHelper [runProducer]");
|
|
281
|
+
var runProducer = /* @__PURE__ */ __name(async (config, orchestrator, locator) => {
|
|
292
282
|
const account = await initProducerAccount({
|
|
293
|
-
config
|
|
283
|
+
config,
|
|
284
|
+
logger: locator.context.logger
|
|
294
285
|
});
|
|
295
|
-
localLogger.info(`Running producer for account ${account.address}`);
|
|
296
|
-
const rewardAddress = asAddress(config.producer.rewardAddress, () => "rewardAddress is required in config.producer");
|
|
297
|
-
localLogger.info(`Using reward address ${rewardAddress}`);
|
|
298
286
|
const producer = await ProducerActor.create({
|
|
299
|
-
account,
|
|
300
287
|
config,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
288
|
+
locator,
|
|
289
|
+
name: "xl1-producer",
|
|
290
|
+
account
|
|
304
291
|
});
|
|
305
292
|
const actors = [
|
|
306
293
|
producer
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ProducerActor.ts","../../src/runProducer.ts"],"sourcesContent":["import type { Attributes, Counter } from '@opentelemetry/api'\nimport type { Address, Logger } from '@xylabs/sdk-js'\nimport {\n assertEx, creatable, isDefined, isUndefined,\n toHex,\n} from '@xylabs/sdk-js'\nimport { buildTelemetryConfig, initEvmProvidersIfAvailable } from '@xyo-network/chain-orchestration'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport { initTelemetry } from '@xyo-network/chain-telemetry'\nimport { startupSpanAsync } from '@xyo-network/chain-utils'\nimport { validateHydratedBlock, validateHydratedBlockState } from '@xyo-network/chain-validation'\nimport type {\n ActorParamsV2,\n BlockBoundWitnessWithHashMeta, ChainId, ChainStakeIntent, HydratedBlockWithHashMeta, XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewer, AccountBalanceViewerMoniker, ActorV2, asXL1BlockNumber, BlockRunner, BlockRunnerMoniker, BlockViewer, BlockViewerMoniker,\n buildJsonRpcProviderLocatorV2, buildTransaction, createDeclarationIntent, DefaultMetricsScrapePorts, HttpRpcTransport, MempoolRunner, MempoolRunnerMoniker,\n MempoolViewer, MempoolViewerMoniker, RpcSchemaMap, SimpleBlockRewardViewer, SimpleBlockValidationViewer, StakeTotalsViewer, StakeTotalsViewerMoniker,\n TransportFactory,\n} from '@xyo-network/xl1-sdk'\nimport { Mutex } from 'async-mutex'\n\nexport type ProducerActorParams = ActorParamsV2<{\n logger: Logger\n rewardAddress: Address\n}>\n\nconst SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true\nconst TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds\n\n/**\n * Formats a hydrated block with hash meta into a string representation of its hash and block number.\n * @param blockBoundWitness The hydrated block with hash meta to format\n * @returns The formatted block reference string\n */\nconst toFormattedBlockReference = (blockBoundWitness: BlockBoundWitnessWithHashMeta): string => {\n return `${blockBoundWitness.block} [${toHex(blockBoundWitness._hash, { prefix: true })}]`\n}\n\n@creatable()\nexport class ProducerActor extends ActorV2<ProducerActorParams> {\n /**\n * The interval time (in MS) between block production attempts.\n */\n static readonly BlockSubmissionCheckInterval = 1500 // 1.5 seconds\n\n /**\n * The threshold time (in MS) for resubmitting the same block number if the head has not changed.\n */\n static readonly HeadResubmissionThreshold = ProducerActor.BlockSubmissionCheckInterval * 30\n\n /**\n * The window (in blocks) before expiration to attempt redeclaration of producer intent.\n */\n static readonly RedeclarationWindow = 10_000\n\n protected _lastProducedBlock?: HydratedBlockWithHashMeta\n protected _lastRedeclarationIntent?: ChainStakeIntent\n protected _metricAttributes?: Attributes\n protected _producerActorBlockProductionAttempts?: Counter<Attributes>\n protected _producerActorBlockProductionChecks?: Counter<Attributes>\n protected _producerActorBlocksProduced?: Counter<Attributes>\n protected _producerActorBlocksPublished?: Counter<Attributes>\n\n private _accountBalanceViewer?: AccountBalanceViewer\n private _blockRunner?: BlockRunner\n private _blockViewer?: BlockViewer\n private _chainId?: ChainId\n private _lastHeadChangeTime?: number\n private _lastHeadHash?: string\n private _mempoolRunner?: MempoolRunner\n private _mempoolViewer?: MempoolViewer\n private _produceBlockMutex = new Mutex()\n private _stakeTotalsViewer?: StakeTotalsViewer\n\n override get logger() {\n return assertEx(super.logger, () => 'Logger is required for ProducerActor')\n }\n\n protected get accountBalanceViewer() {\n return this._accountBalanceViewer!\n }\n\n protected get blockRunner() {\n return this._blockRunner!\n }\n\n protected get blockViewer() {\n return this._blockViewer!\n }\n\n protected get chainId() {\n return this._chainId!\n }\n\n protected get mempoolRunner() {\n return this._mempoolRunner!\n }\n\n protected get mempoolViewer() {\n return this._mempoolViewer!\n }\n\n protected get rewardAddress() {\n return this.params.rewardAddress!\n }\n\n protected get stakeTotalsViewer() {\n return this._stakeTotalsViewer!\n }\n\n static override async paramsHandler<T extends ProducerActor>(params: Partial<T['params']>) {\n const superParams = await super.paramsHandler(params)\n const { logger, account } = superParams\n const rewardAddress = params.rewardAddress ?? account.address\n logger?.info(`Using reward address ${rewardAddress}`)\n if (rewardAddress === account.address) {\n logger?.warn(`Using producer account address as reward address: ${account.address}`)\n }\n\n return {\n ...superParams,\n rewardAddress,\n }\n }\n\n override async createHandler() {\n await super.createHandler()\n // Create the consistent meter attributes that will\n // be included with all metrics from this actor\n this._metricAttributes = { address: this.account.address.toString() }\n // Create the metrics\n this._producerActorBlockProductionChecks = this.meter?.createCounter(\n 'producer_actor_block_production_checks',\n { description: 'Number of block production checks' },\n )\n this._producerActorBlockProductionAttempts = this.meter?.createCounter(\n 'producer_actor_block_production_attempts',\n { description: 'Number of block production attempts' },\n )\n this._producerActorBlocksProduced = this.meter?.createCounter(\n 'producer_actor_blocks_produced',\n { description: 'Number of blocks produced' },\n )\n this._producerActorBlocksPublished = this.meter?.createCounter(\n 'producer_actor_blocks_published',\n { description: 'Number of blocks published' },\n )\n this._accountBalanceViewer = assertEx(\n await this.locator?.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker),\n () => 'Unable to locate AccountBalanceViewer',\n )\n this._blockRunner = assertEx(\n await this.locator?.getInstance<BlockRunner>(BlockRunnerMoniker),\n () => 'Unable to locate BlockRunner',\n )\n this._blockViewer = assertEx(\n await this.locator?.getInstance<BlockViewer>(BlockViewerMoniker),\n () => 'Unable to locate BlockViewer',\n )\n this._mempoolRunner = assertEx(\n await this.locator?.getInstance<MempoolRunner>(MempoolRunnerMoniker),\n () => 'Unable to locate MempoolRunner',\n )\n this._mempoolViewer = assertEx(\n await this.locator?.getInstance<MempoolViewer>(MempoolViewerMoniker),\n () => 'Unable to locate MempoolViewer',\n )\n this._stakeTotalsViewer = assertEx(\n await this.locator?.getInstance<StakeTotalsViewer>(StakeTotalsViewerMoniker),\n () => 'Unable to locate StakeTotalsViewer',\n )\n }\n\n async initLocator() {\n const config = this.config\n const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')\n const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)\n const locator = await buildJsonRpcProviderLocatorV2(config, transportFactory)\n\n const version = '1.0.0'\n const telemetryConfig = buildTelemetryConfig(config, this.name, version, DefaultMetricsScrapePorts.producer)\n const { traceProvider, meterProvider } = await startupSpanAsync('initTelemetry', () => initTelemetry(telemetryConfig))\n\n locator.context.traceProvider = traceProvider\n locator.context.meterProvider = meterProvider\n\n locator.register(SimpleBlockRewardViewer.factory<SimpleBlockRewardViewer>(SimpleBlockRewardViewer.dependencies, {}))\n locator.register(SimpleBlockValidationViewer.factory<SimpleBlockValidationViewer>(\n SimpleBlockValidationViewer.dependencies,\n { state: validateHydratedBlockState, protocol: validateHydratedBlock },\n ))\n locator.register(SimpleBlockRunner.factory<SimpleBlockRunner>(\n SimpleBlockRunner.dependencies,\n { account: this.params.account, rewardAddress: this.params.rewardAddress },\n ))\n return await initEvmProvidersIfAvailable(locator)\n }\n\n override async startHandler() {\n await super.startHandler()\n // Register a timer to check if we should produce a block\n this.registerTimer('BlockProductionTimer', async () => {\n await this.produceBlock()\n }, 2000, ProducerActor.BlockSubmissionCheckInterval)\n\n if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {\n // Register a timer to check if we should redeclare the producer\n this.registerTimer('ProducerRedeclarationTimer', async () => {\n await this.redeclareIntent()\n }, TEN_MINUTES, TEN_MINUTES)\n }\n }\n\n protected calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): number {\n return (this._lastRedeclarationIntent?.exp ?? currentBlock) - currentBlock\n }\n\n protected async produceBlock(): Promise<void> {\n this._producerActorBlockProductionChecks?.add(1, this._metricAttributes)\n await this.spanAsync('produceBlock', async () => {\n if (this._produceBlockMutex.isLocked()) {\n this.logger?.log('Skipping block production, previous production still in progress')\n return\n }\n\n // eslint-disable-next-line complexity\n await this._produceBlockMutex.runExclusive(async () => {\n // Get the updated head\n const head = (await this.blockViewer.currentBlock())[0]\n // Check if we've already produced the next block for this head\n const headHash = head._hash\n\n // Track head changes\n const currentTime = Date.now()\n if (this._lastHeadHash !== headHash) {\n // Log the head change\n const lastHeadHashHex = isDefined(this._lastHeadHash) ? `0x${this._lastHeadHash}` : 'undefined'\n const currentHeadHashHex = `0x${headHash}`\n this.logger?.log(`Found updated head ${lastHeadHashHex} -> ${currentHeadHashHex}`)\n\n // Update the head change info\n this._lastHeadHash = headHash\n this._lastHeadChangeTime = currentTime\n }\n\n // Check if we should resubmit due to stale head\n const timeSinceHeadChange = isDefined(this._lastHeadChangeTime) ? currentTime - this._lastHeadChangeTime : 0\n\n // If we have never produced a block or the last produced block was not built on the current head we\n // need to attempt to produce a new block\n const shouldSubmit = !this._lastProducedBlock || this._lastProducedBlock[0].previous !== headHash\n\n // If the head has not changed determine if we should resubmit again based on head staleness\n const shouldResubmit = timeSinceHeadChange > ProducerActor.HeadResubmissionThreshold\n\n // Determine if we should submit or resubmit\n const shouldSubmitBlock = shouldSubmit || shouldResubmit\n\n if (shouldSubmitBlock) {\n // If we are resubmitting due to stale head\n if (shouldResubmit) {\n // Log that we are resubmitting due to stale head\n this.logger?.log(`Resubmitting block due to stale head. Head ${toFormattedBlockReference(head)} unchanged for ${timeSinceHeadChange}ms`)\n // Reset timer since we're resubmitting\n this._lastHeadChangeTime = currentTime\n }\n this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes)\n // Produce the next block\n const nextBlock = await this.blockRunner.next(head)\n // If it was produced\n if (nextBlock) {\n const displayBlockNumber = toFormattedBlockReference(nextBlock[0])\n this.logger?.log('Produced block:', displayBlockNumber)\n this._producerActorBlocksProduced?.add(1, this._metricAttributes)\n // Insert the block into the chain\n await this.mempoolRunner.submitBlocks([nextBlock])\n this.logger?.log('Published block:', displayBlockNumber)\n this._producerActorBlocksPublished?.add(1, this._metricAttributes)\n // Record that we have produced a block so we do not produce it again\n this._lastProducedBlock = nextBlock\n } else {\n this.logger?.log('No block produced for submission.')\n }\n } else {\n // Log that we are not submitting a block at this time\n let nonSubmissionMessage = 'No block submission required at this time'\n // If we have already produced a block\n if (isDefined(this._lastProducedBlock)) {\n // include that info in the log\n nonSubmissionMessage = nonSubmissionMessage + `, already produced: ${toFormattedBlockReference(this._lastProducedBlock[0])}`\n }\n this.logger?.log(`${nonSubmissionMessage}.`)\n }\n })\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async redeclareIntent(): Promise<void> {\n await this.spanAsync('redeclareIntent', async () => {\n // Decide if we should redeclare intent\n if (this.config.producer.disableIntentRedeclaration) return\n\n // Get the current block\n const head = (await this.blockViewer.currentBlock())[0]\n if (isUndefined(head)) return\n const currentBlock = head.block\n\n // // Calculate the time until the producer's declaration expires\n const blocksUntilExpiration = this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)\n\n // Allow the producer time to redeclare itself via block production\n // (for free) before submitting a redeclaration intent transaction.\n if (blocksUntilExpiration > ProducerActor.RedeclarationWindow * 0.1) {\n // Clear any previous redeclaration intent\n this._lastRedeclarationIntent = undefined\n // No need to redeclare yet\n return\n }\n\n // If we already have a valid redeclaration intent, do not create another\n // unless it has expired.\n if (this._lastRedeclarationIntent) {\n // Check if the last redeclaration intent is still valid\n if (this._lastRedeclarationIntent.exp > currentBlock) return\n // If it has expired, clear the last redeclaration intent\n this._lastRedeclarationIntent = undefined\n }\n\n // Check if we have a valid balance before declaring intent\n if (!await this.validateCurrentBalance()) {\n this.logger?.error(\n `Add balance to address ${this.account.address} for the producer to declare it's intent.`,\n )\n return\n }\n\n // Check if we have a valid stake before declaring intent\n if (!(await this.validateCurrentStake())) {\n this.logger?.error(\n `Add stake to contract address ${this.config.chain.id}`\n + ' for the producer to declare it\\'s intent.',\n )\n return\n }\n\n // Create a redeclaration intent\n this.logger?.log('Creating redeclaration intent for producer:', this.account.address)\n const redeclarationIntent = createDeclarationIntent(\n this.account.address,\n 'producer',\n currentBlock,\n currentBlock + SimpleBlockRunner.RedeclarationDuration,\n )\n\n // Submit the redeclaration intent\n await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)\n\n // On successful submission, save the redeclaration intent\n this._lastRedeclarationIntent = redeclarationIntent\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async submitRedeclarationIntent(currentBlock: XL1BlockNumber, redeclarationIntent: ChainStakeIntent): Promise<void> {\n this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)\n // Create a transaction to submit the redeclaration intent\n const tx = await buildTransaction(\n this.chainId,\n [redeclarationIntent],\n [],\n this.account,\n currentBlock,\n asXL1BlockNumber(currentBlock + 1000, true),\n )\n\n // Submit the redeclaration intent\n await this.mempoolRunner.submitTransactions([tx])\n\n this.logger?.log('Submitted redeclaration intent for producer:', this.account.address)\n }\n\n protected async validateCurrentBalance(): Promise<boolean> {\n // Check if we have a valid balance before declaring intent\n const head = (await this.blockViewer.currentBlock())?.[0]?._hash\n if (isDefined(head)) {\n const balances = await this.accountBalanceViewer.accountBalances([this.account.address], { head })\n const currentBalance = balances[this.account.address] ?? 0n\n if (currentBalance <= 0n) {\n this.logger?.error(`Producer ${this.account.address} has no balance.`)\n return false\n }\n return true\n }\n return true\n }\n\n protected async validateCurrentStake(): Promise<boolean> {\n // Use StakeIntentService to get the required minimum stake\n const requiredMinimumStake = 1n // this.stakeIntentService.getRequiredMinimumStakeForIntent('producer')\n // Check if we have a valid stake before declaring intent\n const currentStake = await this.stakeTotalsViewer.activeByStaked(this.account.address)\n if (currentStake < requiredMinimumStake) {\n this.logger?.error(`Producer ${this.account.address} has insufficient stake.`)\n return false\n }\n return true\n }\n}\n","import type { CreatableName } from '@xylabs/sdk-js'\nimport {\n asAddress, exists, IdLogger,\n} from '@xylabs/sdk-js'\nimport { initProducerAccount, type OrchestratorInstance } from '@xyo-network/chain-orchestration'\nimport { type BaseContext, type Config } from '@xyo-network/xl1-sdk'\n\nimport type { ProducerActorParams } from './ProducerActor.ts'\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport interface RunProducerContext extends BaseContext {\n config: Config\n orchestrator: OrchestratorInstance\n}\n\nexport const runProducer = async ({\n config, logger = console, orchestrator,\n}: RunProducerContext) => {\n const localLogger = logger ?? new IdLogger(logger ?? console, () => 'ResolveHelper [runProducer]')\n const account = await initProducerAccount({ config })\n localLogger.info(`Running producer for account ${account.address}`)\n const rewardAddress = asAddress(config.producer.rewardAddress, () => 'rewardAddress is required in config.producer')\n localLogger.info(`Using reward address ${rewardAddress}`)\n\n // Create actors\n const producer = await ProducerActor.create({\n account, config, logger, rewardAddress, name: 'xl1-producer' as CreatableName,\n } satisfies ProducerActorParams)\n const actors = [producer].filter(exists)\n\n for (const actor of actors) {\n // Register the actor with the orchestrator\n await orchestrator.registerActor(actor)\n }\n // Start the orchestrator => automatically activates the actor\n await orchestrator.start()\n}\n"],"mappings":";;;;AAEA,SACEA,UAAUC,WAAWC,WAAWC,aAChCC,aACK;AACP,SAASC,sBAAsBC,mCAAmC;AAClE,SAASC,yBAAyB;AAClC,SAASC,qBAAqB;AAC9B,SAASC,wBAAwB;AACjC,SAASC,uBAAuBC,kCAAkC;AAKlE,SACwBC,6B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,KAAKvG,kBAAkBwG,eAAe,KAAKrG,QAAQC,OAAO;AACrF,QAAImG,eAAeD,sBAAsB;AACvC,WAAKhH,QAAQiG,MAAM,YAAY,KAAKpF,QAAQC,OAAO,0BAA0B;AAC7E,aAAO;IACT;AACA,WAAO;EACT;AACF;;;;;;ACvZA,SACEqG,WAAWC,QAAQC,gBACd;AACP,SAASC,2BAAsD;AAWxD,IAAMC,cAAc,8BAAO,EAChCC,QAAQC,SAASC,SAASC,aAAY,MACnB;AACnB,QAAMC,cAAcH,UAAU,IAAII,SAASJ,UAAUC,SAAS,MAAM,6BAAA;AACpE,QAAMI,UAAU,MAAMC,oBAAoB;IAAEP;EAAO,CAAA;AACnDI,cAAYI,KAAK,gCAAgCF,QAAQG,OAAO,EAAE;AAClE,QAAMC,gBAAgBC,UAAUX,OAAOY,SAASF,eAAe,MAAM,8CAAA;AACrEN,cAAYI,KAAK,wBAAwBE,aAAAA,EAAe;AAGxD,QAAME,WAAW,MAAMC,cAAcC,OAAO;IAC1CR;IAASN;IAAQC;IAAQS;IAAeK,MAAM;EAChD,CAAA;AACA,QAAMC,SAAS;IAACJ;IAAUK,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMb,aAAaiB,cAAcD,KAAAA;EACnC;AAEA,QAAMhB,aAAakB,MAAK;AAC1B,GArB2B;","names":["assertEx","creatable","isDefined","isUndefined","toHex","buildTelemetryConfig","initEvmProvidersIfAvailable","SimpleBlockRunner","initTelemetry","startupSpanAsync","validateHydratedBlock","validateHydratedBlockState","AccountBalanceViewerMoniker","ActorV2","asXL1BlockNumber","BlockRunnerMoniker","BlockViewerMoniker","buildJsonRpcProviderLocatorV2","buildTransaction","createDeclarationIntent","DefaultMetricsScrapePorts","HttpRpcTransport","MempoolRunnerMoniker","MempoolViewerMoniker","SimpleBlockRewardViewer","SimpleBlockValidationViewer","StakeTotalsViewerMoniker","Mutex","SHOULD_REGISTER_REDECLARATION_INTENT_TIMER","TEN_MINUTES","toFormattedBlockReference","blockBoundWitness","block","toHex","_hash","prefix","ProducerActor","ActorV2","BlockSubmissionCheckInterval","HeadResubmissionThreshold","RedeclarationWindow","_lastProducedBlock","_lastRedeclarationIntent","_metricAttributes","_producerActorBlockProductionAttempts","_producerActorBlockProductionChecks","_producerActorBlocksProduced","_producerActorBlocksPublished","_accountBalanceViewer","_blockRunner","_blockViewer","_chainId","_lastHeadChangeTime","_lastHeadHash","_mempoolRunner","_mempoolViewer","_produceBlockMutex","Mutex","_stakeTotalsViewer","logger","assertEx","accountBalanceViewer","blockRunner","blockViewer","chainId","mempoolRunner","mempoolViewer","rewardAddress","params","stakeTotalsViewer","paramsHandler","superParams","account","address","info","warn","createHandler","toString","meter","createCounter","description","locator","getInstance","AccountBalanceViewerMoniker","BlockRunnerMoniker","BlockViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","initLocator","config","endpoint","services","apiEndpoint","transportFactory","schemas","HttpRpcTransport","buildJsonRpcProviderLocatorV2","version","telemetryConfig","buildTelemetryConfig","name","DefaultMetricsScrapePorts","producer","traceProvider","meterProvider","startupSpanAsync","initTelemetry","context","register","SimpleBlockRewardViewer","factory","dependencies","SimpleBlockValidationViewer","state","validateHydratedBlockState","protocol","validateHydratedBlock","SimpleBlockRunner","initEvmProvidersIfAvailable","startHandler","registerTimer","produceBlock","redeclareIntent","calculateBlocksUntilProducerDeclarationExpiration","currentBlock","exp","add","spanAsync","isLocked","log","runExclusive","head","headHash","currentTime","Date","now","lastHeadHashHex","isDefined","currentHeadHashHex","timeSinceHeadChange","shouldSubmit","previous","shouldResubmit","shouldSubmitBlock","nextBlock","next","displayBlockNumber","submitBlocks","nonSubmissionMessage","timeBudgetLimit","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","chain","id","redeclarationIntent","createDeclarationIntent","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","asAddress","exists","IdLogger","initProducerAccount","runProducer","config","logger","console","orchestrator","localLogger","IdLogger","account","initProducerAccount","info","address","rewardAddress","asAddress","producer","ProducerActor","create","name","actors","filter","exists","actor","registerActor","start"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ProducerActor.ts","../../src/runProducer.ts"],"sourcesContent":["import type { Attributes, Counter } from '@opentelemetry/api'\nimport {\n assertEx, creatable, isDefined, isUndefined,\n toHex,\n} from '@xylabs/sdk-js'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport type {\n ActorParamsV3,\n BlockBoundWitnessWithHashMeta, ChainContractViewer, ChainId, ChainStakeIntent, Config, HydratedBlockWithHashMeta, XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewer, AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunner, BlockRunnerMoniker, BlockViewer, BlockViewerMoniker,\n buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewer, FinalizationViewerMoniker, MempoolRunner, MempoolRunnerMoniker,\n MempoolViewer, MempoolViewerMoniker, StakeTotalsViewer, StakeTotalsViewerMoniker,\n} from '@xyo-network/xl1-sdk'\nimport { Mutex } from 'async-mutex'\n\nexport type ProducerActorParams = ActorParamsV3<{\n config: Config\n}>\n\nconst SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true\nconst TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds\n\n/**\n * Formats a hydrated block with hash meta into a string representation of its hash and block number.\n * @param blockBoundWitness The hydrated block with hash meta to format\n * @returns The formatted block reference string\n */\nconst toFormattedBlockReference = (blockBoundWitness: BlockBoundWitnessWithHashMeta): string => {\n return `${blockBoundWitness.block} [${toHex(blockBoundWitness._hash, { prefix: true })}]`\n}\n\n@creatable()\nexport class ProducerActor extends ActorV3<ProducerActorParams> {\n /**\n * The interval time (in MS) between block production attempts.\n */\n static readonly BlockSubmissionCheckInterval = 1500 // 1.5 seconds\n\n /**\n * The threshold time (in MS) for resubmitting the same block number if the head has not changed.\n */\n static readonly HeadResubmissionThreshold = ProducerActor.BlockSubmissionCheckInterval * 30\n\n /**\n * The window (in blocks) before expiration to attempt redeclaration of producer intent.\n */\n static readonly RedeclarationWindow = 10_000\n\n protected _lastProducedBlock?: HydratedBlockWithHashMeta\n protected _lastRedeclarationIntent?: ChainStakeIntent\n protected _metricAttributes?: Attributes\n protected _producerActorBlockProductionAttempts?: Counter<Attributes>\n protected _producerActorBlockProductionChecks?: Counter<Attributes>\n protected _producerActorBlocksProduced?: Counter<Attributes>\n protected _producerActorBlocksPublished?: Counter<Attributes>\n\n private _accountBalanceViewer?: AccountBalanceViewer\n private _blockRunner?: BlockRunner\n private _blockViewer?: BlockViewer\n private _chainContractViewer?: ChainContractViewer\n private _chainId?: ChainId\n private _lastHeadChangeTime?: number\n private _lastHeadHash?: string\n private _mempoolRunner?: MempoolRunner\n private _mempoolViewer?: MempoolViewer\n private _produceBlockMutex = new Mutex()\n private _stakeTotalsViewer?: StakeTotalsViewer\n\n override get logger() {\n return assertEx(super.logger, () => 'Logger is required for ProducerActor')\n }\n\n protected get accountBalanceViewer() {\n return this._accountBalanceViewer!\n }\n\n protected get blockRunner() {\n return this._blockRunner!\n }\n\n protected get blockViewer() {\n return this._blockViewer!\n }\n\n protected get chainContractViewer() {\n return this._chainContractViewer!\n }\n\n protected get chainId() {\n return this._chainId!\n }\n\n protected get config() {\n return this.params.config\n }\n\n protected get mempoolRunner() {\n return this._mempoolRunner!\n }\n\n protected get mempoolViewer() {\n return this._mempoolViewer!\n }\n\n protected get stakeTotalsViewer() {\n return this._stakeTotalsViewer!\n }\n\n override async createHandler() {\n await super.createHandler()\n // Create the consistent meter attributes that will\n // be included with all metrics from this actor\n this._metricAttributes = { address: this.account.address.toString() }\n // Create the metrics\n this._producerActorBlockProductionChecks = this.meter?.createCounter(\n 'producer_actor_block_production_checks',\n { description: 'Number of block production checks' },\n )\n this._producerActorBlockProductionAttempts = this.meter?.createCounter(\n 'producer_actor_block_production_attempts',\n { description: 'Number of block production attempts' },\n )\n this._producerActorBlocksProduced = this.meter?.createCounter(\n 'producer_actor_blocks_produced',\n { description: 'Number of blocks produced' },\n )\n this._producerActorBlocksPublished = this.meter?.createCounter(\n 'producer_actor_blocks_published',\n { description: 'Number of blocks published' },\n )\n const final = await this.locator?.getInstance<FinalizationViewer>(FinalizationViewerMoniker)\n await final.start()\n this._accountBalanceViewer = assertEx(\n await this.locator?.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker),\n () => 'Unable to locate AccountBalanceViewer',\n )\n this._blockRunner = assertEx(\n await this.locator?.getInstance<BlockRunner>(BlockRunnerMoniker),\n () => 'Unable to locate BlockRunner',\n )\n this._blockViewer = assertEx(\n await this.locator?.getInstance<BlockViewer>(BlockViewerMoniker),\n () => 'Unable to locate BlockViewer',\n )\n this._chainContractViewer = assertEx(\n await this.locator?.getInstance<ChainContractViewer>(ChainContractViewerMoniker),\n () => 'Unable to locate ChainContractViewer',\n )\n this._mempoolRunner = assertEx(\n await this.locator?.getInstance<MempoolRunner>(MempoolRunnerMoniker),\n () => 'Unable to locate MempoolRunner',\n )\n this._mempoolViewer = assertEx(\n await this.locator?.getInstance<MempoolViewer>(MempoolViewerMoniker),\n () => 'Unable to locate MempoolViewer',\n )\n this._stakeTotalsViewer = assertEx(\n await this.locator?.getInstance<StakeTotalsViewer>(StakeTotalsViewerMoniker),\n () => 'Unable to locate StakeTotalsViewer',\n )\n this._chainId = await this.chainContractViewer.chainId()\n }\n\n // async initLocator() {\n // const config = this.config\n // const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')\n // const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)\n // const locator = await buildJsonRpcProviderLocatorV2(config, transportFactory)\n\n // const version = '1.0.0'\n // const telemetryConfig = buildTelemetryConfig(config, this.name, version, DefaultMetricsScrapePorts.producer)\n // const { traceProvider, meterProvider } = await startupSpanAsync('initTelemetry', () => initTelemetry(telemetryConfig))\n\n // locator.context.traceProvider = traceProvider\n // locator.context.meterProvider = meterProvider\n\n // locator.register(SimpleBlockRewardViewer.factory<SimpleBlockRewardViewer>(SimpleBlockRewardViewer.dependencies, {}))\n // locator.register(SimpleBlockValidationViewer.factory<SimpleBlockValidationViewer>(\n // SimpleBlockValidationViewer.dependencies,\n // { state: validateHydratedBlockState, protocol: validateHydratedBlock },\n // ))\n // locator.register(SimpleBlockRunner.factory<SimpleBlockRunner>(\n // SimpleBlockRunner.dependencies,\n // { account: this.params.account, rewardAddress: this.params.rewardAddress },\n // ))\n // return await initEvmProvidersIfAvailable(locator)\n // }\n\n override async startHandler() {\n await super.startHandler()\n // Register a timer to check if we should produce a block\n this.registerTimer('BlockProductionTimer', async () => {\n await this.produceBlock()\n }, 2000, ProducerActor.BlockSubmissionCheckInterval)\n\n if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {\n // Register a timer to check if we should redeclare the producer\n this.registerTimer('ProducerRedeclarationTimer', async () => {\n await this.redeclareIntent()\n }, TEN_MINUTES, TEN_MINUTES)\n }\n }\n\n protected calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): number {\n return (this._lastRedeclarationIntent?.exp ?? currentBlock) - currentBlock\n }\n\n protected async produceBlock(): Promise<void> {\n this._producerActorBlockProductionChecks?.add(1, this._metricAttributes)\n await this.spanAsync('produceBlock', async () => {\n if (this._produceBlockMutex.isLocked()) {\n this.logger?.log('Skipping block production, previous production still in progress')\n return\n }\n\n // eslint-disable-next-line complexity\n await this._produceBlockMutex.runExclusive(async () => {\n // Get the updated head\n const head = (await this.blockViewer.currentBlock())[0]\n // Check if we've already produced the next block for this head\n const headHash = head._hash\n\n // Track head changes\n const currentTime = Date.now()\n if (this._lastHeadHash !== headHash) {\n // Log the head change\n const lastHeadHashHex = isDefined(this._lastHeadHash) ? `0x${this._lastHeadHash}` : 'undefined'\n const currentHeadHashHex = `0x${headHash}`\n this.logger?.log(`Found updated head ${lastHeadHashHex} -> ${currentHeadHashHex}`)\n\n // Update the head change info\n this._lastHeadHash = headHash\n this._lastHeadChangeTime = currentTime\n }\n\n // Check if we should resubmit due to stale head\n const timeSinceHeadChange = isDefined(this._lastHeadChangeTime) ? currentTime - this._lastHeadChangeTime : 0\n\n // If we have never produced a block or the last produced block was not built on the current head we\n // need to attempt to produce a new block\n const shouldSubmit = !this._lastProducedBlock || this._lastProducedBlock[0].previous !== headHash\n\n // If the head has not changed determine if we should resubmit again based on head staleness\n const shouldResubmit = timeSinceHeadChange > ProducerActor.HeadResubmissionThreshold\n\n // Determine if we should submit or resubmit\n const shouldSubmitBlock = shouldSubmit || shouldResubmit\n\n if (shouldSubmitBlock) {\n // If we are resubmitting due to stale head\n if (shouldResubmit) {\n // Log that we are resubmitting due to stale head\n this.logger?.log(`Resubmitting block due to stale head. Head ${toFormattedBlockReference(head)} unchanged for ${timeSinceHeadChange}ms`)\n // Reset timer since we're resubmitting\n this._lastHeadChangeTime = currentTime\n }\n this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes)\n // Produce the next block\n const nextBlock = await this.blockRunner.next(head)\n // If it was produced\n if (nextBlock) {\n const displayBlockNumber = toFormattedBlockReference(nextBlock[0])\n this.logger?.log('Produced block:', displayBlockNumber)\n this._producerActorBlocksProduced?.add(1, this._metricAttributes)\n // Insert the block into the chain\n await this.mempoolRunner.submitBlocks([nextBlock])\n this.logger?.log('Published block:', displayBlockNumber)\n this._producerActorBlocksPublished?.add(1, this._metricAttributes)\n // Record that we have produced a block so we do not produce it again\n this._lastProducedBlock = nextBlock\n } else {\n this.logger?.log('No block produced for submission.')\n }\n } else {\n // Log that we are not submitting a block at this time\n let nonSubmissionMessage = 'No block submission required at this time'\n // If we have already produced a block\n if (isDefined(this._lastProducedBlock)) {\n // include that info in the log\n nonSubmissionMessage = nonSubmissionMessage + `, already produced: ${toFormattedBlockReference(this._lastProducedBlock[0])}`\n }\n this.logger?.log(`${nonSubmissionMessage}.`)\n }\n })\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async redeclareIntent(): Promise<void> {\n await this.spanAsync('redeclareIntent', async () => {\n // Decide if we should redeclare intent\n if (this.config.actors.producer.disableIntentRedeclaration) return\n\n // Get the current block\n const head = (await this.blockViewer.currentBlock())[0]\n if (isUndefined(head)) return\n const currentBlock = head.block\n\n // // Calculate the time until the producer's declaration expires\n const blocksUntilExpiration = this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)\n\n // Allow the producer time to redeclare itself via block production\n // (for free) before submitting a redeclaration intent transaction.\n if (blocksUntilExpiration > ProducerActor.RedeclarationWindow * 0.1) {\n // Clear any previous redeclaration intent\n this._lastRedeclarationIntent = undefined\n // No need to redeclare yet\n return\n }\n\n // If we already have a valid redeclaration intent, do not create another\n // unless it has expired.\n if (this._lastRedeclarationIntent) {\n // Check if the last redeclaration intent is still valid\n if (this._lastRedeclarationIntent.exp > currentBlock) return\n // If it has expired, clear the last redeclaration intent\n this._lastRedeclarationIntent = undefined\n }\n\n // Check if we have a valid balance before declaring intent\n if (!await this.validateCurrentBalance()) {\n this.logger?.error(\n `Add balance to address ${this.account.address} for the producer to declare it's intent.`,\n )\n return\n }\n\n // Check if we have a valid stake before declaring intent\n if (!(await this.validateCurrentStake())) {\n this.logger?.error(\n `Add stake to contract address ${this.chainId}`\n + ' for the producer to declare it\\'s intent.',\n )\n return\n }\n\n // Create a redeclaration intent\n this.logger?.log('Creating redeclaration intent for producer:', this.account.address)\n const redeclarationIntent = createDeclarationIntent(\n this.account.address,\n 'producer',\n currentBlock,\n currentBlock + SimpleBlockRunner.RedeclarationDuration,\n )\n\n // Submit the redeclaration intent\n await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)\n\n // On successful submission, save the redeclaration intent\n this._lastRedeclarationIntent = redeclarationIntent\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async submitRedeclarationIntent(currentBlock: XL1BlockNumber, redeclarationIntent: ChainStakeIntent): Promise<void> {\n this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)\n // Create a transaction to submit the redeclaration intent\n const tx = await buildTransaction(\n this.chainId,\n [redeclarationIntent],\n [],\n this.account,\n currentBlock,\n asXL1BlockNumber(currentBlock + 1000, true),\n )\n\n // Submit the redeclaration intent\n await this.mempoolRunner.submitTransactions([tx])\n\n this.logger?.log('Submitted redeclaration intent for producer:', this.account.address)\n }\n\n protected async validateCurrentBalance(): Promise<boolean> {\n // Check if we have a valid balance before declaring intent\n const head = (await this.blockViewer.currentBlock())?.[0]?._hash\n if (isDefined(head)) {\n const balances = await this.accountBalanceViewer.accountBalances([this.account.address], { head })\n const currentBalance = balances[this.account.address] ?? 0n\n if (currentBalance <= 0n) {\n this.logger?.error(`Producer ${this.account.address} has no balance.`)\n return false\n }\n return true\n }\n return true\n }\n\n protected async validateCurrentStake(): Promise<boolean> {\n // Use StakeIntentService to get the required minimum stake\n const requiredMinimumStake = 1n // this.stakeIntentService.getRequiredMinimumStakeForIntent('producer')\n // Check if we have a valid stake before declaring intent\n const currentStake = await this.stakeTotalsViewer.activeByStaked(this.account.address)\n if (currentStake < requiredMinimumStake) {\n this.logger?.error(`Producer ${this.account.address} has insufficient stake.`)\n return false\n }\n return true\n }\n}\n","import type { CreatableName } from '@xylabs/sdk-js'\nimport { exists } from '@xylabs/sdk-js'\nimport { initProducerAccount, type OrchestratorInstance } from '@xyo-network/chain-orchestration'\nimport type {\n Config,\n ProviderFactoryLocatorInstance,\n} from '@xyo-network/xl1-sdk'\n\nimport type { ProducerActorParams } from './ProducerActor.ts'\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport const runProducer = async (\n config: Config,\n orchestrator: OrchestratorInstance,\n locator: ProviderFactoryLocatorInstance,\n) => {\n const account = await initProducerAccount({ config, logger: locator.context.logger })\n // Create actors\n const producer = await ProducerActor.create({\n config, locator, name: 'xl1-producer' as CreatableName, account,\n } satisfies ProducerActorParams)\n const actors = [producer].filter(exists)\n\n for (const actor of actors) {\n // Register the actor with the orchestrator\n await orchestrator.registerActor(actor)\n }\n // Start the orchestrator => automatically activates the actor\n await orchestrator.start()\n}\n"],"mappings":";;;;AACA,SACEA,UAAUC,WAAWC,WAAWC,aAChCC,aACK;AACP,SAASC,yBAAyB;AAKlC,SACwBC,6BAA6BC,SAASC,kBAA+BC,oBAAiCC,oBAC5HC,kBAAkBC,4BAA4BC,yBAA6CC,2BAA0CC,sBACtHC,sBAAyCC,gCACnD;AACP,SAASC,aAAa;;;;;;;;AAMtB,IAAMC,6CAA6C;AACnD,IAAMC,cAAc,KAAK,KAAK;AAO9B,IAAMC,4BAA4B,wBAACC,sBAAAA;AACjC,SAAO,GAAGA,kBAAkBC,KAAK,KAAKC,MAAMF,kBAAkBG,OAAO;IAAEC,QAAQ;EAAK,CAAA,CAAA;AACtF,GAFkC;AAK3B,IAAMC,gBAAN,MAAMA,uBAAsBC,QAAAA;SAAAA;;;;;;EAIjC,OAAgBC,+BAA+B;;;;EAK/C,OAAgBC,4BAA4BH,eAAcE,+BAA+B;;;;EAKzF,OAAgBE,sBAAsB;EAE5BC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEFC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC,qBAAqB,IAAIC,MAAAA;EACzBC;EAER,IAAaC,SAAS;AACpB,WAAOC,SAAS,MAAMD,QAAQ,MAAM,sCAAA;EACtC;EAEA,IAAcE,uBAAuB;AACnC,WAAO,KAAKd;EACd;EAEA,IAAce,cAAc;AAC1B,WAAO,KAAKd;EACd;EAEA,IAAce,cAAc;AAC1B,WAAO,KAAKd;EACd;EAEA,IAAce,sBAAsB;AAClC,WAAO,KAAKd;EACd;EAEA,IAAce,UAAU;AACtB,WAAO,KAAKd;EACd;EAEA,IAAce,SAAS;AACrB,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAcE,gBAAgB;AAC5B,WAAO,KAAKd;EACd;EAEA,IA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UAAM1B,QAAQ,MAAM,KAAKvC,YAAYgC,aAAY,KAAM,CAAA,GAAI9D;AAC3D,QAAI2E,UAAUN,IAAAA,GAAO;AACnB,YAAMsC,WAAW,MAAM,KAAK/E,qBAAqBgF,gBAAgB;QAAC,KAAKpE,QAAQD;SAAU;QAAE8B;MAAK,CAAA;AAChG,YAAMwC,iBAAiBF,SAAS,KAAKnE,QAAQD,OAAO,KAAK;AACzD,UAAIsE,kBAAkB,IAAI;AACxB,aAAKnF,QAAQsE,MAAM,YAAY,KAAKxD,QAAQD,OAAO,kBAAkB;AACrE,eAAO;MACT;AACA,aAAO;IACT;AACA,WAAO;EACT;EAEA,MAAgB0D,uBAAyC;AAEvD,UAAMa,uBAAuB;AAE7B,UAAMC,eAAe,MAAM,KAAK1E,kBAAkB2E,eAAe,KAAKxE,QAAQD,OAAO;AACrF,QAAIwE,eAAeD,sBAAsB;AACvC,WAAKpF,QAAQsE,MAAM,YAAY,KAAKxD,QAAQD,OAAO,0BAA0B;AAC7E,aAAO;IACT;AACA,WAAO;EACT;AACF;;;;;;AC7YA,SAAS0E,cAAc;AACvB,SAASC,2BAAsD;AASxD,IAAMC,cAAc,8BACzBC,QACAC,cACAC,YAAAA;AAEA,QAAMC,UAAU,MAAMC,oBAAoB;IAAEJ;IAAQK,QAAQH,QAAQI,QAAQD;EAAO,CAAA;AAEnF,QAAME,WAAW,MAAMC,cAAcC,OAAO;IAC1CT;IAAQE;IAASQ,MAAM;IAAiCP;EAC1D,CAAA;AACA,QAAMQ,SAAS;IAACJ;IAAUK,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMV,aAAac,cAAcD,KAAAA;EACnC;AAEA,QAAMb,aAAae,MAAK;AAC1B,GAlB2B;","names":["assertEx","creatable","isDefined","isUndefined","toHex","SimpleBlockRunner","AccountBalanceViewerMoniker","ActorV3","asXL1BlockNumber","BlockRunnerMoniker","BlockViewerMoniker","buildTransaction","ChainContractViewerMoniker","createDeclarationIntent","FinalizationViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","Mutex","SHOULD_REGISTER_REDECLARATION_INTENT_TIMER","TEN_MINUTES","toFormattedBlockReference","blockBoundWitness","block","toHex","_hash","prefix","ProducerActor","ActorV3","BlockSubmissionCheckInterval","HeadResubmissionThreshold","RedeclarationWindow","_lastProducedBlock","_lastRedeclarationIntent","_metricAttributes","_producerActorBlockProductionAttempts","_producerActorBlockProductionChecks","_producerActorBlocksProduced","_producerActorBlocksPublished","_accountBalanceViewer","_blockRunner","_blockViewer","_chainContractViewer","_chainId","_lastHeadChangeTime","_lastHeadHash","_mempoolRunner","_mempoolViewer","_produceBlockMutex","Mutex","_stakeTotalsViewer","logger","assertEx","accountBalanceViewer","blockRunner","blockViewer","chainContractViewer","chainId","config","params","mempoolRunner","mempoolViewer","stakeTotalsViewer","createHandler","address","account","toString","meter","createCounter","description","final","locator","getInstance","FinalizationViewerMoniker","start","AccountBalanceViewerMoniker","BlockRunnerMoniker","BlockViewerMoniker","ChainContractViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","startHandler","registerTimer","produceBlock","redeclareIntent","calculateBlocksUntilProducerDeclarationExpiration","currentBlock","exp","add","spanAsync","isLocked","log","runExclusive","head","headHash","currentTime","Date","now","lastHeadHashHex","isDefined","currentHeadHashHex","timeSinceHeadChange","shouldSubmit","previous","shouldResubmit","shouldSubmitBlock","nextBlock","next","displayBlockNumber","submitBlocks","nonSubmissionMessage","context","timeBudgetLimit","actors","producer","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","redeclarationIntent","createDeclarationIntent","SimpleBlockRunner","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","exists","initProducerAccount","runProducer","config","orchestrator","locator","account","initProducerAccount","logger","context","producer","ProducerActor","create","name","actors","filter","exists","actor","registerActor","start"]}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { type OrchestratorInstance } from '@xyo-network/chain-orchestration';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
config: Config;
|
|
5
|
-
orchestrator: OrchestratorInstance;
|
|
6
|
-
}
|
|
7
|
-
export declare const runProducer: ({ config, logger, orchestrator, }: RunProducerContext) => Promise<void>;
|
|
2
|
+
import type { Config, ProviderFactoryLocatorInstance } from '@xyo-network/xl1-sdk';
|
|
3
|
+
export declare const runProducer: (config: Config, orchestrator: OrchestratorInstance, locator: ProviderFactoryLocatorInstance) => Promise<void>;
|
|
8
4
|
//# sourceMappingURL=runProducer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runProducer.d.ts","sourceRoot":"","sources":["../../src/runProducer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runProducer.d.ts","sourceRoot":"","sources":["../../src/runProducer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AACjG,OAAO,KAAK,EACV,MAAM,EACN,8BAA8B,EAC/B,MAAM,sBAAsB,CAAA;AAK7B,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,cAAc,oBAAoB,EAClC,SAAS,8BAA8B,kBAexC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/chain-producer",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.9",
|
|
4
4
|
"description": "XYO Layer One Producer",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -49,13 +49,10 @@
|
|
|
49
49
|
"types": "tsc --noEmit -p tsconfig.test.json"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@xylabs/sdk-js": "~5.0.
|
|
53
|
-
"@xyo-network/chain-orchestration": "~1.19.
|
|
54
|
-
"@xyo-network/chain-services": "~1.19.
|
|
55
|
-
"@xyo-network/
|
|
56
|
-
"@xyo-network/chain-utils": "~1.19.7",
|
|
57
|
-
"@xyo-network/chain-validation": "~1.19.7",
|
|
58
|
-
"@xyo-network/xl1-sdk": "~1.22.30",
|
|
52
|
+
"@xylabs/sdk-js": "~5.0.79",
|
|
53
|
+
"@xyo-network/chain-orchestration": "~1.19.9",
|
|
54
|
+
"@xyo-network/chain-services": "~1.19.9",
|
|
55
|
+
"@xyo-network/xl1-sdk": "~1.23.14",
|
|
59
56
|
"async-mutex": "~0.5.0"
|
|
60
57
|
},
|
|
61
58
|
"devDependencies": {
|
|
@@ -64,8 +61,8 @@
|
|
|
64
61
|
"@types/cors": "~2.8.19",
|
|
65
62
|
"@types/express": "5.0.6",
|
|
66
63
|
"@types/express-serve-static-core": "~5.1.1",
|
|
67
|
-
"@types/node": "~25.2.
|
|
68
|
-
"@xylabs/sdk-js": "~5.0.
|
|
64
|
+
"@types/node": "~25.2.3",
|
|
65
|
+
"@xylabs/sdk-js": "~5.0.79",
|
|
69
66
|
"@xylabs/ts-scripts-yarn3": "~7.3.2",
|
|
70
67
|
"@xylabs/tsconfig": "~7.3.2",
|
|
71
68
|
"@xyo-network/account": "~5.3.2",
|
|
@@ -73,12 +70,12 @@
|
|
|
73
70
|
"@xyo-network/archivist-abstract": "~5.3.2",
|
|
74
71
|
"@xyo-network/bios-model": "~7.2.1",
|
|
75
72
|
"@xyo-network/boundwitness-builder": "~5.3.2",
|
|
76
|
-
"@xyo-network/chain-services": "~1.19.
|
|
77
|
-
"@xyo-network/chain-validation": "~1.19.
|
|
73
|
+
"@xyo-network/chain-services": "~1.19.9",
|
|
74
|
+
"@xyo-network/chain-validation": "~1.19.9",
|
|
78
75
|
"@xyo-network/module-abstract-mongodb": "~5.3.2",
|
|
79
76
|
"@xyo-network/module-model-mongodb": "~5.3.2",
|
|
80
77
|
"@xyo-network/node-memory": "~5.3.2",
|
|
81
|
-
"@xyo-network/xl1-sdk": "~1.
|
|
78
|
+
"@xyo-network/xl1-sdk": "~1.23.14",
|
|
82
79
|
"dotenv": "~17.2.4",
|
|
83
80
|
"eslint": "^9.39.2",
|
|
84
81
|
"nodemon": "~3.1.11",
|
package/src/ProducerActor.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import type { Attributes, Counter } from '@opentelemetry/api'
|
|
2
|
-
import type { Address, Logger } from '@xylabs/sdk-js'
|
|
3
2
|
import {
|
|
4
3
|
assertEx, creatable, isDefined, isUndefined,
|
|
5
4
|
toHex,
|
|
6
5
|
} from '@xylabs/sdk-js'
|
|
7
|
-
import { buildTelemetryConfig, initEvmProvidersIfAvailable } from '@xyo-network/chain-orchestration'
|
|
8
6
|
import { SimpleBlockRunner } from '@xyo-network/chain-services'
|
|
9
|
-
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
10
|
-
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
11
|
-
import { validateHydratedBlock, validateHydratedBlockState } from '@xyo-network/chain-validation'
|
|
12
7
|
import type {
|
|
13
|
-
|
|
14
|
-
BlockBoundWitnessWithHashMeta, ChainId, ChainStakeIntent, HydratedBlockWithHashMeta, XL1BlockNumber,
|
|
8
|
+
ActorParamsV3,
|
|
9
|
+
BlockBoundWitnessWithHashMeta, ChainContractViewer, ChainId, ChainStakeIntent, Config, HydratedBlockWithHashMeta, XL1BlockNumber,
|
|
15
10
|
} from '@xyo-network/xl1-sdk'
|
|
16
11
|
import {
|
|
17
|
-
AccountBalanceViewer, AccountBalanceViewerMoniker,
|
|
18
|
-
|
|
19
|
-
MempoolViewer, MempoolViewerMoniker,
|
|
20
|
-
TransportFactory,
|
|
12
|
+
AccountBalanceViewer, AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunner, BlockRunnerMoniker, BlockViewer, BlockViewerMoniker,
|
|
13
|
+
buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewer, FinalizationViewerMoniker, MempoolRunner, MempoolRunnerMoniker,
|
|
14
|
+
MempoolViewer, MempoolViewerMoniker, StakeTotalsViewer, StakeTotalsViewerMoniker,
|
|
21
15
|
} from '@xyo-network/xl1-sdk'
|
|
22
16
|
import { Mutex } from 'async-mutex'
|
|
23
17
|
|
|
24
|
-
export type ProducerActorParams =
|
|
25
|
-
|
|
26
|
-
rewardAddress: Address
|
|
18
|
+
export type ProducerActorParams = ActorParamsV3<{
|
|
19
|
+
config: Config
|
|
27
20
|
}>
|
|
28
21
|
|
|
29
22
|
const SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true
|
|
@@ -39,7 +32,7 @@ const toFormattedBlockReference = (blockBoundWitness: BlockBoundWitnessWithHashM
|
|
|
39
32
|
}
|
|
40
33
|
|
|
41
34
|
@creatable()
|
|
42
|
-
export class ProducerActor extends
|
|
35
|
+
export class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
43
36
|
/**
|
|
44
37
|
* The interval time (in MS) between block production attempts.
|
|
45
38
|
*/
|
|
@@ -66,6 +59,7 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
66
59
|
private _accountBalanceViewer?: AccountBalanceViewer
|
|
67
60
|
private _blockRunner?: BlockRunner
|
|
68
61
|
private _blockViewer?: BlockViewer
|
|
62
|
+
private _chainContractViewer?: ChainContractViewer
|
|
69
63
|
private _chainId?: ChainId
|
|
70
64
|
private _lastHeadChangeTime?: number
|
|
71
65
|
private _lastHeadHash?: string
|
|
@@ -90,10 +84,18 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
90
84
|
return this._blockViewer!
|
|
91
85
|
}
|
|
92
86
|
|
|
87
|
+
protected get chainContractViewer() {
|
|
88
|
+
return this._chainContractViewer!
|
|
89
|
+
}
|
|
90
|
+
|
|
93
91
|
protected get chainId() {
|
|
94
92
|
return this._chainId!
|
|
95
93
|
}
|
|
96
94
|
|
|
95
|
+
protected get config() {
|
|
96
|
+
return this.params.config
|
|
97
|
+
}
|
|
98
|
+
|
|
97
99
|
protected get mempoolRunner() {
|
|
98
100
|
return this._mempoolRunner!
|
|
99
101
|
}
|
|
@@ -102,29 +104,10 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
102
104
|
return this._mempoolViewer!
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
protected get rewardAddress() {
|
|
106
|
-
return this.params.rewardAddress!
|
|
107
|
-
}
|
|
108
|
-
|
|
109
107
|
protected get stakeTotalsViewer() {
|
|
110
108
|
return this._stakeTotalsViewer!
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
static override async paramsHandler<T extends ProducerActor>(params: Partial<T['params']>) {
|
|
114
|
-
const superParams = await super.paramsHandler(params)
|
|
115
|
-
const { logger, account } = superParams
|
|
116
|
-
const rewardAddress = params.rewardAddress ?? account.address
|
|
117
|
-
logger?.info(`Using reward address ${rewardAddress}`)
|
|
118
|
-
if (rewardAddress === account.address) {
|
|
119
|
-
logger?.warn(`Using producer account address as reward address: ${account.address}`)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
...superParams,
|
|
124
|
-
rewardAddress,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
111
|
override async createHandler() {
|
|
129
112
|
await super.createHandler()
|
|
130
113
|
// Create the consistent meter attributes that will
|
|
@@ -147,6 +130,8 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
147
130
|
'producer_actor_blocks_published',
|
|
148
131
|
{ description: 'Number of blocks published' },
|
|
149
132
|
)
|
|
133
|
+
const final = await this.locator?.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
|
|
134
|
+
await final.start()
|
|
150
135
|
this._accountBalanceViewer = assertEx(
|
|
151
136
|
await this.locator?.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker),
|
|
152
137
|
() => 'Unable to locate AccountBalanceViewer',
|
|
@@ -159,6 +144,10 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
159
144
|
await this.locator?.getInstance<BlockViewer>(BlockViewerMoniker),
|
|
160
145
|
() => 'Unable to locate BlockViewer',
|
|
161
146
|
)
|
|
147
|
+
this._chainContractViewer = assertEx(
|
|
148
|
+
await this.locator?.getInstance<ChainContractViewer>(ChainContractViewerMoniker),
|
|
149
|
+
() => 'Unable to locate ChainContractViewer',
|
|
150
|
+
)
|
|
162
151
|
this._mempoolRunner = assertEx(
|
|
163
152
|
await this.locator?.getInstance<MempoolRunner>(MempoolRunnerMoniker),
|
|
164
153
|
() => 'Unable to locate MempoolRunner',
|
|
@@ -171,32 +160,33 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
171
160
|
await this.locator?.getInstance<StakeTotalsViewer>(StakeTotalsViewerMoniker),
|
|
172
161
|
() => 'Unable to locate StakeTotalsViewer',
|
|
173
162
|
)
|
|
163
|
+
this._chainId = await this.chainContractViewer.chainId()
|
|
174
164
|
}
|
|
175
165
|
|
|
176
|
-
async initLocator() {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
166
|
+
// async initLocator() {
|
|
167
|
+
// const config = this.config
|
|
168
|
+
// const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')
|
|
169
|
+
// const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)
|
|
170
|
+
// const locator = await buildJsonRpcProviderLocatorV2(config, transportFactory)
|
|
171
|
+
|
|
172
|
+
// const version = '1.0.0'
|
|
173
|
+
// const telemetryConfig = buildTelemetryConfig(config, this.name, version, DefaultMetricsScrapePorts.producer)
|
|
174
|
+
// const { traceProvider, meterProvider } = await startupSpanAsync('initTelemetry', () => initTelemetry(telemetryConfig))
|
|
175
|
+
|
|
176
|
+
// locator.context.traceProvider = traceProvider
|
|
177
|
+
// locator.context.meterProvider = meterProvider
|
|
178
|
+
|
|
179
|
+
// locator.register(SimpleBlockRewardViewer.factory<SimpleBlockRewardViewer>(SimpleBlockRewardViewer.dependencies, {}))
|
|
180
|
+
// locator.register(SimpleBlockValidationViewer.factory<SimpleBlockValidationViewer>(
|
|
181
|
+
// SimpleBlockValidationViewer.dependencies,
|
|
182
|
+
// { state: validateHydratedBlockState, protocol: validateHydratedBlock },
|
|
183
|
+
// ))
|
|
184
|
+
// locator.register(SimpleBlockRunner.factory<SimpleBlockRunner>(
|
|
185
|
+
// SimpleBlockRunner.dependencies,
|
|
186
|
+
// { account: this.params.account, rewardAddress: this.params.rewardAddress },
|
|
187
|
+
// ))
|
|
188
|
+
// return await initEvmProvidersIfAvailable(locator)
|
|
189
|
+
// }
|
|
200
190
|
|
|
201
191
|
override async startHandler() {
|
|
202
192
|
await super.startHandler()
|
|
@@ -300,7 +290,7 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
300
290
|
protected async redeclareIntent(): Promise<void> {
|
|
301
291
|
await this.spanAsync('redeclareIntent', async () => {
|
|
302
292
|
// Decide if we should redeclare intent
|
|
303
|
-
if (this.config.producer.disableIntentRedeclaration) return
|
|
293
|
+
if (this.config.actors.producer.disableIntentRedeclaration) return
|
|
304
294
|
|
|
305
295
|
// Get the current block
|
|
306
296
|
const head = (await this.blockViewer.currentBlock())[0]
|
|
@@ -339,7 +329,7 @@ export class ProducerActor extends ActorV2<ProducerActorParams> {
|
|
|
339
329
|
// Check if we have a valid stake before declaring intent
|
|
340
330
|
if (!(await this.validateCurrentStake())) {
|
|
341
331
|
this.logger?.error(
|
|
342
|
-
`Add stake to contract address ${this.
|
|
332
|
+
`Add stake to contract address ${this.chainId}`
|
|
343
333
|
+ ' for the producer to declare it\'s intent.',
|
|
344
334
|
)
|
|
345
335
|
return
|
package/src/runProducer.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import type { CreatableName } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asAddress, exists, IdLogger,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
2
|
+
import { exists } from '@xylabs/sdk-js'
|
|
5
3
|
import { initProducerAccount, type OrchestratorInstance } from '@xyo-network/chain-orchestration'
|
|
6
|
-
import
|
|
4
|
+
import type {
|
|
5
|
+
Config,
|
|
6
|
+
ProviderFactoryLocatorInstance,
|
|
7
|
+
} from '@xyo-network/xl1-sdk'
|
|
7
8
|
|
|
8
9
|
import type { ProducerActorParams } from './ProducerActor.ts'
|
|
9
10
|
import { ProducerActor } from './ProducerActor.ts'
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
-
config: Config
|
|
13
|
-
orchestrator: OrchestratorInstance
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
config, logger = console, orchestrator,
|
|
18
|
-
}: RunProducerContext) => {
|
|
19
|
-
const localLogger = logger ?? new IdLogger(logger ?? console, () => 'ResolveHelper [runProducer]')
|
|
20
|
-
const account = await initProducerAccount({ config })
|
|
21
|
-
localLogger.info(`Running producer for account ${account.address}`)
|
|
22
|
-
const rewardAddress = asAddress(config.producer.rewardAddress, () => 'rewardAddress is required in config.producer')
|
|
23
|
-
localLogger.info(`Using reward address ${rewardAddress}`)
|
|
24
|
-
|
|
12
|
+
export const runProducer = async (
|
|
13
|
+
config: Config,
|
|
14
|
+
orchestrator: OrchestratorInstance,
|
|
15
|
+
locator: ProviderFactoryLocatorInstance,
|
|
16
|
+
) => {
|
|
17
|
+
const account = await initProducerAccount({ config, logger: locator.context.logger })
|
|
25
18
|
// Create actors
|
|
26
19
|
const producer = await ProducerActor.create({
|
|
27
|
-
|
|
20
|
+
config, locator, name: 'xl1-producer' as CreatableName, account,
|
|
28
21
|
} satisfies ProducerActorParams)
|
|
29
22
|
const actors = [producer].filter(exists)
|
|
30
23
|
|