Skip to content

Commit

Permalink
check host architecture when production mining is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
larskuhtz committed Aug 8, 2024
1 parent 848bced commit 6af6cc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Chainweb/Chainweb/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ instance HasChainwebVersion ChainwebConfiguration where

validateChainwebConfiguration :: ConfigValidation ChainwebConfiguration []
validateChainwebConfiguration c = do
validateMinerConfig (_configMining c)
validateMinerConfig (_configChainwebVersion c) (_configMining c)
validateBackupConfig (_configBackup c)
unless (c ^. chainwebVersion . versionDefaults . disablePeerValidation) $
validateP2pConfiguration (_configP2p c)
Expand Down
41 changes: 30 additions & 11 deletions src/Chainweb/Miner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}

-- |
-- Module: Chainweb.Miner.Config
Expand Down Expand Up @@ -57,8 +58,12 @@ import Pact.Types.Term (mkKeySet, PublicKeyText(..))

import Chainweb.Miner.Pact (Miner(..), MinerKeys(..), MinerId(..), minerId)
import Chainweb.Time
import Chainweb.Utils (hostArch, sshow)
import Chainweb.Version
import Chainweb.Version.Mainnet
import Chainweb.Version.Testnet

---
-- -------------------------------------------------------------------------- --

-- | Strictly for testing.
--
Expand All @@ -69,20 +74,34 @@ newtype MinerCount = MinerCount { _minerCount :: Natural }
-- -------------------------------------------------------------------------- --
-- Mining Config

validateMinerConfig :: ConfigValidation MiningConfig []
validateMinerConfig c = do
when (_nodeMiningEnabled nmc) $ tell
[ "In-node mining is enabled. This should only be used for testing"
, "In order to use in-node mining, mining-coordination must be enabled, too"
]
when (_nodeMiningEnabled nmc && not (_coordinationEnabled cc))
$ throwError "In-node mining is enabled but mining coordination is disabled"
when (_nodeMiningEnabled nmc && view minerId (_nodeMiner nmc) == "")
$ throwError "In-node Mining is enabled but no miner id is configured"
validateMinerConfig :: ChainwebVersion -> ConfigValidation MiningConfig []
validateMinerConfig v c = do
when (_nodeMiningEnabled nmc) $ do
tell
[ "In-node mining is enabled. This should only be used for testing"
, "In order to use in-node mining, mining-coordination must be enabled, too"
]
when (not (_coordinationEnabled cc))
$ throwError "In-node mining is enabled but mining coordination is disabled"
when (view minerId (_nodeMiner nmc) == "")
$ throwError "In-node Mining is enabled but no miner id is configured"

when (_coordinationEnabled cc && isProd) $ do
when (hostArch `notElem` supportedArchs) $ do
throwError $ mconcat
[ "Unsupported host architecture for mining on production networks: " <> sshow hostArch <> "."
, " Supported architectures are " <> sshow supportedArchs
]
where
nmc = _miningInNode c
cc = _miningCoordination c

-- This is a heuristic and we are rather a little too restrictiv. In the
-- future we may also consider uname -m and/or cpuinfo (including flags) here.
--
supportedArchs = [ "x86_64" ]
isProd = v `elem` [Mainnet01, Testnet04]

-- | Full configuration for Mining.
--
data MiningConfig = MiningConfig
Expand Down

0 comments on commit 6af6cc1

Please sign in to comment.