Skip to content

Commit

Permalink
remove with_fee_paid_by
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Sep 1, 2023
1 parent 998bb52 commit 5edb7cd
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 336 deletions.
28 changes: 1 addition & 27 deletions modules/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use sp_runtime::{
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,
},
FixedPointNumber, FixedPointOperand, MultiSignature, Percent, Perquintill,
FixedPointNumber, FixedPointOperand, Percent, Perquintill,
};
use sp_std::prelude::*;
use support::{AggregatedSwapPath, BuyWeightRate, PriceProvider, Ratio, Swap, SwapLimit, TransactionPayment};
Expand Down Expand Up @@ -639,22 +639,6 @@ pub mod module {
call.dispatch(origin)
}

/// Wrap call with fee paid by other account
#[pallet::call_index(5)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(T::WeightInfo::with_fee_paid_by().saturating_add(dispatch_info.weight), dispatch_info.class,)
})]
pub fn with_fee_paid_by(
origin: OriginFor<T>,
call: Box<CallOf<T>>,
_payer_addr: T::AccountId,
_payer_sig: MultiSignature,
) -> DispatchResultWithPostInfo {
ensure_signed(origin.clone())?;
call.dispatch(origin)
}

/// Dapp wrap call, and user pay tx fee as provided aggregated swap path. this dispatch call
/// should make sure the trading path is valid.
#[pallet::call_index(6)]
Expand Down Expand Up @@ -932,16 +916,6 @@ where
.map(|_| (who.clone(), custom_fee_surplus))
}
}
Some(Call::with_fee_paid_by {
call: _,
payer_addr,
payer_sig: _,
}) => {
// validate payer signature in runtime side, because `SignedExtension` between different runtime
// may be different.
Self::native_then_alternative_or_default(payer_addr, fee, WithdrawReasons::TRANSACTION_PAYMENT)
.map(|surplus| (payer_addr.clone(), surplus))
}
_ => Self::native_then_alternative_or_default(who, fee, reason).map(|surplus| (who.clone(), surplus)),
}
}
Expand Down
56 changes: 0 additions & 56 deletions modules/transaction-payment/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ fn with_fee_currency_call(currency_id: CurrencyId) -> <Runtime as Config>::Runti
fee_call
}

fn with_fee_paid_by_call(payer_addr: AccountId, payer_sig: MultiSignature) -> <Runtime as Config>::RuntimeCall {
let fee_call: <Runtime as Config>::RuntimeCall =
RuntimeCall::TransactionPayment(crate::mock::transaction_payment::Call::with_fee_paid_by {
call: Box::new(CALL),
payer_addr,
payer_sig,
});
fee_call
}

fn with_fee_aggregated_path_by_call(
fee_aggregated_path: Vec<AggregatedSwapPath<CurrencyId>>,
) -> <Runtime as Config>::RuntimeCall {
Expand Down Expand Up @@ -878,52 +868,6 @@ fn charges_fee_when_validate_with_fee_currency_call_use_pool() {
});
}

#[test]
fn charges_fee_when_validate_with_fee_paid_by_native_token() {
// Enable dex with Alice, and initialize tx charge fee pool
builder_with_dex_and_fee_pool(true).execute_with(|| {
// make a fake signature
let signature = MultiSignature::Sr25519(sp_core::sr25519::Signature([0u8; 64]));
// payer has enough native asset
assert_ok!(Currencies::update_balance(RuntimeOrigin::root(), BOB, ACA, 500,));

let fee: Balance = 50 * 2 + 100;
assert_ok!(ChargeTransactionPayment::<Runtime>::from(0).validate(
&ALICE,
&with_fee_paid_by_call(BOB, signature),
&INFO2,
50
));
assert_eq!(500 - fee, Currencies::free_balance(ACA, &BOB));
});
}

#[test]
fn charges_fee_when_validate_with_fee_paid_by_default_token() {
// Enable dex with Alice, and initialize tx charge fee pool
builder_with_dex_and_fee_pool(true).execute_with(|| {
let ausd_acc = Pallet::<Runtime>::sub_account_id(AUSD);
assert_eq!(100, Currencies::free_balance(AUSD, &ausd_acc));
assert_eq!(10000, Currencies::free_balance(ACA, &ausd_acc));

// make a fake signature
let signature = MultiSignature::Sr25519(sp_core::sr25519::Signature([0u8; 64]));
// payer has enough native asset
assert_ok!(Currencies::update_balance(RuntimeOrigin::root(), BOB, AUSD, 5000,));

assert_ok!(ChargeTransactionPayment::<Runtime>::from(0).validate(
&ALICE,
&with_fee_paid_by_call(BOB, signature),
&INFO2,
50
));
assert_eq!(2700, Currencies::free_balance(AUSD, &ausd_acc));
assert_eq!(9740, Currencies::free_balance(ACA, &ausd_acc));
assert_eq!(2400, Currencies::free_balance(AUSD, &BOB));
assert_eq!(10, Currencies::free_balance(ACA, &BOB));
});
}

#[test]
fn charges_fee_when_validate_and_native_is_not_enough() {
// Enable dex with Alice, and initialize tx charge fee pool
Expand Down
9 changes: 0 additions & 9 deletions modules/transaction-payment/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub trait WeightInfo {
fn with_fee_path() -> Weight;
fn with_fee_aggregated_path() -> Weight;
fn with_fee_currency() -> Weight;
fn with_fee_paid_by() -> Weight;
}

/// Weights for module_transaction_payment using the Acala node and recommended hardware.
Expand Down Expand Up @@ -102,10 +101,6 @@ impl<T: frame_system::Config> WeightInfo for AcalaWeight<T> {
Weight::from_parts(193_000_000, 0)
.saturating_add(T::DbWeight::get().reads(1 as u64))
}
fn with_fee_paid_by() -> Weight {
Weight::from_parts(193_000_000, 0)
.saturating_add(T::DbWeight::get().reads(1 as u64))
}
// Storage: TransactionPayment NextFeeMultiplier (r:1 w:1)
// Storage: System BlockWeight (r:1 w:0)
fn on_finalize() -> Weight {
Expand Down Expand Up @@ -147,8 +142,4 @@ impl WeightInfo for () {
Weight::from_parts(193_000_000, 0)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
}
fn with_fee_paid_by() -> Weight {
Weight::from_parts(193_000_000, 0)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
}
}
48 changes: 17 additions & 31 deletions primitives/src/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@ use sp_std::alloc::format;
use sp_std::{marker::PhantomData, prelude::*};

#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(ConvertEthTx, CheckPayerTx))]
pub struct AcalaUncheckedExtrinsic<
Call,
Extra: SignedExtension,
ConvertEthTx,
StorageDepositPerByte,
TxFeePerGas,
CheckPayerTx,
>(
#[scale_info(skip_type_params(ConvertEthTx))]
pub struct AcalaUncheckedExtrinsic<Call, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>(
pub UncheckedExtrinsic<Address, Call, AcalaMultiSignature, Extra>,
PhantomData<(ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx)>,
PhantomData<(ConvertEthTx, StorageDepositPerByte, TxFeePerGas)>,
);

impl<Call: TypeInfo, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx> Extrinsic
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call: TypeInfo, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> Extrinsic
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
{
type Call = Call;

Expand All @@ -75,28 +68,27 @@ impl<Call: TypeInfo, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte
}
}

impl<Call, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx> ExtrinsicMetadata
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> ExtrinsicMetadata
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
{
const VERSION: u8 = UncheckedExtrinsic::<Address, Call, AcalaMultiSignature, Extra>::VERSION;
type SignedExtensions = Extra;
}

impl<Call: TypeInfo, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
ExtrinsicCall for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call: TypeInfo, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> ExtrinsicCall
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
{
fn call(&self) -> &Self::Call {
self.0.call()
}
}

impl<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, Lookup, CheckPayerTx> Checkable<Lookup>
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, Lookup> Checkable<Lookup>
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
where
Call: Encode + Member,
Extra: SignedExtension<AccountId = AccountId32>,
ConvertEthTx: Convert<(Call, Extra), Result<(EthereumTransactionMessage, Extra), InvalidTransaction>>,
CheckPayerTx: Convert<(Call, Extra), Result<(), InvalidTransaction>>,
StorageDepositPerByte: Get<Balance>,
TxFeePerGas: Get<Balance>,
Lookup: traits::Lookup<Source = Address, Target = AccountId32>,
Expand All @@ -105,10 +97,6 @@ where

fn check(self, lookup: &Lookup) -> Result<Self::Checked, TransactionValidityError> {
let function = self.0.function.clone();
let signature = self.0.signature.clone();
if let Some((_, _, extra)) = signature {
CheckPayerTx::convert((function.clone(), extra))?;
}

match self.0.signature {
Some((addr, AcalaMultiSignature::Ethereum(sig), extra)) => {
Expand Down Expand Up @@ -240,8 +228,8 @@ where
}
}

impl<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx> GetDispatchInfo
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> GetDispatchInfo
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
where
Call: GetDispatchInfo,
Extra: SignedExtension,
Expand All @@ -251,9 +239,8 @@ where
}
}

impl<Call: Encode, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
serde::Serialize
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<Call: Encode, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> serde::Serialize
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
{
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -263,9 +250,8 @@ impl<Call: Encode, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte,
}
}

impl<'a, Call: Decode, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
serde::Deserialize<'a>
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas, CheckPayerTx>
impl<'a, Call: Decode, Extra: SignedExtension, ConvertEthTx, StorageDepositPerByte, TxFeePerGas> serde::Deserialize<'a>
for AcalaUncheckedExtrinsic<Call, Extra, ConvertEthTx, StorageDepositPerByte, TxFeePerGas>
{
fn deserialize<D>(de: D) -> Result<Self, D::Error>
where
Expand Down
38 changes: 2 additions & 36 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,14 +1848,8 @@ pub type SignedExtra = (
module_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = AcalaUncheckedExtrinsic<
RuntimeCall,
SignedExtra,
ConvertEthereumTx,
StorageDepositPerByte,
TxFeePerGas,
PayerSignatureVerification,
>;
pub type UncheckedExtrinsic =
AcalaUncheckedExtrinsic<RuntimeCall, SignedExtra, ConvertEthereumTx, StorageDepositPerByte, TxFeePerGas>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
/// Extrinsic type that has already been checked.
Expand Down Expand Up @@ -2355,34 +2349,6 @@ impl Convert<(RuntimeCall, SignedExtra), Result<(EthereumTransactionMessage, Sig
}
}

#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
pub struct PayerSignatureVerification;

impl Convert<(RuntimeCall, SignedExtra), Result<(), InvalidTransaction>> for PayerSignatureVerification {
fn convert((call, _extra): (RuntimeCall, SignedExtra)) -> Result<(), InvalidTransaction> {
if let RuntimeCall::TransactionPayment(module_transaction_payment::Call::with_fee_paid_by {
call: _,
payer_addr: _,
payer_sig: _,
}) = call
{
// Disabled for now
return Err(InvalidTransaction::BadProof);
// let payer_account: [u8; 32] = payer_addr
// .encode()
// .as_slice()
// .try_into()
// .map_err(|_| InvalidTransaction::BadSigner)?;
// // payer signature is aim at inner call of `with_fee_paid_by` call.
// let raw_payload = SignedPayload::new(*call, extra).map_err(|_|
// InvalidTransaction::BadSigner)?; if !raw_payload.using_encoded(|payload|
// payer_sig.verify(payload, &payer_account.into())) { return Err(InvalidTransaction::
// BadProof); }
}
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 0 additions & 7 deletions runtime/acala/src/weights/module_transaction_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ impl<T: frame_system::Config> module_transaction_payment::WeightInfo for WeightI
// Minimum execution time: 9_563 nanoseconds.
Weight::from_parts(9_999_000, 0)
}
fn with_fee_paid_by() -> Weight {
// Proof Size summary in bytes:
// Measured: `666`
// Estimated: `0`
// Minimum execution time: 6_405 nanoseconds.
Weight::from_parts(6_669_000, 0)
}
// Storage: `TransactionPayment::NextFeeMultiplier` (r:1 w:1)
// Proof: `TransactionPayment::NextFeeMultiplier` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`)
fn on_finalize() -> Weight {
Expand Down
38 changes: 2 additions & 36 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,14 +1842,8 @@ pub type SignedExtra = (
module_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = AcalaUncheckedExtrinsic<
RuntimeCall,
SignedExtra,
ConvertEthereumTx,
StorageDepositPerByte,
TxFeePerGas,
PayerSignatureVerification,
>;
pub type UncheckedExtrinsic =
AcalaUncheckedExtrinsic<RuntimeCall, SignedExtra, ConvertEthereumTx, StorageDepositPerByte, TxFeePerGas>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
/// Extrinsic type that has already been checked.
Expand Down Expand Up @@ -2359,34 +2353,6 @@ impl Convert<(RuntimeCall, SignedExtra), Result<(EthereumTransactionMessage, Sig
}
}

#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
pub struct PayerSignatureVerification;

impl Convert<(RuntimeCall, SignedExtra), Result<(), InvalidTransaction>> for PayerSignatureVerification {
fn convert((call, _extra): (RuntimeCall, SignedExtra)) -> Result<(), InvalidTransaction> {
if let RuntimeCall::TransactionPayment(module_transaction_payment::Call::with_fee_paid_by {
call: _,
payer_addr: _,
payer_sig: _,
}) = call
{
// Disabled for now
return Err(InvalidTransaction::BadProof);
// let payer_account: [u8; 32] = payer_addr
// .encode()
// .as_slice()
// .try_into()
// .map_err(|_| InvalidTransaction::BadSigner)?;
// // payer signature is aim at inner call of `with_fee_paid_by` call.
// let raw_payload = SignedPayload::new(*call, extra).map_err(|_|
// InvalidTransaction::BadSigner)?; if !raw_payload.using_encoded(|payload|
// payer_sig.verify(payload, &payer_account.into())) { return Err(InvalidTransaction::
// BadProof); }
}
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 0 additions & 7 deletions runtime/karura/src/weights/module_transaction_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ impl<T: frame_system::Config> module_transaction_payment::WeightInfo for WeightI
// Minimum execution time: 10_071 nanoseconds.
Weight::from_parts(10_425_000, 0)
}
fn with_fee_paid_by() -> Weight {
// Proof Size summary in bytes:
// Measured: `666`
// Estimated: `0`
// Minimum execution time: 6_880 nanoseconds.
Weight::from_parts(7_067_000, 0)
}
// Storage: `TransactionPayment::NextFeeMultiplier` (r:1 w:1)
// Proof: `TransactionPayment::NextFeeMultiplier` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`)
fn on_finalize() -> Weight {
Expand Down
Loading

0 comments on commit 5edb7cd

Please sign in to comment.