mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
polkadot: pin one block per session (#1220)
* polkadot: propagate UnpinHandle to ActiveLeafUpdate Also extract the leaf creation for tests into a common function. * dispute-coordinator: try pinned blocks for slashin * apparently 1.72 is smarter than 1.70 * address nits * rename fresh_leaf to new_leaf
This commit is contained in:
@@ -22,6 +22,7 @@ derive_more = "0.99.17"
|
||||
schnellru = "0.2.1"
|
||||
|
||||
polkadot-node-subsystem = { path = "../subsystem" }
|
||||
polkadot-node-subsystem-types = { path = "../subsystem-types" }
|
||||
polkadot-node-jaeger = { path = "../jaeger" }
|
||||
polkadot-node-metrics = { path = "../metrics" }
|
||||
polkadot-node-network-protocol = { path = "../network/protocol" }
|
||||
@@ -33,6 +34,7 @@ metered = { package = "prioritized-metered-channel", version = "0.2.0" }
|
||||
sp-core = { path = "../../../substrate/primitives/core" }
|
||||
sp-application-crypto = { path = "../../../substrate/primitives/application-crypto" }
|
||||
sp-keystore = { path = "../../../substrate/primitives/keystore" }
|
||||
sc-client-api = { path = "../../../substrate/client/api" }
|
||||
|
||||
kvdb = "0.13.0"
|
||||
parity-db = { version = "0.4.8"}
|
||||
|
||||
@@ -28,6 +28,7 @@ use polkadot_node_subsystem::{
|
||||
messages::{RuntimeApiMessage, RuntimeApiRequest},
|
||||
overseer, SubsystemSender,
|
||||
};
|
||||
use polkadot_node_subsystem_types::UnpinHandle;
|
||||
use polkadot_primitives::{
|
||||
vstaging, CandidateEvent, CandidateHash, CoreState, EncodeAs, ExecutorParams, GroupIndex,
|
||||
GroupRotationInfo, Hash, IndexedVec, OccupiedCore, ScrapedOnChainVotes, SessionIndex,
|
||||
@@ -75,6 +76,10 @@ pub struct RuntimeInfo {
|
||||
/// Look up cached sessions by `SessionIndex`.
|
||||
session_info_cache: LruMap<SessionIndex, ExtendedSessionInfo>,
|
||||
|
||||
/// Unpin handle of *some* block in the session.
|
||||
/// Only blocks pinned explicitly by `pin_block` are stored here.
|
||||
pinned_blocks: LruMap<SessionIndex, UnpinHandle>,
|
||||
|
||||
/// Key store for determining whether we are a validator and what `ValidatorIndex` we have.
|
||||
keystore: Option<KeystorePtr>,
|
||||
}
|
||||
@@ -120,6 +125,7 @@ impl RuntimeInfo {
|
||||
Self {
|
||||
session_index_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size.max(10))),
|
||||
session_info_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
|
||||
pinned_blocks: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
|
||||
keystore: cfg.keystore,
|
||||
}
|
||||
}
|
||||
@@ -145,6 +151,17 @@ impl RuntimeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pin a given block in the given session if none are pinned in that session.
|
||||
/// Unpinning will happen automatically when LRU cache grows over the limit.
|
||||
pub fn pin_block(&mut self, session_index: SessionIndex, unpin_handle: UnpinHandle) {
|
||||
self.pinned_blocks.get_or_insert(session_index, || unpin_handle);
|
||||
}
|
||||
|
||||
/// Get the hash of a pinned block for the given session index, if any.
|
||||
pub fn get_block_in_session(&self, session_index: SessionIndex) -> Option<Hash> {
|
||||
self.pinned_blocks.peek(&session_index).map(|h| h.hash())
|
||||
}
|
||||
|
||||
/// Get `ExtendedSessionInfo` by relay parent hash.
|
||||
pub async fn get_session_info<'a, Sender>(
|
||||
&'a mut self,
|
||||
|
||||
Reference in New Issue
Block a user