Skip to content

Commit

Permalink
Fix Multinode tests (#1133)
Browse files Browse the repository at this point in the history
* fix multi-node tests

* just use defaults

* use correct bootstrap config

* whitespace

* small fixes

* fix pact db location in multinode tests

Co-authored-by: Lars Kuhtz <[email protected]>
  • Loading branch information
emilypi and larskuhtz authored Aug 8, 2020
1 parent 512debe commit 02ca529
Showing 1 changed file with 61 additions and 5 deletions.
66 changes: 61 additions & 5 deletions test/Chainweb/Test/MultiNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import Chainweb.Cut
import Chainweb.CutDB
import Chainweb.Graph
import Chainweb.Logger
import Chainweb.Miner.Config
import Chainweb.Miner.Pact
import Chainweb.Test.P2P.Peer.BootstrapConfig
import Chainweb.Test.Utils
import Chainweb.Time (Seconds(..))
import Chainweb.Utils
Expand Down Expand Up @@ -112,22 +115,73 @@ import P2P.Peer
multiConfig
:: ChainwebVersion
-> Natural
-- ^ number of nodes
-- ^ number of node
-> ChainwebConfiguration
multiConfig v n = config v n
multiConfig v n = defaultChainwebConfiguration v
& set (configP2p . p2pConfigPeer . peerConfigHost) host
& set (configP2p . p2pConfigPeer . peerConfigInterface) interface
-- Only listen on the loopback device. On Mac OS X this prevents the
-- firewall dialog form poping up.

& set (configP2p . p2pConfigKnownPeers) mempty
& set (configP2p . p2pConfigIgnoreBootstrapNodes) True
-- The bootstrap peer info is set later after the bootstrap nodes
-- has started and got its port assigned.

& set (configP2p . p2pConfigMaxPeerCount) (n * 2)
-- We make room for all test peers in peer db.

& set (configP2p . p2pConfigMaxSessionCount) 4
-- We set this to a low number in order to keep the network sparse (or
-- at last no being a clique) and to also limit the number of
-- port allocations

& set (configP2p . p2pConfigSessionTimeout) 20
-- Use short sessions to cover session timeouts and setup logic in the
-- test.

& set (configMining . miningInNode) miner

& set configReintroTxs True
-- enable transaction re-introduction

& set (configTransactionIndex . enableConfigEnabled) True
-- enable transaction index

& set configThrottling throttling
-- throttling is effectively disabled to not slow down the test nodes
where
miner = NodeMiningConfig
{ _nodeMiningEnabled = True
, _nodeMiner = noMiner
, _nodeTestMiners = MinerCount n
}

throttling = defaultThrottlingConfig
{ _throttlingRate = 10_000 -- per second
, _throttlingMiningRate = 10_000 -- per second
, _throttlingPeerRate = 10_000 -- per second, one for each p2p network
, _throttlingLocalRate = 10_000 -- per 10 seconds
}

-- | Configure a bootstrap node
--
multiBootstrapConfig
:: ChainwebConfiguration
-> ChainwebConfiguration
multiBootstrapConfig conf = conf
& set (configP2p . p2pConfigPeer) peerConfig
& set (configP2p . p2pConfigKnownPeers) []
where
peerConfig = (head $ bootstrapPeerConfig $ _configChainwebVersion conf)
& set peerConfigPort 0
-- Normally, the port of bootstrap nodes is hard-coded. But in
-- test-suites that may run concurrently we want to use a port that is
-- assigned by the OS.

& set peerConfigHost host
& set peerConfigInterface interface

-- -------------------------------------------------------------------------- --
-- Minimal Node Setup that logs conensus state to the given mvar

Expand All @@ -142,8 +196,8 @@ multiNode
-- ^ Unique node id. Node id 0 is used for the bootstrap node
-> IO ()
multiNode loglevel write stateVar bootstrapPeerInfoVar conf rdb nid = do
withSystemTempDirectory "multiNode-pact-db" $ \pactDbDir ->
withChainweb conf logger nodeRocksDb pactDbDir False $ \cw -> do
withSystemTempDirectory "multiNode-pact-db" $ \tmpDir ->
withChainweb conf logger nodeRocksDb (pactDbDir tmpDir) False $ \cw -> do

-- If this is the bootstrap node we extract the port number and
-- publish via an MVar.
Expand All @@ -155,6 +209,8 @@ multiNode loglevel write stateVar bootstrapPeerInfoVar conf rdb nid = do
sample cw
logFunctionText logger Info "shutdown node"
where
pactDbDir tmpDir = tmpDir <> "/" <> show nid

logger :: GenericLogger
logger = addLabel ("node", toText nid) $ genericLogger loglevel write

Expand Down Expand Up @@ -199,7 +255,7 @@ runNodes loglevel write stateVar v n =
let baseConf = multiConfig v n
conf <- if
| i == 0 ->
return $ bootstrapConfig baseConf
return $ multiBootstrapConfig baseConf
| otherwise ->
setBootstrapPeerInfo <$> readMVar bootstrapPortVar <*> pure baseConf

Expand Down

0 comments on commit 02ca529

Please sign in to comment.