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

Commit f0a054b

Browse files
committed
Merge branch 'master' into rk-batch-vote-import
2 parents 5b5d82d + efb82ef commit f0a054b

File tree

22 files changed

+488
-42
lines changed

22 files changed

+488
-42
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/core/approval-voting/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ futures-timer = "3.0.2"
1010
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
1111
gum = { package = "tracing-gum", path = "../../gum" }
1212
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
13-
lru = "0.7"
13+
lru = "0.8"
1414
merlin = "2.0"
1515
schnorrkel = "0.9.1"
1616
kvdb = "0.11.0"

node/core/approval-voting/src/import.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,38 @@ pub(crate) mod tests {
12961296
}
12971297
);
12981298

1299+
// Caching of sesssions needs sessoion of first unfinalied block.
1300+
assert_matches!(
1301+
handle.recv().await,
1302+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
1303+
s_tx,
1304+
)) => {
1305+
let _ = s_tx.send(Ok(header.number));
1306+
}
1307+
);
1308+
1309+
assert_matches!(
1310+
handle.recv().await,
1311+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
1312+
block_number,
1313+
s_tx,
1314+
)) => {
1315+
assert_eq!(block_number, header.number);
1316+
let _ = s_tx.send(Ok(Some(header.hash())));
1317+
}
1318+
);
1319+
1320+
assert_matches!(
1321+
handle.recv().await,
1322+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
1323+
h,
1324+
RuntimeApiRequest::SessionIndexForChild(s_tx),
1325+
)) => {
1326+
assert_eq!(h, header.hash());
1327+
let _ = s_tx.send(Ok(session));
1328+
}
1329+
);
1330+
12991331
// determine_new_blocks exits early as the parent_hash is in the DB
13001332

13011333
assert_matches!(

node/core/approval-voting/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use std::{
7070
collections::{
7171
btree_map::Entry as BTMEntry, hash_map::Entry as HMEntry, BTreeMap, HashMap, HashSet,
7272
},
73+
num::NonZeroUsize,
7374
sync::Arc,
7475
time::Duration,
7576
};
@@ -104,7 +105,11 @@ const APPROVAL_CHECKING_TIMEOUT: Duration = Duration::from_secs(120);
104105
/// Value rather arbitrarily: Should not be hit in practice, it exists to more easily diagnose dead
105106
/// lock issues for example.
106107
const WAIT_FOR_SIGS_TIMEOUT: Duration = Duration::from_millis(500);
107-
const APPROVAL_CACHE_SIZE: usize = 1024;
108+
const APPROVAL_CACHE_SIZE: NonZeroUsize = match NonZeroUsize::new(1024) {
109+
Some(cap) => cap,
110+
None => panic!("Approval cache size must be non-zero."),
111+
};
112+
108113
const TICK_TOO_FAR_IN_FUTURE: Tick = 20; // 10 seconds.
109114
const APPROVAL_DELAY: Tick = 2;
110115
const LOG_TARGET: &str = "parachain::approval-voting";

node/core/approval-voting/src/tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,37 @@ async fn import_block(
807807
}
808808
);
809809

810+
assert_matches!(
811+
overseer_recv(overseer).await,
812+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
813+
s_tx,
814+
)) => {
815+
let _ = s_tx.send(Ok(number));
816+
}
817+
);
818+
819+
assert_matches!(
820+
overseer_recv(overseer).await,
821+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
822+
block_number,
823+
s_tx,
824+
)) => {
825+
assert_eq!(block_number, number);
826+
let _ = s_tx.send(Ok(Some(hashes[number as usize].0)));
827+
}
828+
);
829+
830+
assert_matches!(
831+
overseer_recv(overseer).await,
832+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
833+
h,
834+
RuntimeApiRequest::SessionIndexForChild(s_tx),
835+
)) => {
836+
assert_eq!(h, hashes[number as usize].0);
837+
let _ = s_tx.send(Ok(number.into()));
838+
}
839+
);
840+
810841
if !fork {
811842
assert_matches!(
812843
overseer_recv(overseer).await,

node/core/dispute-coordinator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ gum = { package = "tracing-gum", path = "../../gum" }
1010
parity-scale-codec = "3.1.5"
1111
kvdb = "0.11.0"
1212
thiserror = "1.0.31"
13-
lru = "0.7.7"
13+
lru = "0.8.0"
1414
fatality = "0.0.6"
1515

1616
polkadot-primitives = { path = "../../../primitives" }

node/core/dispute-coordinator/src/scraping/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use std::collections::{BTreeMap, HashSet};
17+
use std::{
18+
collections::{BTreeMap, HashSet},
19+
num::NonZeroUsize,
20+
};
1821

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

4955
/// Chain scraper
5056
///

node/core/dispute-coordinator/src/tests.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,15 @@ impl TestState {
239239
)))
240240
.await;
241241

242-
self.handle_sync_queries(virtual_overseer, block_hash, session).await;
242+
self.handle_sync_queries(virtual_overseer, block_hash, block_number, session)
243+
.await;
243244
}
244245

245246
async fn handle_sync_queries(
246247
&mut self,
247248
virtual_overseer: &mut VirtualOverseer,
248249
block_hash: Hash,
250+
block_number: BlockNumber,
249251
session: SessionIndex,
250252
) {
251253
// Order of messages is not fixed (different on initializing):
@@ -278,11 +280,45 @@ impl TestState {
278280
finished_steps.got_session_information = true;
279281
assert_eq!(h, block_hash);
280282
let _ = tx.send(Ok(session));
283+
284+
// Queries for fetching earliest unfinalized block session. See `RollingSessionWindow`.
285+
assert_matches!(
286+
overseer_recv(virtual_overseer).await,
287+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockNumber(
288+
s_tx,
289+
)) => {
290+
let _ = s_tx.send(Ok(block_number));
291+
}
292+
);
293+
294+
assert_matches!(
295+
overseer_recv(virtual_overseer).await,
296+
AllMessages::ChainApi(ChainApiMessage::FinalizedBlockHash(
297+
number,
298+
s_tx,
299+
)) => {
300+
assert_eq!(block_number, number);
301+
let _ = s_tx.send(Ok(Some(block_hash)));
302+
}
303+
);
304+
305+
assert_matches!(
306+
overseer_recv(virtual_overseer).await,
307+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
308+
h,
309+
RuntimeApiRequest::SessionIndexForChild(s_tx),
310+
)) => {
311+
assert_eq!(h, block_hash);
312+
let _ = s_tx.send(Ok(session));
313+
}
314+
);
315+
281316
// No queries, if subsystem knows about this session already.
282317
if self.known_session == Some(session) {
283318
continue
284319
}
285320
self.known_session = Some(session);
321+
286322
loop {
287323
// answer session info queries until the current session is reached.
288324
assert_matches!(
@@ -361,7 +397,8 @@ impl TestState {
361397
)))
362398
.await;
363399

364-
self.handle_sync_queries(virtual_overseer, *leaf, session).await;
400+
self.handle_sync_queries(virtual_overseer, *leaf, n as BlockNumber, session)
401+
.await;
365402
}
366403
}
367404

node/network/availability-distribution/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "maste
1919
thiserror = "1.0.31"
2020
rand = "0.8.5"
2121
derive_more = "0.99.17"
22-
lru = "0.7.7"
22+
lru = "0.8.0"
2323
fatality = "0.0.6"
2424

2525
[dev-dependencies]

node/network/availability-distribution/src/requester/session_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use std::collections::HashSet;
17+
use std::{collections::HashSet, num::NonZeroUsize};
1818

1919
use lru::LruCache;
2020
use rand::{seq::SliceRandom, thread_rng};
@@ -85,7 +85,7 @@ impl SessionCache {
8585
pub fn new() -> Self {
8686
SessionCache {
8787
// We need to cache the current and the last session the most:
88-
session_info_cache: LruCache::new(2),
88+
session_info_cache: LruCache::new(NonZeroUsize::new(2).unwrap()),
8989
}
9090
}
9191

node/network/availability-recovery/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66

77
[dependencies]
88
futures = "0.3.21"
9-
lru = "0.7.7"
9+
lru = "0.8.0"
1010
rand = "0.8.5"
1111
fatality = "0.0.6"
1212
thiserror = "1.0.31"

node/network/availability-recovery/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use std::{
2222
collections::{HashMap, VecDeque},
23+
num::NonZeroUsize,
2324
pin::Pin,
2425
time::Duration,
2526
};
@@ -77,7 +78,10 @@ const LOG_TARGET: &str = "parachain::availability-recovery";
7778
const N_PARALLEL: usize = 50;
7879

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

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

node/network/dispute-distribution/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sp-application-crypto = { git = "https://github.com/paritytech/substrate", branc
2121
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
2222
thiserror = "1.0.31"
2323
fatality = "0.0.6"
24-
lru = "0.7.7"
24+
lru = "0.8.0"
2525
indexmap = "1.9.1"
2626

2727
[dev-dependencies]

node/network/dispute-distribution/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! The sender is responsible for getting our vote out, see [`sender`]. The receiver handles
2525
//! incoming [`DisputeRequest`]s and offers spam protection, see [`receiver`].
2626
27-
use std::time::Duration;
27+
use std::{num::NonZeroUsize, time::Duration};
2828

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

@@ -164,7 +164,8 @@ where
164164
) -> Self {
165165
let runtime = RuntimeInfo::new_with_config(runtime::Config {
166166
keystore: Some(keystore),
167-
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
167+
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
168+
.expect("Dispute window can not be 0; qed"),
168169
});
169170
let (tx, sender_rx) = mpsc::channel(1);
170171
let disputes_sender = DisputeSender::new(tx, metrics.clone());

node/network/dispute-distribution/src/receiver/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use std::{
18+
num::NonZeroUsize,
1819
pin::Pin,
1920
task::{Context, Poll},
2021
time::Duration,
@@ -160,7 +161,8 @@ where
160161
) -> Self {
161162
let runtime = RuntimeInfo::new_with_config(runtime::Config {
162163
keystore: None,
163-
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
164+
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
165+
.expect("Dispute window can not be 0; qed"),
164166
});
165167
Self {
166168
runtime,

node/overseer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ polkadot-node-metrics = { path = "../metrics" }
1717
polkadot-primitives = { path = "../../primitives" }
1818
orchestra = "0.0.2"
1919
gum = { package = "tracing-gum", path = "../gum" }
20-
lru = "0.7"
20+
lru = "0.8"
2121
parity-util-mem = { version = "0.11.0", default-features = false }
2222
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
2323
async-trait = "0.1.57"

0 commit comments

Comments
 (0)