From b5e35f71bbf34fb5337df04d299425277eb20825 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Wed, 22 Jan 2025 19:31:49 +0000 Subject: [PATCH] Rework StartOS config to support non-pooled mining properly Co-authored-by: Shadowy Super Coder --- docker_entrypoint.sh | 20 +++++++++++++-- manifest.yaml | 2 +- scripts/procedures/getConfig.ts | 21 +++++++++++----- scripts/procedures/migrations.ts | 43 +++++++++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 8558020..adf6da0 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -11,7 +11,23 @@ else echo "blocknotify is set to: $blocknotify" fi -yq eval -o=json /root/start9/config.yaml > /root/data/datum_gateway_config.json +filter='.' +case $(yq eval .datum.reward_sharing /root/start9/config.yaml) in +require) + filter="${filter}"'|.datum.pooled_mining_only=true' + ;; +prefer) + filter="${filter}"'|.datum.pooled_mining_only=false' + ;; +never) + filter="${filter}"'|.datum.pooled_mining_only=false' + filter="${filter}"'|.datum.pool_host=""' + ;; +esac +yq eval -o=json \ + "${filter}" \ + /root/start9/config.yaml \ + > /root/data/datum_gateway_config.json printf "\n\n [i] Starting Datum Gateway ...\n\n" -exec datum_gateway -c /root/data/datum_gateway_config.json \ No newline at end of file +exec datum_gateway -c /root/data/datum_gateway_config.json diff --git a/manifest.yaml b/manifest.yaml index f6c5709..b15aa0e 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -5,7 +5,7 @@ id: datum # A human readable service title title: "Datum Gateway" # Service version - accepts up to four digits, where the last confirms to revisions necessary for StartOS - see documentation: https://github.com/Start9Labs/emver-rs. This value will change with each release of the service. -version: 0.2.2 +version: 0.2.2.1 # Release notes for the update - can be a string, paragraph or URL release-notes: | - Bug Fixes diff --git a/scripts/procedures/getConfig.ts b/scripts/procedures/getConfig.ts index c4fd90b..303f75e 100644 --- a/scripts/procedures/getConfig.ts +++ b/scripts/procedures/getConfig.ts @@ -335,12 +335,21 @@ export const getConfig: T.ExpectedExports.getConfig = compat.getConfig({ // default: false, // nullable: true, // }, - pooled_mining_only: { - type: "boolean", - name: "Pooled Mining Only", - description: "If the DATUM pool server becomes unavailable, terminate miner connections (otherwise, 100% of any blocks you find pay mining.pool_address) (boolean, default: true)", - default: true, - nullable: true, + reward_sharing: { + type: "enum", + values: [ + "require", + "prefer", + "never", + ], + name: "Collaborative reward sharing (pooled mining)", + description: "You can share rewards and share in others' rewards - or only get rewarded when you find a block yourself.", + "value-names": { + require: "require (pooled mining only)", + prefer: "prefer (failover to non-pooled)", + never: "never (non-pooled only)", + }, + default: "require", }, }, }, diff --git a/scripts/procedures/migrations.ts b/scripts/procedures/migrations.ts index 110df3b..be1669f 100644 --- a/scripts/procedures/migrations.ts +++ b/scripts/procedures/migrations.ts @@ -1,5 +1,34 @@ import { compat, matches, types as T } from "../deps.ts"; +function migrate_022_to_0221(config: any) { + if (config.datum.pooled_mining_only) { + config.datum.reward_sharing = 'require'; + } else if (config.datum.pool_host) { + config.datum.reward_sharing = 'prefer'; + } else { + config.datum.reward_sharing = 'never'; + } + delete config.datum.pooled_mining_only; + return config; +} + +function migrate_0221_to_022(config: any) { + if (config.datum.reward_sharing == 'require') { + config.datum.pooled_mining_only = true; + } else { + config.datum.pooled_mining_only = false; + if (config.datum.reward_sharing == 'prefer') { + if (!config.datum.pool_host) { + config.datum.pool_host = 'datum-beta1.mine.ocean.xyz'; + } + } else { // config.datum.reward_sharing == 'never' + config.datum.pool_host = null; + } + } + delete config.datum.reward_sharing; + return config; +} + export const migration: T.ExpectedExports.migration = compat.migrations.fromMapping( { @@ -19,6 +48,18 @@ export const migration: T.ExpectedExports.migration = { version: "0.2.1", type: "down" } ), }, + "0.2.2.1": { + up: compat.migrations.updateConfig( + migrate_022_to_0221, + true, + { version: "0.2.2.1", type: "up"} + ), + down: compat.migrations.updateConfig( + migrate_0221_to_022, + true, + { version: "0.2.2.1", type: "down"} + ) + } }, - "0.2.2" + "0.2.2.1" );