Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

decouple transaction payment and currency #6912

Merged
27 commits merged into from
Oct 30, 2020

Conversation

weichweich
Copy link
Contributor

@weichweich weichweich commented Aug 18, 2020

polkadot companion: paritytech/polkadot#1784

Hi, we wanted to use the transaction payment pallet with a multi-currency pallet. We therefore needed to remove the Currency dependency from the transaction payment pallet. Is this something that could get merged?

This PR introduces an OnChargeTransaction trait that must be implemented and added to the pallet_transaction_payment::Trait. OnChargeTransaction implements how transaction fees are withdrawn and deposited. To keep the original behavior, I implemented OnChargeTransaction for a CurrencyAdapter which does the same as the implementation before.

These changes would break the API, because all chains need to change the implementation of the pallet_transaction_payment::Trait.

Before:

impl pallet_transaction_payment::Trait for Runtime {
	type Currency = Balances;
	type OnTransactionPayment = ();
	...
}

After:

use pallet_transaction_payment::CurrencyAdapter;

impl pallet_transaction_payment::Trait for Runtime {
	type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
	...
}

@cla-bot-2020
Copy link

cla-bot-2020 bot commented Aug 18, 2020

@weichweich it looks like you have not signed our contributor license aggreement yet. Please visit this link to sign our agreement. This pull request cannot be merged until the agrement is signed.

@cla-bot-2020
Copy link

cla-bot-2020 bot commented Aug 18, 2020

@weichweich, Your signature has been received.

@shawntabrizi
Copy link
Contributor

Where can I see the multi-currency pallet you want to integrate?

Have you considered implementing your own payment pallet for your needs rather than modifying ours?

@weichweich
Copy link
Contributor Author

Where can I see the multi-currency pallet you want to integrate?

It's the token pallet from the ORML.

Have you considered implementing your own payment pallet for your needs rather than modifying ours?

Yes I considered that, but adjusting your payment pallet was easier, I think. I would rather maintain our changed version of the transaction payment pallet than writing everything from scratch.

For us it would just be more convenient to have this as part of substrate and maybe someone wants a more flexible payment pallet too? 😅 But it's also an option to maintain our own version.

@gavofyork
Copy link
Member

gavofyork commented Aug 19, 2020

Is it not possible to implement a Currency trait with an adaptor to the (multicurrency) Balance type (plus some other type that gives an index or key or whatever)? (The Currency trait is used to generalise over something that provides fungible tokens throughout Substrate Frame, so I don't see why we'd want to abstract it to something less specific here and not elsewhere.)

@gavofyork gavofyork added the A0-please_review Pull request needs code review. label Aug 19, 2020
@xlc
Copy link
Contributor

xlc commented Aug 19, 2020

It is possible to implement Currency trait, but I the imbalance features makes it complicated. Maybe we can have a simpler version like this? https://github.com/open-web3-stack/open-runtime-module-library/blob/fa1eef43ad87f3b20f5e3bfaea84bf9ffaa8df18/traits/src/currency.rs#L174

@weichweich
Copy link
Contributor Author

Is it not possible to implement a Currency trait with an adaptor to the (multicurrency) Balance type (plus some other type that gives an index or key or whatever)? (The Currency trait is used to generalise over something that provides fungible tokens throughout Substrate Frame, so I don't see why we'd want to abstract it to something less specific here and not elsewhere.)

As xlc said, the imbalances make this rather complicated. We also want to be able to pay the transaction fees in different currencies depending on the transaction (e.g. if you transfer a multi-currency, you pay the fees in the same currency). That's why we can't just drop in a currency implementation. We inspect the call and then decide which currency is used to pay the fees.

@gavofyork
Copy link
Member

I see. Fair enough, then.

@gavofyork
Copy link
Member

I'm ok with the general direction. Haven't done a deep review of the logic though.

@gavofyork gavofyork added B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Aug 24, 2020
@xlc
Copy link
Contributor

xlc commented Sep 3, 2020

@weichweich FYI orml-tokens now can implement trait Currency open-web3-stack/open-runtime-module-library#262

@gnunicorn gnunicorn requested review from kianenigma and thiolliere and removed request for kianenigma October 1, 2020 14:16
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.

I think this is almost ready. My only complaint is about naming and documentation on the trait.

frame/transaction-payment/src/payment.rs Outdated Show resolved Hide resolved
frame/transaction-payment/src/payment.rs Show resolved Hide resolved
weichweich and others added 2 commits October 5, 2020 13:14
improved documentation

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
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.

Looks good to me now. You need to create a polkadot companion. If there are errors unrelated to your changes in the gitlab-check-polkadot-companion-build CI job you may need to merge master in this PR.

wischli pushed a commit to KILTprotocol/substrate that referenced this pull request Oct 6, 2020
Comment on lines +77 to +79
if fee.is_zero() {
return Ok(None);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already checked in the call site, but anyways good.

/// Note: The `fee` already includes the `tip`.
fn withdraw_fee(
who: &T::AccountId,
_call: &T::Call,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we passing the call here if it is not used? what is the future proof argument?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the answer is this:

We also want to be able to pay the transaction fees in different currencies depending on the transaction (e.g. if you transfer a multi-currency, you pay the fees in the same currency). That's why we can't just drop in a currency implementation. We inspect the call and then decide which currency is used to pay the fees.

But honestly I don't get how you can achieve this in your multi-currency runtime. You still have one currency types passed in as C here. How can you implement something where you deduct from different currencies based on the call?

I am have not worked with such a multi currency pallet yet, so I might be missing some background info here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have another implementation of the OnChargeTransaction Trait. Our implementation doesn't require a Currency, but a multi currency.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

All in all looks good, I just want to see a few questions that I had answered as well.

weichweich and others added 2 commits October 12, 2020 21:39
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Copy link
Contributor

@thiolliere thiolliere 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 to me

frame/transaction-payment/src/lib.rs Outdated Show resolved Hide resolved
frame/transaction-payment/src/payment.rs Show resolved Hide resolved
@thiolliere thiolliere added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Oct 29, 2020
@thiolliere
Copy link
Contributor

Audit is done, sorry for delay.
Can you merge master ?
Also I think this comment is relevant: #6912 (comment)

@thiolliere
Copy link
Contributor

bot merge

@ghost
Copy link

ghost commented Oct 30, 2020

Trying merge.

@ghost ghost merged commit 5d30787 into paritytech:master Oct 30, 2020
ghost pushed a commit to paritytech/polkadot that referenced this pull request Oct 30, 2020
* adjustments for substrate PR

paritytech/substrate#6912

* Update runtime/kusama/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply suggestions from code review

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* update substrate

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
@weichweich weichweich deleted the aw-tx-payment-no-currency branch October 30, 2020 12:59
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Mar 10, 2023
* adjustments for substrate PR

paritytech/substrate#6912

* Update runtime/kusama/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply suggestions from code review

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* update substrate

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Jul 13, 2023
* adjustments for substrate PR

paritytech/substrate#6912

* Update runtime/kusama/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply suggestions from code review

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* update substrate

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants