Skip to content

Commit 343a04d

Browse files
paritytech-release-backport-bot[bot]AlexandruCihodarualindimatdimitrovserban300
authored
[stable2603] Backport #10917 (#11067)
Backport #10917 into `stable2603` from AlexandruCihodaru. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Signed-off-by: Alexandru Cihodaru <alexandru.cihodaru@parity.io> Co-authored-by: Alexandru Cihodaru <40807189+AlexandruCihodaru@users.noreply.github.com> Co-authored-by: alindima <alin@parity.io> Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io> Co-authored-by: Serban Iorga <serban@parity.io> Co-authored-by: Serban Iorga <serban300@gmail.com> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Egor_P <egor@parity.io>
1 parent f6dd735 commit 343a04d

File tree

27 files changed

+2236
-66
lines changed

27 files changed

+2236
-66
lines changed

.github/zombienet-tests/zombienet_polkadot_tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,8 @@
252252
test-filter: "functional::shared_core_idle_parachain::shared_core_idle_parachain_test"
253253
runner-type: "default"
254254
use-zombienet-sdk: true
255+
256+
- job-name: "zombienet-polkadot-collators-basic-reputation-persistence"
257+
test-filter: "functional::collators_reputation_persistence"
258+
runner-type: "default"
259+
use-zombienet-sdk: true

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/client/relay-chain-inprocess-interface/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ fn build_polkadot_full_node(
421421
invulnerable_ah_collators: HashSet::new(),
422422
collator_protocol_hold_off: None,
423423
experimental_collator_protocol: false,
424+
collator_reputation_persist_interval: None,
424425
};
425426

426427
let (relay_chain_full_node, paranode_req_receiver) = match config.network.network_backend {

polkadot/cli/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ pub struct RunCmd {
170170
/// Enable experimental collator protocol. TESTING ONLY! Don't use on production
171171
#[arg(long, hide = true, default_value = "false")]
172172
pub experimental_collator_protocol: bool,
173+
174+
/// Collator reputation persistence interval in seconds.
175+
/// If not specified, defaults to 600 seconds (10 minutes).
176+
/// This should be used only with experimental_collator_protocol
177+
/// and only on validators.
178+
#[arg(long, requires = "experimental_collator_protocol", requires = "validator")]
179+
pub collator_reputation_persist_interval: Option<u64>,
173180
}
174181

175182
#[allow(missing_docs)]

polkadot/cli/src/command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ where
294294
invulnerable_ah_collators,
295295
collator_protocol_hold_off,
296296
experimental_collator_protocol,
297+
collator_reputation_persist_interval: cli
298+
.run
299+
.collator_reputation_persist_interval
300+
.map(std::time::Duration::from_secs),
297301
},
298302
)
299303
.map(|full| full.task_manager)?;

polkadot/node/network/collator-protocol/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ sp-core = { workspace = true, default-features = true }
2323
sp-keystore = { workspace = true, default-features = true }
2424
sp-runtime = { workspace = true, default-features = true }
2525

26+
codec.workspace = true
2627
fatality = { workspace = true }
2728
polkadot-node-network-protocol = { workspace = true, default-features = true }
2829
polkadot-node-primitives = { workspace = true, default-features = true }
2930
polkadot-node-subsystem = { workspace = true, default-features = true }
3031
polkadot-node-subsystem-util = { workspace = true, default-features = true }
3132
polkadot-primitives = { workspace = true, default-features = true }
3233
thiserror = { workspace = true }
34+
tokio.workspace = true
3335
tokio-util = { workspace = true }
3436

3537
[dev-dependencies]
3638
assert_matches = { workspace = true }
39+
kvdb-memorydb = { workspace = true }
3740
rstest = { workspace = true }
3841
sc-network-types = { workspace = true, default-features = true }
3942
sp-tracing = { workspace = true }

polkadot/node/network/collator-protocol/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use std::{
2525
collections::HashSet,
26+
sync::Arc,
2627
time::{Duration, Instant},
2728
};
2829

@@ -31,16 +32,16 @@ use futures::{
3132
FutureExt, TryFutureExt,
3233
};
3334

34-
use polkadot_node_subsystem_util::reputation::ReputationAggregator;
35+
use polkadot_node_subsystem_util::{database::Database, reputation::ReputationAggregator};
3536
use sp_keystore::KeystorePtr;
3637

3738
use polkadot_node_network_protocol::{
3839
request_response::{v2 as protocol_v2, IncomingRequestReceiver},
3940
PeerId, UnifiedReputationChange as Rep,
4041
};
41-
use polkadot_primitives::CollatorPair;
42-
4342
use polkadot_node_subsystem::{errors::SubsystemError, overseer, DummySubsystem, SpawnedSubsystem};
43+
use polkadot_primitives::CollatorPair;
44+
pub use validator_side_experimental::ReputationConfig;
4445

4546
mod collator_side;
4647
mod validator_side;
@@ -91,6 +92,10 @@ pub enum ProtocolSide {
9192
keystore: KeystorePtr,
9293
/// Prometheus metrics for validators.
9394
metrics: validator_side_experimental::Metrics,
95+
/// Database used for reputation house keeping.
96+
db: Arc<dyn Database>,
97+
/// Reputation configuration (column number).
98+
reputation_config: validator_side_experimental::ReputationConfig,
9499
},
95100
/// Collators operate on a parachain.
96101
Collator {
@@ -148,8 +153,8 @@ impl<Context> CollatorProtocolSubsystem {
148153
.map_err(|e| SubsystemError::with_origin("collator-protocol", e))
149154
.boxed()
150155
},
151-
ProtocolSide::ValidatorExperimental { keystore, metrics } => {
152-
validator_side_experimental::run(ctx, keystore, metrics)
156+
ProtocolSide::ValidatorExperimental { keystore, metrics, db, reputation_config } => {
157+
validator_side_experimental::run(ctx, keystore, metrics, db, reputation_config)
153158
.map_err(|e| SubsystemError::with_origin("collator-protocol", e))
154159
.boxed()
155160
},

polkadot/node/network/collator-protocol/src/validator_side_experimental/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use codec::{Decode, Encode};
1718
use polkadot_node_network_protocol::{
1819
peer_set::CollationVersion,
1920
request_response::{outgoing::RequestError, v2 as request_v2},
@@ -84,7 +85,7 @@ pub const MAX_FETCH_DELAY: Duration = Duration::from_millis(300);
8485
pub const MIN_FETCH_TIMER_DELAY: Duration = Duration::from_millis(150);
8586

8687
/// Reputation score type.
87-
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy, Default)]
88+
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy, Default, Encode, Decode)]
8889
pub struct Score(u16);
8990

9091
impl Score {

polkadot/node/network/collator-protocol/src/validator_side_experimental/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use crate::LOG_TARGET;
17+
use crate::{validator_side_experimental::peer_manager::PersistenceError, LOG_TARGET};
1818
use fatality::Nested;
1919
use polkadot_node_subsystem::{ChainApiError, SubsystemError};
2020
use polkadot_node_subsystem_util::{backing_implicit_view, runtime};
@@ -44,6 +44,12 @@ pub enum Error {
4444
#[fatal]
4545
#[error("Receiving message from overseer failed: {0}")]
4646
SubsystemReceive(#[source] SubsystemError),
47+
#[fatal]
48+
#[error("Failed to initialize reputation database: {0}")]
49+
ReputationDbInit(PersistenceError),
50+
#[fatal]
51+
#[error("Failed to spawn background task: {0}")]
52+
SpawnTask(String),
4753
#[error("Unable to retrieve block number for {0:?} from implicit view")]
4854
BlockNumberNotFoundInImplicitView(Hash),
4955
#[fatal(forward)]

0 commit comments

Comments
 (0)