Skip to content

Commit

Permalink
fix(Capacity): remove targeted-fee-adjustment (#1722)
Browse files Browse the repository at this point in the history
Remove targeted fee adjustment from the calculation
for computing fees for Capacity transactions.

Capacity transactions are stable and do not consider
network congestion when calculating the fee. Therefore,
the targeted fee adjustment is set to one.

Closes #1709

Co-authored-by: Enddy Dumbrique <[email protected]>
  • Loading branch information
enddynayn and Enddy Dumbrique authored Oct 18, 2023
1 parent ab1807e commit 744fb89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions e2e/capacity/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,19 +766,25 @@ describe("Capacity Transactions", function () {
const addProviderPayload = await generateDelegationPayload({ ...defaultPayload });
const addProviderData = ExtrinsicHelper.api.registry.createType("PalletMsaAddProvider", addProviderPayload);
let delegatorKeys = createKeys("delegatorKeys");
const tx = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
const call = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
delegatorKeys.publicKey,
signPayloadSr25519(delegatorKeys, addProviderData),
addProviderPayload
);
const feeDetails: FeeDetails = await firstValueFrom(ExtrinsicHelper.api.rpc.frequencyTxPayment.computeCapacityFeeDetails(tx.toHex(), null));

// Actual weights and fee
const { weight: { refTime, proofSize }, } = await firstValueFrom(ExtrinsicHelper.api.call.transactionPaymentApi.queryInfo(call.toHex(), 0));
const weightFee = await firstValueFrom(ExtrinsicHelper.api.call.transactionPaymentApi.queryWeightToFee({refTime, proofSize}));

const feeDetails: FeeDetails = await firstValueFrom(ExtrinsicHelper.api.rpc.frequencyTxPayment.computeCapacityFeeDetails(call.toHex(), null));
assert.notEqual(feeDetails, undefined, "should have returned a feeDetails");
assert.notEqual(feeDetails.inclusionFee, undefined, "should have returned a partialFee");
assert(feeDetails.inclusionFee.isSome, "should have returned a partialFee");
const { baseFee, lenFee, adjustedWeightFee } = feeDetails.inclusionFee.toJSON() as any;
assert(Math.abs(baseFee - 106382) < 10_000, "The base fee appears to be wrong or have changed more than expected");
assert(Math.abs(lenFee - 1170000) < 100, "The len fee appears to be wrong or have changed more than expected");
assert(Math.abs(adjustedWeightFee - 2359035) < 100_000, "The adjusted weight fee appears to be wrong or have changed more than expected");
// This is comparing stable weight, which has no impact from targeted_fee_adjustment, with actual weights.
assert(Math.abs(adjustedWeightFee - weightFee.toNumber()) < 10_000, "The adjusted weight fee appears to be wrong or have changed more than expected");
});

it("Returns `FeeDetails` when requesting capacity cost of a transaction when wrapped in payWithCapacity", async function () {
Expand Down
8 changes: 5 additions & 3 deletions pallets/frequency-tx-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@ impl<T: Config> Pallet<T> {
let len_fee = Self::length_to_fee(len);
let base_fee = Self::weight_to_fee(CAPACITY_EXTRINSIC_BASE_WEIGHT);

let adjusted_weight_fee =
base_fee.saturating_add(weight_fee).saturating_add(len_fee);
let tip = Zero::zero();
fees = FeeDetails {
inclusion_fee: Some(InclusionFee { base_fee, len_fee, adjusted_weight_fee }),
inclusion_fee: Some(InclusionFee {
base_fee,
len_fee,
adjusted_weight_fee: weight_fee,
}),
tip,
};
}
Expand Down

0 comments on commit 744fb89

Please sign in to comment.