-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fee handler #363
base: main
Are you sure you want to change the base?
Fee handler #363
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2024 Polytope Labs. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::{weights::get_weight, Config}; | ||
use frame_support::dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo}; | ||
use ismp::messaging::Message; | ||
|
||
pub trait HandleFee<T: Config> { | ||
fn handle_fee(messages: &[Message], signer: T::AccountId) -> DispatchResultWithPostInfo; | ||
} | ||
|
||
impl<T: Config> HandleFee<T> for () { | ||
fn handle_fee(messages: &[Message], _signer: T::AccountId) -> DispatchResultWithPostInfo { | ||
//Todo: reward the signer | ||
Ok(PostDispatchInfo { | ||
actual_weight: Some(get_weight::<T>(&messages)), | ||
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. We should remove the 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. Eliminate the |
||
pays_fee: Pays::Yes, | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -178,6 +178,7 @@ pub mod child_trie; | |||||
pub mod dispatcher; | ||||||
pub mod errors; | ||||||
pub mod events; | ||||||
mod fee; | ||||||
pub mod host; | ||||||
mod impls; | ||||||
pub mod offchain; | ||||||
|
@@ -197,12 +198,13 @@ pub mod pallet { | |||||
use crate::{ | ||||||
child_trie::{RequestCommitments, ResponseCommitments, CHILD_TRIE_PREFIX}, | ||||||
errors::HandlingError, | ||||||
fee::HandleFee, | ||||||
weights::{get_weight, WeightProvider}, | ||||||
}; | ||||||
use codec::{Codec, Encode}; | ||||||
use core::fmt::Debug; | ||||||
use frame_support::{ | ||||||
dispatch::{DispatchResult, DispatchResultWithPostInfo}, | ||||||
dispatch::{DispatchResult, DispatchResultWithPostInfo, PostDispatchInfo}, | ||||||
pallet_prelude::*, | ||||||
traits::{fungible::Mutate, tokens::Preservation, Get, UnixTime}, | ||||||
PalletId, | ||||||
|
@@ -220,13 +222,12 @@ pub mod pallet { | |||||
router::IsmpRouter, | ||||||
}; | ||||||
use sp_core::{storage::ChildInfo, H256}; | ||||||
#[cfg(feature = "unsigned")] | ||||||
use sp_runtime::transaction_validity::{ | ||||||
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, | ||||||
ValidTransaction, | ||||||
}; | ||||||
use sp_runtime::{ | ||||||
traits::{AccountIdConversion, AtLeast32BitUnsigned}, | ||||||
transaction_validity::{ | ||||||
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, | ||||||
ValidTransaction, | ||||||
}, | ||||||
FixedPointOperand, | ||||||
}; | ||||||
use sp_std::prelude::*; | ||||||
|
@@ -304,6 +305,9 @@ pub mod pallet { | |||||
/// This offchain DB is also allowed to "merkelize" and "generate proofs" for messages. | ||||||
/// Most state machines will likey not need this and can just provide `()` | ||||||
type OffchainDB: OffchainDBProvider<Leaf = Leaf>; | ||||||
|
||||||
/// FeeHandler with custom fee logic | ||||||
type FeeHandler: HandleFee<Self>; | ||||||
} | ||||||
|
||||||
// Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and | ||||||
|
@@ -427,7 +431,6 @@ pub mod pallet { | |||||
/// - `messages`: the messages to handle or process. | ||||||
/// | ||||||
/// Emits different message events based on the Message received if successful. | ||||||
#[cfg(feature = "unsigned")] | ||||||
#[pallet::weight(get_weight::<T>(&messages))] | ||||||
#[pallet::call_index(0)] | ||||||
#[frame_support::transactional] | ||||||
|
@@ -437,7 +440,12 @@ pub mod pallet { | |||||
) -> DispatchResultWithPostInfo { | ||||||
ensure_none(origin)?; | ||||||
|
||||||
Self::execute(messages) | ||||||
Self::execute(messages.clone())?; | ||||||
|
||||||
Ok(PostDispatchInfo { | ||||||
actual_weight: Some(get_weight::<T>(&messages)), | ||||||
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.
Suggested change
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. |
||||||
pays_fee: Pays::No, | ||||||
}) | ||||||
} | ||||||
|
||||||
/// Execute the provided batch of ISMP messages. This call will short-circuit and revert if | ||||||
|
@@ -448,14 +456,15 @@ pub mod pallet { | |||||
/// - `messages`: A set of ISMP [`Message`]s to handle or process. | ||||||
/// | ||||||
/// Emits different message events based on the Message received if successful. | ||||||
#[cfg(not(feature = "unsigned"))] | ||||||
#[pallet::weight(get_weight::<T>(&messages))] | ||||||
#[pallet::call_index(1)] | ||||||
#[frame_support::transactional] | ||||||
pub fn handle(origin: OriginFor<T>, messages: Vec<Message>) -> DispatchResultWithPostInfo { | ||||||
ensure_signed(origin)?; | ||||||
let signer = ensure_signed(origin)?; | ||||||
|
||||||
Self::execute(messages.clone())?; | ||||||
|
||||||
Self::execute(messages) | ||||||
T::FeeHandler::handle_fee(messages.as_slice(), signer) | ||||||
} | ||||||
|
||||||
/// Create a consensus client, using a subjectively chosen consensus state. This can also | ||||||
|
@@ -644,7 +653,6 @@ pub mod pallet { | |||||
} | ||||||
|
||||||
/// This allows users execute ISMP datagrams for free. Use with caution. | ||||||
#[cfg(feature = "unsigned")] | ||||||
#[pallet::validate_unsigned] | ||||||
impl<T: Config> ValidateUnsigned for Pallet<T> { | ||||||
type Call = Call<T>; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ parachains-common = { workspace = true } | |
|
||
# ismp modules | ||
ismp = { workspace = true } | ||
pallet-ismp = { workspace = true, features = ["unsigned"] } | ||
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. let's revert this |
||
pallet-ismp = { workspace = true } | ||
pallet-ismp-demo = { workspace = true } | ||
pallet-ismp-runtime-api = { workspace = true } | ||
ismp-parachain = { workspace = true } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add a
get_weight
method here instead of using the weight routerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest leaving weight to benchmark in a separate trait, as the convention
FeeHandler
focuses on custom fee logic(e.g., rewarding the signer).Some refactoring accordingly in d03c72b
@seunlanlege Please let me know WDYT.