Repository navigation
fix(dash-spv): keep re-queued work off kicked peers #1387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81acc28
6c0134c
d8f5119
63ef6d1
b210260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1093,15 +1093,15 @@ fn spawn_timeout_monitor(state: Arc<NetworkState>, shutdown: CancellationToken) | |||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Re-queue every on-wire request of a culprit (fresh ones too: the connection is | ||||||||||||||||||||||||||||||||
| // going away), keeping keys as Queued so de-dup holds. | ||||||||||||||||||||||||||||||||
| let retried = broker.requeue_from(&culprits).await; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Drop culprits still in the set (some may already be gone). | ||||||||||||||||||||||||||||||||
| // Drop culprits still in the set (some may already be gone) before their work | ||||||||||||||||||||||||||||||||
| // is re-queued, so the router cannot hand it back to them. | ||||||||||||||||||||||||||||||||
| let (kicked, remaining) = connected.remove(&culprits).await; | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ Suggestion, not blocking · Testing · Moderate No test covers the reordered kick sequence in the timeout monitor Why: The main fix moves How to fix it, why, 6 places read, and 3 other checksHow to fix it Why it matters Checked in the code
rust-dashcore/dash-spv/src/network/broker.rs Lines 671 to 675 in d8f5119
The rust-dashcore/dash-spv/src/network/manager.rs Lines 1271 to 1275 in d8f5119
rust-dashcore/dash-spv/src/network/manager.rs Lines 1103 to 1107 in d8f5119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This round raises this problem again as a warning. Regression test does not fail when the reorder in the timeout monitor is reverted What goes wrong: Fix: Make the test force the router to run between the requeue and the removal, or drive the old interleaving directly. For example, run on a multi-thread runtime, or have the router hold a pre-kick snapshot and call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Partly fixed. Still open: Nothing fails if the monitor goes back to re-queuing work before it removes and closes the culprits, so the reorder has no working regression test. |
||||||||||||||||||||||||||||||||
| for peer in &kicked { | ||||||||||||||||||||||||||||||||
| peer.close(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| // Re-queue every on-wire request of a culprit (fresh ones too: the connection is | ||||||||||||||||||||||||||||||||
| // going away), keeping keys as Queued so de-dup holds. | ||||||||||||||||||||||||||||||||
| let retried = broker.requeue_from(&culprits).await; | ||||||||||||||||||||||||||||||||
|
xdustinface marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||
| let dropped = kicked.len(); | ||||||||||||||||||||||||||||||||
| for peer in &culprits { | ||||||||||||||||||||||||||||||||
| bans.ban(peer.addr(), Ban::Kicked).await; | ||||||||||||||||||||||||||||||||
|
|
@@ -1327,6 +1327,8 @@ mod tests { | |||||||||||||||||||||||||||||||
| use dashcore::network::message_filter::{CFilter, GetCFilters}; | ||||||||||||||||||||||||||||||||
| use dashcore::BlockHash; | ||||||||||||||||||||||||||||||||
| use test_case::test_case; | ||||||||||||||||||||||||||||||||
| use tokio::task; | ||||||||||||||||||||||||||||||||
| use tokio::time; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| fn get_cfilters(start: u32) -> NetworkMessage { | ||||||||||||||||||||||||||||||||
| NetworkMessage::GetCFilters(GetCFilters { | ||||||||||||||||||||||||||||||||
|
|
@@ -1580,6 +1582,46 @@ mod tests { | |||||||||||||||||||||||||||||||
| assert_eq!(net.state.broker.len(), stalls as usize); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// A timeout kick re-queues the stalled peer's work only once that peer is closed and out | ||||||||||||||||||||||||||||||||
| /// of the set, so no router snapshot can hand the work back. Holding the filter queue | ||||||||||||||||||||||||||||||||
| /// stops the monitor at that point. The work then goes to the peer that stays. | ||||||||||||||||||||||||||||||||
| #[tokio::test(start_paused = true)] | ||||||||||||||||||||||||||||||||
| async fn a_kicked_peer_gets_none_of_its_requeued_work() { | ||||||||||||||||||||||||||||||||
| let net = broker().await; | ||||||||||||||||||||||||||||||||
| let session = net.session.lock().await.clone(); | ||||||||||||||||||||||||||||||||
| let mut handles = Vec::new(); | ||||||||||||||||||||||||||||||||
| for n in 1..=2 { | ||||||||||||||||||||||||||||||||
| let peer = ConnectedPeer::for_test(conn(n, 0)).await; | ||||||||||||||||||||||||||||||||
| handles.push(peer.handle()); | ||||||||||||||||||||||||||||||||
| let admitted = | ||||||||||||||||||||||||||||||||
| net.state.connected.admit(peer, &session, net.state.max_peers, None).await; | ||||||||||||||||||||||||||||||||
| assert!(matches!(admitted, Admission::Joined)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| net.state.broker.mark_on_wire(&get_cfilters(0), conn(1, 0)).await; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let held = net.state.broker.hold_queue_of(&get_cfilters(0)).await; | ||||||||||||||||||||||||||||||||
| time::advance(REQUEST_TIMEOUT + TIMEOUT_CHECK * 2).await; | ||||||||||||||||||||||||||||||||
| for _ in 0..4 { | ||||||||||||||||||||||||||||||||
| task::yield_now().await; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| let key = RequestKey::CFilters(0); | ||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||
| net.state.broker.state_of(&key).await, | ||||||||||||||||||||||||||||||||
| Some("queued"), | ||||||||||||||||||||||||||||||||
| "the monitor reached the re-queue" | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| assert_eq!(net.connected_count().await, 1, "re-queued before the kick"); | ||||||||||||||||||||||||||||||||
| assert!(handles[0].is_closed(), "re-queued before the stalled peer was closed"); | ||||||||||||||||||||||||||||||||
| drop(held); | ||||||||||||||||||||||||||||||||
| for _ in 0..4 { | ||||||||||||||||||||||||||||||||
| task::yield_now().await; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assert_eq!(net.state.broker.state_of(&key).await, Some("on_wire")); | ||||||||||||||||||||||||||||||||
| assert_eq!(handles[0].in_flight_bytes(), 0, "work went back to the kicked peer"); | ||||||||||||||||||||||||||||||||
| assert!(handles[1].in_flight_bytes() > 0, "the peer that stays carries the work"); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// A peer that was silent while idle is timed from the request it is given, and | ||||||||||||||||||||||||||||||||
| /// kicked only when it stays silent with that work for the full timeout. | ||||||||||||||||||||||||||||||||
| #[tokio::test(start_paused = true)] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.