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 rk-batch-vote-import
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimor committed Oct 4, 2022
2 parents 5b5d82d + efb82ef commit f0a054b
Show file tree
Hide file tree
Showing 22 changed files with 488 additions and 42 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/core/approval-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ futures-timer = "3.0.2"
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
gum = { package = "tracing-gum", path = "../../gum" }
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
lru = "0.7"
lru = "0.8"
merlin = "2.0"
schnorrkel = "0.9.1"
kvdb = "0.11.0"
Expand Down
32 changes: 32 additions & 0 deletions node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,38 @@ pub(crate) mod tests {
}
);

// Caching of sesssions needs sessoion of first unfinalied block.
assert_matches!(
handle.recv().await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
s_tx,
)) => {
let _ = s_tx.send(Ok(header.number));
}
);

assert_matches!(
handle.recv().await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
block_number,
s_tx,
)) => {
assert_eq!(block_number, header.number);
let _ = s_tx.send(Ok(Some(header.hash())));
}
);

assert_matches!(
handle.recv().await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
h,
RuntimeApiRequest::SessionIndexForChild(s_tx),
)) => {
assert_eq!(h, header.hash());
let _ = s_tx.send(Ok(session));
}
);

// determine_new_blocks exits early as the parent_hash is in the DB

assert_matches!(
Expand Down
7 changes: 6 additions & 1 deletion node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ use std::{
collections::{
btree_map::Entry as BTMEntry, hash_map::Entry as HMEntry, BTreeMap, HashMap, HashSet,
},
num::NonZeroUsize,
sync::Arc,
time::Duration,
};
Expand Down Expand Up @@ -104,7 +105,11 @@ const APPROVAL_CHECKING_TIMEOUT: Duration = Duration::from_secs(120);
/// Value rather arbitrarily: Should not be hit in practice, it exists to more easily diagnose dead
/// lock issues for example.
const WAIT_FOR_SIGS_TIMEOUT: Duration = Duration::from_millis(500);
const APPROVAL_CACHE_SIZE: usize = 1024;
const APPROVAL_CACHE_SIZE: NonZeroUsize = match NonZeroUsize::new(1024) {
Some(cap) => cap,
None => panic!("Approval cache size must be non-zero."),
};

const TICK_TOO_FAR_IN_FUTURE: Tick = 20; // 10 seconds.
const APPROVAL_DELAY: Tick = 2;
const LOG_TARGET: &str = "parachain::approval-voting";
Expand Down
31 changes: 31 additions & 0 deletions node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,37 @@ async fn import_block(
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
s_tx,
)) => {
let _ = s_tx.send(Ok(number));
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
block_number,
s_tx,
)) => {
assert_eq!(block_number, number);
let _ = s_tx.send(Ok(Some(hashes[number as usize].0)));
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
h,
RuntimeApiRequest::SessionIndexForChild(s_tx),
)) => {
assert_eq!(h, hashes[number as usize].0);
let _ = s_tx.send(Ok(number.into()));
}
);

if !fork {
assert_matches!(
overseer_recv(overseer).await,
Expand Down
2 changes: 1 addition & 1 deletion node/core/dispute-coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gum = { package = "tracing-gum", path = "../../gum" }
parity-scale-codec = "3.1.5"
kvdb = "0.11.0"
thiserror = "1.0.31"
lru = "0.7.7"
lru = "0.8.0"
fatality = "0.0.6"

polkadot-primitives = { path = "../../../primitives" }
Expand Down
10 changes: 8 additions & 2 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use std::collections::{BTreeMap, HashSet};
use std::{
collections::{BTreeMap, HashSet},
num::NonZeroUsize,
};

use futures::channel::oneshot;
use lru::LruCache;
Expand Down Expand Up @@ -44,7 +47,10 @@ mod tests;
/// `last_observed_blocks` LRU. This means, this value should the very least be as large as the
/// number of expected forks for keeping chain scraping efficient. Making the LRU much larger than
/// that has very limited use.
const LRU_OBSERVED_BLOCKS_CAPACITY: usize = 20;
const LRU_OBSERVED_BLOCKS_CAPACITY: NonZeroUsize = match NonZeroUsize::new(20) {
Some(cap) => cap,
None => panic!("Observed blocks cache size must be non-zero"),
};

/// Chain scraper
///
Expand Down
41 changes: 39 additions & 2 deletions node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ impl TestState {
)))
.await;

self.handle_sync_queries(virtual_overseer, block_hash, session).await;
self.handle_sync_queries(virtual_overseer, block_hash, block_number, session)
.await;
}

async fn handle_sync_queries(
&mut self,
virtual_overseer: &mut VirtualOverseer,
block_hash: Hash,
block_number: BlockNumber,
session: SessionIndex,
) {
// Order of messages is not fixed (different on initializing):
Expand Down Expand Up @@ -278,11 +280,45 @@ impl TestState {
finished_steps.got_session_information = true;
assert_eq!(h, block_hash);
let _ = tx.send(Ok(session));

// Queries for fetching earliest unfinalized block session. See `RollingSessionWindow`.
assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
s_tx,
)) => {
let _ = s_tx.send(Ok(block_number));
}
);

assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
number,
s_tx,
)) => {
assert_eq!(block_number, number);
let _ = s_tx.send(Ok(Some(block_hash)));
}
);

assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
h,
RuntimeApiRequest::SessionIndexForChild(s_tx),
)) => {
assert_eq!(h, block_hash);
let _ = s_tx.send(Ok(session));
}
);

// No queries, if subsystem knows about this session already.
if self.known_session == Some(session) {
continue
}
self.known_session = Some(session);

loop {
// answer session info queries until the current session is reached.
assert_matches!(
Expand Down Expand Up @@ -361,7 +397,8 @@ impl TestState {
)))
.await;

self.handle_sync_queries(virtual_overseer, *leaf, session).await;
self.handle_sync_queries(virtual_overseer, *leaf, n as BlockNumber, session)
.await;
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/network/availability-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "maste
thiserror = "1.0.31"
rand = "0.8.5"
derive_more = "0.99.17"
lru = "0.7.7"
lru = "0.8.0"
fatality = "0.0.6"

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/>.

use std::collections::HashSet;
use std::{collections::HashSet, num::NonZeroUsize};

use lru::LruCache;
use rand::{seq::SliceRandom, thread_rng};
Expand Down Expand Up @@ -85,7 +85,7 @@ impl SessionCache {
pub fn new() -> Self {
SessionCache {
// We need to cache the current and the last session the most:
session_info_cache: LruCache::new(2),
session_info_cache: LruCache::new(NonZeroUsize::new(2).unwrap()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/network/availability-recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
futures = "0.3.21"
lru = "0.7.7"
lru = "0.8.0"
rand = "0.8.5"
fatality = "0.0.6"
thiserror = "1.0.31"
Expand Down
6 changes: 5 additions & 1 deletion node/network/availability-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use std::{
collections::{HashMap, VecDeque},
num::NonZeroUsize,
pin::Pin,
time::Duration,
};
Expand Down Expand Up @@ -77,7 +78,10 @@ const LOG_TARGET: &str = "parachain::availability-recovery";
const N_PARALLEL: usize = 50;

// Size of the LRU cache where we keep recovered data.
const LRU_SIZE: usize = 16;
const LRU_SIZE: NonZeroUsize = match NonZeroUsize::new(16) {
Some(cap) => cap,
None => panic!("Availability-recovery cache size must be non-zero."),
};

const COST_INVALID_REQUEST: Rep = Rep::CostMajor("Peer sent unparsable request");

Expand Down
2 changes: 1 addition & 1 deletion node/network/dispute-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sp-application-crypto = { git = "https://github.com/paritytech/substrate", branc
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
thiserror = "1.0.31"
fatality = "0.0.6"
lru = "0.7.7"
lru = "0.8.0"
indexmap = "1.9.1"

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions node/network/dispute-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! The sender is responsible for getting our vote out, see [`sender`]. The receiver handles
//! incoming [`DisputeRequest`]s and offers spam protection, see [`receiver`].
use std::time::Duration;
use std::{num::NonZeroUsize, time::Duration};

use futures::{channel::mpsc, FutureExt, StreamExt, TryFutureExt};

Expand Down Expand Up @@ -164,7 +164,8 @@ where
) -> Self {
let runtime = RuntimeInfo::new_with_config(runtime::Config {
keystore: Some(keystore),
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
.expect("Dispute window can not be 0; qed"),
});
let (tx, sender_rx) = mpsc::channel(1);
let disputes_sender = DisputeSender::new(tx, metrics.clone());
Expand Down
4 changes: 3 additions & 1 deletion node/network/dispute-distribution/src/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use std::{
num::NonZeroUsize,
pin::Pin,
task::{Context, Poll},
time::Duration,
Expand Down Expand Up @@ -160,7 +161,8 @@ where
) -> Self {
let runtime = RuntimeInfo::new_with_config(runtime::Config {
keystore: None,
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
.expect("Dispute window can not be 0; qed"),
});
Self {
runtime,
Expand Down
2 changes: 1 addition & 1 deletion node/overseer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ polkadot-node-metrics = { path = "../metrics" }
polkadot-primitives = { path = "../../primitives" }
orchestra = "0.0.2"
gum = { package = "tracing-gum", path = "../gum" }
lru = "0.7"
lru = "0.8"
parity-util-mem = { version = "0.11.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
async-trait = "0.1.57"
Expand Down
Loading

0 comments on commit f0a054b

Please sign in to comment.