forked from paritytech/smart-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
257 lines (223 loc) · 9.55 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: Schedule based benchmark of pallet-contracts and pallet-evm
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
MOONBEAM_ARTIFACT: moonbeam
MOONBEAM_DIR: moonbeam_release
MOONBEAM_BIN: moonbeam_release/*/target/release/moonbeam
MOONBEAM_VERSION: version
BENCHMARK_DIR: stats
TEST_PARAMS: --instance-count 1 --call-count 1000
BENCHMARK_URI: https://raw.githubusercontent.com/smiasojed/smart-bench/gh-pages
jobs:
# build_dev_moonbeam:
# runs-on: ubuntu-20.04
# defaults:
# run:
# shell: bash
# steps:
# - name: Clean worker
# run: |
# sudo rm -rf /usr/share/dotnet
# sudo rm -rf /opt/ghc
# sudo rm -rf "/usr/local/share/boost"
# sudo rm -rf "$AGENT_TOOLSDIRECTORY"
# - uses: actions/checkout@v4
# with:
# sparse-checkout: |
# launch/moonbeam.patch
# sparse-checkout-cone-mode: false
# - name: Download Moonbeam Release
# run: |
# API_URL="https://api.github.com/repos/moonbeam-foundation/moonbeam/releases/131808906"
# RESPONSE=$(curl -s "${API_URL}")
# # Remove control characters causing error while parsing
# RESPONSE=$(echo $RESPONSE | tr -cd '[:print:]')
# DOWNLOAD_URL=$(echo $RESPONSE | jq -r '.tarball_url')
# RELEASE_TAG=$(echo $RESPONSE | jq -r '.tag_name')
# mkdir ${{ env.MOONBEAM_DIR }}
# echo "Download moonbeam release: ${DOWNLOAD_URL}"
# curl -L ${DOWNLOAD_URL} | tar -xzv -C ${{ env.MOONBEAM_DIR }}
# echo $RELEASE_TAG > ${{ env.MOONBEAM_DIR }}/${{ env.MOONBEAM_VERSION }}
# - name: Patch
# run: |
# # Add Dev RPC support
# cd moonbeam_release/*/
# patch -p1 < ../../launch/moonbeam.patch
# - name: Build
# uses: docker://paritytech/ci-unified:bullseye-1.73.0
# with:
# args: /bin/bash -c "cd moonbeam_release/*/ && cargo build --release"
# - uses: actions/upload-artifact@v3
# with:
# name: ${{ env.MOONBEAM_ARTIFACT }}
# path: |
# ./${{ env.MOONBEAM_BIN }}
# ./${{ env.MOONBEAM_DIR }}/${{ env.MOONBEAM_VERSION }}
# retention-days: 1
smart_contract_benchmark:
strategy:
matrix:
type: [ink-wasm, sol-wasm, evm]
contract: [erc20]
env:
BENCHMARK_FILE: benchmark_${{ matrix.type }}_${{ matrix.contract }}.csv
# needs: build_dev_moonbeam
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache
uses: Swatinem/rust-cache@v2
# - uses: actions/download-artifact@v3
# with:
# name: ${{ env.MOONBEAM_ARTIFACT }}
# path: ./${{ env.MOONBEAM_DIR }}
- name: Set Moonbeam Release
id: moonbeam_release
run: |
mkdir bin
# cp ${{ env.MOONBEAM_BIN }} bin/moonbeam
# chmod +x bin/moonbeam
# RELEASE_TAG=$(cat ${{ env.MOONBEAM_DIR }}/${{ env.MOONBEAM_VERSION }})
# echo "tag=$(echo ${RELEASE_TAG})" >> $GITHUB_OUTPUT
echo "tag=mon" >> $GITHUB_OUTPUT
- name: Download Polkadot-Parachain Release
id: polkadot_parachain_release
run: |
API_URL="https://api.github.com/repos/paritytech/cumulus/releases/latest"
RESPONSE=$(curl -s "${API_URL}")
# Get the download URL of the release binary from Repo
DOWNLOAD_URL=$(echo $RESPONSE | jq -r '.assets | map(select(.name == "polkadot-parachain")) | .[0].browser_download_url')
RELEASE_TAG=$(echo $RESPONSE | jq -r '.tag_name')
curl -L -o bin/polkadot-parachain ${DOWNLOAD_URL} && chmod +x bin/polkadot-parachain
echo "tag=$(echo ${RELEASE_TAG})" >> $GITHUB_OUTPUT
- name: Get Ink contract language verision
id: ink_version
uses: ./.github/actions/get-contract-language
with:
contracts-directory: './contracts/ink'
- name: Get Solang contract language verision
id: solang_version
uses: ./.github/actions/get-contract-language
with:
contracts-directory: './contracts/solidity/wasm'
- name: Get Solc contract language verision
id: solc_version
run: |
language=""
# Iterate over each contract in the directory
for contract in ./contracts/solidity/evm/contracts/*/*.dbg.json; do
build_info=$(jq -r '.buildInfo' "$contract")
build_info_path="./contracts/solidity/evm/contracts/${build_info#../}"
solc_version=$(jq -r '.solcVersion' "$build_info_path")
current_language="solc $solc_version"
# Check if the current language is different from the previous one
if [ -n "$language" ] && [ "$current_language" != "$language" ]; then
echo "Error: Different language detected in contract $contract: $language != $current_language"
exit 1
fi
language="$current_language"
echo "Contract: $contract, Language: $current_language"
done
echo "language=$language" >> $GITHUB_OUTPUT
- name: Display variables
run: |
echo moonbeam_tag: ${{ steps.moonbeam_release.outputs.tag }}
echo polkadot_parachain_tag: ${{ steps.polkadot_parachain_release.outputs.tag }}
- name: Execute tests
id: run_smart_bench
run: |
cd launch
./download-bins.sh
# overwrite parachains
cp -f ../bin/* ./bin
./build.sh
STATS=$(./run.sh -- ${{ matrix.type }} ${{ matrix.contract }} ${TEST_PARAMS})
BLOCKS=$(echo ${STATS} | grep -o 'Total Blocks: [0-9]*' | awk '{print $3}')
EXTRINSICS=$(echo ${STATS} | grep -o 'Total Extrinsics: [0-9]*' | awk '{print $3}')
TPS=$(echo ${STATS} | grep -o 'sTPS: [0-9]*' | awk '{print $2}')
echo "Blocks: ${BLOCKS}"
echo "Extrinsics: ${EXTRINSICS}"
echo "TPS: ${TPS}"
echo "tps=$(echo ${TPS})" >> $GITHUB_OUTPUT
- name: Extract Ink benchmark stats
if: matrix.type == 'ink-wasm'
run: |
CURRENT_DATE=$(date +"%s")
# date, parachain tag, contract, contract language, TPS
echo "${CURRENT_DATE}, ${{ matrix.type }}, ${{ steps.polkadot_parachain_release.outputs.tag }}, \
${{ matrix.contract }}, ${{ steps.run_smart_bench.outputs.tps }}, ${{ steps.ink_version.outputs.language }}, \
${{ env.TEST_PARAMS }}" > ${BENCHMARK_DIR}/${BENCHMARK_FILE}
- name: Extract Solang benchmark stats
if: matrix.type == 'sol-wasm'
run: |
CURRENT_DATE=$(date +"%s")
# date, parachain tag, contract, contract language, TPS
echo "${CURRENT_DATE}, ${{ matrix.type }}, ${{ steps.polkadot_parachain_release.outputs.tag }}, \
${{ matrix.contract }}, ${{ steps.run_smart_bench.outputs.tps }}, ${{ steps.solang_version.outputs.language }}, \
${{ env.TEST_PARAMS }}" > ${BENCHMARK_DIR}/${BENCHMARK_FILE}
- name: Extract Solidity benchmark stats
if: matrix.type == 'evm'
run: |
CURRENT_DATE=$(date +"%s")
# date, parachain tag, contract, contract language, TPS
echo "${CURRENT_DATE}, ${{ matrix.type }}, ${{ steps.moonbeam_release.outputs.tag }}, \
${{ matrix.contract }}, ${{ steps.run_smart_bench.outputs.tps }}, ${{ steps.solc_version.outputs.language }}, \
${{ env.TEST_PARAMS }}" > ${BENCHMARK_DIR}/${BENCHMARK_FILE}
- uses: actions/upload-artifact@v3
with:
name: ${{ env.BENCHMARK_FILE }}
path: ${{ env.BENCHMARK_DIR }}/${{ env.BENCHMARK_FILE }}
retention-days: 1
collect:
runs-on: ubuntu-latest
needs: [smart_contract_benchmark]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3
with:
path: ${{ env.BENCHMARK_DIR }}
- name: Merge CSV
run: |
for file in ${{ env.BENCHMARK_DIR }}/*/*.csv; do
# Extract contract name
contract_name=$(basename "$file" | sed 's/^.*_\(.*\)\.csv$/\1/')
benchmark_file=bench_${contract_name}.csv
if [ ! -f ${{ env.BENCHMARK_DIR }}/${benchmark_file} ]; then
curl -L -o ${{ env.BENCHMARK_DIR }}/${benchmark_file} ${{ env.BENCHMARK_URI }}/${benchmark_file}
fi
cat $file >> ${{ env.BENCHMARK_DIR }}/${benchmark_file}
done
find ./stats
- name: Generate graph
run: |
for file in ${{ env.BENCHMARK_DIR }}/bench_*.csv; do
contract_name=$(basename "$file" | sed 's/^.*_\(.*\)\.csv$/\1/')
pushd stats
./get_graph.sh --panel-id=2 --csv-data=../${file} --output=../${{ env.BENCHMARK_DIR }}/${contract_name}_stps.png
popd
done
- name: Commit benchmark stats
run: |
CURRENT_DATE=$(date +"%Y%m%d")
# Set git config
git config user.email "[email protected]"
git config user.name "paritytech-ci"
git fetch origin gh-pages
# saving stats
mkdir /tmp/stats
mv ${{ env.BENCHMARK_DIR }}/*.csv /tmp/stats
mv ${{ env.BENCHMARK_DIR }}/*.png /tmp/stats
git checkout gh-pages
mv /tmp/stats/* .
# Upload files
git add *.csv *.png --force
git status
git commit -m "Updated stats in ${CURRENT_DATE} and pushed to gh-pages"
git push origin gh-pages --force
rm -rf .git/ ./*