Skip to content

Commit 31a7d52

Browse files
Seulgi Kimforiequal0
authored andcommitted
trait objects without an explicit dyn are deprecated
1 parent c617d86 commit 31a7d52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+253
-241
lines changed

codechain/rpc_apis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use csync::BlockSyncEvent;
2525
pub struct ApiDependencies {
2626
pub client: Arc<Client>,
2727
pub miner: Arc<Miner>,
28-
pub network_control: Arc<NetworkControl>,
28+
pub network_control: Arc<dyn NetworkControl>,
2929
pub account_provider: Arc<AccountProvider>,
3030
pub block_sync: Option<EventSender<BlockSyncEvent>>,
3131
}

codechain/run_node.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn discovery_start(
9191
fn client_start(
9292
client_config: &ClientConfig,
9393
timer_loop: &TimerLoop,
94-
db: Arc<KeyValueDB>,
94+
db: Arc<dyn KeyValueDB>,
9595
scheme: &Scheme,
9696
miner: Arc<Miner>,
9797
) -> Result<ClientService, String> {
@@ -122,7 +122,7 @@ fn new_miner(
122122
config: &config::Config,
123123
scheme: &Scheme,
124124
ap: Arc<AccountProvider>,
125-
db: Arc<KeyValueDB>,
125+
db: Arc<dyn KeyValueDB>,
126126
) -> Result<Arc<Miner>, String> {
127127
let miner = Miner::new(config.miner_options()?, scheme, Some(ap), db);
128128

@@ -204,7 +204,7 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
204204
Ok(())
205205
}
206206

207-
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<KeyValueDB>, String> {
207+
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<dyn KeyValueDB>, String> {
208208
let base_path = cfg.base_path.as_ref().unwrap().clone();
209209
let db_path = cfg.db_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_DB_PATH);
210210
let client_path = Path::new(&db_path);
@@ -282,7 +282,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
282282

283283
scheme.engine.register_chain_notify(client.client().as_ref());
284284

285-
let network_service: Arc<NetworkControl> = {
285+
let network_service: Arc<dyn NetworkControl> = {
286286
if !config.network.disable.unwrap() {
287287
let network_config = config.network_config()?;
288288
// XXX: What should we do if the network id has been changed.
@@ -303,7 +303,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
303303
service.register_extension(move |api| BlockSyncExtension::new(client, api))
304304
};
305305
let sync = Arc::new(BlockSyncSender::from(sync_sender.clone()));
306-
client.client().add_notify(Arc::downgrade(&sync) as Weak<ChainNotify>);
306+
client.client().add_notify(Arc::downgrade(&sync) as Weak<dyn ChainNotify>);
307307
_maybe_sync = Some(sync); // Hold sync to ensure it not to be destroyed.
308308
maybe_sync_sender = Some(sync_sender);
309309
}
@@ -362,7 +362,7 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
362362
let client = client.client();
363363
let snapshot_period = client.common_params(BlockId::Latest).unwrap().snapshot_period();
364364
let service = SnapshotService::new(Arc::clone(&client), config.snapshot.path.unwrap(), snapshot_period);
365-
client.add_notify(Arc::downgrade(&service) as Weak<ChainNotify>);
365+
client.add_notify(Arc::downgrade(&service) as Weak<dyn ChainNotify>);
366366
Some(service)
367367
} else {
368368
None

core/src/block.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ impl ExecutedBlock {
121121
/// Block that is ready for transactions to be added.
122122
pub struct OpenBlock<'x> {
123123
block: ExecutedBlock,
124-
engine: &'x CodeChainEngine,
124+
engine: &'x dyn CodeChainEngine,
125125
}
126126

127127
impl<'x> OpenBlock<'x> {
128128
/// Create a new `OpenBlock` ready for transaction pushing.
129129
pub fn try_new(
130-
engine: &'x CodeChainEngine,
130+
engine: &'x dyn CodeChainEngine,
131131
db: StateDB,
132132
parent: &Header,
133133
author: Address,
@@ -311,7 +311,7 @@ impl<'x> OpenBlock<'x> {
311311
/// Provide a valid seal
312312
///
313313
/// NOTE: This does not check the validity of `seal` with the engine.
314-
pub fn seal(&mut self, engine: &CodeChainEngine, seal: Vec<Bytes>) -> Result<(), BlockError> {
314+
pub fn seal(&mut self, engine: &dyn CodeChainEngine, seal: Vec<Bytes>) -> Result<(), BlockError> {
315315
let expected_seal_fields = engine.seal_fields(self.header());
316316
if seal.len() != expected_seal_fields {
317317
return Err(BlockError::InvalidSealArity(Mismatch {
@@ -347,7 +347,7 @@ impl ClosedBlock {
347347
}
348348

349349
/// Given an engine reference, reopen the `ClosedBlock` into an `OpenBlock`.
350-
pub fn reopen(self, engine: &CodeChainEngine) -> OpenBlock {
350+
pub fn reopen(self, engine: &dyn CodeChainEngine) -> OpenBlock {
351351
// revert rewards (i.e. set state back at last transaction's state).
352352
let mut block = self.block;
353353
block.state = self.unclosed_state;
@@ -367,7 +367,7 @@ impl LockedBlock {
367367
/// Provide a valid seal in order to turn this into a `SealedBlock`.
368368
///
369369
/// NOTE: This does not check the validity of `seal` with the engine.
370-
pub fn seal(mut self, engine: &CodeChainEngine, seal: Vec<Bytes>) -> Result<SealedBlock, BlockError> {
370+
pub fn seal(mut self, engine: &dyn CodeChainEngine, seal: Vec<Bytes>) -> Result<SealedBlock, BlockError> {
371371
let expected_seal_fields = engine.seal_fields(self.header());
372372
if seal.len() != expected_seal_fields {
373373
return Err(BlockError::InvalidSealArity(Mismatch {
@@ -384,7 +384,11 @@ impl LockedBlock {
384384
/// Provide a valid seal in order to turn this into a `SealedBlock`.
385385
/// This does check the validity of `seal` with the engine.
386386
/// Returns the `ClosedBlock` back again if the seal is no good.
387-
pub fn try_seal(mut self, engine: &CodeChainEngine, seal: Vec<Bytes>) -> Result<SealedBlock, (Error, LockedBlock)> {
387+
pub fn try_seal(
388+
mut self,
389+
engine: &dyn CodeChainEngine,
390+
seal: Vec<Bytes>,
391+
) -> Result<SealedBlock, (Error, LockedBlock)> {
388392
self.block.header.set_seal(seal);
389393

390394
// TODO: passing state context to avoid engines owning it?
@@ -489,7 +493,7 @@ impl IsBlock for SealedBlock {
489493
pub fn enact<C: ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo>(
490494
header: &Header,
491495
transactions: &[SignedTransaction],
492-
engine: &CodeChainEngine,
496+
engine: &dyn CodeChainEngine,
493497
client: &C,
494498
db: StateDB,
495499
parent: &Header,

core/src/blockchain/blockchain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct BlockChain {
5858

5959
impl BlockChain {
6060
/// Create new instance of blockchain from given Genesis.
61-
pub fn new(genesis: &[u8], db: Arc<KeyValueDB>) -> Self {
61+
pub fn new(genesis: &[u8], db: Arc<dyn KeyValueDB>) -> Self {
6262
let genesis_block = BlockView::new(genesis);
6363

6464
// load best block
@@ -102,7 +102,7 @@ impl BlockChain {
102102
&self,
103103
batch: &mut DBTransaction,
104104
header: &HeaderView,
105-
engine: &CodeChainEngine,
105+
engine: &dyn CodeChainEngine,
106106
) -> ImportRoute {
107107
match self.headerchain.insert_header(batch, header, engine) {
108108
Some(c) => ImportRoute::new_from_best_header_changed(header.hash(), &c),
@@ -118,7 +118,7 @@ impl BlockChain {
118118
batch: &mut DBTransaction,
119119
bytes: &[u8],
120120
invoices: Vec<Invoice>,
121-
engine: &CodeChainEngine,
121+
engine: &dyn CodeChainEngine,
122122
) -> ImportRoute {
123123
// create views onto rlp
124124
let new_block = BlockView::new(bytes);
@@ -180,7 +180,7 @@ impl BlockChain {
180180
}
181181

182182
/// Calculate how best block is changed
183-
fn best_block_changed(&self, new_block: &BlockView, engine: &CodeChainEngine) -> BestBlockChanged {
183+
fn best_block_changed(&self, new_block: &BlockView, engine: &dyn CodeChainEngine) -> BestBlockChanged {
184184
let new_header = new_block.header_view();
185185
let parent_hash_of_new_block = new_header.parent_hash();
186186
let parent_details_of_new_block = self.block_details(&parent_hash_of_new_block).expect("Invalid parent hash");

core/src/blockchain/body_db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ pub struct BodyDB {
4242
transaction_address_cache: Mutex<HashMap<H256, TransactionAddresses>>,
4343
pending_transaction_addresses: Mutex<HashMap<H256, Option<TransactionAddresses>>>,
4444

45-
db: Arc<KeyValueDB>,
45+
db: Arc<dyn KeyValueDB>,
4646
}
4747

4848
type TransactionHashAndAddress = (H256, TransactionAddresses);
4949

5050
impl BodyDB {
5151
/// Create new instance of blockchain from given Genesis.
52-
pub fn new(genesis: &BlockView, db: Arc<KeyValueDB>) -> Self {
52+
pub fn new(genesis: &BlockView, db: Arc<dyn KeyValueDB>) -> Self {
5353
let bdb = Self {
5454
body_cache: Mutex::new(LruCache::new(BODY_CACHE_SIZE)),
5555
parcel_address_cache: RwLock::new(HashMap::new()),
@@ -196,8 +196,8 @@ impl BodyDB {
196196
};
197197

198198
let (removed, added): (
199-
Box<Iterator<Item = TransactionHashAndAddress>>,
200-
Box<Iterator<Item = TransactionHashAndAddress>>,
199+
Box<dyn Iterator<Item = TransactionHashAndAddress>>,
200+
Box<dyn Iterator<Item = TransactionHashAndAddress>>,
201201
) = match best_block_changed {
202202
BestBlockChanged::CanonChainAppended {
203203
..

core/src/blockchain/headerchain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct HeaderChain {
5353
detail_cache: RwLock<HashMap<H256, BlockDetails>>,
5454
hash_cache: Mutex<HashMap<BlockNumber, H256>>,
5555

56-
db: Arc<KeyValueDB>,
56+
db: Arc<dyn KeyValueDB>,
5757

5858
pending_best_header_hash: RwLock<Option<H256>>,
5959
pending_best_proposal_block_hash: RwLock<Option<H256>>,
@@ -63,7 +63,7 @@ pub struct HeaderChain {
6363

6464
impl HeaderChain {
6565
/// Create new instance of blockchain from given Genesis.
66-
pub fn new(genesis: &HeaderView, db: Arc<KeyValueDB>) -> Self {
66+
pub fn new(genesis: &HeaderView, db: Arc<dyn KeyValueDB>) -> Self {
6767
// load best header
6868
let best_header_hash = match db.get(db::COL_EXTRA, BEST_HEADER_KEY).unwrap() {
6969
Some(hash) => H256::from_slice(&hash),
@@ -122,7 +122,7 @@ impl HeaderChain {
122122
&self,
123123
batch: &mut DBTransaction,
124124
header: &HeaderView,
125-
engine: &CodeChainEngine,
125+
engine: &dyn CodeChainEngine,
126126
) -> Option<BestHeaderChanged> {
127127
let hash = header.hash();
128128

@@ -239,7 +239,7 @@ impl HeaderChain {
239239
}
240240

241241
/// Calculate how best block is changed
242-
fn best_header_changed(&self, new_header: &HeaderView, engine: &CodeChainEngine) -> BestHeaderChanged {
242+
fn best_header_changed(&self, new_header: &HeaderView, engine: &dyn CodeChainEngine) -> BestHeaderChanged {
243243
let parent_hash_of_new_header = new_header.parent_hash();
244244
let parent_details_of_new_header = self.block_details(&parent_hash_of_new_header).expect("Invalid parent hash");
245245
let is_new_best = parent_details_of_new_header.total_score + new_header.score()
@@ -403,7 +403,7 @@ impl HeaderProvider for HeaderChain {
403403
}
404404

405405
/// Get block header data
406-
fn block_header_data(hash: &H256, header_cache: &Mutex<LruCache<H256, Bytes>>, db: &KeyValueDB) -> Option<Vec<u8>> {
406+
fn block_header_data(hash: &H256, header_cache: &Mutex<LruCache<H256, Bytes>>, db: &dyn KeyValueDB) -> Option<Vec<u8>> {
407407
// Check cache first
408408
{
409409
let mut lock = header_cache.lock();

core/src/blockchain/invoice_db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ pub struct InvoiceDB {
3434
// transaction hash -> error hint
3535
hash_cache: RwLock<HashMap<H256, Option<String>>>,
3636

37-
db: Arc<KeyValueDB>,
37+
db: Arc<dyn KeyValueDB>,
3838
}
3939

4040
impl InvoiceDB {
4141
/// Create new instance of blockchain from given Genesis.
42-
pub fn new(db: Arc<KeyValueDB>) -> Self {
42+
pub fn new(db: Arc<dyn KeyValueDB>) -> Self {
4343
Self {
4444
tracker_cache: Default::default(),
4545
hash_cache: Default::default(),

core/src/blockchain/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct TreeRoute {
7171
///
7272
/// If the tree route verges into pruned or unknown blocks,
7373
/// `None` is returned.
74-
pub fn tree_route(db: &HeaderProvider, from: H256, to: H256) -> Option<TreeRoute> {
74+
pub fn tree_route(db: &dyn HeaderProvider, from: H256, to: H256) -> Option<TreeRoute> {
7575
let mut retracted = vec![];
7676
let mut enacted = vec![];
7777

core/src/client/client.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ use crate::types::{BlockId, BlockStatus, TransactionId, VerificationQueueInfo as
5858
const MAX_MEM_POOL_SIZE: usize = 4096;
5959

6060
pub struct Client {
61-
engine: Arc<CodeChainEngine>,
61+
engine: Arc<dyn CodeChainEngine>,
6262

6363
io_channel: Mutex<IoChannel<ClientIoMessage>>,
6464

6565
chain: RwLock<BlockChain>,
6666

6767
/// Client uses this to store blocks, traces, etc.
68-
db: Arc<KeyValueDB>,
68+
db: Arc<dyn KeyValueDB>,
6969

7070
state_db: RwLock<StateDB>,
7171

7272
/// List of actors to be notified on certain chain events
73-
notify: RwLock<Vec<Weak<ChainNotify>>>,
73+
notify: RwLock<Vec<Weak<dyn ChainNotify>>>,
7474

7575
/// Count of pending transactions in the queue
7676
queue_transactions: AtomicUsize,
@@ -87,7 +87,7 @@ impl Client {
8787
pub fn try_new(
8888
config: &ClientConfig,
8989
scheme: &Scheme,
90-
db: Arc<KeyValueDB>,
90+
db: Arc<dyn KeyValueDB>,
9191
miner: Arc<Miner>,
9292
message_channel: IoChannel<ClientIoMessage>,
9393
reseal_timer: TimerApi,
@@ -133,12 +133,12 @@ impl Client {
133133
}
134134

135135
/// Returns engine reference.
136-
pub fn engine(&self) -> &CodeChainEngine {
136+
pub fn engine(&self) -> &dyn CodeChainEngine {
137137
&*self.engine
138138
}
139139

140140
/// Adds an actor to be notified on certain events
141-
pub fn add_notify(&self, target: Weak<ChainNotify>) {
141+
pub fn add_notify(&self, target: Weak<dyn ChainNotify>) {
142142
self.notify.write().push(target);
143143
}
144144

@@ -194,7 +194,7 @@ impl Client {
194194

195195
fn notify<F>(&self, f: F)
196196
where
197-
F: Fn(&ChainNotify), {
197+
F: Fn(&dyn ChainNotify), {
198198
for np in self.notify.read().iter() {
199199
if let Some(n) = np.upgrade() {
200200
f(&*n);
@@ -305,7 +305,7 @@ impl Client {
305305
}
306306
}
307307

308-
fn state_info(&self, state: StateOrBlock) -> Option<Box<TopStateView>> {
308+
fn state_info(&self, state: StateOrBlock) -> Option<Box<dyn TopStateView>> {
309309
Some(match state {
310310
StateOrBlock::State(state) => state,
311311
StateOrBlock::Block(id) => Box::new(self.state_at(id)?),
@@ -320,7 +320,7 @@ impl Client {
320320
self.chain.read()
321321
}
322322

323-
pub fn db(&self) -> &Arc<KeyValueDB> {
323+
pub fn db(&self) -> &Arc<dyn KeyValueDB> {
324324
&self.db
325325
}
326326
}
@@ -352,7 +352,7 @@ impl TimeoutHandler for Client {
352352
}
353353

354354
impl DatabaseClient for Client {
355-
fn database(&self) -> Arc<KeyValueDB> {
355+
fn database(&self) -> Arc<dyn KeyValueDB> {
356356
Arc::clone(&self.db())
357357
}
358358
}
@@ -440,7 +440,7 @@ impl ExecuteClient for Client {
440440

441441
fn execute_vm(
442442
&self,
443-
tx: &PartialHashing,
443+
tx: &dyn PartialHashing,
444444
inputs: &[AssetTransferInput],
445445
params: &[Vec<Bytes>],
446446
indices: &[usize],
@@ -581,7 +581,7 @@ impl EngineClient for Client {
581581
}
582582
}
583583

584-
fn get_kvdb(&self) -> Arc<KeyValueDB> {
584+
fn get_kvdb(&self) -> Arc<dyn KeyValueDB> {
585585
self.db.clone()
586586
}
587587
}
@@ -905,7 +905,7 @@ impl ChainTimeInfo for Client {
905905
}
906906

907907
impl FindActionHandler for Client {
908-
fn find_action_handler_for(&self, id: u64) -> Option<&ActionHandler> {
908+
fn find_action_handler_for(&self, id: u64) -> Option<&dyn ActionHandler> {
909909
self.engine.find_action_handler_for(id)
910910
}
911911
}

core/src/client/importer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Importer {
4444
pub import_lock: Mutex<()>, // FIXME Maybe wrap the whole `Importer` instead?
4545

4646
/// Used to verify blocks
47-
pub verifier: Box<Verifier<Client>>,
47+
pub verifier: Box<dyn Verifier<Client>>,
4848

4949
/// Queue containing pending blocks
5050
pub block_queue: BlockQueue,
@@ -56,13 +56,13 @@ pub struct Importer {
5656
pub miner: Arc<Miner>,
5757

5858
/// CodeChain engine to be used during import
59-
pub engine: Arc<CodeChainEngine>,
59+
pub engine: Arc<dyn CodeChainEngine>,
6060
}
6161

6262
impl Importer {
6363
pub fn try_new(
6464
config: &ClientConfig,
65-
engine: Arc<CodeChainEngine>,
65+
engine: Arc<dyn CodeChainEngine>,
6666
message_channel: IoChannel<ClientIoMessage>,
6767
miner: Arc<Miner>,
6868
) -> Result<Importer, Error> {

0 commit comments

Comments
 (0)