Skip to content

Use rust 1.37.0 #1806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.36.0
- 1.37.0
stages:
- name: test
if: branch != docker-build
Expand Down
2 changes: 1 addition & 1 deletion codechain/rpc_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use csync::BlockSyncEvent;
pub struct ApiDependencies {
pub client: Arc<Client>,
pub miner: Arc<Miner>,
pub network_control: Arc<NetworkControl>,
pub network_control: Arc<dyn NetworkControl>,
pub account_provider: Arc<AccountProvider>,
pub block_sync: Option<EventSender<BlockSyncEvent>>,
}
Expand Down
12 changes: 6 additions & 6 deletions codechain/run_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn discovery_start(
fn client_start(
client_config: &ClientConfig,
timer_loop: &TimerLoop,
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
scheme: &Scheme,
miner: Arc<Miner>,
) -> Result<ClientService, String> {
Expand Down Expand Up @@ -122,7 +122,7 @@ fn new_miner(
config: &config::Config,
scheme: &Scheme,
ap: Arc<AccountProvider>,
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
) -> Result<Arc<Miner>, String> {
let miner = Miner::new(config.miner_options()?, scheme, Some(ap), db);

Expand Down Expand Up @@ -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<Arc<KeyValueDB>, String> {
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<dyn KeyValueDB>, 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);
Expand Down Expand Up @@ -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<NetworkControl> = {
let network_service: Arc<dyn NetworkControl> = {
if !config.network.disable.unwrap() {
let network_config = config.network_config()?;
// XXX: What should we do if the network id has been changed.
Expand All @@ -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<ChainNotify>);
client.client().add_notify(Arc::downgrade(&sync) as Weak<dyn ChainNotify>);
_maybe_sync = Some(sync); // Hold sync to ensure it not to be destroyed.
maybe_sync_sender = Some(sync_sender);
}
Expand Down Expand Up @@ -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<ChainNotify>);
client.add_notify(Arc::downgrade(&service) as Weak<dyn ChainNotify>);
Some(service)
} else {
None
Expand Down
18 changes: 11 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Bytes>) -> Result<(), BlockError> {
pub fn seal(&mut self, engine: &dyn CodeChainEngine, seal: Vec<Bytes>) -> Result<(), BlockError> {
let expected_seal_fields = engine.seal_fields(self.header());
if seal.len() != expected_seal_fields {
return Err(BlockError::InvalidSealArity(Mismatch {
Expand Down Expand Up @@ -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;
Expand All @@ -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<Bytes>) -> Result<SealedBlock, BlockError> {
pub fn seal(mut self, engine: &dyn CodeChainEngine, seal: Vec<Bytes>) -> Result<SealedBlock, BlockError> {
let expected_seal_fields = engine.seal_fields(self.header());
if seal.len() != expected_seal_fields {
return Err(BlockError::InvalidSealArity(Mismatch {
Expand All @@ -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<Bytes>) -> Result<SealedBlock, (Error, LockedBlock)> {
pub fn try_seal(
mut self,
engine: &dyn CodeChainEngine,
seal: Vec<Bytes>,
) -> Result<SealedBlock, (Error, LockedBlock)> {
self.block.header.set_seal(seal);

// TODO: passing state context to avoid engines owning it?
Expand Down Expand Up @@ -489,7 +493,7 @@ impl IsBlock for SealedBlock {
pub fn enact<C: ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo>(
header: &Header,
transactions: &[SignedTransaction],
engine: &CodeChainEngine,
engine: &dyn CodeChainEngine,
client: &C,
db: StateDB,
parent: &Header,
Expand Down
8 changes: 4 additions & 4 deletions core/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct BlockChain {

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

// load best block
Expand Down Expand Up @@ -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),
Expand All @@ -118,7 +118,7 @@ impl BlockChain {
batch: &mut DBTransaction,
bytes: &[u8],
invoices: Vec<Invoice>,
engine: &CodeChainEngine,
engine: &dyn CodeChainEngine,
) -> ImportRoute {
// create views onto rlp
let new_block = BlockView::new(bytes);
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions core/src/blockchain/body_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub struct BodyDB {
transaction_address_cache: Mutex<HashMap<H256, TransactionAddresses>>,
pending_transaction_addresses: Mutex<HashMap<H256, Option<TransactionAddresses>>>,

db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
}

type TransactionHashAndAddress = (H256, TransactionAddresses);

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

let (removed, added): (
Box<Iterator<Item = TransactionHashAndAddress>>,
Box<Iterator<Item = TransactionHashAndAddress>>,
Box<dyn Iterator<Item = TransactionHashAndAddress>>,
Box<dyn Iterator<Item = TransactionHashAndAddress>>,
) = match best_block_changed {
BestBlockChanged::CanonChainAppended {
..
Expand Down
10 changes: 5 additions & 5 deletions core/src/blockchain/headerchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct HeaderChain {
detail_cache: RwLock<HashMap<H256, BlockDetails>>,
hash_cache: Mutex<HashMap<BlockNumber, H256>>,

db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,

pending_best_header_hash: RwLock<Option<H256>>,
pending_best_proposal_block_hash: RwLock<Option<H256>>,
Expand All @@ -63,7 +63,7 @@ pub struct HeaderChain {

impl HeaderChain {
/// Create new instance of blockchain from given Genesis.
pub fn new(genesis: &HeaderView, db: Arc<KeyValueDB>) -> Self {
pub fn new(genesis: &HeaderView, db: Arc<dyn KeyValueDB>) -> Self {
// load best header
let best_header_hash = match db.get(db::COL_EXTRA, BEST_HEADER_KEY).unwrap() {
Some(hash) => H256::from_slice(&hash),
Expand Down Expand Up @@ -122,7 +122,7 @@ impl HeaderChain {
&self,
batch: &mut DBTransaction,
header: &HeaderView,
engine: &CodeChainEngine,
engine: &dyn CodeChainEngine,
) -> Option<BestHeaderChanged> {
let hash = header.hash();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -403,7 +403,7 @@ impl HeaderProvider for HeaderChain {
}

/// Get block header data
fn block_header_data(hash: &H256, header_cache: &Mutex<LruCache<H256, Bytes>>, db: &KeyValueDB) -> Option<Vec<u8>> {
fn block_header_data(hash: &H256, header_cache: &Mutex<LruCache<H256, Bytes>>, db: &dyn KeyValueDB) -> Option<Vec<u8>> {
// Check cache first
{
let mut lock = header_cache.lock();
Expand Down
4 changes: 2 additions & 2 deletions core/src/blockchain/invoice_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub struct InvoiceDB {
// transaction hash -> error hint
hash_cache: RwLock<HashMap<H256, Option<String>>>,

db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
}

impl InvoiceDB {
/// Create new instance of blockchain from given Genesis.
pub fn new(db: Arc<KeyValueDB>) -> Self {
pub fn new(db: Arc<dyn KeyValueDB>) -> Self {
Self {
tracker_cache: Default::default(),
hash_cache: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/blockchain/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeRoute> {
pub fn tree_route(db: &dyn HeaderProvider, from: H256, to: H256) -> Option<TreeRoute> {
let mut retracted = vec![];
let mut enacted = vec![];

Expand Down
26 changes: 13 additions & 13 deletions core/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ use crate::types::{BlockId, BlockStatus, TransactionId, VerificationQueueInfo as
const MAX_MEM_POOL_SIZE: usize = 4096;

pub struct Client {
engine: Arc<CodeChainEngine>,
engine: Arc<dyn CodeChainEngine>,

io_channel: Mutex<IoChannel<ClientIoMessage>>,

chain: RwLock<BlockChain>,

/// Client uses this to store blocks, traces, etc.
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,

state_db: RwLock<StateDB>,

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

/// Count of pending transactions in the queue
queue_transactions: AtomicUsize,
Expand All @@ -87,7 +87,7 @@ impl Client {
pub fn try_new(
config: &ClientConfig,
scheme: &Scheme,
db: Arc<KeyValueDB>,
db: Arc<dyn KeyValueDB>,
miner: Arc<Miner>,
message_channel: IoChannel<ClientIoMessage>,
reseal_timer: TimerApi,
Expand Down Expand Up @@ -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<ChainNotify>) {
pub fn add_notify(&self, target: Weak<dyn ChainNotify>) {
self.notify.write().push(target);
}

Expand Down Expand Up @@ -194,7 +194,7 @@ impl Client {

fn notify<F>(&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);
Expand Down Expand Up @@ -305,7 +305,7 @@ impl Client {
}
}

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

pub fn db(&self) -> &Arc<KeyValueDB> {
pub fn db(&self) -> &Arc<dyn KeyValueDB> {
&self.db
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ impl TimeoutHandler for Client {
}

impl DatabaseClient for Client {
fn database(&self) -> Arc<KeyValueDB> {
fn database(&self) -> Arc<dyn KeyValueDB> {
Arc::clone(&self.db())
}
}
Expand Down Expand Up @@ -440,7 +440,7 @@ impl ExecuteClient for Client {

fn execute_vm(
&self,
tx: &PartialHashing,
tx: &dyn PartialHashing,
inputs: &[AssetTransferInput],
params: &[Vec<Bytes>],
indices: &[usize],
Expand Down Expand Up @@ -581,7 +581,7 @@ impl EngineClient for Client {
}
}

fn get_kvdb(&self) -> Arc<KeyValueDB> {
fn get_kvdb(&self) -> Arc<dyn KeyValueDB> {
self.db.clone()
}
}
Expand Down Expand Up @@ -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)
}
}
Loading