From 6babc527f572130d781644314b4ef9eaf5302314 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 13:01:59 -0800 Subject: [PATCH] Since pow is already so expensive, the overhead of creating workers is negligible, so spin up a new pool when calculating and dismiss it when finished. --- src/lib/block.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 3499762..1e409f9 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -16,7 +16,6 @@ import { Pow } from './workers.js' * of three derived classes: SendBlock, ReceiveBlock, ChangeBlock. */ abstract class Block { - #pool: Pool account: Account type: string = 'state' abstract subtype: 'send' | 'receive' | 'change' @@ -38,7 +37,6 @@ abstract class Block { } else { throw new TypeError('Invalid account') } - this.#pool = new Pool(Pow) } /** @@ -84,11 +82,13 @@ abstract class Block { * A successful response sets the `work` property. */ async pow (): Promise { + const pool = new Pool(Pow) const data = { "hash": this.previous } - const [{ work }] = await this.#pool.work('converge', [data]) + const [{ work }] = await pool.work('converge', [data]) this.work = work + pool.dismiss() } /** -- 2.34.1