referrerpolicy=no-referrer-when-downgrade

polkadot_collator_protocol/validator_side_experimental/peer_manager/
backend.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use crate::validator_side_experimental::{common::Score, peer_manager::ReputationUpdate};
18use async_trait::async_trait;
19use polkadot_node_network_protocol::PeerId;
20use polkadot_primitives::{BlockNumber, Id as ParaId};
21use std::collections::{BTreeMap, BTreeSet, HashMap};
22
23/// Trait describing the interface of the reputation database.
24#[async_trait]
25pub trait Backend {
26	/// Return the latest finalized block for which the backend processed bumps.
27	async fn processed_finalized_block_number(&self) -> Option<BlockNumber>;
28	/// Get the peer's stored reputation for this paraid, if any.
29	async fn query(&self, peer_id: &PeerId, para_id: &ParaId) -> Option<Score>;
30	/// Slash the peer's reputation for this paraid, with the given value.
31	async fn slash(&mut self, peer_id: &PeerId, para_id: &ParaId, value: Score);
32	/// Prune all data for paraids that are no longer in this registered set.
33	async fn prune_paras(&mut self, registered_paras: BTreeSet<ParaId>);
34	/// Process the reputation bumps, returning all the reputation changes that were done in
35	/// consequence. This is needed because a reputation bump for a para also means a reputation
36	/// decay for the other collators of that para (if the `decay_value` param is present) and
37	/// because if the number of stored reputations go over the `stored_limit_per_para`, we'll 100%
38	/// slash the least recently bumped peers. `leaf_number` needs to be at least equal to the
39	/// `processed_finalized_block_number`
40	async fn process_bumps(
41		&mut self,
42		leaf_number: BlockNumber,
43		bumps: BTreeMap<ParaId, HashMap<PeerId, Score>>,
44		decay_value: Option<Score>,
45	) -> Vec<ReputationUpdate>;
46}