Skip to content

Commit

Permalink
Deposit and Recover
Browse files Browse the repository at this point in the history
Signed-off-by: Sasha Bogicevic <[email protected]>
  • Loading branch information
v0d1ch committed Sep 2, 2024
1 parent 465dc4b commit 5fe3e18
Show file tree
Hide file tree
Showing 19 changed files with 599 additions and 144 deletions.
3 changes: 3 additions & 0 deletions hydra-node/bench/tx-cost/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ scriptSizes =
, "| " <> "νCommit" <> " | " <> serialiseToRawBytesHexText commitScriptHash <> " | " <> show commitScriptSize <> " | "
, "| " <> "νHead" <> " | " <> serialiseToRawBytesHexText headScriptHash <> " | " <> show headScriptSize <> " | "
, "| " <> "μHead" <> " | " <> serialiseToRawBytesHexText mintingScriptHash <> "* | " <> show mintingScriptSize <> " | "
, "| " <> "νDeposit" <> " | " <> serialiseToRawBytesHexText depositScriptHash <> " | " <> show depositScriptSize <> " | "
, ""
, "* The minting policy hash is only usable for comparison. As the script is parameterized, the actual script is unique per head."
]
Expand All @@ -148,6 +149,8 @@ scriptSizes =
, commitScriptSize
, headScriptHash
, headScriptSize
, depositScriptHash
, depositScriptSize
} = scriptInfo

costOfInit :: IO Text
Expand Down
26 changes: 26 additions & 0 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ onOpenNetworkReqTx ::
onOpenNetworkReqTx env ledger st ttl tx =
-- Keep track of transactions by-id
(newState TransactionReceived{tx} <>) $
-- Spec: wait L̂ ◦ tx ≠ ⊥
-- Spec: wait L̂ ◦ tx ≠ ⊥

-- Spec: wait L̂ ◦ tx ≠ ⊥
waitApplyTx $ \newLocalUTxO ->
(cause (ClientEffect $ ServerOutput.TxValid headId tx) <>) $
-- Spec: T̂ ← T̂ ⋃ {tx}
-- Spec: T̂ ← T̂ ⋃ {tx}
-- L̂ ← L̂ ◦ tx
-- L̂ ← L̂ ◦ tx

-- Spec: T̂ ← T̂ ⋃ {tx}
-- L̂ ← L̂ ◦ tx
newState TransactionAppliedToLocalUTxO{tx, newLocalUTxO}
Expand Down Expand Up @@ -410,8 +418,26 @@ onOpenNetworkReqSn ::
onOpenNetworkReqSn env ledger st otherParty sv sn requestedTxIds mDecommitTx =
-- Spec: require s = ŝ + 1 ∧ leader(s) = j
requireReqSn $
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s

-- Spec: wait ŝ = ̅S.s
waitNoSnapshotInFlight $
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂

-- Spec: wait v = v̂
waitOnSnapshotVersion $
requireApplicableDecommitTx $ \(activeUTxO, mUtxoToDecommit) ->
Expand Down
35 changes: 35 additions & 0 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Gen.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- | Generators used in mutation testing framework
module Hydra.Chain.Direct.Contract.Gen where

import Data.ByteString qualified as BS
import Hydra.Cardano.Api
import Hydra.Contract.HeadTokens (headPolicyId)
import Hydra.Contract.Util (hydraHeadV1)
import Hydra.Prelude
import Hydra.Tx.Fixture qualified as Fixtures
import Hydra.Tx.Utils ()
import PlutusTx.Builtins (fromBuiltin)
import Test.QuickCheck (oneof, suchThat, vector)

-- * Party / key utilities

genBytes :: Gen ByteString
genBytes = arbitrary

genHash :: Gen ByteString
genHash = BS.pack <$> vector 32

-- | Generates value such that:
-- - alters between policy id we use in test fixtures with a random one.
-- - mixing arbitrary token names with 'hydraHeadV1'
-- - excluding 0 for quantity to mimic minting/burning
genMintedOrBurnedValue :: Gen Value
genMintedOrBurnedValue = do
policyId <-
oneof
[ headPolicyId <$> arbitrary
, pure Fixtures.testPolicyId
]
tokenName <- oneof [arbitrary, pure (AssetName $ fromBuiltin hydraHeadV1)]
quantity <- arbitrary `suchThat` (/= 0)
pure $ valueFromList [(AssetId policyId tokenName, Quantity quantity)]
2 changes: 1 addition & 1 deletion hydra-plutus/scripts/vDeposit.plutus
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "PlutusScriptV2",
"description": "hydra-vDeposit-0.18.1-42-gfdb9d672a",
"cborHex": "590ccd590cca0100003232332232332232323232323232323322323232323232333222323232323232323232323232323232323232323232222533533332323222235003322322225335008153535300c5006220012233553335002213300d49010344303100333573466e200040140c80c44c0c92410344303200130324910344303200153353300c49010344303600533533302a02300535302b00922222222222200821533533302b024323724605e66050446a004446a00644a666a6605800800426605a006002266058008004266058008004002605a00800242666ae68cdc3800999818110009a98181100111000a40040660642062206026601892103433032003006355335300d302b0091303249010350543800221002222200310301030153535300c5006220022233553335002213300d49010344303400333573466e240040140c40c84c0c9241034430330013032491034430330013300c49010344303500330233724606a66a0266068006a66a601aa010260649210350543900221001372460786604c446a004446a004446a00a446a00444a666a6605c00c00426605e00a00226605c00c00426605c00c0040062060607444a66a00220584426a00444a666ae68cdc7801003898178008980300189a8009100111299a8008813899ab9c00202623500122222222222200a23500122222222222200530040033232325333573466e1d2000002112200215333573466e1d200200211220011302701535573c0046aae74004dd50011919192999ab9a3370e90000010999109198008018011919192999ab9a3370e9000001099191919191919191919199999999999911111111111091999999999998008068060058050048040038030028020018011980c80e1aba100b3301901c357420146603203e6ae84024ccc091d728119aba100833302475ca0466ae8401ccc06406cd5d08031998120103ad3574200a646464a666ae68cdc3a4000004266442466002006004646464a666ae68cdc3a40000042664424660020060046603ceb4d5d0800980e9aba135744002260740506aae78008d55ce8009baa35742002646464a666ae68cdc3a40000042664424660020060046603ceb4d5d0800980e9aba135744002260740506aae78008d55ce8009baa357426ae880044c0dc094d55cf0011aab9d00137546ae84010cc065d71aba100333302401a01635742004666048eb8058d5d0800980f1aba1357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10008981500c1aab9e00235573a0026ea8d5d080098069aba1357440022604e02a6aae78008d55ce8009baa001102b1302449103505435003223232325333573466e1d20000021323233332222123333001005004003002375c6ae8400cdd71aba1002375a6ae84004c01cd5d09aba2001357440026ae880044c09404cd55cf0011aab9d0013754002600a4646464a666ae68cdc3a4000004266442466002006004601a6ae84004dd71aba135744002260480246aae78008d55ce8009baa0013302d221225333573466e240092000102f15335001102f22133503000233530061200133702008900100089000900091919192999ab9a3370e9000001080f8a999ab9a3370e90010010810098108079aab9e00235573a0026ea800488c8c8c94ccd5cd19b87480000084488800854ccd5cd19b87480080084c84888c00c010c014d5d08008a999ab9a3370e900200108911000898108079aab9e00235573a0026ea80048c88c008dd60009815111999aab9f001202b233502a30043574200460066ae8800807c8c8c8c94ccd5cd19b87480000084c848888c00c014dd71aba100115333573466e1d20020021321222230010053007357420022a666ae68cdc3a400800426424444600400a60146ae8400454ccd5cd19b87480180084c848888c010014c014d5d08008980f0061aab9e00235573a0026ea80048c8c8c94ccd5cd19b87480000084c848888888c014020c024d5d08008a999ab9a3370e900100109909111111180380418049aba100115333573466e1d20040021332212222222330060090083009357420026eb8d5d09aba200115333573466e1d2006002133221222222233002009008375c6ae84004dd71aba1357440022a666ae68cdc3a40100042664424444444660020120106eb8d5d08009bad357426ae8800454ccd5cd19b874802800844888888801054ccd5cd19b874803000844888888800c4c07402cd55cf0011aab9d00137540024646464a666ae68cdc3a4000004266442466002006004600a6ae84004c01cd5d09aba20011301c00a35573c0046aae74004dd500091919192999ab9a3370e900000109991091980080180118029aba1001375a6ae84d5d10008980d8049aab9e00235573a0026ea80048c8c8c94ccd5cd19b87480000084dd71aba10011301a00835573c0046aae74004dd50009911919192999ab9a3370e900000109919199991110919998008028020018011919192999ab9a3370e900000109991091980080180118061aba10013300a00b357426ae880044c07c034d55cf0011aab9d00137546ae8400cccc031d728059aba10023232325333573466e1d20000021122200315333573466e1d200200213212223001004375c6ae8400454ccd5cd19b87480100084c84888c008010d5d08008980f8069aab9e00235573a0026ea8d5d080099803bae357426ae88004d5d10009aba20011301a00835573c0046aae74004dd5000911919192999ab9a3370e90010010a8110a999ab9a3370e90000010981198029aba10011301a00835573c0046aae74004dd500091919192999ab9a3370e9000001099091180100198029aba100115333573466e1d2002002132333222122333001005004003375a6ae84008dd69aba1001375a6ae84d5d10009aba20011301800635573c0046aae74004dd500091919192999ab9a3370e900000109909118010019bae357420022a666ae68cdc3a400400426424460020066eb8d5d08008980b8029aab9e00235573a0026ea80052401035054310013300175ceb488c88c008dd58009810111999aab9f001202123233502133221233001003002300635573a002600a6aae78004c010d5d10019aba100201522333573466e3c00800404003c894ccd5cd19b8f002001100715333573466e4400800440144018894ccd5cd19b87002001100615333573466e24008004401040148c8c8c8c8c8c8c88c008c01c004c084894cd40044c008c00c0848854cd40044008884c018c01c014c080894cd400440808854cd4004400c884cd408ccc01c010008c018004c07c8894cd400840048854cd400c4010c88854ccd4cc0340140085400c4cd4090008cc02001c0045400c4cd4084008cc01400400cd400c888004d4008888008d400488800ccc8c0040048848c8ccc0088c008888c00c0108c008888c0080108c008888c0040108d4cc01001000cd400c00448888ccc01094cd40044cd40740780788854cd40044cd407c00c0808854c8ccd4cc02c01400c540044ccc02000ccd408801408c008540044ccc0180088cd40880140040048894cd40044cd407ccd407c00c008c018080c88854ccd4cc02c0180085400c4ccc020008cd40880180140045400c4cd407ccd407c00c008c0180048894c8cd40084c0052622153233353300c0070031500113004498540044ccc01c0088c018cd408c01c0040048cd4080c00ccd4080010084c01c008488800c4888008488800488c88c008004c060894cd400454050884d4008894cd4cc02000801c4c0640044c01800c8d400488008c050894cd40044050884cd4054d400888008c010004c04c894cd40044050884cdc51bb335002223374a900019aba03374a900019aba037520046ec4048cd5d01ba80013762024600800246600224660024466e0000800520002233702004002602244a66a00220064426a00444a666ae68cdc7a4410b4879647261486561645631000021333573466e1d200200100800713006003122002122001232633573800200424002601844a66a0022900011099b8048008c010004c02c894cd40044030884cdc51bb33500222223374a900019aba035004223374a900019aba0300b00233574066018466a002466e952000335740601a0026ec4040888cdd2a400466ae80dd400199aba0375000466ae80dd40009bb1012001376201c66ae80ccc02dd499805ba92375000200666ae814ccd40084cdd2a40006ec403084cdd2a400866ae80004dd88069099ba548008cd5d01ba9001376201a66ae80cc029d48009bb100c3004001233500123374a900019aba037520026ec40148cdd2a400466ae80dd48009bb1005225335001213374a900019aba03003001376200a266e9520023762008446446e98c008004c028894cd40044dd90029109a8011119aba0337606010004600e002600c00693109118010018891000980211299a80088029109a8011119b8a0013006003122002122122330010040034881002323001001230022330020020011"
"cborHex": "590ac5590ac20100003233322232332232323232323232323232323232323322323232323232323232323232323232323232322225335333222353007006322225335006101f2153535355005222222222222005220022233553335002213300b4910344303400333573466e2400401808808c4c07124103443033001301c491034430330013300a49010344303500333573466e3cdc9181199a8078019aa8039111111111110051b92302b3028302f004022021102113500122002225335001101a1335738004032646464a666ae68cdc3a400000422440042a666ae68cdc3a400400426424460020066eb4d5d08008980a80b1aab9e00235573a0026ea8008c8c8c94ccd5cd19b87480000084cc8848cc00400c008c8c8c94ccd5cd19b87480000084c8c8c8c8c8c8c8c8c8c8cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cc064070d5d08059980c80e1aba100a3301901f3574201266604aeb94090d5d0804199812bae50243574200e660320366ae84018ccc094081d69aba10053232325333573466e1d20000021332212330010030023232325333573466e1d20000021332212330010030023301e75a6ae84004c074d5d09aba20011302802935573c0046aae74004dd51aba10013232325333573466e1d20000021332212330010030023301e75a6ae84004c074d5d09aba20011302802935573c0046aae74004dd51aba1357440022604a04c6aae78008d55ce8009baa3574200866032eb8d5d080199981280d00b1aba100233302575c02c6ae84004c078d5d09aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae880044c060064d55cf0011aab9d00137546ae84004c034d5d09aba20011301501635573c0046aae74004dd5000880e89809248103505435003223232325333573466e1d200000213233322212333001004003002375c6ae84008dd69aba10013006357426ae88004d5d10008980980a1aab9e00235573a0026ea8004c0148c8c8c94ccd5cd19b87480000084cc8848cc00400c008c034d5d08009bae357426ae880044c04804cd55cf0011aab9d00137540026605044244a666ae68cdc480124000204e2a66a002204e44266a05000466a600c2400266e04011200200112001200123232325333573466e1d2000002101415333573466e1d200200210151300f01035573c0046aae74004dd5000911919192999ab9a3370e9000001089110010a999ab9a3370e90010010990911180180218029aba100115333573466e1d2004002112220011300f01035573c0046aae74004dd5000919118011bac00130252233335573e0024046466a04460086ae84008c00cd5d100100811919192999ab9a3370e90000010990911118018029bae357420022a666ae68cdc3a400400426424444600200a600e6ae8400454ccd5cd19b87480100084c848888c008014c028d5d08008a999ab9a3370e900300109909111180200298029aba10011300c00d35573c0046aae74004dd500091919192999ab9a3370e900000109909111111180280418049aba100115333573466e1d20020021321222222230070083009357420022a666ae68cdc3a400800426644244444446600c01201060126ae84004dd71aba1357440022a666ae68cdc3a400c0042664424444444660040120106eb8d5d08009bae357426ae8800454ccd5cd19b87480200084cc8848888888cc004024020dd71aba1001375a6ae84d5d10008a999ab9a3370e90050010891111110020a999ab9a3370e9006001089111111001898058061aab9e00235573a0026ea80048c8c8c94ccd5cd19b87480000084cc8848cc00400c008c014d5d080098039aba135744002260140166aae78008d55ce8009baa00123232325333573466e1d20000021332212330010030023005357420026eb4d5d09aba20011300900a35573c0046aae74004dd500091919192999ab9a3370e900000109bae35742002260100126aae78008d55ce8009baa0013223232325333573466e1d200000213232333322221233330010050040030023232325333573466e1d2000002133221233001003002300c35742002660140166ae84d5d1000898068071aab9e00235573a0026ea8d5d0801999806bae500c35742004646464a666ae68cdc3a4000004224440062a666ae68cdc3a4004004264244460020086eb8d5d08008a999ab9a3370e9002001099091118010021aba10011300d00e35573c0046aae74004dd51aba10013300775c6ae84d5d10009aba200135744002260100126aae78008d55ce8009baa001223232325333573466e1d2002002112200115333573466e1d20000021321223002003300535742002260100126aae78008d55ce8009baa00123232325333573466e1d200000213212230020033005357420022a666ae68cdc3a400400426466644424466600200a0080066eb4d5d08011bad357420026eb4d5d09aba2001357440022600c00e6aae78008d55ce8009baa00123232325333573466e1d20000021321223002003375c6ae8400454ccd5cd19b87480080084c8488c00400cdd71aba10011300500635573c0046aae74004dd5000919319ab9c0010054901035054310013300175ceb488c88c008dd5800980d111999aab9f001201823233501833221233001003002300635573a002600a6aae78004c010d5d10019aba1002005120011220021220013014225335001100b221337146eccd40088888cdd2a400066ae80d401088cdd2a400066ae80c02c008cd5d019806119a800919ba548000cd5d018068009bb10102223374a900119aba0375000666ae80dd400119aba037500026ec4048004dd880719aba033300b75266016ea48dd400080199aba05333500213374a90001bb100c213374a900219aba0001376201a4266e9520023357406ea4004dd880699aba03300a7520026ec4030c0100048cd40048cdd2a400066ae80dd48009bb100523374a900119aba037520026ec4014894cd400484cdd2a400066ae80c00c004dd8802899ba548008dd8802111911ba6300200130132253350011376400a4426a0044466ae80cdd8180400118038009803001a4c601e44a66a002260046006018442a66a0022004442600c600e00a601c44a66a0022016442a66a002200644266a01c6600e008004600c002601a444a66a0042002442a66a006200864442a666a6602200a0042a006266a01e0046601000e0022a006266a0180046600a002006601844a66a00220064426a0044466e28004c01800d22010035003222001350022220023500122200333230010012212323330022300222230030042300222230020042300222230010042353300400400335003001122223330042533500113350060070072215335001133500800300922153233353300d00500315001133300800333500b00500c002150011333006002233500b00500100122253350011335008335008003002300600932221533353300d00600215003133300800233500b0060050011500313350083350080030023006001222532335002130014988854c8ccd4cc03801c00c540044c011261500113330070022300633500c0070010012335009300333500900400a30070021220021221223300100400332223500222350022235005223500222533353300b00600215333573466e1c014004403854ccd5cd19b89005001100c100d13300b00600213300b006002225333573466e3c008004401454ccd5cd19b91002001100310041222003122200212220012323001001230022330020020011"
}
5 changes: 5 additions & 0 deletions hydra-plutus/src/Hydra/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Hydra.Cardano.Api (
pattern PlutusScript,
)
import Hydra.Contract.Commit qualified as Commit
import Hydra.Contract.Deposit qualified as Deposit
import Hydra.Contract.Head qualified as Head
import Hydra.Contract.HeadTokens qualified as HeadTokens
import Hydra.Contract.Initial qualified as Initial
Expand All @@ -30,6 +31,8 @@ data ScriptInfo = ScriptInfo
, commitScriptSize :: Int64
, headScriptHash :: ScriptHash
, headScriptSize :: Int64
, depositScriptHash :: ScriptHash
, depositScriptSize :: Int64
}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON)
Expand All @@ -47,6 +50,8 @@ scriptInfo =
, commitScriptSize = scriptSize Commit.validatorScript
, headScriptHash = plutusScriptHash Head.validatorScript
, headScriptSize = scriptSize Head.validatorScript
, depositScriptHash = plutusScriptHash Deposit.validatorScript
, depositScriptSize = scriptSize Deposit.validatorScript
}
where
plutusScriptHash =
Expand Down
Loading

0 comments on commit 5fe3e18

Please sign in to comment.