@xyo-network/chain-producer 1.20.28 → 1.20.29

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.
@@ -1,11 +1,11 @@
1
1
  import type { Attributes, Counter } from '@opentelemetry/api';
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';
2
+ import { type ActorCapabilityNeeds, type ActorParamsV3, ActorV3, type ProducerConfig } from '@xyo-network/chain-orchestration';
3
+ import type { AccountBalanceViewer, BlockRunner, BlockViewer, ChainContractViewer, ChainStakeIntent, HydratedBlockWithHashMeta, MempoolRunner, MempoolViewer, StakeTotalsViewer, XL1BlockNumber } from '@xyo-network/xl1-sdk';
5
4
  export type ProducerActorParams = ActorParamsV3<{
6
5
  config: ProducerConfig;
7
6
  }>;
8
7
  export declare class ProducerActor extends ActorV3<ProducerActorParams> {
8
+ static readonly needs: ActorCapabilityNeeds;
9
9
  /**
10
10
  * The default interval time (in MS) between block production attempts.
11
11
  */
@@ -140,6 +140,7 @@ export declare class ProducerActor extends ActorV3<ProducerActorParams> {
140
140
  startHandler(): Promise<void>;
141
141
  protected calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): number;
142
142
  protected produceBlock(): Promise<void>;
143
+ protected readyHandler(): Promise<void>;
143
144
  protected redeclareIntent(): Promise<void>;
144
145
  protected submitRedeclarationIntent(currentBlock: XL1BlockNumber, redeclarationIntent: ChainStakeIntent): Promise<void>;
145
146
  protected validateCurrentBalance(): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["../../src/ProducerActor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE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,CAAC;CAWzD"}
@@ -3,9 +3,9 @@ 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
+ import { ActorV3, DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL } from "@xyo-network/chain-orchestration";
7
7
  import { SimpleBlockRunner } from "@xyo-network/chain-services";
8
- import { AccountBalanceViewerMoniker, ActorV3, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker, buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker, StakeTotalsViewerMoniker } from "@xyo-network/xl1-sdk";
8
+ import { AccountBalanceViewerMoniker, asXL1BlockNumber, BlockRunnerMoniker, BlockViewerMoniker, buildTransaction, ChainContractViewerMoniker, createDeclarationIntent, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker, StakeTotalsViewerMoniker } from "@xyo-network/xl1-sdk";
9
9
  import { Mutex } from "async-mutex";
10
10
  function _ts_decorate(decorators, target, key, desc) {
11
11
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -25,6 +25,18 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
25
25
  static {
26
26
  __name(this, "ProducerActor");
27
27
  }
28
+ static needs = {
29
+ required: [
30
+ AccountBalanceViewerMoniker,
31
+ BlockRunnerMoniker,
32
+ BlockViewerMoniker,
33
+ ChainContractViewerMoniker,
34
+ FinalizationViewerMoniker,
35
+ MempoolRunnerMoniker,
36
+ MempoolViewerMoniker,
37
+ StakeTotalsViewerMoniker
38
+ ]
39
+ };
28
40
  /**
29
41
  * The default interval time (in MS) between block production attempts.
30
42
  */
@@ -206,6 +218,9 @@ var ProducerActor = class _ProducerActor extends ActorV3 {
206
218
  timeBudgetLimit: 1e3
207
219
  });
208
220
  }
221
+ async readyHandler() {
222
+ await this.produceBlock();
223
+ }
209
224
  async redeclareIntent() {
210
225
  await this.spanAsync("redeclareIntent", async () => {
211
226
  if (this.config.disableIntentRedeclaration) return;
@@ -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 {\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,WAAO,KAAKhB;EACd;EAEA,IAAciB,UAAU;AACtB,WAAO,KAAKhB;EACd;EAEA,IAAcY,SAAS;AACrB,WAAO,KAAKK,OAAOL;EACrB;EAEA,I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E,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"]}
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 type ActorCapabilityNeeds,\n type ActorParamsV3,\n ActorV3,\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,\n BlockBoundWitness,\n BlockRunner, BlockViewer, ChainContractViewer, ChainId, ChainStakeIntent, FinalizationViewer, HydratedBlockWithHashMeta, MempoolRunner,\n MempoolViewer, StakeTotalsViewer, XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewerMoniker, 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 static readonly needs: ActorCapabilityNeeds = {\n required: [\n AccountBalanceViewerMoniker,\n BlockRunnerMoniker,\n BlockViewerMoniker,\n ChainContractViewerMoniker,\n FinalizationViewerMoniker,\n MempoolRunnerMoniker,\n MempoolViewerMoniker,\n StakeTotalsViewerMoniker,\n ],\n }\n\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 override async readyHandler(): Promise<void> {\n // Warm pass: prove the production loop reaches its dependencies before declaring ready.\n await this.produceBlock()\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,SAGEC,SACAC,+CAEK;AACP,SAASC,yBAAyB;AAQlC,SACEC,6BAA6BC,kBAAkBC,oBAAoBC,oBACnEC,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;;;EACjC,OAAgBC,QAA8B;IAC5CC,UAAU;MACRC;MACAC;MACAC;MACAC;MACAC;MACAC;MACAC;MACAC;;EAEJ;;;;EAKA,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,gCAAgCtC,eAAcY;EACnE;EAEA,IAAc4B,cA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,KAAAA;EACnC;AAEA,QAAMZ,aAAac,MAAK;AAC1B,GAlB2B;","names":["assertEx","creatable","isDefined","isUndefined","toHex","ActorV3","DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL","SimpleBlockRunner","AccountBalanceViewerMoniker","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","needs","required","AccountBalanceViewerMoniker","BlockRunnerMoniker","BlockViewerMoniker","ChainContractViewerMoniker","FinalizationViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","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","start","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","readyHandler","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.28",
3
+ "version": "1.20.29",
4
4
  "description": "XYO Layer One Producer",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -35,8 +35,8 @@
35
35
  "README.md"
36
36
  ],
37
37
  "dependencies": {
38
- "@xyo-network/chain-orchestration": "~1.20.28",
39
- "@xyo-network/chain-services": "~1.20.28"
38
+ "@xyo-network/chain-orchestration": "~1.20.29",
39
+ "@xyo-network/chain-services": "~1.20.29"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@bitauth/libauth": "~3.0.0",
@@ -44,17 +44,17 @@
44
44
  "@metamask/providers": "^22.1.1",
45
45
  "@metamask/utils": "~11.11.0",
46
46
  "@opentelemetry/api": "^1.9.1",
47
- "@opentelemetry/context-async-hooks": "~2.7.0",
48
- "@opentelemetry/context-zone": "~2.7.0",
49
- "@opentelemetry/core": "~2.7.0",
50
- "@opentelemetry/exporter-prometheus": "~0.215.0",
51
- "@opentelemetry/exporter-trace-otlp-grpc": "~0.215.0",
52
- "@opentelemetry/exporter-trace-otlp-http": "~0.215.0",
47
+ "@opentelemetry/context-async-hooks": "~2.7.1",
48
+ "@opentelemetry/context-zone": "~2.7.1",
49
+ "@opentelemetry/core": "~2.7.1",
50
+ "@opentelemetry/exporter-prometheus": "~0.216.0",
51
+ "@opentelemetry/exporter-trace-otlp-grpc": "~0.216.0",
52
+ "@opentelemetry/exporter-trace-otlp-http": "~0.216.0",
53
53
  "@opentelemetry/host-metrics": "~0.38.3",
54
- "@opentelemetry/instrumentation-runtime-node": "~0.28.0",
55
- "@opentelemetry/resources": "~2.7.0",
56
- "@opentelemetry/sdk-metrics": "~2.7.0",
57
- "@opentelemetry/sdk-trace-base": "^2.7.0",
54
+ "@opentelemetry/instrumentation-runtime-node": "~0.29.0",
55
+ "@opentelemetry/resources": "~2.7.1",
56
+ "@opentelemetry/sdk-metrics": "~2.7.1",
57
+ "@opentelemetry/sdk-trace-base": "^2.7.1",
58
58
  "@opentelemetry/semantic-conventions": "~1.40.0",
59
59
  "@scure/base": "~2.2.0",
60
60
  "@scure/bip39": "~2.2.0",
@@ -64,8 +64,8 @@
64
64
  "@xylabs/mongo": "^5.0.101",
65
65
  "@xylabs/sdk-js": "^5.0.101",
66
66
  "@xylabs/threads": "~5.0.101",
67
- "@xylabs/toolchain": "~7.11.12",
68
- "@xylabs/tsconfig": "~7.11.12",
67
+ "@xylabs/toolchain": "~7.12.3",
68
+ "@xylabs/tsconfig": "~7.12.3",
69
69
  "@xyo-network/account": "~5.5.2",
70
70
  "@xyo-network/account-model": "~5.5.2",
71
71
  "@xyo-network/api": "~5.5.2",
@@ -91,8 +91,8 @@
91
91
  "@xyo-network/typechain": "^4.1.3",
92
92
  "@xyo-network/wallet": "~5.5.2",
93
93
  "@xyo-network/wallet-model": "^5.5.2",
94
- "@xyo-network/xl1-sdk": "^1.26.39",
95
- "ajv": "^8.18.0",
94
+ "@xyo-network/xl1-sdk": "^1.26.44",
95
+ "ajv": "^8.20.0",
96
96
  "async-mutex": "^0.5.0",
97
97
  "axios": "^1.15.2",
98
98
  "bn.js": "^5.2.3",
@@ -115,7 +115,7 @@
115
115
  "idb": "^8.0.3",
116
116
  "lmdb": "^3.5.4",
117
117
  "lru-cache": "^11.3.5",
118
- "mapbox-gl": "^3.22.0",
118
+ "mapbox-gl": "^3.23.0",
119
119
  "mongodb": "^7.2.0",
120
120
  "nodemon": "~3.1.14",
121
121
  "observable-fns": "~0.6.1",
@@ -133,86 +133,86 @@
133
133
  "webextension-polyfill": "^0.12.0",
134
134
  "winston": "~3.19.0",
135
135
  "winston-transport": "~4.9.0",
136
- "zod": "^4.3.6"
136
+ "zod": "~4.4.2"
137
137
  },
138
138
  "peerDependencies": {
139
- "@bitauth/libauth": ">=3.0.0 <4",
139
+ "@bitauth/libauth": ">=3.0.0 <3.1",
140
140
  "@metamask/json-rpc-engine": ">=10.2.4 <11",
141
141
  "@metamask/providers": ">=22.1.1 <23",
142
- "@metamask/utils": ">=11.11.0 <12",
142
+ "@metamask/utils": ">=11.11.0 <11.12",
143
143
  "@opentelemetry/api": ">=1.9.1 <2",
144
- "@opentelemetry/context-async-hooks": ">=2.7.0 <3",
145
- "@opentelemetry/context-zone": ">=2.7.0 <3",
146
- "@opentelemetry/core": ">=2.7.0 <3",
147
- "@opentelemetry/exporter-prometheus": ">=0.215.0 <1",
148
- "@opentelemetry/exporter-trace-otlp-grpc": ">=0.215.0 <1",
149
- "@opentelemetry/exporter-trace-otlp-http": ">=0.215.0 <1",
150
- "@opentelemetry/host-metrics": ">=0.38.3 <1",
151
- "@opentelemetry/instrumentation-runtime-node": ">=0.28.0 <1",
152
- "@opentelemetry/resources": ">=2.7.0 <3",
153
- "@opentelemetry/sdk-metrics": ">=2.7.0 <3",
154
- "@opentelemetry/sdk-trace-base": ">=2.7.0 <3",
155
- "@opentelemetry/semantic-conventions": ">=1.40.0 <2",
156
- "@scure/base": ">=2.2.0 <3",
157
- "@scure/bip39": ">=2.2.0 <3",
144
+ "@opentelemetry/context-async-hooks": ">=2.7.1 <2.8",
145
+ "@opentelemetry/context-zone": ">=2.7.1 <2.8",
146
+ "@opentelemetry/core": ">=2.7.1 <2.8",
147
+ "@opentelemetry/exporter-prometheus": ">=0.216.0 <0.217",
148
+ "@opentelemetry/exporter-trace-otlp-grpc": ">=0.216.0 <0.217",
149
+ "@opentelemetry/exporter-trace-otlp-http": ">=0.216.0 <0.217",
150
+ "@opentelemetry/host-metrics": ">=0.38.3 <0.39",
151
+ "@opentelemetry/instrumentation-runtime-node": ">=0.29.0 <0.30",
152
+ "@opentelemetry/resources": ">=2.7.1 <2.8",
153
+ "@opentelemetry/sdk-metrics": ">=2.7.1 <2.8",
154
+ "@opentelemetry/sdk-trace-base": ">=2.7.1 <3",
155
+ "@opentelemetry/semantic-conventions": ">=1.40.0 <1.41",
156
+ "@scure/base": ">=2.2.0 <2.3",
157
+ "@scure/bip39": ">=2.2.0 <2.3",
158
158
  "@xylabs/express": ">=5.0.101 <6",
159
159
  "@xylabs/geo": ">=5.0.101 <6",
160
160
  "@xylabs/mongo": ">=5.0.101 <6",
161
161
  "@xylabs/sdk-js": ">=5.0.101 <6",
162
- "@xylabs/threads": ">=5.0.101 <6",
163
- "@xyo-network/account": ">=5.5.2 <6",
164
- "@xyo-network/account-model": ">=5.5.2 <6",
165
- "@xyo-network/api": ">=5.5.2 <6",
166
- "@xyo-network/api-models": ">=5.5.2 <6",
167
- "@xyo-network/archivist-lmdb": ">=5.5.6 <6",
168
- "@xyo-network/archivist-mongodb": ">=5.5.6 <6",
169
- "@xyo-network/archivist-view": ">=5.5.6 <6",
170
- "@xyo-network/bios-model": ">=7.3.0 <8",
171
- "@xyo-network/boundwitness-builder": ">=5.5.2 <6",
172
- "@xyo-network/boundwitness-model": ">=5.5.2 <6",
173
- "@xyo-network/boundwitness-validator": ">=5.5.2 <6",
174
- "@xyo-network/boundwitness-wrapper": ">=5.5.2 <6",
175
- "@xyo-network/config-payload-plugin": ">=5.5.2 <6",
176
- "@xyo-network/huri": ">=5.5.2 <6",
177
- "@xyo-network/manifest-model": ">=5.5.2 <6",
178
- "@xyo-network/payload-builder": ">=5.5.2 <6",
179
- "@xyo-network/payload-model": ">=5.5.2 <6",
180
- "@xyo-network/payload-plugin": ">=5.5.2 <6",
181
- "@xyo-network/payload-wrapper": ">=5.5.2 <6",
182
- "@xyo-network/query-payload-plugin": ">=5.5.2 <6",
162
+ "@xylabs/threads": ">=5.0.101 <5.1",
163
+ "@xyo-network/account": ">=5.5.2 <5.6",
164
+ "@xyo-network/account-model": ">=5.5.2 <5.6",
165
+ "@xyo-network/api": ">=5.5.2 <5.6",
166
+ "@xyo-network/api-models": ">=5.5.2 <5.6",
167
+ "@xyo-network/archivist-lmdb": ">=5.5.6 <5.6",
168
+ "@xyo-network/archivist-mongodb": ">=5.5.6 <5.6",
169
+ "@xyo-network/archivist-view": ">=5.5.6 <5.6",
170
+ "@xyo-network/bios-model": ">=7.3.0 <7.4",
171
+ "@xyo-network/boundwitness-builder": ">=5.5.2 <5.6",
172
+ "@xyo-network/boundwitness-model": ">=5.5.2 <5.6",
173
+ "@xyo-network/boundwitness-validator": ">=5.5.2 <5.6",
174
+ "@xyo-network/boundwitness-wrapper": ">=5.5.2 <5.6",
175
+ "@xyo-network/config-payload-plugin": ">=5.5.2 <5.6",
176
+ "@xyo-network/huri": ">=5.5.2 <5.6",
177
+ "@xyo-network/manifest-model": ">=5.5.2 <5.6",
178
+ "@xyo-network/payload-builder": ">=5.5.2 <5.6",
179
+ "@xyo-network/payload-model": ">=5.5.2 <5.6",
180
+ "@xyo-network/payload-plugin": ">=5.5.2 <5.6",
181
+ "@xyo-network/payload-wrapper": ">=5.5.2 <5.6",
182
+ "@xyo-network/query-payload-plugin": ">=5.5.2 <5.6",
183
183
  "@xyo-network/sdk-js": ">=5.5.6 <6",
184
- "@xyo-network/sdk-protocol-js": ">=5.5.2 <6",
184
+ "@xyo-network/sdk-protocol-js": ">=5.5.2 <5.6",
185
185
  "@xyo-network/typechain": ">=4.1.3 <5",
186
- "@xyo-network/wallet": ">=5.5.2 <6",
186
+ "@xyo-network/wallet": ">=5.5.2 <5.6",
187
187
  "@xyo-network/wallet-model": ">=5.5.2 <6",
188
- "@xyo-network/xl1-sdk": ">=1.26.39 <2",
189
- "ajv": ">=8.18.0 <9",
188
+ "@xyo-network/xl1-sdk": ">=1.26.44 <2",
189
+ "ajv": ">=8.20.0 <9",
190
190
  "async-mutex": ">=0.5.0 <1",
191
191
  "axios": ">=1.15.2 <2",
192
192
  "bn.js": ">=5.2.3 <6",
193
193
  "buffer": ">=6.0.3 <7",
194
194
  "chalk": ">=5.6.2 <6",
195
- "compression": ">=1.8.1 <2",
196
- "cors": ">=2.8.6 <3",
195
+ "compression": ">=1.8.1 <1.9",
196
+ "cors": ">=2.8.6 <2.9",
197
197
  "cosmiconfig": ">=9.0.1 <10",
198
- "debug": ">=4.4.3 <5",
198
+ "debug": ">=4.4.3 <4.5",
199
199
  "ethers": ">=6.16.0 <7",
200
200
  "express": ">=5.2.1 <6",
201
- "hash-wasm": ">=4.12.0 <5",
201
+ "hash-wasm": ">=4.12.0 <4.13",
202
202
  "idb": ">=8.0.3 <9",
203
203
  "lmdb": ">=3.5.4 <4",
204
204
  "lru-cache": ">=11.3.5 <12",
205
- "mapbox-gl": ">=3.22.0 <4",
205
+ "mapbox-gl": ">=3.23.0 <4",
206
206
  "mongodb": ">=7.2.0 <8",
207
- "observable-fns": ">=0.6.1 <1",
207
+ "observable-fns": ">=0.6.1 <0.7",
208
208
  "pako": ">=2.1.0 <3",
209
- "shallowequal": ">=1.1.0 <2",
210
- "store2": ">=2.14.4 <3",
211
- "typescript": ">=5.9.3 <6",
212
- "uuid": ">=14.0.0 <15",
213
- "wasm-feature-detect": ">=1.8.0 <2",
214
- "web3-types": ">=1.10.0 <2",
215
- "zod": ">=4.3.6 <5"
209
+ "shallowequal": ">=1.1.0 <1.2",
210
+ "store2": ">=2.14.4 <2.15",
211
+ "typescript": ">=5.9.3 <5.10",
212
+ "uuid": ">=14.0.0 <14.1",
213
+ "wasm-feature-detect": ">=1.8.0 <1.9",
214
+ "web3-types": ">=1.10.0 <1.11",
215
+ "zod": ">=4.4.2 <4.5"
216
216
  },
217
217
  "engines": {
218
218
  "node": ">=24"