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

Add pact-5 chainweb integration #1916

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion bench/Chainweb/Pact/Backend/ForkingBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ safeCapitalize = maybe [] (uncurry (:) . bimap toUpper (Prelude.map toLower)) .


-- TODO: Use the new `assertCommand` function.
validateCommand :: Command Text -> Either String ChainwebTransaction
validateCommand :: Command Text -> Either String Pact4Transaction
validateCommand cmdText = case verifyCommand cmdBS of
ProcSucc cmd -> Right (mkPayloadWithTextOld <$> cmd)
ProcFail err -> Left err
Expand Down
20 changes: 17 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ package pact
-- avoid conflict with cryptonite during linking
flags: +cryptonite-ed25519 -build-tool

package pact-tng
ghc-options: -Wwarn
-- avoid conflict with cryptonite during linking
flags: +cryptonite-ed25519 -build-tool

package rocksdb-haskell-kadena
ghc-options: -Wwarn -optc-w -optcxx-w

Expand All @@ -64,6 +69,9 @@ package vault
package yet-another-logger
flags: -tbmqueue

packages:
../pact-core

-- -------------------------------------------------------------------------- --
-- Source Repository Packages
--
Expand All @@ -78,6 +86,12 @@ source-repository-package
tag: 9ccef1fbeff545f07864896094eb2e2bd4c5ffb3
--sha256: 0pai52mvyikhm527if4gxa1nwsmva3wg3nhvida7qg48rchjrxry

-- source-repository-package
-- type: git
-- location: https://github.com/kadena-io/pact-5.git
-- tag: c065ebd60ea0460a98779968200e943044fe4939
-- --sha256: sha256-pSDMa5QZDF5/dsccDgZFQMfhgo+/HjDqc0m9W9h7m3g=

source-repository-package
type: git
location: https://github.com/kadena-io/pact-json.git
Expand Down Expand Up @@ -133,9 +147,9 @@ source-repository-package
-- Required for non-canonical decode in base64-bytestring (remove after 2.20 fork)
source-repository-package
type: git
location: https://github.com/emilypi/base64-bytestring-kadena
tag: 174af3523616c8fe01449da5ccbb9f16df097ac3
--sha256: sha256-kVFIy+Aj3TNJpsM1Cs/5uGmzeWwHKYWjjCQ+L1/XOj8=
location: https://github.com/kadena-io/base64-bytestring-kadena
tag: 90247042ab3b8662809210af2a78e6dee0f9b4ac
--sha256: sha256-xqIGml2asB+FxqVpsvVO59fdOGyJVBhZL6MyULvMGjc=

source-repository-package
type: git
Expand Down
18 changes: 14 additions & 4 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ custom-setup
-- -------------------------------------------------------------------------- --

library
import: warning-flags, debugging-flags
import: debugging-flags
default-language: Haskell2010
hs-source-dirs: src
other-modules:
Expand Down Expand Up @@ -297,6 +297,7 @@ library

-- pact
, Chainweb.Pact.Backend.ChainwebPactDb
, Chainweb.Pact.Backend.ChainwebPactCoreDb
, Chainweb.Pact.Backend.DbCache
, Chainweb.Pact.Backend.Compaction
, Chainweb.Pact.Backend.PactState
Expand All @@ -312,6 +313,7 @@ library
, Chainweb.Pact.Backend.SQLite.V2
, Chainweb.Pact.Backend.Types
, Chainweb.Pact.Backend.Utils
, Chainweb.Pact.Conversion
, Chainweb.Pact.NoCoinbase
, Chainweb.Pact.PactService
, Chainweb.Pact.PactService.Checkpointer
Expand All @@ -326,10 +328,14 @@ library
, Chainweb.Pact.Service.PactInProcApi
, Chainweb.Pact.Service.PactQueue
, Chainweb.Pact.Service.Types
, Chainweb.Pact.Templates
, Chainweb.Pact.TransactionExec
, Chainweb.Pact.Templates.Pact4
, Chainweb.Pact.Templates.Pact5
, Chainweb.Pact.TransactionExec.Pact4
, Chainweb.Pact.TransactionExec.Pact5
, Chainweb.Pact.Transactions.FungibleV2Transactions
, Chainweb.Pact.Transactions.CoinV3Transactions
, Chainweb.Pact.Transactions.CoinV4Transactions
, Chainweb.Pact.Transactions.CoinCoreV4Transactions
, Chainweb.Pact.Transactions.CoinV5Transactions
, Chainweb.Pact.Transactions.CoinV6Transactions
, Chainweb.Pact.Transactions.Mainnet0Transactions
Expand Down Expand Up @@ -366,6 +372,7 @@ library
, base16-bytestring >= 0.1
, base64-bytestring-kadena == 0.1
, binary >= 0.8
, bound >= 2
, bytestring >= 0.10.12
, case-insensitive >= 1.2
, cassava >= 0.5.1
Expand Down Expand Up @@ -416,6 +423,7 @@ library
, pact-json >= 0.1
, parallel >= 3.2.2.0
, patience >= 0.3
, pact-tng
, pem >=0.2
, primitive >= 0.7.1.0
, random >= 1.2
Expand Down Expand Up @@ -471,7 +479,7 @@ library
-- -------------------------------------------------------------------------- --

test-suite chainweb-tests
import: warning-flags, debugging-flags
import: debugging-flags
default-language: Haskell2010
ghc-options:
-threaded
Expand Down Expand Up @@ -589,6 +597,7 @@ test-suite chainweb-tests
, patience >= 0.3
, http-client-tls >=0.3
, pact
, pact-tng
, pact-json >= 0.1
, quickcheck-instances >= 0.3
, random >= 1.2
Expand Down Expand Up @@ -773,6 +782,7 @@ executable cwtool
, optparse-applicative >= 0.14
, pact
, pact-json
, pact-tng
, patience >= 0.3
, process >= 1.5
, quickcheck-instances >= 0.3
Expand Down
3 changes: 0 additions & 3 deletions pact/coin-contract/v5/install-coin-contract-v5.yaml

This file was deleted.

17 changes: 9 additions & 8 deletions src/Chainweb/Chainweb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ module Chainweb.Chainweb
, NowServing(..)

-- ** Mempool integration
, ChainwebTransaction
, Mempool.chainwebTransactionConfig
, Pact4Transaction
, Pact5Transaction
, Mempool.pact4TransactionConfig
, validatingMempoolConfig

, withChainweb
Expand Down Expand Up @@ -269,7 +270,7 @@ validatingMempoolConfig
-> Mempool.GasLimit
-> Mempool.GasPrice
-> MVar PactExecutionService
-> Mempool.InMemConfig ChainwebTransaction
-> Mempool.InMemConfig Pact4Transaction
validatingMempoolConfig cid v gl gp mv = Mempool.InMemConfig
{ Mempool._inmemTxCfg = txcfg
, Mempool._inmemTxBlockSizeLimit = gl
Expand All @@ -280,7 +281,7 @@ validatingMempoolConfig cid v gl gp mv = Mempool.InMemConfig
, Mempool._inmemCurrentTxsSize = currentTxsSize
}
where
txcfg = Mempool.chainwebTransactionConfig (maxBound :: PactParserVersion)
txcfg = Mempool.pact4TransactionConfig (maxBound :: PactParserVersion)
-- The mempool doesn't provide a chain context to the codec which means
-- that the latest version of the parser is used.

Expand All @@ -293,7 +294,7 @@ validatingMempoolConfig cid v gl gp mv = Mempool.InMemConfig

-- | Validation: Is this TX associated with the correct `ChainId`?
--
preInsertSingle :: ChainwebTransaction -> Either Mempool.InsertError ChainwebTransaction
preInsertSingle :: Pact4Transaction -> Either Mempool.InsertError Pact4Transaction
preInsertSingle tx = do
let !pay = payloadObj . P._cmdPayload $ tx
pcid = P._pmChainId $ P._pMeta pay
Expand All @@ -315,9 +316,9 @@ validatingMempoolConfig cid v gl gp mv = Mempool.InMemConfig
-- is gossiped to us from a peer's mempool.
--
preInsertBatch
:: V.Vector (T2 Mempool.TransactionHash ChainwebTransaction)
:: V.Vector (T2 Mempool.TransactionHash Pact4Transaction)
-> IO (V.Vector (Either (T2 Mempool.TransactionHash Mempool.InsertError)
(T2 Mempool.TransactionHash ChainwebTransaction)))
(T2 Mempool.TransactionHash Pact4Transaction)))
preInsertBatch txs = do
pex <- readMVar mv
rs <- _pactPreInsertCheck pex cid (V.map ssnd txs)
Expand Down Expand Up @@ -762,7 +763,7 @@ runChainweb cw nowServing = do
chainDbsToServe :: [(ChainId, BlockHeaderDb)]
chainDbsToServe = proj _chainResBlockHeaderDb

mempoolsToServe :: [(ChainId, Mempool.MempoolBackend ChainwebTransaction)]
mempoolsToServe :: [(ChainId, Mempool.MempoolBackend Pact4Transaction)]
mempoolsToServe = proj _chainResMempool

peerDb = _peerResDb (_chainwebPeer cw)
Expand Down
4 changes: 2 additions & 2 deletions src/Chainweb/Chainweb/ChainResources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import Chainweb.Storage.Table.RocksDB
data ChainResources logger = ChainResources
{ _chainResBlockHeaderDb :: !BlockHeaderDb
, _chainResLogger :: !logger
, _chainResMempool :: !(MempoolBackend ChainwebTransaction)
, _chainResMempool :: !(MempoolBackend Pact4Transaction)
, _chainResPact :: PactExecutionService
}

Expand All @@ -83,7 +83,7 @@ withChainResources
-> ChainId
-> RocksDb
-> logger
-> (MVar PactExecutionService -> Mempool.InMemConfig ChainwebTransaction)
-> (MVar PactExecutionService -> Mempool.InMemConfig Pact4Transaction)
-> PayloadDb tbl
-> FilePath
-- ^ database directory for checkpointer
Expand Down
12 changes: 6 additions & 6 deletions src/Chainweb/Mempool/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ import Data.LogMessage (JsonLog(..), LogFunction)

------------------------------------------------------------------------------
data MempoolConsensus = MempoolConsensus
{ mpcMempool :: !(MempoolBackend ChainwebTransaction)
{ mpcMempool :: !(MempoolBackend Pact4Transaction)
, mpcLastNewBlockParent :: !(IORef (Maybe BlockHeader))
, mpcProcessFork
:: LogFunction -> BlockHeader -> IO (Vector ChainwebTransaction, Vector ChainwebTransaction)
:: LogFunction -> BlockHeader -> IO (Vector Pact4Transaction, Vector Pact4Transaction)
}

data ReintroducedTxsLog = ReintroducedTxsLog
Expand All @@ -80,7 +80,7 @@ instance Exception MempoolException
------------------------------------------------------------------------------
mkMempoolConsensus
:: CanReadablePayloadCas tbl
=> MempoolBackend ChainwebTransaction
=> MempoolBackend Pact4Transaction
-> BlockHeaderDb
-> Maybe (PayloadDb tbl)
-> IO MempoolConsensus
Expand All @@ -102,7 +102,7 @@ processFork
-> IORef (Maybe BlockHeader)
-> LogFunction
-> BlockHeader
-> IO (Vector ChainwebTransaction, Vector ChainwebTransaction)
-> IO (Vector Pact4Transaction, Vector Pact4Transaction)
processFork blockHeaderDb payloadStore lastHeaderRef logFun newHeader = do
now <- getCurrentTimeIntegral
lastHeader <- readIORef lastHeaderRef
Expand All @@ -122,7 +122,7 @@ processForkCheckTTL
-> HashableTrans PayloadWithText -> Bool
processForkCheckTTL ppv now (HashableTrans t) =
either (const False) (const True) $
txTTLCheck (chainwebTransactionConfig ppv) now t
txTTLCheck (pact4TransactionConfig ppv) now t


------------------------------------------------------------------------------
Expand Down Expand Up @@ -194,4 +194,4 @@ chainwebTxsFromPd ppv pd = do
let theRights = rights $ toList eithers
return $! HS.fromList $ HashableTrans <$!> theRights
where
toCWTransaction = codecDecode (chainwebPayloadCodec ppv)
toCWTransaction = codecDecode (pact4PayloadCodec ppv)
10 changes: 5 additions & 5 deletions src/Chainweb/Mempool/Mempool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module Chainweb.Mempool.Mempool
, bfTxHashes
, bfCount

, chainwebTransactionConfig
, pact4TransactionConfig
, mockCodec
, mockEncode
, mockBlockGasLimit
Expand Down Expand Up @@ -363,11 +363,11 @@ noopMempool = do

------------------------------------------------------------------------------

chainwebTransactionConfig
pact4TransactionConfig
:: PactParserVersion
-> TransactionConfig ChainwebTransaction
chainwebTransactionConfig ppv = TransactionConfig
{ txCodec = chainwebPayloadCodec ppv
-> TransactionConfig Pact4Transaction
pact4TransactionConfig ppv = TransactionConfig
{ txCodec = pact4PayloadCodec ppv
, txHasher = commandHash
, txHashMeta = chainwebTestHashMeta
, txGasPrice = getGasPrice
Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/Miner/Miners.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ localTest lf v coord m cdb gen miners =
--
mempoolNoopMiner
:: LogFunction
-> HashMap ChainId (MempoolBackend ChainwebTransaction)
-> HashMap ChainId (MempoolBackend Pact4Transaction)
-> IO ()
mempoolNoopMiner lf chainRes =
runForever lf "Chainweb.Miner.Miners.mempoolNoopMiner" $ do
Expand Down
Loading
Loading