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

[pallet-revive] use evm decimals in call host fn #6466

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

pgherveou
Copy link
Contributor

@pgherveou pgherveou commented Nov 13, 2024

This PR update the pallet to use the EVM 18 decimal balance in contracts call and host functions instead of the native balance.

It also updates the js example to add the piggy-bank solidity contract that expose the problem

@pgherveou
Copy link
Contributor Author

/cmd prdoc --audience runtime_dev --bump minor

@pgherveou pgherveou added T7-smart_contracts This PR/Issue is related to smart contracts. R0-silent Changes should not be mentioned in any release notes labels Nov 13, 2024
@pgherveou pgherveou marked this pull request as ready for review November 13, 2024 19:55
Copy link

@jarkkojs jarkkojs left a comment

Choose a reason for hiding this comment

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

My expertise is limited but with that I don't see anything obnoxious...

Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Didn't we do the conversion inside the checked extrinsic conversion before? I would expect that code to be touched here, too.

Copy link
Member

Choose a reason for hiding this comment

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

Are those versioned by accident? Same for the other build outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by versioned?

Copy link
Member

Choose a reason for hiding this comment

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

Meaning: Why are we checking in compilation outputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are used to run tests e.g https://github.com/paritytech/polkadot-sdk/blob/pg/piggy-bank/substrate/frame/revive/rpc/src/tests.rs?plain=1#L243-L260

they were already checked in, except they were part of the json file, this approach works better for tooling like chaintypes that generates the ts types from the abi files

Copy link
Member

Choose a reason for hiding this comment

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

So if we make breaking changes to pallet_revive we need to wait for a new revive version and then rebuild those files? Because there are CI tests that use them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting, that we only build test cases in Rust?
Would be pretty bad if we were breaking people's tooling and they could not submit a contract on chain anymore ?

substrate/frame/revive/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/lib.rs Outdated Show resolved Hide resolved
@pgherveou
Copy link
Contributor Author

pgherveou commented Nov 13, 2024

Didn't we do the conversion inside the checked extrinsic conversion before? I would expect that code to be touched here, too.

right fixed by using the helper functions d4364fd

and the rpc does not have to know about this 0bd3f74

@pgherveou pgherveou changed the title [pallet-revive] add piggy-bank sol example [pallet-revive] use evm decimals in call host fn Nov 13, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Can those not be vendored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean exactly, there is a js build script that can regenerate these blobs

substrate/frame/revive/rpc/examples/js/src/build-contracts.ts

Copy link
Member

Choose a reason for hiding this comment

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

Then we shouldn't put them in git?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well they are mostly here to play with js code
but I also use them to run integration tests rpc tests in CI
I don't want to add the revive tooling to the mono repo

Copy link
Member

Choose a reason for hiding this comment

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

Ok no hard opinion, I just find vendored code blobs always annoying because they have to get updated manually (in this case with breaking PVM or pallet changes

@smiasojed
Copy link
Contributor

Do we have information about native and EVM balances, as well as their conversion, in our tutorial? I assume that when we use the Substrate tools, we will see the native balance, and when we use the Ethereum tools, we will see the EVM balance.

@pgherveou
Copy link
Contributor Author

Do we have information about native and EVM balances, as well as their conversion, in our tutorial? I assume that when we use the Substrate tools, we will see the native balance, and when we use the Ethereum tools, we will see the EVM balance.

good call, so these number should be the same.
i.e when you look at the balance in your MM it should be the same as the balance for the same account in subxt
so it should be transparent from the point of view of the user.
One thing that should be mentioned though is that you can't transact with values that are too small for Substrate since the min value is 1_000_000wei (1Mwei)

@smiasojed
Copy link
Contributor

Just to confirm, I can use the pallet-balances to check the account balance, or I can look into the block explorer. Will it match what I see in MetaMask?

@pgherveou
Copy link
Contributor Author

Just to confirm, I can use the pallet-balances to check the account balance, or I can look into the block explorer. Will it match what I see in MetaMask?

All ui should display the same value
but if you look at the actual value with pjs you have to divide the EVM value by 1_000_000 since EVM use 18 digits and we use 12

Copy link

Review required! Latest push from author must always be reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants