-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
is it doable to have a test somehow ? |
@thiolliere thanks for your suggestion. I wanted to do just that and discussed it with @shawntabrizi. I believe he was of the opinion that writing a test for it wasn't strictly necessary to consider the issues solved. However, I'm open for suggestions on how to do that. Maybe there should be a new issue like "test benchmark reporting"? I'd be of course happy to take it up if I also know whom to ask. It was a bit hard to reach anyone for detailed questions and I also didn't get a reply when posting to the substrate technical chat... |
then I think it is fine without tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like returning a Vec<u8>
while it will be interpreted a String
in the client is a bit confusing.
But I'm ok anyway, code looks good otherwise
frame/benchmarking/src/lib.rs
Outdated
@@ -1050,7 +1057,18 @@ macro_rules! add_benchmark { | |||
*repeat, | |||
whitelist, | |||
*verify, | |||
)?, | |||
).map_err(|e| { | |||
$crate::join_u8_sequences( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use format!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think format!
is not available in a no_std
environment. Is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ;) sp_std::alloc::format!
, but 🤫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thanks. that would make things a lot easier.
so if I replace the join_u8_sequences(...)
call with something like sp_std::alloc::format!("blabla {}", 1u32).as_bytes().to_vec()
, recompiling fails with
Compiling node-template-runtime v2.0.0 (/Users/simon/dev/substrate/bin/node-template/runtime)
error[E0433]: failed to resolve: could not find `format` in `alloc`
--> bin/node-template/runtime/src/lib.rs:471:4
|
471 | add_benchmark!(params, batches, pallet_timestamp, Timestamp);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `format` in `alloc`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: could not find `format` in `alloc`
--> bin/node-template/runtime/src/lib.rs:470:4
|
470 | add_benchmark!(params, batches, pallet_balances, Balances);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `format` in `alloc`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: could not find `format` in `alloc`
--> bin/node-template/runtime/src/lib.rs:469:4
|
469 | add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `format` in `alloc`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
what am I doing wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean I see that without_std.rs
does public extern crate alloc;
and that format!
is in there. but I can't seem to get it to work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is hard so say why without the code, did you use sp_std::alloc or just alloc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh that error is probably from the native build? For native we don't export the alloc crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. so format!
is not available then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On native format!
is provided by the rustc prelude, meaning it is "just" available.
So you need to use some cfgs around this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah, thanks @bkchr and @thiolliere for enlightening me. I wasn't aware of the fact that it was compiled once with and once without std
features. Now it makes a lot more sense to me.
@thiolliere @bkchr I have now refactored the solution quite a bit to use |
* Error message: {}", | ||
sp_std::str::from_utf8(instance_string) | ||
.expect("it's all just strings ran through the wasm interface. qed"), | ||
sp_std::str::from_utf8(benchmark) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor note: the runtime doesn't check that this is a string, but the cli does, so it's fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thank you @ropottnik for the PR and @thiolliere and @bkchr for taking over mentorship :)
these test failures don't look related to what I did. should I rebase to let the CI/CD run again? |
@ropottnik can you merge substrate master in your branch ? I think the CI fails because of it |
bot merge |
Trying merge. |
fixes #7386
This PR adds pallet and benchmark to benchmark error output.
The PR also changes the wrapped type in the error variant of
fn dispatch_benchmark
fromsp_std::RuntimeString
toVec<u8>
and creates a dedicated functionjoin_u8_sequences
to achieve concatenation of character vectors.I couldn't find an equivalent of
format!
in anon_std
environment (would appreciate if anyone could point my nose to it if it is available). That's why I implemented the clumsy concatenation function.My struggles with using
RuntimeStrings
led to me changing the function signatures to returnVec<u8>
. I posted a question here in the substrate technical chat but to my knowledge got no reply. Again, I appreciate any suggestion on how to work withRuntimeStrings
and therefore leave the signatures as they are.Any feedback is welcome!