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

Increment validator and corresponding mutations #1715

Merged
merged 88 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
60bb86d
Add increment redeemer
v0d1ch Oct 15, 2024
ee6e19b
Implement check and mutation for altering the parameters
v0d1ch Oct 15, 2024
c9f8e5a
Check the increment version
v0d1ch Oct 15, 2024
2a0c9f8
Postpone check that claim deposit is spent
v0d1ch Oct 16, 2024
754277c
Move hashPreSerializedCommits and hashTxOuts to Utils module
v0d1ch Oct 16, 2024
8616023
Check snapshot sig and corresponding mutation
v0d1ch Oct 16, 2024
5e40ea6
Check value is increased and the mutation for it
v0d1ch Oct 16, 2024
b630d4a
Tx signed by participant check and mutation
v0d1ch Oct 17, 2024
87a4eb2
Check that deposit ref is spent together with mutation
v0d1ch Oct 17, 2024
63eb814
Add new close redeemer types
v0d1ch Oct 18, 2024
1a8d1fd
Increase tx size to make increment work for now
v0d1ch Oct 18, 2024
b65b7a2
Use === for value comparison and small fix for deposit spending
v0d1ch Oct 24, 2024
c0a7704
Derive deposited value from the deposit out present in the deposit sc…
ffakenz Oct 24, 2024
94ede14
Fix close used healthy tx
ffakenz Oct 24, 2024
4164eae
Correctly set value for script deposit
ffakenz Oct 24, 2024
3715b10
Add StateSpec tests for increment tx
v0d1ch Oct 24, 2024
83f08b1
Make the increment generation pass the state spec tests
v0d1ch Oct 25, 2024
77bd406
Add new close redeemer CloseAny
v0d1ch Oct 28, 2024
568febf
Revrite deposit validator in aiken
v0d1ch Oct 21, 2024
aa397f7
Use the new deposit aiken validator
v0d1ch Oct 29, 2024
1c1aef0
Recover redeemer - compare output hashes
v0d1ch Oct 29, 2024
559ede3
Add increment transaction to tx-cost
v0d1ch Oct 30, 2024
a39fc76
Small cleanup for DepositDatum type
v0d1ch Oct 30, 2024
2a46222
Rename ContestOutdated to ContestUnusedDec
v0d1ch Oct 30, 2024
25a4ace
ContestUsedDec AlterRedeemerDecommitHash
v0d1ch Oct 30, 2024
3e5be06
ContestUseDec AlterDatumDeltaUTxOHash
v0d1ch Oct 30, 2024
6a29d86
ContestUsedDec MutateSnapshotVersion
v0d1ch Oct 30, 2024
635b294
Merge contest used and unused mutations
v0d1ch Oct 30, 2024
4222394
Add ContestUnusedDec redeemer
v0d1ch Oct 30, 2024
082cb6a
Post rebase fixes
v0d1ch Nov 12, 2024
8873783
Reduce the size of Head minting policy
v0d1ch Nov 12, 2024
29e0764
Publish scripts separately
v0d1ch Nov 13, 2024
f71addb
Fix all of state spec tests
v0d1ch Nov 13, 2024
51659da
Add new Contest redeemer types and decide on usage
v0d1ch Nov 14, 2024
966f42d
Refactor redeemer construction for close/contest
v0d1ch Nov 14, 2024
5964b2d
Bump mithil to unstable
v0d1ch Nov 15, 2024
c509bd0
Stub out Increment in TxTraceSpec
v0d1ch Nov 15, 2024
e68ae09
Stub out Deposit in TxTraceSpec
v0d1ch Nov 15, 2024
4724ba5
Trying to get the expected coverage
v0d1ch Nov 18, 2024
f8a0a90
Introduce alphaUTxOHash to solve close/fanout bugs
v0d1ch Nov 27, 2024
898198f
Rename delta hash to omega and fix mutations + behavior
v0d1ch Nov 28, 2024
5afad4a
Exercise closing a bit more
v0d1ch Nov 28, 2024
81f86ab
More progress on the coverage
v0d1ch Nov 29, 2024
c7f9558
Change changelog to enable releasing again
v0d1ch Nov 29, 2024
bc0a544
Try to fix tui refreshing
v0d1ch Nov 29, 2024
c58ce8d
Reduce the coverage for multiple contests
v0d1ch Dec 2, 2024
b3ec8a6
Add more info when de/crement and recover fail
v0d1ch Dec 2, 2024
d100a53
Add CommitIgnored message
v0d1ch Dec 3, 2024
17471b1
Improve on e2e but no luck reproducing
v0d1ch Dec 3, 2024
98ce3ed
Remove pending decommit from a utxo in the tui
v0d1ch Dec 3, 2024
fb87c11
minor display enhancements
ffakenz Dec 3, 2024
f071c65
Handle multiple increment messages and refresh active utxo on every u…
ffakenz Dec 3, 2024
9f844fc
Add more behaviour tests
v0d1ch Dec 4, 2024
7a00221
tui: add recover pending deposit action
ffakenz Dec 4, 2024
945887b
Add Recover to the tui
v0d1ch Dec 4, 2024
e0623f3
tui: refactor deposit form into radio
ffakenz Dec 5, 2024
52c637d
Improve on tui messages related to inc/decrement
v0d1ch Dec 5, 2024
a414492
tui: minor enhancement to handle report events info
ffakenz Dec 5, 2024
5c72548
Reduce max number of parties to 8
v0d1ch Dec 6, 2024
048ea8a
Reduce the max parties back to 7
v0d1ch Dec 6, 2024
85a210d
Fix json schema tests
v0d1ch Dec 6, 2024
afa54d8
PR Review changes
v0d1ch Dec 9, 2024
eb301a4
Parse scripts from list as well
noonio Dec 9, 2024
c5211bf
Correctly form the input string --hydra-scripts-tx-id
v0d1ch Dec 9, 2024
89e16a5
Fix assertion in the new edited test in DirectChain
v0d1ch Dec 9, 2024
b2ae626
Explain de/committing
v0d1ch Dec 11, 2024
f9b3592
Update networks.json with preview tx-ids
v0d1ch Dec 11, 2024
28cc787
Add separate error for fanout commit mismatch
v0d1ch Dec 12, 2024
54933ab
Add rust-overlay to please mithril
v0d1ch Dec 12, 2024
5672065
Add preprod tx-ids to networks.json
v0d1ch Dec 12, 2024
741042c
Fix loop in the tx-trace bench
v0d1ch Dec 16, 2024
ab7fccf
Apply suggestions from code review
v0d1ch Dec 16, 2024
3f2f198
Remove rust overlay
v0d1ch Dec 16, 2024
515130d
Fix rebase error
v0d1ch Dec 16, 2024
341bd86
Fix StateSpec close/fanout utxo generation
v0d1ch Dec 17, 2024
d51799d
Fix the loop in genFanoutTx/tx-cost
v0d1ch Dec 17, 2024
c633b42
PR Review changes
v0d1ch Dec 17, 2024
e742e96
Fix Plutus tests
v0d1ch Dec 17, 2024
dbefb5a
Use IncrementalAction to remove error usage in Close
v0d1ch Dec 17, 2024
4807922
Refactor contest with IncrementalAction and fix the contestcurrent
v0d1ch Dec 18, 2024
91bc663
Simplify close and contest pattern matches
v0d1ch Dec 18, 2024
96947d1
More checks on-chain, some more refactoring
v0d1ch Dec 18, 2024
b920d9f
State fanout test to fix
v0d1ch Dec 18, 2024
0fd1e1a
Remove unused functions
v0d1ch Dec 19, 2024
92db63b
Update preview 0.20 scripts
v0d1ch Dec 19, 2024
9bfdd89
Fix DirectChainSpec version
v0d1ch Dec 19, 2024
b46fad2
Add mainnet scripts tx-ids
v0d1ch Dec 23, 2024
c29a27a
Enable errors on broken links and fix haddock paths
v0d1ch Dec 25, 2024
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
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ changes.

## [0.20.0] - UNRELEASED

- Bump docusaurus version
- **BETA** hydra-node now supports incremental commits in beta mode. We would like to test out this feature
with the community members building on Hydra. This feature means you can commit funds to a Head while it is running.
TODO: Implement missing spec changes.

- **IMPORTANT - Do not release this version**
- Incremental commits - off-chain changes to make the incremental commits possible.
Important to note is that on-chain security is not implemented and hydra-node in this
state is not releasable!
Missing off-chain items to implement as a series of next PR's:
- Revisit types related to observations/posting transactions and make sure the fields are named appropriatelly
- **BREAKING** hydra-node accepts multiple `hydra-scripts-tx-id` as a comma-seperated list, as the outcome of changes in the Hydra scripts publishing.

- Tested with `cardano-node 10.1.2` and `cardano-cli 10.1.1.0`.

Expand All @@ -41,6 +38,8 @@ changes.
- Overall this results in transactions still to be submitted once per client,
but requires signifanctly less book-keeping on the client-side.

- Bump docusaurus version

- Add blockfrost support to `hydra-chain-observer`, to follow the chain via Blockfrost API.

- Fix `bench-e2e single` benchmarks and only use `--output-directory` to keep
Expand Down
4 changes: 3 additions & 1 deletion demo/seed-devnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ function publishReferenceScripts() {
hnode publish-scripts \
--testnet-magic ${NETWORK_ID} \
--node-socket ${DEVNET_DIR}/node.socket \
--cardano-signing-key devnet/credentials/faucet.sk
--cardano-signing-key devnet/credentials/faucet.sk \
| tr '\n' ',' \
| head -c -1
}

function queryPParams() {
Expand Down
4 changes: 2 additions & 2 deletions docs/benchmarks/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here, isolate the transaction for `5` parties by altering the function to `maybe

## Compiling a script for profiling

The `collectCom` transaction utilizes the `vCommit` and `vHead` validator scripts. To enable profiling, add the following directive to the modules [`Hydra.Contract.Commit`](/haddock/hydra-plutus/Hydra-Contract-Commit.html) and [`Hydra.Contract.Head`](/haddock/hydra-plutus/Hydra-Contract-Head.html):
The `collectCom` transaction utilizes the `vCommit` and `vHead` validator scripts. To enable profiling, add the following directive to the modules [`Hydra.Contract.Commit`](pathname:///haddock/hydra-plutus/Hydra-Contract-Commit.html) and [`Hydra.Contract.Head`](pathname:///haddock/hydra-plutus/Hydra-Contract-Head.html):

```
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:profile-all #-}
Expand All @@ -48,7 +48,7 @@ The `collectCom` transaction utilizes the `vCommit` and `vHead` validator script
## Acquiring an executable script

You can achieve this using
[`prepareTxScripts`](/haddock/hydra-tx/Hydra-Ledger-Cardano-Evaluate.html#v:prepareTxScripts).
[`prepareTxScripts`](pathname:///haddock/hydra-tx/Hydra-Ledger-Cardano-Evaluate.html#v:prepareTxScripts).
To acquire and save the fully applied scripts from the transaction onto disk, run:

```haskell
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev/architecture/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ See also [this ADR](/adr/27) for a past discussion on making the network compone

### Current network stack

See [haddocks](/haddock/hydra-node/Hydra-Node-Network.html)
See [haddocks](pathname:///haddock/hydra-node/Hydra-Node-Network.html)

- Hydra nodes form a network of pairwise connected *peers* using point-to-point (eg, TCP) connections that are expected to remain active at all times:
- Nodes use [Ouroboros](https://github.com/input-output-hk/ouroboros-network/) as the underlying network abstraction, which manages connections with peers via a reliable point-to-point stream-based communication framework known as a `Snocket`
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev/commit_to_a_Head.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ users can request a recover by providing a `TxId` of the deposit transaction
which initially locked the funds.

::::info
Users can also request to see pending deposits. See our api [documentation](/api-reference/#operation-publish-/commits).
Users can also request to see pending deposits. See our api [documentation](/api-reference).
::::

Any Head participant can request to recover the deposit not only the one which initially deposited the funds.
Expand Down
121 changes: 121 additions & 0 deletions docs/docs/dev/incremental-commits-and-decommits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Incremental commits and decommits

These two new addons to the initial Hydra Head protocol deserve more
explanation so our users are aware of how they work _under the hood_ to bring
more clarity to these processes.

For now these two new additions run sequentially so we are doing one thing at a
time, at least for now, while we will think about batching certain actions in
the future if the need for that arises.

It is only possible to either commit or decommit - we don't allow snapshots with both
fields specified for simplicity. This restriction might be lifted later on - once we
are sure this simpler version works nicely.

## Incremental Commits

Incremental Commits allow us to take some `UTxO` from L1 and make it available
on L2 for transacting inside of a running Hydra Head.

The process for incremental commits is pretty much the same as when
_committing_ before the Head is in the `Open` state. In fact we can open a Head
without committing some funds and then _top-up_ our L2 funds by doing incremental
commits.

The process of incrementally committing a `UTxO` starts by sending a `HTTP` request to
the hydra-node API endpoint:

```bash

curl -X POST <IP>:<PORT>/commit --data @commit.json
```

:::info

Note that the commit transaction, which is sent to the hydra-node API, only needs
to specify the transaction inputs present in L1 that we want to make available
on L2. It will ignore any specified outputs and instead the owner of
incremented `UTxO` on L2 is the same one that owned the funds on L1.

:::

Hydra node will accept a plain `UTxO` encoded as JSON in the `POST` request
body or a _blueprint_ transaction together with the `UTxO` used to resolve it's
inputs.

_Blueprint_ transaction is just like a recipe that describes which transaction
inputs should be made available on L2 network ignoring any specified outputs.
It goes together with a `UTxO` used to resolve the transaction inputs. It's
purpose is to prove that one can spend specified transaction inputs.

Successfull API response includes a _deposit_ transaction that needs to be
signed and submitted by the user in order to kick-off the deposit process.

This process just locks the specified `UTxO` at a deposit script address which
will then, later on, after confirmed snapshot, be unlocked by the _increment_
transaction which will actually make this `UTxO` available on L2.

The deposit transaction contains a deadline - time window in which we expect
the hydra-node to be able to observe this deposit and issue a _increment_
transaction that will do the heavy lifting and bring the specified input on L2.

Currently, _contestation period_ value is used to specify a deposit deadline
but this should be made available as a separate argument to hydra-node since it
heavily depends on the network we are running on.

Once a hydra-node observes a deposit transaction it will record the deposit as
pending into the local state. There can be many pending deposits but the new
Snapshot will include them one by one.

When this new Snapshot is acknowledged by all parties _increment_ transaction
will be posted by the leader.

:::info
Note that any node that posts increment transaction will also pay the fees even if
the deposit will not be owned by them on L2.
:::

Upon observing increment transaction we remove deposit from the local pending deposits
and the process can start again.

:::note

Since we can potentially request many deposits, the leader will increment only
one of them. While others are stuck in the pending state any new transaction on
L2 will take next pending deposit and try to include it in a snapshot.

:::

## Incremental Decommits

Incremental decommits allow us to take some L2 `UTxO` and bring it to the L1
while the Head protocol is running.

Head participant (or any other user that can send requests to the hydra-node
API endpoint) requests inclusion of some UTxO from L1 by sending a `POST`
`HTTP` request which contains in the request body a decommit transaction
encoded as _TextEnvelope_ JSON value.

```bash
curl -X POST <IP>:<PORT>/decommit --data @decommit-tx.json
```

This transaction needs to be signed by the owner of the funds on L2.

:::info

What we call a decommit transaction is the one that user supplies in the API
endpoint. The decrement transaction is the transaction that hydra-node posts
after it checks that decommit transaction applies and the one that actually
makes some UTxO available on L1.

:::

Hydra node accepts this transaction and checks if it can be cleanly applied to
the local `UTxO` set. After this check hydra-node will issue a `ReqDec` message
signalling to other parties that we want to produce a new `Snapshot` that
contains the same `UTxO` to decommit. Once a snapshot is signed, hydra-node
posts a _decrement_ transaction that will take specified output and make it
available on L1.


2 changes: 1 addition & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config = {
baseUrl: "/head-protocol/",
// Note: This gives warnings about the haddocks; but actually they are
// present. If you are concerned, please check the links manually!
onBrokenLinks: "warn",
onBrokenLinks: "throw",
onBrokenMarkdownLinks: "warn",
favicon: "img/hydra.png",
organizationName: "Input Output",
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
label: "Specification",
},
"dev/protocol",
"dev/incremental-commits-and-decommits",
{
type: "doc",
id: "dev/commit_to_a_Head",
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Control.Exception (IOException)
import Control.Monad.Class.MonadThrow (Handler (Handler), catches)
import Control.Tracer (Tracer, traceWith)
import GHC.IO.Exception (IOErrorType (ResourceExhausted), IOException (ioe_type))
import Hydra.Chain.CardanoClient (queryProtocolParameters)
import Hydra.Chain.ScriptRegistry (
publishHydraScripts,
)
Expand Down Expand Up @@ -150,15 +149,8 @@ createOutputAtAddress ::
createOutputAtAddress node@RunningNode{networkId, nodeSocket} atAddress datum val = do
(faucetVk, faucetSk) <- keysFor Faucet
utxo <- findFaucetUTxO node 0
pparams <- queryProtocolParameters networkId nodeSocket QueryTip
let collateralTxIns = mempty
let output =
mkTxOutAutoBalance
pparams
atAddress
val
datum
ReferenceScriptNone
let output = TxOut atAddress val datum ReferenceScriptNone
buildTransaction
networkId
nodeSocket
Expand Down Expand Up @@ -205,7 +197,7 @@ retryOnExceptions tracer action =
--
-- The key of the given Actor is used to pay for fees in required transactions,
-- it is expected to have sufficient funds.
publishHydraScriptsAs :: RunningNode -> Actor -> IO TxId
publishHydraScriptsAs :: RunningNode -> Actor -> IO [TxId]
publishHydraScriptsAs RunningNode{networkId, nodeSocket} actor = do
(_, sk) <- keysFor actor
publishHydraScripts networkId nodeSocket sk
11 changes: 9 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Options.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{-# LANGUAGE OverloadedStrings #-}

module Hydra.Cluster.Options where

import Data.ByteString.Char8 qualified as BSC
import Data.List qualified as List
import Hydra.Cardano.Api (AsType (AsTxId), TxId, deserialiseFromRawBytesHex)
import Hydra.Cluster.Fixture (KnownNetwork (..))
import Hydra.Prelude
Expand All @@ -17,7 +20,7 @@ data Options = Options
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

data PublishOrReuse = Publish | Reuse TxId
data PublishOrReuse = Publish | Reuse [TxId]
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

Expand Down Expand Up @@ -73,13 +76,17 @@ parseOptions =
<> help "Publish hydra scripts before running the scenario."
)
<|> option
(eitherReader $ bimap show Reuse . deserialiseFromRawBytesHex AsTxId . BSC.pack)
(eitherReader $ bimap show Reuse . parseTxIds)
( long "hydra-scripts-tx-id"
<> metavar "TXID"
<> help
"Use the hydra scripts already published in given transaction id. \
\See --publish-hydra-scripts or hydra-node publish-scripts"
)
where
parseTxIds str =
let parsed = fmap (deserialiseFromRawBytesHex AsTxId . BSC.pack) (List.lines str)
in if null (lefts parsed) then Right (rights parsed) else Left ("Invalid TxId" :: String)

parseUseMithril =
flag
Expand Down
Loading
Loading