Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into ao-disputes-offences-runtime
Browse files Browse the repository at this point in the history
* master:
  Fix regexp to find the repo name (#5751)
  Limit stagnant checks to a certain amount of entries (#5742)
  fix(staking miner): check latest state in solution (#5744)
  staking-miner: CLI flag delay solution x secs (#5734)
  backport minimum weight to fee to master (#5739)
  Bump quote from 1.0.19 to 1.0.20 (#5736)
  • Loading branch information
ordian committed Jul 5, 2022
2 parents 65146ca + 4833bae commit 650eb19
Show file tree
Hide file tree
Showing 24 changed files with 460 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-01_branch-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

jobs:
tag_rc:
check_branch:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion node/core/chain-selection/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ pub(super) trait Backend {
/// Load the stagnant list at the given timestamp.
fn load_stagnant_at(&self, timestamp: Timestamp) -> Result<Vec<Hash>, Error>;
/// Load all stagnant lists up to and including the given Unix timestamp
/// in ascending order.
/// in ascending order. Stop fetching stagnant entries upon reaching `max_elements`.
fn load_stagnant_at_up_to(
&self,
up_to: Timestamp,
max_elements: usize,
) -> Result<Vec<(Timestamp, Vec<Hash>)>, Error>;
/// Load the earliest kept block number.
fn load_first_block_number(&self) -> Result<Option<BlockNumber>, Error>;
Expand Down
25 changes: 18 additions & 7 deletions node/core/chain-selection/src/db_backend/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl Backend for DbBackend {
fn load_stagnant_at_up_to(
&self,
up_to: crate::Timestamp,
max_elements: usize,
) -> Result<Vec<(crate::Timestamp, Vec<Hash>)>, Error> {
let stagnant_at_iter =
self.inner.iter_with_prefix(self.config.col_data, &STAGNANT_AT_PREFIX[..]);
Expand All @@ -240,7 +241,9 @@ impl Backend for DbBackend {
_ => None,
}
})
.take_while(|(at, _)| *at <= up_to.into())
.enumerate()
.take_while(|(idx, (at, _))| *at <= up_to.into() && *idx < max_elements)
.map(|(_, v)| v)
.collect::<Vec<_>>();

Ok(val)
Expand Down Expand Up @@ -528,7 +531,10 @@ mod tests {
let mut backend = DbBackend::new(db, config);

// Prove that it's cheap
assert!(backend.load_stagnant_at_up_to(Timestamp::max_value()).unwrap().is_empty());
assert!(backend
.load_stagnant_at_up_to(Timestamp::max_value(), usize::MAX)
.unwrap()
.is_empty());

backend
.write(vec![
Expand All @@ -539,7 +545,7 @@ mod tests {
.unwrap();

assert_eq!(
backend.load_stagnant_at_up_to(Timestamp::max_value()).unwrap(),
backend.load_stagnant_at_up_to(Timestamp::max_value(), usize::MAX).unwrap(),
vec![
(2, vec![Hash::repeat_byte(1)]),
(5, vec![Hash::repeat_byte(2)]),
Expand All @@ -548,7 +554,7 @@ mod tests {
);

assert_eq!(
backend.load_stagnant_at_up_to(10).unwrap(),
backend.load_stagnant_at_up_to(10, usize::MAX).unwrap(),
vec![
(2, vec![Hash::repeat_byte(1)]),
(5, vec![Hash::repeat_byte(2)]),
Expand All @@ -557,21 +563,26 @@ mod tests {
);

assert_eq!(
backend.load_stagnant_at_up_to(9).unwrap(),
backend.load_stagnant_at_up_to(9, usize::MAX).unwrap(),
vec![(2, vec![Hash::repeat_byte(1)]), (5, vec![Hash::repeat_byte(2)]),]
);

assert_eq!(
backend.load_stagnant_at_up_to(9, 1).unwrap(),
vec![(2, vec![Hash::repeat_byte(1)]),]
);

backend.write(vec![BackendWriteOp::DeleteStagnantAt(2)]).unwrap();

assert_eq!(
backend.load_stagnant_at_up_to(5).unwrap(),
backend.load_stagnant_at_up_to(5, usize::MAX).unwrap(),
vec![(5, vec![Hash::repeat_byte(2)]),]
);

backend.write(vec![BackendWriteOp::WriteStagnantAt(5, vec![])]).unwrap();

assert_eq!(
backend.load_stagnant_at_up_to(10).unwrap(),
backend.load_stagnant_at_up_to(10, usize::MAX).unwrap(),
vec![(10, vec![Hash::repeat_byte(3)]),]
);
}
Expand Down
12 changes: 9 additions & 3 deletions node/core/chain-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Timestamp = u64;
// If a block isn't approved in 120 seconds, nodes will abandon it
// and begin building on another chain.
const STAGNANT_TIMEOUT: Timestamp = 120;
// Maximum number of stagnant entries cleaned during one `STAGNANT_TIMEOUT` iteration
const MAX_STAGNANT_ENTRIES: usize = 1000;

#[derive(Debug, Clone)]
enum Approval {
Expand Down Expand Up @@ -435,7 +437,7 @@ where
}
}
_ = stagnant_check_stream.next().fuse() => {
detect_stagnant(backend, clock.timestamp_now())?;
detect_stagnant(backend, clock.timestamp_now(), MAX_STAGNANT_ENTRIES)?;
}
}
}
Expand Down Expand Up @@ -637,9 +639,13 @@ fn handle_approved_block(backend: &mut impl Backend, approved_block: Hash) -> Re
backend.write(ops)
}

fn detect_stagnant(backend: &mut impl Backend, now: Timestamp) -> Result<(), Error> {
fn detect_stagnant(
backend: &mut impl Backend,
now: Timestamp,
max_elements: usize,
) -> Result<(), Error> {
let ops = {
let overlay = tree::detect_stagnant(&*backend, now)?;
let overlay = tree::detect_stagnant(&*backend, now, max_elements)?;

overlay.into_write_ops()
};
Expand Down
5 changes: 4 additions & 1 deletion node/core/chain-selection/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ impl Backend for TestBackend {
fn load_stagnant_at_up_to(
&self,
up_to: Timestamp,
max_elements: usize,
) -> Result<Vec<(Timestamp, Vec<Hash>)>, Error> {
Ok(self
.inner
.lock()
.stagnant_at
.range(..=up_to)
.map(|(t, v)| (*t, v.clone()))
.enumerate()
.take_while(|(idx, _)| *idx < max_elements)
.map(|(_, (t, v))| (*t, v.clone()))
.collect())
}
fn load_first_block_number(&self) -> Result<Option<BlockNumber>, Error> {
Expand Down
33 changes: 32 additions & 1 deletion node/core/chain-selection/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,28 @@ pub(super) fn approve_block(
pub(super) fn detect_stagnant<'a, B: 'a + Backend>(
backend: &'a B,
up_to: Timestamp,
max_elements: usize,
) -> Result<OverlayedBackend<'a, B>, Error> {
let stagnant_up_to = backend.load_stagnant_at_up_to(up_to)?;
let stagnant_up_to = backend.load_stagnant_at_up_to(up_to, max_elements)?;
let mut backend = OverlayedBackend::new(backend);

let (min_ts, max_ts) = match stagnant_up_to.len() {
0 => (0 as Timestamp, 0 as Timestamp),
1 => (stagnant_up_to[0].0, stagnant_up_to[0].0),
n => (stagnant_up_to[0].0, stagnant_up_to[n - 1].0),
};

// As this is in ascending order, only the earliest stagnant
// blocks will involve heavy viability propagations.
gum::debug!(
target: LOG_TARGET,
?up_to,
?min_ts,
?max_ts,
"Prepared {} stagnant entries for pruning",
stagnant_up_to.len()
);

for (timestamp, maybe_stagnant) in stagnant_up_to {
backend.delete_stagnant_at(timestamp);

Expand All @@ -550,12 +566,27 @@ pub(super) fn detect_stagnant<'a, B: 'a + Backend>(
entry.viability.approval = Approval::Stagnant;
}
let is_viable = entry.viability.is_viable();
gum::trace!(
target: LOG_TARGET,
?block_hash,
?timestamp,
?was_viable,
?is_viable,
"Found existing stagnant entry"
);

if was_viable && !is_viable {
propagate_viability_update(&mut backend, entry)?;
} else {
backend.write_block_entry(entry);
}
} else {
gum::trace!(
target: LOG_TARGET,
?block_hash,
?timestamp,
"Found non-existing stagnant entry"
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/gum/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ proc-macro = true

[dependencies]
syn = { version = "1.0.95", features = ["full", "extra-traits"] }
quote = "1.0.19"
quote = "1.0.20"
proc-macro2 = "1.0.40"
proc-macro-crate = "1.1.3"
expander = "0.0.6"
Expand Down
2 changes: 1 addition & 1 deletion node/orchestra/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ proc-macro = true

[dependencies]
syn = { version = "1.0.95", features = ["full", "extra-traits"] }
quote = "1.0.19"
quote = "1.0.20"
proc-macro2 = "1.0.40"
proc-macro-crate = "1.1.3"
expander = { version = "0.0.6", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion node/test/performance-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
thiserror = "1.0.31"
quote = "1.0.19"
quote = "1.0.20"
env_logger = "0.9"
log = "0.4"

Expand Down
2 changes: 1 addition & 1 deletion parachain/test-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Integration tests using the test-parachains"
edition = "2021"

[dependencies]
tiny-keccak = "2.0.2"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["derive"] }

adder = { package = "test-parachain-adder", path = "adder" }
Expand Down
117 changes: 2 additions & 115 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ parameter_types! {
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
/// change the fees more rapidly.
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(75, 1000_000);
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10u128);
/// Maximum length of block. Up to 5MB.
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
Expand Down Expand Up @@ -244,116 +244,3 @@ macro_rules! prod_or_fast {
}
};
}

#[cfg(test)]
mod multiplier_tests {
use super::*;
use frame_support::{
parameter_types,
weights::{DispatchClass, Weight},
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, Convert, IdentityLookup, One},
Perbill,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockLength: frame_system::limits::BlockLength =
frame_system::limits::BlockLength::max(2 * 1024);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}

impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = Call;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

fn run_with_system_weight<F>(w: Weight, mut assertions: F)
where
F: FnMut() -> (),
{
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap()
.into();
t.execute_with(|| {
System::set_block_consumed_resources(w, 0);
assertions()
});
}

#[test]
fn multiplier_can_grow_from_zero() {
let minimum_multiplier = MinimumMultiplier::get();
let target = TargetBlockFullness::get() *
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
// if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/100th bigger than target.
run_with_system_weight(target * 101 / 100, || {
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier);
assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier);
})
}

#[test]
#[ignore]
fn multiplier_growth_simulator() {
// assume the multiplier is initially set to its minimum. We update it with values twice the
//target (target is 25%, thus 50%) and we see at which point it reaches 1.
let mut multiplier = MinimumMultiplier::get();
let block_weight = TargetBlockFullness::get() *
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() *
2;
let mut blocks = 0;
while multiplier <= Multiplier::one() {
run_with_system_weight(block_weight, || {
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(multiplier);
// ensure that it is growing as well.
assert!(next > multiplier, "{:?} !>= {:?}", next, multiplier);
multiplier = next;
});
blocks += 1;
println!("block = {} multiplier {:?}", blocks, multiplier);
}
}
}
2 changes: 1 addition & 1 deletion runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default

[dev-dependencies]
hex-literal = "0.3.4"
tiny-keccak = "2.0.2"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
separator = "0.4.1"
Expand Down
Loading

0 comments on commit 650eb19

Please sign in to comment.