mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Upgrade from futures-preview to futures 0.3.1, and remove futures 0.1 where currently possible (#4083)
* Migrate node and node-template * Migrate srml * Simple changes * Add async-std for interval * Fix test-runtime warning * Small changes * move futures01 in core/rpc to dev-deps * Change wasm CI builds * Switch to async-std 1.0.1 * Remove async-std dep of network * Add modified lockfile * Fix node cli browser build * Remove authority-discovery async-std dep * Add Send + Sync to interval dyn stream
This commit is contained in:
@@ -51,9 +51,8 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use futures::task::{Context, Poll};
|
||||
use futures::Future;
|
||||
use futures_timer::Interval;
|
||||
use futures::prelude::*;
|
||||
use futures::{Future, FutureExt, Stream, StreamExt};
|
||||
use futures_timer::Delay;
|
||||
|
||||
use authority_discovery_primitives::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair};
|
||||
use client_api::blockchain::HeaderBackend;
|
||||
@@ -68,6 +67,8 @@ use prost::Message;
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi};
|
||||
|
||||
type Interval = Box<dyn Stream<Item = ()> + Unpin + Send + Sync>;
|
||||
|
||||
mod error;
|
||||
/// Dht payload schemas generated from Protobuf definitions via Prost crate in build.rs.
|
||||
mod schema {
|
||||
@@ -129,14 +130,14 @@ where
|
||||
// Kademlia's default time-to-live for Dht records is 36h, republishing records every 24h. Given that a node
|
||||
// could restart at any point in time, one can not depend on the republishing process, thus publishing own
|
||||
// external addresses should happen on an interval < 36h.
|
||||
let publish_interval = Interval::new_at(
|
||||
let publish_interval = interval_at(
|
||||
Instant::now() + LIBP2P_KADEMLIA_BOOTSTRAP_TIME,
|
||||
Duration::from_secs(12 * 60 * 60),
|
||||
);
|
||||
|
||||
// External addresses of other authorities can change at any given point in time. The interval on which to query
|
||||
// for external addresses of other authorities is a trade off between efficiency and performance.
|
||||
let query_interval = Interval::new_at(
|
||||
let query_interval = interval_at(
|
||||
Instant::now() + LIBP2P_KADEMLIA_BOOTSTRAP_TIME,
|
||||
Duration::from_secs(10 * 60),
|
||||
);
|
||||
@@ -455,6 +456,19 @@ fn hash_authority_id(id: &[u8]) -> Result<libp2p::kad::record::Key> {
|
||||
.map_err(Error::HashingAuthorityId)
|
||||
}
|
||||
|
||||
fn interval_at(start: Instant, duration: Duration) -> Interval {
|
||||
let stream = futures::stream::unfold((), move |_| {
|
||||
let wait_time = start.saturating_duration_since(Instant::now());
|
||||
|
||||
futures::future::join(
|
||||
Delay::new(wait_time),
|
||||
Delay::new(duration)
|
||||
).map(|_| Some(((), ())))
|
||||
}).map(drop);
|
||||
|
||||
Box::new(stream)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user