Run cargo fix on a few of the worst offenders (#10854)

* Run cargo fix on `vm`

* Run cargo fix on ethcore-db

* Run cargo fix on evm

* Run cargo fix on ethcore-light

* Run cargo fix on journaldb

* Run cargo fix on wasm

* Missing docs

* Run cargo fix on ethcore-sync
This commit is contained in:
David
2019-07-09 10:04:20 +02:00
committed by Seun LanLege
parent fdc7b0fdaa
commit f53c3e582c
46 changed files with 369 additions and 368 deletions

View File

@@ -74,7 +74,7 @@ impl<DB: HashDB<KeccakHasher, DBValue>> CHT<DB> {
if block_to_cht_number(num) != Some(self.number) { return Ok(None) }
let mut recorder = Recorder::with_depth(from_level);
let db: &HashDB<_,_> = &self.db;
let db: &dyn HashDB<_,_> = &self.db;
let t = TrieDB::new(&db, &self.root)?;
t.get_with(&key!(num), &mut recorder)?;

View File

@@ -47,8 +47,8 @@ pub trait ChainDataFetcher: Send + Sync + 'static {
fn epoch_transition(
&self,
_hash: H256,
_engine: Arc<Engine>,
_checker: Arc<StateDependentProof>
_engine: Arc<dyn Engine>,
_checker: Arc<dyn StateDependentProof>
) -> Self::Transition;
}
@@ -76,8 +76,8 @@ impl ChainDataFetcher for Unavailable {
fn epoch_transition(
&self,
_hash: H256,
_engine: Arc<Engine>,
_checker: Arc<StateDependentProof>
_engine: Arc<dyn Engine>,
_checker: Arc<dyn StateDependentProof>
) -> Self::Transition {
Err("fetching epoch transition proofs unavailable")
}

View File

@@ -213,7 +213,7 @@ pub struct HeaderChain {
#[ignore_malloc_size_of = "ignored for performance reason"]
live_epoch_proofs: RwLock<H256FastMap<EpochTransition>>,
#[ignore_malloc_size_of = "ignored for performance reason"]
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
#[ignore_malloc_size_of = "ignored for performance reason"]
col: Option<u32>,
#[ignore_malloc_size_of = "ignored for performance reason"]
@@ -223,7 +223,7 @@ pub struct HeaderChain {
impl HeaderChain {
/// Create a new header chain given this genesis block and database to read from.
pub fn new(
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
col: Option<u32>,
spec: &Spec,
cache: Arc<Mutex<Cache>>,
@@ -880,7 +880,7 @@ mod tests {
use std::time::Duration;
use parking_lot::Mutex;
fn make_db() -> Arc<KeyValueDB> {
fn make_db() -> Arc<dyn KeyValueDB> {
Arc::new(kvdb_memorydb::create(0))
}

View File

@@ -79,7 +79,7 @@ impl Default for Config {
/// Trait for interacting with the header chain abstractly.
pub trait LightChainClient: Send + Sync {
/// Adds a new `LightChainNotify` listener.
fn add_listener(&self, listener: Weak<LightChainNotify>);
fn add_listener(&self, listener: Weak<dyn LightChainNotify>);
/// Get chain info.
fn chain_info(&self) -> BlockChainInfo;
@@ -104,7 +104,7 @@ pub trait LightChainClient: Send + Sync {
fn score(&self, id: BlockId) -> Option<U256>;
/// Get an iterator over a block and its ancestry.
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<Iterator<Item=encoded::Header> + 'a>;
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<dyn Iterator<Item=encoded::Header> + 'a>;
/// Get the signing chain ID.
fn signing_chain_id(&self) -> Option<u64>;
@@ -114,7 +114,7 @@ pub trait LightChainClient: Send + Sync {
fn env_info(&self, id: BlockId) -> Option<EnvInfo>;
/// Get a handle to the consensus engine.
fn engine(&self) -> &Arc<Engine>;
fn engine(&self) -> &Arc<dyn Engine>;
/// Query whether a block is known.
fn is_known(&self, hash: &H256) -> bool;
@@ -159,23 +159,23 @@ impl<T: LightChainClient> AsLightClient for T {
/// Light client implementation.
pub struct Client<T> {
queue: HeaderQueue,
engine: Arc<Engine>,
engine: Arc<dyn Engine>,
chain: HeaderChain,
report: RwLock<ClientReport>,
import_lock: Mutex<()>,
db: Arc<KeyValueDB>,
listeners: RwLock<Vec<Weak<LightChainNotify>>>,
db: Arc<dyn KeyValueDB>,
listeners: RwLock<Vec<Weak<dyn LightChainNotify>>>,
fetcher: T,
verify_full: bool,
/// A closure to call when we want to restart the client
exit_handler: Mutex<Option<Box<Fn(String) + 'static + Send>>>,
exit_handler: Mutex<Option<Box<dyn Fn(String) + 'static + Send>>>,
}
impl<T: ChainDataFetcher> Client<T> {
/// Create a new `Client`.
pub fn new(
config: Config,
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
chain_col: Option<u32>,
spec: &Spec,
fetcher: T,
@@ -208,7 +208,7 @@ impl<T: ChainDataFetcher> Client<T> {
}
/// Adds a new `LightChainNotify` listener.
pub fn add_listener(&self, listener: Weak<LightChainNotify>) {
pub fn add_listener(&self, listener: Weak<dyn LightChainNotify>) {
self.listeners.write().push(listener);
}
@@ -375,7 +375,7 @@ impl<T: ChainDataFetcher> Client<T> {
}
/// Get a handle to the verification engine.
pub fn engine(&self) -> &Arc<Engine> {
pub fn engine(&self) -> &Arc<dyn Engine> {
&self.engine
}
@@ -416,7 +416,7 @@ impl<T: ChainDataFetcher> Client<T> {
Arc::new(v)
}
fn notify<F: Fn(&LightChainNotify)>(&self, f: F) {
fn notify<F: Fn(&dyn LightChainNotify)>(&self, f: F) {
for listener in &*self.listeners.read() {
if let Some(listener) = listener.upgrade() {
f(&*listener)
@@ -536,7 +536,7 @@ impl<T: ChainDataFetcher> Client<T> {
impl<T: ChainDataFetcher> LightChainClient for Client<T> {
fn add_listener(&self, listener: Weak<LightChainNotify>) {
fn add_listener(&self, listener: Weak<dyn LightChainNotify>) {
Client::add_listener(self, listener)
}
@@ -566,7 +566,7 @@ impl<T: ChainDataFetcher> LightChainClient for Client<T> {
Client::score(self, id)
}
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<Iterator<Item=encoded::Header> + 'a> {
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<dyn Iterator<Item=encoded::Header> + 'a> {
Box::new(Client::ancestry_iter(self, start))
}
@@ -578,7 +578,7 @@ impl<T: ChainDataFetcher> LightChainClient for Client<T> {
Client::env_info(self, id)
}
fn engine(&self) -> &Arc<Engine> {
fn engine(&self) -> &Arc<dyn Engine> {
Client::engine(self)
}
@@ -633,7 +633,7 @@ impl<T: ChainDataFetcher> ::ethcore::client::EngineClient for Client<T> {
})
}
fn as_full_client(&self) -> Option<&::ethcore::client::BlockChainClient> {
fn as_full_client(&self) -> Option<&dyn (::ethcore::client::BlockChainClient)> {
None
}

View File

@@ -65,7 +65,7 @@ pub struct Service<T> {
impl<T: ChainDataFetcher> Service<T> {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, db: Arc<BlockChainDB>, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, db: Arc<dyn BlockChainDB>, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
let io_service = IoService::<ClientIoMessage>::start().map_err(Error::Io)?;
let client = Arc::new(Client::new(config,
db.key_value().clone(),
@@ -85,12 +85,12 @@ impl<T: ChainDataFetcher> Service<T> {
}
/// Set the actor to be notified on certain chain events
pub fn add_notify(&self, notify: Arc<LightChainNotify>) {
pub fn add_notify(&self, notify: Arc<dyn LightChainNotify>) {
self.client.add_listener(Arc::downgrade(&notify));
}
/// Register an I/O handler on the service.
pub fn register_handler(&self, handler: Arc<IoHandler<ClientIoMessage> + Send>) -> Result<(), IoError> {
pub fn register_handler(&self, handler: Arc<dyn IoHandler<ClientIoMessage> + Send>) -> Result<(), IoError> {
self.io_service.register_handler(handler)
}

View File

@@ -116,13 +116,13 @@ pub trait EventContext: BasicContext {
fn peer(&self) -> PeerId;
/// Treat the event context as a basic context.
fn as_basic(&self) -> &BasicContext;
fn as_basic(&self) -> &dyn BasicContext;
}
/// Basic context.
pub struct TickCtx<'a> {
/// Io context to enable dispatch.
pub io: &'a IoContext,
pub io: &'a dyn IoContext,
/// Protocol implementation.
pub proto: &'a LightProtocol,
}
@@ -153,7 +153,7 @@ impl<'a> BasicContext for TickCtx<'a> {
/// an io context.
pub struct Ctx<'a> {
/// Io context to enable immediate response to events.
pub io: &'a IoContext,
pub io: &'a dyn IoContext,
/// Protocol implementation.
pub proto: &'a LightProtocol,
/// Relevant peer for event.
@@ -187,7 +187,7 @@ impl<'a> EventContext for Ctx<'a> {
self.peer
}
fn as_basic(&self) -> &BasicContext {
fn as_basic(&self) -> &dyn BasicContext {
&*self
}
}

View File

@@ -82,7 +82,7 @@ pub struct LoadDistribution {
impl LoadDistribution {
/// Load rolling samples from the given store.
pub fn load(store: &SampleStore) -> Self {
pub fn load(store: &dyn SampleStore) -> Self {
let mut samples = store.load();
for kind_samples in samples.values_mut() {
@@ -133,7 +133,7 @@ impl LoadDistribution {
}
/// End the current time period. Provide a store to
pub fn end_period(&self, store: &SampleStore) {
pub fn end_period(&self, store: &dyn SampleStore) {
let active_period = self.active_period.read();
let mut samples = self.samples.write();

View File

@@ -236,25 +236,25 @@ pub trait Handler: Send + Sync {
/// Called when a peer connects.
fn on_connect(
&self,
_ctx: &EventContext,
_ctx: &dyn EventContext,
_status: &Status,
_capabilities: &Capabilities
) -> PeerStatus { PeerStatus::Kept }
/// Called when a peer disconnects, with a list of unfulfilled request IDs as
/// of yet.
fn on_disconnect(&self, _ctx: &EventContext, _unfulfilled: &[ReqId]) { }
fn on_disconnect(&self, _ctx: &dyn EventContext, _unfulfilled: &[ReqId]) { }
/// Called when a peer makes an announcement.
fn on_announcement(&self, _ctx: &EventContext, _announcement: &Announcement) { }
fn on_announcement(&self, _ctx: &dyn EventContext, _announcement: &Announcement) { }
/// Called when a peer requests relay of some transactions.
fn on_transactions(&self, _ctx: &EventContext, _relay: &[UnverifiedTransaction]) { }
fn on_transactions(&self, _ctx: &dyn EventContext, _relay: &[UnverifiedTransaction]) { }
/// Called when a peer responds to requests.
/// Responses not guaranteed to contain valid data and are not yet checked against
/// the requests they correspond to.
fn on_responses(&self, _ctx: &EventContext, _req_id: ReqId, _responses: &[Response]) { }
fn on_responses(&self, _ctx: &dyn EventContext, _req_id: ReqId, _responses: &[Response]) { }
/// Called when a peer responds with a transaction proof. Each proof is a vector of state items.
fn on_transaction_proof(&self, _ctx: &EventContext, _req_id: ReqId, _state_items: &[DBValue]) { }
fn on_transaction_proof(&self, _ctx: &dyn EventContext, _req_id: ReqId, _state_items: &[DBValue]) { }
/// Called to "tick" the handler periodically.
fn tick(&self, _ctx: &BasicContext) { }
fn tick(&self, _ctx: &dyn BasicContext) { }
/// Called on abort. This signals to handlers that they should clean up
/// and ignore peers.
// TODO: coreresponding `on_activate`?
@@ -290,7 +290,7 @@ pub struct Params {
/// Initial capabilities.
pub capabilities: Capabilities,
/// The sample store (`None` if data shouldn't persist between runs).
pub sample_store: Option<Box<SampleStore>>,
pub sample_store: Option<Box<dyn SampleStore>>,
}
/// Type alias for convenience.
@@ -391,7 +391,7 @@ impl Statistics {
// Locks must be acquired in the order declared, and when holding a read lock
// on the peers, only one peer may be held at a time.
pub struct LightProtocol {
provider: Arc<Provider>,
provider: Arc<dyn Provider>,
config: Config,
genesis_hash: H256,
network_id: u64,
@@ -400,16 +400,16 @@ pub struct LightProtocol {
capabilities: RwLock<Capabilities>,
flow_params: RwLock<Arc<FlowParams>>,
free_flow_params: Arc<FlowParams>,
handlers: Vec<Arc<Handler>>,
handlers: Vec<Arc<dyn Handler>>,
req_id: AtomicUsize,
sample_store: Box<SampleStore>,
sample_store: Box<dyn SampleStore>,
load_distribution: LoadDistribution,
statistics: RwLock<Statistics>,
}
impl LightProtocol {
/// Create a new instance of the protocol manager.
pub fn new(provider: Arc<Provider>, params: Params) -> Self {
pub fn new(provider: Arc<dyn Provider>, params: Params) -> Self {
debug!(target: "pip", "Initializing light protocol handler");
let genesis_hash = provider.chain_info().genesis_hash;
@@ -473,7 +473,7 @@ impl LightProtocol {
/// insufficient credits. Does not check capabilities before sending.
/// On success, returns a request id which can later be coordinated
/// with an event.
pub fn request_from(&self, io: &IoContext, peer_id: PeerId, requests: Requests) -> Result<ReqId, Error> {
pub fn request_from(&self, io: &dyn IoContext, peer_id: PeerId, requests: Requests) -> Result<ReqId, Error> {
let peers = self.peers.read();
let peer = match peers.get(&peer_id) {
Some(peer) => peer,
@@ -518,7 +518,7 @@ impl LightProtocol {
/// Make an announcement of new chain head and capabilities to all peers.
/// The announcement is expected to be valid.
pub fn make_announcement(&self, io: &IoContext, mut announcement: Announcement) {
pub fn make_announcement(&self, io: &dyn IoContext, mut announcement: Announcement) {
let mut reorgs_map = HashMap::new();
let now = Instant::now();
@@ -568,7 +568,7 @@ impl LightProtocol {
/// These are intended to be added when the protocol structure
/// is initialized as a means of customizing its behavior,
/// and dispatching requests immediately upon events.
pub fn add_handler(&mut self, handler: Arc<Handler>) {
pub fn add_handler(&mut self, handler: Arc<dyn Handler>) {
self.handlers.push(handler);
}
@@ -635,7 +635,7 @@ impl LightProtocol {
/// Handle a packet using the given io context.
/// Packet data is _untrusted_, which means that invalid data won't lead to
/// issues.
pub fn handle_packet(&self, io: &IoContext, peer: PeerId, packet_id: u8, data: &[u8]) {
pub fn handle_packet(&self, io: &dyn IoContext, peer: PeerId, packet_id: u8, data: &[u8]) {
let rlp = Rlp::new(data);
trace!(target: "pip", "Incoming packet {} from peer {}", packet_id, peer);
@@ -664,7 +664,7 @@ impl LightProtocol {
}
// check timeouts and punish peers.
fn timeout_check(&self, io: &IoContext) {
fn timeout_check(&self, io: &dyn IoContext) {
let now = Instant::now();
// handshake timeout
@@ -706,7 +706,7 @@ impl LightProtocol {
// propagate transactions to relay peers.
// if we aren't on the mainnet, we just propagate to all relay peers
fn propagate_transactions(&self, io: &IoContext) {
fn propagate_transactions(&self, io: &dyn IoContext) {
if self.capabilities.read().tx_relay { return }
let ready_transactions = self.provider.transactions_to_propagate();
@@ -746,7 +746,7 @@ impl LightProtocol {
}
/// called when a peer connects.
pub fn on_connect(&self, peer: PeerId, io: &IoContext) {
pub fn on_connect(&self, peer: PeerId, io: &dyn IoContext) {
let proto_version = match io.protocol_version(peer).ok_or(Error::WrongNetwork) {
Ok(pv) => pv,
Err(e) => { punish(peer, io, &e); return }
@@ -788,7 +788,7 @@ impl LightProtocol {
}
/// called when a peer disconnects.
pub fn on_disconnect(&self, peer: PeerId, io: &IoContext) {
pub fn on_disconnect(&self, peer: PeerId, io: &dyn IoContext) {
trace!(target: "pip", "Peer {} disconnecting", peer);
self.pending_peers.write().remove(&peer);
@@ -813,8 +813,8 @@ impl LightProtocol {
}
/// Execute the given closure with a basic context derived from the I/O context.
pub fn with_context<F, T>(&self, io: &IoContext, f: F) -> T
where F: FnOnce(&BasicContext) -> T
pub fn with_context<F, T>(&self, io: &dyn IoContext, f: F) -> T
where F: FnOnce(&dyn BasicContext) -> T
{
f(&TickCtx {
io,
@@ -822,7 +822,7 @@ impl LightProtocol {
})
}
fn tick_handlers(&self, io: &IoContext) {
fn tick_handlers(&self, io: &dyn IoContext) {
for handler in &self.handlers {
handler.tick(&TickCtx {
io,
@@ -831,7 +831,7 @@ impl LightProtocol {
}
}
fn begin_new_cost_period(&self, io: &IoContext) {
fn begin_new_cost_period(&self, io: &dyn IoContext) {
self.load_distribution.end_period(&*self.sample_store);
let avg_peer_count = self.statistics.read().avg_peer_count();
@@ -872,7 +872,7 @@ impl LightProtocol {
impl LightProtocol {
// Handle status message from peer.
fn status(&self, peer: PeerId, io: &IoContext, data: &Rlp) -> Result<(), Error> {
fn status(&self, peer: PeerId, io: &dyn IoContext, data: &Rlp) -> Result<(), Error> {
let pending = match self.pending_peers.write().remove(&peer) {
Some(pending) => pending,
None => {
@@ -937,7 +937,7 @@ impl LightProtocol {
}
// Handle an announcement.
fn announcement(&self, peer: PeerId, io: &IoContext, data: &Rlp) -> Result<(), Error> {
fn announcement(&self, peer: PeerId, io: &dyn IoContext, data: &Rlp) -> Result<(), Error> {
if !self.peers.read().contains_key(&peer) {
debug!(target: "pip", "Ignoring announcement from unknown peer");
return Ok(())
@@ -982,7 +982,7 @@ impl LightProtocol {
}
// Receive requests from a peer.
fn request(&self, peer_id: PeerId, io: &IoContext, raw: &Rlp) -> Result<(), Error> {
fn request(&self, peer_id: PeerId, io: &dyn IoContext, raw: &Rlp) -> Result<(), Error> {
// the maximum amount of requests we'll fill in a single packet.
const MAX_REQUESTS: usize = 256;
@@ -1050,7 +1050,7 @@ impl LightProtocol {
}
// handle a packet with responses.
fn response(&self, peer: PeerId, io: &IoContext, raw: &Rlp) -> Result<(), Error> {
fn response(&self, peer: PeerId, io: &dyn IoContext, raw: &Rlp) -> Result<(), Error> {
let (req_id, responses) = {
let id_guard = self.pre_verify_response(peer, &raw)?;
let responses: Vec<Response> = raw.list_at(2)?;
@@ -1069,7 +1069,7 @@ impl LightProtocol {
}
// handle an update of request credits parameters.
fn update_credits(&self, peer_id: PeerId, io: &IoContext, raw: &Rlp) -> Result<(), Error> {
fn update_credits(&self, peer_id: PeerId, io: &dyn IoContext, raw: &Rlp) -> Result<(), Error> {
let peers = self.peers.read();
let peer = peers.get(&peer_id).ok_or(Error::UnknownPeer)?;
@@ -1104,7 +1104,7 @@ impl LightProtocol {
}
// handle an acknowledgement of request credits update.
fn acknowledge_update(&self, peer_id: PeerId, _io: &IoContext, _raw: &Rlp) -> Result<(), Error> {
fn acknowledge_update(&self, peer_id: PeerId, _io: &dyn IoContext, _raw: &Rlp) -> Result<(), Error> {
let peers = self.peers.read();
let peer = peers.get(&peer_id).ok_or(Error::UnknownPeer)?;
let mut peer = peer.lock();
@@ -1123,7 +1123,7 @@ impl LightProtocol {
}
// Receive a set of transactions to relay.
fn relay_transactions(&self, peer: PeerId, io: &IoContext, data: &Rlp) -> Result<(), Error> {
fn relay_transactions(&self, peer: PeerId, io: &dyn IoContext, data: &Rlp) -> Result<(), Error> {
const MAX_TRANSACTIONS: usize = 256;
let txs: Vec<_> = data.iter()
@@ -1146,7 +1146,7 @@ impl LightProtocol {
}
// if something went wrong, figure out how much to punish the peer.
fn punish(peer: PeerId, io: &IoContext, e: &Error) {
fn punish(peer: PeerId, io: &dyn IoContext, e: &Error) {
match e.punishment() {
Punishment::None => {}
Punishment::Disconnect => {
@@ -1161,7 +1161,7 @@ fn punish(peer: PeerId, io: &IoContext, e: &Error) {
}
impl NetworkProtocolHandler for LightProtocol {
fn initialize(&self, io: &NetworkContext) {
fn initialize(&self, io: &dyn NetworkContext) {
io.register_timer(TIMEOUT, TIMEOUT_INTERVAL)
.expect("Error registering sync timer.");
io.register_timer(TICK_TIMEOUT, TICK_TIMEOUT_INTERVAL)
@@ -1174,19 +1174,19 @@ impl NetworkProtocolHandler for LightProtocol {
.expect("Error registering statistics timer.");
}
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
self.handle_packet(&io, *peer, packet_id, data);
}
fn connected(&self, io: &NetworkContext, peer: &PeerId) {
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) {
self.on_connect(*peer, &io);
}
fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) {
self.on_disconnect(*peer, &io);
}
fn timeout(&self, io: &NetworkContext, timer: TimerToken) {
fn timeout(&self, io: &dyn NetworkContext, timer: TimerToken) {
match timer {
TIMEOUT => self.timeout_check(&io),
TICK_TIMEOUT => self.tick_handlers(&io),

View File

@@ -81,7 +81,7 @@ pub mod error {
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(std::error::Error + 'static)> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::ChannelCanceled(err) => Some(err),
_ => None,
@@ -98,7 +98,7 @@ pub trait OnDemandRequester: Send + Sync {
/// Submit a strongly-typed batch of requests.
///
/// Fails if back-reference are not coherent.
fn request<T>(&self, ctx: &BasicContext, requests: T) -> Result<OnResponses<T>, basic_request::NoSuchOutput>
fn request<T>(&self, ctx: &dyn BasicContext, requests: T) -> Result<OnResponses<T>, basic_request::NoSuchOutput>
where
T: request::RequestAdapter;
@@ -106,7 +106,7 @@ pub trait OnDemandRequester: Send + Sync {
///
/// Fails if back-references are not coherent.
/// The returned vector of responses will correspond to the requests exactly.
fn request_raw(&self, ctx: &BasicContext, requests: Vec<Request>)
fn request_raw(&self, ctx: &dyn BasicContext, requests: Vec<Request>)
-> Result<Receiver<PendingResponse>, basic_request::NoSuchOutput>;
}
@@ -373,7 +373,7 @@ pub struct OnDemand {
}
impl OnDemandRequester for OnDemand {
fn request_raw(&self, ctx: &BasicContext, requests: Vec<Request>)
fn request_raw(&self, ctx: &dyn BasicContext, requests: Vec<Request>)
-> Result<Receiver<PendingResponse>, basic_request::NoSuchOutput>
{
let (sender, receiver) = oneshot::channel();
@@ -429,7 +429,7 @@ impl OnDemandRequester for OnDemand {
Ok(receiver)
}
fn request<T>(&self, ctx: &BasicContext, requests: T) -> Result<OnResponses<T>, basic_request::NoSuchOutput>
fn request<T>(&self, ctx: &dyn BasicContext, requests: T) -> Result<OnResponses<T>, basic_request::NoSuchOutput>
where T: request::RequestAdapter
{
self.request_raw(ctx, requests.make_requests()).map(|recv| OnResponses {
@@ -503,7 +503,7 @@ impl OnDemand {
// maybe dispatch pending requests.
// sometimes
fn attempt_dispatch(&self, ctx: &BasicContext) {
fn attempt_dispatch(&self, ctx: &dyn BasicContext) {
if !self.no_immediate_dispatch {
self.dispatch_pending(ctx)
}
@@ -511,7 +511,7 @@ impl OnDemand {
// dispatch pending requests, and discard those for which the corresponding
// receiver has been dropped.
fn dispatch_pending(&self, ctx: &BasicContext) {
fn dispatch_pending(&self, ctx: &dyn BasicContext) {
if self.pending.read().is_empty() {
return
}
@@ -566,7 +566,7 @@ impl OnDemand {
// submit a pending request set. attempts to answer from cache before
// going to the network. if complete, sends response and consumes the struct.
fn submit_pending(&self, ctx: &BasicContext, mut pending: Pending) {
fn submit_pending(&self, ctx: &dyn BasicContext, mut pending: Pending) {
// answer as many requests from cache as we can, and schedule for dispatch
// if incomplete.
@@ -585,7 +585,7 @@ impl OnDemand {
impl Handler for OnDemand {
fn on_connect(
&self,
ctx: &EventContext,
ctx: &dyn EventContext,
status: &Status,
capabilities: &Capabilities
) -> PeerStatus {
@@ -597,7 +597,7 @@ impl Handler for OnDemand {
PeerStatus::Kept
}
fn on_disconnect(&self, ctx: &EventContext, unfulfilled: &[ReqId]) {
fn on_disconnect(&self, ctx: &dyn EventContext, unfulfilled: &[ReqId]) {
self.peers.write().remove(&ctx.peer());
let ctx = ctx.as_basic();
@@ -614,7 +614,7 @@ impl Handler for OnDemand {
self.attempt_dispatch(ctx);
}
fn on_announcement(&self, ctx: &EventContext, announcement: &Announcement) {
fn on_announcement(&self, ctx: &dyn EventContext, announcement: &Announcement) {
{
let mut peers = self.peers.write();
if let Some(ref mut peer) = peers.get_mut(&ctx.peer()) {
@@ -626,7 +626,7 @@ impl Handler for OnDemand {
self.attempt_dispatch(ctx.as_basic());
}
fn on_responses(&self, ctx: &EventContext, req_id: ReqId, responses: &[basic_request::Response]) {
fn on_responses(&self, ctx: &dyn EventContext, req_id: ReqId, responses: &[basic_request::Response]) {
let mut pending = match self.in_transit.write().remove(&req_id) {
Some(req) => req,
None => return,
@@ -662,7 +662,7 @@ impl Handler for OnDemand {
self.submit_pending(ctx.as_basic(), pending);
}
fn tick(&self, ctx: &BasicContext) {
fn tick(&self, ctx: &dyn BasicContext) {
self.attempt_dispatch(ctx)
}
}

View File

@@ -1032,7 +1032,7 @@ pub struct TransactionProof {
// TODO: it's not really possible to provide this if the header is unknown.
pub env_info: EnvInfo,
/// Consensus engine.
pub engine: Arc<Engine>,
pub engine: Arc<dyn Engine>,
}
impl TransactionProof {
@@ -1075,9 +1075,9 @@ pub struct Signal {
/// Block hash and number to fetch proof for.
pub hash: H256,
/// Consensus engine, used to check the proof.
pub engine: Arc<Engine>,
pub engine: Arc<dyn Engine>,
/// Special checker for the proof.
pub proof_check: Arc<StateDependentProof>,
pub proof_check: Arc<dyn StateDependentProof>,
}
impl Signal {

View File

@@ -51,7 +51,7 @@ impl EventContext for Context {
}
}
fn as_basic(&self) -> &BasicContext { self }
fn as_basic(&self) -> &dyn BasicContext { self }
}
impl BasicContext for Context {