Skip to content

Commit

Permalink
Merge branch 'master' into lc/remove-hash-module
Browse files Browse the repository at this point in the history
  • Loading branch information
noonio authored Oct 16, 2024
2 parents 1b038d8 + 2c0707f commit 9d6b76f
Show file tree
Hide file tree
Showing 40 changed files with 17,899 additions and 22,413 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ jobs:
name: hydra-x86_64-linux-${{ env.VERSION }} # automatically zips
path: out/*

- name: ❄ Build devShells (for cache)
run: |
nix build .#devShells.x86_64-linux.default
build-macos:
name: "Build for aarch64-darwin"
runs-on: macos-latest
Expand Down Expand Up @@ -101,7 +97,3 @@ jobs:
with:
name: hydra-aarch64-darwin-${{ env.VERSION }} # automatically zips
path: out/*

- name: ❄ Build devShells (for cache)
run: |
nix build .#devShells.aarch64-darwin.default
79 changes: 79 additions & 0 deletions .github/workflows/ci-nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ jobs:
path: |
./*.pdf
documentation:
name: Documentation
needs: [haddock,benchmarks,build-test,build-specification]
Expand Down Expand Up @@ -359,3 +360,81 @@ jobs:
run: |
yarn
yarn build-dev
# Compute the cost difference between this branch and master.
tx-cost-diff:
name: Compute cost differences
runs-on: ubuntu-latest
# Only run on PR
if: github.event_name == 'pull_request'
steps:
- name: "Checkout the PR as the 'new' source"
uses: actions/checkout@v4
with:
path: ./new
ref: ${{ github.event.pull_request.head.sha }}

- name: "Checkout `master` as the 'old' source"
uses: actions/checkout@v4
with:
path: ./old
ref: master

- name: ❄ Prepare nix
uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
accept-flake-config = true
log-lines = 1000
- name: ❄ Cachix cache of nix derivations
uses: cachix/cachix-action@v15
with:
name: cardano-scaling
authToken: '${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'

- name: Set up and use the "ci" devShell
uses: nicknovitski/nix-develop@v1
with:
arguments: "./new#costDifferences"

- name: "Compute costs on both old and new"
run: |
nix run ./new/#tx-cost >new.md
nix run ./old/#tx-cost >old.md
- name: "Compute the difference markdown"
run: |
# Convert to HTML, as that's the easiest way to read the markdown
# tables via pandas (!!!)
pandoc -i new.md -o new.html
pandoc -i old.md -o old.html
cat new.md | grep '##' >new-headers.txt
cat old.md | grep '##' >old-headers.txt
# Stop if the heading columns aren't the same.
cmp old-headers.txt new-headers.txt
# Run the diff script; note that it's located in the "new" folder.
./new/.github/workflows/cost-differences/diff.py \
old-headers.txt \
old.html \
new.html >diff.md
- name: 🔎 Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Transaction cost differences

- name: ✏ Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
issue-number: ${{ github.event.pull_request.number }}
body-file: diff.md
80 changes: 80 additions & 0 deletions .github/workflows/cost-differences/diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /usr/bin/env python

import pandas as pd
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("header_file", type=str)
parser.add_argument("old_file", type=str)
parser.add_argument("new_file", type=str)
args = parser.parse_args()

with open(args.header_file, "r") as f:
headers = [ l[3:].strip() for l in f.readlines() ]

base = pd.read_html(args.old_file, flavor="html5lib")
branch = pd.read_html(args.new_file, flavor="html5lib")

def script_size(df):
return df.drop(columns=["Hash"]).set_index("Name")

def parties(df):
return df.set_index("Parties")

def utxo(df):
return df.set_index("UTxO")

def compare_to_md(f, old, new):
# New should be better, so we compare to that.
df = f(new) - f(old)

# Don't keep what we couldn't compare.
df = df.dropna()

# Round everything to 2 decimals
df = df.round(2)

# Add colour
def update_colour(x):
if x == 0:
return "-"

if type(x) is object:
return x

if x > 0:
return f"+{x}"
else:
return f"$${{\\color{{green}}{x:.2f}}}$$"

df = df.map(update_colour)

return df.to_markdown()

print("Transaction cost differences")

# First is the script size

print(f"## {headers[0]}")
print("")
print( compare_to_md( script_size, base[1], branch[1]) )

# Then Init,
print("")
print(f"## {headers[1]}")
print("")
print( compare_to_md(parties, base[2], branch[2]) )

# Then Commit is different; it doesn't have a "Parties" column

print("")
print(f"## {headers[2]}")
print("")
print( compare_to_md(utxo, base[3], branch[3]) )

# The remaining are all the same as Init.
for i in range(4, 9 + 1):
print("")
print(f"## {headers[i - 1]}")
print("")
print( compare_to_md(parties, base[i], branch[i]) )
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ changes.
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:
- Add documentation to explain the feature
- Implement tests scenarios outlined in the [incremental-commit] (https://github.com/cardano-scaling/hydra/issues/199) issue
- Revisit types related to observations/posting transactions and make sure the fields are named appropriatelly


- Tested with `cardano-node 9.2.0` and `cardano-cli 9.4.1.0`.

- **BREAKING** Rewrite of the commit script in aiken:
Expand Down
11 changes: 2 additions & 9 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repository cardano-haskell-packages

-- See CONTRIBUTING.md for information about when and how to update these.
index-state:
, hackage.haskell.org 2024-09-25T13:28:12Z
, cardano-haskell-packages 2024-09-23T21:46:49Z
, hackage.haskell.org 2024-10-14T02:12:15Z
, cardano-haskell-packages 2024-10-11T15:49:11Z

packages:
hydra-prelude
Expand Down Expand Up @@ -44,10 +44,3 @@ test-show-details: direct

program-options
ghc-options: -fwrite-ide-info

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api
tag: 00f025d1fda127d0f7b2e69227e298199bea1fe1
--sha256: sha256-GttvKWo+2SytPW59a1JIYSpdlTr+7mcWvvK+EPAgH/k=
subdir: cardano-api
99 changes: 99 additions & 0 deletions docs/docs/dev/commit_to_a_Head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Commit funds to a Head


In order to transact inside of a Head on L2 users need to have some funds
available before staring the Head protocol.

In addition to public key outputs users can also commit script outputs to a
Head in order to accomodate different usecases for dApps and add custom validator logic.

We can distinguish two types of commits:

- **Commit before the Head is open**

- **Commit when the Head is already opened (incremental commits)**

Both types of commits are pretty similar from the user perspective but the latter one
is more useful since it depreciates the old behavior where the users needed to
have available funds before the Head protocol can actually be started.

In order to commit a `UTxO` user owns on L1 they can choose to do what we call
a _simple_ or a _blueprint_ commit.

**_Simple_** here means the user wants to commit a public key output to a Head in
which case they only need to show the JSON representation of the `UTxO` they
own.

The **_blueprint_** option requires providing the _blueprint_ transaction
together with the `UTxO` it spends to be able to have more fine grained control
over the commit process. Note that in this case `hydra-node` ignores any
outputs of a user transaction and is only concerned with the **inputs** it spends.

::::info
For example when committing a script `UTxO` and when more control of some of
the transaction attributes is needed (lower/upper validity bounds, custom
redeemers, reference inputs etc.)
::::

### Commit process

Both commit options mentioned should not be different from the users
perspective and the only difference is _when_ commit is made in the Head
[lifecycle](./../protocol-overview#hydra-head-lifecycle) - before or after the Head is opened.

In any case user needs to have the `hydra-node` running and be able to issue a
request which is already described in more detailed
[simple](./../how-to/incremental-commit) and
[blueprint](./../how-to/commit-blueprint) tutorials.

Upon succesfull request `hydra-node` returns a transaction to the user which
then they need to sign and submit to the L1 network.

`hydra-node` constantly observes interesting L1 transactions and in case the
Head is not yet opened it would wait for all other Head participants to commit
before the Head protocol starts.

When the Head is already opened we are talking about _incremental commit_ and
what happens _under the hood_ is a bit different.

To be able to commit to a running Head `hydra-node` would lock the provided
`UTxO` in the **deposit** script output controlled by the `hydra-node`.

It would also set the deadline by which this locked `UTxO` needs to be picked
up and made available inside of L2 by posting a **increment** transaction. This
also happens automatically but here we want to describe this process and bring
it closer to Hydra users.

It is worthwhile mentioning that deposit deadline is double the value used for
contestation period. This gives the users control by specifying the
contestation period it in the arguments to `hydra-node` executable.

::::info
Deadline information is present in the `CommitRecorded` API server output.
::::


### Recovering the deposited funds

If for some reason `hydra-node` failed to observe the deposit there is a
**recover** process in place so that users can always have a way to unlock
their funds.

If the deadline is reached and the requested commit didn't show up on L2
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).
::::

Any Head participant can request to recover the deposit not only the one which initially deposited the funds.









5 changes: 5 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ module.exports = {
label: "Specification",
},
"dev/protocol",
{
type: "doc",
id: "dev/commit_to_a_Head",
label: "Commit funds to a Head",
},
{
type: "category",
link: { type: "doc", id: "dev/architecture/index" },
Expand Down
Loading

0 comments on commit 9d6b76f

Please sign in to comment.