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

compaction in memory #1900

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ jobs:
- name: Build chainweb library
run: cabal build --ghc-options=-j2 lib:chainweb
- name: Build chainweb applications
run: cabal build -j2 --ghc-options=-j2 exe:chainweb-node test:chainweb-tests exe:cwtool chainweb:bench:bench
run: cabal build -j2 --ghc-options=-j2 exe:chainweb-node exe:compact test:chainweb-tests exe:cwtool chainweb:bench:bench

# Checks
- name: Check that working directory tree is clean
Expand All @@ -360,6 +360,7 @@ jobs:
run: |
mkdir -p artifacts/chainweb
cp $(cabal list-bin chainweb-node) artifacts/chainweb
cp $(cabal list-bin compact) artifacts/chainweb
cp $(cabal list-bin chainweb-tests) artifacts/chainweb
cp $(cabal list-bin cwtool) artifacts/chainweb
cp $(cabal list-bin bench) artifacts/chainweb
Expand Down
33 changes: 25 additions & 8 deletions bench/Chainweb/Pact/Backend/ForkingBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,32 @@ withResources rdb trunkLength logLevel compact p f = C.envWithCleanup create des
coinAccounts <- newMVar mempty
nonceCounter <- newIORef 1
txPerBlock <- newIORef 10
sqlEnv <- openSQLiteConnection "" {- temporary SQLite db -} chainwebBenchPragmas
mp <- testMemPoolAccess txPerBlock coinAccounts
pactService <-
startPact testVer logger blockHeaderDb payloadDb mp sqlEnv
mainTrunkBlocks <-
playLine payloadDb blockHeaderDb trunkLength genesisBlock (snd pactService) nonceCounter
when (compact == DoCompact) $ do
C.withDefaultLogger Error $ \lgr -> do
void $ C.compact (BlockHeight trunkLength) lgr sqlEnv []
(sqlEnv, pactService, mainTrunkBlocks) <- do
srcSqlEnv <- openSQLiteConnection "" {- temporary SQLite db -} chainwebBenchPragmas
srcPactService <-
startPact testVer logger blockHeaderDb payloadDb mp srcSqlEnv
mainTrunkBlocks <-
playLine payloadDb blockHeaderDb trunkLength genesisBlock (snd srcPactService) nonceCounter

(sqlEnv, pactService) <- do
if compact == DoCompact
then do
targetSqlEnv <- openSQLiteConnection "" {- temporary SQLite db -} chainwebBenchPragmas
C.withDefaultLogger Error $ \lgr -> do
C.compactPactState lgr C.defaultRetainment (BlockHeight trunkLength) srcSqlEnv targetSqlEnv
targetPactService <-
startPact testVer logger blockHeaderDb payloadDb mp targetSqlEnv

-- Stop the previous pact service/close the sqlite connection
stopPact srcPactService
stopSqliteDb srcSqlEnv

pure (targetSqlEnv, targetPactService)
else do
pure (srcSqlEnv, srcPactService)

pure (sqlEnv, pactService, mainTrunkBlocks)

return $ NoopNFData $ Resources {..}

Expand Down
16 changes: 2 additions & 14 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/kadena-io/chainweb-storage.git
tag: 4b45c1ab9c070c6d16a058bcbab0c06ac0fb6d4e
--sha256: 0m6c7kl6x5a3k02q2i7qzfx91kxz19dzav0piqfxra52bq0x3sm6
tag: a5e06a8aa2da1e7981ff9fad91dfd41f7c39fc85
--sha256: sha256-3Zqsgrxa7SQUr8XzT2O5PLTELkI92NXZU4j2UUvlL4E=

source-repository-package
type: git
Expand Down Expand Up @@ -137,18 +137,6 @@ 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

source-repository-package
type: git
location: https://github.com/andrewthad/chronos
tag: b199bf6df1453af95832c2d2f9f0ef48c3622caa
--sha256: 056awkmdmkqdd5g3m8a1ibg2vp02kbppmidkfh4aildb1brq970a

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

Expand Down
53 changes: 44 additions & 9 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,15 @@ library
, case-insensitive >= 1.2
, cassava >= 0.5.1
, chainweb-storage >= 0.1
, chronos >= 1.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
, crypton-x509 >=1.7
, crypton-x509-system >=1.6
, crypton-x509-validation >=1.6
, cuckoo >= 0.3
, data-default >=0.7
, data-dword >= 0.3
Expand Down Expand Up @@ -411,8 +414,8 @@ library
, mmorph >= 1.1
, monad-control >= 1.0
, mtl >= 2.3
, mwc-random >= 0.13
, mwc-probability >= 2.0 && <2.4
, mwc-random >= 0.13
, network >= 3.1.2
, optparse-applicative >= 0.14
, pact >= 4.2.0.1
Expand All @@ -422,6 +425,7 @@ library
, pem >=0.2
, primitive >= 0.7.1.0
, random >= 1.2
, rocksdb-haskell-kadena >= 1.1.0
, rosetta >= 1.0
, safe-exceptions >= 0.1
, scheduler >= 1.4
Expand All @@ -436,29 +440,26 @@ library
, streaming-commons >= 0.2
, template-haskell >= 2.14
, text >= 2.0
, trifecta >= 2.1
, these >= 1.0
, time >= 1.12.2
, tls >=1.9
, tls-session-manager >= 0.0
, token-bucket >= 0.1
, transformers >= 0.5
, trifecta >= 2.1
, unliftio ^>= 0.2
, unordered-containers >= 0.2.16
, uuid >= 1.3.15
, vector >= 0.12.2
, vector-algorithms >= 0.7
, wai >= 3.2.2.1
, wai-app-static >= 3.1.6.3
, wai-cors >= 0.2.7
, wai-extra >= 3.0.28
, wai-middleware-validation
, vector >= 0.12.2
, vector-algorithms >= 0.7
, wai-middleware-throttle >= 0.3
, wai-middleware-validation
, warp >= 3.3.6
, warp-tls >= 3.4
, crypton-x509 >=1.7
, crypton-x509-system >=1.6
, crypton-x509-validation >=1.6
, yaml >= 0.11
, yet-another-logger >= 0.4.1

Expand Down Expand Up @@ -815,6 +816,40 @@ executable cwtool
if flag(ed25519)
cpp-options: -DWITH_ED25519=1

executable compact
import: warning-flags, debugging-flags
default-language: Haskell2010
ghc-options:
-threaded
-rtsopts
"-with-rtsopts=-N -A4M --disable-delayed-os-memory-return -qn1"
hs-source-dirs:
compact
main-is: Main.hs
build-depends:
-- internal
, chainweb

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

executable pact-diff
import: warning-flags, debugging-flags
default-language: Haskell2010
ghc-options:
-threaded
-rtsopts
"-with-rtsopts=-N -A4M --disable-delayed-os-memory-return -qn1"
hs-source-dirs:
pact-diff
main-is: Main.hs
build-depends:
-- internal
, chainweb

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

benchmark bench
import: warning-flags, debugging-flags
default-language: Haskell2010
Expand Down
11 changes: 11 additions & 0 deletions compact/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# language
ImportQualifiedPost
#-}

module Main (main) where

import Chainweb.Pact.Backend.Compaction qualified as Compact

main :: IO ()
main = do
Compact.main
34 changes: 23 additions & 11 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ let haskellSrc = with nix-filter.lib; filter {
shell.buildInputs = with pkgs; [
zlib
pkg-config
sqlite
];
modules = [
{
Expand All @@ -102,17 +103,28 @@ let haskellSrc = with nix-filter.lib; filter {
};
pact = pactFromCached pkgs pact passthru.cached;
};
default = pkgs.runCommandCC "chainweb" { inherit passthru; } ''
mkdir -pv $out/bin
cp ${flake.packages."chainweb:exe:chainweb-node"}/bin/chainweb-node $out/bin/chainweb-node
cp ${flake.packages."chainweb:exe:cwtool"}/bin/cwtool $out/bin/cwtool
chmod +w $out/bin/{cwtool,chainweb-node}
$STRIP $out/bin/chainweb-node
$STRIP $out/bin/cwtool
${pkgs.lib.optionalString (pkgs.stdenv.isLinux) ''
patchelf --shrink-rpath $out/bin/{cwtool,chainweb-node}
''}
'';
default =
let
exes = [
"chainweb-node"
"cwtool"
"compact"
"pact-diff"
];

for = xs: f: builtins.map f xs;
in
pkgs.runCommandCC "chainweb" { inherit passthru; } ''
mkdir -pv $out/bin
${builtins.concatStringsSep "\n" (for exes (exe: ''
cp ${flake.packages."chainweb:exe:${exe}"}/bin/${exe} $out/bin/${exe}
chmod +w $out/bin/${exe}
$STRIP $out/bin/${exe}
${pkgs.lib.optionalString (pkgs.stdenv.isLinux) ''
patchelf --shrink-rpath $out/bin/${exe}
''}
''))}
'';
in {
# The Haskell project flake: Used by flake.nix
inherit flake;
Expand Down
11 changes: 11 additions & 0 deletions pact-diff/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# language
ImportQualifiedPost
#-}

module Main (main) where

import Chainweb.Pact.Backend.PactState.Diff qualified as PactDiff

main :: IO ()
main = do
PactDiff.main
Loading
Loading