Skip to content
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
35 changes: 19 additions & 16 deletions src/Chainweb/Chainweb/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ import Chainweb.BlockHeight
import Chainweb.Difficulty
import Chainweb.HostAddress
import Chainweb.Miner.Config
import Chainweb.Pact.Types (RewindLimit)
import Chainweb.Pact.Types (defaultReorgLimit)
import Chainweb.Pact.Types (RewindLimit, defaultReorgLimit)
import Chainweb.Pact.Payload.RestAPI (PayloadBatchLimit(..), defaultServicePayloadBatchLimit)
import Chainweb.PayloadProvider.EVM (EvmProviderConfig, pEvmProviderConfig, defaultEvmProviderConfig, validateEvmProviderConfig)
import Chainweb.PayloadProvider.Minimal (MinimalProviderConfig, defaultMinimalProviderConfig, pMinimalProviderConfig)
Expand Down Expand Up @@ -161,7 +160,7 @@ validatePayloadProviderConfig conf = do
PactProvider -> return () -- FIXME implement validation
e -> do
tell [ "Pact provider configured for chain " <> sshow cid <> ": " <> sshow conf ]
throwError $ mconcat $
throwError $ mconcat
[ "Wrong payload provider type configuration for chain " <> sshow cid
, ". Expected " <> sshow e <> " but found Pact"
]
Expand All @@ -170,7 +169,7 @@ validatePayloadProviderConfig conf = do
EvmProvider _ -> validateEvmProviderConfig cid _conf
e -> do
tell [ "EVM provider configured for chain " <> sshow cid <> ": " <> sshow conf ]
throwError $ mconcat $
throwError $ mconcat
[ "Wrong payload provider type configuration for chain " <> sshow cid
, ". Expected " <> sshow e <> " but found EVM"
]
Expand Down Expand Up @@ -209,8 +208,10 @@ instance ToJSON PayloadProviderConfig where
--
instance FromJSON (PayloadProviderConfig -> PayloadProviderConfig) where
parseJSON = withObject "PayloadProviderConfig" $ \o -> do
updateMinimal <- payloadProviderConfigMinimal %.: "default" % o
ifoldlM go updateMinimal (KM.toMapText o)
updateMinimal <- jlabel "minimalPayloadProviderConfig" $
payloadProviderConfigMinimal %.: "default" % o
jlabel "payloadProviderConfig" $
ifoldlM go updateMinimal (KM.toMapText o)
where
parseKey k = case T.stripPrefix "chain-" k of
Nothing -> fail $ "failed to parse chain key: " <> sshow k
Expand All @@ -220,27 +221,29 @@ instance FromJSON (PayloadProviderConfig -> PayloadProviderConfig) where
Right _ -> fail $ "trailng garabage when parsing chain value: " <> sshow x

go "default" c _ = return c
go k c v = do
cid <- parseKey k
go2 cid c v
go k c v = jlabel k $ do
cid <- jlabel k $ parseKey k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one right?

jlabel ("chain:" <> toText cid) $ go2 cid c v

-- disable provider:
go2 cid c Null = return $ (payloadProviderConfigPact . at cid .~ Nothing) . c
go2 cid c Null = jlabel "provider:null" $
return ((payloadProviderConfigPact . at cid .~ Nothing) . c)

-- enabled provider:
go2 cid c v = flip (withObject ("ProviderConfig for chain " <> sshow cid)) v $ \o -> do
(o .: "type") >>= \case
"pact" -> do
"pact" -> jlabel "provider:pact" $ do
x <- parseJSON (Object o)
let f Nothing = Just (x defaultPactProviderConfig)
f (Just y) = Just (x y)
return $ (payloadProviderConfigPact . at cid %~ f) . c
"evm" -> do
"evm" -> jlabel "provider:evm" $ do
x <- parseJSON (Object o)
let f Nothing = Just (x defaultEvmProviderConfig)
f (Just y) = Just (x y)
return $ (payloadProviderConfigEvm . at cid %~ f) . c
(x :: T.Text) -> fail $ "unknown payload provider type: " <> sshow x
(x :: T.Text) -> jlabel ("provider:" <> x) $
fail $ "unknown payload provider type: " <> sshow x

-- | Command line option parser for the payload provider configuration.
--
Expand All @@ -262,7 +265,7 @@ pPayloadProviderConfig = id
-- FIXME this is is ugly. At least use the largest know graph. Ideally,
-- we would use the chainweb version -- but we don't know it yet.
-- For the help message we just display options for chain 0.
pevm = foldr (\a b -> a . b) id <$> traverse go cids
pevm = foldr (.) id <$> traverse go cids
go cid
= parserOptionGroup "EVM [only options for chain 0 are shown]" evmChains
<|> parserOptionGroup "Pact [only for chain 0 are shown]" pactChains
Expand Down Expand Up @@ -294,12 +297,12 @@ providerOpt prov cid a p = f <$> dis <*> ena <*> p cid

ena = switch
% long ("enable-chain-" <> T.unpack (toText cid) <> "-" <> prov)
<> help ("enable the payload provider for this chain")
<> help "enable the payload provider for this chain"
<> mconcat [ hidden <> internal | chainIdInt @Int cid /= 0 ]

dis = switch
% long ("disable-chain-" <> T.unpack (toText cid) <> "-" <> prov)
<> help ("disabled the payload provider for this chain")
<> help "disabled the payload provider for this chain"
<> mconcat [ hidden <> internal | chainIdInt @Int cid /= 0 ]

-- -------------------------------------------------------------------------- --
Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/PayloadProvider/EVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
-> RocksDb
-> EVM.Header
-> EvmDB.Configuration
payloadDbConfiguration c rdb hdr = EvmDB.configuration c rdb hdr
payloadDbConfiguration = EvmDB.configuration

-- -------------------------------------------------------------------------- --
-- Configuration
Expand Down Expand Up @@ -301,12 +301,12 @@
latestStateIO = fmap (_consensusStateLatest . sfst) . stateIO

isPayloadRequestedIO :: EvmPayloadProvider logger -> IO Bool
isPayloadRequestedIO p = case _evmMinerAddress p of

Check warning on line 304 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, 3.14, ubuntu-22.04, true)

Defined but not used: ‘isPayloadRequestedIO’

Check warning on line 304 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, latest, ubuntu-22.04, false)

Defined but not used: ‘isPayloadRequestedIO’

Check warning on line 304 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.4, latest, macos-latest, true)

Defined but not used: ‘isPayloadRequestedIO’
Nothing -> return False
Just _ -> (isJust . ssnd) <$> stateIO p

newBlockCtxIO :: EvmPayloadProvider logger -> IO (Maybe NewBlockCtx)
newBlockCtxIO p = case _evmMinerAddress p of

Check warning on line 309 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, 3.14, ubuntu-22.04, true)

Defined but not used: ‘newBlockCtxIO’

Check warning on line 309 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, latest, ubuntu-22.04, false)

Defined but not used: ‘newBlockCtxIO’

Check warning on line 309 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.4, latest, macos-latest, true)

Defined but not used: ‘newBlockCtxIO’
Nothing -> return Nothing
Just _ -> ssnd <$> stateIO p

Expand Down Expand Up @@ -1383,7 +1383,7 @@
-- overhead for this exceptional scenario.
--
candidatePruningDepth :: HasVersion => EvmPayloadProvider logger -> BlockHeight -> BlockHeight
candidatePruningDepth p h = int $ diameter (chainGraphAt h)

Check warning on line 1386 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, 3.14, ubuntu-22.04, true)

Defined but not used: ‘p’

Check warning on line 1386 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, latest, ubuntu-22.04, false)

Defined but not used: ‘p’

Check warning on line 1386 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.4, latest, macos-latest, true)

Defined but not used: ‘p’

pruneCandidates :: HasVersion => EvmPayloadProvider logger -> IO ()
pruneCandidates p = do
Expand Down Expand Up @@ -1449,7 +1449,7 @@
-> Payload
-> EvaluationCtx ConsensusPayload
-> IO ()
validatePayload p pld ctx = do

Check warning on line 1452 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, 3.14, ubuntu-22.04, true)

Defined but not used: ‘ctx’

Check warning on line 1452 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.2, latest, ubuntu-22.04, false)

Defined but not used: ‘ctx’

Check warning on line 1452 in src/Chainweb/PayloadProvider/EVM.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.4, latest, macos-latest, true)

Defined but not used: ‘ctx’

-- FIXME: this requires that we have the full evaluation context available,
-- which includes all transactions. This is potentially expensive.
Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/PayloadProvider/Minimal/Payload.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ account bs
encodeAccount :: HasCallStack => Account -> Put
encodeAccount (Account bs) = do
let l = BS.length bs
void $ when (l > int (maxBound @Word16)) $
when (l > int (maxBound @Word16)) $
error "Chainweb.PayloadProvider.Minimal.encodePayload: account is too large"
putWord16le (int l)
putShortByteString bs
Expand Down
7 changes: 6 additions & 1 deletion src/Chainweb/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module Chainweb.Utils
, decodeFileStrictOrThrow'
, parseJsonFromText
, JsonTextRepresentation(..)
, jlabel

-- ** Cassava (CSV)
, CsvDecimal(..)
Expand Down Expand Up @@ -275,6 +276,7 @@ import Control.Monad.Primitive
import Control.Monad.Reader as Reader
import Control.Monad.Trans.Resource

import Data.Aeson.Key qualified as Aeson
import Data.Aeson.Text (encodeToLazyText)
import Data.Aeson.Types qualified as Aeson
import Data.Array.Byte
Expand Down Expand Up @@ -877,6 +879,9 @@ instance
parseJSON = fmap JsonTextRepresentation . parseJsonFromText (symbolVal_ @s)
{-# INLINE parseJSON #-}

jlabel :: T.Text -> Aeson.Parser a -> Aeson.Parser a
jlabel t = flip (<?>) (Aeson.Key $ Aeson.fromString $ T.unpack t)

-- -------------------------------------------------------------------------- --
-- ** Cassava (CSV)

Expand All @@ -885,7 +890,7 @@ newtype CsvDecimal = CsvDecimal { _csvDecimal :: Decimal }

instance CSV.FromField CsvDecimal where
parseField s = do
cs <- either (fail . show) pure $ T.unpack <$> T.decodeUtf8' s
cs <- either (fail . show) (pure . T.unpack) $ T.decodeUtf8' s
either fail pure $ readEither cs
{-# INLINE parseField #-}

Expand Down
Loading