Skip to content

Conversation

@koushiro
Copy link
Contributor

@koushiro koushiro commented Feb 7, 2023

What does it do?

Improve the calculation of weight per gas.

What important points reviewers should know?

Is there something left for follow-up PRs?

No

What alternative implementations were considered?

Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?

polkadot-evm/frontier#995
polkadot-evm/frontier#1000

What value does it bring to the blockchain users?

@koushiro
Copy link
Contributor Author

koushiro commented Feb 7, 2023

I have contributed code to this repo, why does the CI still need a maintainer to approve 😕

@koushiro
Copy link
Contributor Author

koushiro commented Feb 8, 2023

@notlesh @tgmichel PTAL

@tgmichel tgmichel added A0-pleasereview Pull request needs code review. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed. not-breaking Does not need to be mentioned in breaking changes labels Feb 9, 2023
@tgmichel
Copy link
Contributor

PR looks good to me but just to be sure I understand, this is a refactor of the original formula and the improvement comes from readability only? Or is there any other benefit?

@koushiro
Copy link
Contributor Author

PR looks good to me but just to be sure I understand, this is a refactor of the original formula and the improvement comes from readability only? Or is there any other benefit?

just for readability only, I think

@koushiro koushiro changed the title Improve weight per gas calculation Improve readability of weight per gas calculation Feb 10, 2023
@tgmichel tgmichel changed the title Improve readability of weight per gas calculation Improve readability in weight per gas calculation Feb 10, 2023
@tgmichel
Copy link
Contributor

We are in the process of reviewing #2072 , please if you don't mind waiting until it is merged to rebase. Thank you!

@koushiro
Copy link
Contributor Author

@tgmichel PTAL again.
BTW, Once polkadot-evm/frontier#1000 is merged, we can directly use the fp_evm::weight_per_gas function to calculate WeightPerGas.

Copy link
Contributor

@tgmichel tgmichel left a comment

Choose a reason for hiding this comment

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

Thank you @koushiro LGTM. cc @notlesh

@koushiro
Copy link
Contributor Author

@notlesh could you take a look this PR?

// subtract roughly the cost of a balance transfer from it (about 1/3 the cost)
// and some cost to account for per-byte-fee.
// TODO: we should use benchmarking's overhead feature to measure this
pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_ref_time(10000 * WEIGHT_PER_GAS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this constant means we have to use the 10_000 magic number elsewhere (e.g. in tests below). In addition, extracting this value out of BlockWeights isn't straightforward. I think we should leave 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.

added the extrinsic_base_weight function and moved it into moonbeam_runtime_common crate.

Comment on lines -373 to -381
/// Current approximation of the gas/s consumption considering
/// EVM execution over compiled WASM (on 4.4Ghz CPU).
/// Given the 500ms Weight, from which 75% only are used for transactions,
/// the total EVM execution gas limit is: GAS_PER_SECOND * 0.500 * 0.75 ~= 15_000_000.
pub const GAS_PER_SECOND: u64 = 40_000_000;

/// Approximate ratio of the amount of Weight per Gas.
/// u64 works for approximations because Weight is a very small unit compared to gas.
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I think these constants are valuable for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koushiro
Copy link
Contributor Author

@tgmichel @notlesh could you take a look at the docker-moonbeam CI job?

@koushiro
Copy link
Contributor Author

koushiro commented Feb 27, 2023

@tgmichel @notlesh could you take a look at the CI job? This PR is pending for a long time :(
if you guys disagree with the changes, I will close this PR.

@koushiro
Copy link
Contributor Author

koushiro commented Mar 7, 2023

💢

@koushiro koushiro closed this Mar 7, 2023
@koushiro koushiro deleted the improve-weight-per-gas-calc branch March 7, 2023 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A0-pleasereview Pull request needs code review. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed. not-breaking Does not need to be mentioned in breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants