Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standalone replay executable #1978

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
79 changes: 44 additions & 35 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,28 @@ custom-setup

library
import: warning-flags, debugging-flags
default-language: Haskell2010
hs-source-dirs: src
default-language:
Haskell2010
hs-source-dirs:
src
other-modules:
Paths_chainweb
PkgInfo
Utils.CheckRLimits
Utils.InstallSignalHandlers
autogen-modules:
Paths_chainweb
c-sources: c/shathree.c
cc-options: -DSQLITE_CORE
PkgInfo
c-sources:
c/shathree.c
c/rlim_utils.c
install-includes:
c/rlim_utils.h
cc-options:
-DSQLITE_CORE
exposed-modules:
Chainweb.Backup
ChainwebNode
, Chainweb.Backup
, Chainweb.BlockCreationTime
, Chainweb.BlockHash
, Chainweb.BlockHeader
Expand Down Expand Up @@ -359,7 +371,7 @@ library
, Utils.Logging.Trace

build-depends:
Decimal >= 0.4.2
, Decimal >= 0.4.2
, aeson >= 2.2
, asn1-encoding >=0.9
, asn1-types >=0.3
Expand All @@ -375,7 +387,6 @@ library
, chainweb-storage >= 0.1
, clock >= 0.7
, configuration-tools >= 0.6
, crypton-connection >= 0.2 && < 0.4
, containers >= 0.5
, crypton >= 0.31
, crypton-connection >= 0.2 && < 0.4
Expand All @@ -400,15 +411,16 @@ library
, hashable >= 1.4
, heaps >= 0.3
, hourglass >=0.2
, http2 >= 5.2.1
, http-client >= 0.5
, http-client-tls >=0.3
, http-media >= 0.7
, http-types >= 0.12
, http2 >= 5.2.1
, iproute >= 1.7
, ixset-typed >= 0.4
, lens >= 4.17
, loglevel >= 0.1
, managed >= 1.0
, memory >=0.14
, merkle-log >=0.2
, mmorph >= 1.1
Expand Down Expand Up @@ -463,6 +475,10 @@ library
, yaml >= 0.11
, yet-another-logger >= 0.4.1

if !os(windows)
build-depends:
unix >= 2.7

if flag(ed25519)
cpp-options: -DWITH_ED25519=1
if flag(ghc-flags)
Expand Down Expand Up @@ -652,42 +668,35 @@ executable chainweb-node
"-with-rtsopts=-N -H1G -A64M --disable-delayed-os-memory-return"
-rtsopts
hs-source-dirs: node
main-is: ChainwebNode.hs
install-includes: node/c/rlim_utils.h
c-sources: node/c/rlim_utils.c
other-modules:
Paths_chainweb
PkgInfo
Utils.CheckRLimits
Utils.InstallSignalHandlers
autogen-modules:
Paths_chainweb
PkgInfo
main-is: Main.hs
build-depends:
-- internal
chainweb
, chainweb

-- external
, base >= 4.12 && < 5

executable replay
import: warning-flags, debugging-flags

default-language: Haskell2010
ghc-options:
-threaded
"-with-rtsopts=-N -H1G -A64M --disable-delayed-os-memory-return"
-rtsopts
hs-source-dirs: replay
main-is: Main.hs
build-depends:
-- internal
, chainweb

-- external
, async >= 2.2
, base >= 4.12 && < 5
, chainweb-storage >= 0.1
, configuration-tools >= 0.6
, deepseq >= 1.4
, directory >= 1.3
, filepath >= 1.4
, http-client >= 0.5
, http-client-tls >=0.3
, lens >= 4.17
, loglevel >= 0.1
, managed >= 1.0
, streaming >= 0.2
, optparse-applicative >= 0.14
, text >= 2.0
, time >= 1.12.2
, yet-another-logger >= 0.4.1

if !os(windows)
build-depends:
unix >= 2.7

executable cwtool
import: warning-flags, debugging-flags
Expand Down
9 changes: 9 additions & 0 deletions node/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE ImportQualifiedPost #-}

module Main (main) where

import ChainwebNode qualified

main :: IO ()
main = do
ChainwebNode.main
96 changes: 96 additions & 0 deletions replay/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{-# language
ImportQualifiedPost
, OverloadedRecordDot
, OverloadedStrings
, ScopedTypeVariables
#-}

module Main (main) where

import Chainweb.BlockHeight (BlockHeight(..))
import Chainweb.Chainweb (ChainwebStatus(..))
import Chainweb.Chainweb.Configuration (ChainwebConfiguration(..), defaultChainwebConfiguration, defaultCutConfig, configP2p, configReadOnlyReplay, configFullHistoricPactState, configOnlySyncPact, configCuts, cutInitialBlockHeightLimit, cutFastForwardBlockHeightLimit)
import Chainweb.Logger (logFunctionJson, logFunctionText)
import Chainweb.Utils (fromText)
import Chainweb.Version (ChainwebVersion(..))
import Chainweb.Version.Mainnet (mainnet)
import Chainweb.Version.Registry (lookupVersionByName, registerVersion)
import ChainwebNode (ChainwebNodeConfiguration(..), defaultChainwebNodeConfiguration, nodeConfigDatabaseDirectory, nodeConfigChainweb, node, withNodeLogger, withServiceDate)
import Control.Applicative (optional)
import Control.Exception (SomeException, SomeAsyncException, Handler(..), catches, throwIO)
import Control.Lens ((?~), (.~))
import Data.Function ((&))
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Time.Format.ISO8601 (iso8601ParseM)
import Options.Applicative qualified as O
import P2P.Node.Configuration (defaultP2pConfiguration, p2pConfigBootstrapReachability, p2pConfigIgnoreBootstrapNodes, p2pConfigPrivate)
import System.IO qualified as IO
import System.LogLevel (LogLevel(..))

main :: IO ()
main = do
cfg <- getConfig
let nodeConfig = mkReplayConfiguration cfg
registerVersion cfg.chainwebVersion
IO.hSetBuffering IO.stderr IO.LineBuffering
withNodeLogger (_nodeConfigLog nodeConfig) (_nodeConfigChainweb nodeConfig) cfg.chainwebVersion $ \logger -> do
logFunctionJson logger Info ProcessStarted
flip catches
[ Handler $ \(e :: SomeAsyncException) ->
logFunctionJson logger Info (ProcessDied $ show e) >> throwIO e
, Handler $ \(e :: SomeException) ->
logFunctionJson logger Error (ProcessDied $ show e) >> throwIO e
] $ do
kt <- mapM iso8601ParseM (_versionServiceDate cfg.chainwebVersion)
withServiceDate (_configChainwebVersion (_nodeConfigChainweb nodeConfig)) (logFunctionText logger) kt $ node nodeConfig logger

mkReplayConfiguration :: Config -> ChainwebNodeConfiguration
mkReplayConfiguration cfg = defaultChainwebNodeConfiguration
& nodeConfigDatabaseDirectory ?~ cfg.databaseDir
& nodeConfigChainweb .~ cwConfig
where
cwConfig = defaultChainwebConfiguration mainnet
& configReadOnlyReplay .~ not cfg.noReadOnly
& configOnlySyncPact .~ cfg.noReadOnly
& configCuts .~ cutConfig
& configP2p .~ p2pConfig
& configFullHistoricPactState .~ False

cutConfig = defaultCutConfig
& cutInitialBlockHeightLimit .~ cfg.initialBlockHeightLimit
& cutFastForwardBlockHeightLimit .~ cfg.fastForwardBlockHeightLimit

p2pConfig = defaultP2pConfiguration
& p2pConfigBootstrapReachability .~ 0
& p2pConfigIgnoreBootstrapNodes .~ True
& p2pConfigPrivate .~ True

data Config = Config
{ chainwebVersion :: ChainwebVersion
, noReadOnly :: Bool
, databaseDir :: FilePath
, initialBlockHeightLimit :: Maybe BlockHeight
, fastForwardBlockHeightLimit :: Maybe BlockHeight
}

getConfig :: IO Config
getConfig = do
O.execParser opts
where
opts :: O.ParserInfo Config
opts = O.info (parser O.<**> O.helper) (O.fullDesc <> O.progDesc "Chainweb Replay tool")

parser :: O.Parser Config
parser = Config
<$> (parseVersion <$> O.strOption (O.long "chainweb-version" <> O.help "chainweb version (e.g. mainnet01, testnet04)" <> O.value "mainnet01"))
<*> O.switch (O.long "no-read-only" <> O.help "Don't run in read-only mode")
<*> O.strOption (O.long "database-dir" <> O.help "Path to the database directory")
<*> optional (BlockHeight <$> O.option O.auto (O.long "initial-block-height-limit" <> O.help "Initial block height limit"))
<*> optional (BlockHeight <$> O.option O.auto (O.long "fast-forward-block-height-limit" <> O.help "Fast forward block height limit"))

parseVersion :: Text -> ChainwebVersion
parseVersion =
lookupVersionByName
. fromMaybe (error "ChainwebVersion parse failed")
. fromText
1 change: 1 addition & 0 deletions src/Chainweb/Chainweb/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module Chainweb.Chainweb.Configuration
, configOnlySyncPact
, configSyncPactChains
, configEnableLocalTimeout
, configReadOnlyReplay
, defaultChainwebConfiguration
, pChainwebConfiguration
, validateChainwebConfiguration
Expand Down
12 changes: 8 additions & 4 deletions node/ChainwebNode.hs → src/ChainwebNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@

-- |
-- Module: ChainwebNode
-- Copyright: Copyright © 2018 Kadena LLC.
-- Copyright: Copyright © 2024 Kadena LLC.
-- License: MIT
-- Maintainer: Lars Kuhtz <[email protected]>
-- Stability: experimental
--
-- TODO
--
module Main
module ChainwebNode
(
-- * Configuration
ChainwebNodeConfiguration(..)
, defaultChainwebNodeConfiguration
, nodeConfigChainweb
, nodeConfigLog
, nodeConfigDatabaseDirectory
, nodeConfigResetChainDbs

-- * Monitor
, runCutMonitor
Expand All @@ -40,6 +43,7 @@ module Main
-- * Chainweb Node
, node
, withNodeLogger
, withServiceDate

-- * Main function
, main
Expand Down
1 change: 1 addition & 0 deletions src/P2P/Node/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module P2P.Node.Configuration
, p2pConfigKnownPeers
, p2pConfigIgnoreBootstrapNodes
, p2pConfigBootstrapReachability
, p2pConfigPrivate
, defaultP2pConfiguration
, validateP2pConfiguration
, pP2pConfiguration
Expand Down
File renamed without changes.
File renamed without changes.
Loading