From c0caab57d474876c0ea6e74d15575d751ffb7a89 Mon Sep 17 00:00:00 2001 From: Remco Ros Date: Fri, 4 Oct 2024 19:01:10 +0000 Subject: [PATCH] remove public-pool patch in favor or restarting the container when the main process crashes. --- Dockerfile | 6 ---- docker_entrypoint.sh | 13 ++++++-- patches/public-pool.patch | 65 --------------------------------------- 3 files changed, 11 insertions(+), 73 deletions(-) delete mode 100644 patches/public-pool.patch diff --git a/Dockerfile b/Dockerfile index ea2d297..9a28246 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,12 +32,6 @@ RUN \ # apply patch for rpc-bitcoin (see: https://github.com/vansergen/rpc-bitcoin/pull/65) COPY patches/rpc-bitcoin+2.0.0.patch /build/public-pool/patches/rpc-bitcoin+2.0.0.patch -# Apply patches not included in upstream repo (yet) -COPY patches/public-pool.patch /build/public-pool/public-pool.patch -RUN \ - cd public-pool && \ - git apply public-pool.patch - RUN \ cd public-pool && \ npm ci && \ diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 1258462..cfaf1d3 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -55,7 +55,7 @@ app_process=$! nginx -g "daemon off;" & proxy_process=$! -# hook the TERM signal and wait for all our processes +# hook the TERM signal and wait _term() { echo "Caught TERM signal!" kill -TERM "$proxy_process" 2>/dev/null @@ -63,4 +63,13 @@ _term() { } trap _term TERM -wait $app_process $proxy_process + +# wait for one of the processes to finish (or crash) +wait -n $app_process $proxy_process +status=$? + +# terminate the rest of processes +kill -TERM "$proxy_process" 2>/dev/null +kill -TERM "$app_process" 2>/dev/null + +exit $status \ No newline at end of file diff --git a/patches/public-pool.patch b/patches/public-pool.patch deleted file mode 100644 index 60ef788..0000000 --- a/patches/public-pool.patch +++ /dev/null @@ -1,65 +0,0 @@ -diff --git a/src/services/bitcoin-rpc.service.ts b/src/services/bitcoin-rpc.service.ts -index 2625a7f..14bdfda 100644 ---- a/src/services/bitcoin-rpc.service.ts -+++ b/src/services/bitcoin-rpc.service.ts -@@ -102,34 +102,36 @@ export class BitcoinRpcService implements OnModuleInit { - - public async getBlockTemplate(blockHeight: number): Promise { - let result: IBlockTemplate; -- try { -- const block = await this.rpcBlockService.getBlock(blockHeight); -- const completeBlock = block?.data != null; -- -- // If the block has already been loaded, and the same instance is fetching the template again, we just need to refresh it. -- if (completeBlock && block.lockedBy == process.env.NODE_APP_INSTANCE) { -- result = await this.loadBlockTemplate(blockHeight); -- } -- else if (completeBlock) { -- return Promise.resolve(JSON.parse(block.data)); -- } else if (!completeBlock) { -- if (process.env.NODE_APP_INSTANCE != null) { -- // There is a unique constraint on the block height so if another process tries to lock, it'll throw -- try { -- await this.rpcBlockService.lockBlock(blockHeight, process.env.NODE_APP_INSTANCE); -- } catch (e) { -- result = await this.waitForBlock(blockHeight); -+ while (result == null) { -+ try { -+ const block = await this.rpcBlockService.getBlock(blockHeight); -+ const completeBlock = block?.data != null; -+ -+ // If the block has already been loaded, and the same instance is fetching the template again, we just need to refresh it. -+ if (completeBlock && block.lockedBy == process.env.NODE_APP_INSTANCE) { -+ result = await this.loadBlockTemplate(blockHeight); -+ } -+ else if (completeBlock) { -+ return Promise.resolve(JSON.parse(block.data)); -+ } else if (!completeBlock) { -+ if (process.env.NODE_APP_INSTANCE != null) { -+ // There is a unique constraint on the block height so if another process tries to lock, it'll throw -+ try { -+ await this.rpcBlockService.lockBlock(blockHeight, process.env.NODE_APP_INSTANCE); -+ } catch (e) { -+ result = await this.waitForBlock(blockHeight); -+ } - } -+ result = await this.loadBlockTemplate(blockHeight); -+ } else { -+ //wait for block -+ result = await this.waitForBlock(blockHeight); - } -- result = await this.loadBlockTemplate(blockHeight); -- } else { -- //wait for block -- result = await this.waitForBlock(blockHeight); -+ } catch (e) { -+ console.error('Error getblocktemplate:', e.message); - } -- } catch (e) { -- console.error('Error getblocktemplate:', e.message); -- throw new Error('Error getblocktemplate'); - } -+ - console.log(`getblocktemplate tx count: ${result.transactions.length}`); - return result; - }