mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Add Auctions and Crowdloans to Kusama and Westend (#2999)
* add to westend * fixes * fix runtime tests * add to kusama * 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 * fix auctions benchmarks * add benchmark to kusama * update weights * 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=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 * update to use weights * 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 * Initiate auctions with 2/3 council * add check and docs * update crowdloan deposits * move tests * move other tests * update ending period * 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 * fix origin * 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 Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The Polkadot runtime. This can be compiled with `#[no_std]`, ready for Wasm.
|
||||
//! The Kusama runtime. This can be compiled with `#[no_std]`, ready for Wasm.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||
@@ -32,7 +32,8 @@ use primitives::v1::{
|
||||
InboundDownwardMessage, InboundHrmpMessage, SessionInfo,
|
||||
};
|
||||
use runtime_common::{
|
||||
claims, SlowAdjustingFeeUpdate, CurrencyToVote, paras_registrar, xcm_sender, slots, impls::DealWithFees,
|
||||
claims, paras_registrar, xcm_sender, slots, auctions, crowdloan,
|
||||
SlowAdjustingFeeUpdate, CurrencyToVote, impls::DealWithFees,
|
||||
BlockHashCount, RocksDbWeight, BlockWeights, BlockLength, OffchainSolutionWeightLimit, OffchainSolutionLengthLimit,
|
||||
ToAuthor,
|
||||
};
|
||||
@@ -426,8 +427,9 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
|
||||
_total_issuance: Balance,
|
||||
era_duration_millis: u64,
|
||||
) -> (Balance, Balance) {
|
||||
// TODO: #2999 Update with Auctions logic when auctions pallet added.
|
||||
const AUCTIONED_SLOTS: u64 = 0;
|
||||
// TODO: #3011 Update with proper auctioned slots tracking.
|
||||
// This should be fine for the first year of parachains.
|
||||
let auctioned_slots: u64 = auctions::Pallet::<Runtime>::auction_counter().into();
|
||||
const MAX_ANNUAL_INFLATION: Perquintill = Perquintill::from_percent(10);
|
||||
const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100;
|
||||
|
||||
@@ -436,7 +438,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
|
||||
Gilt::issuance().non_gilt,
|
||||
MAX_ANNUAL_INFLATION,
|
||||
Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR),
|
||||
AUCTIONED_SLOTS,
|
||||
auctioned_slots,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1106,6 +1108,52 @@ impl slots::Config for Runtime {
|
||||
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const CrowdloanId: PalletId = PalletId(*b"py/cfund");
|
||||
pub const SubmissionDeposit: Balance = 3 * GRAND; // ~ 10 KSM
|
||||
pub const MinContribution: Balance = 3_000 * CENTS; // ~ .1 KSM
|
||||
pub const RemoveKeysLimit: u32 = 1000;
|
||||
// Allow 32 bytes for an additional memo to a crowdloan.
|
||||
pub const MaxMemoLength: u8 = 32;
|
||||
}
|
||||
|
||||
impl crowdloan::Config for Runtime {
|
||||
type Event = Event;
|
||||
type PalletId = CrowdloanId;
|
||||
type SubmissionDeposit = SubmissionDeposit;
|
||||
type MinContribution = MinContribution;
|
||||
type RemoveKeysLimit = RemoveKeysLimit;
|
||||
type Registrar = Registrar;
|
||||
type Auctioneer = Auctions;
|
||||
type MaxMemoLength = MaxMemoLength;
|
||||
type WeightInfo = weights::runtime_common_crowdloan::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
// The average auction is 7 days long, so this will be 70% for ending period.
|
||||
// 5 Days = 72000 Blocks @ 6 sec per block
|
||||
pub const EndingPeriod: BlockNumber = 5 * DAYS;
|
||||
// ~ 1000 samples per day -> ~ 20 blocks per sample -> 2 minute samples
|
||||
pub const SampleLength: BlockNumber = 2 * MINUTES;
|
||||
}
|
||||
|
||||
type AuctionInitiate = EnsureOneOf<
|
||||
AccountId,
|
||||
EnsureRoot<AccountId>,
|
||||
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>
|
||||
>;
|
||||
|
||||
impl auctions::Config for Runtime {
|
||||
type Event = Event;
|
||||
type Leaser = Slots;
|
||||
type Registrar = Registrar;
|
||||
type EndingPeriod = EndingPeriod;
|
||||
type SampleLength = SampleLength;
|
||||
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
|
||||
type InitiateOrigin = AuctionInitiate;
|
||||
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
/// The location of the KSM token, from the context of this chain. Since this token is native to this
|
||||
/// chain, we make it synonymous with it and thus it is the `Null` location, which means "equivalent to
|
||||
@@ -1389,6 +1437,8 @@ construct_runtime! {
|
||||
// Parachain Onboarding Pallets. Start indices at 70 to leave room.
|
||||
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>} = 70,
|
||||
Slots: slots::{Pallet, Call, Storage, Event<T>} = 71,
|
||||
Auctions: auctions::{Pallet, Call, Storage, Event<T>} = 72,
|
||||
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>} = 73,
|
||||
|
||||
// Pallet for sending XCM.
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>} = 99,
|
||||
@@ -1811,6 +1861,8 @@ sp_api::impl_runtime_apis! {
|
||||
// Polkadot
|
||||
// NOTE: Make sure to prefix these `runtime_common::` so that path resolves correctly
|
||||
// in the generated file.
|
||||
add_benchmark!(params, batches, runtime_common::auctions, Auctions);
|
||||
add_benchmark!(params, batches, runtime_common::crowdloan, Crowdloan);
|
||||
add_benchmark!(params, batches, runtime_common::claims, Claims);
|
||||
add_benchmark!(params, batches, runtime_common::slots, Slots);
|
||||
add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar);
|
||||
@@ -1844,103 +1896,3 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_fees {
|
||||
use super::*;
|
||||
use frame_support::weights::WeightToFeePolynomial;
|
||||
use frame_support::storage::StorageValue;
|
||||
use sp_runtime::FixedPointNumber;
|
||||
use frame_support::weights::GetDispatchInfo;
|
||||
use parity_scale_codec::Encode;
|
||||
use pallet_transaction_payment::Multiplier;
|
||||
use separator::Separatable;
|
||||
|
||||
#[test]
|
||||
fn payout_weight_portion() {
|
||||
use pallet_staking::WeightInfo;
|
||||
let payout_weight =
|
||||
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
|
||||
MaxNominatorRewardedPerValidator::get(),
|
||||
) as f64;
|
||||
let block_weight = BlockWeights::get().max_block as f64;
|
||||
|
||||
println!(
|
||||
"a full payout takes {:.2} of the block weight [{} / {}]",
|
||||
payout_weight / block_weight,
|
||||
payout_weight,
|
||||
block_weight
|
||||
);
|
||||
assert!(payout_weight * 2f64 < block_weight);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn block_cost() {
|
||||
let max_block_weight = BlockWeights::get().max_block;
|
||||
let raw_fee = WeightToFee::calc(&max_block_weight);
|
||||
|
||||
println!(
|
||||
"Full Block weight == {} // WeightToFee(full_block) == {} plank",
|
||||
max_block_weight,
|
||||
raw_fee.separated_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn transfer_cost_min_multiplier() {
|
||||
let min_multiplier = runtime_common::MinimumMultiplier::get();
|
||||
let call = <pallet_balances::Call<Runtime>>::transfer_keep_alive(Default::default(), Default::default());
|
||||
let info = call.get_dispatch_info();
|
||||
// convert to outer call.
|
||||
let call = Call::Balances(call);
|
||||
let len = call.using_encoded(|e| e.len()) as u32;
|
||||
|
||||
let mut ext = sp_io::TestExternalities::new_empty();
|
||||
let mut test_with_multiplier = |m| {
|
||||
ext.execute_with(|| {
|
||||
pallet_transaction_payment::NextFeeMultiplier::put(m);
|
||||
let fee = TransactionPayment::compute_fee(len, &info, 0);
|
||||
println!(
|
||||
"weight = {:?} // multiplier = {:?} // full transfer fee = {:?}",
|
||||
info.weight.separated_string(),
|
||||
pallet_transaction_payment::NextFeeMultiplier::get(),
|
||||
fee.separated_string(),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
test_with_multiplier(min_multiplier);
|
||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1u128));
|
||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000u128));
|
||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000u128));
|
||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000_000u128));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nominator_limit() {
|
||||
use pallet_election_provider_multi_phase::WeightInfo;
|
||||
// starting point of the nominators.
|
||||
let all_voters: u32 = 10_000;
|
||||
|
||||
// assuming we want around 5k candidates and 1k active validators.
|
||||
let all_targets: u32 = 5_000;
|
||||
let desired: u32 = 1_000;
|
||||
let weight_with = |active| {
|
||||
<Runtime as pallet_election_provider_multi_phase::Config>::WeightInfo::submit_unsigned(
|
||||
all_voters.max(active),
|
||||
all_targets,
|
||||
active,
|
||||
desired,
|
||||
)
|
||||
};
|
||||
|
||||
let mut active = 1;
|
||||
while weight_with(active) <= OffchainSolutionWeightLimit::get() || active == all_voters {
|
||||
active += 1;
|
||||
}
|
||||
|
||||
println!("can support {} nominators to yield a weight of {}", active, weight_with(active));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user