Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0402ecc
Adds try_state to elections pallet
gpestana Mar 27, 2023
af0e6a5
Finishes elections try-state hook; starts EPM hook impl
gpestana Mar 28, 2023
788ddf4
Adds scaffolding for EPM try_state checks
gpestana Mar 28, 2023
b721463
implements checks for EPM
gpestana Mar 30, 2023
3103262
Update frame/election-provider-multi-phase/src/lib.rs
gpestana Apr 20, 2023
6cbf9ab
Update frame/elections-phragmen/src/lib.rs
gpestana Apr 20, 2023
a483470
chore(sc-cli): improve runner and signals (#13688)
yjhmelody Mar 26, 2023
8077b19
add a new ci job to fuzz sp-arithmetic (#13673)
Mar 27, 2023
19e9edc
sc-slots: Forward block size limit (#13716)
bkchr Mar 27, 2023
322d31b
FRAME: Fix the Referenda confirming alarm (#13704)
gavofyork Mar 27, 2023
c04f812
Update pallet licenses to Apache-2.0 (#13467)
aaronbassett Mar 27, 2023
f0bcd0d
Reward pool migration fix (#13715)
Mar 27, 2023
f94fce0
contracts: Add host function tracing (#13648)
pgherveou Mar 27, 2023
67e1cab
Change license of node-template and FRAME examples to MIT-0 (#13465)
aaronbassett Mar 27, 2023
08e037a
updating labels descriptions (#13557)
the-right-joyce Mar 27, 2023
9522b75
CI: Investigate why `RUSTFLAGS` differs on `master` and PRs (#13686)
rcny Mar 28, 2023
998d768
Remove HeaderBackend requirement from AuthorityDiscovery and NetworkW…
skunert Mar 28, 2023
f34444b
CI: rephrase `RUSTFLAGS` (#13735)
rcny Mar 28, 2023
f799177
contracts: proper event link in docs (#13729)
kziemianek Mar 28, 2023
9bc5215
Support stable rust for compiling the runtime (#13580)
bkchr Mar 29, 2023
6618041
provide a default value for RELENG_SCRIPTS_BRANCH (#13743)
Mar 29, 2023
42ee907
roll out new debian 11 ci image (#13744)
Mar 29, 2023
2482f20
Swap 'base58' with 'bs58' (#13739)
davxy Mar 29, 2023
204296a
proc-macro: check for non-args runtime calls added (#13742)
michalkucharczyk Mar 29, 2023
08a35e1
Clean up after debian 11 rollout (#13762)
Mar 29, 2023
17a5d9e
[Fix] Bump tuple element number in frame-support. (#13760)
ruseinov Mar 29, 2023
57dddd2
Generic keystore internals (#13749)
davxy Mar 29, 2023
8929804
Application Crypto cleanup (#13746)
davxy Mar 30, 2023
cb3869d
Attempt to relieve pressure on `mpsc_network_worker` (#13725)
altonen Mar 30, 2023
daf303f
[Enhancement] Throw an error when there are too many pallets (#13763)
ruseinov Mar 30, 2023
6e4e5f5
Build wasm for mvp cpu (#13758)
athei Mar 30, 2023
2fbf914
BEEFY: gossip finality proofs (#13727)
acatangiu Mar 30, 2023
6c1b1ad
Fix nomiantion pools doc render (#13748)
kianenigma Mar 30, 2023
e070908
sp-runtime-interface-test: Fix flaky test (#13770)
bkchr Mar 30, 2023
83d9516
bump zombienet version (#13772)
pepoviola Mar 30, 2023
7756bb1
[Contracts] Overflowing bounded `DeletionQueue` allows DoS against co…
pgherveou Mar 31, 2023
668d61b
Refactor: extract most aura logic out to standalone module, make use …
rphmeier Mar 31, 2023
c9a1ff0
contracts: make test work with debugger (#13776)
pgherveou Mar 31, 2023
19fe15a
add claim_commission weight (#13774)
Apr 1, 2023
76adcec
FRAME: Minor fix for failsafe. (#13741)
gavofyork Apr 1, 2023
81ea064
Adjustments to RPC-query docstrings. (#13698)
DamianStraszak Apr 3, 2023
e1b12eb
Force upgrade snow to 0.9.2 (#13806)
bkchr Apr 3, 2023
a066028
Scheduler pre block limit note (#13231)
muharem Apr 3, 2023
6d38833
Disable `sign-ext` WASM feature when building runtimes (#13804)
koute Apr 3, 2023
71eaef9
refactor: inconsistent BalanceConversion fn (#13610)
wischli Apr 4, 2023
fae245d
Remove deprecated batch verification (#13799)
bkchr Apr 4, 2023
d5ddea6
Uniform pallet warnings (#13798)
ggwpez Apr 4, 2023
cc3f56a
Update documentation for uniques (This PR renames classes and instanc…
simonsso Apr 4, 2023
ee40229
Implement #[pallet::composite_enum] (#13722)
KiChjang Apr 4, 2023
f6f7ced
Expose WASM extensions in executor semantics (#13811)
s0me0ne-unkn0wn Apr 4, 2023
6c45413
Deprecate V1 Weights (#13699)
ggwpez Apr 4, 2023
32f601b
update links to ink! (#13819)
agryaznov Apr 5, 2023
d1e309f
Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension` …
bkchr Apr 5, 2023
5b508e9
Mention `on_idle` round-robin logic to `trait Hooks` cargo doc (#13797)
gpestana Apr 5, 2023
a930258
ProofRecorder: Implement transactional support (#13769)
bkchr Apr 5, 2023
a98e3c2
remove duplicate sync option documentation (#13828)
liamaharon Apr 6, 2023
74c0cf6
Add HoldReason to the NIS pallet (#13823)
KiChjang Apr 6, 2023
3c139bc
Fix `try-runtime follow-chain`, try-runtime upgrade tuple tests, cli …
liamaharon Apr 6, 2023
37479ad
Use proper weights in the `pallet-template` (#13817)
AlexD10S Apr 6, 2023
359d86d
Addresses PR review comments
gpestana Apr 23, 2023
c6633c8
Merge branch 'master' into gpestana/try_state_elections
gpestana Apr 23, 2023
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
[Contracts] Overflowing bounded DeletionQueue allows DoS against co…
…ntract termination (#13702)

* [Contracts review] Overflowing bounded `DeletionQueue` allows DoS against contract termination

* wip

* wip

* wip

* wip

* wip

* fix doc

* wip

* PR review

* unbreak tests

* fixes

* update budget computation

* PR comment: use BlockWeights::get().max_block

* PR comment: Update queue_trie_for_deletion signature

* PR comment: update deletion budget docstring

* PR comment: impl Default with derive(DefaultNoBound)

* PR comment: Remove DeletedContract

* PR comment Add ring_buffer test

* remove missed comment

* misc comments

* contracts: add sr25519_recover

* Revert "contracts: add sr25519_recover"

This reverts commit d4600e0.

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts

* PR comments update print_schedule

* Update frame/contracts/src/benchmarking/mod.rs

* Update frame/contracts/src/storage.rs

* Update frame/contracts/src/storage.rs

* rm temporary fixes

* fix extra ;

* Update frame/contracts/src/storage.rs

Co-authored-by: juangirini <[email protected]>

* Update frame/contracts/src/storage.rs

Co-authored-by: Alexander Theißen <[email protected]>

* Update frame/contracts/src/lib.rs

Co-authored-by: Alexander Theißen <[email protected]>

* Update frame/contracts/src/lib.rs

Co-authored-by: Alexander Theißen <[email protected]>

* Support stable rust for compiling the runtime (#13580)

* Support stable rust for compiling the runtime

This pull request brings support for compiling the runtime with stable Rust. This requires at least
rust 1.68.0 to work on stable. The code is written in a way that it is backwards compatible and
should automatically work when someone compiles with 1.68.0+ stable.

* We always support nightlies!

* 🤦

* Sort by version

* Review feedback

* Review feedback

* Fix version parsing

* Apply suggestions from code review

Co-authored-by: Koute <[email protected]>

---------

Co-authored-by: Koute <[email protected]>

* github PR commit fixes

* Revert "Support stable rust for compiling the runtime (#13580)"

This reverts commit 0b985aa.

* Restore DeletionQueueMap

* fix namings

* PR comment

* move comments

* Update frame/contracts/src/storage.rs

* Update frame/contracts/src/storage.rs

* fixes

---------

Co-authored-by: command-bot <>
Co-authored-by: juangirini <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Koute <[email protected]>
  • Loading branch information
5 people authored and gpestana committed Apr 20, 2023
commit 7756bb18b6f1f17064019215e81fe08fe6f8e0ec
9 changes: 0 additions & 9 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,13 +1198,6 @@ impl pallet_tips::Config for Runtime {
parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerByte: Balance = deposit(0, 1);
pub const DeletionQueueDepth: u32 = 128;
// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = RuntimeBlockWeights::get()
.per_class
.get(DispatchClass::Normal)
.max_total
.unwrap_or(RuntimeBlockWeights::get().max_block);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

Expand All @@ -1227,8 +1220,6 @@ impl pallet_contracts::Config for Runtime {
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type DeletionQueueDepth = DeletionQueueDepth;
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
Expand Down
26 changes: 5 additions & 21 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,7 @@ benchmarks! {
on_initialize_per_trie_key {
let k in 0..1024;
let instance = Contract::<T>::with_storage(WasmModule::dummy(), k, T::Schedule::get().limits.payload_len)?;
instance.info()?.queue_trie_for_deletion()?;
}: {
ContractInfo::<T>::process_deletion_queue_batch(Weight::MAX)
}

#[pov_mode = Measured]
on_initialize_per_queue_item {
let q in 0..1024.min(T::DeletionQueueDepth::get());
for i in 0 .. q {
let instance = Contract::<T>::with_index(i, WasmModule::dummy(), vec![])?;
instance.info()?.queue_trie_for_deletion()?;
ContractInfoOf::<T>::remove(instance.account_id);
}
instance.info()?.queue_trie_for_deletion();
}: {
ContractInfo::<T>::process_deletion_queue_batch(Weight::MAX)
}
Expand Down Expand Up @@ -3020,16 +3008,12 @@ benchmarks! {
print_schedule {
#[cfg(feature = "std")]
{
let weight_limit = T::DeletionWeightLimit::get();
let max_queue_depth = T::DeletionQueueDepth::get() as usize;
let empty_queue_throughput = ContractInfo::<T>::deletion_budget(0, weight_limit);
let full_queue_throughput = ContractInfo::<T>::deletion_budget(max_queue_depth, weight_limit);
let max_weight = <T as frame_system::Config>::BlockWeights::get().max_block;
let (weight_per_key, key_budget) = ContractInfo::<T>::deletion_budget(max_weight);
println!("{:#?}", Schedule::<T>::default());
println!("###############################################");
println!("Lazy deletion weight per key: {}", empty_queue_throughput.0);
println!("Lazy deletion throughput per block (empty queue, full queue): {}, {}",
empty_queue_throughput.1, full_queue_throughput.1,
);
println!("Lazy deletion weight per key: {weight_per_key}");
println!("Lazy deletion throughput per block: {key_budget}");
}
#[cfg(not(feature = "std"))]
Err("Run this bench with a native runtime in order to see the schedule.")?;
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ where
T::Currency::reducible_balance(&frame.account_id, Expendable, Polite),
ExistenceRequirement::AllowDeath,
)?;
info.queue_trie_for_deletion()?;
info.queue_trie_for_deletion();
ContractInfoOf::<T>::remove(&frame.account_id);
E::remove_user(info.code_hash);
Contracts::<T>::deposit_event(
Expand Down
65 changes: 9 additions & 56 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests;
use crate::{
exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Key, Stack as ExecStack},
gas::GasMeter,
storage::{meter::Meter as StorageMeter, ContractInfo, DeletedContract},
storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager},
wasm::{OwnerInfo, PrefabWasmModule, TryInstantiate},
weights::WeightInfo,
};
Expand Down Expand Up @@ -245,33 +245,6 @@ pub mod pallet {
/// memory usage of your runtime.
type CallStack: Array<Item = Frame<Self>>;

/// The maximum number of contracts that can be pending for deletion.
///
/// When a contract is deleted by calling `seal_terminate` it becomes inaccessible
/// immediately, but the deletion of the storage items it has accumulated is performed
/// later. The contract is put into the deletion queue. This defines how many
/// contracts can be queued up at the same time. If that limit is reached `seal_terminate`
/// will fail. The action must be retried in a later block in that case.
///
/// The reasons for limiting the queue depth are:
///
/// 1. The queue is in storage in order to be persistent between blocks. We want to limit
/// the amount of storage that can be consumed.
/// 2. The queue is stored in a vector and needs to be decoded as a whole when reading
/// it at the end of each block. Longer queues take more weight to decode and hence
/// limit the amount of items that can be deleted per block.
#[pallet::constant]
type DeletionQueueDepth: Get<u32>;

/// The maximum amount of weight that can be consumed per block for lazy trie removal.
///
/// The amount of weight that is dedicated per block to work on the deletion queue. Larger
/// values allow more trie keys to be deleted in each block but reduce the amount of
/// weight that is left for transactions. See [`Self::DeletionQueueDepth`] for more
/// information about the deletion queue.
#[pallet::constant]
type DeletionWeightLimit: Get<Weight>;

/// The amount of balance a caller has to pay for each byte of storage.
///
/// # Note
Expand Down Expand Up @@ -329,25 +302,6 @@ pub mod pallet {
.saturating_add(T::WeightInfo::on_process_deletion_queue_batch())
}

fn on_initialize(_block: T::BlockNumber) -> Weight {
// We want to process the deletion_queue in the on_idle hook. Only in the case
// that the queue length has reached its maximal depth, we process it here.
let max_len = T::DeletionQueueDepth::get() as usize;
let queue_len = <DeletionQueue<T>>::decode_len().unwrap_or(0);
if queue_len >= max_len {
// We do not want to go above the block limit and rather avoid lazy deletion
// in that case. This should only happen on runtime upgrades.
let weight_limit = T::BlockWeights::get()
.max_block
.saturating_sub(System::<T>::block_weight().total())
.min(T::DeletionWeightLimit::get());
ContractInfo::<T>::process_deletion_queue_batch(weight_limit)
.saturating_add(T::WeightInfo::on_process_deletion_queue_batch())
} else {
T::WeightInfo::on_process_deletion_queue_batch()
}
}

fn integrity_test() {
// Total runtime memory is expected to have 128Mb upper limit
const MAX_RUNTIME_MEM: u32 = 1024 * 1024 * 128;
Expand Down Expand Up @@ -860,12 +814,6 @@ pub mod pallet {
/// in this error. Note that this usually shouldn't happen as deploying such contracts
/// is rejected.
NoChainExtension,
/// Removal of a contract failed because the deletion queue is full.
///
/// This can happen when calling `seal_terminate`.
/// The queue is filled by deleting contracts and emptied by a fixed amount each block.
/// Trying again during another block is the only way to resolve this issue.
DeletionQueueFull,
/// A contract with the same AccountId already exists.
DuplicateContract,
/// A contract self destructed in its constructor.
Expand Down Expand Up @@ -949,10 +897,15 @@ pub mod pallet {
/// Evicted contracts that await child trie deletion.
///
/// Child trie deletion is a heavy operation depending on the amount of storage items
/// stored in said trie. Therefore this operation is performed lazily in `on_initialize`.
/// stored in said trie. Therefore this operation is performed lazily in `on_idle`.
#[pallet::storage]
pub(crate) type DeletionQueue<T: Config> = StorageMap<_, Twox64Concat, u32, TrieId>;

/// A pair of monotonic counters used to track the latest contract marked for deletion
/// and the latest deleted contract in queue.
#[pallet::storage]
pub(crate) type DeletionQueue<T: Config> =
StorageValue<_, BoundedVec<DeletedContract, T::DeletionQueueDepth>, ValueQuery>;
pub(crate) type DeletionQueueCounter<T: Config> =
StorageValue<_, DeletionQueueManager<T>, ValueQuery>;
}

/// Context of a contract invocation.
Expand Down
Loading