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

Post tx-cost benchmark results verbatim into PR #340

Merged
merged 13 commits into from
May 5, 2022
Merged
45 changes: 45 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,51 @@ jobs:
name: benchmarks-and-haddocks
path: ./docs

publish-benchmark-results:
name: Publish benchmark results
# TODO: this is actually only requires the tx-cost benchmark results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: remove is

needs: [haddock-benchmarks]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.1
with:
repository: input-output-hk/hydra-poc
token: ${{ secrets.MY_TOKEN || github.token }}

- uses: actions/download-artifact@v3
with:
name: benchmarks-and-haddocks
path: artifact

- run: find artifact

- name: Prepare comment body
id: comment-body
run: |
# Drop first 5 header lines and demote headlines one level
body="$(cat artifact/benchmarks/transaction-cost.md | sed '1,5d;s/^#/##/')"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$body"

- name: Find Comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Transactions Costs

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.comment-body.outputs.body }}
reactions: rocket

documentation:
name: Documentation
needs: [haddock-benchmarks]
Expand Down
110 changes: 24 additions & 86 deletions hydra-node/exe/tx-cost/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import TxCost (
computeCollectComCost,
computeCommitCost,
computeFanOutCost,
computeHashingCost,
computeInitCost,
computeMerkleTreeCost,
maxCpu,
maxMem,
)
Expand Down Expand Up @@ -81,9 +79,7 @@ writeTransactionCostMarkdown hdl = do
collectComC <- costOfCollectCom
closeC <- costOfClose
abortC <- costOfAbort
fanout <- costOfFanOut
mt <- costOfMerkleTree
let h = costOfHashing
fanoutC <- costOfFanOut
hPut hdl $
encodeUtf8 $
unlines $
Expand All @@ -95,11 +91,11 @@ writeTransactionCostMarkdown hdl = do
, collectComC
, closeC
, abortC
, fanout
, mt
, h
, fanoutC
]

-- NOTE: Github Actions CI depends on the number of header lines, see
-- .github/workflows/ci.yaml
pageHeader :: [Text]
pageHeader =
[ "--- "
Expand All @@ -109,8 +105,10 @@ pageHeader =
, ""
, "# Transactions Costs "
, ""
, "| | |"
, "| --- | ---- |"
, "Sizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using `arbitrary` values and results are not fully deterministic and comparable to previous runs."
, ""
, "| Metadata | |"
, "| :--- | :--- |"
, "| _Generated at_ | " <> show now <> " |"
, "| _Max. memory units_ | " <> show maxMem <> " |"
, "| _Max. CPU units_ | " <> show maxCpu <> " |"
Expand All @@ -129,8 +127,8 @@ costOfInit = markdownInitCost <$> computeInitCost
unlines $
[ "## Cost of Init Transaction"
, ""
, "| # Parties | Tx. size |"
, "| :-------- | -------: |"
, "| Parties | Tx size |"
, "| :------ | ------: |"
]
<> fmap
( \(numParties, txSize) ->
Expand All @@ -147,15 +145,14 @@ costOfCommit = markdownCommitCost <$> computeCommitCost
markdownCommitCost stats =
unlines $
[ "## Cost of Commit Transaction"
, " Uses ada-only UTxO for better comparability."
, ""
, "| # UTxO Committed | Assets size | Tx. size | % max Mem | % max CPU |"
, "| :--------------- | ----------: | -------: | --------: | ----------: |"
, "| UTxO | Tx size | % max Mem | % max CPU |"
, "| :--- | ------: | --------: | --------: |"
]
<> map
( \(ulen, valueSz, txSize, mem, cpu) ->
( \(ulen, txSize, mem, cpu) ->
"| " <> show ulen
<> "| "
<> show valueSz
<> "| "
<> show txSize
<> " | "
Expand All @@ -173,8 +170,8 @@ costOfCollectCom = markdownCollectComCost <$> computeCollectComCost
unlines $
[ "## Cost of CollectCom Transaction"
, ""
, "| # Parties | Tx. size | % max Mem | % max CPU |"
, "| :-------- | -------: | --------: | ----------: |"
, "| Parties | Tx size | % max Mem | % max CPU |"
, "| :------ | ------: | --------: | --------: |"
]
<> fmap
( \(numParties, txSize, mem, cpu) ->
Expand All @@ -196,8 +193,8 @@ costOfClose = markdownClose <$> computeCloseCost
unlines $
[ "## Cost of Close Transaction"
, ""
, "| # Parties | Tx. size | % max Mem | % max CPU |"
, "| :-------- | -------: | --------: | ----------: |"
, "| Parties | Tx size | % max Mem | % max CPU |"
, "| :------ | ------: | --------: | --------: |"
]
<> fmap
( \(numParties, txSize, mem, cpu) ->
Expand All @@ -219,8 +216,8 @@ costOfAbort = markdownAbortCost <$> computeAbortCost
unlines $
[ "## Cost of Abort Transaction"
, ""
, "| # Parties | Tx. size | % max Mem | % max CPU |"
, "| :-------- | -------: | --------: | ----------: |"
, "| Parties | Tx size | % max Mem | % max CPU |"
, "| :------ | ------: | --------: | --------: |"
]
<> fmap
( \(numParties, txSize, mem, cpu) ->
Expand All @@ -240,10 +237,11 @@ costOfFanOut = markdownFanOutCost <$> computeFanOutCost
where
markdownFanOutCost stats =
unlines $
[ "## Cost of FanOut Transaction (spend Head + burn HeadTokens)"
[ "## Cost of FanOut Transaction"
, " Involves spending head output and burning head tokens. Uses ada-only UTxO for better comparability."
, ""
, "| UTXO | Tx. size | % max Mem | % max CPU |"
, "| :---- | -------: | --------: | ----------: |"
, "| UTxO | Tx size | % max Mem | % max CPU |"
, "| :---- | ------: | --------: | --------: |"
]
<> fmap
( \(numElems, txSize, mem, cpu) ->
Expand All @@ -257,63 +255,3 @@ costOfFanOut = markdownFanOutCost <$> computeFanOutCost
<> " |"
)
stats

costOfMerkleTree :: IO Text
costOfMerkleTree = markdownMerkleTreeCost <$> computeMerkleTreeCost
where
markdownMerkleTreeCost stats =
unlines $
[ "## Cost of on-chain Merkle-Tree"
, ""
, "| Size | % member max mem | % member max cpu | % builder max mem | % builder max cpu |"
, "| :--- | ---------------: | ---------------: | ----------------: | ----------------: |"
]
<> fmap
( \(numElems, memberMem, memberCpu, builderMem, builderCpu) ->
"| "
<> show numElems
<> " | "
<> show (100 * fromIntegral (fromIntegral memberMem `div` numElems) / maxMem)
<> " | "
<> show (100 * fromIntegral (fromIntegral memberCpu `div` numElems) / maxCpu)
<> " | "
<> show (100 * fromIntegral builderMem / maxMem)
<> " | "
<> show (100 * fromIntegral builderCpu / maxCpu)
<> " |"
)
stats

costOfHashing :: Text
costOfHashing = markdownHashingCost computeHashingCost
where
markdownHashingCost stats =
unlines $
[ "## Cost of on-chain Hashing"
, ""
]
<> concatMap
( \(n, s, costs) ->
[ "### n = " <> show n <> ", s = " <> show s
, ""
, "| Algorithm | Cpu | Mem | Δcpu | Δmem |"
, "| :-------- | ---: | ---: | ---: | ---: |"
]
<> fmap
( \case
Right (algorithm, baseCpu, baseMem, cpu, mem) ->
"| " <> show algorithm
<> " | "
<> show baseCpu
<> " | "
<> show baseMem
<> " | "
<> show (toInteger cpu - toInteger baseCpu)
<> " | "
<> show (toInteger mem - toInteger baseMem)
<> " |"
Left _ -> "| - | - |"
)
costs
)
stats
Loading