Skip to content

Commit d7f413a

Browse files
committed
westend-runtime: integrate with pallet-dap-satellite
Integrate westend-runtime with pallet-dap-satellite. Preserve the pre-existing logic for which: - 100% of tx fees -> block author - 100% of tips -> block author This is an overkill for Westend but is just an exercise in preparation of what we will do for Polkadot and Kusama (e.g. X% / 100 -X% split)
1 parent f6a542e commit d7f413a

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/runtime/westend/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pallet-balances = { workspace = true }
6060
pallet-beefy = { workspace = true }
6161
pallet-beefy-mmr = { workspace = true }
6262
pallet-conviction-voting = { workspace = true }
63+
pallet-dap-satellite = { workspace = true }
6364
pallet-delegated-staking = { workspace = true }
6465
pallet-election-provider-multi-phase = { workspace = true }
6566
pallet-fast-unstake = { workspace = true }
@@ -156,6 +157,7 @@ std = [
156157
"pallet-beefy-mmr/std",
157158
"pallet-beefy/std",
158159
"pallet-conviction-voting/std",
160+
"pallet-dap-satellite/std",
159161
"pallet-delegated-staking/std",
160162
"pallet-election-provider-multi-phase/std",
161163
"pallet-election-provider-support-benchmarking?/std",
@@ -246,6 +248,7 @@ runtime-benchmarks = [
246248
"pallet-balances/runtime-benchmarks",
247249
"pallet-beefy-mmr/runtime-benchmarks",
248250
"pallet-conviction-voting/runtime-benchmarks",
251+
"pallet-dap-satellite/runtime-benchmarks",
249252
"pallet-delegated-staking/runtime-benchmarks",
250253
"pallet-election-provider-multi-phase/runtime-benchmarks",
251254
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
@@ -312,6 +315,7 @@ try-runtime = [
312315
"pallet-beefy-mmr/try-runtime",
313316
"pallet-beefy/try-runtime",
314317
"pallet-conviction-voting/try-runtime",
318+
"pallet-dap-satellite/try-runtime",
315319
"pallet-delegated-staking/try-runtime",
316320
"pallet-election-provider-multi-phase/try-runtime",
317321
"pallet-fast-unstake/try-runtime",

polkadot/runtime/westend/src/lib.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ use frame_support::{
3535
genesis_builder_helper::{build_state, get_preset},
3636
parameter_types,
3737
traits::{
38-
fungible::HoldConsideration, tokens::UnityOrOuterConversion, AsEnsureOriginWithArg,
39-
ConstU32, Contains, EitherOf, EitherOfDiverse, EnsureOriginWithArg, FromContains,
40-
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, Nothing, ProcessMessage,
41-
ProcessMessageError, VariantCountOf, WithdrawReasons,
38+
fungible::{Credit, HoldConsideration},
39+
tokens::UnityOrOuterConversion,
40+
AsEnsureOriginWithArg, ConstU32, Contains, EitherOf, EitherOfDiverse, EnsureOriginWithArg,
41+
FromContains, Imbalance, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, Nothing,
42+
OnUnbalanced, ProcessMessage, ProcessMessageError, VariantCountOf, WithdrawReasons,
4243
},
4344
weights::{ConstantMultiplier, WeightMeter},
4445
PalletId,
@@ -479,11 +480,43 @@ parameter_types! {
479480
/// This value increases the priority of `Operational` transactions by adding
480481
/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
481482
pub const OperationalFeeMultiplier: u8 = 5;
483+
/// Percentage of fees that go to DAP satellite (0-100).
484+
/// The remainder goes to block author. Tips always go 100% to author.
485+
/// Westend: 0% to DAP (preserving original behavior of 100% to author)
486+
/// Polkadot/Kusama: configurable (e.g., 80% to DAP, 20% to author)
487+
pub const DapSatelliteFeePercent: u32 = 0;
488+
}
489+
490+
/// Fee handler that splits fees between DAP satellite and block author.
491+
/// - `DapSatelliteFeePercent`% of fees go to DAP satellite
492+
/// - (100 - `DapSatelliteFeePercent`)% of fees go to block author
493+
/// - 100% of tips go to block author
494+
pub struct DealWithFeesSatellite;
495+
impl OnUnbalanced<Credit<AccountId, Balances>> for DealWithFeesSatellite {
496+
fn on_unbalanceds(mut fees_then_tips: impl Iterator<Item = Credit<AccountId, Balances>>) {
497+
if let Some(fees) = fees_then_tips.next() {
498+
let dap_percent = DapSatelliteFeePercent::get();
499+
let author_percent = 100u32.saturating_sub(dap_percent);
500+
let mut split = fees.ration(dap_percent, author_percent);
501+
if let Some(tips) = fees_then_tips.next() {
502+
// For tips: 100% to author
503+
tips.merge_into(&mut split.1);
504+
}
505+
// Send configured % to DAP satellite (if any)
506+
if dap_percent > 0 {
507+
<pallet_dap_satellite::SlashToSatellite<Runtime> as OnUnbalanced<_>>::on_unbalanced(
508+
split.0,
509+
);
510+
}
511+
// Send remainder + tips to author
512+
<ToAuthor<Runtime> as OnUnbalanced<_>>::on_unbalanced(split.1);
513+
}
514+
}
482515
}
483516

484517
impl pallet_transaction_payment::Config for Runtime {
485518
type RuntimeEvent = RuntimeEvent;
486-
type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>;
519+
type OnChargeTransaction = FungibleAdapter<Balances, DealWithFeesSatellite>;
487520
type OperationalFeeMultiplier = OperationalFeeMultiplier;
488521
type WeightToFee = WeightToFee;
489522
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
@@ -1747,6 +1780,10 @@ impl pallet_root_offences::Config for Runtime {
17471780
type ReportOffence = Offences;
17481781
}
17491782

1783+
impl pallet_dap_satellite::Config for Runtime {
1784+
type Currency = Balances;
1785+
}
1786+
17501787
parameter_types! {
17511788
pub MbmServiceWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
17521789
}
@@ -2027,6 +2064,10 @@ mod runtime {
20272064
#[runtime::pallet_index(105)]
20282065
pub type RootOffences = pallet_root_offences;
20292066

2067+
// DAP Satellite - collects funds for transfer to DAP on AssetHub
2068+
#[runtime::pallet_index(106)]
2069+
pub type DapSatellite = pallet_dap_satellite;
2070+
20302071
// BEEFY Bridges support.
20312072
#[runtime::pallet_index(200)]
20322073
pub type Beefy = pallet_beefy;

prdoc/pr_10481.prdoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ doc:
1616
on system chains like Coretime, People and BridheHub and on the RelayChain. It should not be deployed
1717
on AssetHub, which hosts the central DAP pallet.
1818

19-
asset-hub-westend-runtime and staking-async test runtime have been modified to include pallet-dap and to send part of slashing and treasury's unspent funds to pallet-dap.
20-
coretime-westend-runtime has been updated to include pallet-dap-satellite. Coretime revenues are now accumulated in the pallet-dap-satellite account instead of being burned.
19+
Runtime changes:
20+
- westend-runtime has been updated to include pallet-dap-satellite. It preserves the original behavior for which 100% of tx fees are redirected to the block author.
21+
- asset-hub-westend-runtime and staking-async test runtime have been modified to include pallet-dap and to send part of slashing and treasury's unspent funds to pallet-dap.
22+
- coretime-westend-runtime has been updated to include pallet-dap-satellite. Coretime revenues are now accumulated in the pallet-dap-satellite account instead of being burned.
2123
crates:
2224
- name: frame-support
2325
bump: major

0 commit comments

Comments
 (0)