Skip to content

Commit

Permalink
Chainweb.Version recordification and overhaul (#1550)
Browse files Browse the repository at this point in the history
* check

* add test registry

* re-run ea and fix tests

* clear up some todos

* Removals

* Fix build

* fix haddock

* Fix build add docs

* fix haddock again

* Fix other warnings

* Eq for upgrades

* Move maxBlockGasLimit

* Delete old testnet history case in ExecBlock

* Update Utils.hs

* Update chainweb.cabal

* Remove distributive and adjunctions deps

* Remove memotrie dep

* Remove errors dep from cwtool

* Reorder some declarations around makeLenses

* fix bench

* Disable POW by default in devnet, but allow enabling it

* Remove quotes from Show ChainwebVersionName

* enable pow by default on Development

* Revert some guard heights for devnet, add HasCallStack to some places in Difficulty

* Make upgrades coinv3-coinv5 precocious on devnet

* More cleanup

* delete stm-chans dep

* Reorder forks according to order of mainnet appearance

* cleanup and docs

* Comment Chainweb.Version.Guards

* Start doing DA during tests

* self-review

* More self-review

* changes from code review

* split VersionCheats to add VersionDefaults

* remove redundant pragma

* Specific memoization for mainnet and testnet genesis headers

* instance HasChainwebVersion ChainwebVersionCode

* small changes from review

* Change forks and upgrades for barebonesTestVersion

* More docs and better TestVersions

* Small fork height tweaks

* profiling enabled

* fix tests

* Hahahahahaha wow. Fix dumb performance glitch

* disable profiling

* Use ChainwebVersionName in CutHashes

* Enable profiling

* Revert "Enable profiling"

This reverts commit c0f14f7.

* fix version configuration and validation

* Move upgrades to after 20 chain change

* Make development fork heights what they once were

* Small update

* Disable POW in devnet replay

* Allow non-devnet versions

---------

Co-authored-by: Lars Kuhtz <[email protected]>
  • Loading branch information
edmundnoble and larskuhtz authored Jun 23, 2023
1 parent b8afd94 commit eae5242
Show file tree
Hide file tree
Showing 150 changed files with 3,193 additions and 3,330 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,11 @@ jobs:
EOF
- name: Validate database and replay pact transactions
timeout-minutes: 6
env:
DISABLE_POW_VALIDATION: 1
run: |
chainweb-node +RTS -T -H1G -A64M -RTS \
--config-file=config.yaml \
--log-level=info
--log-level=info \
--disable-pow
# ########################################################################## #
# Run Unit Tests
Expand Down
3 changes: 3 additions & 0 deletions bench/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import qualified Chainweb.Pact.Backend.ForkingBench as ForkingBench
import qualified JSONEncoding

import Chainweb.Storage.Table.RocksDB
import Chainweb.Version.Development
import Chainweb.Version.Registry

main :: IO ()
main = withTempRocksDb "benchmarks" $ \rdb -> do
registerVersion Development
defaultMain
[ Checkpointer.bench
, ForkingBench.bench rdb
Expand Down
4 changes: 3 additions & 1 deletion bench/Chainweb/Pact/Backend/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ import qualified Pact.Types.SQLite as PSQL
-- chainweb imports

import Chainweb.BlockHash
import Chainweb.BlockHeader
import Chainweb.BlockHeight
import Chainweb.Graph
import Chainweb.MerkleLogHash
import Chainweb.Pact.Backend.RelationalCheckpointer
import Chainweb.Pact.Backend.Types
import Chainweb.Pact.Backend.Utils
import Chainweb.Pact.Types
import Chainweb.Test.TestVersions
import Chainweb.Utils.Bench
import Chainweb.Utils (sshow)
import Chainweb.Version

v :: ChainwebVersion
v = FastTimedCPM petersonChainGraph
v = fastForkingCpmTestVersion petersonChainGraph

bench :: C.Benchmark
bench = C.bgroup "pact-backend" $
Expand Down
29 changes: 22 additions & 7 deletions bench/Chainweb/Pact/Backend/ForkingBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import Pact.Types.Util hiding (unwrap)

import Chainweb.BlockCreationTime
import Chainweb.BlockHeader
import Chainweb.BlockHeader.Genesis
import Chainweb.BlockHeaderDB
import Chainweb.BlockHeaderDB.Internal
import Chainweb.ChainId
Expand All @@ -89,6 +88,7 @@ import Chainweb.Pact.Utils (toTxCreationTime)
import Chainweb.Payload
import Chainweb.Payload.PayloadStore
import Chainweb.Payload.PayloadStore.InMemory
import Chainweb.Test.TestVersions
import Chainweb.Time
import Chainweb.Transaction
import Chainweb.Utils
Expand Down Expand Up @@ -379,7 +379,7 @@ cid :: ChainId
cid = someChainId testVer

testVer :: ChainwebVersion
testVer = FastTimedCPM petersonChainGraph
testVer = slowForkingCpmTestVersion petersonChainGraph

assertNotLeft :: (MonadThrow m, Exception e) => Either e a -> m a
assertNotLeft (Left l) = throwM l
Expand All @@ -397,7 +397,10 @@ createCoinAccount v meta name = do
nameKeyset <- NEL.fromList <$> getKeyset name
let attach = attachCaps "sender00" name 1000.0
let theData = object [T.pack name .= fmap (formatB16PubKey . fst) (attach nameKeyset)]
res <- mkExec (T.pack theCode) theData meta (NEL.toList $ attach sender00Keyset) (Just $ Pact.NetworkId $ toText v) Nothing
res <- mkExec (T.pack theCode) theData meta
(NEL.toList $ attach sender00Keyset)
(Just $ Pact.NetworkId $ toText (_versionName v))
Nothing
pure (nameKeyset, res)
where
theCode = printf "(coin.transfer-create \"sender00\" \"%s\" (read-keyset \"%s\") 1000.0)" name name
Expand Down Expand Up @@ -550,14 +553,20 @@ createCoinContractRequest v meta ks request =
object
[ "create-account-guard" .= fmap (formatB16PubKey . fst) guardd
]
mkExec (T.pack theCode) theData meta (NEL.toList ks) (Just $ Pact.NetworkId $ toText v) Nothing
mkExec (T.pack theCode) theData meta
(NEL.toList ks)
(Just $ Pact.NetworkId $ toText $ _versionName v)
Nothing
CoinAccountBalance (Account account) -> do
let theData = Null
theCode =
printf
"(coin.get-balance \"%s\")"
account
mkExec (T.pack theCode) theData meta (NEL.toList ks) (Just $ Pact.NetworkId $ toText v) Nothing
mkExec (T.pack theCode) theData meta
(NEL.toList ks)
(Just $ Pact.NetworkId $ toText $ _versionName v)
Nothing
CoinTransferAndCreate (SenderName (Account sn)) (ReceiverName (Account rn)) (Guard guardd) (Amount amount) -> do
let theCode =
printf
Expand All @@ -570,7 +579,10 @@ createCoinContractRequest v meta ks request =
object
[ "receiver-guard" .= fmap (formatB16PubKey . fst) guardd
]
mkExec (T.pack theCode) theData meta (NEL.toList ks) (Just $ Pact.NetworkId $ toText v) Nothing
mkExec (T.pack theCode) theData meta
(NEL.toList ks)
(Just $ Pact.NetworkId $ toText $ _versionName v)
Nothing

CoinTransfer (SenderName (Account sn)) (ReceiverName (Account rn)) (Amount amount) -> do
let theCode =
Expand All @@ -581,7 +593,10 @@ createCoinContractRequest v meta ks request =
-- Super janky, but gets the job done for now
(fromRational @Double $ toRational amount)
theData = object []
mkExec (T.pack theCode) theData meta (NEL.toList ks) (Just $ Pact.NetworkId $ toText v) Nothing
mkExec (T.pack theCode) theData meta
(NEL.toList ks)
(Just $ Pact.NetworkId $ toText $ _versionName v)
Nothing

makeMetaWithSender :: String -> ChainId -> IO PublicMeta
makeMetaWithSender sender c =
Expand Down
2 changes: 1 addition & 1 deletion bench/JSONEncoding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Chainweb.Payload
import Chainweb.RestAPI.NodeInfo
import Chainweb.Test.Orphans.Internal
import Chainweb.Utils.Paging
import Chainweb.Version
import Chainweb.Version.Mainnet

-- -------------------------------------------------------------------------- --
-- Main
Expand Down
16 changes: 9 additions & 7 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ library
, Chainweb.BlockCreationTime
, Chainweb.BlockHash
, Chainweb.BlockHeader
, Chainweb.BlockHeader.Genesis
, Chainweb.BlockHeader.Genesis.Development0Payload
, Chainweb.BlockHeader.Genesis.DevelopmentKADPayload
, Chainweb.BlockHeader.Genesis.DevelopmentNPayload
Expand Down Expand Up @@ -235,14 +234,18 @@ library
, Chainweb.Utils
, Chainweb.Utils.Paging
, Chainweb.Utils.RequestLog
, Chainweb.Utils.Rule
, Chainweb.Utils.Serialization
, Chainweb.Version
, Chainweb.Version.Development
, Chainweb.Version.Guards
, Chainweb.Version.Mainnet
, Chainweb.Version.Registry
, Chainweb.Version.Testnet
, Chainweb.Version.Utils
, Chainweb.WebBlockHeaderDB
, Chainweb.WebPactExecutionService

, Control.Concurrent.FixedThreadPool

, Data.IVar
, Data.LogMessage
, Data.PQueue
Expand Down Expand Up @@ -306,7 +309,6 @@ library
, Chainweb.Pact.Transactions.Mainnet9Transactions
, Chainweb.Pact.Transactions.MainnetKADTransactions
, Chainweb.Pact.Transactions.OtherTransactions
, Chainweb.Pact.Transactions.UpgradeTransactions
, Chainweb.Pact.Types
, Chainweb.Pact.Utils
, Chainweb.Pact.Validations
Expand Down Expand Up @@ -379,12 +381,12 @@ library
, rosetta >= 1.0
, safe-exceptions >= 0.1
, scheduler >= 1.4
, semigroupoids >= 5.3.7
, servant >= 0.18.2
, servant-client >= 0.18.2
, servant-client-core >= 0.18.2
, servant-server >= 0.18.2
, stm >= 2.4
, stm-chans
, stopwatch >= 0.1
, streaming >= 0.2
, streaming-commons >= 0.2
Expand Down Expand Up @@ -481,14 +483,14 @@ test-suite chainweb-tests
Chainweb.Test.SPV
Chainweb.Test.SPV.EventProof
Chainweb.Test.Sync.WebBlockHeaderStore
Chainweb.Test.TestVersions
Chainweb.Test.TreeDB
Chainweb.Test.TreeDB.RemoteDB
Chainweb.Test.Utils
Chainweb.Test.Utils.APIValidation
Chainweb.Test.Version
Chainweb.Test.Utils.BlockHeader
Chainweb.Test.Utils.TestHeader
Chainweb.Test.Utils.ApiQueries

-- Data
Data.Test.PQueue
Expand Down Expand Up @@ -685,7 +687,6 @@ executable cwtool
, digraph >= 0.2
, direct-sqlite >= 2.3.27
, directory >= 1.3
, errors >= 2.3
, file-embed
, filepath >= 1.4
, exceptions >= 0.8
Expand All @@ -704,6 +705,7 @@ executable cwtool
, process >= 1.5
, quickcheck-instances >= 0.3
, random >= 1.2
, retry >= 0.9
, rocksdb-haskell-kadena >= 1.1.0
, safe-exceptions >= 0.1
, servant-client >= 0.18.2
Expand Down
2 changes: 1 addition & 1 deletion docs/RecoveringFromDeepForks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Help! My node has failed with the following fatal error:
```
Fatal error: Requested rewind exceeds limit (4). Our previous cut block height: 1, fork ancestor's block height: 6.
Offending new block:
BlockHeader {_blockNonce = Nonce 0, _blockCreationTime = BlockCreationTime {_bct = Time (TimeSpan (Micros 1575672858613932))}, _blockParent = "ugAOff6YkKmvp_pJIHqx6HLTRPwyHEHD2c2Olm6L2Fg", _blockAdjacentHashes = BlockHashRecord {_getBlockHashRecord = fromList []}, _blockTarget = HashTarget (PowHashNat 115792089237316195423570985008687907853269984665640564039457584007913129639935), _blockPayloadHash = BlockPayloadHash (MerkleLogHash U-3paUKNKQUkggFmNOnGBEAJnjpy4K_-7t_dGyV0lhw), _blockChainId = ChainId 8, _blockWeight = BlockWeight (HashDifficulty (PowHashNat 1)), _blockHeight = 1, _blockChainwebVersion = fastTimedCPM-peterson, _blockEpochStart = EpochStartTime (Time (TimeSpan (Micros 0))), _blockFlags = FeatureFlags 0, _blockHash = "SKZ0mTWp08ooXsWz_yyT7v_MSrRdyKkmCyWJBTK8u3g"}
BlockHeader {_blockNonce = Nonce 0, _blockCreationTime = BlockCreationTime {_bct = Time (TimeSpan (Micros 1575672858613932))}, _blockParent = "ugAOff6YkKmvp_pJIHqx6HLTRPwyHEHD2c2Olm6L2Fg", _blockAdjacentHashes = BlockHashRecord {_getBlockHashRecord = fromList []}, _blockTarget = HashTarget (PowHashNat 115792089237316195423570985008687907853269984665640564039457584007913129639935), _blockPayloadHash = BlockPayloadHash (MerkleLogHash U-3paUKNKQUkggFmNOnGBEAJnjpy4K_-7t_dGyV0lhw), _blockChainId = ChainId 8, _blockWeight = BlockWeight (HashDifficulty (PowHashNat 1)), _blockHeight = 1, _blockChainwebVersion = fastfork-CPM-peterson, _blockEpochStart = EpochStartTime (Time (TimeSpan (Micros 0))), _blockFlags = FeatureFlags 0, _blockHash = "SKZ0mTWp08ooXsWz_yyT7v_MSrRdyKkmCyWJBTK8u3g"}
Your node is part of a losing fork longer than your reorg-limit, which
is a situation that requires manual intervention.
Expand Down
19 changes: 10 additions & 9 deletions node/ChainwebNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import Chainweb.Time
import Chainweb.Utils
import Chainweb.Utils.RequestLog
import Chainweb.Version
import Chainweb.Version.Mainnet
import Chainweb.Version.Registry

import Chainweb.Storage.Table
import Chainweb.Storage.Table.RocksDB
Expand Down Expand Up @@ -128,18 +130,16 @@ data ChainwebNodeConfiguration = ChainwebNodeConfiguration

makeLenses ''ChainwebNodeConfiguration

defaultChainwebNodeConfiguration :: ChainwebVersion -> ChainwebNodeConfiguration
defaultChainwebNodeConfiguration v = ChainwebNodeConfiguration
{ _nodeConfigChainweb = defaultChainwebConfiguration v
defaultChainwebNodeConfiguration :: ChainwebNodeConfiguration
defaultChainwebNodeConfiguration = ChainwebNodeConfiguration
{ _nodeConfigChainweb = defaultChainwebConfiguration Mainnet01
, _nodeConfigLog = defaultLogConfig
& logConfigLogger . L.loggerConfigThreshold .~ level
, _nodeConfigDatabaseDirectory = Nothing
, _nodeConfigResetChainDbs = False
}
where
level = case v of
Mainnet01 -> L.Info
_ -> L.Info
level = L.Info

validateChainwebNodeConfiguration :: ConfigValidation ChainwebNodeConfiguration []
validateChainwebNodeConfiguration o = do
Expand Down Expand Up @@ -185,7 +185,7 @@ getBackupsDir conf = (</> "backups") <$> getDbBaseDir conf
getDbBaseDir :: HasCallStack => ChainwebNodeConfiguration -> IO FilePath
getDbBaseDir conf = case _nodeConfigDatabaseDirectory conf of
Nothing -> getXdgDirectory XdgData
$ "chainweb-node" </> sshow v
$ "chainweb-node" </> sshow (_versionName v)
Just d -> return d
where
v = _configChainwebVersion $ _nodeConfigChainweb conf
Expand Down Expand Up @@ -439,7 +439,7 @@ withNodeLogger logConfig v f = runManaged $ do

liftIO $ f
$ maybe id (\x -> addLabel ("cluster", toText x)) (_logConfigClusterId logConfig)
$ addLabel ("chainwebVersion", sshow v)
$ addLabel ("chainwebVersion", sshow (_versionName v))
$ logger
where
teleLogConfig = _logConfigTelemetryBackend logConfig
Expand Down Expand Up @@ -525,7 +525,7 @@ mainInfo :: ProgramInfo ChainwebNodeConfiguration
mainInfo = programInfoValidate
"Chainweb Node"
pChainwebNodeConfiguration
(defaultChainwebNodeConfiguration Mainnet01)
defaultChainwebNodeConfiguration
validateChainwebNodeConfiguration

handles :: [Handler a] -> IO a -> IO a
Expand All @@ -537,6 +537,7 @@ main = do
checkRLimits
runWithPkgInfoConfiguration mainInfo pkgInfo $ \conf -> do
let v = _configChainwebVersion $ _nodeConfigChainweb conf
registerVersion v
hSetBuffering stderr LineBuffering
withNodeLogger (_nodeConfigLog conf) v $ \logger -> do
logFunctionJson logger Info ProcessStarted
Expand Down
Loading

0 comments on commit eae5242

Please sign in to comment.