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

Make rolling session more resilient in case of long finality stalls #6106

Merged
merged 45 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e488f52
Impl dynamic window size. Keep sessions for unfinalized chain
sandreim Sep 26, 2022
5780cc9
feedback
sandreim Sep 26, 2022
2132d9c
Stretch also in contructor plus tests
sandreim Sep 27, 2022
eb06959
review feedback
sandreim Sep 27, 2022
88ac66f
fix approval-voting tests
sandreim Sep 27, 2022
a7d97d0
grunting: dispute coordinator tests
sandreim Sep 27, 2022
3e4d9d5
add session window column
sandreim Oct 3, 2022
810c4d6
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Oct 4, 2022
1732baa
integrate approval vote and fix tests
sandreim Oct 4, 2022
c9045cd
fix rolling session tests
sandreim Oct 4, 2022
781ef47
Small refactor
sandreim Oct 4, 2022
89d4d00
WIP, tests failing
sandreim Oct 5, 2022
09d25e6
Fix approval voting tests
sandreim Oct 6, 2022
6ea92ed
fix dispute-coordinator tests
sandreim Oct 7, 2022
cecd5e0
remove uneeded param
sandreim Oct 7, 2022
e0aee8b
fmt
sandreim Oct 7, 2022
c6e727d
fix loose ends
sandreim Oct 7, 2022
90cdad7
allow failure and tests for it
sandreim Oct 7, 2022
1ae389b
fix comment
sandreim Oct 7, 2022
ee093f8
comment fix
sandreim Oct 7, 2022
5ccc675
style fix
sandreim Oct 7, 2022
762be95
new col doesn't need to be ordered
sandreim Oct 7, 2022
f6d37a9
fmt and spellcheck
sandreim Oct 7, 2022
8de8d66
db persist tests
sandreim Oct 10, 2022
5c41d35
Add v2 config and cols
sandreim Oct 10, 2022
11fb825
DB upgrade WIP
sandreim Oct 11, 2022
0a2ecd6
Fix comments
sandreim Oct 11, 2022
c887eca
add todo
sandreim Oct 12, 2022
32947c9
update to parity-db to "0.4.2"
sandreim Oct 13, 2022
3d75b69
migration complete
sandreim Oct 13, 2022
a17770d
One session window size
sandreim Oct 13, 2022
93b5943
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Oct 13, 2022
f91681c
fix merge damage
sandreim Oct 13, 2022
5a5e7c6
fix build errors
sandreim Oct 13, 2022
cf05ac6
fmt
sandreim Oct 13, 2022
dcb31c9
comment fix
sandreim Oct 13, 2022
47765bc
fix build
sandreim Oct 13, 2022
81d7e05
make error more explicit
sandreim Oct 14, 2022
516f23e
add comment
sandreim Oct 14, 2022
0b4bf94
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Nov 8, 2022
316f5ed
refactor conflict merge
sandreim Nov 8, 2022
3b45f23
rename col_data
sandreim Nov 8, 2022
8305677
add doc comment
sandreim Nov 8, 2022
f8b6023
fix build
sandreim Nov 8, 2022
43e1823
migration: move all cols to v2
sandreim Nov 8, 2022
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
34 changes: 27 additions & 7 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions node/core/approval-voting/src/approval_db/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ pub type Bitfield = BitVec<u8, BitOrderLsb0>;
pub struct Config {
/// The column family in the database where data is stored.
pub col_data: u32,
/// The column of the database where rolling session window data is stored.
pub col_session_data: u32,
}

/// Details pertaining to our assignment on a block.
Expand Down
6 changes: 4 additions & 2 deletions node/core/approval-voting/src/approval_db/v1/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ use std::{collections::HashMap, sync::Arc};
use ::test_helpers::{dummy_candidate_receipt, dummy_candidate_receipt_bad_sig, dummy_hash};

const DATA_COL: u32 = 0;
const NUM_COLUMNS: u32 = 1;
const SESSION_DATA_COL: u32 = 1;

const TEST_CONFIG: Config = Config { col_data: DATA_COL };
const NUM_COLUMNS: u32 = 2;

const TEST_CONFIG: Config = Config { col_data: DATA_COL, col_session_data: SESSION_DATA_COL };

fn make_db() -> (DbBackend, Arc<dyn Database>) {
let db = kvdb_memorydb::create(NUM_COLUMNS);
Expand Down
71 changes: 17 additions & 54 deletions node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,12 @@ pub(crate) mod tests {
};

const DATA_COL: u32 = 0;
const NUM_COLUMNS: u32 = 1;
const SESSION_DATA_COL: u32 = 1;

const TEST_CONFIG: DatabaseConfig = DatabaseConfig { col_data: DATA_COL };
const NUM_COLUMNS: u32 = 2;

const TEST_CONFIG: DatabaseConfig =
DatabaseConfig { col_data: DATA_COL, col_session_data: SESSION_DATA_COL };
#[derive(Default)]
struct MockClock;

Expand All @@ -652,22 +655,23 @@ pub(crate) mod tests {
}

fn blank_state() -> State {
let db = kvdb_memorydb::create(NUM_COLUMNS);
let db = polkadot_node_subsystem_util::database::kvdb_impl::DbAdapter::new(db, &[]);
let db: Arc<dyn Database> = Arc::new(db);
State {
session_window: None,
keystore: Arc::new(LocalKeystore::in_memory()),
slot_duration_millis: 6_000,
clock: Box::new(MockClock::default()),
assignment_criteria: Box::new(MockAssignmentCriteria),
db,
db_config: TEST_CONFIG,
}
}

fn single_session_state(index: SessionIndex, info: SessionInfo) -> State {
State {
session_window: Some(RollingSessionWindow::with_session_info(
APPROVAL_SESSIONS,
index,
vec![info],
)),
session_window: Some(RollingSessionWindow::with_session_info(index, vec![info])),
..blank_state()
}
}
Expand Down Expand Up @@ -780,11 +784,8 @@ pub(crate) mod tests {
.map(|(r, c, g)| (r.hash(), r.clone(), *c, *g))
.collect::<Vec<_>>();

let session_window = RollingSessionWindow::with_session_info(
APPROVAL_SESSIONS,
session,
vec![session_info],
);
let session_window =
RollingSessionWindow::with_session_info(session, vec![session_info]);

let header = header.clone();
Box::pin(async move {
Expand Down Expand Up @@ -889,11 +890,8 @@ pub(crate) mod tests {
.collect::<Vec<_>>();

let test_fut = {
let session_window = RollingSessionWindow::with_session_info(
APPROVAL_SESSIONS,
session,
vec![session_info],
);
let session_window =
RollingSessionWindow::with_session_info(session, vec![session_info]);

let header = header.clone();
Box::pin(async move {
Expand Down Expand Up @@ -1087,11 +1085,8 @@ pub(crate) mod tests {
.map(|(r, c, g)| (r.hash(), r.clone(), *c, *g))
.collect::<Vec<_>>();

let session_window = Some(RollingSessionWindow::with_session_info(
APPROVAL_SESSIONS,
session,
vec![session_info],
));
let session_window =
Some(RollingSessionWindow::with_session_info(session, vec![session_info]));

let header = header.clone();
Box::pin(async move {
Expand Down Expand Up @@ -1296,38 +1291,6 @@ 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
37 changes: 30 additions & 7 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use polkadot_node_subsystem_util::{
database::Database,
metrics::{self, prometheus},
rolling_session_window::{
new_session_window_size, RollingSessionWindow, SessionWindowSize, SessionWindowUpdate,
DatabaseParams, RollingSessionWindow, SessionWindowSize, SessionWindowUpdate,
SessionsUnavailable,
},
TimeoutExt,
Expand Down Expand Up @@ -97,8 +97,6 @@ use crate::{
#[cfg(test)]
mod tests;

pub const APPROVAL_SESSIONS: SessionWindowSize = new_session_window_size!(6);

const APPROVAL_CHECKING_TIMEOUT: Duration = Duration::from_secs(120);
/// How long are we willing to wait for approval signatures?
///
Expand All @@ -119,6 +117,8 @@ const LOG_TARGET: &str = "parachain::approval-voting";
pub struct Config {
/// The column family in the DB where approval-voting data is stored.
pub col_data: u32,
sandreim marked this conversation as resolved.
Show resolved Hide resolved
/// The of the DB where rolling session info is stored.
pub col_session_data: u32,
/// The slot duration of the consensus algorithm, in milliseconds. Should be evenly
/// divisible by 500.
pub slot_duration_millis: u64,
Expand Down Expand Up @@ -358,7 +358,10 @@ impl ApprovalVotingSubsystem {
keystore,
slot_duration_millis: config.slot_duration_millis,
db,
db_config: DatabaseConfig { col_data: config.col_data },
db_config: DatabaseConfig {
col_data: config.col_data,
col_session_data: config.col_session_data,
},
mode: Mode::Syncing(sync_oracle),
metrics,
}
Expand All @@ -367,7 +370,10 @@ impl ApprovalVotingSubsystem {
/// Revert to the block corresponding to the specified `hash`.
/// The operation is not allowed for blocks older than the last finalized one.
pub fn revert_to(&self, hash: Hash) -> Result<(), SubsystemError> {
let config = approval_db::v1::Config { col_data: self.db_config.col_data };
let config = approval_db::v1::Config {
col_data: self.db_config.col_data,
col_session_data: self.db_config.col_session_data,
};
let mut backend = approval_db::v1::DbBackend::new(self.db.clone(), config);
let mut overlay = OverlayedBackend::new(&backend);

Expand Down Expand Up @@ -615,6 +621,9 @@ struct State {
slot_duration_millis: u64,
clock: Box<dyn Clock + Send + Sync>,
assignment_criteria: Box<dyn AssignmentCriteria + Send + Sync>,
// Require for `RollingSessionWindow`.
db_config: DatabaseConfig,
db: Arc<dyn Database>,
}

#[overseer::contextbounds(ApprovalVoting, prefix = self::overseer)]
Expand All @@ -636,8 +645,17 @@ impl State {
match session_window {
None => {
let sender = ctx.sender().clone();
self.session_window =
Some(RollingSessionWindow::new(sender, APPROVAL_SESSIONS, head).await?);
self.session_window = Some(
RollingSessionWindow::new(
sender,
head,
DatabaseParams {
db: self.db.clone(),
db_column: self.db_config.col_session_data,
},
)
.await?,
);
Ok(None)
},
Some(mut session_window) => {
Expand Down Expand Up @@ -732,12 +750,17 @@ async fn run<B, Context>(
where
B: Backend,
{
let db = subsystem.db.clone();
let db_config = subsystem.db_config.clone();

let mut state = State {
session_window: None,
keystore: subsystem.keystore,
slot_duration_millis: subsystem.slot_duration_millis,
clock,
assignment_criteria,
db_config,
db,
};

let mut wakeups = Wakeups::default();
Expand Down
Loading