Skip to content

Commit fc8f9d6

Browse files
committed
pallet-dap-satellite: introduce minimal implementation and use it coretime-westend runtime
1 parent 877e9a9 commit fc8f9d6

File tree

8 files changed

+488
-75
lines changed

8 files changed

+488
-75
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ members = [
356356
"substrate/frame/conviction-voting",
357357
"substrate/frame/core-fellowship",
358358
"substrate/frame/dap",
359+
"substrate/frame/dap-satellite",
359360
"substrate/frame/delegated-staking",
360361
"substrate/frame/democracy",
361362
"substrate/frame/derivatives",
@@ -985,6 +986,7 @@ pallet-contracts-uapi = { path = "substrate/frame/contracts/uapi", default-featu
985986
pallet-conviction-voting = { path = "substrate/frame/conviction-voting", default-features = false }
986987
pallet-core-fellowship = { path = "substrate/frame/core-fellowship", default-features = false }
987988
pallet-dap = { path = "substrate/frame/dap", default-features = false }
989+
pallet-dap-satellite = { path = "substrate/frame/dap-satellite", default-features = false }
988990
pallet-default-config-example = { path = "substrate/frame/examples/default-config", default-features = false }
989991
pallet-delegated-staking = { path = "substrate/frame/delegated-staking", default-features = false }
990992
pallet-democracy = { path = "substrate/frame/democracy", default-features = false }

cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pallet-aura = { workspace = true }
3131
pallet-authorship = { workspace = true }
3232
pallet-balances = { workspace = true }
3333
pallet-broker = { workspace = true }
34+
pallet-dap-satellite = { workspace = true }
3435
pallet-message-queue = { workspace = true }
3536
pallet-multisig = { workspace = true }
3637
pallet-proxy = { workspace = true }
@@ -113,6 +114,7 @@ std = [
113114
"pallet-balances/std",
114115
"pallet-broker/std",
115116
"pallet-collator-selection/std",
117+
"pallet-dap-satellite/std",
116118
"pallet-message-queue/std",
117119
"pallet-multisig/std",
118120
"pallet-proxy/std",
@@ -167,6 +169,7 @@ runtime-benchmarks = [
167169
"pallet-balances/runtime-benchmarks",
168170
"pallet-broker/runtime-benchmarks",
169171
"pallet-collator-selection/runtime-benchmarks",
172+
"pallet-dap-satellite/runtime-benchmarks",
170173
"pallet-message-queue/runtime-benchmarks",
171174
"pallet-multisig/runtime-benchmarks",
172175
"pallet-proxy/runtime-benchmarks",
@@ -202,6 +205,7 @@ try-runtime = [
202205
"pallet-balances/try-runtime",
203206
"pallet-broker/try-runtime",
204207
"pallet-collator-selection/try-runtime",
208+
"pallet-dap-satellite/try-runtime",
205209
"pallet-message-queue/try-runtime",
206210
"pallet-multisig/try-runtime",
207211
"pallet-proxy/try-runtime",

cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,22 @@ use crate::{xcm_config::LocationToAccountId, *};
1818
use codec::{Decode, Encode};
1919
use cumulus_pallet_parachain_system::RelaychainDataProvider;
2020
use cumulus_primitives_core::relay_chain;
21-
use frame_support::{
22-
parameter_types,
23-
traits::{
24-
fungible::{Balanced, Credit, Inspect},
25-
tokens::{Fortitude, Preservation},
26-
DefensiveResult, OnUnbalanced,
27-
},
28-
};
29-
use frame_system::Pallet as System;
21+
use frame_support::parameter_types;
3022
use pallet_broker::{
3123
CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId, Timeslice,
3224
};
3325
use parachains_common::{AccountId, Balance};
34-
use sp_runtime::traits::{AccountIdConversion, MaybeConvert};
26+
use sp_runtime::traits::MaybeConvert;
3527
use westend_runtime_constants::system_parachain::coretime;
3628
use xcm::latest::prelude::*;
37-
use xcm_executor::traits::{ConvertLocation, TransactAsset};
38-
39-
pub struct BurnCoretimeRevenue;
40-
impl OnUnbalanced<Credit<AccountId, Balances>> for BurnCoretimeRevenue {
41-
fn on_nonzero_unbalanced(amount: Credit<AccountId, Balances>) {
42-
let acc = RevenueAccumulationAccount::get();
43-
if !System::<Runtime>::account_exists(&acc) {
44-
System::<Runtime>::inc_providers(&acc);
45-
}
46-
Balances::resolve(&acc, amount).defensive_ok();
47-
}
48-
}
29+
use xcm_executor::traits::ConvertLocation;
4930

50-
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
51-
52-
fn burn_at_relay(stash: &AccountId, value: Balance) -> Result<(), XcmError> {
53-
let dest = Location::parent();
54-
let stash_location =
55-
Junction::AccountId32 { network: None, id: stash.clone().into() }.into_location();
56-
let asset = Asset { id: AssetId(Location::parent()), fun: Fungible(value) };
57-
let dummy_xcm_context = XcmContext { origin: None, message_id: [0; 32], topic: None };
58-
59-
let withdrawn = AssetTransactor::withdraw_asset(&asset, &stash_location, None)?;
60-
61-
AssetTransactor::can_check_out(&dest, &asset, &dummy_xcm_context)?;
62-
63-
let parent_assets = Into::<Assets>::into(withdrawn)
64-
.reanchored(&dest, &Here.into())
65-
.defensive_map_err(|_| XcmError::ReanchorFailed)?;
66-
67-
PolkadotXcm::send_xcm(
68-
Here,
69-
Location::parent(),
70-
Xcm(vec![
71-
Instruction::UnpaidExecution {
72-
weight_limit: WeightLimit::Unlimited,
73-
check_origin: None,
74-
},
75-
ReceiveTeleportedAsset(parent_assets.clone()),
76-
BurnAsset(parent_assets),
77-
]),
78-
)?;
79-
80-
AssetTransactor::check_out(&dest, &asset, &dummy_xcm_context);
81-
82-
Ok(())
83-
}
31+
/// Coretime revenue handler that sends funds to the DAP satellite account.
32+
///
33+
/// Previously, revenue was accumulated in a stash account and then burned at the relay chain.
34+
/// With DAP, revenue is accumulated in the satellite account and then periodically sent
35+
/// to the DAP buffer on AssetHub via XCM.
36+
pub type CoretimeRevenueToSatellite = pallet_dap_satellite::SlashToSatellite<Runtime>;
8437

8538
/// A type containing the encoding of the coretime pallet in the Relay chain runtime. Used to
8639
/// construct any remote calls. The codec index must correspond to the index of `Coretime` in the
@@ -112,7 +65,6 @@ enum CoretimeProviderCalls {
11265
parameter_types! {
11366
pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
11467
pub const MinimumCreditPurchase: Balance = UNITS / 10;
115-
pub RevenueAccumulationAccount: AccountId = BrokerPalletId::get().into_sub_account_truncating(b"burnstash");
11668
pub const MinimumEndPrice: Balance = UNITS;
11769
}
11870

@@ -287,21 +239,9 @@ impl CoretimeInterface for CoretimeAllocator {
287239
}
288240

289241
fn on_new_timeslice(_timeslice: Timeslice) {
290-
let stash = RevenueAccumulationAccount::get();
291-
let value =
292-
Balances::reducible_balance(&stash, Preservation::Expendable, Fortitude::Polite);
293-
294-
if value > 0 {
295-
tracing::debug!(target: "runtime::coretime", %value, "Going to burn stashed tokens at RC");
296-
match burn_at_relay(&stash, value) {
297-
Ok(()) => {
298-
tracing::debug!(target: "runtime::coretime", %value, "Successfully burnt tokens");
299-
},
300-
Err(err) => {
301-
tracing::error!(target: "runtime::coretime", error=?err, "burn_at_relay failed");
302-
},
303-
}
304-
}
242+
// With DAP satellite, revenue is already accumulated in the satellite account via
243+
// CoretimeRevenueToSatellite (OnRevenue handler). The satellite pallet then sends
244+
// accumulated funds to AssetHub DAP via XCM
305245
}
306246
}
307247

@@ -317,7 +257,7 @@ impl MaybeConvert<TaskId, AccountId> for SovereignAccountOf {
317257
impl pallet_broker::Config for Runtime {
318258
type RuntimeEvent = RuntimeEvent;
319259
type Currency = Balances;
320-
type OnRevenue = BurnCoretimeRevenue;
260+
type OnRevenue = CoretimeRevenueToSatellite;
321261
type TimeslicePeriod = ConstU32<{ coretime::TIMESLICE_PERIOD }>;
322262
// We don't actually need any leases at launch but set to 10 in case we want to sudo some in.
323263
type MaxLeasedCores = ConstU32<10>;

cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ impl pallet_sudo::Config for Runtime {
612612
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
613613
}
614614

615+
impl pallet_dap_satellite::Config for Runtime {
616+
type Currency = Balances;
617+
}
618+
615619
pub struct BrokerMigrationV4BlockConversion;
616620

617621
impl pallet_broker::migration::v4::BlockToRelayHeightConversion<Runtime>
@@ -667,6 +671,9 @@ construct_runtime!(
667671
// The main stage.
668672
Broker: pallet_broker = 50,
669673

674+
// DAP Satellite - collects funds for eventual transfer to DAP on AssetHub
675+
DapSatellite: pallet_dap_satellite = 60,
676+
670677
// Sudo
671678
Sudo: pallet_sudo = 100,
672679
}

prdoc/pr_10481.prdoc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
title: '[DRAFT] PoC DAP'
1+
title: 'Introduced pallet-dap'
22
doc:
33
- audience: Runtime Dev
44
description: |-
55
Initial PoC PR to play around with Dynamic Allocation Proposal here: https://hackmd.io/a0KSL4XHQ1WvcGZlKykGzg
66

7-
So far, I am just currently removing treasury burn and staking slashing, redirecting them to the DAP / issuance buffer.
7+
Initial version supports the following:
8+
- Introduced FundingSink and FundingSource traits in frame-support
9+
- Introduced pallet-dap with minimal implementation of FundingSink trait only. This pallet is meant to be
10+
deployed on AssetHub as the central DAP pallet.
11+
- Redirected treasury unspent to pallet-dap instead of burning
12+
- Redirected staking slashes to pallet-dap instead of burning
13+
- Introduced pallet-dap-satellite, to collect funds that otherwise would be burned (e.g. tx fees,
14+
coretime revenues, ...) into a local satellite account. These funds are accumulated locally and
15+
will be sent to pallet-dap periodically in future iterations. This pallet is meant to be deployed
16+
on system chains like Coretime, People and BridheHub and on the RelayChain. It should not be deployed
17+
on AssetHub, which hosts the central DAP pallet.
18+
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.
821
crates:
922
- name: frame-support
1023
bump: major
1124
- name: pallet-dap
1225
bump: major
26+
- name: pallet-dap-satellite
27+
bump: major
1328
- name: asset-hub-westend-runtime
1429
bump: major
1530
- name: pallet-staking-async
1631
bump: major
32+
- name: coretime-westend-runtime
33+
bump: major
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[package]
2+
name = "pallet-dap-satellite"
3+
version = "0.1.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
license = "Apache-2.0"
7+
homepage.workspace = true
8+
repository.workspace = true
9+
description = "FRAME pallet for DAP Satellite - collects funds for periodic transfer to DAP on AssetHub"
10+
11+
[lints]
12+
workspace = true
13+
14+
[package.metadata.docs.rs]
15+
targets = ["x86_64-unknown-linux-gnu"]
16+
17+
[dependencies]
18+
codec = { features = ["derive", "max-encoded-len"], workspace = true }
19+
frame-benchmarking = { optional = true, workspace = true }
20+
frame-support = { workspace = true }
21+
frame-system = { workspace = true }
22+
log = { workspace = true }
23+
scale-info = { features = ["derive"], workspace = true }
24+
sp-runtime = { workspace = true }
25+
26+
[dev-dependencies]
27+
pallet-balances = { workspace = true, default-features = true }
28+
pallet-dap = { workspace = true, default-features = true }
29+
sp-core = { workspace = true, default-features = true }
30+
sp-io = { workspace = true, default-features = true }
31+
32+
[features]
33+
default = ["std"]
34+
std = [
35+
"codec/std",
36+
"frame-benchmarking?/std",
37+
"frame-support/std",
38+
"frame-system/std",
39+
"log/std",
40+
"pallet-balances/std",
41+
"scale-info/std",
42+
"sp-core/std",
43+
"sp-io/std",
44+
"sp-runtime/std",
45+
]
46+
runtime-benchmarks = [
47+
"frame-benchmarking/runtime-benchmarks",
48+
"frame-support/runtime-benchmarks",
49+
"frame-system/runtime-benchmarks",
50+
"pallet-balances/runtime-benchmarks",
51+
"pallet-dap/runtime-benchmarks",
52+
"sp-runtime/runtime-benchmarks",
53+
]
54+
try-runtime = [
55+
"frame-support/try-runtime",
56+
"frame-system/try-runtime",
57+
"pallet-balances/try-runtime",
58+
"pallet-dap/try-runtime",
59+
"sp-runtime/try-runtime",
60+
]

0 commit comments

Comments
 (0)