Skip to content

Commit

Permalink
fix: fix dump to config (#1637)
Browse files Browse the repository at this point in the history
commit-id:6da233c9

Co-Authored-By: nadin-Starkware <nadin@starkware.co>
  • Loading branch information
Itay-Tsabary-Starkware and nadin-Starkware authored Oct 28, 2024
1 parent 4d70210 commit 3f750d8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 62 deletions.
17 changes: 4 additions & 13 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,9 @@
"value": 5
},
"mempool_p2p_config.network_config.discovery_config.bootstrap_dial_retry_config.max_delay": {
"description": "The maximum delay for the exponential backoff strategy.",
"description": "The maximum delay in seconds for the exponential backoff strategy.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 5
}
"value": 5
},
"mempool_p2p_config.network_config.discovery_config.heartbeat_interval": {
"description": "The interval between each discovery (Kademlia) query in milliseconds.",
Expand All @@ -710,18 +707,12 @@
"mempool_p2p_config.network_config.peer_manager_config.malicious_timeout": {
"description": "The duration a peer is blacklisted after being marked as malicious.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 31536000
}
"value": 31536000
},
"mempool_p2p_config.network_config.peer_manager_config.unstable_timeout": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 1
}
"value": 1
},
"mempool_p2p_config.network_config.quic_port": {
"description": "The port that the node listens on for incoming quic connections.",
Expand Down
19 changes: 5 additions & 14 deletions config/papyrus/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@
"value": 5
},
"network.discovery_config.bootstrap_dial_retry_config.max_delay": {
"description": "The maximum delay for the exponential backoff strategy.",
"description": "The maximum delay in seconds for the exponential backoff strategy.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 5
}
"value": 5
},
"network.discovery_config.heartbeat_interval": {
"description": "The interval between each discovery (Kademlia) query in milliseconds.",
Expand All @@ -205,18 +202,12 @@
"network.peer_manager_config.malicious_timeout": {
"description": "The duration a peer is blacklisted after being marked as malicious.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 31536000
}
"value": 31536000
},
"network.peer_manager_config.unstable_timeout": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"privacy": "Public",
"value": {
"nanos": 0,
"secs": 1
}
"value": 1
},
"network.quic_port": {
"description": "The port that the node listens on for incoming quic connections.",
Expand Down Expand Up @@ -433,4 +424,4 @@
"privacy": "Public",
"value": true
}
}
}
2 changes: 1 addition & 1 deletion crates/papyrus_network/src/discovery/discovery_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const BOOTSTRAP_DIAL_SLEEP: Duration = Duration::from_secs(1);
const CONFIG: DiscoveryConfig = DiscoveryConfig {
bootstrap_dial_retry_config: RetryConfig {
base_delay_millis: BOOTSTRAP_DIAL_SLEEP.as_millis() as u64,
max_delay: BOOTSTRAP_DIAL_SLEEP,
max_delay: BOOTSTRAP_DIAL_SLEEP.as_secs(),
factor: 1,
},
heartbeat_interval: Duration::ZERO,
Expand Down
8 changes: 4 additions & 4 deletions crates/papyrus_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ impl SerializeConfig for DiscoveryConfig {
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct RetryConfig {
pub base_delay_millis: u64,
pub max_delay: Duration,
pub max_delay: u64,
pub factor: u64,
}

impl Default for RetryConfig {
fn default() -> Self {
Self { base_delay_millis: 2, max_delay: Duration::from_secs(5), factor: 5 }
Self { base_delay_millis: 2, max_delay: 5, factor: 5 }
}
}

Expand All @@ -243,7 +243,7 @@ impl SerializeConfig for RetryConfig {
ser_param(
"max_delay",
&self.max_delay,
"The maximum delay for the exponential backoff strategy.",
"The maximum delay in seconds for the exponential backoff strategy.",
ParamPrivacyInput::Public,
),
ser_param(
Expand All @@ -259,7 +259,7 @@ impl SerializeConfig for RetryConfig {
impl RetryConfig {
fn strategy(&self) -> ExponentialBackoff {
ExponentialBackoff::from_millis(self.base_delay_millis)
.max_delay(self.max_delay)
.max_delay(Duration::from_secs(self.max_delay))
.factor(self.factor)
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/papyrus_network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub struct PeerManager {

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct PeerManagerConfig {
malicious_timeout: Duration,
unstable_timeout: Duration,
malicious_timeout: u64,
unstable_timeout: u64,
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -70,8 +70,8 @@ impl Default for PeerManagerConfig {
fn default() -> Self {
Self {
// 1 year.
malicious_timeout: Duration::from_secs(3600 * 24 * 365),
unstable_timeout: Duration::from_secs(1),
malicious_timeout: 3600 * 24 * 365,
unstable_timeout: 1,
}
}
}
Expand Down Expand Up @@ -216,12 +216,12 @@ impl PeerManager {
ReputationModifier::Misconduct { misconduct_score } => {
peer.report(misconduct_score);
if peer.is_malicious() {
peer.blacklist_peer(self.config.malicious_timeout);
peer.blacklist_peer(Duration::from_secs(self.config.malicious_timeout));
peer.reset_misconduct_score();
}
}
ReputationModifier::Unstable => {
peer.blacklist_peer(self.config.unstable_timeout);
peer.blacklist_peer(Duration::from_secs(self.config.unstable_timeout));
}
}
Ok(())
Expand Down
16 changes: 11 additions & 5 deletions crates/papyrus_network/src/peer_manager/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ async fn peer_assignment_no_peers() {

#[tokio::test]
async fn peer_assignment_no_unblocked_peers() {
const BLOCKED_UNTIL: Duration = Duration::from_secs(5);
const TIMEOUT: Duration = Duration::from_secs(1);
const BLOCKED_UNTIL: u64 = 5;
const TIMEOUT: u64 = 1;
// Create a new peer manager
let config = PeerManagerConfig { malicious_timeout: TIMEOUT, unstable_timeout: TIMEOUT };
let mut peer_manager: PeerManager = PeerManager::new(config.clone());
Expand All @@ -172,7 +172,10 @@ async fn peer_assignment_no_unblocked_peers() {
peer_manager.report_peer(peer_id, ReputationModifier::Unstable).unwrap();

// Consume the peer blacklisted event
let event = tokio::time::timeout(TIMEOUT, peer_manager.next()).await.unwrap().unwrap();
let event = tokio::time::timeout(Duration::from_secs(TIMEOUT), peer_manager.next())
.await
.unwrap()
.unwrap();
assert_matches!(
event,
ToSwarm::GenerateEvent(ToOtherBehaviourEvent::PeerBlacklisted { peer_id: event_peer_id })
Expand All @@ -185,11 +188,14 @@ async fn peer_assignment_no_unblocked_peers() {

// Simulate that BLOCKED_UNTIL has passed.
tokio::time::pause();
tokio::time::advance(BLOCKED_UNTIL).await;
tokio::time::advance(Duration::from_secs(BLOCKED_UNTIL)).await;
tokio::time::resume();

// After BLOCKED_UNTIL has passed, the peer manager can assign the session.
let event = tokio::time::timeout(TIMEOUT, peer_manager.next()).await.unwrap().unwrap();
let event = tokio::time::timeout(Duration::from_secs(TIMEOUT), peer_manager.next())
.await
.unwrap()
.unwrap();
assert_matches!(
event,
ToSwarm::GenerateEvent(ToOtherBehaviourEvent::SessionAssigned {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/papyrus_node/src/config/config_test.rs
assertion_line: 101
expression: dumped_default_config
---
{
Expand Down Expand Up @@ -211,14 +212,9 @@ expression: dumped_default_config
"privacy": "Public"
},
"network.discovery_config.bootstrap_dial_retry_config.max_delay": {
"description": "The maximum delay for the exponential backoff strategy.",
"description": "The maximum delay in seconds for the exponential backoff strategy.",
"value": {
"nanos": {
"$serde_json::private::Number": "0"
},
"secs": {
"$serde_json::private::Number": "5"
}
"$serde_json::private::Number": "5"
},
"privacy": "Public"
},
Expand All @@ -239,24 +235,14 @@ expression: dumped_default_config
"network.peer_manager_config.malicious_timeout": {
"description": "The duration a peer is blacklisted after being marked as malicious.",
"value": {
"nanos": {
"$serde_json::private::Number": "0"
},
"secs": {
"$serde_json::private::Number": "31536000"
}
"$serde_json::private::Number": "31536000"
},
"privacy": "Public"
},
"network.peer_manager_config.unstable_timeout": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"value": {
"nanos": {
"$serde_json::private::Number": "0"
},
"secs": {
"$serde_json::private::Number": "1"
}
"$serde_json::private::Number": "1"
},
"privacy": "Public"
},
Expand Down

0 comments on commit 3f750d8

Please sign in to comment.