Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8c83835
Dispute protocol.
eskimor Jun 14, 2021
125dd32
Dispute distribution protocol.
eskimor Jun 15, 2021
2c395e5
Get network requests routed.
eskimor Jun 15, 2021
7c53c69
WIP: Basic dispute sender logic.
eskimor Jun 15, 2021
0bd8713
Basic validator determination logic.
eskimor Jun 15, 2021
608f84c
WIP: Getting things to typecheck.
eskimor Jun 15, 2021
a78fbc9
Slightly larger timeout.
eskimor Jun 15, 2021
53f0c15
More typechecking stuff.
eskimor Jun 16, 2021
6abf1f3
Cleanup.
eskimor Jun 16, 2021
b541062
Finished most of the sending logic.
eskimor Jun 17, 2021
5883c08
Handle active leaves updates
eskimor Jun 17, 2021
4c4e3a7
Pass sessions in already.
eskimor Jun 17, 2021
bd8bb95
Startup dispute sending.
eskimor Jun 17, 2021
4ebe127
Provide incoming decoding facilities
eskimor Jun 18, 2021
95351bd
Relaxed runtime util requirements.
eskimor Jun 18, 2021
863b1d9
Better usability of incoming requests.
eskimor Jun 18, 2021
35d2cad
Add basic receiver functionality.
eskimor Jun 18, 2021
da8abac
Cleanup + fixes for sender.
eskimor Jun 18, 2021
c997aed
One more sender fix.
eskimor Jun 18, 2021
06770db
Start receiver.
eskimor Jun 18, 2021
2378c7e
Make sure to send responses back.
eskimor Jun 19, 2021
3910cf4
WIP: Exposed authority discovery
eskimor Jun 21, 2021
840a046
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jun 21, 2021
5b10c78
Make tests pass.
eskimor Jun 21, 2021
d2aa4ff
Fully featured receiver.
eskimor Jun 21, 2021
da4955d
Decrease cost of `NotAValidator`.
eskimor Jun 22, 2021
1fc9740
Make `RuntimeInfo` LRU cache size configurable.
eskimor Jun 22, 2021
9397e35
Cache more sessions.
eskimor Jun 22, 2021
ccbab3f
Fix collator protocol.
eskimor Jun 22, 2021
5db60d3
Disable metrics for now.
eskimor Jun 22, 2021
da20774
Make dispute-distribution a proper subsystem.
eskimor Jun 22, 2021
f9da3ae
Fix naming.
eskimor Jun 22, 2021
2231dc3
Code style fixes.
eskimor Jun 23, 2021
41c2801
Factored out 4x copied mock function.
eskimor Jun 23, 2021
3e91427
WIP: Tests.
eskimor Jun 23, 2021
8a3da18
Whitespace cleanup.
eskimor Jun 24, 2021
0b188cd
Accessor functions.
eskimor Jun 24, 2021
2637c1b
More testing.
eskimor Jun 24, 2021
3d09d48
More Debug instances.
eskimor Jun 25, 2021
def8772
Fix busy loop.
eskimor Jun 25, 2021
c7cdca9
Working tests.
eskimor Jun 29, 2021
b9f20c2
More tests.
eskimor Jun 30, 2021
6f7da40
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jun 30, 2021
b3c7427
Cleanup.
eskimor Jun 30, 2021
c01d8d1
Fix build.
eskimor Jun 30, 2021
4f616d6
Basic receiving test.
eskimor Jun 30, 2021
a3ff6ae
Non validator message gets dropped.
eskimor Jun 30, 2021
217bd7e
More receiving tests.
eskimor Jun 30, 2021
26b8b00
Test nested and subsequent imports.
eskimor Jun 30, 2021
5dd7c84
Fix spaces.
eskimor Jun 30, 2021
488fb47
Better formatted imports.
eskimor Jun 30, 2021
92ff4be
Import cleanup.
eskimor Jul 1, 2021
7d5f416
Metrics.
eskimor Jul 2, 2021
04f91e9
Message -> MuxedMessage
eskimor Jul 2, 2021
d43fb5f
Message -> MuxedMessage
eskimor Jul 2, 2021
dc6d0f1
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 2, 2021
fc6a612
More review remarks.
eskimor Jul 2, 2021
2907a53
Add missing metrics.rs.
eskimor Jul 2, 2021
1f7ce88
Fix flaky test.
eskimor Jul 2, 2021
cd66550
Dispute coordinator - deliver confirmations.
eskimor Jul 6, 2021
fd920a1
Send out `DisputeMessage` on issue local statement.
eskimor Jul 6, 2021
90b46f4
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 8, 2021
210b853
Unwire dispute distribution.
eskimor Jul 8, 2021
58b1bee
Review remarks.
eskimor Jul 8, 2021
59c76c8
Review remarks.
eskimor Jul 8, 2021
3cd91cb
Better docs.
eskimor Jul 8, 2021
dedbaa8
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle active leaves updates
- Cleanup dead disputes
- Update sends for new sessions
- Retry on errors
  • Loading branch information
eskimor committed Jun 17, 2021
commit 5883c088f93378eb364c674750cdeb1dc99a65d8
23 changes: 16 additions & 7 deletions node/network/dispute-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,22 @@ impl DisputeDistributionSubsystem {
signal: OverseerSignal
) -> SignalResult
{
// let result = match signal {
// OverseerSignal::Conclude => return SignalResult::Conclude,
// OverseerSignal::ActiveLeaves(update) => {
// }
// };
// SignalResult::Result(result)
panic!("WIP");
let result = match signal {
OverseerSignal::Conclude => return SignalResult::Conclude,
OverseerSignal::ActiveLeaves(update) => {
self.disputes_sender.update_leaves(
ctx,
&mut self.runtime,
update
)
.await
.map_err(From::from)
}
OverseerSignal::BlockFinalized(_,_) => {
Ok(())
}
};
SignalResult::Result(result)
}

/// Handle `DisputeDistributionMessage`s.
Expand Down
4 changes: 4 additions & 0 deletions node/network/dispute-distribution/src/sender/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub enum NonFatal {
#[error("No active heads available - needed for finding relevant authorities.")]
NoActiveHeads,

/// This error likely indicates a bug in the coordinator.
#[error("Oneshot for asking dispute coordinator for active disputes got canceled.")]
AskActiveDisputesCanceled,

/// Errors coming from runtime::Runtime.
#[error("Error while accessing runtime information")]
Runtime(#[from] #[source] runtime::NonFatal),
Expand Down
90 changes: 83 additions & 7 deletions node/network/dispute-distribution/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::collections::hash_map::Entry;

use futures::Future;
use futures::channel::mpsc;
use futures::channel::oneshot;
use futures::future::RemoteHandle;

use polkadot_node_network_protocol::IfDisconnected;
Expand All @@ -31,7 +32,9 @@ use polkadot_node_network_protocol::request_response::Requests;
use polkadot_node_network_protocol::request_response::v1::DisputeResponse;
use polkadot_node_primitives::DisputeMessage;
use polkadot_primitives::v1::{SessionIndex, AuthorityDiscoveryId};
use polkadot_subsystem::ActiveLeavesUpdate;
use polkadot_subsystem::messages::AllMessages;
use polkadot_subsystem::messages::DisputeCoordinatorMessage;
use polkadot_subsystem::messages::NetworkBridgeMessage;
use polkadot_node_network_protocol::request_response::v1::DisputeRequest;
use polkadot_primitives::v1::CandidateHash;
Expand Down Expand Up @@ -60,14 +63,16 @@ pub struct DisputeSender {
/// All heads we currently consider active.
active_heads: Vec<Hash>,

/// List of currently active sessions.
///
/// Value is the hash that was used for the query.
active_sessions: Vec<(SessionIndex, Hash)>,

/// All ongoing dispute sendings this subsystem is aware of.
sendings: HashMap<CandidateHash, SendTask>,

/// Sender to be cloned for `SendTask`s.
tx: mpsc::Sender<FromSendingTask>,

//// Receive messages from `SendTask`.
// rx: mpsc::Receiver<FromSendingTask>,
}

impl DisputeSender
Expand Down Expand Up @@ -111,6 +116,34 @@ impl DisputeSender
Ok(())
}

/// Take care of a change in active leaves.
///
/// - Initiate a retry of sends disputes are still active.
/// - Get new authorities to send messages to.
/// - Get rid of obsolete tasks and disputes.
pub async fn update_leaves<Context: SubsystemContext>(
&mut self,
ctx: &mut Context,
runtime: &mut RuntimeInfo,
update: ActiveLeavesUpdate,
) -> Result<()> {
let ActiveLeavesUpdate { activated, deactivated } = update;
let deactivated: HashSet<_> = deactivated.into_iter().collect();
self.active_heads.retain(|h| !deactivated.contains(h));
self.active_heads.extend(activated.into_iter().map(|l| l.hash));

let have_new_sessions = self.refresh_sessions(ctx, runtime).await?;

self.cleanup_dead_disputes(ctx).await?;

for send in self.sendings.values_mut() {
if have_new_sessions || send.has_failed_sends() {
send.refresh_sends(ctx, runtime, &self.active_heads).await?;
}
}
Ok(())
}

/// Receive message from a sending task.
pub async fn on_task_message(&mut self, msg: FromSendingTask) {
match msg {
Expand All @@ -131,18 +164,61 @@ impl DisputeSender
}
}
}

/// Make active sessions correspond to currently active heads.
///
/// Returns: true if sessions changed.
async fn refresh_sessions<Context: SubsystemContext>(
&mut self,
ctx: &mut Context,
runtime: &mut RuntimeInfo,
) -> Result<bool> {
let new_sessions = get_active_session_indeces(ctx, runtime, &self.active_heads).await?;
let new_sessions_raw: HashSet<_> =
new_sessions.iter().map(|(s,_)| s).collect();
let old_sessions_raw: HashSet<_> =
self.active_sessions.iter().map(|(s,_)| s).collect();
let updated = new_sessions_raw != old_sessions_raw;
// Update in any case, so we use current heads for queries:
self.active_sessions = new_sessions;
Ok(updated)
}

/// Query dispute coordinator for currently active disputes and get rid of all obsolete
/// senders.
async fn cleanup_dead_disputes<Context: SubsystemContext>(
&mut self,
ctx: &mut Context,
) -> Result<()> {
let active_disputes = get_active_disputes(ctx).await?;
self.sendings.retain(|candidate_hash, _| active_disputes.contains(candidate_hash));
Ok(())
}
}

/// Retrieve the currently active sessions.
///
/// List is all indeces of all active sessions together with the head that was used for the query.
async fn get_active_session_indeces<Context: SubsystemContext>(
ctx: &mut Context,
runtime: &mut RuntimeInfo,
active_heads: &Vec<Hash>,
) -> Result<HashSet<SessionIndex>> {
let mut indeces = HashSet::new();
) -> Result<Vec<(SessionIndex, Hash)>> {
let mut indeces = HashMap::new();
for head in active_heads {
let session_index = runtime.get_session_index(ctx, *head).await?;
indeces.insert(session_index);
indeces.insert(session_index, *head);
}
Ok(indeces)
Ok(indeces.into_iter().collect())
}

/// Retrieve Set of active disputes from the dispute coordinator.
async fn get_active_disputes<Context: SubsystemContext>(ctx: &mut Context)
-> Result<HashSet<CandidateHash>> {
let (tx, rx) = oneshot::channel();
ctx.send_message(AllMessages::DisputeCoordinator(
DisputeCoordinatorMessage::ActiveDisputes(tx)
)).await;
let disputes = rx.await.map_err(|_| NonFatal::AskActiveDisputesCanceled)?;
Ok(disputes.into_iter().map(|(_, c)| c).collect())
}
11 changes: 11 additions & 0 deletions node/network/dispute-distribution/src/sender/send_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct SendTask {
/// dispute happened and the authorities of the current sessions as determined by active heads.
deliveries: HashMap<AuthorityDiscoveryId, DeliveryStatus>,

/// Whether or not we have any tasks failed since the last refresh.
has_failed_sends: bool,

/// Sender to be cloned for tasks.
tx: mpsc::Sender<FromSendingTask>,
}
Expand Down Expand Up @@ -96,6 +99,7 @@ impl SendTask
let mut send_task = Self {
request,
deliveries: HashMap::new(),
has_failed_sends: false,
tx,
};
send_task.refresh_sends(
Expand Down Expand Up @@ -136,9 +140,15 @@ impl SendTask
).await?;

self.deliveries.extend(new_statuses.into_iter());
self.has_failed_sends = false;
Ok(())
}

/// Whether or not any sends have failed since the last refreshed.
pub fn has_failed_sends(&self) -> bool {
self.has_failed_sends
}

/// Handle a finished response waiting task.
pub fn on_finished_send(&mut self, authority: &AuthorityDiscoveryId, result: TaskResult) {
match result {
Expand All @@ -149,6 +159,7 @@ impl SendTask
?authority,
"Could not get our message out! If this keeps happening, then check chain whether the dispute made it there."
);
self.has_failed_sends = true;
// Remove state, so we know what to try again:
self.deliveries.remove(authority);
}
Expand Down