@xyo-network/chain-producer 1.18.5 → 1.19.0

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 +1 @@
1
- {"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["../../src/ProducerActor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAU7C,OAAO,KAAK,EAEV,gBAAgB,EAAE,yBAAyB,EAC3C,cAAc,EACf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,oBAAoB,EAA+B,KAAK,EAAE,WAAW,EACrE,WAAW,EACX,WAAW,EAKO,aAAa,EAE/B,aAAa,EAIb,iBAAiB,EAGlB,MAAM,sBAAsB,CAAA;AAG7B,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;IAC5C,aAAa,EAAE,OAAO,CAAA;CACvB,CAAC,CAAA;AAKF,qBACa,aAAc,SAAQ,KAAK,CAAC,mBAAmB,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,mBAAmB,SAAS;IAE5C,SAAS,CAAC,kBAAkB,CAAC,EAAE,yBAAyB,CAAA;IACxD,SAAS,CAAC,wBAAwB,CAAC,EAAE,gBAAgB,CAAA;IACrD,SAAS,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAA;IACxC,SAAS,CAAC,qCAAqC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IACrE,SAAS,CAAC,mCAAmC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IACnE,SAAS,CAAC,4BAA4B,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IAC5D,SAAS,CAAC,6BAA6B,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7D,OAAO,CAAC,qBAAqB,CAAC,CAAsB;IAC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SAAS,KAAK,WAAW,gBAExB;IAED,SAAS,KAAK,WAAW,+BAExB;IAED,SAAS,KAAK,OAAO,wCAEpB;IAED,SAAS,KAAK,aAAa,kBAE1B;IAED,SAAS,KAAK,aAAa,kBAE1B;IAED,SAAS,KAAK,aAAa;;;;MAE1B;IAED,SAAS,KAAK,iBAAiB,sBAE9B;WAEqB,aAAa,CAAC,CAAC,SAAS,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;qBAwB1D,WAAW,CACzC,MAAM,EAAE,mBAAmB;IA0Bd,aAAa;IAgDb,YAAY;IAe3B,SAAS,CAAC,iDAAiD,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;cAIzE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAwC7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;cAiEhC,yBAAyB,CAAC,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cAkB7G,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC;cAe1C,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;CAWzD"}
@@ -193,6 +193,7 @@ var ProducerActor = class _ProducerActor extends Actor {
193
193
  }
194
194
  });
195
195
  }, {
196
+ ...this.context,
196
197
  timeBudgetLimit: 1e3
197
198
  });
198
199
  }
@@ -224,6 +225,7 @@ var ProducerActor = class _ProducerActor extends Actor {
224
225
  await this.submitRedeclarationIntent(currentBlock, redeclarationIntent);
225
226
  this._lastRedeclarationIntent = redeclarationIntent;
226
227
  }, {
228
+ ...this.context,
227
229
  timeBudgetLimit: 1e3
228
230
  });
229
231
  }
@@ -238,7 +240,7 @@ var ProducerActor = class _ProducerActor extends Actor {
238
240
  this.logger?.log("Submitted redeclaration intent for producer:", this.account.address);
239
241
  }
240
242
  async validateCurrentBalance() {
241
- const head = this._lastProducedBlock?.[0]._hash;
243
+ const head = (await this.blockViewer.currentBlock())?.[0]?._hash;
242
244
  if (isDefined(head)) {
243
245
  const balances = await this.accountBalanceViewer.accountBalances([
244
246
  this.account.address
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ProducerActor.ts","../../src/runProducer.ts"],"sourcesContent":["import type { Attributes, Counter } from '@opentelemetry/api'\nimport type { Address } from '@xylabs/sdk-js'\nimport {\n asAddress,\n assertEx,\n creatable, isDefined, isUndefined, toHex,\n} from '@xylabs/sdk-js'\nimport { EvmChainContractViewer, EvmStakeTotalsViewer } from '@xyo-network/chain-ethereum'\nimport { initEvmProvider, initProducerAccount } from '@xyo-network/chain-orchestration'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport { validateHydratedBlock, validateHydratedBlockState } from '@xyo-network/chain-validation'\nimport type {\n ChainId,\n ChainStakeIntent, HydratedBlockWithHashMeta,\n XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewer, AccountBalanceViewerMoniker, Actor, ActorParams, asXL1BlockNumber,\n BlockRunner, BlockRunnerMoniker,\n BlockViewer, BlockViewerMoniker, buildJsonRpcProviderLocator,\n buildTransaction,\n Config,\n createDeclarationIntent,\n getDefaultConfig,\n HttpRpcTransport, MempoolRunner,\n MempoolRunnerMoniker,\n MempoolViewer,\n MempoolViewerMoniker,\n RpcSchemaMap, SimpleBlockRewardViewer,\n SimpleBlockValidationViewer,\n StakeTotalsViewer,\n StakeTotalsViewerMoniker,\n TransportFactory,\n} from '@xyo-network/xl1-sdk'\nimport { Mutex } from 'async-mutex'\n\nexport type ProducerActorParams = ActorParams<{\n rewardAddress: Address\n}>\n\nconst SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true\nconst TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds\n\n@creatable()\nexport class ProducerActor extends Actor<ProducerActorParams> {\n static readonly RedeclarationWindow = 10_000\n\n protected _lastProducedBlock?: HydratedBlockWithHashMeta\n protected _lastRedeclarationIntent?: ChainStakeIntent\n protected _metricAttributes?: Attributes\n protected _producerActorBlockProductionAttempts?: Counter<Attributes>\n protected _producerActorBlockProductionChecks?: Counter<Attributes>\n protected _producerActorBlocksProduced?: Counter<Attributes>\n protected _producerActorBlocksPublished?: Counter<Attributes>\n\n private _accountBalanceViewer?: AccountBalanceViewer\n private _blockRunner?: BlockRunner\n private _blockViewer?: BlockViewer\n private _chainId?: ChainId\n private _mempoolRunner?: MempoolRunner\n private _mempoolViewer?: MempoolViewer\n\n private _produceBlockMutex = new Mutex()\n\n private _stakeTotalsViewer?: StakeTotalsViewer\n\n protected get accountBalanceViewer() {\n return this._accountBalanceViewer!\n }\n\n protected get blockRunner() {\n return this._blockRunner!\n }\n\n protected get blockViewer() {\n return this._blockViewer!\n }\n\n protected get chainId() {\n return this._chainId!\n }\n\n protected get mempoolRunner() {\n return this._mempoolRunner!\n }\n\n protected get mempoolViewer() {\n return this._mempoolViewer!\n }\n\n protected get rewardAddress() {\n return this.params.rewardAddress!\n }\n\n protected get stakeTotalsViewer() {\n return this._stakeTotalsViewer!\n }\n\n static override async paramsHandler<T extends ProducerActor>(params?: Partial<T['params']>) {\n const logger = params?.context?.logger\n const config = params?.context?.config ?? getDefaultConfig()\n const displayName = params?.displayName ?? 'ProducerActor'\n const account = params?.account ?? await initProducerAccount({ config })\n const id = account?.address.toString() ?? 'unknown'\n logger?.info(`Running producer for account ${account.address}`)\n const rewardAddress = params?.rewardAddress ?? account.address\n logger?.info(`Using reward address ${rewardAddress}`)\n if (rewardAddress === account.address) {\n logger?.warn(`Using producer account address as reward address: ${account.address}`)\n }\n\n return {\n ...await super.paramsHandler({\n ...params,\n account,\n displayName,\n id,\n }),\n rewardAddress,\n }\n }\n\n protected static override async initContext(\n params: ProducerActorParams,\n ) {\n const config: Config = params?.context?.config ?? getDefaultConfig()\n const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')\n\n const context = await super.initContext(params)\n\n const chainId = assertEx(config.chain.id, () => 'Chain ID is required in config.chain.id')\n\n const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)\n const locator = await buildJsonRpcProviderLocator({ context, transportFactory })\n const runner = await initEvmProvider({ config })\n locator.register(EvmChainContractViewer.factory<EvmChainContractViewer>(EvmChainContractViewer.dependencies, { address: asAddress(chainId), runner }))\n locator.register(EvmStakeTotalsViewer.factory<EvmStakeTotalsViewer>(EvmStakeTotalsViewer.dependencies, { address: asAddress(chainId), runner }))\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: params.account, rewardAddress: params.rewardAddress },\n ))\n return locator.context\n }\n\n override async createHandler() {\n await super.createHandler()\n // Create the consistent meter attributes that will\n // be included with all metrics from this actor\n this._metricAttributes = { address: this.account.address.toString() }\n // Create the metrics\n this._producerActorBlockProductionChecks = this.meter?.createCounter(\n 'producer_actor_block_production_checks',\n { description: 'Number of block production checks' },\n )\n this._producerActorBlockProductionAttempts = this.meter?.createCounter(\n 'producer_actor_block_production_attempts',\n { description: 'Number of block production attempts' },\n )\n this._producerActorBlocksProduced = this.meter?.createCounter(\n 'producer_actor_blocks_produced',\n { description: 'Number of blocks produced' },\n )\n this._producerActorBlocksPublished = this.meter?.createCounter(\n 'producer_actor_blocks_published',\n { description: 'Number of blocks published' },\n )\n this._accountBalanceViewer = assertEx(\n await this.locator?.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker),\n () => 'Unable to locate AccountBalanceViewer',\n )\n this._blockRunner = assertEx(\n await this.locator?.getInstance<BlockRunner>(BlockRunnerMoniker),\n () => 'Unable to locate BlockRunner',\n )\n this._blockViewer = assertEx(\n await this.locator?.getInstance<BlockViewer>(BlockViewerMoniker),\n () => 'Unable to locate BlockViewer',\n )\n this._mempoolRunner = assertEx(\n await this.locator?.getInstance<MempoolRunner>(MempoolRunnerMoniker),\n () => 'Unable to locate MempoolRunner',\n )\n this._mempoolViewer = assertEx(\n await this.locator?.getInstance<MempoolViewer>(MempoolViewerMoniker),\n () => 'Unable to locate MempoolViewer',\n )\n this._stakeTotalsViewer = assertEx(\n await this.locator?.getInstance<StakeTotalsViewer>(StakeTotalsViewerMoniker),\n () => 'Unable to locate StakeTotalsViewer',\n )\n }\n\n 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, 1500/* 500 */)\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 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 // If our last produced block was the next block for the current head, we do not\n // need to produce another. This prevents duplicate blocks from being produced\n if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {\n this.logger?.log('Block already produced:', `0x${toHex(this._lastProducedBlock[0].block)}`, this._lastProducedBlock[0].block)\n } else {\n this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes)\n // Produce the next block\n const nextBlock = await this.blockRunner.next(head)\n // If it was produced\n if (nextBlock) {\n const displayBlockNumber = `0x${toHex(nextBlock[0].block)}`\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, nextBlock[0].block)\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 at this time.')\n }\n }\n })\n }, { timeBudgetLimit: 1000 })\n }\n\n protected async redeclareIntent(): Promise<void> {\n await this.spanAsync('redeclareIntent', async () => {\n // Decide if we should redeclare intent\n if (this.config.producer.disableIntentRedeclaration) return\n\n // Get the current block\n const head = (await this.blockViewer.currentBlock())[0]\n if (isUndefined(head)) return\n const currentBlock = head.block\n\n // // Calculate the time until the producer's declaration expires\n const blocksUntilExpiration = this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)\n\n // Allow the producer time to redeclare itself via block production\n // (for free) before submitting a redeclaration intent transaction.\n if (blocksUntilExpiration > ProducerActor.RedeclarationWindow * 0.1) {\n // Clear any previous redeclaration intent\n this._lastRedeclarationIntent = undefined\n // No need to redeclare yet\n return\n }\n\n // If we already have a valid redeclaration intent, do not create another\n // unless it has expired.\n if (this._lastRedeclarationIntent) {\n // Check if the last redeclaration intent is still valid\n if (this._lastRedeclarationIntent.exp > currentBlock) return\n // If it has expired, clear the last redeclaration intent\n this._lastRedeclarationIntent = undefined\n }\n\n // Check if we have a valid balance before declaring intent\n if (!await this.validateCurrentBalance()) {\n this.logger?.error(\n `Add balance to address ${this.account.address} for the producer to declare it's intent.`,\n )\n return\n }\n\n // Check if we have a valid stake before declaring intent\n if (!(await this.validateCurrentStake())) {\n this.logger?.error(\n `Add stake to contract address ${this.config.chain.id}`\n + ' for the producer to declare it\\'s intent.',\n )\n return\n }\n\n // Create a redeclaration intent\n this.logger?.log('Creating redeclaration intent for producer:', this.account.address)\n const redeclarationIntent = createDeclarationIntent(\n this.account.address,\n 'producer',\n currentBlock,\n currentBlock + SimpleBlockRunner.RedeclarationDuration,\n )\n\n // Submit the redeclaration intent\n await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)\n\n // On successful submission, save the redeclaration intent\n this._lastRedeclarationIntent = redeclarationIntent\n }, { 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 = this._lastProducedBlock?.[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 {\n asAddress, exists, IdLogger,\n} from '@xylabs/sdk-js'\nimport { initProducerAccount, type OrchestratorInstance } from '@xyo-network/chain-orchestration'\nimport type {\n BaseContext, Config, ProviderFactoryLocatorInstance,\n} from '@xyo-network/xl1-sdk'\n\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport interface RunProducerContext extends BaseContext {\n config: Config\n locator?: ProviderFactoryLocatorInstance\n orchestrator: OrchestratorInstance\n}\n\nexport const runProducer = async ({\n config, logger, orchestrator, locator,\n}: RunProducerContext) => {\n const localLogger = logger ?? new IdLogger(logger ?? console, () => 'ResolveHelper [runProducer]')\n const account = await initProducerAccount({ config })\n localLogger.info(`Running producer for account ${account.address}`)\n const rewardAddress = asAddress(config.producer.rewardAddress, () => 'rewardAddress is required in config.producer')\n localLogger.info(`Using reward address ${rewardAddress}`)\n\n // Create actors\n const producer = await ProducerActor.create({\n logger,\n context: {\n config, locator, singletons: {}, caches: {},\n },\n })\n const actors = [producer].filter(exists)\n\n for (const actor of actors) {\n // Register the actor with the orchestrator\n await orchestrator.registerActor(actor)\n }\n // Start the orchestrator => automatically activates the actor\n await orchestrator.start()\n}\n"],"mappings":";;;;AAEA,SACEA,WACAC,UACAC,WAAWC,WAAWC,aAAaC,aAC9B;AACP,SAASC,wBAAwBC,4BAA4B;AAC7D,SAASC,iBAAiBC,2BAA2B;AACrD,SAASC,yBAAyB;AAClC,SAASC,uBAAuBC,kCAAkC;AAMlE,SACwBC,6BAA6BC,OAAoBC,kBAC1DC,oBACAC,oBAAoBC,6BACjCC,kBAEAC,yBACAC,kBACAC,kBACAC,sBAEAC,sBACcC,yBACdC,6BAEAC,gCAEK;AACP,SAASC,aAAa;;;;;;;;AAMtB,IAAMC,6CAA6C;AACnD,IAAMC,cAAc,KAAK,KAAK;AAGvB,IAAMC,gBAAN,MAAMA,uBAAsBC,MAAAA;SAAAA;;;EACjC,OAAgBC,sBAAsB;EAE5BC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEFC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEAC,qBAAqB,IAAIC,MAAAA;EAEzBC;EAER,IAAcC,uBAAuB;AACnC,WAAO,KAAKT;EACd;EAEA,IAAcU,cAAc;AAC1B,WAAO,KAAKT;EACd;E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BuE,uBAAyC;AAEvD,UAAMa,uBAAuB;AAE7B,UAAMC,eAAe,MAAM,KAAK/F,kBAAkBgG,eAAe,KAAKzF,QAAQG,OAAO;AACrF,QAAIqF,eAAeD,sBAAsB;AACvC,WAAK5F,QAAQ8E,MAAM,YAAY,KAAKzE,QAAQG,OAAO,0BAA0B;AAC7E,aAAO;IACT;AACA,WAAO;EACT;AACF;;;;;;AC7WA,SACEuF,aAAAA,YAAWC,QAAQC,gBACd;AACP,SAASC,uBAAAA,4BAAsD;AAaxD,IAAMC,cAAc,8BAAO,EAChCC,QAAQC,QAAQC,cAAcC,QAAO,MAClB;AACnB,QAAMC,cAAcH,UAAU,IAAII,SAASJ,UAAUK,SAAS,MAAM,6BAAA;AACpE,QAAMC,UAAU,MAAMC,qBAAoB;IAAER;EAAO,CAAA;AACnDI,cAAYK,KAAK,gCAAgCF,QAAQG,OAAO,EAAE;AAClE,QAAMC,gBAAgBC,WAAUZ,OAAOa,SAASF,eAAe,MAAM,8CAAA;AACrEP,cAAYK,KAAK,wBAAwBE,aAAAA,EAAe;AAGxD,QAAME,WAAW,MAAMC,cAAcC,OAAO;IAC1Cd;IACAe,SAAS;MACPhB;MAAQG;MAASc,YAAY,CAAC;MAAGC,QAAQ,CAAC;IAC5C;EACF,CAAA;AACA,QAAMC,SAAS;IAACN;IAAUO,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMjB,aAAaqB,cAAcD,KAAAA;EACnC;AAEA,QAAMpB,aAAasB,MAAK;AAC1B,GAxB2B;","names":["asAddress","assertEx","creatable","isDefined","isUndefined","toHex","EvmChainContractViewer","EvmStakeTotalsViewer","initEvmProvider","initProducerAccount","SimpleBlockRunner","validateHydratedBlock","validateHydratedBlockState","AccountBalanceViewerMoniker","Actor","asXL1BlockNumber","BlockRunnerMoniker","BlockViewerMoniker","buildJsonRpcProviderLocator","buildTransaction","createDeclarationIntent","getDefaultConfig","HttpRpcTransport","MempoolRunnerMoniker","MempoolViewerMoniker","SimpleBlockRewardViewer","SimpleBlockValidationViewer","StakeTotalsViewerMoniker","Mutex","SHOULD_REGISTER_REDECLARATION_INTENT_TIMER","TEN_MINUTES","ProducerActor","Actor","RedeclarationWindow","_lastProducedBlock","_lastRedeclarationIntent","_metricAttributes","_producerActorBlockProductionAttempts","_producerActorBlockProductionChecks","_producerActorBlocksProduced","_producerActorBlocksPublished","_accountBalanceViewer","_blockRunner","_blockViewer","_chainId","_mempoolRunner","_mempoolViewer","_produceBlockMutex","Mutex","_stakeTotalsViewer","accountBalanceViewer","blockRunner","blockViewer","chainId","mempoolRunner","mempoolViewer","rewardAddress","params","stakeTotalsViewer","paramsHandler","logger","context","config","getDefaultConfig","displayName","account","initProducerAccount","id","address","toString","info","warn","initContext","endpoint","assertEx","services","apiEndpoint","chain","transportFactory","schemas","HttpRpcTransport","locator","buildJsonRpcProviderLocator","runner","initEvmProvider","register","EvmChainContractViewer","factory","dependencies","asAddress","EvmStakeTotalsViewer","SimpleBlockRewardViewer","SimpleBlockValidationViewer","state","validateHydratedBlockState","protocol","validateHydratedBlock","SimpleBlockRunner","createHandler","meter","createCounter","description","getInstance","AccountBalanceViewerMoniker","BlockRunnerMoniker","BlockViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","startHandler","registerTimer","produceBlock","redeclareIntent","calculateBlocksUntilProducerDeclarationExpiration","currentBlock","exp","add","spanAsync","isLocked","log","runExclusive","head","headHash","_hash","previous","toHex","block","nextBlock","next","displayBlockNumber","submitBlocks","timeBudgetLimit","producer","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","redeclarationIntent","createDeclarationIntent","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","isDefined","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","asAddress","exists","IdLogger","initProducerAccount","runProducer","config","logger","orchestrator","locator","localLogger","IdLogger","console","account","initProducerAccount","info","address","rewardAddress","asAddress","producer","ProducerActor","create","context","singletons","caches","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 type { Address } from '@xylabs/sdk-js'\nimport {\n asAddress, assertEx, creatable, isDefined, isUndefined, toHex,\n} from '@xylabs/sdk-js'\nimport { EvmChainContractViewer, EvmStakeTotalsViewer } from '@xyo-network/chain-ethereum'\nimport { initEvmProvider, initProducerAccount } from '@xyo-network/chain-orchestration'\nimport { SimpleBlockRunner } from '@xyo-network/chain-services'\nimport { validateHydratedBlock, validateHydratedBlockState } from '@xyo-network/chain-validation'\nimport type {\n ChainId, ChainStakeIntent, HydratedBlockWithHashMeta, XL1BlockNumber,\n} from '@xyo-network/xl1-sdk'\nimport {\n AccountBalanceViewer, AccountBalanceViewerMoniker, Actor, ActorParams, asXL1BlockNumber, BlockRunner, BlockRunnerMoniker, BlockViewer, BlockViewerMoniker,\n buildJsonRpcProviderLocator, buildTransaction, Config, createDeclarationIntent, getDefaultConfig, HttpRpcTransport, MempoolRunner, MempoolRunnerMoniker,\n MempoolViewer, MempoolViewerMoniker, RpcSchemaMap, SimpleBlockRewardViewer, SimpleBlockValidationViewer, StakeTotalsViewer, StakeTotalsViewerMoniker,\n TransportFactory,\n} from '@xyo-network/xl1-sdk'\nimport { Mutex } from 'async-mutex'\n\nexport type ProducerActorParams = ActorParams<{\n rewardAddress: Address\n}>\n\nconst SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true\nconst TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds\n\n@creatable()\nexport class ProducerActor extends Actor<ProducerActorParams> {\n static readonly RedeclarationWindow = 10_000\n\n protected _lastProducedBlock?: HydratedBlockWithHashMeta\n protected _lastRedeclarationIntent?: ChainStakeIntent\n protected _metricAttributes?: Attributes\n protected _producerActorBlockProductionAttempts?: Counter<Attributes>\n protected _producerActorBlockProductionChecks?: Counter<Attributes>\n protected _producerActorBlocksProduced?: Counter<Attributes>\n protected _producerActorBlocksPublished?: Counter<Attributes>\n\n private _accountBalanceViewer?: AccountBalanceViewer\n private _blockRunner?: BlockRunner\n private _blockViewer?: BlockViewer\n private _chainId?: ChainId\n private _mempoolRunner?: MempoolRunner\n private _mempoolViewer?: MempoolViewer\n\n private _produceBlockMutex = new Mutex()\n\n private _stakeTotalsViewer?: StakeTotalsViewer\n\n protected get accountBalanceViewer() {\n return this._accountBalanceViewer!\n }\n\n protected get blockRunner() {\n return this._blockRunner!\n }\n\n protected get blockViewer() {\n return this._blockViewer!\n }\n\n protected get chainId() {\n return this._chainId!\n }\n\n protected get mempoolRunner() {\n return this._mempoolRunner!\n }\n\n protected get mempoolViewer() {\n return this._mempoolViewer!\n }\n\n protected get rewardAddress() {\n return this.params.rewardAddress!\n }\n\n protected get stakeTotalsViewer() {\n return this._stakeTotalsViewer!\n }\n\n static override async paramsHandler<T extends ProducerActor>(params?: Partial<T['params']>) {\n const logger = params?.context?.logger\n const config = params?.context?.config ?? getDefaultConfig()\n const displayName = params?.displayName ?? 'ProducerActor'\n const account = params?.account ?? await initProducerAccount({ config })\n const id = account?.address.toString() ?? 'unknown'\n logger?.info(`Running producer for account ${account.address}`)\n const rewardAddress = params?.rewardAddress ?? account.address\n logger?.info(`Using reward address ${rewardAddress}`)\n if (rewardAddress === account.address) {\n logger?.warn(`Using producer account address as reward address: ${account.address}`)\n }\n\n return {\n ...await super.paramsHandler({\n ...params,\n account,\n displayName,\n id,\n }),\n rewardAddress,\n }\n }\n\n protected static override async initContext(\n params: ProducerActorParams,\n ) {\n const config: Config = params?.context?.config ?? getDefaultConfig()\n const endpoint = assertEx(config.services.apiEndpoint, () => 'API endpoint is required in config.services.apiEndpoint')\n\n const context = await super.initContext(params)\n\n const chainId = assertEx(config.chain.id, () => 'Chain ID is required in config.chain.id')\n\n const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)\n const locator = await buildJsonRpcProviderLocator({ context, transportFactory })\n const runner = await initEvmProvider({ config })\n locator.register(EvmChainContractViewer.factory<EvmChainContractViewer>(EvmChainContractViewer.dependencies, { address: asAddress(chainId), runner }))\n locator.register(EvmStakeTotalsViewer.factory<EvmStakeTotalsViewer>(EvmStakeTotalsViewer.dependencies, { address: asAddress(chainId), runner }))\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: params.account, rewardAddress: params.rewardAddress },\n ))\n return locator.context\n }\n\n override async createHandler() {\n await super.createHandler()\n // Create the consistent meter attributes that will\n // be included with all metrics from this actor\n this._metricAttributes = { address: this.account.address.toString() }\n // Create the metrics\n this._producerActorBlockProductionChecks = this.meter?.createCounter(\n 'producer_actor_block_production_checks',\n { description: 'Number of block production checks' },\n )\n this._producerActorBlockProductionAttempts = this.meter?.createCounter(\n 'producer_actor_block_production_attempts',\n { description: 'Number of block production attempts' },\n )\n this._producerActorBlocksProduced = this.meter?.createCounter(\n 'producer_actor_blocks_produced',\n { description: 'Number of blocks produced' },\n )\n this._producerActorBlocksPublished = this.meter?.createCounter(\n 'producer_actor_blocks_published',\n { description: 'Number of blocks published' },\n )\n this._accountBalanceViewer = assertEx(\n await this.locator?.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker),\n () => 'Unable to locate AccountBalanceViewer',\n )\n this._blockRunner = assertEx(\n await this.locator?.getInstance<BlockRunner>(BlockRunnerMoniker),\n () => 'Unable to locate BlockRunner',\n )\n this._blockViewer = assertEx(\n await this.locator?.getInstance<BlockViewer>(BlockViewerMoniker),\n () => 'Unable to locate BlockViewer',\n )\n this._mempoolRunner = assertEx(\n await this.locator?.getInstance<MempoolRunner>(MempoolRunnerMoniker),\n () => 'Unable to locate MempoolRunner',\n )\n this._mempoolViewer = assertEx(\n await this.locator?.getInstance<MempoolViewer>(MempoolViewerMoniker),\n () => 'Unable to locate MempoolViewer',\n )\n this._stakeTotalsViewer = assertEx(\n await this.locator?.getInstance<StakeTotalsViewer>(StakeTotalsViewerMoniker),\n () => 'Unable to locate StakeTotalsViewer',\n )\n }\n\n 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, 1500/* 500 */)\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 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 // If our last produced block was the next block for the current head, we do not\n // need to produce another. This prevents duplicate blocks from being produced\n if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {\n this.logger?.log('Block already produced:', `0x${toHex(this._lastProducedBlock[0].block)}`, this._lastProducedBlock[0].block)\n } else {\n this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes)\n // Produce the next block\n const nextBlock = await this.blockRunner.next(head)\n // If it was produced\n if (nextBlock) {\n const displayBlockNumber = `0x${toHex(nextBlock[0].block)}`\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, nextBlock[0].block)\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 at this time.')\n }\n }\n })\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async redeclareIntent(): Promise<void> {\n await this.spanAsync('redeclareIntent', async () => {\n // Decide if we should redeclare intent\n if (this.config.producer.disableIntentRedeclaration) return\n\n // Get the current block\n const head = (await this.blockViewer.currentBlock())[0]\n if (isUndefined(head)) return\n const currentBlock = head.block\n\n // // Calculate the time until the producer's declaration expires\n const blocksUntilExpiration = this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)\n\n // Allow the producer time to redeclare itself via block production\n // (for free) before submitting a redeclaration intent transaction.\n if (blocksUntilExpiration > ProducerActor.RedeclarationWindow * 0.1) {\n // Clear any previous redeclaration intent\n this._lastRedeclarationIntent = undefined\n // No need to redeclare yet\n return\n }\n\n // If we already have a valid redeclaration intent, do not create another\n // unless it has expired.\n if (this._lastRedeclarationIntent) {\n // Check if the last redeclaration intent is still valid\n if (this._lastRedeclarationIntent.exp > currentBlock) return\n // If it has expired, clear the last redeclaration intent\n this._lastRedeclarationIntent = undefined\n }\n\n // Check if we have a valid balance before declaring intent\n if (!await this.validateCurrentBalance()) {\n this.logger?.error(\n `Add balance to address ${this.account.address} for the producer to declare it's intent.`,\n )\n return\n }\n\n // Check if we have a valid stake before declaring intent\n if (!(await this.validateCurrentStake())) {\n this.logger?.error(\n `Add stake to contract address ${this.config.chain.id}`\n + ' for the producer to declare it\\'s intent.',\n )\n return\n }\n\n // Create a redeclaration intent\n this.logger?.log('Creating redeclaration intent for producer:', this.account.address)\n const redeclarationIntent = createDeclarationIntent(\n this.account.address,\n 'producer',\n currentBlock,\n currentBlock + SimpleBlockRunner.RedeclarationDuration,\n )\n\n // Submit the redeclaration intent\n await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)\n\n // On successful submission, save the redeclaration intent\n this._lastRedeclarationIntent = redeclarationIntent\n }, { ...this.context, timeBudgetLimit: 1000 })\n }\n\n protected async submitRedeclarationIntent(currentBlock: XL1BlockNumber, redeclarationIntent: ChainStakeIntent): Promise<void> {\n this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)\n // Create a transaction to submit the redeclaration intent\n const tx = await buildTransaction(\n this.chainId,\n [redeclarationIntent],\n [],\n this.account,\n currentBlock,\n asXL1BlockNumber(currentBlock + 1000, true),\n )\n\n // Submit the redeclaration intent\n await this.mempoolRunner.submitTransactions([tx])\n\n this.logger?.log('Submitted redeclaration intent for producer:', this.account.address)\n }\n\n protected async validateCurrentBalance(): Promise<boolean> {\n // Check if we have a valid balance before declaring intent\n const head = (await this.blockViewer.currentBlock())?.[0]?._hash\n if (isDefined(head)) {\n const balances = await this.accountBalanceViewer.accountBalances([this.account.address], { head })\n const currentBalance = balances[this.account.address] ?? 0n\n if (currentBalance <= 0n) {\n this.logger?.error(`Producer ${this.account.address} has no balance.`)\n return false\n }\n return true\n }\n return true\n }\n\n protected async validateCurrentStake(): Promise<boolean> {\n // Use StakeIntentService to get the required minimum stake\n const requiredMinimumStake = 1n // this.stakeIntentService.getRequiredMinimumStakeForIntent('producer')\n // Check if we have a valid stake before declaring intent\n const currentStake = await this.stakeTotalsViewer.activeByStaked(this.account.address)\n if (currentStake < requiredMinimumStake) {\n this.logger?.error(`Producer ${this.account.address} has insufficient stake.`)\n return false\n }\n return true\n }\n}\n","import {\n asAddress, exists, IdLogger,\n} from '@xylabs/sdk-js'\nimport { initProducerAccount, type OrchestratorInstance } from '@xyo-network/chain-orchestration'\nimport type {\n BaseContext, Config, ProviderFactoryLocatorInstance,\n} from '@xyo-network/xl1-sdk'\n\nimport { ProducerActor } from './ProducerActor.ts'\n\nexport interface RunProducerContext extends BaseContext {\n config: Config\n locator?: ProviderFactoryLocatorInstance\n orchestrator: OrchestratorInstance\n}\n\nexport const runProducer = async ({\n config, logger, orchestrator, locator,\n}: RunProducerContext) => {\n const localLogger = logger ?? new IdLogger(logger ?? console, () => 'ResolveHelper [runProducer]')\n const account = await initProducerAccount({ config })\n localLogger.info(`Running producer for account ${account.address}`)\n const rewardAddress = asAddress(config.producer.rewardAddress, () => 'rewardAddress is required in config.producer')\n localLogger.info(`Using reward address ${rewardAddress}`)\n\n // Create actors\n const producer = await ProducerActor.create({\n logger,\n context: {\n config, locator, singletons: {}, caches: {},\n },\n })\n const actors = [producer].filter(exists)\n\n for (const actor of actors) {\n // Register the actor with the orchestrator\n await orchestrator.registerActor(actor)\n }\n // Start the orchestrator => automatically activates the actor\n await orchestrator.start()\n}\n"],"mappings":";;;;AAEA,SACEA,WAAWC,UAAUC,WAAWC,WAAWC,aAAaC,aACnD;AACP,SAASC,wBAAwBC,4BAA4B;AAC7D,SAASC,iBAAiBC,2BAA2B;AACrD,SAASC,yBAAyB;AAClC,SAASC,uBAAuBC,kCAAkC;AAIlE,SACwBC,6BAA6BC,OAAoBC,kBAA+BC,oBAAiCC,oBACvIC,6BAA6BC,kBAA0BC,yBAAyBC,kBAAkBC,kBAAiCC,sBACpHC,sBAAoCC,yBAAyBC,6BAAgDC,gCAEvH;AACP,SAASC,aAAa;;;;;;;;AAMtB,IAAMC,6CAA6C;AACnD,IAAMC,cAAc,KAAK,KAAK;AAGvB,IAAMC,gBAAN,MAAMA,uBAAsBC,MAAAA;SAAAA;;;EACjC,OAAgBC,sBAAsB;EAE5BC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEFC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEAC,qBAAqB,IAAIC,MAAAA;EAEzBC;EAER,IAAcC,uBAAuB;AACnC,WAAO,KAAKT;EACd;EAEA,IAAcU,cAAc;AAC1B,WAAO,KAAKT;EACd;EAEA,IAAcU,cAAc;AAC1B,WAAO,KAAKT;EACd;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;EACT;EAEA,MAAgBuE,uBAAyC;AAEvD,UAAMa,uBAAuB;AAE7B,UAAMC,eAAe,MAAM,KAAK/F,kBAAkBgG,eAAe,KAAKzF,QAAQG,OAAO;AACrF,QAAIqF,eAAeD,sBAAsB;AACvC,WAAK5F,QAAQ8E,MAAM,YAAY,KAAKzE,QAAQG,OAAO,0BAA0B;AAC7E,aAAO;IACT;AACA,WAAO;EACT;AACF;;;;;;AC7VA,SACEuF,aAAAA,YAAWC,QAAQC,gBACd;AACP,SAASC,uBAAAA,4BAAsD;AAaxD,IAAMC,cAAc,8BAAO,EAChCC,QAAQC,QAAQC,cAAcC,QAAO,MAClB;AACnB,QAAMC,cAAcH,UAAU,IAAII,SAASJ,UAAUK,SAAS,MAAM,6BAAA;AACpE,QAAMC,UAAU,MAAMC,qBAAoB;IAAER;EAAO,CAAA;AACnDI,cAAYK,KAAK,gCAAgCF,QAAQG,OAAO,EAAE;AAClE,QAAMC,gBAAgBC,WAAUZ,OAAOa,SAASF,eAAe,MAAM,8CAAA;AACrEP,cAAYK,KAAK,wBAAwBE,aAAAA,EAAe;AAGxD,QAAME,WAAW,MAAMC,cAAcC,OAAO;IAC1Cd;IACAe,SAAS;MACPhB;MAAQG;MAASc,YAAY,CAAC;MAAGC,QAAQ,CAAC;IAC5C;EACF,CAAA;AACA,QAAMC,SAAS;IAACN;IAAUO,OAAOC,MAAAA;AAEjC,aAAWC,SAASH,QAAQ;AAE1B,UAAMjB,aAAaqB,cAAcD,KAAAA;EACnC;AAEA,QAAMpB,aAAasB,MAAK;AAC1B,GAxB2B;","names":["asAddress","assertEx","creatable","isDefined","isUndefined","toHex","EvmChainContractViewer","EvmStakeTotalsViewer","initEvmProvider","initProducerAccount","SimpleBlockRunner","validateHydratedBlock","validateHydratedBlockState","AccountBalanceViewerMoniker","Actor","asXL1BlockNumber","BlockRunnerMoniker","BlockViewerMoniker","buildJsonRpcProviderLocator","buildTransaction","createDeclarationIntent","getDefaultConfig","HttpRpcTransport","MempoolRunnerMoniker","MempoolViewerMoniker","SimpleBlockRewardViewer","SimpleBlockValidationViewer","StakeTotalsViewerMoniker","Mutex","SHOULD_REGISTER_REDECLARATION_INTENT_TIMER","TEN_MINUTES","ProducerActor","Actor","RedeclarationWindow","_lastProducedBlock","_lastRedeclarationIntent","_metricAttributes","_producerActorBlockProductionAttempts","_producerActorBlockProductionChecks","_producerActorBlocksProduced","_producerActorBlocksPublished","_accountBalanceViewer","_blockRunner","_blockViewer","_chainId","_mempoolRunner","_mempoolViewer","_produceBlockMutex","Mutex","_stakeTotalsViewer","accountBalanceViewer","blockRunner","blockViewer","chainId","mempoolRunner","mempoolViewer","rewardAddress","params","stakeTotalsViewer","paramsHandler","logger","context","config","getDefaultConfig","displayName","account","initProducerAccount","id","address","toString","info","warn","initContext","endpoint","assertEx","services","apiEndpoint","chain","transportFactory","schemas","HttpRpcTransport","locator","buildJsonRpcProviderLocator","runner","initEvmProvider","register","EvmChainContractViewer","factory","dependencies","asAddress","EvmStakeTotalsViewer","SimpleBlockRewardViewer","SimpleBlockValidationViewer","state","validateHydratedBlockState","protocol","validateHydratedBlock","SimpleBlockRunner","createHandler","meter","createCounter","description","getInstance","AccountBalanceViewerMoniker","BlockRunnerMoniker","BlockViewerMoniker","MempoolRunnerMoniker","MempoolViewerMoniker","StakeTotalsViewerMoniker","startHandler","registerTimer","produceBlock","redeclareIntent","calculateBlocksUntilProducerDeclarationExpiration","currentBlock","exp","add","spanAsync","isLocked","log","runExclusive","head","headHash","_hash","previous","toHex","block","nextBlock","next","displayBlockNumber","submitBlocks","timeBudgetLimit","producer","disableIntentRedeclaration","isUndefined","blocksUntilExpiration","undefined","validateCurrentBalance","error","validateCurrentStake","redeclarationIntent","createDeclarationIntent","RedeclarationDuration","submitRedeclarationIntent","tx","buildTransaction","asXL1BlockNumber","submitTransactions","isDefined","balances","accountBalances","currentBalance","requiredMinimumStake","currentStake","activeByStaked","asAddress","exists","IdLogger","initProducerAccount","runProducer","config","logger","orchestrator","locator","localLogger","IdLogger","console","account","initProducerAccount","info","address","rewardAddress","asAddress","producer","ProducerActor","create","context","singletons","caches","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.18.5",
3
+ "version": "1.19.0",
4
4
  "description": "XYO Layer One Producer",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -50,11 +50,11 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@xylabs/sdk-js": "~5.0.64",
53
- "@xyo-network/chain-ethereum": "~1.18.5",
54
- "@xyo-network/chain-orchestration": "~1.18.5",
55
- "@xyo-network/chain-services": "~1.18.5",
56
- "@xyo-network/chain-validation": "~1.18.5",
57
- "@xyo-network/xl1-sdk": "~1.19.6",
53
+ "@xyo-network/chain-ethereum": "~1.19.0",
54
+ "@xyo-network/chain-orchestration": "~1.19.0",
55
+ "@xyo-network/chain-services": "~1.19.0",
56
+ "@xyo-network/chain-validation": "~1.19.0",
57
+ "@xyo-network/xl1-sdk": "~1.20.2",
58
58
  "async-mutex": "~0.5.0"
59
59
  },
60
60
  "devDependencies": {
@@ -63,21 +63,21 @@
63
63
  "@types/cors": "~2.8.19",
64
64
  "@types/express": "5.0.6",
65
65
  "@types/express-serve-static-core": "~5.1.1",
66
- "@types/node": "~25.0.10",
66
+ "@types/node": "~25.1.0",
67
67
  "@xylabs/sdk-js": "~5.0.64",
68
68
  "@xylabs/ts-scripts-yarn3": "~7.3.2",
69
69
  "@xylabs/tsconfig": "~7.3.2",
70
- "@xyo-network/account": "~5.2.25",
71
- "@xyo-network/account-model": "~5.2.25",
72
- "@xyo-network/archivist-abstract": "~5.2.25",
73
- "@xyo-network/bios-model": "~7.2.0",
74
- "@xyo-network/boundwitness-builder": "~5.2.25",
75
- "@xyo-network/chain-services": "~1.18.5",
76
- "@xyo-network/chain-validation": "~1.18.5",
77
- "@xyo-network/module-abstract-mongodb": "~5.2.25",
78
- "@xyo-network/module-model-mongodb": "~5.2.25",
79
- "@xyo-network/node-memory": "~5.2.25",
80
- "@xyo-network/xl1-sdk": "~1.19.6",
70
+ "@xyo-network/account": "~5.3.2",
71
+ "@xyo-network/account-model": "~5.3.2",
72
+ "@xyo-network/archivist-abstract": "~5.3.2",
73
+ "@xyo-network/bios-model": "~7.2.1",
74
+ "@xyo-network/boundwitness-builder": "~5.3.2",
75
+ "@xyo-network/chain-services": "~1.19.0",
76
+ "@xyo-network/chain-validation": "~1.19.0",
77
+ "@xyo-network/module-abstract-mongodb": "~5.3.2",
78
+ "@xyo-network/module-model-mongodb": "~5.3.2",
79
+ "@xyo-network/node-memory": "~5.3.2",
80
+ "@xyo-network/xl1-sdk": "~1.20.2",
81
81
  "dotenv": "~17.2.3",
82
82
  "eslint": "^9.39.2",
83
83
  "nodemon": "~3.1.11",
@@ -1,35 +1,19 @@
1
1
  import type { Attributes, Counter } from '@opentelemetry/api'
2
2
  import type { Address } from '@xylabs/sdk-js'
3
3
  import {
4
- asAddress,
5
- assertEx,
6
- creatable, isDefined, isUndefined, toHex,
4
+ asAddress, assertEx, creatable, isDefined, isUndefined, toHex,
7
5
  } from '@xylabs/sdk-js'
8
6
  import { EvmChainContractViewer, EvmStakeTotalsViewer } from '@xyo-network/chain-ethereum'
9
7
  import { initEvmProvider, initProducerAccount } from '@xyo-network/chain-orchestration'
10
8
  import { SimpleBlockRunner } from '@xyo-network/chain-services'
11
9
  import { validateHydratedBlock, validateHydratedBlockState } from '@xyo-network/chain-validation'
12
10
  import type {
13
- ChainId,
14
- ChainStakeIntent, HydratedBlockWithHashMeta,
15
- XL1BlockNumber,
11
+ ChainId, ChainStakeIntent, HydratedBlockWithHashMeta, XL1BlockNumber,
16
12
  } from '@xyo-network/xl1-sdk'
17
13
  import {
18
- AccountBalanceViewer, AccountBalanceViewerMoniker, Actor, ActorParams, asXL1BlockNumber,
19
- BlockRunner, BlockRunnerMoniker,
20
- BlockViewer, BlockViewerMoniker, buildJsonRpcProviderLocator,
21
- buildTransaction,
22
- Config,
23
- createDeclarationIntent,
24
- getDefaultConfig,
25
- HttpRpcTransport, MempoolRunner,
26
- MempoolRunnerMoniker,
27
- MempoolViewer,
28
- MempoolViewerMoniker,
29
- RpcSchemaMap, SimpleBlockRewardViewer,
30
- SimpleBlockValidationViewer,
31
- StakeTotalsViewer,
32
- StakeTotalsViewerMoniker,
14
+ AccountBalanceViewer, AccountBalanceViewerMoniker, Actor, ActorParams, asXL1BlockNumber, BlockRunner, BlockRunnerMoniker, BlockViewer, BlockViewerMoniker,
15
+ buildJsonRpcProviderLocator, buildTransaction, Config, createDeclarationIntent, getDefaultConfig, HttpRpcTransport, MempoolRunner, MempoolRunnerMoniker,
16
+ MempoolViewer, MempoolViewerMoniker, RpcSchemaMap, SimpleBlockRewardViewer, SimpleBlockValidationViewer, StakeTotalsViewer, StakeTotalsViewerMoniker,
33
17
  TransportFactory,
34
18
  } from '@xyo-network/xl1-sdk'
35
19
  import { Mutex } from 'async-mutex'
@@ -251,7 +235,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
251
235
  }
252
236
  }
253
237
  })
254
- }, { timeBudgetLimit: 1000 })
238
+ }, { ...this.context, timeBudgetLimit: 1000 })
255
239
  }
256
240
 
257
241
  protected async redeclareIntent(): Promise<void> {
@@ -316,7 +300,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
316
300
 
317
301
  // On successful submission, save the redeclaration intent
318
302
  this._lastRedeclarationIntent = redeclarationIntent
319
- }, { timeBudgetLimit: 1000 })
303
+ }, { ...this.context, timeBudgetLimit: 1000 })
320
304
  }
321
305
 
322
306
  protected async submitRedeclarationIntent(currentBlock: XL1BlockNumber, redeclarationIntent: ChainStakeIntent): Promise<void> {
@@ -339,7 +323,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
339
323
 
340
324
  protected async validateCurrentBalance(): Promise<boolean> {
341
325
  // Check if we have a valid balance before declaring intent
342
- const head = this._lastProducedBlock?.[0]._hash
326
+ const head = (await this.blockViewer.currentBlock())?.[0]?._hash
343
327
  if (isDefined(head)) {
344
328
  const balances = await this.accountBalanceViewer.accountBalances([this.account.address], { head })
345
329
  const currentBalance = balances[this.account.address] ?? 0n