Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
minor chore changes (#3944)
Browse files Browse the repository at this point in the history
* chore: mild refactor, avoid the channel in handle_import_statements

* chore/md: lint
  • Loading branch information
drahnr authored Sep 27, 2021
1 parent 2257112 commit 1d05f77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
37 changes: 10 additions & 27 deletions node/core/dispute-coordinator/src/real/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ async fn handle_incoming(
statements,
pending_confirmation,
} => {
handle_import_statements(
let outcome = handle_import_statements(
ctx,
overlay_db,
state,
Expand All @@ -546,10 +546,10 @@ async fn handle_incoming(
session,
statements,
now,
pending_confirmation,
metrics,
)
.await?;
pending_confirmation.send(outcome).map_err(|_| Error::OneshotSend)?;
},
DisputeCoordinatorMessage::RecentDisputes(rx) => {
let recent_disputes = overlay_db.load_recent_disputes()?.unwrap_or_default();
Expand Down Expand Up @@ -648,14 +648,10 @@ async fn handle_import_statements(
now: Timestamp,
pending_confirmation: oneshot::Sender<ImportStatementsResult>,
metrics: &Metrics,
) -> Result<(), Error> {
) -> Result<ImportStatementsResult, Error> {
if state.highest_session.map_or(true, |h| session + DISPUTE_WINDOW < h) {
// It is not valid to participate in an ancient dispute (spam?).
pending_confirmation
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;

return Ok(())
return Ok(ImportStatementsResult::InvalidImport)
}

let validators = match state.rolling_session_window.session_info(session) {
Expand All @@ -666,11 +662,7 @@ async fn handle_import_statements(
"Missing info for session which has an active dispute",
);

pending_confirmation
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;

return Ok(())
return Ok(ImportStatementsResult::InvalidImport)
},
Some(info) => info.validators.clone(),
};
Expand Down Expand Up @@ -795,15 +787,12 @@ async fn handle_import_statements(
//
// We expect that if the candidate is truly disputed that the higher-level network
// code will retry.
pending_confirmation
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;

tracing::debug!(
target: LOG_TARGET,
"Recovering availability failed - invalid import."
);
return Ok(())
return Ok(ImportStatementsResult::InvalidImport)
}
metrics.on_open();

Expand All @@ -821,11 +810,7 @@ async fn handle_import_statements(

overlay_db.write_candidate_votes(session, candidate_hash, votes.into());

pending_confirmation
.send(ImportStatementsResult::ValidImport)
.map_err(|_| Error::OneshotSend)?;

Ok(())
Ok(ImportStatementsResult::ValidImport)
}

fn find_controlled_validator_indices(
Expand Down Expand Up @@ -932,8 +917,7 @@ async fn issue_local_statement(

// Do import
if !statements.is_empty() {
let (pending_confirmation, rx) = oneshot::channel();
handle_import_statements(
match handle_import_statements(
ctx,
overlay_db,
state,
Expand All @@ -942,11 +926,10 @@ async fn issue_local_statement(
session,
statements,
now,
pending_confirmation,
metrics,
)
.await?;
match rx.await {
.await?
{
Err(_) => {
tracing::error!(
target: LOG_TARGET,
Expand Down
2 changes: 2 additions & 0 deletions parachain/test-parachains/adder/collator/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# How to run this collator

First start two validators that will run for the relay chain:

```sh
cargo run --release -- -d alice --chain rococo-local --validator --alice --port 50551
cargo run --release -- -d bob --chain rococo-local --validator --bob --port 50552
```

Next start the collator that will collate for the adder parachain:

```sh
cargo run --release -p test-parachain-adder-collator -- --tmp --chain rococo-local --port 50553
```
Expand Down

0 comments on commit 1d05f77

Please sign in to comment.