@xyo-network/chain-producer 1.20.16 → 1.20.18
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 +13 -7
- package/dist/node/ProducerActor.d.ts.map +1 -1
- package/dist/node/index.mjs +36 -32
- package/dist/node/index.mjs.map +1 -1
- package/package.json +15 -18
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Attributes, Counter } from '@opentelemetry/api';
|
|
2
|
-
import { ProducerConfig } from '@xyo-network/chain-orchestration';
|
|
3
|
-
import type { ActorParamsV3, ChainContractViewer, ChainStakeIntent, HydratedBlockWithHashMeta, XL1BlockNumber } from '@xyo-network/xl1-sdk';
|
|
4
|
-
import {
|
|
2
|
+
import { type ProducerConfig } from '@xyo-network/chain-orchestration';
|
|
3
|
+
import type { AccountBalanceViewer, ActorParamsV3, BlockRunner, BlockViewer, ChainContractViewer, ChainStakeIntent, HydratedBlockWithHashMeta, MempoolRunner, MempoolViewer, StakeTotalsViewer, XL1BlockNumber } from '@xyo-network/xl1-sdk';
|
|
4
|
+
import { ActorV3 } from '@xyo-network/xl1-sdk';
|
|
5
5
|
export type ProducerActorParams = ActorParamsV3<{
|
|
6
6
|
config: ProducerConfig;
|
|
7
7
|
}>;
|
|
8
8
|
export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
9
9
|
/**
|
|
10
|
-
* The interval time (in MS) between block production attempts.
|
|
10
|
+
* The default interval time (in MS) between block production attempts.
|
|
11
11
|
*/
|
|
12
|
-
static readonly
|
|
12
|
+
static readonly DefaultBlockProductionCheckInterval = 10000;
|
|
13
13
|
/**
|
|
14
|
-
* The
|
|
14
|
+
* The multiplier applied to the block production check interval to determine
|
|
15
|
+
* the threshold for resubmitting the same block number if the head has not changed.
|
|
15
16
|
*/
|
|
16
|
-
static readonly
|
|
17
|
+
static readonly HeadResubmissionMultiplier = 30;
|
|
17
18
|
/**
|
|
18
19
|
* The window (in blocks) before expiration to attempt redeclaration of producer intent.
|
|
19
20
|
*/
|
|
@@ -38,6 +39,7 @@ export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
|
38
39
|
private _stakeTotalsViewer?;
|
|
39
40
|
get logger(): import("@xylabs/sdk-js").Logger;
|
|
40
41
|
protected get accountBalanceViewer(): AccountBalanceViewer;
|
|
42
|
+
protected get blockProductionCheckInterval(): number;
|
|
41
43
|
protected get blockRunner(): BlockRunner;
|
|
42
44
|
protected get blockViewer(): BlockViewer<"BlockViewer">;
|
|
43
45
|
protected get chainContractViewer(): ChainContractViewer;
|
|
@@ -102,6 +104,8 @@ export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
|
102
104
|
} | undefined;
|
|
103
105
|
};
|
|
104
106
|
validation: {
|
|
107
|
+
minCandidates: number;
|
|
108
|
+
backoffMs: number;
|
|
105
109
|
allowedRewardRedeemers?: (Lowercase<string> & {
|
|
106
110
|
readonly __hex: true;
|
|
107
111
|
} & {
|
|
@@ -114,6 +118,7 @@ export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
|
114
118
|
})[] | undefined;
|
|
115
119
|
};
|
|
116
120
|
name: string;
|
|
121
|
+
blockProductionCheckInterval: number;
|
|
117
122
|
heartbeatInterval: number;
|
|
118
123
|
minStake: number;
|
|
119
124
|
dataLake?: import("@xyo-network/xl1-sdk").DataLakeConfig | undefined;
|
|
@@ -127,6 +132,7 @@ export declare class ProducerActor extends ActorV3<ProducerActorParams> {
|
|
|
127
132
|
disableIntentRedeclaration?: boolean | undefined;
|
|
128
133
|
rewardAddress?: string | undefined;
|
|
129
134
|
};
|
|
135
|
+
protected get headResubmissionThreshold(): number;
|
|
130
136
|
protected get mempoolRunner(): MempoolRunner;
|
|
131
137
|
protected get mempoolViewer(): MempoolViewer;
|
|
132
138
|
protected get stakeTotalsViewer(): StakeTotalsViewer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["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AgB,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,6 +3,7 @@ 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 { DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL } from "@xyo-network/chain-orchestration";
|
|
6
7
|
import { SimpleBlockRunner } from "@xyo-network/chain-services";
|
|
7
8
|
import { AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker, buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker, StakeTotalsViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
8
9
|
import { Mutex } from "async-mutex";
|
|
@@ -25,13 +26,14 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
25
26
|
__name(this, "ProducerActor");
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
* The interval time (in MS) between block production attempts.
|
|
29
|
+
* The default interval time (in MS) between block production attempts.
|
|
29
30
|
*/
|
|
30
|
-
static
|
|
31
|
+
static DefaultBlockProductionCheckInterval = DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL;
|
|
31
32
|
/**
|
|
32
|
-
* The
|
|
33
|
+
* The multiplier applied to the block production check interval to determine
|
|
34
|
+
* the threshold for resubmitting the same block number if the head has not changed.
|
|
33
35
|
*/
|
|
34
|
-
static
|
|
36
|
+
static HeadResubmissionMultiplier = 30;
|
|
35
37
|
/**
|
|
36
38
|
* The window (in blocks) before expiration to attempt redeclaration of producer intent.
|
|
37
39
|
*/
|
|
@@ -60,6 +62,9 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
60
62
|
get accountBalanceViewer() {
|
|
61
63
|
return this._accountBalanceViewer;
|
|
62
64
|
}
|
|
65
|
+
get blockProductionCheckInterval() {
|
|
66
|
+
return this.config.blockProductionCheckInterval ?? _ProducerActor.DefaultBlockProductionCheckInterval;
|
|
67
|
+
}
|
|
63
68
|
get blockRunner() {
|
|
64
69
|
return this._blockRunner;
|
|
65
70
|
}
|
|
@@ -75,6 +80,9 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
75
80
|
get config() {
|
|
76
81
|
return this.params.config;
|
|
77
82
|
}
|
|
83
|
+
get headResubmissionThreshold() {
|
|
84
|
+
return this.blockProductionCheckInterval * _ProducerActor.HeadResubmissionMultiplier;
|
|
85
|
+
}
|
|
78
86
|
get mempoolRunner() {
|
|
79
87
|
return this._mempoolRunner;
|
|
80
88
|
}
|
|
@@ -137,7 +145,7 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
137
145
|
await super.startHandler();
|
|
138
146
|
this.registerTimer("BlockProductionTimer", async () => {
|
|
139
147
|
await this.produceBlock();
|
|
140
|
-
}, 2e3,
|
|
148
|
+
}, 2e3, this.blockProductionCheckInterval);
|
|
141
149
|
if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {
|
|
142
150
|
this.registerTimer("ProducerRedeclarationTimer", async () => {
|
|
143
151
|
await this.redeclareIntent();
|
|
@@ -151,7 +159,7 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
151
159
|
this._producerActorBlockProductionChecks?.add(1, this._metricAttributes);
|
|
152
160
|
await this.spanAsync("produceBlock", async () => {
|
|
153
161
|
if (this._produceBlockMutex.isLocked()) {
|
|
154
|
-
this.logger?.
|
|
162
|
+
this.logger?.debug("Skipping block production, previous production still in progress");
|
|
155
163
|
return;
|
|
156
164
|
}
|
|
157
165
|
await this._produceBlockMutex.runExclusive(async () => {
|
|
@@ -167,34 +175,30 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
|
|
|
167
175
|
}
|
|
168
176
|
const timeSinceHeadChange = isDefined(this._lastHeadChangeTime) ? currentTime - this._lastHeadChangeTime : 0;
|
|
169
177
|
const shouldSubmit = !this._lastProducedBlock || this._lastProducedBlock[0].previous !== headHash;
|
|
170
|
-
const shouldResubmit = timeSinceHeadChange >
|
|
178
|
+
const shouldResubmit = timeSinceHeadChange > this.headResubmissionThreshold;
|
|
171
179
|
const shouldSubmitBlock = shouldSubmit || shouldResubmit;
|
|
172
|
-
if (shouldSubmitBlock) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
if (!shouldSubmitBlock) {
|
|
181
|
+
this.logger?.debug("No block submission required at this time.");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (shouldResubmit) {
|
|
185
|
+
this.logger?.log(`Resubmitting block due to stale head. Head ${toFormattedBlockReference(head)} unchanged for ${timeSinceHeadChange}ms`);
|
|
186
|
+
this._lastHeadChangeTime = currentTime;
|
|
187
|
+
}
|
|
188
|
+
this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes);
|
|
189
|
+
const nextBlock = await this.blockRunner.produceNextBlock(head);
|
|
190
|
+
if (nextBlock) {
|
|
191
|
+
const displayBlockNumber = toFormattedBlockReference(nextBlock[0]);
|
|
192
|
+
this.logger?.log("Produced block:", displayBlockNumber);
|
|
193
|
+
this._producerActorBlocksProduced?.add(1, this._metricAttributes);
|
|
194
|
+
await this.mempoolRunner.submitBlocks([
|
|
195
|
+
nextBlock
|
|
196
|
+
]);
|
|
197
|
+
this.logger?.log("Published block:", displayBlockNumber);
|
|
198
|
+
this._producerActorBlocksPublished?.add(1, this._metricAttributes);
|
|
199
|
+
this._lastProducedBlock = nextBlock;
|
|
192
200
|
} else {
|
|
193
|
-
|
|
194
|
-
if (isDefined(this._lastProducedBlock)) {
|
|
195
|
-
nonSubmissionMessage = nonSubmissionMessage + `, already produced: ${toFormattedBlockReference(this._lastProducedBlock[0])}`;
|
|
196
|
-
}
|
|
197
|
-
this.logger?.log(`${nonSubmissionMessage}.`);
|
|
201
|
+
this.logger?.log("No block produced for submission.");
|
|
198
202
|
}
|
|
199
203
|
});
|
|
200
204
|
}, {
|
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 {\n assertEx, creatable, isDefined, isUndefined,\n toHex,\n} from '@xylabs/sdk-js'\nimport { ProducerConfig } from '@xyo-network/chain-orchestration'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport { WithHashMeta } from '@xyo-network/sdk-js'\nimport type {\n ActorParamsV3,\n BlockBoundWitness,\n ChainContractViewer, ChainId, ChainStakeIntent, 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: ProducerConfig\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: WithHashMeta<BlockBoundWitness>): 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 = 1000\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.produceNextBlock(head, shouldResubmit)\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.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 {\n initActorAccount,\n type OrchestratorInstance,\n type ProducerConfig,\n} from '@xyo-network/chain-orchestration'\nimport type { ProviderFactoryLocatorInstance } from '@xyo-network/xl1-sdk'\n\nimport type { ProducerActorParams } from './ProducerActor.ts'\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport const runProducer = async (\n config: ProducerConfig,\n orchestrator: OrchestratorInstance,\n locator: ProviderFactoryLocatorInstance,\n) => {\n const account = await initActorAccount({ ...locator.context, config })\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;AAEP,SAASC,yBAAyB;AAOlC,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;A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;IAAUK,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMT,aAAaa,cAAcD,KAAAA;EACnC;AAEA,QAAMZ,aAAac,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","produceNextBlock","displayBlockNumber","submitBlocks","nonSubmissionMessage","context","timeBudgetLimit","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","redeclarationIntent","createDeclarationIntent","SimpleBlockRunner","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","exists","initActorAccount","runProducer","config","orchestrator","locator","account","initActorAccount","context","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 {\n DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL,\n type ProducerConfig,\n} from '@xyo-network/chain-orchestration'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport type { WithHashMeta } from '@xyo-network/sdk-js'\nimport type {\n AccountBalanceViewer, ActorParamsV3,\n BlockBoundWitness,\n BlockRunner, BlockViewer, ChainContractViewer, ChainId, ChainStakeIntent, FinalizationViewer, HydratedBlockWithHashMeta, MempoolRunner,\n MempoolViewer, StakeTotalsViewer, XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker,\n buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker, StakeTotalsViewerMoniker,\n} from '@xyo-network/xl1-sdk'\nimport { Mutex } from 'async-mutex'\n\nexport type ProducerActorParams = ActorParamsV3<{\n config: ProducerConfig\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: WithHashMeta<BlockBoundWitness>): string => {\n return `${blockBoundWitness.block} [${toHex(blockBoundWitness._hash, { prefix: true })}]`\n}\n\n@creatable()\nexport class ProducerActor extends ActorV3<ProducerActorParams> {\n /**\n * The default interval time (in MS) between block production attempts.\n */\n static readonly DefaultBlockProductionCheckInterval = DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL\n\n /**\n * The multiplier applied to the block production check interval to determine\n * the threshold for resubmitting the same block number if the head has not changed.\n */\n static readonly HeadResubmissionMultiplier = 30\n\n /**\n * The window (in blocks) before expiration to attempt redeclaration of producer intent.\n */\n static readonly RedeclarationWindow = 1000\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 blockProductionCheckInterval() {\n return this.config.blockProductionCheckInterval ?? ProducerActor.DefaultBlockProductionCheckInterval\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 headResubmissionThreshold() {\n return this.blockProductionCheckInterval * ProducerActor.HeadResubmissionMultiplier\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, this.blockProductionCheckInterval)\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?.debug('Skipping block production, previous production still in progress')\n return\n }\n\n await this._produceBlockMutex.runExclusive(async () => {\n // Get the updated head\n const head = (await this.blockViewer.currentBlock())[0]\n const headHash = head._hash\n\n // Track head changes\n const currentTime = Date.now()\n if (this._lastHeadHash !== headHash) {\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 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 > this.headResubmissionThreshold\n\n // Determine if we should submit or resubmit\n const shouldSubmitBlock = shouldSubmit || shouldResubmit\n\n if (!shouldSubmitBlock) {\n this.logger?.debug('No block submission required at this time.')\n return\n }\n\n if (shouldResubmit) {\n this.logger?.log(`Resubmitting block due to stale head. Head ${toFormattedBlockReference(head)} unchanged for ${timeSinceHeadChange}ms`)\n this._lastHeadChangeTime = currentTime\n }\n this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes)\n // Produce the next block (do not pass force — undefined result is valid when idle)\n const nextBlock = await this.blockRunner.produceNextBlock(head)\n if (nextBlock) {\n const displayBlockNumber = toFormattedBlockReference(nextBlock[0])\n this.logger?.log('Produced block:', displayBlockNumber)\n this._producerActorBlocksProduced?.add(1, this._metricAttributes)\n await this.mempoolRunner.submitBlocks([nextBlock])\n this.logger?.log('Published block:', displayBlockNumber)\n this._producerActorBlocksPublished?.add(1, this._metricAttributes)\n this._lastProducedBlock = nextBlock\n } else {\n this.logger?.log('No block produced for submission.')\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.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 {\n initActorAccount,\n type OrchestratorInstance,\n type ProducerConfig,\n} from '@xyo-network/chain-orchestration'\nimport type { ProviderFactoryLocatorInstance } from '@xyo-network/xl1-sdk'\n\nimport type { ProducerActorParams } from './ProducerActor.ts'\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport const runProducer = async (\n config: ProducerConfig,\n orchestrator: OrchestratorInstance,\n locator: ProviderFactoryLocatorInstance,\n) => {\n const account = await initActorAccount({ ...locator.context, config })\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,SACEC,+CAEK;AACP,SAASC,yBAAyB;AAQlC,SACEC,6BAA6BC,SAASC,kBAAkBC,oBAAoBC,oBAC5EC,kBAAkBC,4BAA4BC,yBAAyBC,2BAA2BC,sBAAsBC,sBAAsBC,gCACzI;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,sCAAsCC;;;;;EAMtD,OAAgBC,6BAA6B;;;;EAK7C,OAAgBC,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,+BAA+B;AAC3C,WAAO,KAAKC,OAAOD,gCAAgC5B,eAAcE;EACnE;EAEA,IAAc4B,cAAc;AAC1B,WAAO,KAAKhB;EACd;EAEA,IAAciB,cAAc;AAC1B,WAAO,KAAKhB;EACd;EAEA,IAAciB,sBAAsB;AAClC,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,OAAO;EACvF;EAEA,MAAgBsD,yBAA2C;AAEzD,UAAMxB,QAAQ,MAAM,KAAKvC,YAAYgC,aAAY,KAAM,CAAA,GAAIjE;AAC3D,QAAI8E,UAAUN,IAAAA,GAAO;AACnB,YAAMoC,WAAW,MAAM,KAAK/E,qBAAqBgF,gBAAgB;QAAC,KAAKlE,QAAQD;SAAU;QAAE8B;MAAK,CAAA;AAChG,YAAMsC,iBAAiBF,SAAS,KAAKjE,QAAQD,OAAO,KAAK;AACzD,UAAIoE,kBAAkB,IAAI;AACxB,aAAKnF,QAAQsE,MAAM,YAAY,KAAKtD,QAAQD,OAAO,kBAAkB;AACrE,eAAO;MACT;AACA,aAAO;IACT;AACA,WAAO;EACT;EAEA,MAAgBwD,uBAAyC;AAEvD,UAAMa,uBAAuB;AAE7B,UAAMC,eAAe,MAAM,KAAKxE,kBAAkByE,eAAe,KAAKtE,QAAQD,OAAO;AACrF,QAAIsE,eAAeD,sBAAsB;AACvC,WAAKpF,QAAQsE,MAAM,YAAY,KAAKtD,QAAQD,OAAO,0BAA0B;AAC7E,aAAO;IACT;AACA,WAAO;EACT;AACF;;;;;;AC3YA,SAASwE,cAAc;AACvB,SACEC,wBAGK;AAMA,IAAMC,cAAc,8BACzBC,QACAC,cACAC,YAAAA;AAEA,QAAMC,UAAU,MAAMC,iBAAiB;IAAE,GAAGF,QAAQG;IAASL;EAAO,CAAA;AAEpE,QAAMM,WAAW,MAAMC,cAAcC,OAAO;IAC1CR;IAAQE;IAASO,MAAM;IAAiCN;EAC1D,CAAA;AACA,QAAMO,SAAS;IAACJ;IAAUK,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMT,aAAaa,cAAcD,KAAAA;EACnC;AAEA,QAAMZ,aAAac,MAAK;AAC1B,GAlB2B;","names":["assertEx","creatable","isDefined","isUndefined","toHex","DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL","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","DefaultBlockProductionCheckInterval","DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL","HeadResubmissionMultiplier","RedeclarationWindow","_lastProducedBlock","_lastRedeclarationIntent","_metricAttributes","_producerActorBlockProductionAttempts","_producerActorBlockProductionChecks","_producerActorBlocksProduced","_producerActorBlocksPublished","_accountBalanceViewer","_blockRunner","_blockViewer","_chainContractViewer","_chainId","_lastHeadChangeTime","_lastHeadHash","_mempoolRunner","_mempoolViewer","_produceBlockMutex","Mutex","_stakeTotalsViewer","logger","assertEx","accountBalanceViewer","blockProductionCheckInterval","config","blockRunner","blockViewer","chainContractViewer","chainId","params","headResubmissionThreshold","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","debug","runExclusive","head","headHash","currentTime","Date","now","lastHeadHashHex","isDefined","currentHeadHashHex","log","timeSinceHeadChange","shouldSubmit","previous","shouldResubmit","shouldSubmitBlock","nextBlock","produceNextBlock","displayBlockNumber","submitBlocks","context","timeBudgetLimit","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","redeclarationIntent","createDeclarationIntent","SimpleBlockRunner","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","exists","initActorAccount","runProducer","config","orchestrator","locator","account","initActorAccount","context","producer","ProducerActor","create","name","actors","filter","exists","actor","registerActor","start"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/chain-producer",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.18",
|
|
4
4
|
"description": "XYO Layer One Producer",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -27,8 +27,6 @@
|
|
|
27
27
|
"./package.json": "./package.json",
|
|
28
28
|
"./README.md": "./README.md"
|
|
29
29
|
},
|
|
30
|
-
"module": "./dist/node/index.mjs",
|
|
31
|
-
"types": "./dist/node/index.d.ts",
|
|
32
30
|
"files": [
|
|
33
31
|
"dist",
|
|
34
32
|
"!**/*.bench.*",
|
|
@@ -38,18 +36,17 @@
|
|
|
38
36
|
],
|
|
39
37
|
"dependencies": {
|
|
40
38
|
"@opentelemetry/api": "^1.9.1",
|
|
41
|
-
"@xyo-network/xl1-sdk": "^1.26.
|
|
39
|
+
"@xyo-network/xl1-sdk": "^1.26.29",
|
|
42
40
|
"async-mutex": "~0.5.0",
|
|
43
|
-
"@xyo-network/chain-orchestration": "~1.20.
|
|
41
|
+
"@xyo-network/chain-orchestration": "~1.20.18"
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"@types/node": "~25.
|
|
44
|
+
"@types/node": "~25.6.0",
|
|
47
45
|
"@xylabs/express": "^5.0.95",
|
|
48
46
|
"@xylabs/mongo": "~5.0.95",
|
|
49
47
|
"@xylabs/sdk-js": "~5.0.95",
|
|
50
|
-
"@xylabs/
|
|
51
|
-
"@xylabs/
|
|
52
|
-
"@xylabs/tsconfig": "~7.9.3",
|
|
48
|
+
"@xylabs/toolchain": "~7.10.7",
|
|
49
|
+
"@xylabs/tsconfig": "~7.10.7",
|
|
53
50
|
"@xyo-network/account": "~5.3.30",
|
|
54
51
|
"@xyo-network/account-model": "~5.3",
|
|
55
52
|
"@xyo-network/api-models": "~5.3.30",
|
|
@@ -102,8 +99,8 @@
|
|
|
102
99
|
"@xyo-network/witness-adhoc": "~5.3.30",
|
|
103
100
|
"@xyo-network/witness-model": "~5.3.30",
|
|
104
101
|
"ajv": "^8",
|
|
105
|
-
"axios": "^1.
|
|
106
|
-
"dotenv": "~17.4.
|
|
102
|
+
"axios": "^1.15.0",
|
|
103
|
+
"dotenv": "~17.4.2",
|
|
107
104
|
"esbuild": ">=0.18",
|
|
108
105
|
"ethers": "^6.16.0",
|
|
109
106
|
"lmdb": "^3",
|
|
@@ -112,11 +109,11 @@
|
|
|
112
109
|
"pako": "~2.1.0",
|
|
113
110
|
"tslib": "~2.8.1",
|
|
114
111
|
"typescript": "~5.9.3",
|
|
115
|
-
"vite": "^8.0.
|
|
116
|
-
"vitest": "^4.1.
|
|
112
|
+
"vite": "^8.0.8",
|
|
113
|
+
"vitest": "^4.1.4",
|
|
117
114
|
"zod": "^4.3.6",
|
|
118
|
-
"@xyo-network/chain-
|
|
119
|
-
"@xyo-network/chain-
|
|
115
|
+
"@xyo-network/chain-telemetry": "~1.20.18",
|
|
116
|
+
"@xyo-network/chain-services": "~1.20.18"
|
|
120
117
|
},
|
|
121
118
|
"peerDependencies": {
|
|
122
119
|
"@xylabs/express": "^5.0.95",
|
|
@@ -133,6 +130,8 @@
|
|
|
133
130
|
"@xyo-network/boundwitness-validator": "~5.3",
|
|
134
131
|
"@xyo-network/bridge-abstract": "~5.3.30",
|
|
135
132
|
"@xyo-network/bridge-model": "~5.3.30",
|
|
133
|
+
"@xyo-network/chain-services": "~1.20",
|
|
134
|
+
"@xyo-network/chain-telemetry": "~1.20",
|
|
136
135
|
"@xyo-network/config-payload-plugin": "~5.3.30",
|
|
137
136
|
"@xyo-network/data": "~5.3.30",
|
|
138
137
|
"@xyo-network/diviner-boundwitness-memory": "~5.3.30",
|
|
@@ -166,9 +165,7 @@
|
|
|
166
165
|
"@xyo-network/wasm": "~5.3.30",
|
|
167
166
|
"@xyo-network/witness-adhoc": "~5.3.30",
|
|
168
167
|
"@xyo-network/witness-model": "~5.3.30",
|
|
169
|
-
"pako": "~2.1.0"
|
|
170
|
-
"@xyo-network/chain-services": "~1.20.16",
|
|
171
|
-
"@xyo-network/chain-telemetry": "~1.20.16"
|
|
168
|
+
"pako": "~2.1.0"
|
|
172
169
|
},
|
|
173
170
|
"engines": {
|
|
174
171
|
"node": ">=24"
|