Skip to content

Commit

Permalink
Move validators crate to tokio 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Valverde authored and styppo committed Jul 30, 2020
1 parent 6d662cf commit 97e7685
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
3 changes: 1 addition & 2 deletions validator/Cargo.toml
Expand Up @@ -14,12 +14,11 @@ maintenance = { status = "experimental" }

[dependencies]
failure = "0.1"
futures = "0.1"
hex = { version = "0.4", optional = true }
log = "0.4"
parking_lot = "0.9"
rand = "0.7"
tokio = "0.1"
tokio = { version = "0.2", features = ["rt-core"] }

beserial = { path = "../beserial", version = "0.1" }
nimiq-account = { path = "../primitives/account", version = "0.1" }
Expand Down
11 changes: 4 additions & 7 deletions validator/src/validator.rs
Expand Up @@ -5,7 +5,6 @@ use std::time::{Duration, Instant};

use parking_lot::RwLock;
use tokio;
use futures::future;

use account::Account;
use block_albatross::{
Expand Down Expand Up @@ -334,12 +333,11 @@ impl Validator {
let transaction = proof_builder.generate().unwrap();

let weak = self.self_weak.clone();
tokio::spawn(future::lazy(move || {
tokio::spawn(async move {
if let Some(this) = Weak::upgrade(&weak) {
this.consensus.mempool.push_transaction(transaction.clone());
}
Ok(())
}));
});
}
}
}
Expand Down Expand Up @@ -572,7 +570,7 @@ impl Validator {

let weak = self.self_weak.clone();
trace!("Spawning thread to produce next block");
tokio::spawn(futures::lazy(move || {
tokio::spawn(async move {
if let Some(this) = Weak::upgrade(&weak) {
match block_type {
BlockType::Macro => this.produce_macro_block(
Expand All @@ -587,8 +585,7 @@ impl Validator {
),
}
}
Ok(())
}));
});
}
}

Expand Down
11 changes: 3 additions & 8 deletions validator/src/validator_network.rs
Expand Up @@ -3,7 +3,6 @@ use std::fmt;
use std::sync::{Arc, Weak};

use failure::Fail;
use futures::future;
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
use tokio;

Expand Down Expand Up @@ -308,10 +307,7 @@ impl ValidatorNetwork {
}
ValidatorAgentEvent::ViewChangeProof(view_change_proof) => {
let ViewChangeProofMessage { view_change, proof } = *view_change_proof;
tokio::spawn(future::lazy(move || {
this.on_view_change_proof(view_change, proof);
Ok(())
}));
tokio::spawn(async move { this.on_view_change_proof(view_change, proof); });
}
ValidatorAgentEvent::PbftProposal(proposal) => {
this.on_pbft_proposal(*proposal)
Expand Down Expand Up @@ -877,11 +873,10 @@ impl ValidatorNetwork {
move |this, event| match event {
AggregationEvent::Complete { best } => {
let view_change = view_change.clone();
tokio::spawn(future::lazy(move || {
tokio::spawn(async move {
let proof = ViewChangeProof::new(best.signature, best.signers);
this.on_view_change_proof(view_change, proof);
Ok(())
}));
});
}
},
));
Expand Down

0 comments on commit 97e7685

Please sign in to comment.