mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 20:35:41 +00:00
Don't allow bids for a ParaId where there is an overlapping lease period (#3361)
* add already leased Co-Authored-By: parity-processbot <> * add unit test Co-Authored-By: parity-processbot <> * add integration test and fix Co-Authored-By: parity-processbot <> * better doc Co-Authored-By: parity-processbot <> * Update runtime/common/src/slots.rs * Update runtime/common/src/slots.rs * Apply suggestions from code review Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update runtime/common/src/integration_tests.rs * Update runtime/common/src/integration_tests.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::auctions --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_auctions.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::auctions --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_auctions.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::crowdloan --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_crowdloan.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_common::auctions --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_common_auctions.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_common::crowdloan --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_common_crowdloan.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::slots --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_slots.rs * cargo run --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_common::slots --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_common_slots.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
//! must handled by a separately, through the trait interface that this pallet provides or the root dispatchables.
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::traits::{CheckedSub, Zero, CheckedConversion};
|
||||
use sp_runtime::traits::{CheckedSub, Zero, CheckedConversion, Saturating};
|
||||
use frame_support::{
|
||||
decl_module, decl_storage, decl_event, decl_error, dispatch::DispatchResult,
|
||||
traits::{Currency, ReservableCurrency, Get}, weights::Weight,
|
||||
@@ -421,6 +421,41 @@ impl<T: Config> Leaser for Module<T> {
|
||||
fn lease_period_index() -> Self::LeasePeriod {
|
||||
<frame_system::Pallet<T>>::block_number() / T::LeasePeriod::get()
|
||||
}
|
||||
|
||||
fn already_leased(
|
||||
para_id: ParaId,
|
||||
first_period: Self::LeasePeriod,
|
||||
last_period: Self::LeasePeriod,
|
||||
) -> bool {
|
||||
let current_lease_period = Self::lease_period_index();
|
||||
|
||||
// Can't look in the past, so we pick whichever is the biggest.
|
||||
let start_period = first_period.max(current_lease_period);
|
||||
// Find the offset to look into the lease period list.
|
||||
// Subtraction is safe because of max above.
|
||||
let offset = match (start_period - current_lease_period).checked_into::<usize>() {
|
||||
Some(offset) => offset,
|
||||
None => return true,
|
||||
};
|
||||
|
||||
// This calculates how deep we should look in the vec for a potential lease.
|
||||
let period_count = match last_period.saturating_sub(start_period).checked_into::<usize>() {
|
||||
Some(period_count) => period_count,
|
||||
None => return true,
|
||||
};
|
||||
|
||||
// Get the leases, and check each item in the vec which is part of the range we are checking.
|
||||
let leases = Leases::<T>::get(para_id);
|
||||
for slot in offset ..= offset + period_count {
|
||||
if let Some(Some(_)) = leases.get(slot) {
|
||||
// If there exists any lease period, we exit early and return true.
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here, then we did not find any overlapping leases.
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user