Skip to content

Commit ec8953a

Browse files
committed
Merge branch 'master' into ao-fix-issue-64
* master: Fix storage expansion in pallet section (#6023) /cmd: Improved devx of benching many pallets simultaneously (#6007)
2 parents 2b29d09 + d1c115b commit ec8953a

File tree

12 files changed

+197
-65
lines changed

12 files changed

+197
-65
lines changed

.github/scripts/cmd/cmd.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,30 @@
1515
runtimeNames = list(map(lambda x: x['name'], runtimesMatrix))
1616

1717
common_args = {
18-
'--continue-on-fail': {"action": "store_true", "help": "Won't exit(1) on failed command and continue with next steps. "},
1918
'--quiet': {"action": "store_true", "help": "Won't print start/end/failed messages in PR"},
2019
'--clean': {"action": "store_true", "help": "Clean up the previous bot's & author's comments in PR"},
2120
'--image': {"help": "Override docker image '--image docker.io/paritytech/ci-unified:latest'"},
2221
}
2322

23+
def print_and_log(message, output_file='/tmp/cmd/command_output.log'):
24+
print(message)
25+
with open(output_file, 'a') as f:
26+
f.write(message + '\n')
27+
28+
def setup_logging():
29+
if not os.path.exists('/tmp/cmd'):
30+
os.makedirs('/tmp/cmd')
31+
open('/tmp/cmd/command_output.log', 'w')
32+
2433
parser = argparse.ArgumentParser(prog="/cmd ", description='A command runner for polkadot-sdk repo', add_help=False)
2534
parser.add_argument('--help', action=_HelpAction, help='help for help if you need some help') # help for help
2635
for arg, config in common_args.items():
2736
parser.add_argument(arg, **config)
2837

2938
subparsers = parser.add_subparsers(help='a command to run', dest='command')
3039

40+
setup_logging()
41+
3142
"""
3243
BENCH
3344
"""
@@ -39,8 +50,8 @@
3950
Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
4051
%(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
4152
42-
Runs bench for all pallets for westend runtime and continues even if some benchmarks fail
43-
%(prog)s --runtime westend --continue-on-fail
53+
Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
54+
%(prog)s --runtime westend --fail-fast
4455
4556
Does not output anything and cleans up the previous bot's & author command triggering comments in PR
4657
%(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
@@ -53,6 +64,7 @@
5364

5465
parser_bench.add_argument('--runtime', help='Runtime(s) space separated', choices=runtimeNames, nargs='*', default=runtimeNames)
5566
parser_bench.add_argument('--pallet', help='Pallet(s) space separated', nargs='*', default=[])
67+
parser_bench.add_argument('--fail-fast', help='Fail fast on first failed benchmark', action='store_true')
5668

5769
"""
5870
FMT
@@ -156,7 +168,9 @@ def main():
156168
manifest_path = os.popen(search_manifest_path).read()
157169
if not manifest_path:
158170
print(f'-- pallet {pallet} not found in dev runtime')
159-
exit(1)
171+
if args.fail_fast:
172+
print_and_log(f'Error: {pallet} not found in dev runtime')
173+
sys.exit(1)
160174
package_dir = os.path.dirname(manifest_path)
161175
print(f'-- package_dir: {package_dir}')
162176
print(f'-- manifest_path: {manifest_path}')
@@ -186,8 +200,9 @@ def main():
186200
f"{config['bench_flags']}"
187201
print(f'-- Running: {cmd} \n')
188202
status = os.system(cmd)
189-
if status != 0 and not args.continue_on_fail:
190-
print(f'Failed to benchmark {pallet} in {runtime}')
203+
204+
if status != 0 and args.fail_fast:
205+
print_and_log(f'❌ Failed to benchmark {pallet} in {runtime}')
191206
sys.exit(1)
192207

193208
# Otherwise collect failed benchmarks and print them at the end
@@ -198,39 +213,39 @@ def main():
198213
successful_benchmarks[f'{runtime}'] = successful_benchmarks.get(f'{runtime}', []) + [pallet]
199214

200215
if failed_benchmarks:
201-
print('❌ Failed benchmarks of runtimes/pallets:')
216+
print_and_log('❌ Failed benchmarks of runtimes/pallets:')
202217
for runtime, pallets in failed_benchmarks.items():
203-
print(f'-- {runtime}: {pallets}')
218+
print_and_log(f'-- {runtime}: {pallets}')
204219

205220
if successful_benchmarks:
206-
print('✅ Successful benchmarks of runtimes/pallets:')
221+
print_and_log('✅ Successful benchmarks of runtimes/pallets:')
207222
for runtime, pallets in successful_benchmarks.items():
208-
print(f'-- {runtime}: {pallets}')
223+
print_and_log(f'-- {runtime}: {pallets}')
209224

210225
elif args.command == 'fmt':
211226
command = f"cargo +nightly fmt"
212227
print(f'Formatting with `{command}`')
213228
nightly_status = os.system(f'{command}')
214229
taplo_status = os.system('taplo format --config .config/taplo.toml')
215230

216-
if (nightly_status != 0 or taplo_status != 0) and not args.continue_on_fail:
217-
print('❌ Failed to format code')
231+
if (nightly_status != 0 or taplo_status != 0):
232+
print_and_log('❌ Failed to format code')
218233
sys.exit(1)
219234

220235
elif args.command == 'update-ui':
221236
command = 'sh ./scripts/update-ui-tests.sh'
222237
print(f'Updating ui with `{command}`')
223238
status = os.system(f'{command}')
224239

225-
if status != 0 and not args.continue_on_fail:
226-
print('❌ Failed to format code')
240+
if status != 0:
241+
print_and_log('❌ Failed to update ui')
227242
sys.exit(1)
228243

229244
elif args.command == 'prdoc':
230245
# Call the main function from ./github/scripts/generate-prdoc.py module
231246
exit_code = generate_prdoc.main(args)
232-
if exit_code != 0 and not args.continue_on_fail:
233-
print('❌ Failed to generate prdoc')
247+
if exit_code != 0:
248+
print_and_log('❌ Failed to generate prdoc')
234249
sys.exit(exit_code)
235250

236251
print('🚀 Done')

.github/scripts/cmd/test_cmd.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_bench_command_normal_execution_all_runtimes(self):
9696
command='bench',
9797
runtime=list(map(lambda x: x['name'], mock_runtimes_matrix)),
9898
pallet=['pallet_balances'],
99-
continue_on_fail=False,
99+
fail_fast=True,
100100
quiet=False,
101101
clean=False,
102102
image=None
@@ -153,7 +153,7 @@ def test_bench_command_normal_execution(self):
153153
command='bench',
154154
runtime=['westend'],
155155
pallet=['pallet_balances', 'pallet_staking'],
156-
continue_on_fail=False,
156+
fail_fast=True,
157157
quiet=False,
158158
clean=False,
159159
image=None
@@ -196,7 +196,7 @@ def test_bench_command_normal_execution_xcm(self):
196196
command='bench',
197197
runtime=['westend'],
198198
pallet=['pallet_xcm_benchmarks::generic'],
199-
continue_on_fail=False,
199+
fail_fast=True,
200200
quiet=False,
201201
clean=False,
202202
image=None
@@ -232,7 +232,7 @@ def test_bench_command_two_runtimes_two_pallets(self):
232232
command='bench',
233233
runtime=['westend', 'rococo'],
234234
pallet=['pallet_balances', 'pallet_staking'],
235-
continue_on_fail=False,
235+
fail_fast=True,
236236
quiet=False,
237237
clean=False,
238238
image=None
@@ -290,7 +290,7 @@ def test_bench_command_one_dev_runtime(self):
290290
command='bench',
291291
runtime=['dev'],
292292
pallet=['pallet_balances'],
293-
continue_on_fail=False,
293+
fail_fast=True,
294294
quiet=False,
295295
clean=False,
296296
image=None
@@ -327,7 +327,7 @@ def test_bench_command_one_cumulus_runtime(self):
327327
command='bench',
328328
runtime=['asset-hub-westend'],
329329
pallet=['pallet_assets'],
330-
continue_on_fail=False,
330+
fail_fast=True,
331331
quiet=False,
332332
clean=False,
333333
image=None
@@ -362,7 +362,7 @@ def test_bench_command_one_cumulus_runtime_xcm(self):
362362
command='bench',
363363
runtime=['asset-hub-westend'],
364364
pallet=['pallet_xcm_benchmarks::generic', 'pallet_assets'],
365-
continue_on_fail=False,
365+
fail_fast=True,
366366
quiet=False,
367367
clean=False,
368368
image=None
@@ -400,7 +400,7 @@ def test_bench_command_one_cumulus_runtime_xcm(self):
400400

401401
self.mock_system.assert_has_calls(expected_calls, any_order=True)
402402

403-
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='fmt', continue_on_fail=False), []))
403+
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='fmt'), []))
404404
@patch('os.system', return_value=0)
405405
def test_fmt_command(self, mock_system, mock_parse_args):
406406
with patch('sys.exit') as mock_exit:
@@ -410,7 +410,7 @@ def test_fmt_command(self, mock_system, mock_parse_args):
410410
mock_system.assert_any_call('cargo +nightly fmt')
411411
mock_system.assert_any_call('taplo format --config .config/taplo.toml')
412412

413-
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='update-ui', continue_on_fail=False), []))
413+
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='update-ui'), []))
414414
@patch('os.system', return_value=0)
415415
def test_update_ui_command(self, mock_system, mock_parse_args):
416416
with patch('sys.exit') as mock_exit:
@@ -419,7 +419,7 @@ def test_update_ui_command(self, mock_system, mock_parse_args):
419419
mock_exit.assert_not_called()
420420
mock_system.assert_called_with('sh ./scripts/update-ui-tests.sh')
421421

422-
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='prdoc', continue_on_fail=False), []))
422+
@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='prdoc'), []))
423423
@patch('os.system', return_value=0)
424424
def test_prdoc_command(self, mock_system, mock_parse_args):
425425
with patch('sys.exit') as mock_exit:

.github/workflows/cmd.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ jobs:
369369
git status
370370
git diff
371371
372+
if [ -f /tmp/cmd/command_output.log ]; then
373+
CMD_OUTPUT=$(cat /tmp/cmd/command_output.log)
374+
# export to summary to display in the PR
375+
echo "$CMD_OUTPUT" >> $GITHUB_STEP_SUMMARY
376+
# should be multiline, otherwise it captures the first line only
377+
echo 'cmd_output<<EOF' >> $GITHUB_OUTPUT
378+
echo "$CMD_OUTPUT" >> $GITHUB_OUTPUT
379+
echo 'EOF' >> $GITHUB_OUTPUT
380+
fi
381+
382+
- name: Upload command output
383+
if: ${{ always() }}
384+
uses: actions/upload-artifact@v4
385+
with:
386+
name: command-output
387+
path: /tmp/cmd/command_output.log
388+
372389
- name: Commit changes
373390
run: |
374391
if [ -n "$(git status --porcelain)" ]; then
@@ -414,35 +431,50 @@ jobs:
414431
uses: actions/github-script@v7
415432
env:
416433
SUBWEIGHT: "${{ steps.subweight.outputs.result }}"
434+
CMD_OUTPUT: "${{ steps.cmd.outputs.cmd_output }}"
417435
with:
418436
github-token: ${{ secrets.GITHUB_TOKEN }}
419437
script: |
420438
let runUrl = ${{ steps.build-link.outputs.run_url }}
421439
let subweight = process.env.SUBWEIGHT;
440+
let cmdOutput = process.env.CMD_OUTPUT;
441+
console.log(cmdOutput);
422442
423-
let subweightCollapsed = subweight
443+
let subweightCollapsed = subweight.trim() !== ''
424444
? `<details>\n\n<summary>Subweight results:</summary>\n\n${subweight}\n\n</details>`
425445
: '';
426446
447+
let cmdOutputCollapsed = cmdOutput.trim() !== ''
448+
? `<details>\n\n<summary>Command output:</summary>\n\n${cmdOutput}\n\n</details>`
449+
: '';
450+
427451
github.rest.issues.createComment({
428452
issue_number: context.issue.number,
429453
owner: context.repo.owner,
430454
repo: context.repo.repo,
431-
body: `Command "${{ steps.get-pr-comment.outputs.group2 }}" has finished ✅ [See logs here](${runUrl})${subweightCollapsed}`
455+
body: `Command "${{ steps.get-pr-comment.outputs.group2 }}" has finished ✅ [See logs here](${runUrl})${subweightCollapsed}${cmdOutputCollapsed}`
432456
})
433457
434458
- name: Comment PR (Failure)
435459
if: ${{ failure() && !contains(github.event.comment.body, '--quiet') }}
436460
uses: actions/github-script@v7
461+
env:
462+
CMD_OUTPUT: "${{ steps.cmd.outputs.cmd_output }}"
437463
with:
438464
github-token: ${{ secrets.GITHUB_TOKEN }}
439465
script: |
440466
let jobUrl = ${{ steps.build-link.outputs.job_url }}
467+
let cmdOutput = process.env.CMD_OUTPUT;
468+
469+
let cmdOutputCollapsed = cmdOutput.trim() !== ''
470+
? `<details>\n\n<summary>Command output:</summary>\n\n${cmdOutput}\n\n</details>`
471+
: '';
472+
441473
github.rest.issues.createComment({
442474
issue_number: context.issue.number,
443475
owner: context.repo.owner,
444476
repo: context.repo.repo,
445-
body: `Command "${{ steps.get-pr-comment.outputs.group2 }}" has failed ❌! [See logs here](${jobUrl})`
477+
body: `Command "${{ steps.get-pr-comment.outputs.group2 }}" has failed ❌! [See logs here](${jobUrl})${cmdOutputCollapsed}`
446478
})
447479
448480
- name: Add 😕 reaction on failure

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div align="center">
32

43
![SDK Logo](./docs/images/Polkadot_Logo_Horizontal_Pink_White.png#gh-dark-mode-only)

docs/contributor/commands-readme.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ By default, the Start and End/Failure of the command will be commented with the
2424
If you want to avoid, use this flag. Go to
2525
[Action Tab](https://github.com/paritytech/polkadot-sdk/actions/workflows/cmd.yml) to see the pipeline status.
2626

27-
2.`--continue-on-fail` to continue running the command even if something inside a command
28-
(like specific pallet weight generation) are failed.
29-
Basically avoids interruption in the middle with `exit 1`
30-
The pipeline logs will include what is failed (like which runtimes/pallets), then you can re-run them separately or not.
31-
3227
3.`--clean` to clean up all yours and bot's comments in PR relevant to `/cmd` commands. If you run too many commands,
3328
or they keep failing, and you're rerunning them again, it's handy to add this flag to keep a PR clean.
3429

docs/contributor/weight-generation.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,53 @@ In a PR run the actions through comment:
1919

2020
To regenerate all weights (however it will take long,
2121
so don't do it unless you really need it), run the following command:
22+
2223
```sh
2324
/cmd bench
2425
```
2526

2627
To generate weights for all pallets in a particular runtime(s), run the following command:
28+
2729
```sh
2830
/cmd bench --runtime kusama polkadot
2931
```
3032

3133
For Substrate pallets (supports sub-modules too):
34+
3235
```sh
3336
/cmd bench --runtime dev --pallet pallet_asset_conversion_ops
3437
```
3538

3639
> **📝 Note**: The action is not being run right-away, it will be queued and run in the next available runner.
37-
So might be quick, but might also take up to 10 mins (That's in control of Github).
38-
Once the action is run, you'll see reaction 👀 on original comment, and if you didn't pass `--quiet` -
39-
it will also send a link to a pipeline when started, and link to whole workflow when finished.
40+
> So might be quick, but might also take up to 10 mins (That's in control of Github).
41+
> Once the action is run, you'll see reaction 👀 on original comment, and if you didn't pass `--quiet` -
42+
> it will also send a link to a pipeline when started, and link to whole workflow when finished.
43+
>
44+
> **📝 Note**: It will try keep benchmarking even if some pallets failed, with the result of failed/successful pallets.
45+
>
46+
> If you want to fail fast on first failed benchmark, add `--fail-fast` flag to the command.
4047
4148
---
4249

43-
> **💡Hint #1** : if you run all runtimes or all pallets, it might be that some pallet in the middle is failed
44-
to generate weights, thus it stops (fails) the whole pipeline.
45-
> If you want, you can make it to continue running, even if some pallets are failed, add `--continue-on-fail`
46-
flag to the command. The report will include which runtimes/pallets have failed, then you can re-run
47-
them separately after all is done.
48-
4950
This way it runs all possible runtimes for the specified pallets, if it finds them in the runtime
51+
5052
```sh
5153
/cmd bench --pallet pallet_balances pallet_xcm_benchmarks::generic pallet_xcm_benchmarks::fungible
5254
```
5355

5456
If you want to run all specific pallet(s) for specific runtime(s), you can do it like this:
57+
5558
```sh
5659
/cmd bench --runtime bridge-hub-polkadot --pallet pallet_xcm_benchmarks::generic pallet_xcm_benchmarks::fungible
5760
```
5861

59-
60-
> **💡Hint #2** : Sometimes when you run too many commands, or they keep failing and you're rerunning them again,
61-
it's handy to add `--clean` flag to the command. This will clean up all yours and bot's comments in PR relevant to
62-
/cmd commands.
62+
> **💡Hint #1** : Sometimes when you run too many commands, or they keep failing and you're rerunning them again,
63+
> it's handy to add `--clean` flag to the command. This will clean up all yours and bot's comments in PR relevant to
64+
> /cmd commands.
6365
6466
```sh
65-
/cmd bench --runtime kusama polkadot --pallet=pallet_balances --clean --continue-on-fail
67+
/cmd bench --runtime kusama polkadot --pallet=pallet_balances --clean
6668
```
6769

68-
> **💡Hint #3** : If you have questions or need help, feel free to tag @paritytech/opstooling (in github comments)
69-
or ping in [matrix](https://matrix.to/#/#command-bot:parity.io) channel.
70+
> **💡Hint #2** : If you have questions or need help, feel free to tag @paritytech/opstooling (in github comments)
71+
> or ping in [matrix](https://matrix.to/#/#command-bot:parity.io) channel.

prdoc/pr_6023.prdoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: Fix storage in pallet section
2+
3+
doc:
4+
- audience: Runtime Dev
5+
description: |
6+
Fix compilation of `pallet::storage` in a pallet section: a local binding definition was not
7+
correctly referenced due to macro hygiene.
8+
9+
crates:
10+
- name: frame-support-procedural
11+
bump: patch

substrate/bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,7 @@ mod benches {
26432643
[pallet_contracts, Contracts]
26442644
[pallet_revive, Revive]
26452645
[pallet_core_fellowship, CoreFellowship]
2646-
[tasks_example, TasksExample]
2646+
[pallet_example_tasks, TasksExample]
26472647
[pallet_democracy, Democracy]
26482648
[pallet_asset_conversion, AssetConversion]
26492649
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]

0 commit comments

Comments
 (0)