Skip to content
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

Coretime: Add request revenue info #3940

Merged
merged 128 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
aabcb4b
Start implementing request revenue info
antonva Mar 20, 2024
d8df101
Add revenue tracking to on demand pallet
antonva Mar 20, 2024
8f7c179
Add revenue call to broker pallet
antonva Apr 2, 2024
54e0326
Partial impl of revenue from relay chain
antonva Apr 2, 2024
d8bfb72
Move xcm sending from ondemand to coretime pallet
antonva Apr 4, 2024
f3dfe44
Move ondemand types into separate module
antonva Apr 4, 2024
4f1a44d
Add pallet id to on demand
antonva Apr 4, 2024
ef1174b
Fix tests for on demand
antonva Apr 4, 2024
21f9657
Rework get_revenue
antonva Apr 4, 2024
4d00c85
Add empty weight implementations
antonva Apr 4, 2024
8251ede
Add revenueinbox for broker pallet
antonva Apr 4, 2024
af93286
Merge branch 'master' into ava-request-revenue-info
antonva Apr 5, 2024
7dd6a34
Add log target to coretime pallet
antonva Apr 17, 2024
d5d84e3
Fix coretime benchmarking
antonva Apr 17, 2024
aecc034
Remove check notify revenue info
antonva Apr 19, 2024
1f9a4de
Update broker pallet for revenue info
antonva Apr 19, 2024
6879dd7
Remove negative imbalance shorthand
antonva Apr 19, 2024
7a1f198
Update revenue info calls
antonva Apr 19, 2024
c7d586d
Remove unused imports
antonva Apr 19, 2024
74c88b1
Fix benchmarks
antonva Apr 19, 2024
ff69a3d
Merge branch 'master' into ava-request-revenue-info
antonva Apr 19, 2024
aa137da
Fix tests
antonva Apr 19, 2024
f255e47
Update revenue_until fn
antonva Apr 23, 2024
a6be112
Remove unused imports
antonva Apr 26, 2024
f8da2cd
Adress minor discussions
s0me0ne-unkn0wn May 25, 2024
0e99692
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn May 25, 2024
2e0e3ef
Fix revenue calculation
s0me0ne-unkn0wn May 25, 2024
0f6a2ba
Propose different implementation of revenue reporting
s0me0ne-unkn0wn May 26, 2024
af899e2
Minor fix
s0me0ne-unkn0wn May 26, 2024
f1b9000
Rename call
s0me0ne-unkn0wn May 26, 2024
dd8ed91
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn May 29, 2024
65af55c
Fix weights
s0me0ne-unkn0wn May 29, 2024
84151b1
Move constants
s0me0ne-unkn0wn May 29, 2024
6df281b
Improve error handling
s0me0ne-unkn0wn May 29, 2024
8f482fe
Fix and improve test
s0me0ne-unkn0wn May 29, 2024
724b7a5
Fix benchmarking code
s0me0ne-unkn0wn May 30, 2024
00fd411
Add benchmark
s0me0ne-unkn0wn May 30, 2024
d5d668b
Minor fixes
s0me0ne-unkn0wn May 30, 2024
36d9cef
Fix clippy
s0me0ne-unkn0wn May 30, 2024
cd559af
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn May 30, 2024
fac55b0
Fix broker benchmark
s0me0ne-unkn0wn May 30, 2024
3f8482a
Fix mock impl
s0me0ne-unkn0wn May 31, 2024
338316e
Fix tests
s0me0ne-unkn0wn May 31, 2024
bf4ed2e
Improve revenue collection implementation
s0me0ne-unkn0wn May 31, 2024
d8b4ad1
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 31, 2024
14e4bc2
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 31, 2024
3130df8
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 31, 2024
d90b4cb
Accumulate overdue revenue instead of burning it
s0me0ne-unkn0wn May 31, 2024
93f98d6
Merge remote-tracking branch 'origin/ava-request-revenue-info' into a…
s0me0ne-unkn0wn May 31, 2024
f52bf9b
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn May 31, 2024
8744d5d
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 31, 2024
884c077
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 31, 2024
db2bb27
Add missing benchmark
s0me0ne-unkn0wn May 31, 2024
42914c5
Merge remote-tracking branch 'origin/ava-request-revenue-info' into a…
s0me0ne-unkn0wn May 31, 2024
7dd59f6
Add stub weights
s0me0ne-unkn0wn May 31, 2024
b794eec
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 31, 2024
3d67f5d
Sort out weights mess
s0me0ne-unkn0wn Jun 1, 2024
f6c23cc
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 1, 2024
c3468bb
Add prdoc
s0me0ne-unkn0wn Jun 1, 2024
1b60cbf
Fix prdoc
s0me0ne-unkn0wn Jun 1, 2024
832ee90
Add constant docs
s0me0ne-unkn0wn Jun 1, 2024
ddd9f1e
Properly propagate `fast-runtime` feature
s0me0ne-unkn0wn Jun 4, 2024
d59f8ec
Implement parachain-side end of revenue teleport
s0me0ne-unkn0wn Jun 4, 2024
3fb3f6a
Fix test values and add explanation
s0me0ne-unkn0wn Jun 4, 2024
4be7536
Address discussions
s0me0ne-unkn0wn Jun 5, 2024
250e480
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 5, 2024
7eca0a0
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 5, 2024
50916c9
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jun 5, 2024
7de6355
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 5, 2024
bcfcf64
Add logs and simplify tests
s0me0ne-unkn0wn Jun 5, 2024
cd3b769
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn Jun 5, 2024
70e511f
Add comments addressing commented out code
s0me0ne-unkn0wn Jun 6, 2024
76cff00
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 8, 2024
1d1e53d
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn Jun 12, 2024
21638bb
Fix semver bumps
s0me0ne-unkn0wn Jun 12, 2024
9ace334
Apply suggestions from code review
s0me0ne-unkn0wn Jun 13, 2024
c263b19
Restore the coretime interface and re-implement revenue inbox using it
s0me0ne-unkn0wn Jun 13, 2024
544e558
Address discussions and clippy complains
s0me0ne-unkn0wn Jun 13, 2024
057d356
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 14, 2024
83c6a86
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 14, 2024
e21be97
Draft teleport implementation
s0me0ne-unkn0wn Jun 17, 2024
e447bbd
Fixes
s0me0ne-unkn0wn Jun 18, 2024
447fd89
Make transactional; Clean up
s0me0ne-unkn0wn Jun 18, 2024
8235de4
Draft the backward teleport
s0me0ne-unkn0wn Jun 18, 2024
1f7842c
Fix teleports, format, clean up
s0me0ne-unkn0wn Jun 19, 2024
a24d410
Revert debug
s0me0ne-unkn0wn Jun 19, 2024
75a6c7f
Batch asset burns
s0me0ne-unkn0wn Jun 21, 2024
5138f8b
Address minor discussions
s0me0ne-unkn0wn Jun 24, 2024
763f68a
Bump `fast-runtime` timeslice to 20 blocks
s0me0ne-unkn0wn Jun 24, 2024
2f9f41d
Merge remote-tracking branch 'origin/master' into ava-request-revenue…
s0me0ne-unkn0wn Jun 24, 2024
201637a
Update Cargo.lock
s0me0ne-unkn0wn Jun 24, 2024
38bd4cc
Fix tests
s0me0ne-unkn0wn Jun 24, 2024
d899c9e
Fix node template
s0me0ne-unkn0wn Jun 24, 2024
44e9ed4
Fix and improve benchmarks
s0me0ne-unkn0wn Jun 24, 2024
9cc55c1
Fix pallet tests
s0me0ne-unkn0wn Jun 25, 2024
5b8638a
Fix benchmark test
s0me0ne-unkn0wn Jun 25, 2024
b45ccda
Fix revenue benchmark
s0me0ne-unkn0wn Jun 25, 2024
c808679
Fix benchmark
s0me0ne-unkn0wn Jun 25, 2024
737990f
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 25, 2024
eb4a21c
Apply suggestions from code review
s0me0ne-unkn0wn Jun 25, 2024
2b0558a
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 25, 2024
3d19187
Address discussions; Minor fixes
s0me0ne-unkn0wn Jun 25, 2024
3decbf3
Make burn stash survive burn cycles
s0me0ne-unkn0wn Jun 25, 2024
223039c
Fix credit-related test... Again
s0me0ne-unkn0wn Jun 25, 2024
1d97bdc
Add docstring
s0me0ne-unkn0wn Jun 25, 2024
0d01a6f
Rename parameter
s0me0ne-unkn0wn Jun 25, 2024
4d49eab
Get rid of transactions
s0me0ne-unkn0wn Jun 25, 2024
512d7ba
Move `OnNewTimeslice` to `CoretimeInterface`
s0me0ne-unkn0wn Jun 25, 2024
44881bc
Remove unused imports
s0me0ne-unkn0wn Jun 25, 2024
1bf474c
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 25, 2024
298d7c6
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 25, 2024
7f51df9
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 25, 2024
87cc279
Remove unneeded trait
s0me0ne-unkn0wn Jun 26, 2024
74e341e
Fix naming
s0me0ne-unkn0wn Jun 26, 2024
7ddd961
Remove redundant interfaces
s0me0ne-unkn0wn Jun 26, 2024
3662e34
Merge remote-tracking branch 'origin/ava-request-revenue-info' into a…
s0me0ne-unkn0wn Jun 26, 2024
a40e811
Add account preservation
s0me0ne-unkn0wn Jun 26, 2024
27615d5
Fix unused imports
s0me0ne-unkn0wn Jun 26, 2024
1c0d41c
More clippy fixes
s0me0ne-unkn0wn Jun 26, 2024
3ff9e6b
Optimize revenue collection loop
s0me0ne-unkn0wn Jun 26, 2024
4de04c1
Make broker pot pallet-provided
s0me0ne-unkn0wn Jun 26, 2024
c0d95a4
Merge remote-tracking branch 'origin/ava-request-revenue-info' into a…
s0me0ne-unkn0wn Jun 26, 2024
8ba0e7e
Rename things, minor fixes
s0me0ne-unkn0wn Jun 26, 2024
2dd05de
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 26, 2024
6330fe1
Fix tests
s0me0ne-unkn0wn Jun 26, 2024
8667d4a
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 26, 2024
ce47be7
Revert erroneous changes
s0me0ne-unkn0wn Jun 26, 2024
59efed2
Merge branch 'master' into ava-request-revenue-info
s0me0ne-unkn0wn Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,6 @@ try-runtime = [
"sp-runtime/try-runtime",
]

fast-runtime = []
fast-runtime = [
"rococo-runtime-constants/fast-runtime",
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,65 @@ use cumulus_primitives_core::relay_chain;
use frame_support::{
parameter_types,
traits::{
fungible::{Balanced, Credit},
OnUnbalanced,
fungible::{Balanced, Credit, Inspect},
tokens::{Fortitude, Preservation},
DefensiveResult, OnUnbalanced,
},
};
use frame_system::Pallet as System;
use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf};
use parachains_common::{AccountId, Balance, BlockNumber};
use parachains_common::{AccountId, Balance};
use rococo_runtime_constants::system_parachain::coretime;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_executor::traits::TransactAsset;

pub struct CreditToCollatorPot;
impl OnUnbalanced<Credit<AccountId, Balances>> for CreditToCollatorPot {
fn on_nonzero_unbalanced(credit: Credit<AccountId, Balances>) {
let staking_pot = CollatorSelection::account_id();
let _ = <Balances as Balanced<_>>::resolve(&staking_pot, credit);
pub struct StashToBurn;
impl OnUnbalanced<Credit<AccountId, Balances>> for StashToBurn {
fn on_nonzero_unbalanced(amount: Credit<AccountId, Balances>) {
let acc = BurnStashAccount::get();
if !System::<Runtime>::account_exists(&acc) {
System::<Runtime>::inc_providers(&acc);
}
Balances::resolve(&acc, amount).defensive_ok();
}
}

type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;

fn burn_at_relay(stash: &AccountId, value: Balance) -> Result<(), XcmError> {
let dest = Location::parent();
let stash_location =
Junction::AccountId32 { network: None, id: stash.clone().into() }.into_location();
let asset = Asset { id: AssetId(Location::parent()), fun: Fungible(value) };
let dummy_xcm_context = XcmContext { origin: None, message_id: [0; 32], topic: None };

let withdrawn = AssetTransactor::withdraw_asset(&asset, &stash_location, None)?;

AssetTransactor::can_check_out(&dest, &asset, &dummy_xcm_context)?;

let parent_assets = Into::<Assets>::into(withdrawn)
.reanchored(&dest, &Here.into())
.defensive_map_err(|_| XcmError::ReanchorFailed)?;

PolkadotXcm::send_xcm(
Here,
Location::parent(),
Xcm(vec![
Instruction::UnpaidExecution {
weight_limit: WeightLimit::Unlimited,
check_origin: None,
},
ReceiveTeleportedAsset(parent_assets.clone()),
BurnAsset(parent_assets),
]),
)?;

AssetTransactor::check_out(&dest, &asset, &dummy_xcm_context);

Ok(())
}

/// A type containing the encoding of the coretime pallet in the Relay chain runtime. Used to
/// construct any remote calls. The codec index must correspond to the index of `Coretime` in the
/// `construct_runtime` of the Relay chain.
Expand Down Expand Up @@ -66,11 +109,7 @@ enum CoretimeProviderCalls {

parameter_types! {
pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
}

parameter_types! {
pub storage CoreCount: Option<CoreIndex> = None;
pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None;
pub BurnStashAccount: AccountId = BrokerPalletId::get().into_sub_account_truncating(b"burnstash");
s0me0ne-unkn0wn marked this conversation as resolved.
Show resolved Hide resolved
}

/// Type that implements the `CoretimeInterface` for the allocation of Coretime. Meant to operate
Expand Down Expand Up @@ -205,26 +244,30 @@ impl CoretimeInterface for CoretimeAllocator {
}
}

fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)> {
let revenue = CoretimeRevenue::get();
CoretimeRevenue::set(&None);
revenue
}
fn on_new_timeslice(_t: pallet_broker::Timeslice) {
let stash = BurnStashAccount::get();
let value =
Balances::reducible_balance(&stash, Preservation::Expendable, Fortitude::Polite);
Comment on lines +249 to +250
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably just take all of it, but not that important here for the test chain.


#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_revenue_info(when: RCBlockNumberOf<Self>, revenue: Self::Balance) {
CoretimeRevenue::set(&Some((when, revenue)));
if value > 0 {
log::debug!(target: "runtime::coretime", "Going to burn {value} stashed tokens at RC");
match burn_at_relay(&stash, value) {
Ok(()) => {
log::debug!(target: "runtime::coretime", "Succesfully burnt {value} tokens");
},
Err(err) => {
log::error!(target: "runtime::coretime", "burn_at_relay failed: {err:?}");
},
}
}
}
}

impl pallet_broker::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type OnRevenue = CreditToCollatorPot;
#[cfg(feature = "fast-runtime")]
type TimeslicePeriod = ConstU32<10>;
#[cfg(not(feature = "fast-runtime"))]
type TimeslicePeriod = ConstU32<80>;
type OnRevenue = StashToBurn;
type TimeslicePeriod = ConstU32<{ coretime::TIMESLICE_PERIOD }>;
type MaxLeasedCores = ConstU32<50>;
type MaxReservedCores = ConstU32<10>;
type Coretime = CoretimeAllocator;
Expand Down
Loading
Loading