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-5535-followup
Browse files Browse the repository at this point in the history
* master:
  Companion for substrate#12530: Consolidate and deduplicate MMR API methods (#6167)
  Companion for substrate#12560 (#6226)
  [Companion] Bound Election and Staking by MaxActiveValidators (#6157)
  Retry failed PVF execution (AmbiguousWorkerDeath) (#6235)
  Make rolling session more resilient in case of long finality stalls (#6106)
  companion for fast unstake batching (#6253)
  staking miner: remove needless queue check (#6221)
  Retry failed PVF prepare jobs (#6213)
  Add a `last change` footer to the implementers guide (#6216)
  Update polkadot inflation to take into account auctions (#5872)
  Increase max rewardable nominators (#6230)
  BlockId removal: &Hash to Hash (#6246)
  • Loading branch information
ordian committed Nov 9, 2022
2 parents e3d7ba6 + 3711c6f commit 78c1cda
Show file tree
Hide file tree
Showing 39 changed files with 2,033 additions and 1,025 deletions.
655 changes: 291 additions & 364 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions node/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl UsageProvider<Block> for Client {
impl sc_client_api::BlockBackend<Block> for Client {
fn block_body(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
with_client! {
self,
Expand Down Expand Up @@ -360,7 +360,7 @@ impl sc_client_api::BlockBackend<Block> for Client {

fn justifications(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Justifications>> {
with_client! {
self,
Expand All @@ -386,7 +386,7 @@ impl sc_client_api::BlockBackend<Block> for Client {

fn indexed_transaction(
&self,
id: &<Block as BlockT>::Hash,
id: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<u8>>> {
with_client! {
self,
Expand All @@ -399,7 +399,7 @@ impl sc_client_api::BlockBackend<Block> for Client {

fn block_indexed_body(
&self,
id: &<Block as BlockT>::Hash,
id: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> {
with_client! {
self,
Expand All @@ -424,7 +424,7 @@ impl sc_client_api::BlockBackend<Block> for Client {
impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
fn storage(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
key: &StorageKey,
) -> sp_blockchain::Result<Option<StorageData>> {
with_client! {
Expand All @@ -438,7 +438,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn storage_keys(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<StorageKey>> {
with_client! {
Expand All @@ -452,7 +452,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn storage_hash(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
key: &StorageKey,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
with_client! {
Expand All @@ -466,7 +466,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn storage_pairs(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<(StorageKey, StorageData)>> {
with_client! {
Expand All @@ -480,7 +480,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn storage_keys_iter<'a>(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
prefix: Option<&'a StorageKey>,
start_key: Option<&StorageKey>,
) -> sp_blockchain::Result<
Expand All @@ -497,7 +497,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn child_storage(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<StorageData>> {
Expand All @@ -512,7 +512,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn child_storage_keys(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
child_info: &ChildInfo,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<StorageKey>> {
Expand All @@ -527,7 +527,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn child_storage_keys_iter<'a>(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
child_info: ChildInfo,
prefix: Option<&'a StorageKey>,
start_key: Option<&StorageKey>,
Expand All @@ -545,7 +545,7 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {

fn child_storage_hash(
&self,
hash: &<Block as BlockT>::Hash,
hash: <Block as BlockT>::Hash,
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
Expand Down
36 changes: 21 additions & 15 deletions node/core/approval-voting/src/approval_db/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,45 @@ impl Backend for DbBackend {
match op {
BackendWriteOp::WriteStoredBlockRange(stored_block_range) => {
tx.put_vec(
self.config.col_data,
self.config.col_approval_data,
&STORED_BLOCKS_KEY,
stored_block_range.encode(),
);
},
BackendWriteOp::DeleteStoredBlockRange => {
tx.delete(self.config.col_data, &STORED_BLOCKS_KEY);
tx.delete(self.config.col_approval_data, &STORED_BLOCKS_KEY);
},
BackendWriteOp::WriteBlocksAtHeight(h, blocks) => {
tx.put_vec(self.config.col_data, &blocks_at_height_key(h), blocks.encode());
tx.put_vec(
self.config.col_approval_data,
&blocks_at_height_key(h),
blocks.encode(),
);
},
BackendWriteOp::DeleteBlocksAtHeight(h) => {
tx.delete(self.config.col_data, &blocks_at_height_key(h));
tx.delete(self.config.col_approval_data, &blocks_at_height_key(h));
},
BackendWriteOp::WriteBlockEntry(block_entry) => {
let block_entry: BlockEntry = block_entry.into();
tx.put_vec(
self.config.col_data,
self.config.col_approval_data,
&block_entry_key(&block_entry.block_hash),
block_entry.encode(),
);
},
BackendWriteOp::DeleteBlockEntry(hash) => {
tx.delete(self.config.col_data, &block_entry_key(&hash));
tx.delete(self.config.col_approval_data, &block_entry_key(&hash));
},
BackendWriteOp::WriteCandidateEntry(candidate_entry) => {
let candidate_entry: CandidateEntry = candidate_entry.into();
tx.put_vec(
self.config.col_data,
self.config.col_approval_data,
&candidate_entry_key(&candidate_entry.candidate.hash()),
candidate_entry.encode(),
);
},
BackendWriteOp::DeleteCandidateEntry(candidate_hash) => {
tx.delete(self.config.col_data, &candidate_entry_key(&candidate_hash));
tx.delete(self.config.col_approval_data, &candidate_entry_key(&candidate_hash));
},
}
}
Expand All @@ -149,7 +153,9 @@ pub type Bitfield = BitVec<u8, BitOrderLsb0>;
#[derive(Debug, Clone, Copy)]
pub struct Config {
/// The column family in the database where data is stored.
pub col_data: u32,
pub col_approval_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 Expand Up @@ -243,10 +249,10 @@ pub type Result<T> = std::result::Result<T, Error>;

pub(crate) fn load_decode<D: Decode>(
store: &dyn Database,
col_data: u32,
col_approval_data: u32,
key: &[u8],
) -> Result<Option<D>> {
match store.get(col_data, key)? {
match store.get(col_approval_data, key)? {
None => Ok(None),
Some(raw) => D::decode(&mut &raw[..]).map(Some).map_err(Into::into),
}
Expand Down Expand Up @@ -303,7 +309,7 @@ pub fn load_stored_blocks(
store: &dyn Database,
config: &Config,
) -> SubsystemResult<Option<StoredBlockRange>> {
load_decode(store, config.col_data, STORED_BLOCKS_KEY)
load_decode(store, config.col_approval_data, STORED_BLOCKS_KEY)
.map_err(|e| SubsystemError::with_origin("approval-voting", e))
}

Expand All @@ -313,7 +319,7 @@ pub fn load_blocks_at_height(
config: &Config,
block_number: &BlockNumber,
) -> SubsystemResult<Vec<Hash>> {
load_decode(store, config.col_data, &blocks_at_height_key(*block_number))
load_decode(store, config.col_approval_data, &blocks_at_height_key(*block_number))
.map(|x| x.unwrap_or_default())
.map_err(|e| SubsystemError::with_origin("approval-voting", e))
}
Expand All @@ -324,7 +330,7 @@ pub fn load_block_entry(
config: &Config,
block_hash: &Hash,
) -> SubsystemResult<Option<BlockEntry>> {
load_decode(store, config.col_data, &block_entry_key(block_hash))
load_decode(store, config.col_approval_data, &block_entry_key(block_hash))
.map(|u: Option<BlockEntry>| u.map(|v| v.into()))
.map_err(|e| SubsystemError::with_origin("approval-voting", e))
}
Expand All @@ -335,7 +341,7 @@ pub fn load_candidate_entry(
config: &Config,
candidate_hash: &CandidateHash,
) -> SubsystemResult<Option<CandidateEntry>> {
load_decode(store, config.col_data, &candidate_entry_key(candidate_hash))
load_decode(store, config.col_approval_data, &candidate_entry_key(candidate_hash))
.map(|u: Option<CandidateEntry>| u.map(|v| v.into()))
.map_err(|e| SubsystemError::with_origin("approval-voting", e))
}
7 changes: 5 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,12 @@ 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_approval_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
75 changes: 18 additions & 57 deletions node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,15 @@ pub(crate) mod tests {
pub(crate) use sp_runtime::{Digest, DigestItem};
use std::{pin::Pin, sync::Arc};

use crate::{
approval_db::v1::Config as DatabaseConfig, criteria, BlockEntry, APPROVAL_SESSIONS,
};
use crate::{approval_db::v1::Config as DatabaseConfig, criteria, BlockEntry};

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

const NUM_COLUMNS: u32 = 2;

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

Expand All @@ -654,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 @@ -782,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 @@ -891,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 @@ -1089,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 @@ -1304,38 +1297,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
Loading

0 comments on commit 78c1cda

Please sign in to comment.