This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add WeightToFee and LengthToFee impls to transaction-payment Runtime API #13110
Merged
paritytech-processbot
merged 5 commits into
paritytech:master
from
notlesh:notlesh-weight-to-fee-rpc
Jan 26, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8a0d2d
Add WeightToFee and LengthToFee impls to RPC
notlesh ee6f399
Remove RPC additions
notlesh 0ae8033
Update frame/transaction-payment/rpc/runtime-api/src/lib.rs
notlesh 9767e6b
Add comments to length_to_fee and weight_to_fee
notlesh 8eae333
Merge remote-tracking branch 'origin/master' into notlesh-weight-to-f…
ggwpez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,20 @@ pub trait TransactionPaymentApi<BlockHash, ResponseType> { | |
| encoded_xt: Bytes, | ||
| at: Option<BlockHash>, | ||
| ) -> RpcResult<FeeDetails<NumberOrHex>>; | ||
|
|
||
| #[method(name = "payment_weightToFee")] | ||
| fn query_weight_to_fee( | ||
| &self, | ||
| weight: sp_weights::Weight, | ||
| at: Option<BlockHash>, | ||
| ) -> RpcResult<NumberOrHex>; | ||
|
|
||
| #[method(name = "payment_lengthToFee")] | ||
| fn query_length_to_fee( | ||
| &self, | ||
| length: u32, | ||
| at: Option<BlockHash>, | ||
| ) -> RpcResult<NumberOrHex>; | ||
|
||
| } | ||
|
|
||
| /// Provides RPC methods to query a dispatchable's class, weight and fee. | ||
|
|
@@ -194,4 +208,58 @@ where | |
| tip: Default::default(), | ||
| }) | ||
| } | ||
|
|
||
| fn query_weight_to_fee( | ||
| &self, | ||
| weight: sp_weights::Weight, | ||
| at: Option<Block::Hash>, | ||
| ) -> RpcResult<NumberOrHex> { | ||
| let api = self.client.runtime_api(); | ||
| let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); | ||
|
|
||
| let fee = api.query_weight_to_fee(&at, weight).map_err(|e| { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Unable to query weight_to_fee.", | ||
| Some(e.to_string()), | ||
| )) | ||
| })?; | ||
|
|
||
| let fee = fee.try_into().map_err(|_| { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Balance not convertible", | ||
| Some("Balance could not be converted to NumberOrHex"), | ||
| )) | ||
| })?; | ||
|
|
||
| Ok(fee) | ||
| } | ||
|
|
||
| fn query_length_to_fee( | ||
| &self, | ||
| length: u32, | ||
| at: Option<Block::Hash>, | ||
| ) -> RpcResult<NumberOrHex> { | ||
| let api = self.client.runtime_api(); | ||
| let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); | ||
|
|
||
| let fee = api.query_length_to_fee(&at, length).map_err(|e| { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Unable to query length_to_fee.", | ||
| Some(e.to_string()), | ||
| )) | ||
| })?; | ||
|
|
||
| let fee = fee.try_into().map_err(|_| { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Balance not convertible", | ||
| Some("Balance could not be converted to NumberOrHex"), | ||
| )) | ||
| })?; | ||
|
|
||
| Ok(fee) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,11 +607,11 @@ where | |
| } | ||
| } | ||
|
|
||
| fn length_to_fee(length: u32) -> BalanceOf<T> { | ||
| pub fn length_to_fee(length: u32) -> BalanceOf<T> { | ||
| T::LengthToFee::weight_to_fee(&Weight::from_ref_time(length as u64)) | ||
| } | ||
|
|
||
| fn weight_to_fee(weight: Weight) -> BalanceOf<T> { | ||
| pub fn weight_to_fee(weight: Weight) -> BalanceOf<T> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add some docs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 9767e6b |
||
| // cap the weight to the maximum defined in runtime, otherwise it will be the | ||
| // `Bounded` maximum of its data type, which is not desired. | ||
| let capped_weight = weight.min(T::BlockWeights::get().max_block); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.