Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] #2073: Prefer ConstString over String #2505

Conversation

ales-tsurko
Copy link
Contributor

@ales-tsurko ales-tsurko commented Jul 18, 2022

Description of the Change

Replaces String with ConstString for types stored in the blockchain. It also encapsulates iroha_data_primitives into a shared crate.

Issue

Closes #2073

Benefits

Possible Drawbacks

Usage Examples or Tests [optional]

Alternate Designs [optional]

@github-actions github-actions bot added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Jul 18, 2022
@ales-tsurko ales-tsurko added Refactor Improvement to overall code quality Optimization Something isn't working as well as it should labels Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #2505 (892eb81) into iroha2-dev (4f81009) will decrease coverage by 0.32%.
The diff coverage is 54.95%.

@@              Coverage Diff               @@
##           iroha2-dev    #2505      +/-   ##
==============================================
- Coverage       67.61%   67.28%   -0.33%     
==============================================
  Files             140      140              
  Lines           26173    26428     +255     
==============================================
+ Hits            17696    17783      +87     
- Misses           8477     8645     +168     
Impacted Files Coverage Δ
actor/src/broker.rs 88.05% <ø> (ø)
cli/src/main.rs 1.35% <0.00%> (ø)
cli/src/torii/mod.rs 28.88% <ø> (ø)
client_cli/src/main.rs 0.26% <0.00%> (ø)
core/src/kura.rs 90.02% <ø> (ø)
core/src/lib.rs 100.00% <ø> (ø)
core/src/smartcontracts/isi/asset.rs 54.82% <ø> (ø)
core/src/smartcontracts/isi/mod.rs 56.77% <ø> (+3.90%) ⬆️
core/src/smartcontracts/isi/triggers.rs 0.00% <0.00%> (ø)
data_model/src/events/execute_trigger.rs 7.40% <ø> (ø)
... and 93 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@mversic
Copy link
Contributor

mversic commented Jul 19, 2022

we don't need ConstString in tests. We also don't need it when returning errors. It mostly makes sense to use it for things that are stored in memory and never modified. An example of this is PublicKey::digest in iroha_crypto or IpfsPath in data_model

@ales-tsurko
Copy link
Contributor Author

we don't need ConstString in tests. We also don't need it when returning errors. It mostly makes sense to use it for things that are stored in memory and never modified. An example of this is PublicKey::digest in iroha_crypto or IpfsPath in data_model

OK, I'll remove it in tests and errors where possible, but somewhere it's updated because of dependencies.

It mostly makes sense to use it for things that are stored in memory and never modified.

This part of the task is not very clear to me. For example, we initialize an error with string, this string is stored in memory and it's never modified afterwards. Actually, there's a very rare case when we need to modify String, so these requirements can be applied to a lot of types, including errors and those from the tests.

@ales-tsurko ales-tsurko force-pushed the feature/2073-use-conststring branch 4 times, most recently from b9b3c8c to 26c8971 Compare July 19, 2022 14:22
@mversic
Copy link
Contributor

mversic commented Jul 19, 2022

This part of the task is not very clear to me. For example, we initialize an error with string, this string is stored in memory and it's never modified afterwards. Actually, there's a very rare case when we need to modify String, so these requirements can be applied to a lot of types, including errors and those from the tests.

what you say is true but the benefit is marginal. We need ConstString only for types that are stored on the blockchain

@ales-tsurko
Copy link
Contributor Author

We need ConstString only for types that are stored on the block

I got it. Thanks!

@ales-tsurko ales-tsurko force-pushed the feature/2073-use-conststring branch 4 times, most recently from 708e548 to 131ffce Compare July 19, 2022 19:57
@ales-tsurko ales-tsurko marked this pull request as ready for review July 19, 2022 20:50
@ales-tsurko ales-tsurko enabled auto-merge (squash) July 19, 2022 20:51
@Erigara Erigara self-assigned this Jul 20, 2022
mversic
mversic previously approved these changes Jul 20, 2022
Copy link
Contributor

@mversic mversic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good
I see you dropped implementation on Peer::address. I support this revert.

Cargo.toml Outdated
"data_model",
"data_model/primitives",
"data_primitives",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider naming it primitives. Let's see what the other reviewer would have to say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename it into primitives as well. Just kept existing name. Should I rename it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert PeerId::address, ok

Copy link
Contributor

@mversic mversic Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert PeerId::address, ok

I don't think there is anything to change now. All is good

Copy link
Contributor Author

@ales-tsurko ales-tsurko Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming data_primitives into primitives?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming data_primitives into primitives?

Now I see data_model/primitives was already a separate crate. I think you could have referenced it directly from iroha_crypto without moving it outside of data_model?

Copy link
Contributor Author

@ales-tsurko ales-tsurko Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, anyway it had a strange design. It was re-exported from data_model, but still used somewhere directly. I don't recall why I didn't (or couldn't) use it directly, but then I already knew that it's a separate crate. Anyway, it's better to make it shared only or private only to omit confusions and inconsistency.

UPD

I've just checked it on iroha2-dev branch and actually yes, I could use it directly. Well, maybe because it was a deep night or something alike, I don't know how I skipped it 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then just rename to primitives and all is good

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also don't mind renaming it to just primitives

@mversic mversic self-assigned this Jul 20, 2022
data_model/tests/ui_fail/fix_num_private.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated
"data_model",
"data_model/primitives",
"data_primitives",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also don't mind renaming it to just primitives

mversic
mversic previously approved these changes Jul 20, 2022
mversic
mversic previously approved these changes Jul 20, 2022
Erigara
Erigara previously approved these changes Jul 21, 2022
@ales-tsurko ales-tsurko dismissed stale reviews from Erigara and mversic via 546de44 July 21, 2022 12:31
@mversic mversic requested review from mversic and Erigara July 21, 2022 15:03
…data_model

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
…nto shared crate

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
…rimitives

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
@ales-tsurko ales-tsurko enabled auto-merge (squash) July 22, 2022 09:37
@ales-tsurko ales-tsurko merged commit 9c5c531 into hyperledger-iroha:iroha2-dev Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST Optimization Something isn't working as well as it should Refactor Improvement to overall code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants