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

PactDB Compaction #1680

Merged
merged 85 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
7994f59
PactDB: compute sha3 checksums
larskuhtz Jun 16, 2022
3eb1f48
fix build
sirlensalot Jun 16, 2022
31eebfa
compact system tables
sirlensalot Jun 16, 2022
33d5884
refactor
sirlensalot Oct 11, 2022
f5714ba
docs
sirlensalot Oct 12, 2022
106db3f
test verifies hashes
sirlensalot Oct 12, 2022
a6c1682
return global hash
sirlensalot Oct 12, 2022
b90251c
dedicated test
sirlensalot Oct 13, 2022
27e6329
Code-complete with cw-tool
sirlensalot Oct 14, 2022
21d4385
test comments
sirlensalot Oct 14, 2022
8a063c5
cleanup sql
sirlensalot Oct 28, 2022
2282f20
cleanup
sirlensalot Jan 30, 2023
0a65092
cleanup
sirlensalot Jan 30, 2023
59e9934
fix build
sirlensalot Jan 31, 2023
614baeb
Hashing no longer in checkpointer, internal to compaction
sirlensalot Feb 4, 2023
cc7198e
cleanup
sirlensalot Feb 4, 2023
d4b8bde
fix drop table, add vacuum
sirlensalot Feb 4, 2023
ecbfd3e
test TODOs
sirlensalot Feb 9, 2023
f123fe6
optparse cleanups
chessai Apr 24, 2023
4b8a48d
remove flag addition in chainweb.cabal
chessai Apr 24, 2023
b7c701f
clean up imports
chessai Apr 24, 2023
0269ed1
make relevant fields strict
chessai Apr 24, 2023
870db50
minor src cleanups
chessai Apr 25, 2023
0ddb865
add some docs to compaction functions
chessai Apr 25, 2023
0f5f38c
first test stuff
chessai May 1, 2023
5f97870
more compaction haddocks/add blockheight to invalid block height exce…
chessai May 1, 2023
559101e
remove redundant import
chessai May 1, 2023
a232790
add flag to not drop new tables
chessai Jun 5, 2023
e4d1a29
compact concurrently, add log directory for per-chain logs
chessai Jun 5, 2023
a969717
debugging doRestore
chessai Jun 6, 2023
2ca8f49
compaction: just don't drop new tables at all, ever
chessai Jun 6, 2023
484cf42
change compact log file name prefix from compact-log- to compact-chain-
chessai Jun 6, 2023
1f8a72f
Revert "compaction: just don't drop new tables at all, ever"
chessai Jun 13, 2023
5b41d58
undo residual changes from rebase
chessai Jun 13, 2023
26f17f1
undo redundant logging
chessai Jun 13, 2023
b39a6cc
use new chainweb version code
chessai Jul 10, 2023
c6d0d80
print compaction hash in base64
chessai Jul 11, 2023
5a19423
fix compactSystemTables
chessai Jul 11, 2023
beb57fe
Add --threads option and use pooledMapConcurrentlyN_ in compaction
Jul 14, 2023
ee96fe7
Merge branch 'master' into chessai/compaction
edmundnoble Aug 18, 2023
1d00f06
Merge branch 'master' into chessai/compaction
chessai Aug 18, 2023
fb0953d
compaction logging: create directory and files before attempting to l…
chessai Aug 18, 2023
ac065a7
add new test idea from John
chessai Aug 21, 2023
3d049bf
add NoGrandHash flag
chessai Aug 21, 2023
0c680cb
fix type error
chessai Aug 21, 2023
01f0cb0
fix compact flag for no grand hash
chessai Aug 21, 2023
ffd68d3
don't verifyTable when NoGrandHash is set
chessai Aug 21, 2023
d04943a
Merge branch 'master' into chessai/compaction
chessai Sep 14, 2023
4dd62be
fix compile error in tests from prior change
chessai Sep 14, 2023
89eaa22
make PactService exit if rosetta is enabled and we don't have the ful…
chessai Sep 21, 2023
e330bd4
Merge branch 'master' into chessai/compaction
chessai Sep 21, 2023
01e71a8
Merge branch 'master' into chessai/compaction
chessai Sep 25, 2023
cc742f7
informative error message if you try to rewind before min(blockheight…
chessai Sep 25, 2023
67c8710
Merge branch 'master' into chessai/compaction
chessai Sep 27, 2023
51f8e05
MultiNode compaction test (#1742)
chessai Sep 27, 2023
012f28f
Merge branch 'master' into chessai/compaction
chessai Oct 2, 2023
a5ca07f
Merge branch 'master' into chessai/compaction
chessai Oct 12, 2023
a450f9a
refactor compaction code
chessai Oct 13, 2023
d6cd8e8
STM-based chain selection algo for mining
edmundnoble Oct 16, 2023
f4fc0e9
compact-resume test: move to singletonChainGraph
chessai Oct 18, 2023
457a0ee
Merge branch 'master' into chessai/compaction
chessai Oct 18, 2023
70dc4f1
Merge branch 'master' into chessai/compaction
chessai Oct 19, 2023
0601a9e
compaction idempotency test (#1759)
chessai Oct 20, 2023
eb34fb2
Merge branch 'master' into chessai/compaction
chessai Oct 20, 2023
97b5a42
compaction pre-and-post active row test (#1756)
chessai Oct 20, 2023
e44ae36
Merge branch 'master' into chessai/compaction
chessai Oct 27, 2023
cef87dc
Merge branch 'master' into chessai/compaction
chessai Nov 3, 2023
bc0bc51
benchmark newBlock after compaction (#1774)
chessai Nov 3, 2023
2ed9345
[test] compaction tables created after target blockheight are dropped…
chessai Nov 3, 2023
c06e1b8
Merge branch 'master' into chessai/compaction
chessai Nov 6, 2023
cadb781
add latest option for chain compaction
chessai Nov 7, 2023
e9e5279
Merge branch 'master' into chessai/compaction
chessai Nov 13, 2023
7bf673f
Revert "STM-based chain selection algo for mining"
chessai Nov 13, 2023
ec4e7fa
compaction compare pact state tool (#1764)
chessai Nov 15, 2023
de12389
remove redundant/bad old Compaction.hs test
chessai Nov 15, 2023
4997e25
respond to some review
chessai Nov 15, 2023
9939c07
finish responding to Austin's review
chessai Nov 15, 2023
a6f8e7d
respond to first round of Edmund's reviews
chessai Nov 15, 2023
1fb2d6c
respond to Edmund's second wave of review
chessai Nov 15, 2023
2093ede
Revert "compact-resume test: move to singletonChainGraph"
chessai Nov 15, 2023
205a992
make compact function take a TargetBlockHeight instead of a BlockHeight
chessai Nov 16, 2023
ae02900
get rid of redundant ITxId type
chessai Nov 16, 2023
bf274a4
fix index of getLatestBlockHeight query log
chessai Nov 16, 2023
1e24675
respond to more review
chessai Nov 16, 2023
f7ca60d
compaction test txlogs (#1780)
chessai Nov 16, 2023
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
86 changes: 63 additions & 23 deletions bench/Chainweb/Pact/Backend/ForkingBench.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
Expand Down Expand Up @@ -33,6 +35,7 @@ import Data.FileEmbed
import Data.Foldable (toList)
import Data.IORef
import Data.List (uncons)
import Data.List qualified as List
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NEL
import Data.Map.Strict (Map)
Expand All @@ -49,6 +52,7 @@ import qualified Data.Yaml as Y
import GHC.Generics hiding (from, to)

import System.Environment
import System.Logger.Types qualified
import System.LogLevel
import System.Random

Expand All @@ -74,11 +78,13 @@ import Chainweb.BlockCreationTime
import Chainweb.BlockHeader
import Chainweb.BlockHeaderDB
import Chainweb.BlockHeaderDB.Internal
import Chainweb.BlockHeight (BlockHeight(..))
import Chainweb.ChainId
import Chainweb.Graph
import Chainweb.Logger
import Chainweb.Mempool.Mempool (BlockFill(..))
import Chainweb.Miner.Pact
import Chainweb.Pact.Backend.Compaction qualified as C
import Chainweb.Pact.Backend.Types
import Chainweb.Pact.Backend.Utils
import Chainweb.Pact.PactService
Expand All @@ -90,7 +96,7 @@ import Chainweb.Pact.Utils (toTxCreationTime)
import Chainweb.Payload
import Chainweb.Payload.PayloadStore
import Chainweb.Payload.PayloadStore.InMemory
import Chainweb.Test.TestVersions
import Chainweb.Test.TestVersions (slowForkingCpmTestVersion)
import Chainweb.Time
import Chainweb.Transaction
import Chainweb.Utils
Expand All @@ -111,28 +117,48 @@ _run args = withTempRocksDb "forkingbench" $ \rdb ->
-- -------------------------------------------------------------------------- --
-- Benchmarks

data BenchConfig = BenchConfig
{ numPriorBlocks :: Word64
-- ^ number of blocks to create prior to benchmarking
, validate :: Validate
-- ^ whether or not to validate the blocks as part of the benchmark
, compact :: Compact
-- ^ whether or not to compact the pact database prior to benchmarking
}

defBenchConfig :: BenchConfig
defBenchConfig = BenchConfig
{ numPriorBlocks = 100
, validate = DontValidate
, compact = DontCompact
}

data Compact = DoCompact | DontCompact
deriving stock (Eq)

data Validate = DoValidate | DontValidate
deriving stock (Eq)

bench :: RocksDb -> C.Benchmark
bench rdb = C.bgroup "PactService"
bench rdb = C.bgroup "PactService" $
[ forkingBench
, doubleForkingBench
, oneBlock True 1
, oneBlock True 10
, oneBlock True 50
, oneBlock True 100
, oneBlock False 0
, oneBlock False 1
, oneBlock False 10
, oneBlock False 50
, oneBlock False 100
]
] ++ map (oneBlock defBenchConfig) [1, 10, 50, 100]
++ map (oneBlock validateCfg) [0, 1, 10, 50, 100]
++ map (oneBlock compactCfg) [0, 1, 10, 50, 100]
++ map (oneBlock compactValidateCfg) [1, 10, 50, 100]
where
forkingBench = withResources rdb 10 Quiet
validateCfg = defBenchConfig { validate = DoValidate }
compactCfg = defBenchConfig { compact = DoCompact }
compactValidateCfg = compactCfg { validate = DoValidate }

forkingBench = withResources rdb 10 Quiet DontCompact
$ \mainLineBlocks pdb bhdb nonceCounter pactQueue _ ->
C.bench "forkingBench" $ C.whnfIO $ do
let (T3 _ join1 _) = mainLineBlocks !! 5
void $ playLine pdb bhdb 5 join1 pactQueue nonceCounter

doubleForkingBench = withResources rdb 10 Quiet
doubleForkingBench = withResources rdb 10 Quiet DontCompact
$ \mainLineBlocks pdb bhdb nonceCounter pactQueue _ ->
C.bench "doubleForkingBench" $ C.whnfIO $ do
let (T3 _ join1 _) = mainLineBlocks !! 5
Expand All @@ -141,15 +167,21 @@ bench rdb = C.bgroup "PactService"
void $ playLine pdb bhdb forkLength1 join1 pactQueue nonceCounter
void $ playLine pdb bhdb forkLength2 join1 pactQueue nonceCounter

oneBlock validate txCount = withResources rdb 3 Error go
oneBlock :: BenchConfig -> Int -> C.Benchmark
oneBlock cfg txCount = withResources rdb cfg.numPriorBlocks Error cfg.compact go
where
go mainLineBlocks _pdb _bhdb _nonceCounter pactQueue txsPerBlock =
go mainLineBlocks _pdb _bhdb _nonceCounter pactQueue txsPerBlock = do
C.bench name $ C.whnfIO $ do
writeIORef txsPerBlock txCount
let (T3 _ join1 _) = last mainLineBlocks
createBlock validate (ParentHeader join1) (Nonce 1234) pactQueue
name = "block-new" ++ (if validate then "-validated" else "") ++
"[" ++ show txCount ++ "]"
createBlock cfg.validate (ParentHeader join1) (Nonce 1234) pactQueue
name = "block-new ["
++ List.intercalate ","
[ "txCount=" ++ show txCount
, "validate=" ++ show (cfg.validate == DoValidate)
, "compact=" ++ show (cfg.compact == DoCompact)
]
++ "]"

-- -------------------------------------------------------------------------- --
-- Benchmark Function
Expand Down Expand Up @@ -188,14 +220,14 @@ mineBlock
-> PactQueue
-> IO (T3 ParentHeader BlockHeader PayloadWithOutputs)
mineBlock parent nonce pdb bhdb pact = do
!r@(T3 _ newHeader payload) <- createBlock True parent nonce pact
r@(T3 _ newHeader payload) <- createBlock DoValidate parent nonce pact
addNewPayload pdb payload
-- NOTE: this doesn't validate the block header, which is fine in this test case
unsafeInsertBlockHeaderDb bhdb newHeader
return r

createBlock
:: Bool
:: Validate
-> ParentHeader
-> Nonce
-> PactQueue
Expand All @@ -216,7 +248,7 @@ createBlock validate parent nonce pact = do
creationTime
parent

when validate $ do
when (validate == DoValidate) $ do
mv' <- validateBlock bh (payloadWithOutputsToPayloadData payload) pact
void $ assertNotLeft =<< takeMVar mv'

Expand Down Expand Up @@ -250,9 +282,10 @@ withResources :: ()
=> RocksDb
-> Word64
-> LogLevel
-> Compact
-> RunPactService
-> C.Benchmark
withResources rdb trunkLength logLevel f = C.envWithCleanup create destroy unwrap
withResources rdb trunkLength logLevel compact f = C.envWithCleanup create destroy unwrap
where

unwrap ~(NoopNFData (Resources {..})) =
Expand All @@ -270,6 +303,13 @@ withResources rdb trunkLength logLevel f = C.envWithCleanup create destroy unwra
startPact testVer logger blockHeaderDb payloadDb mp sqlEnv
mainTrunkBlocks <-
playLine payloadDb blockHeaderDb trunkLength genesisBlock (snd pactService) nonceCounter
when (compact == DoCompact) $ do
C.withDefaultLogger System.Logger.Types.Error $ \lgr -> do
let flags = [C.NoGrandHash]
let db = _sConn sqlEnv
let bh = BlockHeight trunkLength
void $ C.compact (C.Target bh) lgr db flags

return $ NoopNFData $ Resources {..}

destroy (NoopNFData (Resources {..})) = do
Expand Down
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ source-repository-package
tag: 174af3523616c8fe01449da5ccbb9f16df097ac3
--sha256: sha256-kVFIy+Aj3TNJpsM1Cs/5uGmzeWwHKYWjjCQ+L1/XOj8=

source-repository-package
type: git
location: https://github.com/chessai/patience
tag: 2f67d546ea6608fc6ebe5f2f6976503cbf340442
--sha256: 0x137akvbh4kr3qagksw74xdj2xz5vjnx1fbr41bb54a0lkcb8mm

-- -------------------------------------------------------------------------- --
-- Relaxed Bounds

Expand Down
4 changes: 4 additions & 0 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ library
-- pact
, Chainweb.Pact.Backend.ChainwebPactDb
, Chainweb.Pact.Backend.DbCache
, Chainweb.Pact.Backend.Compaction
, Chainweb.Pact.Backend.PactState
, Chainweb.Pact.Backend.RelationalCheckpointer
, Chainweb.Pact.Backend.SQLite.DirectV2
, Chainweb.Pact.Backend.SQLite.V2
Expand Down Expand Up @@ -403,6 +405,7 @@ library
, tls-session-manager >= 0.0
, token-bucket >= 0.1
, transformers >= 0.5
, unliftio ^>= 0.2
, unordered-containers >= 0.2.16
, uuid >= 1.3.15
, wai >= 3.2.2.1
Expand Down Expand Up @@ -540,6 +543,7 @@ test-suite chainweb-tests
, merkle-log >=0.2
, mtl >= 2.3
, network >= 3.1.2
, patience >= 0.3
, http-client-tls >=0.3
, pact
, pact-json >= 0.1
Expand Down
7 changes: 4 additions & 3 deletions src/Chainweb/Chainweb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ validatingMempoolConfig cid v gl gp mv = Mempool.InMemConfig
f (This _) = Left (T2 (Mempool.TransactionHash "") (Mempool.InsertErrorOther "preInsertBatch: align mismatch 1"))


data StartedChainweb logger
= forall cas. (CanReadablePayloadCas cas, Logger logger) => StartedChainweb !(Chainweb logger cas)
| Replayed !Cut !Cut
data StartedChainweb logger where
StartedChainweb :: (CanReadablePayloadCas cas, Logger logger) => !(Chainweb logger cas) -> StartedChainweb logger
Replayed :: !Cut -> !Cut -> StartedChainweb logger

data ChainwebStatus
= ProcessStarted
Expand Down Expand Up @@ -427,6 +427,7 @@ withChainwebInternal conf logger peer serviceSock rocksDb pactDbDir backupDir re
, _pactBlockGasLimit = maybe id min maxGasLimit (_configBlockGasLimit conf)
, _pactLogGas = _configLogGas conf
, _pactModuleCacheLimit = _configModuleCacheLimit conf
, _pactFullHistoryRequired = _configRosetta conf -- this could be OR'd with other things that require full history
}

pruningLogger :: T.Text -> logger
Expand Down
Loading
Loading