minor chore changes (#3944)

* chore: mild refactor, avoid the channel in handle_import_statements

* chore/md: lint
This commit is contained in:
Bernhard Schuster
2021-09-27 20:18:59 +02:00
committed by GitHub
parent 94986bec7e
commit d64394ef59
2 changed files with 12 additions and 27 deletions
@@ -537,7 +537,7 @@ async fn handle_incoming(
statements, statements,
pending_confirmation, pending_confirmation,
} => { } => {
handle_import_statements( let outcome = handle_import_statements(
ctx, ctx,
overlay_db, overlay_db,
state, state,
@@ -546,10 +546,10 @@ async fn handle_incoming(
session, session,
statements, statements,
now, now,
pending_confirmation,
metrics, metrics,
) )
.await?; .await?;
pending_confirmation.send(outcome).map_err(|_| Error::OneshotSend)?;
}, },
DisputeCoordinatorMessage::RecentDisputes(rx) => { DisputeCoordinatorMessage::RecentDisputes(rx) => {
let recent_disputes = overlay_db.load_recent_disputes()?.unwrap_or_default(); let recent_disputes = overlay_db.load_recent_disputes()?.unwrap_or_default();
@@ -648,14 +648,10 @@ async fn handle_import_statements(
now: Timestamp, now: Timestamp,
pending_confirmation: oneshot::Sender<ImportStatementsResult>, pending_confirmation: oneshot::Sender<ImportStatementsResult>,
metrics: &Metrics, metrics: &Metrics,
) -> Result<(), Error> { ) -> Result<ImportStatementsResult, Error> {
if state.highest_session.map_or(true, |h| session + DISPUTE_WINDOW < h) { if state.highest_session.map_or(true, |h| session + DISPUTE_WINDOW < h) {
// It is not valid to participate in an ancient dispute (spam?). // It is not valid to participate in an ancient dispute (spam?).
pending_confirmation return Ok(ImportStatementsResult::InvalidImport)
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;
return Ok(())
} }
let validators = match state.rolling_session_window.session_info(session) { let validators = match state.rolling_session_window.session_info(session) {
@@ -666,11 +662,7 @@ async fn handle_import_statements(
"Missing info for session which has an active dispute", "Missing info for session which has an active dispute",
); );
pending_confirmation return Ok(ImportStatementsResult::InvalidImport)
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;
return Ok(())
}, },
Some(info) => info.validators.clone(), Some(info) => info.validators.clone(),
}; };
@@ -795,15 +787,12 @@ async fn handle_import_statements(
// //
// We expect that if the candidate is truly disputed that the higher-level network // We expect that if the candidate is truly disputed that the higher-level network
// code will retry. // code will retry.
pending_confirmation
.send(ImportStatementsResult::InvalidImport)
.map_err(|_| Error::OneshotSend)?;
tracing::debug!( tracing::debug!(
target: LOG_TARGET, target: LOG_TARGET,
"Recovering availability failed - invalid import." "Recovering availability failed - invalid import."
); );
return Ok(()) return Ok(ImportStatementsResult::InvalidImport)
} }
metrics.on_open(); metrics.on_open();
@@ -821,11 +810,7 @@ async fn handle_import_statements(
overlay_db.write_candidate_votes(session, candidate_hash, votes.into()); overlay_db.write_candidate_votes(session, candidate_hash, votes.into());
pending_confirmation Ok(ImportStatementsResult::ValidImport)
.send(ImportStatementsResult::ValidImport)
.map_err(|_| Error::OneshotSend)?;
Ok(())
} }
fn find_controlled_validator_indices( fn find_controlled_validator_indices(
@@ -932,8 +917,7 @@ async fn issue_local_statement(
// Do import // Do import
if !statements.is_empty() { if !statements.is_empty() {
let (pending_confirmation, rx) = oneshot::channel(); match handle_import_statements(
handle_import_statements(
ctx, ctx,
overlay_db, overlay_db,
state, state,
@@ -942,11 +926,10 @@ async fn issue_local_statement(
session, session,
statements, statements,
now, now,
pending_confirmation,
metrics, metrics,
) )
.await?; .await?
match rx.await { {
Err(_) => { Err(_) => {
tracing::error!( tracing::error!(
target: LOG_TARGET, target: LOG_TARGET,
@@ -1,12 +1,14 @@
# How to run this collator # How to run this collator
First start two validators that will run for the relay chain: First start two validators that will run for the relay chain:
```sh ```sh
cargo run --release -- -d alice --chain rococo-local --validator --alice --port 50551 cargo run --release -- -d alice --chain rococo-local --validator --alice --port 50551
cargo run --release -- -d bob --chain rococo-local --validator --bob --port 50552 cargo run --release -- -d bob --chain rococo-local --validator --bob --port 50552
``` ```
Next start the collator that will collate for the adder parachain: Next start the collator that will collate for the adder parachain:
```sh ```sh
cargo run --release -p test-parachain-adder-collator -- --tmp --chain rococo-local --port 50553 cargo run --release -p test-parachain-adder-collator -- --tmp --chain rococo-local --port 50553
``` ```