mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
Introduce Notification block pinning limit (#2935)
While investigating some pruning issues I found some room for improvement in the notification pin handling. **Problem:** It was not possible to define an upper limit on notification pins. The block pinning cache has a limit, but only handles bodies and justifications. After this PR, bookkeeping for notifications is managed in the pinning worker. A limit can be defined in the worker. If that limit is crossed, blocks that were pinned for that notification are unpinned, which now affects the state as well as bodies and justifications. The pinned blocks cache still has a limit, but should never be hit. closes #19 --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -278,7 +278,7 @@ impl fmt::Display for UsageInfo {
|
||||
pub struct UnpinHandleInner<Block: BlockT> {
|
||||
/// Hash of the block pinned by this handle
|
||||
hash: Block::Hash,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> Debug for UnpinHandleInner<Block> {
|
||||
@@ -291,7 +291,7 @@ impl<Block: BlockT> UnpinHandleInner<Block> {
|
||||
/// Create a new [`UnpinHandleInner`]
|
||||
pub fn new(
|
||||
hash: Block::Hash,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
) -> Self {
|
||||
Self { hash, unpin_worker_sender }
|
||||
}
|
||||
@@ -299,12 +299,25 @@ impl<Block: BlockT> UnpinHandleInner<Block> {
|
||||
|
||||
impl<Block: BlockT> Drop for UnpinHandleInner<Block> {
|
||||
fn drop(&mut self) {
|
||||
if let Err(err) = self.unpin_worker_sender.unbounded_send(self.hash) {
|
||||
if let Err(err) =
|
||||
self.unpin_worker_sender.unbounded_send(UnpinWorkerMessage::Unpin(self.hash))
|
||||
{
|
||||
log::debug!(target: "db", "Unable to unpin block with hash: {}, error: {:?}", self.hash, err);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Message that signals notification-based pinning actions to the pinning-worker.
|
||||
///
|
||||
/// When the notification is dropped, an `Unpin` message should be sent to the worker.
|
||||
#[derive(Debug)]
|
||||
pub enum UnpinWorkerMessage<Block: BlockT> {
|
||||
/// Should be sent when a import or finality notification is created.
|
||||
AnnouncePin(Block::Hash),
|
||||
/// Should be sent when a import or finality notification is dropped.
|
||||
Unpin(Block::Hash),
|
||||
}
|
||||
|
||||
/// Keeps a specific block pinned while the handle is alive.
|
||||
/// Once the last handle instance for a given block is dropped, the
|
||||
/// block is unpinned in the [`Backend`](crate::backend::Backend::unpin_block).
|
||||
@@ -315,7 +328,7 @@ impl<Block: BlockT> UnpinHandle<Block> {
|
||||
/// Create a new [`UnpinHandle`]
|
||||
pub fn new(
|
||||
hash: Block::Hash,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
) -> UnpinHandle<Block> {
|
||||
UnpinHandle(Arc::new(UnpinHandleInner::new(hash, unpin_worker_sender)))
|
||||
}
|
||||
@@ -353,7 +366,7 @@ impl<Block: BlockT> BlockImportNotification<Block> {
|
||||
header: Block::Header,
|
||||
is_new_best: bool,
|
||||
tree_route: Option<Arc<sp_blockchain::TreeRoute<Block>>>,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
hash,
|
||||
@@ -412,7 +425,7 @@ impl<Block: BlockT> FinalityNotification<Block> {
|
||||
/// Create finality notification from finality summary.
|
||||
pub fn from_summary(
|
||||
mut summary: FinalizeSummary<Block>,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
) -> FinalityNotification<Block> {
|
||||
let hash = summary.finalized.pop().unwrap_or_default();
|
||||
FinalityNotification {
|
||||
@@ -436,7 +449,7 @@ impl<Block: BlockT> BlockImportNotification<Block> {
|
||||
/// Create finality notification from finality summary.
|
||||
pub fn from_summary(
|
||||
summary: ImportSummary<Block>,
|
||||
unpin_worker_sender: TracingUnboundedSender<Block::Hash>,
|
||||
unpin_worker_sender: TracingUnboundedSender<UnpinWorkerMessage<Block>>,
|
||||
) -> BlockImportNotification<Block> {
|
||||
let hash = summary.hash;
|
||||
BlockImportNotification {
|
||||
|
||||
Reference in New Issue
Block a user