Skip to content

Commit

Permalink
Deterministic tx cost computation in CI (#1712)
Browse files Browse the repository at this point in the history
Follow up to #1711 .

~A draft as it will only work once that one is merged.~
  • Loading branch information
noonio authored Oct 16, 2024
2 parents a0635c6 + 6e803d7 commit d55c4ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci-nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ jobs:

- name: "Compute costs on both old and new"
run: |
nix run ./new/#tx-cost >new.md
nix run ./old/#tx-cost >old.md
SEED=$RANDOM
echo "Using random seed $SEED"
nix run ./new/#tx-cost -- --seed $SEED >new.md
nix run ./old/#tx-cost -- --seed $SEED >old.md
- name: "Compute the difference markdown"
run: |
Expand Down
50 changes: 30 additions & 20 deletions .github/workflows/cost-differences/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parties(df):
def utxo(df):
return df.set_index("UTxO")

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

Expand All @@ -34,6 +34,9 @@ def compare_to_md(f, old, new):
# Round everything to 2 decimals
df = df.round(2)

return df

def to_markdown(df):
# Add colour
def update_colour(x):
if x == 0:
Expand All @@ -51,30 +54,37 @@ def update_colour(x):

return df.to_markdown()

print("Transaction cost differences")

# First is the script size
# We ignore the first table, namely the metadata, that's why the base/branch
# index starts at 1.

diffs = [
# First is the script size
(headers[0], compare( script_size, base[1], branch[1]))
# Then Init,
, (headers[1], compare( parties, base[2], branch[2]))
# Then Commit is different; it doesn't have a "Parties" column
, (headers[2], compare( utxo, base[3], branch[3]))
]

print(f"## {headers[0]}")
print("")
print( compare_to_md( script_size, base[1], branch[1]) )
# Then the remaining are all the same.
for i in range(4, 9 + 1):
diffs.append(( headers[i - 1]
, compare( parties, base[i], branch[i] )
))

# Then Init,
print("")
print(f"## {headers[1]}")
print("")
print( compare_to_md(parties, base[2], branch[2]) )
# Check that ther was _some_ difference, at least.
some_change = any( df.to_numpy().sum() != 0 for _, df in diffs )

# Then Commit is different; it doesn't have a "Parties" column
print("# Transaction cost differences")

print("")
print(f"## {headers[2]}")
print("")
print( compare_to_md(utxo, base[3], branch[3]) )
if not (some_change):
print("No cost or size differences found")
exit(0)

# The remaining are all the same as Init.
for i in range(4, 9 + 1):
for (header, df) in diffs:
print("")
print(f"## {headers[i - 1]}")
print(f"## {header}")
print("")
print( compare_to_md(parties, base[i], branch[i]) )
diff = to_markdown(df)
print(diff)

0 comments on commit d55c4ef

Please sign in to comment.