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

refactor(types): vbyte -> storage score #1398

Closed
wants to merge 12 commits into from

Conversation

Alex6323
Copy link
Contributor

@Alex6323 Alex6323 commented Oct 5, 2023

Description of change

  • Renames (and refactors) the Rent trait to StorageScore and provides 2 fns: storage_score and rent_cost.
  • Renames RentStructure to RentParameters and changes its semantics to offsets.
  • Introduces the new RentStructure type which wraps a RentParameters and something unmemorable but has to do with the implicit account

Links to any relevant issues

Closes #1352

NOTE:
I turned this into a draft again, because the TIP isn't complete yet. So far this PR has implemented what was merged into iota.go here: iotaledger/iota.go#537 (except for the closures that can be provided on some storage score implementors)

@@ -31,145 +36,153 @@ const DEFAULT_BYTE_COST_FACTOR_BLOCK_ISSUER_KEY: u8 = 1;
serde(rename_all = "camelCase")
)]
pub struct RentStructure {
Copy link
Member

Choose a reason for hiding this comment

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

@Alex6323 Alex6323 marked this pull request as ready for review October 6, 2023 16:58
@@ -721,12 +721,12 @@ pub async fn send_native_token_command(
let address = address.convert()?;
let transaction = if gift_storage_deposit.unwrap_or(false) {
// Send native tokens together with the required storage deposit
let rent_structure = account.client().get_rent_structure().await?;
let rent_struct = account.client().get_rent_parameters().await?.into();
Copy link

@DaughterOfMars DaughterOfMars Oct 6, 2023

Choose a reason for hiding this comment

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

rent_params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, it's converted into a RentStructure

Choose a reason for hiding this comment

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

but why

Copy link
Contributor Author

Choose a reason for hiding this comment

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

downstream effect ... RentStructure (new) wraps the RentParameters (old RentStructure) and a new field regarding implicit account creation. Unfortunately it is not reflected in the TIP yet, but here you can see that's it's going to be:
https://github.com/iotaledger/iota.go/pull/537/files#diff-74ba3861618d2996e83bd87e90b7259060214740d314c9d10cc0ae99c47df9c5R51-R55

This new field must be computed at runtime to create the new RentStructure instance, and this is what we have to use in the trait to calculate the score and hence the rent cost correctly.

Choose a reason for hiding this comment

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

Since it's calculated at runtime, why not just make it a method on RentParameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aight, but even if it won't become part of the TIP, from a technical PoV I think it's still a good idea to calculate it only once at runtime (when the rent parameters are fetched from the node) and keep it buffered somewhere. I think it's fine to use a wrapper struct in order to keep RentParameters identical with the TIP. This is the path forward they chose in iota.go. One can go a different route, but you have to/should buffer that computed score, and not re-compute it unnecessarily.

Choose a reason for hiding this comment

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

I think there's probably a better way to cache the value, if we need to

Copy link
Contributor Author

@Alex6323 Alex6323 Oct 12, 2023

Choose a reason for hiding this comment

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

Maybe, but since there's no immediately obvious way I would suggest to create an issue and someone from the team investigates a different approach in another/next sprint. I am strongly against caching the value globally or making everything overly complex just to prevent the wrapper. Wrappers are bread and butter in Rust so I don't really understand the discomfort with that 🤷

Choose a reason for hiding this comment

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

I think there's no immediately obvious reason to cache this tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, I guess questioning that is fair! I'm changing it ...

@Alex6323 Alex6323 marked this pull request as draft October 10, 2023 14:59
@Alex6323 Alex6323 linked an issue Oct 11, 2023 that may be closed by this pull request
3 tasks
@thibault-martinez
Copy link
Member

Closing in favour of #1065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename RentStructure to StorageScoreParameters
3 participants