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

Crowdloan rewards precompiles #607

Merged
merged 36 commits into from
Jul 22, 2021
Merged

Conversation

girazoki
Copy link
Collaborator

@girazoki girazoki commented Jul 15, 2021

What does it do?

It adds crowdloan precompiles for:

  • is_contributor(address)
  • reward_info(address)
  • claim
  • update_reward_address(address)

This PR follows closely the test structure in #518. Ideally once any of these gets merged, we should move some test utils to precompiles-utils

What important points reviewers should know?

Is there something left for follow-up PRs?

What alternative implementations were considered?

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

What value does it bring to the blockchain users?

Checklist

  • Does it require a purge of the network?
  • You bumped the runtime version if there are breaking changes in the runtime ?
  • Does it require changes in documentation/tutorials ?

// Solidity's bool type is 256 bits as shown by these examples
// https://docs.soliditylang.org/en/v0.8.0/abi-spec.html
// This utility function converts a Rust bool into the corresponding Solidity type
fn bool_to_solidity_bytes(b: bool) -> Vec<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should really DRY this (I think it's copied here from parachain-staking)...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am just thinking of making a precompiles-common package that we can import here

@girazoki girazoki marked this pull request as ready for review July 20, 2021 09:08
@girazoki girazoki added the B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes label Jul 20, 2021
return Err(ExitError::OutOfGas);
}
}
log::trace!(target: "crowdloan-rewards-precompile", "Made it past gas check");
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably clean up some of these log statements before merging

Ok(post_info) => {
let gas_used = Runtime::GasWeightMapping::weight_to_gas(
post_info.actual_weight.unwrap_or(info.weight),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that gas_used here could be > gas provided? Or is this guaranteed to be the same as required_gas above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have been checking that substrate uses the get_dispatch_info to calculate weights in pallets like utility and others. So I assume they should coincide

"In update_reward_address dispatchable wrapper"
);
log::trace!(target: "crowdloan-rewards-precompile", "input is {:?}", input);
let new_address = parse_account(&input[..32])?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need a bounds check here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can add them yes

// Solidity's bool type is 256 bits as shown by these examples
// https://docs.soliditylang.org/en/v0.8.0/abi-spec.html
// This utility function converts a Rust bool into the corresponding Solidity type
pub fn bool_to_solidity_bytes(b: bool) -> Vec<u8> {
Copy link
Contributor

@notlesh notlesh Jul 20, 2021

Choose a reason for hiding this comment

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

Perhaps this could be a const fn and could be something like:

match b {
    true => 1usize.into(),
    false => 0usize.into(),
}

Assuming it could return a U256...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And then convert the U256 to vec?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe. Isn't that the purpose of the following fn?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah perhaps is more clear that way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

having constant functions does not allow to do function calls or conversions, so I guess I will leave it as it is for now

Copy link
Contributor

@notlesh notlesh 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 had a few comments that you are free to ignore, but do see the one about the bounds check.

@4meta5 4meta5 added the A8-mergeoncegreen Pull request is reviewed well. label Jul 21, 2021
@girazoki girazoki added the A0-pleasereview Pull request needs code review. label Jul 21, 2021
@girazoki girazoki mentioned this pull request Jul 22, 2021
3 tasks
@girazoki girazoki merged commit b824a28 into master Jul 22, 2021
@girazoki girazoki deleted the crowdloan_rewards_precompiles branch July 22, 2021 12:06
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. A8-mergeoncegreen Pull request is reviewed well. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants