forked from paritytech/smart-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
217 lines (185 loc) · 7.81 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
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: results
jobs:
build_dev_moonbeam:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
container:
image: paritytech/ci-unified:bullseye-1.73.0
steps:
- 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/latest"
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 }}
curl -L ${DOWNLOAD_URL} | tar -xzv -C ${{ env.MOONBEAM_DIR }}
echo $RELEASE_TAG > ${{ env.MOONBEAM_DIR }}/${{ env.MOONBEAM_VERSION }}
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Build
run: |
# Rebuild Moonbeam with Dev RPC support
cd moonbeam_release/*/
git apply ../../launch/moonbeam.patch
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
- 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
env:
TEST_PARAMS: --instance-count 1 --call-count 100
run: |
cd launch
./download-bins.sh
# overwrite parachains
cp ../bin/* ./bin
./build.sh
TPS=$(./run.sh -- ${{ matrix.type }} ${{ matrix.contract }} ${TEST_PARAMS} | grep -o 'TPS: [0-9]*' | awk '{print $2}')
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 }}" > ${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 }}" > ${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 }}" > ${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]
env:
BENCHMARK_FILE: benchmark-results.csv
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3
with:
path: ${{ env.BENCHMARK_DIR }}
- name: Merge CSV
run: |
cat ${{ env.BENCHMARK_DIR }}/*/*.csv >> ${{ env.BENCHMARK_DIR }}/${{ env.BENCHMARK_FILE }}
- name: Generate graph
run: |
cd stats
./get_graph.sh --panel-id=2 --csv-data=../${{ env.BENCHMARK_DIR }}/${{ env.BENCHMARK_FILE }} --output=../${{ env.BENCHMARK_DIR }}/tps.png
- name: Commit benchmark stats
run: |
CURRENT_DATE=$(date +"%Y%m%d")
git config user.email "[email protected]"
git config user.name "paritytech-ci"
git add ${{ env.BENCHMARK_DIR }}/${{ env.BENCHMARK_FILE }} ${{ env.BENCHMARK_DIR }}/tps.png
git commit -m "Add benchmark results on ${CURRENT_DATE}"
git push