From d0eb924387b330156387fa70d5d548a9f171815f Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 7 Oct 2019 10:20:16 +0900 Subject: [PATCH 1/3] Use rust 1.37.0 --- .travis.yml | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89ecc447c1..e377307b98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.36.0 + - 1.37.0 stages: - name: test if: branch != docker-build diff --git a/rust-toolchain b/rust-toolchain index 39fc130ef8..bf50e910e6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.36.0 +1.37.0 From 6869cb15413096b6a299c00f630a9d108d5ef14c Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 7 Oct 2019 11:07:11 +0900 Subject: [PATCH 2/3] trait objects without an explicit `dyn` are deprecated --- codechain/rpc_apis.rs | 2 +- codechain/run_node.rs | 12 ++++----- core/src/block.rs | 18 ++++++++----- core/src/blockchain/blockchain.rs | 8 +++--- core/src/blockchain/body_db.rs | 8 +++--- core/src/blockchain/headerchain.rs | 10 +++---- core/src/blockchain/invoice_db.rs | 4 +-- core/src/blockchain/route.rs | 2 +- core/src/client/client.rs | 26 +++++++++---------- core/src/client/importer.rs | 6 ++--- core/src/client/mod.rs | 12 ++++----- core/src/client/test_client.rs | 4 +-- core/src/consensus/mod.rs | 8 +++--- core/src/consensus/simple_poa/mod.rs | 6 ++--- core/src/consensus/solo/mod.rs | 6 ++--- core/src/consensus/stake/actions.rs | 6 ++--- core/src/consensus/stake/mod.rs | 10 +++---- core/src/consensus/tendermint/backup.rs | 4 +-- core/src/consensus/tendermint/engine.rs | 12 ++++----- core/src/consensus/tendermint/mod.rs | 14 +++++----- core/src/consensus/tendermint/network.rs | 4 +-- core/src/consensus/tendermint/worker.rs | 16 ++++++------ .../validator_set/dynamic_validator.rs | 8 +++--- core/src/consensus/validator_set/mod.rs | 2 +- .../consensus/validator_set/validator_list.rs | 6 ++--- core/src/db.rs | 22 ++++++++-------- core/src/miner/backup.rs | 2 +- core/src/miner/mem_pool.rs | 4 +-- core/src/miner/miner.rs | 20 +++++++------- core/src/scheme/scheme.rs | 6 ++--- core/src/service.rs | 2 +- core/src/verification/canon_verifier.rs | 4 +-- core/src/verification/mod.rs | 2 +- core/src/verification/noop_verifier.rs | 4 +-- core/src/verification/queue/kind.rs | 20 +++++++++----- core/src/verification/queue/mod.rs | 6 ++--- core/src/verification/verification.rs | 10 +++---- core/src/verification/verifier.rs | 4 +-- discovery/src/extension.rs | 4 +-- keystore/src/import.rs | 4 +-- keystore/src/keystore.rs | 12 ++++----- keystore/src/secret_store.rs | 2 +- network/src/client.rs | 2 +- network/src/p2p/handler.rs | 4 +-- network/src/service.rs | 6 ++--- rpc/src/v1/impls/devel.rs | 2 +- rpc/src/v1/impls/net.rs | 4 +-- state/src/action_handler/mod.rs | 2 +- state/src/cache/shard_cache.rs | 2 +- state/src/cache/top_cache.rs | 2 +- state/src/cache/write_back.rs | 2 +- state/src/db/state_db.rs | 8 +++--- state/src/impls/shard_level.rs | 4 +-- state/src/impls/top_level.rs | 4 +-- state/src/tests.rs | 2 +- state/src/traits.rs | 2 +- stratum/src/lib.rs | 4 +-- sync/src/block/downloader/header.rs | 4 +-- sync/src/block/extension.rs | 4 +-- sync/src/snapshot/snapshot.rs | 18 ++++++------- sync/src/transaction/extension.rs | 6 ++--- util/hashdb/src/lib.rs | 14 +++++----- util/io/src/service.rs | 4 +-- util/io/src/worker.rs | 2 +- util/journaldb/src/archivedb.rs | 8 +++--- util/journaldb/src/lib.rs | 2 +- util/journaldb/src/traits.rs | 4 +-- util/kvdb/src/lib.rs | 2 +- util/merkle/src/lib.rs | 6 ++--- util/merkle/src/triedb.rs | 6 ++--- util/merkle/src/triedbmut.rs | 8 +++--- util/rlp_compress/src/lib.rs | 4 +-- util/secp256k1/src/lib.rs | 2 +- util/timer/src/timer.rs | 6 ++--- vm/src/executor.rs | 2 +- 75 files changed, 253 insertions(+), 241 deletions(-) diff --git a/codechain/rpc_apis.rs b/codechain/rpc_apis.rs index ab8eec6ad5..3f4d3c016a 100644 --- a/codechain/rpc_apis.rs +++ b/codechain/rpc_apis.rs @@ -25,7 +25,7 @@ use csync::BlockSyncEvent; pub struct ApiDependencies { pub client: Arc, pub miner: Arc, - pub network_control: Arc, + pub network_control: Arc, pub account_provider: Arc, pub block_sync: Option>, } diff --git a/codechain/run_node.rs b/codechain/run_node.rs index b3003f8938..5ec7eb7c02 100644 --- a/codechain/run_node.rs +++ b/codechain/run_node.rs @@ -91,7 +91,7 @@ fn discovery_start( fn client_start( client_config: &ClientConfig, timer_loop: &TimerLoop, - db: Arc, + db: Arc, scheme: &Scheme, miner: Arc, ) -> Result { @@ -122,7 +122,7 @@ fn new_miner( config: &config::Config, scheme: &Scheme, ap: Arc, - db: Arc, + db: Arc, ) -> Result, String> { let miner = Miner::new(config.miner_options()?, scheme, Some(ap), db); @@ -204,7 +204,7 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String Ok(()) } -pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result, String> { +pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result, String> { let base_path = cfg.base_path.as_ref().unwrap().clone(); let db_path = cfg.db_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_DB_PATH); let client_path = Path::new(&db_path); @@ -282,7 +282,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> { scheme.engine.register_chain_notify(client.client().as_ref()); - let network_service: Arc = { + let network_service: Arc = { if !config.network.disable.unwrap() { let network_config = config.network_config()?; // XXX: What should we do if the network id has been changed. @@ -303,7 +303,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> { service.register_extension(move |api| BlockSyncExtension::new(client, api)) }; let sync = Arc::new(BlockSyncSender::from(sync_sender.clone())); - client.client().add_notify(Arc::downgrade(&sync) as Weak); + client.client().add_notify(Arc::downgrade(&sync) as Weak); _maybe_sync = Some(sync); // Hold sync to ensure it not to be destroyed. maybe_sync_sender = Some(sync_sender); } @@ -362,7 +362,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> { let client = client.client(); let snapshot_period = client.common_params(BlockId::Latest).unwrap().snapshot_period(); let service = SnapshotService::new(Arc::clone(&client), config.snapshot.path.unwrap(), snapshot_period); - client.add_notify(Arc::downgrade(&service) as Weak); + client.add_notify(Arc::downgrade(&service) as Weak); Some(service) } else { None diff --git a/core/src/block.rs b/core/src/block.rs index 1261d075f2..6b9e218aa5 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -121,13 +121,13 @@ impl ExecutedBlock { /// Block that is ready for transactions to be added. pub struct OpenBlock<'x> { block: ExecutedBlock, - engine: &'x CodeChainEngine, + engine: &'x dyn CodeChainEngine, } impl<'x> OpenBlock<'x> { /// Create a new `OpenBlock` ready for transaction pushing. pub fn try_new( - engine: &'x CodeChainEngine, + engine: &'x dyn CodeChainEngine, db: StateDB, parent: &Header, author: Address, @@ -311,7 +311,7 @@ impl<'x> OpenBlock<'x> { /// Provide a valid seal /// /// NOTE: This does not check the validity of `seal` with the engine. - pub fn seal(&mut self, engine: &CodeChainEngine, seal: Vec) -> Result<(), BlockError> { + pub fn seal(&mut self, engine: &dyn CodeChainEngine, seal: Vec) -> Result<(), BlockError> { let expected_seal_fields = engine.seal_fields(self.header()); if seal.len() != expected_seal_fields { return Err(BlockError::InvalidSealArity(Mismatch { @@ -347,7 +347,7 @@ impl ClosedBlock { } /// Given an engine reference, reopen the `ClosedBlock` into an `OpenBlock`. - pub fn reopen(self, engine: &CodeChainEngine) -> OpenBlock { + pub fn reopen(self, engine: &dyn CodeChainEngine) -> OpenBlock { // revert rewards (i.e. set state back at last transaction's state). let mut block = self.block; block.state = self.unclosed_state; @@ -367,7 +367,7 @@ impl LockedBlock { /// Provide a valid seal in order to turn this into a `SealedBlock`. /// /// NOTE: This does not check the validity of `seal` with the engine. - pub fn seal(mut self, engine: &CodeChainEngine, seal: Vec) -> Result { + pub fn seal(mut self, engine: &dyn CodeChainEngine, seal: Vec) -> Result { let expected_seal_fields = engine.seal_fields(self.header()); if seal.len() != expected_seal_fields { return Err(BlockError::InvalidSealArity(Mismatch { @@ -384,7 +384,11 @@ impl LockedBlock { /// Provide a valid seal in order to turn this into a `SealedBlock`. /// This does check the validity of `seal` with the engine. /// Returns the `ClosedBlock` back again if the seal is no good. - pub fn try_seal(mut self, engine: &CodeChainEngine, seal: Vec) -> Result { + pub fn try_seal( + mut self, + engine: &dyn CodeChainEngine, + seal: Vec, + ) -> Result { self.block.header.set_seal(seal); // TODO: passing state context to avoid engines owning it? @@ -489,7 +493,7 @@ impl IsBlock for SealedBlock { pub fn enact( header: &Header, transactions: &[SignedTransaction], - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, client: &C, db: StateDB, parent: &Header, diff --git a/core/src/blockchain/blockchain.rs b/core/src/blockchain/blockchain.rs index abec2d35d9..3b55954fb3 100644 --- a/core/src/blockchain/blockchain.rs +++ b/core/src/blockchain/blockchain.rs @@ -58,7 +58,7 @@ pub struct BlockChain { impl BlockChain { /// Create new instance of blockchain from given Genesis. - pub fn new(genesis: &[u8], db: Arc) -> Self { + pub fn new(genesis: &[u8], db: Arc) -> Self { let genesis_block = BlockView::new(genesis); // load best block @@ -102,7 +102,7 @@ impl BlockChain { &self, batch: &mut DBTransaction, header: &HeaderView, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, ) -> ImportRoute { match self.headerchain.insert_header(batch, header, engine) { Some(c) => ImportRoute::new_from_best_header_changed(header.hash(), &c), @@ -118,7 +118,7 @@ impl BlockChain { batch: &mut DBTransaction, bytes: &[u8], invoices: Vec, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, ) -> ImportRoute { // create views onto rlp let new_block = BlockView::new(bytes); @@ -180,7 +180,7 @@ impl BlockChain { } /// Calculate how best block is changed - fn best_block_changed(&self, new_block: &BlockView, engine: &CodeChainEngine) -> BestBlockChanged { + fn best_block_changed(&self, new_block: &BlockView, engine: &dyn CodeChainEngine) -> BestBlockChanged { let new_header = new_block.header_view(); let parent_hash_of_new_block = new_header.parent_hash(); let parent_details_of_new_block = self.block_details(&parent_hash_of_new_block).expect("Invalid parent hash"); diff --git a/core/src/blockchain/body_db.rs b/core/src/blockchain/body_db.rs index 547c4c4b43..a97a591989 100644 --- a/core/src/blockchain/body_db.rs +++ b/core/src/blockchain/body_db.rs @@ -42,14 +42,14 @@ pub struct BodyDB { transaction_address_cache: Mutex>, pending_transaction_addresses: Mutex>>, - db: Arc, + db: Arc, } type TransactionHashAndAddress = (H256, TransactionAddresses); impl BodyDB { /// Create new instance of blockchain from given Genesis. - pub fn new(genesis: &BlockView, db: Arc) -> Self { + pub fn new(genesis: &BlockView, db: Arc) -> Self { let bdb = Self { body_cache: Mutex::new(LruCache::new(BODY_CACHE_SIZE)), parcel_address_cache: RwLock::new(HashMap::new()), @@ -196,8 +196,8 @@ impl BodyDB { }; let (removed, added): ( - Box>, - Box>, + Box>, + Box>, ) = match best_block_changed { BestBlockChanged::CanonChainAppended { .. diff --git a/core/src/blockchain/headerchain.rs b/core/src/blockchain/headerchain.rs index c3d78fc20e..490510f556 100644 --- a/core/src/blockchain/headerchain.rs +++ b/core/src/blockchain/headerchain.rs @@ -53,7 +53,7 @@ pub struct HeaderChain { detail_cache: RwLock>, hash_cache: Mutex>, - db: Arc, + db: Arc, pending_best_header_hash: RwLock>, pending_best_proposal_block_hash: RwLock>, @@ -63,7 +63,7 @@ pub struct HeaderChain { impl HeaderChain { /// Create new instance of blockchain from given Genesis. - pub fn new(genesis: &HeaderView, db: Arc) -> Self { + pub fn new(genesis: &HeaderView, db: Arc) -> Self { // load best header let best_header_hash = match db.get(db::COL_EXTRA, BEST_HEADER_KEY).unwrap() { Some(hash) => H256::from_slice(&hash), @@ -122,7 +122,7 @@ impl HeaderChain { &self, batch: &mut DBTransaction, header: &HeaderView, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, ) -> Option { let hash = header.hash(); @@ -239,7 +239,7 @@ impl HeaderChain { } /// Calculate how best block is changed - fn best_header_changed(&self, new_header: &HeaderView, engine: &CodeChainEngine) -> BestHeaderChanged { + fn best_header_changed(&self, new_header: &HeaderView, engine: &dyn CodeChainEngine) -> BestHeaderChanged { let parent_hash_of_new_header = new_header.parent_hash(); let parent_details_of_new_header = self.block_details(&parent_hash_of_new_header).expect("Invalid parent hash"); let is_new_best = parent_details_of_new_header.total_score + new_header.score() @@ -403,7 +403,7 @@ impl HeaderProvider for HeaderChain { } /// Get block header data -fn block_header_data(hash: &H256, header_cache: &Mutex>, db: &KeyValueDB) -> Option> { +fn block_header_data(hash: &H256, header_cache: &Mutex>, db: &dyn KeyValueDB) -> Option> { // Check cache first { let mut lock = header_cache.lock(); diff --git a/core/src/blockchain/invoice_db.rs b/core/src/blockchain/invoice_db.rs index 9bd5a58c2e..8c14499d90 100644 --- a/core/src/blockchain/invoice_db.rs +++ b/core/src/blockchain/invoice_db.rs @@ -34,12 +34,12 @@ pub struct InvoiceDB { // transaction hash -> error hint hash_cache: RwLock>>, - db: Arc, + db: Arc, } impl InvoiceDB { /// Create new instance of blockchain from given Genesis. - pub fn new(db: Arc) -> Self { + pub fn new(db: Arc) -> Self { Self { tracker_cache: Default::default(), hash_cache: Default::default(), diff --git a/core/src/blockchain/route.rs b/core/src/blockchain/route.rs index be8cb2d63e..553680bb60 100644 --- a/core/src/blockchain/route.rs +++ b/core/src/blockchain/route.rs @@ -71,7 +71,7 @@ pub struct TreeRoute { /// /// If the tree route verges into pruned or unknown blocks, /// `None` is returned. -pub fn tree_route(db: &HeaderProvider, from: H256, to: H256) -> Option { +pub fn tree_route(db: &dyn HeaderProvider, from: H256, to: H256) -> Option { let mut retracted = vec![]; let mut enacted = vec![]; diff --git a/core/src/client/client.rs b/core/src/client/client.rs index 4c39949f3d..3117abd55f 100644 --- a/core/src/client/client.rs +++ b/core/src/client/client.rs @@ -58,19 +58,19 @@ use crate::types::{BlockId, BlockStatus, TransactionId, VerificationQueueInfo as const MAX_MEM_POOL_SIZE: usize = 4096; pub struct Client { - engine: Arc, + engine: Arc, io_channel: Mutex>, chain: RwLock, /// Client uses this to store blocks, traces, etc. - db: Arc, + db: Arc, state_db: RwLock, /// List of actors to be notified on certain chain events - notify: RwLock>>, + notify: RwLock>>, /// Count of pending transactions in the queue queue_transactions: AtomicUsize, @@ -87,7 +87,7 @@ impl Client { pub fn try_new( config: &ClientConfig, scheme: &Scheme, - db: Arc, + db: Arc, miner: Arc, message_channel: IoChannel, reseal_timer: TimerApi, @@ -133,12 +133,12 @@ impl Client { } /// Returns engine reference. - pub fn engine(&self) -> &CodeChainEngine { + pub fn engine(&self) -> &dyn CodeChainEngine { &*self.engine } /// Adds an actor to be notified on certain events - pub fn add_notify(&self, target: Weak) { + pub fn add_notify(&self, target: Weak) { self.notify.write().push(target); } @@ -194,7 +194,7 @@ impl Client { fn notify(&self, f: F) where - F: Fn(&ChainNotify), { + F: Fn(&dyn ChainNotify), { for np in self.notify.read().iter() { if let Some(n) = np.upgrade() { f(&*n); @@ -305,7 +305,7 @@ impl Client { } } - fn state_info(&self, state: StateOrBlock) -> Option> { + fn state_info(&self, state: StateOrBlock) -> Option> { Some(match state { StateOrBlock::State(state) => state, StateOrBlock::Block(id) => Box::new(self.state_at(id)?), @@ -320,7 +320,7 @@ impl Client { self.chain.read() } - pub fn db(&self) -> &Arc { + pub fn db(&self) -> &Arc { &self.db } } @@ -352,7 +352,7 @@ impl TimeoutHandler for Client { } impl DatabaseClient for Client { - fn database(&self) -> Arc { + fn database(&self) -> Arc { Arc::clone(&self.db()) } } @@ -440,7 +440,7 @@ impl ExecuteClient for Client { fn execute_vm( &self, - tx: &PartialHashing, + tx: &dyn PartialHashing, inputs: &[AssetTransferInput], params: &[Vec], indices: &[usize], @@ -581,7 +581,7 @@ impl EngineClient for Client { } } - fn get_kvdb(&self) -> Arc { + fn get_kvdb(&self) -> Arc { self.db.clone() } } @@ -905,7 +905,7 @@ impl ChainTimeInfo for Client { } impl FindActionHandler for Client { - fn find_action_handler_for(&self, id: u64) -> Option<&ActionHandler> { + fn find_action_handler_for(&self, id: u64) -> Option<&dyn ActionHandler> { self.engine.find_action_handler_for(id) } } diff --git a/core/src/client/importer.rs b/core/src/client/importer.rs index b00e992e8f..e2cca86c7a 100644 --- a/core/src/client/importer.rs +++ b/core/src/client/importer.rs @@ -44,7 +44,7 @@ pub struct Importer { pub import_lock: Mutex<()>, // FIXME Maybe wrap the whole `Importer` instead? /// Used to verify blocks - pub verifier: Box>, + pub verifier: Box>, /// Queue containing pending blocks pub block_queue: BlockQueue, @@ -56,13 +56,13 @@ pub struct Importer { pub miner: Arc, /// CodeChain engine to be used during import - pub engine: Arc, + pub engine: Arc, } impl Importer { pub fn try_new( config: &ClientConfig, - engine: Arc, + engine: Arc, message_channel: IoChannel, miner: Arc, ) -> Result { diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index 10ee58c47e..33594dcf4a 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -111,7 +111,7 @@ pub trait EngineClient: Sync + Send + BlockChainTrait + ImportBlock { /// Used in Tendermint, when going to the commit step. fn update_best_as_committed(&self, block_hash: H256); - fn get_kvdb(&self) -> Arc; + fn get_kvdb(&self) -> Arc; } pub trait ConsensusClient: BlockChainClient + EngineClient + EngineInfo + TermInfo + StateInfo {} @@ -164,14 +164,14 @@ pub trait AccountData { /// State information to be used during client query pub enum StateOrBlock { /// State to be used, may be pending - State(Box), + State(Box), /// Id of an existing block from a chain to get state from Block(BlockId), } -impl From> for StateOrBlock { - fn from(info: Box) -> StateOrBlock { +impl From> for StateOrBlock { + fn from(info: Box) -> StateOrBlock { StateOrBlock::State(info) } } @@ -275,7 +275,7 @@ pub trait MiningBlockChainClient: BlockChainClient + BlockProducer + FindActionH /// Provides methods to access database. pub trait DatabaseClient { - fn database(&self) -> Arc; + fn database(&self) -> Arc; } /// Provides methods to access asset @@ -303,7 +303,7 @@ pub trait ExecuteClient: ChainTimeInfo { fn execute_vm( &self, - tx: &PartialHashing, + tx: &dyn PartialHashing, inputs: &[AssetTransferInput], params: &[Vec], indices: &[usize], diff --git a/core/src/client/test_client.rs b/core/src/client/test_client.rs index c922de1856..f823758c79 100644 --- a/core/src/client/test_client.rs +++ b/core/src/client/test_client.rs @@ -136,7 +136,7 @@ impl TestBlockChainClient { } /// Create test client with custom scheme and extra data. - pub fn new_with_scheme_and_extra(scheme: Scheme, extra_data: Bytes, db: Arc) -> Self { + pub fn new_with_scheme_and_extra(scheme: Scheme, extra_data: Bytes, db: Arc) -> Self { let genesis_block = scheme.genesis_block(); let genesis_header = scheme.genesis_header(); let genesis_hash = genesis_header.hash(); @@ -614,7 +614,7 @@ impl super::EngineClient for TestBlockChainClient { fn update_best_as_committed(&self, _block_hash: H256) {} - fn get_kvdb(&self) -> Arc { + fn get_kvdb(&self) -> Arc { let db = kvdb_memorydb::create(NUM_COLUMNS.unwrap_or(0)); Arc::new(db) } diff --git a/core/src/consensus/mod.rs b/core/src/consensus/mod.rs index 9647203d52..7be9fdce92 100644 --- a/core/src/consensus/mod.rs +++ b/core/src/consensus/mod.rs @@ -233,7 +233,7 @@ pub trait ConsensusEngine: Sync + Send { } /// Add Client which can be used for sealing, potentially querying the state and sending messages. - fn register_client(&self, _client: Weak) {} + fn register_client(&self, _client: Weak) {} /// Find out if the block is a proposal block and should not be inserted into the DB. /// Takes a header of a fully verified block. @@ -254,7 +254,7 @@ pub trait ConsensusEngine: Sync + Send { fn block_reward(&self, block_number: u64) -> u64; - fn block_fee(&self, transactions: Box>) -> u64 { + fn block_fee(&self, transactions: Box>) -> u64 { transactions.map(|tx| tx.fee).sum() } @@ -270,11 +270,11 @@ pub trait ConsensusEngine: Sync + Send { true } - fn action_handlers(&self) -> &[Arc] { + fn action_handlers(&self) -> &[Arc] { &[] } - fn find_action_handler_for(&self, id: u64) -> Option<&ActionHandler> { + fn find_action_handler_for(&self, id: u64) -> Option<&dyn ActionHandler> { self.action_handlers().iter().find(|handler| handler.handler_id() == id).map(AsRef::as_ref) } diff --git a/core/src/consensus/simple_poa/mod.rs b/core/src/consensus/simple_poa/mod.rs index 6a410dbb11..d2a2633ef8 100644 --- a/core/src/consensus/simple_poa/mod.rs +++ b/core/src/consensus/simple_poa/mod.rs @@ -37,7 +37,7 @@ use crate::error::{BlockError, Error}; pub struct SimplePoA { machine: CodeChainMachine, signer: RwLock, - validators: Box, + validators: Box, /// Reward per block, in base units. block_reward: u64, } @@ -55,7 +55,7 @@ impl SimplePoA { } } -fn verify_external(header: &Header, validators: &ValidatorSet) -> Result<(), Error> { +fn verify_external(header: &Header, validators: &dyn ValidatorSet) -> Result<(), Error> { use rlp::UntrustedRlp; // Check if the signature belongs to a validator, can depend on parent state. @@ -130,7 +130,7 @@ impl ConsensusEngine for SimplePoA { self.machine.add_balance(block, &author, total_reward) } - fn register_client(&self, client: Weak) { + fn register_client(&self, client: Weak) { self.validators.register_client(client); } diff --git a/core/src/consensus/solo/mod.rs b/core/src/consensus/solo/mod.rs index b8c9bfd155..915e6485f9 100644 --- a/core/src/consensus/solo/mod.rs +++ b/core/src/consensus/solo/mod.rs @@ -34,13 +34,13 @@ use crate::error::Error; pub struct Solo { params: SoloParams, machine: CodeChainMachine, - action_handlers: Vec>, + action_handlers: Vec>, } impl Solo { /// Returns new instance of Solo over the given state machine. pub fn new(params: SoloParams, machine: CodeChainMachine) -> Self { - let mut action_handlers: Vec> = Vec::new(); + let mut action_handlers: Vec> = Vec::new(); if params.enable_hit_handler { action_handlers.push(Arc::new(HitHandler::new())); } @@ -135,7 +135,7 @@ impl ConsensusEngine for Solo { 1 } - fn action_handlers(&self) -> &[Arc] { + fn action_handlers(&self) -> &[Arc] { &self.action_handlers } diff --git a/core/src/consensus/stake/actions.rs b/core/src/consensus/stake/actions.rs index f96fd4d26d..013bda7180 100644 --- a/core/src/consensus/stake/actions.rs +++ b/core/src/consensus/stake/actions.rs @@ -73,8 +73,8 @@ impl Action { pub fn verify( &self, current_params: &CommonParams, - client: Option>, - validators: Option>, + client: Option>, + validators: Option>, ) -> Result<(), SyntaxError> { match self { Action::TransferCCS { @@ -456,7 +456,7 @@ mod tests { message1: Box::new(consensus_message1), message2: Box::new(consensus_message2), }; - let arced_client: Arc = Arc::new(test_client); + let arced_client: Arc = Arc::new(test_client); validator_set.register_client(Arc::downgrade(&arced_client)); action.verify(&CommonParams::default_for_test(), Some(Arc::clone(&arced_client)), Some(Arc::new(validator_set))) } diff --git a/core/src/consensus/stake/mod.rs b/core/src/consensus/stake/mod.rs index 8bd8d6d5b2..d6bb44885c 100644 --- a/core/src/consensus/stake/mod.rs +++ b/core/src/consensus/stake/mod.rs @@ -43,8 +43,8 @@ pub const CUSTOM_ACTION_HANDLER_ID: u64 = 2; pub struct Stake { genesis_stakes: HashMap, - client: RwLock>>, - validators: RwLock>>, + client: RwLock>>, + validators: RwLock>>, } impl Stake { @@ -55,7 +55,7 @@ impl Stake { validators: Default::default(), } } - pub fn register_resources(&self, client: Weak, validators: Weak) { + pub fn register_resources(&self, client: Weak, validators: Weak) { *self.client.write() = Some(Weak::clone(&client)); *self.validators.write() = Some(Weak::clone(&validators)); } @@ -151,8 +151,8 @@ impl ActionHandler for Stake { fn verify(&self, bytes: &[u8], current_params: &CommonParams) -> Result<(), SyntaxError> { let action = Action::decode(&UntrustedRlp::new(bytes)) .map_err(|err| SyntaxError::InvalidCustomAction(err.to_string()))?; - let client: Option> = self.client.read().as_ref().and_then(Weak::upgrade); - let validators: Option> = self.validators.read().as_ref().and_then(Weak::upgrade); + let client: Option> = self.client.read().as_ref().and_then(Weak::upgrade); + let validators: Option> = self.validators.read().as_ref().and_then(Weak::upgrade); action.verify(current_params, client, validators) } diff --git a/core/src/consensus/tendermint/backup.rs b/core/src/consensus/tendermint/backup.rs index 83f88973a4..bc22a664f1 100644 --- a/core/src/consensus/tendermint/backup.rs +++ b/core/src/consensus/tendermint/backup.rs @@ -40,7 +40,7 @@ pub struct BackupData { pub last_confirmed_view: View, } -pub fn backup(db: &KeyValueDB, backup_data: BackupView) { +pub fn backup(db: &dyn KeyValueDB, backup_data: BackupView) { let BackupView { height, view, @@ -58,7 +58,7 @@ pub fn backup(db: &KeyValueDB, backup_data: BackupView) { db.write(batch).expect("Low level database error. Some issue with disk?"); } -pub fn restore(db: &KeyValueDB) -> Option { +pub fn restore(db: &dyn KeyValueDB) -> Option { let value = db.get(db::COL_EXTRA, BACKUP_KEY).expect("Low level database error. Some issue with disk?"); let (height, view, step, votes, last_confirmed_view) = value.map(|bytes| { let bytes = bytes.into_vec(); diff --git a/core/src/consensus/tendermint/engine.rs b/core/src/consensus/tendermint/engine.rs index 3f13e6d693..1805caef4b 100644 --- a/core/src/consensus/tendermint/engine.rs +++ b/core/src/consensus/tendermint/engine.rs @@ -248,7 +248,7 @@ impl ConsensusEngine for Tendermint { Ok(()) } - fn register_client(&self, client: Weak) { + fn register_client(&self, client: Weak) { *self.client.write() = Some(Weak::clone(&client)); self.stake.register_resources(client, Arc::downgrade(&self.validators)); } @@ -301,7 +301,7 @@ impl ConsensusEngine for Tendermint { } fn register_chain_notify(&self, client: &Client) { - client.add_notify(Arc::downgrade(&self.chain_notify) as Weak); + client.add_notify(Arc::downgrade(&self.chain_notify) as Weak); } fn get_best_block_from_best_proposal_header(&self, header: &HeaderView) -> H256 { @@ -319,7 +319,7 @@ impl ConsensusEngine for Tendermint { header.number() >= allowed_height } - fn action_handlers(&self) -> &[Arc] { + fn action_handlers(&self) -> &[Arc] { &self.action_handlers } @@ -363,7 +363,7 @@ fn block_number_if_term_changed( } fn inactive_validators( - client: &ConsensusClient, + client: &dyn ConsensusClient, start_of_the_current_term: u64, current_block: &Header, mut validators: HashSet
, @@ -380,8 +380,8 @@ fn inactive_validators( } fn calculate_pending_rewards_of_the_previous_term( - chain: &ConsensusClient, - validators: &ValidatorSet, + chain: &dyn ConsensusClient, + validators: &dyn ValidatorSet, rewards: BTreeMap, start_of_the_current_term: u64, start_of_the_current_term_header: encoded::Header, diff --git a/core/src/consensus/tendermint/mod.rs b/core/src/consensus/tendermint/mod.rs index 8366faf1ae..a5ca75668d 100644 --- a/core/src/consensus/tendermint/mod.rs +++ b/core/src/consensus/tendermint/mod.rs @@ -58,20 +58,20 @@ pub type BlockHash = H256; /// ConsensusEngine using `Tendermint` consensus algorithm pub struct Tendermint { - client: RwLock>>, + client: RwLock>>, external_params_initializer: crossbeam::Sender, - extension_initializer: crossbeam::Sender<(crossbeam::Sender, Weak)>, + extension_initializer: crossbeam::Sender<(crossbeam::Sender, Weak)>, timeouts: TimeoutParams, join: Option>, quit_tendermint: crossbeam::Sender<()>, inner: crossbeam::Sender, - validators: Arc, + validators: Arc, /// Reward per block, in base units. block_reward: u64, /// codechain machine descriptor machine: Arc, /// Action handlers for this consensus method - action_handlers: Vec>, + action_handlers: Vec>, /// stake object to register client data later stake: Arc, /// Chain notify @@ -98,7 +98,7 @@ impl Tendermint { let (join, external_params_initializer, extension_initializer, inner, quit_tendermint) = worker::spawn(our_params.validators); - let action_handlers: Vec> = vec![stake.clone()]; + let action_handlers: Vec> = vec![stake.clone()]; let chain_notify = Arc::new(TendermintChainNotify::new(inner.clone())); Arc::new(Tendermint { @@ -149,7 +149,7 @@ mod tests { let test = TestBlockChainClient::new_with_scheme(Scheme::new_test_tendermint()); let test_client: Arc = Arc::new(test); - let consensus_client = Arc::clone(&test_client) as Arc; + let consensus_client = Arc::clone(&test_client) as Arc; scheme.engine.register_client(Arc::downgrade(&consensus_client)); (scheme, tap, test_client) } @@ -172,7 +172,7 @@ mod tests { addr } - fn insert_and_register(tap: &Arc, engine: &CodeChainEngine, acc: &str) -> Address { + fn insert_and_register(tap: &Arc, engine: &dyn CodeChainEngine, acc: &str) -> Address { let addr = insert_and_unlock(tap, acc); engine.set_signer(tap.clone(), addr); addr diff --git a/core/src/consensus/tendermint/network.rs b/core/src/consensus/tendermint/network.rs index 05175fd636..d1746d51fa 100644 --- a/core/src/consensus/tendermint/network.rs +++ b/core/src/consensus/tendermint/network.rs @@ -44,7 +44,7 @@ use super::{ pub struct TendermintExtension { inner: crossbeam::Sender, peers: HashMap, - api: Box, + api: Box, timeouts: TimeoutParams, } @@ -52,7 +52,7 @@ const MIN_PEERS_PROPAGATION: usize = 4; const MAX_PEERS_PROPAGATION: usize = 128; impl TendermintExtension { - pub fn new(inner: crossbeam::Sender, timeouts: TimeoutParams, api: Box) -> Self { + pub fn new(inner: crossbeam::Sender, timeouts: TimeoutParams, api: Box) -> Self { let initial = timeouts.initial(); ctrace!(ENGINE, "Setting the initial timeout to {:?}.", initial); api.set_timer_once(ENGINE_TIMEOUT_TOKEN_NONCE_BASE, initial).expect("Timer set succeeds"); diff --git a/core/src/consensus/tendermint/worker.rs b/core/src/consensus/tendermint/worker.rs index ed23a1fdb0..86f6344af2 100644 --- a/core/src/consensus/tendermint/worker.rs +++ b/core/src/consensus/tendermint/worker.rs @@ -58,7 +58,7 @@ use std::cell::Cell; type SpawnResult = ( JoinHandle<()>, crossbeam::Sender, - crossbeam::Sender<(crossbeam::Sender, Weak)>, + crossbeam::Sender<(crossbeam::Sender, Weak)>, crossbeam::Sender, crossbeam::Sender<()>, ); @@ -68,7 +68,7 @@ pub fn spawn(validators: Arc) -> SpawnResult { } struct Worker { - client: Weak, + client: Weak, /// Blockchain height. height: Height, /// Consensus view. @@ -141,7 +141,7 @@ pub enum Event { signature: SchnorrSignature, view: View, message: Bytes, - result: crossbeam::Sender>>, + result: crossbeam::Sender>>, }, StepState { token: NodeId, @@ -169,7 +169,7 @@ pub enum Event { GetCommit { block: Bytes, votes: Vec, - result: crossbeam::Sender>>, + result: crossbeam::Sender>>, }, } @@ -178,7 +178,7 @@ impl Worker { fn new( validators: Arc, extension: EventSender, - client: Weak, + client: Weak, time_gap_params: TimeGapParams, ) -> Self { Worker { @@ -387,7 +387,7 @@ impl Worker { } /// The client is a thread-safe struct. Using it in multi-threads is safe. - fn client(&self) -> Arc { + fn client(&self) -> Arc { self.client.upgrade().expect("Client lives longer than consensus") } @@ -1697,7 +1697,7 @@ impl Worker { signature: SchnorrSignature, proposed_view: View, bytes: Bytes, - ) -> Option> { + ) -> Option> { let c = self.client.upgrade()?; // This block borrows bytes @@ -1986,7 +1986,7 @@ impl Worker { } #[allow(clippy::cognitive_complexity)] - fn on_commit_message(&mut self, block: Bytes, votes: Vec) -> Option> { + fn on_commit_message(&mut self, block: Bytes, votes: Vec) -> Option> { if self.step.is_commit() { return None } diff --git a/core/src/consensus/validator_set/dynamic_validator.rs b/core/src/consensus/validator_set/dynamic_validator.rs index bb4e12496d..b9b95a09c4 100644 --- a/core/src/consensus/validator_set/dynamic_validator.rs +++ b/core/src/consensus/validator_set/dynamic_validator.rs @@ -30,7 +30,7 @@ use crate::consensus::EngineError; /// Validator set containing a known set of public keys. pub struct DynamicValidator { initial_list: RoundRobinValidator, - client: RwLock>>, + client: RwLock>>, } impl DynamicValidator { @@ -42,7 +42,7 @@ impl DynamicValidator { } fn validators(&self, parent: H256) -> Option> { - let client: Arc = + let client: Arc = self.client.read().as_ref().and_then(Weak::upgrade).expect("Client is not initialized"); let block_id = parent.into(); let term_id = client.current_term_id(block_id).expect( @@ -174,7 +174,7 @@ impl ValidatorSet for DynamicValidator { } /// Allows blockchain state access. - fn register_client(&self, client: Weak) { + fn register_client(&self, client: Weak) { self.initial_list.register_client(Weak::clone(&client)); let mut client_lock = self.client.write(); assert!(client_lock.is_none()); @@ -207,7 +207,7 @@ mod tests { let a1 = Public::from_str("34959b60d54703e9dfe36afb1e9950a4abe34d666cbb64c92969013bc9cc74063f9e4680d9d48c4597ee623bd4b507a1b2f43a9c5766a06463f85b73a94c51d1").unwrap(); let a2 = Public::from_str("8c5a25bfafceea03073e2775cfb233a46648a088c12a1ca18a5865534887ccf60e1670be65b5f8e29643f463fdf84b1cbadd6027e71d8d04496570cb6b04885d").unwrap(); let set = DynamicValidator::new(vec![a1, a2]); - let test_client: Arc = Arc::new({ + let test_client: Arc = Arc::new({ let mut client = TestBlockChainClient::new(); client.term_id = Some(1); client diff --git a/core/src/consensus/validator_set/mod.rs b/core/src/consensus/validator_set/mod.rs index 4c84777c5e..b86f8d9d14 100644 --- a/core/src/consensus/validator_set/mod.rs +++ b/core/src/consensus/validator_set/mod.rs @@ -55,7 +55,7 @@ pub trait ValidatorSet: Send + Sync { fn check_enough_votes(&self, parent: &H256, votes: &BitSet) -> Result<(), EngineError>; /// Allows blockchain state access. - fn register_client(&self, _client: Weak) {} + fn register_client(&self, _client: Weak) {} fn addresses(&self, _parent: &H256) -> Vec
; } diff --git a/core/src/consensus/validator_set/validator_list.rs b/core/src/consensus/validator_set/validator_list.rs index a568ea435f..cdec5664e5 100644 --- a/core/src/consensus/validator_set/validator_list.rs +++ b/core/src/consensus/validator_set/validator_list.rs @@ -32,7 +32,7 @@ use crate::types::BlockId; pub struct RoundRobinValidator { validators: Vec, addresses: HashSet
, - client: RwLock>>, + client: RwLock>>, } impl RoundRobinValidator { @@ -70,7 +70,7 @@ impl ValidatorSet for RoundRobinValidator { } fn next_block_proposer(&self, parent: &H256, view: u64) -> Option
{ - let client: Arc = self.client.read().as_ref().and_then(Weak::upgrade)?; + let client: Arc = self.client.read().as_ref().and_then(Weak::upgrade)?; client.block_header(&BlockId::from(*parent)).map(|header| { let proposer = header.author(); let grand_parent = header.parent_hash(); @@ -101,7 +101,7 @@ impl ValidatorSet for RoundRobinValidator { } } - fn register_client(&self, client: Weak) { + fn register_client(&self, client: Weak) { *self.client.write() = Some(client); } diff --git a/core/src/db.rs b/core/src/db.rs index 115994fa6b..ec15ac4deb 100644 --- a/core/src/db.rs +++ b/core/src/db.rs @@ -88,13 +88,13 @@ pub trait Key { /// Should be used to write value into database. pub trait Writable { /// Writes the value into the database. - fn write(&mut self, col: Option, key: &Key, value: &T) + fn write(&mut self, col: Option, key: &dyn Key, value: &T) where T: rlp::Encodable, R: Deref; /// Deletes key from the databse. - fn delete(&mut self, col: Option, key: &Key) + fn delete(&mut self, col: Option, key: &dyn Key) where T: rlp::Encodable, R: Deref; @@ -103,7 +103,7 @@ pub trait Writable { fn write_with_cache( &mut self, col: Option, - cache: &mut Cache, + cache: &mut dyn Cache, key: K, value: T, policy: CacheUpdatePolicy, @@ -126,7 +126,7 @@ pub trait Writable { fn extend_with_cache( &mut self, col: Option, - cache: &mut Cache, + cache: &mut dyn Cache, values: HashMap, policy: CacheUpdatePolicy, ) where @@ -153,7 +153,7 @@ pub trait Writable { fn extend_with_option_cache( &mut self, col: Option, - cache: &mut Cache>, + cache: &mut dyn Cache>, values: HashMap>, policy: CacheUpdatePolicy, ) where @@ -186,7 +186,7 @@ pub trait Writable { /// Should be used to read values from database. pub trait Readable { /// Returns value for given key. - fn read(&self, col: Option, key: &Key) -> Option + fn read(&self, col: Option, key: &dyn Key) -> Option where T: rlp::Decodable, R: Deref; @@ -210,7 +210,7 @@ pub trait Readable { } /// Returns true if given value exists. - fn exists(&self, col: Option, key: &Key) -> bool + fn exists(&self, col: Option, key: &dyn Key) -> bool where R: Deref; @@ -232,14 +232,14 @@ pub trait Readable { } impl Writable for DBTransaction { - fn write(&mut self, col: Option, key: &Key, value: &T) + fn write(&mut self, col: Option, key: &dyn Key, value: &T) where T: rlp::Encodable, R: Deref, { self.put(col, &key.key(), &rlp::encode(value)); } - fn delete(&mut self, col: Option, key: &Key) + fn delete(&mut self, col: Option, key: &dyn Key) where T: rlp::Encodable, R: Deref, { @@ -248,7 +248,7 @@ impl Writable for DBTransaction { } impl Readable for KVDB { - fn read(&self, col: Option, key: &Key) -> Option + fn read(&self, col: Option, key: &dyn Key) -> Option where T: rlp::Decodable, R: Deref, { @@ -262,7 +262,7 @@ impl Readable for KVDB { } } - fn exists(&self, col: Option, key: &Key) -> bool + fn exists(&self, col: Option, key: &dyn Key) -> bool where R: Deref, { let result = self.get(col, &key.key()); diff --git a/core/src/miner/backup.rs b/core/src/miner/backup.rs index f355424eff..7ba35afc43 100644 --- a/core/src/miner/backup.rs +++ b/core/src/miner/backup.rs @@ -42,7 +42,7 @@ pub fn remove_item(batch: &mut DBTransaction, key: &H256) { batch.delete(dblib::COL_MEMPOOL, db_key.as_ref()); } -pub fn recover_to_data(db: &KeyValueDB) -> HashMap { +pub fn recover_to_data(db: &dyn KeyValueDB) -> HashMap { let mut by_hash = HashMap::new(); for (key, value) in db.iter(dblib::COL_MEMPOOL) { diff --git a/core/src/miner/mem_pool.rs b/core/src/miner/mem_pool.rs index 0ceb45dd02..d95627f55a 100644 --- a/core/src/miner/mem_pool.rs +++ b/core/src/miner/mem_pool.rs @@ -110,12 +110,12 @@ pub struct MemPool { /// Next id that should be assigned to a transaction imported to the pool next_transaction_id: u64, /// Arc of KeyValueDB in which the backup information is stored. - db: Arc, + db: Arc, } impl MemPool { /// Create new instance of this Queue with specified limits - pub fn with_limits(limit: usize, memory_limit: usize, fee_bump_shift: usize, db: Arc) -> Self { + pub fn with_limits(limit: usize, memory_limit: usize, fee_bump_shift: usize, db: Arc) -> Self { MemPool { minimal_fee: 0, fee_bump_shift, diff --git a/core/src/miner/miner.rs b/core/src/miner/miner.rs index 6e6de60521..43f1e00dbf 100644 --- a/core/src/miner/miner.rs +++ b/core/src/miner/miner.rs @@ -110,7 +110,7 @@ struct SealingWork { enabled: bool, } -type TransactionListener = Box; +type TransactionListener = Box; pub struct Miner { mem_pool: Arc>, @@ -120,18 +120,18 @@ pub struct Miner { sealing_block_last_request: Mutex, sealing_work: Mutex, params: RwLock, - engine: Arc, + engine: Arc, options: MinerOptions, sealing_enabled: AtomicBool, accounts: Option>, - notifiers: RwLock>>, + notifiers: RwLock>>, } impl Miner { /// Push listener that will handle new jobs - pub fn add_work_listener(&self, notifier: Box) { + pub fn add_work_listener(&self, notifier: Box) { self.notifiers.write().push(notifier); } @@ -139,12 +139,12 @@ impl Miner { options: MinerOptions, scheme: &Scheme, accounts: Option>, - db: Arc, + db: Arc, ) -> Arc { Arc::new(Self::new_raw(options, scheme, accounts, db)) } - pub fn with_scheme(scheme: &Scheme, db: Arc) -> Self { + pub fn with_scheme(scheme: &Scheme, db: Arc) -> Self { Self::new_raw(Default::default(), scheme, None, db) } @@ -152,7 +152,7 @@ impl Miner { options: MinerOptions, scheme: &Scheme, accounts: Option>, - db: Arc, + db: Arc, ) -> Self { let mem_limit = options.mem_pool_memory_limit.unwrap_or_else(usize::max_value); let mem_pool = Arc::new(RwLock::new(MemPool::with_limits( @@ -162,7 +162,7 @@ impl Miner { db, ))); - let notifiers: Vec> = if options.new_work_notify.is_empty() { + let notifiers: Vec> = if options.new_work_notify.is_empty() { Vec::new() } else { vec![Box::new(WorkPoster::new(&options.new_work_notify))] @@ -192,7 +192,7 @@ impl Miner { } /// Set a callback to be notified about imported transactions' hashes. - pub fn add_transactions_listener(&self, f: Box) { + pub fn add_transactions_listener(&self, f: Box) { self.transaction_listener.write().push(f); } @@ -1143,7 +1143,7 @@ pub mod test { miner.add_transactions_to_pool(client.as_ref(), transactions, TxOrigin::Local, &mut mem_pool); } - fn generate_test_client(db: Arc, miner: Arc, scheme: &Scheme) -> Result, Error> { + fn generate_test_client(db: Arc, miner: Arc, scheme: &Scheme) -> Result, Error> { let timer_loop = TimerLoop::new(2); let client_config: ClientConfig = Default::default(); diff --git a/core/src/scheme/scheme.rs b/core/src/scheme/scheme.rs index fd1ad38cb6..69a425a5a5 100644 --- a/core/src/scheme/scheme.rs +++ b/core/src/scheme/scheme.rs @@ -44,7 +44,7 @@ pub struct Scheme { /// User friendly scheme name pub name: String, /// What engine are we using for this? - pub engine: Arc, + pub engine: Arc, /// Name of the subdir inside the main data dir to use for chain data and settings. pub data_dir: String, @@ -97,7 +97,7 @@ impl Scheme { /// Convert engine scheme into a arc'd Engine of the right underlying type. /// TODO avoid this hard-coded nastiness - use dynamic-linked plugin framework instead. - fn engine(engine_scheme: cjson::scheme::Engine, params: CommonParams) -> Arc { + fn engine(engine_scheme: cjson::scheme::Engine, params: CommonParams) -> Arc { let machine = Self::machine(&engine_scheme, params); match engine_scheme { @@ -182,7 +182,7 @@ impl Scheme { Ok(top_level.commit_and_into_db()?) } - pub fn check_genesis_root(&self, db: &HashDB) -> bool { + pub fn check_genesis_root(&self, db: &dyn HashDB) -> bool { if db.is_empty() { return true } diff --git a/core/src/service.rs b/core/src/service.rs index 9744bbe3ec..78e3a1e4ef 100644 --- a/core/src/service.rs +++ b/core/src/service.rs @@ -38,7 +38,7 @@ impl ClientService { pub fn start( config: &ClientConfig, scheme: &Scheme, - db: Arc, + db: Arc, miner: Arc, reseal_timer: TimerApi, ) -> Result { diff --git a/core/src/verification/canon_verifier.rs b/core/src/verification/canon_verifier.rs index b481242c6b..295ed45769 100644 --- a/core/src/verification/canon_verifier.rs +++ b/core/src/verification/canon_verifier.rs @@ -31,7 +31,7 @@ impl Verifier for CanonVerifier { block: &[u8], header: &Header, parent: &Header, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, do_full: Option>, common_params: &CommonParams, ) -> Result<(), Error> { @@ -42,7 +42,7 @@ impl Verifier for CanonVerifier { verification::verify_block_final(expected, got) } - fn verify_block_external(&self, header: &Header, engine: &CodeChainEngine) -> Result<(), Error> { + fn verify_block_external(&self, header: &Header, engine: &dyn CodeChainEngine) -> Result<(), Error> { engine.verify_block_external(header) } } diff --git a/core/src/verification/mod.rs b/core/src/verification/mod.rs index 67174c5b9f..a13cb4a00e 100644 --- a/core/src/verification/mod.rs +++ b/core/src/verification/mod.rs @@ -58,7 +58,7 @@ impl Default for VerifierType { } /// Create a new verifier based on type. -pub fn new(v: VerifierType) -> Box> { +pub fn new(v: VerifierType) -> Box> { match v { VerifierType::Canon | VerifierType::CanonNoSeal => Box::new(CanonVerifier), VerifierType::Noop => Box::new(NoopVerifier), diff --git a/core/src/verification/noop_verifier.rs b/core/src/verification/noop_verifier.rs index 9d771d07d5..8c93d2e1a9 100644 --- a/core/src/verification/noop_verifier.rs +++ b/core/src/verification/noop_verifier.rs @@ -30,7 +30,7 @@ impl Verifier for NoopVerifier { _block: &[u8], _: &Header, _t: &Header, - _: &CodeChainEngine, + _: &dyn CodeChainEngine, _: Option>, _common_params: &CommonParams, ) -> Result<(), Error> { @@ -41,7 +41,7 @@ impl Verifier for NoopVerifier { Ok(()) } - fn verify_block_external(&self, _header: &Header, _engine: &CodeChainEngine) -> Result<(), Error> { + fn verify_block_external(&self, _header: &Header, _engine: &dyn CodeChainEngine) -> Result<(), Error> { Ok(()) } } diff --git a/core/src/verification/queue/kind.rs b/core/src/verification/queue/kind.rs index f1755ca2b0..7140d38a5b 100644 --- a/core/src/verification/queue/kind.rs +++ b/core/src/verification/queue/kind.rs @@ -70,12 +70,12 @@ pub trait Kind: 'static + Sized + Send + Sync { fn name() -> &'static str; /// Attempt to create the `Unverified` item from the input. - fn create(input: Self::Input, engine: &CodeChainEngine) -> Result; + fn create(input: Self::Input, engine: &dyn CodeChainEngine) -> Result; /// Attempt to verify the `Unverified` item using the given engine. fn verify( unverified: Self::Unverified, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, check_seal: bool, ) -> Result; @@ -120,14 +120,18 @@ pub mod headers { "Headers" } - fn create(input: Self::Input, engine: &CodeChainEngine) -> Result { + fn create(input: Self::Input, engine: &dyn CodeChainEngine) -> Result { // FIXME: this doesn't seem to match with full block verification verify_header_basic(&input)?; verify_header_with_engine(&input, engine)?; Ok(input) } - fn verify(un: Self::Unverified, engine: &CodeChainEngine, check_seal: bool) -> Result { + fn verify( + un: Self::Unverified, + engine: &dyn CodeChainEngine, + check_seal: bool, + ) -> Result { if check_seal { engine.verify_block_seal(&un).map(|_| un) } else { @@ -166,7 +170,7 @@ pub mod blocks { "Blocks" } - fn create(input: Self::Input, engine: &CodeChainEngine) -> Result { + fn create(input: Self::Input, engine: &dyn CodeChainEngine) -> Result { match verify_block_basic(&input.header, &input.bytes) .and_then(|_| verify_header_with_engine(&input.header, engine)) { @@ -178,7 +182,11 @@ pub mod blocks { } } - fn verify(un: Self::Unverified, engine: &CodeChainEngine, check_seal: bool) -> Result { + fn verify( + un: Self::Unverified, + engine: &dyn CodeChainEngine, + check_seal: bool, + ) -> Result { let hash = un.hash(); match verify_block_seal(un.header, un.bytes, engine, check_seal) { Ok(verified) => Ok(verified), diff --git a/core/src/verification/queue/mod.rs b/core/src/verification/queue/mod.rs index 2521d41820..451c51c787 100644 --- a/core/src/verification/queue/mod.rs +++ b/core/src/verification/queue/mod.rs @@ -63,7 +63,7 @@ impl Default for Config { } pub struct VerificationQueue { - engine: Arc, + engine: Arc, verification: Arc>, processing: RwLock>, // hash to score deleting: Arc, @@ -121,7 +121,7 @@ impl QueueSignal { impl VerificationQueue { pub fn new( config: &Config, - engine: Arc, + engine: Arc, message_channel: IoChannel, check_seal: bool, ) -> Self { @@ -193,7 +193,7 @@ impl VerificationQueue { fn verify( verification: &Verification, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, ready_signal: &QueueSignal, empty: &SCondvar, more_to_verify: &SCondvar, diff --git a/core/src/verification/verification.rs b/core/src/verification/verification.rs index c98d831846..7e7c88c61e 100644 --- a/core/src/verification/verification.rs +++ b/core/src/verification/verification.rs @@ -52,7 +52,7 @@ pub fn verify_block_basic(header: &Header, bytes: &[u8]) -> Result<(), Error> { Ok(()) } -pub fn verify_header_with_engine(header: &Header, engine: &CodeChainEngine) -> Result<(), Error> { +pub fn verify_header_with_engine(header: &Header, engine: &dyn CodeChainEngine) -> Result<(), Error> { engine.verify_header_basic(&header)?; let expected_seal_fields = engine.seal_fields(header); @@ -68,7 +68,7 @@ pub fn verify_header_with_engine(header: &Header, engine: &CodeChainEngine) -> R pub fn verify_block_with_params( header: &Header, bytes: &[u8], - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, common_params: &CommonParams, ) -> Result<(), Error> { verify_header_with_params(&header, common_params)?; @@ -157,7 +157,7 @@ fn verify_transactions_root( pub fn verify_block_seal( header: Header, bytes: Bytes, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, check_seal: bool, ) -> Result { if check_seal { @@ -188,7 +188,7 @@ pub struct FullFamilyParams<'a, C: BlockChainTrait + 'a> { pub transactions: &'a [SignedTransaction], /// Block provider to use during verification - pub block_provider: &'a BlockProvider, + pub block_provider: &'a dyn BlockProvider, /// Engine client to use during verification pub client: &'a C, @@ -199,7 +199,7 @@ pub fn verify_block_family( block: &[u8], header: &Header, parent: &Header, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, do_full: Option>, common_params: &CommonParams, ) -> Result<(), Error> { diff --git a/core/src/verification/verifier.rs b/core/src/verification/verifier.rs index e272d5b246..6917d0e4cb 100644 --- a/core/src/verification/verifier.rs +++ b/core/src/verification/verifier.rs @@ -31,7 +31,7 @@ where block: &[u8], header: &Header, parent: &Header, - engine: &CodeChainEngine, + engine: &dyn CodeChainEngine, do_full: Option>, common_params: &CommonParams, ) -> Result<(), Error>; @@ -39,5 +39,5 @@ where /// Do a final verification check for an enacted header vs its expected counterpart. fn verify_block_final(&self, expected: &Header, got: &Header) -> Result<(), Error>; /// Verify a block, inspecing external state. - fn verify_block_external(&self, header: &Header, engine: &CodeChainEngine) -> Result<(), Error>; + fn verify_block_external(&self, header: &Header, engine: &dyn CodeChainEngine) -> Result<(), Error>; } diff --git a/discovery/src/extension.rs b/discovery/src/extension.rs index a8d595ba80..16444a1128 100644 --- a/discovery/src/extension.rs +++ b/discovery/src/extension.rs @@ -32,13 +32,13 @@ use super::Config; pub struct Extension { config: Config, routing_table: Arc, - api: Box, + api: Box, nodes: HashSet, // FIXME: Find the optimized data structure for it use_kademlia: bool, } impl Extension { - pub fn new(routing_table: Arc, config: Config, api: Box, use_kademlia: bool) -> Self { + pub fn new(routing_table: Arc, config: Config, api: Box, use_kademlia: bool) -> Self { if use_kademlia { cinfo!(DISCOVERY, "Discovery starts with kademlia option"); } else { diff --git a/keystore/src/import.rs b/keystore/src/import.rs index d7e55cfd68..2a0130c1da 100644 --- a/keystore/src/import.rs +++ b/keystore/src/import.rs @@ -25,7 +25,7 @@ use crate::accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}; use crate::Error; /// Import an account from a file. -pub fn import_account(path: &Path, dst: &KeyDirectory) -> Result { +pub fn import_account(path: &Path, dst: &dyn KeyDirectory) -> Result { let key_manager = DiskKeyFileManager; let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::>(); let filename = path.file_name().and_then(OsStr::to_str).map(ToOwned::to_owned); @@ -39,7 +39,7 @@ pub fn import_account(path: &Path, dst: &KeyDirectory) -> Result } /// Import all accounts from one directory to the other. -pub fn import_accounts(src: &KeyDirectory, dst: &KeyDirectory) -> Result, Error> { +pub fn import_accounts(src: &dyn KeyDirectory, dst: &dyn KeyDirectory) -> Result, Error> { let accounts = src.load()?; let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::>(); diff --git a/keystore/src/keystore.rs b/keystore/src/keystore.rs index 8cd8a23f14..bc46604b7c 100644 --- a/keystore/src/keystore.rs +++ b/keystore/src/keystore.rs @@ -36,12 +36,12 @@ pub struct KeyStore { impl KeyStore { /// Open a new accounts store with given key directory backend. - pub fn open(directory: Box) -> Result { + pub fn open(directory: Box) -> Result { Self::open_with_iterations(directory, KEY_ITERATIONS as u32) } /// Open a new account store with given key directory backend and custom number of iterations. - pub fn open_with_iterations(directory: Box, iterations: u32) -> Result { + pub fn open_with_iterations(directory: Box, iterations: u32) -> Result { Ok(KeyStore { store: KeyMultiStore::open_with_iterations(directory, iterations)?, }) @@ -123,7 +123,7 @@ impl SecretStore for KeyStore { fn copy_account( &self, - new_store: &SimpleSecretStore, + new_store: &dyn SimpleSecretStore, account: &Address, password: &Password, new_password: &Password, @@ -159,7 +159,7 @@ impl SecretStore for KeyStore { /// Similar to `KeyStore` but may store many accounts (with different passwords) for the same `Address` pub struct KeyMultiStore { - dir: Box, + dir: Box, iterations: u32, // order lock: cache cache: RwLock>>, @@ -174,12 +174,12 @@ struct Timestamp { impl KeyMultiStore { /// Open new multi-accounts store with given key directory backend. - pub fn open(directory: Box) -> Result { + pub fn open(directory: Box) -> Result { Self::open_with_iterations(directory, KEY_ITERATIONS as u32) } /// Open new multi-accounts store with given key directory backend and custom number of iterations for new keys. - pub fn open_with_iterations(directory: Box, iterations: u32) -> Result { + pub fn open_with_iterations(directory: Box, iterations: u32) -> Result { let store = KeyMultiStore { dir: directory, iterations, diff --git a/keystore/src/secret_store.rs b/keystore/src/secret_store.rs index 51cb3ced53..fa00667dd3 100644 --- a/keystore/src/secret_store.rs +++ b/keystore/src/secret_store.rs @@ -68,7 +68,7 @@ pub trait SecretStore: SimpleSecretStore { /// Copies account between stores. fn copy_account( &self, - new_store: &SimpleSecretStore, + new_store: &dyn SimpleSecretStore, account: &Address, password: &Password, new_password: &Password, diff --git a/network/src/client.rs b/network/src/client.rs index 06bcc80601..8d94fb15a5 100644 --- a/network/src/client.rs +++ b/network/src/client.rs @@ -112,7 +112,7 @@ impl Client { where T: 'static + Sized + NetworkExtension, E: 'static + Sized + Send, - F: 'static + FnOnce(Box) -> T + Send, { + F: 'static + FnOnce(Box) -> T + Send, { let mut extensions = self.extensions.write(); let name = T::name(); let timer = self.timer_loop.new_timer_with_name(name); diff --git a/network/src/p2p/handler.rs b/network/src/p2p/handler.rs index 0a108d0f3e..6cc7a0193e 100644 --- a/network/src/p2p/handler.rs +++ b/network/src/p2p/handler.rs @@ -102,7 +102,7 @@ pub struct Handler { establishing_outgoing_session: Mutex>, routing_table: Arc, - filters: Arc, + filters: Arc, remote_node_ids: RwLock>, remote_node_ids_reverse: RwLock>, @@ -126,7 +126,7 @@ impl Handler { socket_address: SocketAddr, client: Arc, routing_table: Arc, - filters: Arc, + filters: Arc, bootstrap_addresses: Vec, min_peers: usize, max_peers: usize, diff --git a/network/src/service.rs b/network/src/service.rs index 62f64bd596..93b5449d42 100644 --- a/network/src/service.rs +++ b/network/src/service.rs @@ -35,7 +35,7 @@ pub struct Service { client: Arc, routing_table: Arc, p2p_handler: Arc, - filters_control: Arc, + filters_control: Arc, } impl Service { @@ -46,7 +46,7 @@ impl Service { bootstrap_addresses: Vec, min_peers: usize, max_peers: usize, - filters_control: Arc, + filters_control: Arc, routing_table: Arc, ) -> Result, Error> { let p2p = IoService::start("P2P")?; @@ -79,7 +79,7 @@ impl Service { where T: 'static + Sized + NetworkExtension, E: 'static + Sized + Send, - F: 'static + FnOnce(Box) -> T + Send, { + F: 'static + FnOnce(Box) -> T + Send, { self.client.register_extension(factory) } diff --git a/rpc/src/v1/impls/devel.rs b/rpc/src/v1/impls/devel.rs index e916b8ec56..51e96aa71d 100644 --- a/rpc/src/v1/impls/devel.rs +++ b/rpc/src/v1/impls/devel.rs @@ -47,7 +47,7 @@ use super::super::types::{TPSTestOption, TPSTestSetting}; pub struct DevelClient { client: Arc, - db: Arc, + db: Arc, miner: Arc, block_sync: Option>, } diff --git a/rpc/src/v1/impls/net.rs b/rpc/src/v1/impls/net.rs index d76bdb9d74..7d2c50b282 100644 --- a/rpc/src/v1/impls/net.rs +++ b/rpc/src/v1/impls/net.rs @@ -28,11 +28,11 @@ use super::super::traits::Net; use super::super::types::FilterStatus; pub struct NetClient { - network_control: Arc, + network_control: Arc, } impl NetClient { - pub fn new(network_control: Arc) -> Self { + pub fn new(network_control: Arc) -> Self { Self { network_control, } diff --git a/state/src/action_handler/mod.rs b/state/src/action_handler/mod.rs index 55bd45a250..519f8e62df 100644 --- a/state/src/action_handler/mod.rs +++ b/state/src/action_handler/mod.rs @@ -57,7 +57,7 @@ pub trait ActionHandler: Send + Sync { } pub trait FindActionHandler { - fn find_action_handler_for(&self, _id: u64) -> Option<&ActionHandler> { + fn find_action_handler_for(&self, _id: u64) -> Option<&dyn ActionHandler> { None } } diff --git a/state/src/cache/shard_cache.rs b/state/src/cache/shard_cache.rs index 1d19bc8b9e..b028036758 100644 --- a/state/src/cache/shard_cache.rs +++ b/state/src/cache/shard_cache.rs @@ -52,7 +52,7 @@ impl ShardCache { self.asset.revert_to_checkpoint(); } - pub fn commit(&mut self, trie: &mut TrieMut) -> TrieResult<()> { + pub fn commit(&mut self, trie: &mut dyn TrieMut) -> TrieResult<()> { self.asset_scheme.commit(trie)?; self.asset.commit(trie)?; Ok(()) diff --git a/state/src/cache/top_cache.rs b/state/src/cache/top_cache.rs index 6c9bb78e37..91c442078b 100644 --- a/state/src/cache/top_cache.rs +++ b/state/src/cache/top_cache.rs @@ -80,7 +80,7 @@ impl TopCache { self.action_data.revert_to_checkpoint(); } - pub fn commit<'db>(&mut self, trie: &mut (TrieMut + 'db)) -> TrieResult<()> { + pub fn commit<'db>(&mut self, trie: &mut (dyn TrieMut + 'db)) -> TrieResult<()> { self.account.commit(trie)?; self.regular_account.commit(trie)?; self.metadata.commit(trie)?; diff --git a/state/src/cache/write_back.rs b/state/src/cache/write_back.rs index 46a68e542e..f2323ec4d1 100644 --- a/state/src/cache/write_back.rs +++ b/state/src/cache/write_back.rs @@ -176,7 +176,7 @@ where } } - pub fn commit<'db>(&mut self, trie: &mut (TrieMut + 'db)) -> TrieResult<()> { + pub fn commit<'db>(&mut self, trie: &mut (dyn TrieMut + 'db)) -> TrieResult<()> { let mut cache = self.cache.borrow_mut(); for (address, ref mut a) in cache.iter_mut().filter(|&(_, ref a)| a.is_dirty) { a.is_dirty = false; diff --git a/state/src/db/state_db.rs b/state/src/db/state_db.rs index 3035482f84..ed129bb013 100644 --- a/state/src/db/state_db.rs +++ b/state/src/db/state_db.rs @@ -47,14 +47,14 @@ use crate::impls::TopLevelState; /// State database abstraction. pub struct StateDB { /// Backing database. - db: Box, + db: Box, cache: GlobalCache, current_hash: Option, } impl StateDB { /// Create a new instance wrapping `JournalDB` - pub fn new(db: Box) -> StateDB { + pub fn new(db: Box) -> StateDB { StateDB { db, cache: Default::default(), @@ -130,12 +130,12 @@ impl StateDB { impl AsHashDB for StateDB { /// Conversion method to interpret self as `HashDB` reference - fn as_hashdb(&self) -> &HashDB { + fn as_hashdb(&self) -> &dyn HashDB { self.db.as_hashdb() } /// Conversion method to interpret self as mutable `HashDB` reference - fn as_hashdb_mut(&mut self) -> &mut HashDB { + fn as_hashdb_mut(&mut self) -> &mut dyn HashDB { self.db.as_hashdb_mut() } } diff --git a/state/src/impls/shard_level.rs b/state/src/impls/shard_level.rs index 0a079f1d7c..07a9333445 100644 --- a/state/src/impls/shard_level.rs +++ b/state/src/impls/shard_level.rs @@ -521,7 +521,7 @@ impl<'db> ShardLevelState<'db> { fn check_and_run_input_script( &self, input: &AssetTransferInput, - transaction: &PartialHashing, + transaction: &dyn PartialHashing, burn: bool, sender: &Address, approvers: &[Address], @@ -534,7 +534,7 @@ impl<'db> ShardLevelState<'db> { return Ok(()) // Don't execute scripts when regulator sends the transaction. } - let to_hash: &PartialHashing = transaction; + let to_hash: &dyn PartialHashing = transaction; if *asset.lock_script_hash() != Blake::blake(&input.lock_script) { return Err(RuntimeError::ScriptHashMismatch(Mismatch { diff --git a/state/src/impls/top_level.rs b/state/src/impls/top_level.rs index ba4fe10b79..55cf04cc22 100644 --- a/state/src/impls/top_level.rs +++ b/state/src/impls/top_level.rs @@ -127,7 +127,7 @@ impl TopStateView for TopLevelState { self.top_cache.shard(&shard_address, &trie) } - fn shard_state<'db>(&'db self, shard_id: ShardId) -> TrieResult>> { + fn shard_state<'db>(&'db self, shard_id: ShardId) -> TrieResult>> { match self.shard_root(shard_id)? { // FIXME: Find a way to use stored cache. Some(shard_root) => { @@ -999,7 +999,7 @@ impl TopState for TopLevelState { } } -fn is_active_account(state: &TopStateView, address: &Address) -> TrieResult { +fn is_active_account(state: &dyn TopStateView, address: &Address) -> TrieResult { match &state.account(address)? { Some(account) if account.is_active() => Ok(true), _ => Ok(false), diff --git a/state/src/tests.rs b/state/src/tests.rs index ce41af4a02..3de024e8e2 100644 --- a/state/src/tests.rs +++ b/state/src/tests.rs @@ -44,7 +44,7 @@ pub mod helpers { impl FindActionHandler for TestClient {} - pub fn get_memory_db() -> Arc { + pub fn get_memory_db() -> Arc { Arc::new(kvdb_memorydb::create(1)) } diff --git a/state/src/traits.rs b/state/src/traits.rs index 0828b9ffad..164e2e53fa 100644 --- a/state/src/traits.rs +++ b/state/src/traits.rs @@ -93,7 +93,7 @@ pub trait TopStateView { } fn shard(&self, shard_id: ShardId) -> TrieResult>; - fn shard_state<'db>(&'db self, shard_id: ShardId) -> TrieResult>>; + fn shard_state<'db>(&'db self, shard_id: ShardId) -> TrieResult>>; fn shard_root(&self, shard_id: ShardId) -> TrieResult> { Ok(self.shard(shard_id)?.map(|shard| *shard.root())) diff --git a/stratum/src/lib.rs b/stratum/src/lib.rs index a92088c0ca..2a38335fff 100644 --- a/stratum/src/lib.rs +++ b/stratum/src/lib.rs @@ -76,7 +76,7 @@ pub struct Stratum { impl Stratum { pub fn start( addr: &SocketAddr, - dispatcher: Arc, + dispatcher: Arc, secret: Option, ) -> Result, Error> { let implementation = Arc::new(StratumImpl { @@ -135,7 +135,7 @@ struct StratumImpl { /// List of workers supposed to receive job update job_que: RwLock>, /// Payload manager - dispatcher: Arc, + dispatcher: Arc, /// Authorized workers (socket - worker_id) workers: Arc>>, /// Secret if any diff --git a/sync/src/block/downloader/header.rs b/sync/src/block/downloader/header.rs index 141998c988..d05a40074f 100644 --- a/sync/src/block/downloader/header.rs +++ b/sync/src/block/downloader/header.rs @@ -38,7 +38,7 @@ struct Pivot { #[derive(Clone)] pub struct HeaderDownloader { // NOTE: Use this member as minimum as possible. - client: Arc, + client: Arc, total_score: U256, best_hash: H256, @@ -55,7 +55,7 @@ impl HeaderDownloader { self.total_score } - pub fn new(client: Arc, total_score: U256, best_hash: H256) -> Self { + pub fn new(client: Arc, total_score: U256, best_hash: H256) -> Self { let best_header_hash = client.best_block_header().hash(); let best_score = client.block_total_score(&BlockId::Latest).expect("Best block always exist"); diff --git a/sync/src/block/extension.rs b/sync/src/block/extension.rs index d865a56fd2..1038e2c4b6 100644 --- a/sync/src/block/extension.rs +++ b/sync/src/block/extension.rs @@ -64,12 +64,12 @@ pub struct Extension { tokens_info: HashMap, token_generator: TokenGenerator, client: Arc, - api: Box, + api: Box, last_request: u64, } impl Extension { - pub fn new(client: Arc, api: Box) -> Extension { + pub fn new(client: Arc, api: Box) -> Extension { api.set_timer(SYNC_TIMER_TOKEN, Duration::from_millis(SYNC_TIMER_INTERVAL)).expect("Timer set succeeds"); let mut header = client.best_header(); diff --git a/sync/src/snapshot/snapshot.rs b/sync/src/snapshot/snapshot.rs index d0759e9494..d0e03eed00 100644 --- a/sync/src/snapshot/snapshot.rs +++ b/sync/src/snapshot/snapshot.rs @@ -71,7 +71,7 @@ impl Snapshot { Ok(()) } - fn read_chunk(&self, backing: Arc, root: &H256) -> Result { + fn read_chunk(&self, backing: Arc, root: &H256) -> Result { let file = File::open(self.file_for(root))?; let mut buf = Vec::new(); let mut snappy = snap::Reader::new(file); @@ -123,7 +123,7 @@ impl Snapshot { } struct Chunk { - journal: Box, + journal: Box, never_referenced_keys: Vec, } @@ -185,15 +185,15 @@ impl Chunk { } pub trait WriteSnapshot { - fn write_snapshot(&self, db: &KeyValueDB, root: &H256) -> Result<(), Error>; + fn write_snapshot(&self, db: &dyn KeyValueDB, root: &H256) -> Result<(), Error>; } pub trait ReadSnapshot { - fn read_snapshot(&self, db: Arc, root: &H256) -> Result<(), Error>; + fn read_snapshot(&self, db: Arc, root: &H256) -> Result<(), Error>; } impl WriteSnapshot for Snapshot { - fn write_snapshot(&self, db: &KeyValueDB, root: &H256) -> Result<(), Error> { + fn write_snapshot(&self, db: &dyn KeyValueDB, root: &H256) -> Result<(), Error> { let root_val = match db.get(COL_STATE, root) { Ok(Some(value)) => value.to_vec(), Ok(None) => return Err(Error::SyncError("Invalid state root, or the database is empty".to_string())), @@ -217,7 +217,7 @@ impl WriteSnapshot for Snapshot { } impl ReadSnapshot for Snapshot { - fn read_snapshot(&self, db: Arc, root: &H256) -> Result<(), Error> { + fn read_snapshot(&self, db: Arc, root: &H256) -> Result<(), Error> { let head = { let mut head = self.read_chunk(db.clone(), root)?; if head.purge() { @@ -253,7 +253,7 @@ impl ReadSnapshot for Snapshot { } } -fn get_node(db: &KeyValueDB, key: &H256) -> Result, Error> { +fn get_node(db: &dyn KeyValueDB, key: &H256) -> Result, Error> { match db.get(COL_STATE, key) { Ok(Some(value)) => Ok(value.to_vec()), Ok(None) => Err(Error::NodeNotFound(*key)), @@ -261,7 +261,7 @@ fn get_node(db: &KeyValueDB, key: &H256) -> Result, Error> { } } -fn children_of(db: &KeyValueDB, node: &[u8]) -> Result)>, Error> { +fn children_of(db: &dyn KeyValueDB, node: &[u8]) -> Result)>, Error> { let keys = match Node::decoded(node) { None => Vec::new(), Some(Node::Leaf(..)) => Vec::new(), @@ -275,7 +275,7 @@ fn children_of(db: &KeyValueDB, node: &[u8]) -> Result)>, Err Ok(result) } -fn enumerate_subtree(db: &KeyValueDB, root: &H256) -> Result)>, Error> { +fn enumerate_subtree(db: &dyn KeyValueDB, root: &H256) -> Result)>, Error> { let node = get_node(db, root)?; let children = match Node::decoded(&node) { None => Vec::new(), diff --git a/sync/src/transaction/extension.rs b/sync/src/transaction/extension.rs index ea24368749..4eb1aa912c 100644 --- a/sync/src/transaction/extension.rs +++ b/sync/src/transaction/extension.rs @@ -55,12 +55,12 @@ impl KnownTxs { pub struct Extension { known_txs: KnownTxs, peers: HashMap, - client: Arc, - api: Box, + client: Arc, + api: Box, } impl Extension { - pub fn new(client: Arc, api: Box) -> Self { + pub fn new(client: Arc, api: Box) -> Self { api.set_timer(BROADCAST_TIMER_TOKEN, Duration::from_millis(BROADCAST_TIMER_INTERVAL)) .expect("Timer set succeeds"); Extension { diff --git a/util/hashdb/src/lib.rs b/util/hashdb/src/lib.rs index 801928b4e7..3550d0619b 100644 --- a/util/hashdb/src/lib.rs +++ b/util/hashdb/src/lib.rs @@ -56,26 +56,26 @@ pub trait HashDB: AsHashDB + Send + Sync { /// Upcast trait. pub trait AsHashDB { /// Perform upcast to HashDB for anything that derives from HashDB. - fn as_hashdb(&self) -> &HashDB; + fn as_hashdb(&self) -> &dyn HashDB; /// Perform mutable upcast to HashDB for anything that derives from HashDB. - fn as_hashdb_mut(&mut self) -> &mut HashDB; + fn as_hashdb_mut(&mut self) -> &mut dyn HashDB; } impl AsHashDB for T { - fn as_hashdb(&self) -> &HashDB { + fn as_hashdb(&self) -> &dyn HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { + fn as_hashdb_mut(&mut self) -> &mut dyn HashDB { self } } -impl<'a> AsHashDB for &'a mut HashDB { - fn as_hashdb(&self) -> &HashDB { +impl<'a> AsHashDB for &'a mut dyn HashDB { + fn as_hashdb(&self) -> &dyn HashDB { &**self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { + fn as_hashdb_mut(&mut self) -> &mut dyn HashDB { &mut **self } } diff --git a/util/io/src/service.rs b/util/io/src/service.rs index 65a8a7c016..91d564b333 100644 --- a/util/io/src/service.rs +++ b/util/io/src/service.rs @@ -176,7 +176,7 @@ struct UserTimer { once: bool, } -type HandlerType = RwLock>>>; +type HandlerType = RwLock>>>; /// Root IO handler. Manages user handler, messages and IO timers. pub struct IoManager @@ -479,7 +479,7 @@ where } /// Register an IO handler with the event loop. - pub fn register_handler(&self, handler: Arc + Send>) -> Result<(), IoError> { + pub fn register_handler(&self, handler: Arc + Send>) -> Result<(), IoError> { let h = Arc::clone(&handler); assert!(self.handler.read().is_none()); *self.handler.write() = Some(handler); diff --git a/util/io/src/worker.rs b/util/io/src/worker.rs index 841ec10455..ba292abf50 100644 --- a/util/io/src/worker.rs +++ b/util/io/src/worker.rs @@ -44,7 +44,7 @@ pub enum WorkType { pub struct Work { pub work_type: WorkType, pub token: usize, - pub handler: Arc>, + pub handler: Arc>, } /// An IO worker thread diff --git a/util/journaldb/src/archivedb.rs b/util/journaldb/src/archivedb.rs index 3859e5e9c4..62e5729780 100644 --- a/util/journaldb/src/archivedb.rs +++ b/util/journaldb/src/archivedb.rs @@ -37,14 +37,14 @@ use traits::JournalDB; /// that the states of any block the node has ever processed will be accessible. pub struct ArchiveDB { overlay: MemoryDB, - backing: Arc, + backing: Arc, latest_era: Option, column: Option, } impl ArchiveDB { /// Create a new instance from a key-value db. - pub fn new(backing: Arc, col: Option) -> ArchiveDB { + pub fn new(backing: Arc, col: Option) -> ArchiveDB { let latest_era = backing.get(col, &LATEST_ERA_KEY).expect("Low-level database error.").map(|val| decode::(&val)); ArchiveDB { @@ -109,7 +109,7 @@ impl HashDB for ArchiveDB { } impl JournalDB for ArchiveDB { - fn boxed_clone(&self) -> Box { + fn boxed_clone(&self) -> Box { Box::new(ArchiveDB { overlay: self.overlay.clone(), backing: self.backing.clone(), @@ -189,7 +189,7 @@ impl JournalDB for ArchiveDB { false } - fn backing(&self) -> &Arc { + fn backing(&self) -> &Arc { &self.backing } diff --git a/util/journaldb/src/lib.rs b/util/journaldb/src/lib.rs index 3ae7da9679..4614077fa0 100644 --- a/util/journaldb/src/lib.rs +++ b/util/journaldb/src/lib.rs @@ -85,7 +85,7 @@ impl fmt::Display for Algorithm { } /// Create a new `JournalDB` trait object over a generic key-value database. -pub fn new(backing: Arc<::kvdb::KeyValueDB>, algorithm: Algorithm, col: Option) -> Box { +pub fn new(backing: Arc, algorithm: Algorithm, col: Option) -> Box { match algorithm { Algorithm::Archive => Box::new(archivedb::ArchiveDB::new(backing, col)), } diff --git a/util/journaldb/src/traits.rs b/util/journaldb/src/traits.rs index 5bb39486c0..64fb31e54e 100644 --- a/util/journaldb/src/traits.rs +++ b/util/journaldb/src/traits.rs @@ -26,7 +26,7 @@ use std::sync::Arc; /// exclusive actions. pub trait JournalDB: HashDB { /// Return a copy of ourself, in a box. - fn boxed_clone(&self) -> Box; + fn boxed_clone(&self) -> Box; /// Returns the size of journalled state in memory. /// This function has a considerable speed requirement -- @@ -68,7 +68,7 @@ pub trait JournalDB: HashDB { } /// Get backing database. - fn backing(&self) -> &Arc; + fn backing(&self) -> &Arc; /// Clear internal strucutres. This should called after changes have been written /// to the backing strage diff --git a/util/kvdb/src/lib.rs b/util/kvdb/src/lib.rs index f430e4d46d..cdee56678f 100644 --- a/util/kvdb/src/lib.rs +++ b/util/kvdb/src/lib.rs @@ -183,4 +183,4 @@ pub trait KeyValueDB: Sync + Send { fn restore(&self, new_db: &str) -> Result<()>; } -pub type KeyValueDBIterator<'a> = Box, Box<[u8]>)> + 'a>; +pub type KeyValueDBIterator<'a> = Box, Box<[u8]>)> + 'a>; diff --git a/util/merkle/src/lib.rs b/util/merkle/src/lib.rs index dca921debe..63f7b708f7 100644 --- a/util/merkle/src/lib.rs +++ b/util/merkle/src/lib.rs @@ -140,17 +140,17 @@ pub enum TrieFactory {} impl TrieFactory { /// Create new immutable instance of Trie. - pub fn readonly<'db>(db: &'db HashDB, root: &'db H256) -> Result> { + pub fn readonly<'db>(db: &'db dyn HashDB, root: &'db H256) -> Result> { Ok(TrieDB::try_new(db, root)?) } /// Create new mutable instance of Trie. - pub fn create<'db>(db: &'db mut HashDB, root: &'db mut H256) -> Box { + pub fn create<'db>(db: &'db mut dyn HashDB, root: &'db mut H256) -> Box { Box::new(TrieDBMut::new(db, root)) } /// Create new mutable instance of trie and check for errors. - pub fn from_existing<'db>(db: &'db mut HashDB, root: &'db mut H256) -> Result> { + pub fn from_existing<'db>(db: &'db mut dyn HashDB, root: &'db mut H256) -> Result> { Ok(Box::new(TrieDBMut::from_existing(db, root)?)) } } diff --git a/util/merkle/src/triedb.rs b/util/merkle/src/triedb.rs index b377a1a74a..7ef72e31bb 100644 --- a/util/merkle/src/triedb.rs +++ b/util/merkle/src/triedb.rs @@ -48,14 +48,14 @@ use crate::{Query, Trie, TrieError}; /// } /// ``` pub struct TrieDB<'db> { - db: &'db HashDB, + db: &'db dyn HashDB, root: &'db H256, } impl<'db> TrieDB<'db> { /// Create a new trie with the backing database `db` and `root` /// Returns an error if `root` does not exist - pub fn try_new(db: &'db HashDB, root: &'db H256) -> crate::Result { + pub fn try_new(db: &'db dyn HashDB, root: &'db H256) -> crate::Result { if !db.contains(root) { Err(TrieError::InvalidStateRoot(*root)) } else { @@ -67,7 +67,7 @@ impl<'db> TrieDB<'db> { } /// Get the backing database. - pub fn db(&self) -> &HashDB { + pub fn db(&self) -> &dyn HashDB { self.db } diff --git a/util/merkle/src/triedbmut.rs b/util/merkle/src/triedbmut.rs index 456628d9fb..17b2a23da6 100644 --- a/util/merkle/src/triedbmut.rs +++ b/util/merkle/src/triedbmut.rs @@ -31,14 +31,14 @@ fn empty_children() -> [Option; 16] { } pub struct TrieDBMut<'a> { - db: &'a mut HashDB, + db: &'a mut dyn HashDB, // When Trie is empty, root has None. root: &'a mut H256, } impl<'a> TrieDBMut<'a> { /// Create a new trie with backing database `db` and empty `root`. - pub fn new(db: &'a mut HashDB, root: &'a mut H256) -> Self { + pub fn new(db: &'a mut dyn HashDB, root: &'a mut H256) -> Self { *root = BLAKE_NULL_RLP; TrieDBMut { @@ -49,7 +49,7 @@ impl<'a> TrieDBMut<'a> { /// Create a new trie with the backing database `db` and `root. /// Returns an error if `root` does not exist. - pub fn from_existing(db: &'a mut HashDB, root: &'a mut H256) -> crate::Result { + pub fn from_existing(db: &'a mut dyn HashDB, root: &'a mut H256) -> crate::Result { if !db.contains(root) { return Err(TrieError::InvalidStateRoot(*root)) } @@ -348,7 +348,7 @@ mod tests { use super::*; - fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &[(Vec, Vec)]) -> TrieDBMut<'db> { + fn populate_trie<'db>(db: &'db mut dyn HashDB, root: &'db mut H256, v: &[(Vec, Vec)]) -> TrieDBMut<'db> { let mut t = TrieDBMut::new(db, root); for (key, val) in v { t.insert(key, val).unwrap(); diff --git a/util/rlp_compress/src/lib.rs b/util/rlp_compress/src/lib.rs index 25c1fa7d82..2b0c1fe642 100644 --- a/util/rlp_compress/src/lib.rs +++ b/util/rlp_compress/src/lib.rs @@ -40,7 +40,7 @@ pub trait Decompressor { } /// Call this function to compress rlp. -pub fn compress(c: &[u8], swapper: &Compressor) -> ElasticArray1024 { +pub fn compress(c: &[u8], swapper: &dyn Compressor) -> ElasticArray1024 { let rlp = UntrustedRlp::new(c); if rlp.is_data() { ElasticArray1024::from_slice(swapper.compressed(rlp.as_raw()).unwrap_or_else(|| rlp.as_raw())) @@ -50,7 +50,7 @@ pub fn compress(c: &[u8], swapper: &Compressor) -> ElasticArray1024 { } /// Call this function to decompress rlp. -pub fn decompress(c: &[u8], swapper: &Decompressor) -> ElasticArray1024 { +pub fn decompress(c: &[u8], swapper: &dyn Decompressor) -> ElasticArray1024 { let rlp = UntrustedRlp::new(c); if rlp.is_data() { ElasticArray1024::from_slice(swapper.decompressed(rlp.as_raw()).unwrap_or_else(|| rlp.as_raw())) diff --git a/util/secp256k1/src/lib.rs b/util/secp256k1/src/lib.rs index 0bfb6dc16b..21b37dc0d4 100644 --- a/util/secp256k1/src/lib.rs +++ b/util/secp256k1/src/lib.rs @@ -333,7 +333,7 @@ impl fmt::Display for Error { } impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } diff --git a/util/timer/src/timer.rs b/util/timer/src/timer.rs index c0e4990a81..565685ae2b 100644 --- a/util/timer/src/timer.rs +++ b/util/timer/src/timer.rs @@ -106,7 +106,7 @@ type TimerId = usize; pub struct TimerApi { timer_id: TimerId, timer_name: Arc>>, - handler: Arc>>>, + handler: Arc>>>, scheduler: Weak, } @@ -533,7 +533,7 @@ struct Schedule { schedule_id: ScheduleId, repeat: Option, state_control: Arc, - handler: Weak, + handler: Weak, timer_name: TimerName, } @@ -569,7 +569,7 @@ struct Callback { schedule_id: ScheduleId, from_oneshot_schedule: bool, state_control: Arc, - handler: Arc, + handler: Arc, timer_name: TimerName, } diff --git a/vm/src/executor.rs b/vm/src/executor.rs index f5dbd8843a..ab03140cd7 100644 --- a/vm/src/executor.rs +++ b/vm/src/executor.rs @@ -164,7 +164,7 @@ pub fn execute( unlock: &[Instruction], params: &[Vec], lock: &[Instruction], - tx: &PartialHashing, + tx: &dyn PartialHashing, config: Config, cur: &AssetTransferInput, burn: bool, From 9e3174c86c16fe66339e77dbe595e30cca9ea836 Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 7 Oct 2019 11:14:57 +0900 Subject: [PATCH 3/3] `...` range patterns are deprecated --- network/src/p2p/handler.rs | 58 +++++++++++++++++------------------ sync/src/block/extension.rs | 2 +- util/rlp/src/stream.rs | 4 +-- util/rlp/src/untrusted_rlp.rs | 22 ++++++------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/network/src/p2p/handler.rs b/network/src/p2p/handler.rs index 6cc7a0193e..ce46872384 100644 --- a/network/src/p2p/handler.rs +++ b/network/src/p2p/handler.rs @@ -363,15 +363,15 @@ impl IoHandler for Handler { const CHECK_BOOTSTRAP_INTERVAL: Duration = Duration::from_secs(15); io.register_timer_once(CONNECT_TO_BOOTSTRAP, CHECK_BOOTSTRAP_INTERVAL); } - FIRST_WAIT_SYNC...LAST_WAIT_SYNC => { + FIRST_WAIT_SYNC..=LAST_WAIT_SYNC => { cwarn!(NETWORK, "No sync message from {}", timer); io.deregister_stream(wait_sync_stream(timer)); } - FIRST_WAIT_ACK...LAST_WAIT_ACK => { + FIRST_WAIT_ACK..=LAST_WAIT_ACK => { cwarn!(NETWORK, "No ack message from {}", timer); io.deregister_stream(wait_ack_stream(timer)); } - FIRST_TRY_SYNC...LAST_TRY_SYNC => { + FIRST_TRY_SYNC..=LAST_TRY_SYNC => { let stream = retry_sync_stream(timer); let mut outgoing_connections = self.outgoing_connections.write(); if let Some(con) = outgoing_connections.get_mut(&stream) { @@ -430,7 +430,7 @@ impl IoHandler for Handler { let stream = *self.remote_node_ids_reverse.read().get(&node_id).ok_or_else(|| Error::InvalidNode(node_id))?; let (network_message_size, peer_addr) = match stream { - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { let mut outbound_connections = self.outbound_connections.write(); if let Some(con) = outbound_connections.get_mut(&stream) { let _f = finally(|| { @@ -445,7 +445,7 @@ impl IoHandler for Handler { return Err(format!("{} is an invalid stream", stream).into()) } } - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { let mut inbound_connections = self.inbound_connections.write(); if let Some(con) = inbound_connections.get_mut(&stream) { let _f = finally(|| { @@ -577,19 +577,19 @@ impl IoHandler for Handler { fn stream_hup(&self, io: &IoContext, stream: StreamToken) -> IoHandlerResult<()> { match stream { - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { cinfo!(NETWORK, "Hang-up inbound stream({})", stream); io.deregister_stream(stream); } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { cinfo!(NETWORK, "Hang-up outbound stream({})", stream); io.deregister_stream(stream); } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { cinfo!(NETWORK, "Hang-up incoming stream({})", stream); io.deregister_stream(stream); } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { cinfo!(NETWORK, "Hang-up outgoing stream({})", stream); io.deregister_stream(stream); } @@ -647,7 +647,7 @@ impl IoHandler for Handler { io.register_timer_once(wait_sync_timer(token), WAIT_SYNC); } } - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { let mut inbound_connections = self.inbound_connections.write(); if let Some(con) = inbound_connections.get_mut(&stream_token) { let should_update = AtomicBool::new(true); @@ -716,7 +716,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid inbound token({}) on read", stream_token); } } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { let mut outbound_connections = self.outbound_connections.write(); if let Some(con) = outbound_connections.get_mut(&stream_token) { let should_update = AtomicBool::new(true); @@ -761,7 +761,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid outbound token({}) on read", stream_token); } } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { let mut incoming_connections = self.incoming_connections.write(); if let Some(con) = incoming_connections.get_mut(&stream_token) { let should_update = AtomicBool::new(true); @@ -855,7 +855,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid incoming token({}) on read", stream_token); } } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { let mut outgoing_connections = self.outgoing_connections.write(); if let Some(con) = outgoing_connections.get_mut(&stream_token) { let should_update = AtomicBool::new(true); @@ -904,28 +904,28 @@ impl IoHandler for Handler { fn stream_writable(&self, _io: &IoContext, stream: StreamToken) -> IoHandlerResult<()> { match stream { - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { if let Some(con) = self.inbound_connections.write().get_mut(&stream) { con.flush()?; } else { cdebug!(NETWORK, "Invalid inbound token({}) on write", stream); } } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { if let Some(con) = self.outbound_connections.write().get_mut(&stream) { con.flush()?; } else { cdebug!(NETWORK, "Invalid outbound token({}) on write", stream); } } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { if let Some(con) = self.incoming_connections.write().get_mut(&stream) { con.flush()?; } else { cdebug!(NETWORK, "Invalid incoming token({}) on write", stream); } } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { if let Some(con) = self.outgoing_connections.write().get_mut(&stream) { con.flush()?; } else { @@ -948,7 +948,7 @@ impl IoHandler for Handler { event_loop.register(&self.listener, reg, Ready::readable(), PollOpt::edge())?; ctrace!(NETWORK, "TCP connection starts for {}", self.socket_address); } - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { if let Some(con) = self.inbound_connections.read().get(&stream) { con.register(reg, event_loop)?; ctrace!(NETWORK, "Inbound connect({}) registered", stream); @@ -956,7 +956,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid inbound token({}) on register", stream); } } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { if let Some(con) = self.outbound_connections.read().get(&stream) { con.register(reg, event_loop)?; ctrace!(NETWORK, "Outbound connect({}) registered", stream); @@ -964,7 +964,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid outbound token({}) on register", stream); } } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { if let Some(con) = self.incoming_connections.read().get(&stream) { con.register(reg, event_loop)?; ctrace!(NETWORK, "Incoming connect({}) registered", stream); @@ -972,7 +972,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid incoming token({}) on register", stream); } } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { if let Some(con) = self.outgoing_connections.read().get(&stream) { con.register(reg, event_loop)?; ctrace!(NETWORK, "Outgoing connect({}) registered", stream); @@ -1000,7 +1000,7 @@ impl IoHandler for Handler { ACCEPT => { event_loop.reregister(&self.listener, reg, Ready::readable(), PollOpt::edge())?; } - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { if let Some(con) = self.inbound_connections.read().get(&stream) { con.reregister(reg, event_loop)?; ctrace!(NETWORK, "Inbound connect({}) updated", stream); @@ -1008,7 +1008,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid inbound token({}) on update", stream); } } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { if let Some(con) = self.outbound_connections.read().get(&stream) { con.reregister(reg, event_loop)?; ctrace!(NETWORK, "Outbound connect({}) updated", stream); @@ -1016,7 +1016,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid outbound token({}) on update", stream); } } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { if let Some(con) = self.incoming_connections.read().get(&stream) { con.reregister(reg, event_loop)?; ctrace!(NETWORK, "Incoming connect({}) updated", stream); @@ -1024,7 +1024,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid incoming token({}) on update", stream); } } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { if let Some(con) = self.outgoing_connections.read().get(&stream) { con.reregister(reg, event_loop)?; ctrace!(NETWORK, "Outgoing connect({}) updated", stream); @@ -1044,7 +1044,7 @@ impl IoHandler for Handler { ) -> IoHandlerResult<()> { self.channel.send(Message::StartConnect)?; match stream { - FIRST_INBOUND...LAST_INBOUND => { + FIRST_INBOUND..=LAST_INBOUND => { let mut inbound_connections = self.inbound_connections.write(); if let Some(con) = inbound_connections.remove(&stream) { if let Some(node_id) = self.remote_node_ids.write().remove(&stream) { @@ -1061,7 +1061,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid inbound token({}) on deregister", stream); } } - FIRST_OUTBOUND...LAST_OUTBOUND => { + FIRST_OUTBOUND..=LAST_OUTBOUND => { let mut outbound_connections = self.outbound_connections.write(); if let Some(con) = outbound_connections.remove(&stream) { if let Some(node_id) = self.remote_node_ids.write().remove(&stream) { @@ -1078,7 +1078,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid outbound token({}) on deregister", stream); } } - FIRST_INCOMING...LAST_INCOMING => { + FIRST_INCOMING..=LAST_INCOMING => { let mut incoming_connections = self.incoming_connections.write(); if let Some(con) = incoming_connections.remove(&stream) { con.deregister(event_loop)?; @@ -1107,7 +1107,7 @@ impl IoHandler for Handler { cdebug!(NETWORK, "Invalid incoming token({}) on deregister", stream); } } - FIRST_OUTGOING...LAST_OUTGOING => { + FIRST_OUTGOING..=LAST_OUTGOING => { let mut outgoing_connections = self.outgoing_connections.write(); if let Some(con) = outgoing_connections.remove(&stream) { con.deregister(event_loop)?; diff --git a/sync/src/block/extension.rs b/sync/src/block/extension.rs index 1038e2c4b6..32927c4fab 100644 --- a/sync/src/block/extension.rs +++ b/sync/src/block/extension.rs @@ -311,7 +311,7 @@ impl NetworkExtension for Extension { } } } - SYNC_EXPIRE_TOKEN_BEGIN...SYNC_EXPIRE_TOKEN_END => { + SYNC_EXPIRE_TOKEN_BEGIN..=SYNC_EXPIRE_TOKEN_END => { self.check_sync_variable(); let (id, request_id) = { let token_info = match self.tokens_info.get_mut(&token) { diff --git a/util/rlp/src/stream.rs b/util/rlp/src/stream.rs index 34c2b35da3..2e00952433 100644 --- a/util/rlp/src/stream.rs +++ b/util/rlp/src/stream.rs @@ -352,7 +352,7 @@ impl<'a> BasicEncoder<'a> { fn insert_list_payload(&mut self, len: usize, pos: usize) { // 1 byte was already reserved for payload earlier match len { - 0...55 => { + 0..=55 => { self.buffer[pos - 1] = 0xc0u8 + len as u8; } _ => { @@ -370,7 +370,7 @@ impl<'a> BasicEncoder<'a> { // byte is its own encoding if < 0x80 1 if value[0] < 0x80 => self.buffer.push(value[0]), // (prefix + length), followed by the string - len @ 1...55 => { + len @ 1..=55 => { self.buffer.push(0x80u8 + len as u8); self.buffer.append_slice(value); } diff --git a/util/rlp/src/untrusted_rlp.rs b/util/rlp/src/untrusted_rlp.rs index 161d771bba..79944565c4 100644 --- a/util/rlp/src/untrusted_rlp.rs +++ b/util/rlp/src/untrusted_rlp.rs @@ -89,14 +89,14 @@ impl PayloadInfo { expected: 1, got: 0, }), - Some(0...0x7f) => Ok(PayloadInfo::new(0, 1)), - Some(l @ 0x80...0xb7) => Ok(PayloadInfo::new(1, l as usize - 0x80)), - Some(l @ 0xb8...0xbf) => { + Some(0..=0x7f) => Ok(PayloadInfo::new(0, 1)), + Some(l @ 0x80..=0xb7) => Ok(PayloadInfo::new(1, l as usize - 0x80)), + Some(l @ 0xb8..=0xbf) => { let len_of_len = l as usize - 0xb7; calculate_payload_info(header_bytes, len_of_len) } - Some(l @ 0xc0...0xf7) => Ok(PayloadInfo::new(1, l as usize - 0xc0)), - Some(l @ 0xf8...0xff) => { + Some(l @ 0xc0..=0xf7) => Ok(PayloadInfo::new(1, l as usize - 0xc0)), + Some(l @ 0xf8..=0xff) => { let len_of_len = l as usize - 0xf7; calculate_payload_info(header_bytes, len_of_len) } @@ -263,9 +263,9 @@ where } match self.bytes[0] { - 0...0x80 => true, - 0x81...0xb7 => self.bytes[1] != 0, - b @ 0xb8...0xbf => self.bytes[1 + b as usize - 0xb7] != 0, + 0..=0x80 => true, + 0x81..=0xb7 => self.bytes[1] != 0, + b @ 0xb8..=0xbf => self.bytes[1 + b as usize - 0xb7] != 0, _ => false, } } @@ -402,9 +402,9 @@ impl<'a> BasicDecoder<'a> { got: 0, }), // Single byte value. - Some(l @ 0...0x7f) => Ok(f(&[l])?), + Some(l @ 0..=0x7f) => Ok(f(&[l])?), // 0-55 bytes - Some(l @ 0x80...0xb7) => { + Some(l @ 0x80..=0xb7) => { let last_index_of = 1 + l as usize - 0x80; if bytes.len() < last_index_of { return Err(DecoderError::RlpInconsistentLengthAndData { @@ -419,7 +419,7 @@ impl<'a> BasicDecoder<'a> { Ok(f(d)?) } // Longer than 55 bytes. - Some(l @ 0xb8...0xbf) => { + Some(l @ 0xb8..=0xbf) => { let len_of_len = l as usize - 0xb7; let begin_of_value = 1 as usize + len_of_len; if bytes.len() < begin_of_value {