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 auto-renew #4424

Merged
merged 53 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
afb5e75
start
Szegoo May 4, 2024
2716e0f
setup
Szegoo May 8, 2024
e443c9e
outlining the main logic
Szegoo May 9, 2024
2a8a68b
bounded vec
Szegoo May 10, 2024
8df2f81
resolvinig some todos
Szegoo May 11, 2024
82859ad
auto-renew for legacy leases
Szegoo May 11, 2024
e2a4dd5
init test
Szegoo May 11, 2024
9c1c7e3
more tests
Szegoo May 12, 2024
c7ccf5a
enable_auto_renew_renews
Szegoo May 12, 2024
c3eaa21
different approach
Szegoo May 12, 2024
edffbfc
docs
Szegoo May 13, 2024
68f244c
enable_auto_renewal_with_end_hint_works
Szegoo May 13, 2024
893fa9d
auto_renewal_works
Szegoo May 15, 2024
0b50a58
progress
Szegoo May 15, 2024
9dc9b6a
store account instead of task
Szegoo May 15, 2024
9baa77a
fix builds
Szegoo May 15, 2024
ee7e3c4
disable auto-renewal
Szegoo May 17, 2024
e0f1c71
disable auto renew test
Szegoo May 17, 2024
1a46abc
docs
Szegoo May 17, 2024
2f17544
account for changing core indices
Szegoo May 23, 2024
63b6f66
fix
Szegoo May 23, 2024
aaba50d
bench enable_auto_renew
Szegoo May 23, 2024
7d682e6
bench disable & auto_renew
Szegoo May 23, 2024
af8f109
weights
Szegoo May 23, 2024
f22c451
fix
Szegoo May 23, 2024
a6c0676
dummy weights
Szegoo May 23, 2024
a4f3b6c
don't auto renew when not needed
Szegoo May 24, 2024
4f18949
fix auto renewal
Szegoo May 24, 2024
5d29cd3
more checks
Szegoo May 24, 2024
0d9e91d
test fixes/improvements
Szegoo May 27, 2024
dad2b91
merge
Szegoo May 30, 2024
88c9ce1
merge fix
Szegoo May 30, 2024
17e0ee5
cleanup | benchmarks: TODO
Szegoo May 30, 2024
8be2d02
Update substrate/frame/broker/src/dispatchable_impls.rs
Szegoo May 31, 2024
c8fa5f8
Update substrate/frame/broker/src/types.rs
Szegoo May 31, 2024
7d887ab
Update substrate/frame/broker/src/lib.rs
Szegoo May 31, 2024
78a203f
resolve comments
Szegoo May 31, 2024
5f02e32
cleanup
Szegoo May 31, 2024
b0aa972
rename
Szegoo May 31, 2024
de89f30
comment
Szegoo May 31, 2024
7259f41
fix benchmarks
Szegoo May 31, 2024
9a23b2f
cleanup
Szegoo Jun 3, 2024
0c4e651
simplify logic
Szegoo Jun 3, 2024
ef9c4fb
fix benchmarks
Szegoo Jul 1, 2024
4d35d2b
Merge branch 'master' into auto-renew
Szegoo Jul 1, 2024
15d9e1b
merge fixes
Szegoo Jul 1, 2024
eff4ee7
benchmark fix
Szegoo Jul 1, 2024
61f466d
resolve conflicts
Szegoo Jul 30, 2024
d2041f1
prdoc
Szegoo Jul 30, 2024
7155233
improve docs
Szegoo Jul 30, 2024
9a90fbd
improve comments
Szegoo Aug 1, 2024
0cf0dad
Merge branch 'master' into auto-renew
Szegoo Aug 1, 2024
c1fc125
Merge branch 'master' into auto-renew
Szegoo Aug 3, 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
Prev Previous commit
Next Next commit
Merge branch 'master' into auto-renew
  • Loading branch information
Szegoo authored Jul 1, 2024
commit 4d35d2b5fc298c307b2ecc1b5d2ad7c5acf3d5df
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ use frame_support::{
DefensiveResult, OnUnbalanced,
},
};
use pallet_broker::{
CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId,
};
use parachains_common::{AccountId, Balance, BlockNumber};
use sp_runtime::traits::MaybeConvert;
use frame_system::Pallet as System;
use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId};
use parachains_common::{AccountId, Balance};
use rococo_runtime_constants::system_parachain::coretime;
use sp_runtime::traits::{AccountIdConversion, MaybeConvert};
use xcm::latest::prelude::*;
use xcm_executor::traits::ConvertLocation;
use xcm_executor::traits::{ConvertLocation, TransactAsset};

pub struct BurnCoretimeRevenue;
impl OnUnbalanced<Credit<AccountId, Balances>> for BurnCoretimeRevenue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,5 +586,27 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
Weight::from_parts(10_400_000, 1516)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
/// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1)
/// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0)
/// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0)
/// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1)
/// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn on_new_timeslice() -> Weight {
// Proof Size summary in bytes:
// Measured: `322`
// Estimated: `3787`
// Minimum execution time: 45_561_000 picoseconds.
Weight::from_parts(47_306_000, 0)
.saturating_add(Weight::from_parts(0, 3787))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ use frame_support::{
DefensiveResult, OnUnbalanced,
},
};
use frame_system::Pallet as System;
use pallet_broker::{
CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId,
CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId, Timeslice,
};
use parachains_common::{AccountId, Balance, BlockNumber};
use sp_runtime::traits::MaybeConvert;
use parachains_common::{AccountId, Balance};
use sp_runtime::traits::{AccountIdConversion, MaybeConvert};
use westend_runtime_constants::system_parachain::coretime;
use xcm::latest::prelude::*;
use xcm_executor::traits::ConvertLocation;
use xcm_executor::traits::{ConvertLocation, TransactAsset};

pub struct BurnCoretimeRevenue;
impl OnUnbalanced<Credit<AccountId, Balances>> for BurnCoretimeRevenue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,5 +586,16 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
Weight::from_parts(10_400_000, 1516)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `System::Account` (r:1 w:0)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn on_new_timeslice() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3593`
// Minimum execution time: 2_187_000 picoseconds.
Weight::from_parts(2_372_000, 0)
.saturating_add(Weight::from_parts(0, 3593))
.saturating_add(T::DbWeight::get().reads(1))
}
}
24 changes: 24 additions & 0 deletions substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,30 @@ mod benches {

assert_last_event::<T>(Event::AutoRenewalDisabled { core: _core, task: 1000 }.into());

Ok(())
}

fn on_new_timeslice() -> Result<(), BenchmarkError> {
setup_and_start_sale::<T>()?;

advance_to::<T>(2);

let caller: T::AccountId = whitelisted_caller();
T::Currency::set_balance(
&caller.clone(),
T::Currency::minimum_balance().saturating_add(u32::MAX.into()),
);

let _region = Broker::<T>::do_purchase(caller.clone(), (u32::MAX / 2).into())
.map_err(|_| BenchmarkError::Weightless)?;

let timeslice = Broker::<T>::current_timeslice();

#[block]
{
T::Coretime::on_new_timeslice(timeslice);
}

Ok(())
}

Expand Down
16 changes: 16 additions & 0 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub mod pallet {
pub type AutoRenewals<T: Config> =
StorageValue<_, BoundedVec<AutoRenewalRecord, T::MaxAutoRenewals>, ValueQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for being a doomer, but isn't this super not scalable? As in, up to N renewals can happen at most, and all of it is on_init, in a single block?

Moreover, if there is congestion (e.g. more than MaxAutoRenewals cores that wanna auto-renew), how do we deal with congestion? The right way to solve this kind of issue is to let user compete via more tx-fees.

I suppose this is still assuming we will only have a maximum of a few dozen cores that want to auto-renew, which is fine, but I think we could have done a bit better.

Copy link
Contributor Author

@Szegoo Szegoo Aug 5, 2024

Choose a reason for hiding this comment

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

You are right; there is an assumption that there is a fairly limited number of cores and also a limited amount that will own an entire core and do auto-renewals. However, what you mentioned is valid, but I don't think this will be an issue until the number of available cores drastically increases.

I am not really sure what you meant by 'let users compete via more tx-fees.'


/// Received revenue info from the relay chain.
#[pallet::storage]
pub type RevenueInbox<T> = StorageValue<_, OnDemandRevenueRecordOf<T>, OptionQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -920,6 +924,18 @@ pub mod pallet {
ensure!(who == sovereign_account, Error::<T>::NoPermission);

Self::do_disable_auto_renew(core, task)?;

Ok(())
}

#[pallet::call_index(20)]
#[pallet::weight(T::WeightInfo::notify_revenue())]
pub fn notify_revenue(
origin: OriginFor<T>,
revenue: OnDemandRevenueRecordOf<T>,
) -> DispatchResult {
T::AdminOrigin::ensure_origin_or_root(origin)?;
Self::do_notify_revenue(revenue)?;
Ok(())
}

Expand Down
41 changes: 13 additions & 28 deletions substrate/frame/broker/src/weights.rs

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

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.