Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into dp/feature/eip-1344-add-ChainID-opcode
Browse files Browse the repository at this point in the history
* master:
  Make ClientIoMessage generic over the Client (#10981)
  bump spin to 0.5.2 (#10996)
  fix compile warnings (#10993)
  Fix compilation on recent nightlies (#10991)
  [ipfs] Convert to edition 2018 (#10979)
  • Loading branch information
dvdplm committed Aug 28, 2019
2 parents 1fc96cc + cd26526 commit e28fce7
Show file tree
Hide file tree
Showing 87 changed files with 307 additions and 285 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions accounts/ethstore/src/accounts_dir/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<T> KeyDirectory for DiskDirectory<T> where T: KeyFileManager {

fn path(&self) -> Option<&PathBuf> { Some(&self.path) }

fn as_vault_provider(&self) -> Option<&VaultKeyDirectoryProvider> {
fn as_vault_provider(&self) -> Option<&dyn VaultKeyDirectoryProvider> {
Some(self)
}

Expand All @@ -294,12 +294,12 @@ impl<T> KeyDirectory for DiskDirectory<T> where T: KeyFileManager {
}

impl<T> VaultKeyDirectoryProvider for DiskDirectory<T> where T: KeyFileManager {
fn create(&self, name: &str, key: VaultKey) -> Result<Box<VaultKeyDirectory>, Error> {
fn create(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error> {
let vault_dir = VaultDiskDirectory::create(&self.path, name, key)?;
Ok(Box::new(vault_dir))
}

fn open(&self, name: &str, key: VaultKey) -> Result<Box<VaultKeyDirectory>, Error> {
fn open(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error> {
let vault_dir = VaultDiskDirectory::at(&self.path, name, key)?;
Ok(Box::new(vault_dir))
}
Expand Down
8 changes: 4 additions & 4 deletions accounts/ethstore/src/accounts_dir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ pub trait KeyDirectory: Send + Sync {
/// Get directory filesystem path, if available
fn path(&self) -> Option<&PathBuf> { None }
/// Return vault provider, if available
fn as_vault_provider(&self) -> Option<&VaultKeyDirectoryProvider> { None }
fn as_vault_provider(&self) -> Option<&dyn VaultKeyDirectoryProvider> { None }
/// Unique representation of directory account collection
fn unique_repr(&self) -> Result<u64, Error>;
}

/// Vaults provider
pub trait VaultKeyDirectoryProvider {
/// Create new vault with given key
fn create(&self, name: &str, key: VaultKey) -> Result<Box<VaultKeyDirectory>, Error>;
fn create(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error>;
/// Open existing vault with given key
fn open(&self, name: &str, key: VaultKey) -> Result<Box<VaultKeyDirectory>, Error>;
fn open(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error>;
/// List all vaults
fn list_vaults(&self) -> Result<Vec<String>, Error>;
/// Get vault meta
Expand All @@ -77,7 +77,7 @@ pub trait VaultKeyDirectoryProvider {
/// Vault directory
pub trait VaultKeyDirectory: KeyDirectory {
/// Cast to `KeyDirectory`
fn as_key_directory(&self) -> &KeyDirectory;
fn as_key_directory(&self) -> &dyn KeyDirectory;
/// Vault name
fn name(&self) -> &str;
/// Get vault key
Expand Down
2 changes: 1 addition & 1 deletion accounts/ethstore/src/accounts_dir/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl VaultDiskDirectory {
}

impl VaultKeyDirectory for VaultDiskDirectory {
fn as_key_directory(&self) -> &KeyDirectory {
fn as_key_directory(&self) -> &dyn KeyDirectory {
self
}

Expand Down
14 changes: 7 additions & 7 deletions accounts/ethstore/src/ethstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ pub struct EthStore {

impl EthStore {
/// Open a new accounts store with given key directory backend.
pub fn open(directory: Box<KeyDirectory>) -> Result<Self, Error> {
pub fn open(directory: Box<dyn KeyDirectory>) -> Result<Self, Error> {
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<KeyDirectory>, iterations: u32) -> Result<Self, Error> {
pub fn open_with_iterations(directory: Box<dyn KeyDirectory>, iterations: u32) -> Result<Self, Error> {
Ok(EthStore {
store: EthMultiStore::open_with_iterations(directory, iterations)?,
})
Expand Down Expand Up @@ -184,7 +184,7 @@ impl SecretStore for EthStore {
Ok(account.check_password(password))
}

fn copy_account(&self, new_store: &SimpleSecretStore, new_vault: SecretVaultRef, account: &StoreAccountRef, password: &Password, new_password: &Password) -> Result<(), Error> {
fn copy_account(&self, new_store: &dyn SimpleSecretStore, new_vault: SecretVaultRef, account: &StoreAccountRef, password: &Password, new_password: &Password) -> Result<(), Error> {
let account = self.get(account)?;
let secret = account.crypto.secret(password)?;
new_store.insert_account(new_vault, secret, new_password)?;
Expand Down Expand Up @@ -256,11 +256,11 @@ impl SecretStore for EthStore {

/// Similar to `EthStore` but may store many accounts (with different passwords) for the same `Address`
pub struct EthMultiStore {
dir: Box<KeyDirectory>,
dir: Box<dyn KeyDirectory>,
iterations: u32,
// order lock: cache, then vaults
cache: RwLock<BTreeMap<StoreAccountRef, Vec<SafeAccount>>>,
vaults: Mutex<HashMap<String, Box<VaultKeyDirectory>>>,
vaults: Mutex<HashMap<String, Box<dyn VaultKeyDirectory>>>,
timestamp: Mutex<Timestamp>,
}

Expand All @@ -272,12 +272,12 @@ struct Timestamp {

impl EthMultiStore {
/// Open new multi-accounts store with given key directory backend.
pub fn open(directory: Box<KeyDirectory>) -> Result<Self, Error> {
pub fn open(directory: Box<dyn KeyDirectory>) -> Result<Self, Error> {
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<KeyDirectory>, iterations: u32) -> Result<Self, Error> {
pub fn open_with_iterations(directory: Box<dyn KeyDirectory>, iterations: u32) -> Result<Self, Error> {
let store = EthMultiStore {
dir: directory,
vaults: Mutex::new(HashMap::new()),
Expand Down
6 changes: 3 additions & 3 deletions accounts/ethstore/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use dir;
use Error;

/// Import an account from a file.
pub fn import_account(path: &Path, dst: &KeyDirectory) -> Result<Address, Error> {
pub fn import_account(path: &Path, dst: &dyn KeyDirectory) -> Result<Address, Error> {
let key_manager = DiskKeyFileManager::default();
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();
let filename = path.file_name().and_then(|n| n.to_str()).map(|f| f.to_owned());
Expand All @@ -40,7 +40,7 @@ pub fn import_account(path: &Path, dst: &KeyDirectory) -> Result<Address, Error>
}

/// Import all accounts from one directory to the other.
pub fn import_accounts(src: &KeyDirectory, dst: &KeyDirectory) -> Result<Vec<Address>, Error> {
pub fn import_accounts(src: &dyn KeyDirectory, dst: &dyn KeyDirectory) -> Result<Vec<Address>, Error> {
let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter()
.map(|a| a.address)
Expand All @@ -64,7 +64,7 @@ pub fn read_geth_accounts(testnet: bool) -> Vec<Address> {
}

/// Import specific `desired` accounts from the Geth keystore into `dst`.
pub fn import_geth_accounts(dst: &KeyDirectory, desired: HashSet<Address>, testnet: bool) -> Result<Vec<Address>, Error> {
pub fn import_geth_accounts(dst: &dyn KeyDirectory, desired: HashSet<Address>, testnet: bool) -> Result<Vec<Address>, Error> {
let src = RootDiskDirectory::at(dir::geth(testnet));
let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();
Expand Down
2 changes: 1 addition & 1 deletion accounts/ethstore/src/secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub trait SecretStore: SimpleSecretStore {
/// Imports existing JSON wallet
fn import_wallet(&self, vault: SecretVaultRef, json: &[u8], password: &Password, gen_id: bool) -> Result<StoreAccountRef, Error>;
/// Copies account between stores and vaults.
fn copy_account(&self, new_store: &SimpleSecretStore, new_vault: SecretVaultRef, account: &StoreAccountRef, password: &Password, new_password: &Password) -> Result<(), Error>;
fn copy_account(&self, new_store: &dyn SimpleSecretStore, new_vault: SecretVaultRef, account: &StoreAccountRef, password: &Password, new_password: &Password) -> Result<(), Error>;
/// Checks if password matches given account.
fn test_password(&self, account: &StoreAccountRef, password: &Password) -> Result<bool, Error>;

Expand Down
4 changes: 2 additions & 2 deletions accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct AccountProvider {
/// Address book.
address_book: RwLock<AddressBook>,
/// Accounts on disk
sstore: Box<SecretStore>,
sstore: Box<dyn SecretStore>,
/// Accounts unlocked with rolling tokens
transient_sstore: EthMultiStore,
/// When unlocking account permanently we additionally keep a raw secret in memory
Expand All @@ -80,7 +80,7 @@ fn transient_sstore() -> EthMultiStore {

impl AccountProvider {
/// Creates new account provider.
pub fn new(sstore: Box<SecretStore>, settings: AccountProviderSettings) -> Self {
pub fn new(sstore: Box<dyn SecretStore>, settings: AccountProviderSettings) -> Self {
if let Ok(accounts) = sstore.accounts() {
for account in accounts.into_iter().filter(|a| settings.blacklisted_accounts.contains(&a.address)) {
warn!("Local Account {} has a blacklisted (known to be weak) address and will be ignored",
Expand Down
2 changes: 1 addition & 1 deletion cli-signer/rpc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern crate log;
extern crate matches;

/// Boxed future response.
pub type BoxFuture<T, E> = Box<futures::Future<Item=T, Error=E> + Send>;
pub type BoxFuture<T, E> = Box<dyn futures::Future<Item=T, Error=E> + Send>;

#[cfg(test)]
mod tests {
Expand Down
14 changes: 8 additions & 6 deletions ethcore/client-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ use trace::{
};
use vm::{LastHashes, Schedule};

mod io_message;
pub use self::io_message::ClientIoMessage;
use common_types::snapshot::Progress;

/// State information to be used during client query
Expand Down Expand Up @@ -172,14 +170,13 @@ pub trait EngineClient: Sync + Send + ChainInfo {
fn block_header(&self, id: BlockId) -> Option<encoded::Header>;
}

// FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient?
/// Provides methods to import block into blockchain
pub trait ImportBlock {
/// Import a block into the blockchain.
fn import_block(&self, block: Unverified) -> EthcoreResult<H256>;

// todo[dvdplm]: probably a bad place for this method
/// Triggered by a message from a block queue when the block is ready for insertion
/// Triggered by a message from a block queue when the block is ready for insertion.
/// Returns the number of blocks imported.
fn import_verified_blocks(&self) -> usize;
}

Expand All @@ -195,11 +192,14 @@ pub trait IoClient: Sync + Send {
fn queue_consensus_message(&self, message: Bytes);
}

/// Implement this for clients that need logic to decide when/how to advance.
pub trait Tick {
/// Tick the client
fn tick(&self, _prevent_sleep: bool) {}
}

impl Tick for () {}

/// Provides recently seen bad blocks.
pub trait BadBlocks {
/// Returns a list of blocks that were recently not imported because they were invalid.
Expand Down Expand Up @@ -446,8 +446,10 @@ pub trait DatabaseRestore: Send + Sync {
fn restore_db(&self, new_db: &str) -> Result<(), EthcoreError>;
}

/// Trait alias for the Client traits used when taking snapshots
/// Snapshot related functionality
pub trait SnapshotClient: BlockChainClient + BlockInfo + DatabaseRestore + BlockChainReset {
/// Take a snapshot at the given block.
/// If the ID given is "latest", this will default to 1000 blocks behind.
fn take_snapshot<W: SnapshotWriter + Send>(
&self,
writer: W,
Expand Down
8 changes: 4 additions & 4 deletions ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use common_types::{
errors::EthcoreResult,
header::Header,
ids::BlockId,
io_message::ClientIoMessage,
verification::VerificationQueueInfo as BlockQueueInfo,
};
use client_traits::ClientIoMessage;
use kvdb::KeyValueDB;
use vm::EnvInfo;

Expand Down Expand Up @@ -162,8 +162,8 @@ impl<T: LightChainClient> AsLightClient for T {
}

/// Light client implementation.
pub struct Client<T: 'static> {
queue: HeaderQueue<Self>,
pub struct Client<T> {
queue: HeaderQueue<()>,
engine: Arc<dyn Engine>,
chain: HeaderChain,
report: RwLock<ClientReport>,
Expand All @@ -184,7 +184,7 @@ impl<T: ChainDataFetcher> Client<T> {
chain_col: Option<u32>,
spec: &Spec,
fetcher: T,
io_channel: IoChannel<ClientIoMessage<Self>>,
io_channel: IoChannel<ClientIoMessage<()>>,
cache: Arc<Mutex<Cache>>
) -> Result<Self, Error> {
Ok(Self {
Expand Down
18 changes: 10 additions & 8 deletions ethcore/light/src/client/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
use std::fmt;
use std::sync::Arc;

use common_types::errors::EthcoreError as CoreError;
use client_traits::ClientIoMessage;
use common_types::{
errors::EthcoreError as CoreError,
io_message::ClientIoMessage,
};
use ethcore_db as db;
use ethcore_blockchain::BlockChainDB;
use spec::Spec;
Expand Down Expand Up @@ -60,13 +62,13 @@ impl fmt::Display for Error {
/// Light client service.
pub struct Service<T: 'static> {
client: Arc<Client<T>>,
io_service: IoService<ClientIoMessage<Client<T>>>,
io_service: IoService<ClientIoMessage<()>>,
}

impl<T: ChainDataFetcher> Service<T> {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, db: Arc<dyn BlockChainDB>, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
let io_service = IoService::<ClientIoMessage<Client<T>>>::start().map_err(Error::Io)?;
let io_service = IoService::<ClientIoMessage<()>>::start().map_err(Error::Io)?;
let client = Arc::new(Client::new(config,
db.key_value().clone(),
db::COL_LIGHT_CHAIN,
Expand All @@ -90,7 +92,7 @@ impl<T: ChainDataFetcher> Service<T> {
}

/// Register an I/O handler on the service.
pub fn register_handler(&self, handler: Arc<dyn IoHandler<ClientIoMessage<Client<T>>> + Send>) -> Result<(), IoError> {
pub fn register_handler(&self, handler: Arc<dyn IoHandler<ClientIoMessage<()>> + Send>) -> Result<(), IoError> {
self.io_service.register_handler(handler)
}

Expand All @@ -100,10 +102,10 @@ impl<T: ChainDataFetcher> Service<T> {
}
}

struct ImportBlocks<T: 'static>(Arc<Client<T>>);
struct ImportBlocks<T>(Arc<Client<T>>);

impl<T: ChainDataFetcher> IoHandler<ClientIoMessage<Client<T>>> for ImportBlocks<T> {
fn message(&self, _io: &IoContext<ClientIoMessage<Client<T>>>, message: &ClientIoMessage<Client<T>>) {
impl<T: ChainDataFetcher> IoHandler<ClientIoMessage<()>> for ImportBlocks<T> {
fn message(&self, _io: &IoContext<ClientIoMessage<()>>, message: &ClientIoMessage<()>) {
if let ClientIoMessage::BlockVerified = *message {
self.0.import_verified();
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/private-tx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub enum Error {
}

impl error::Error for Error {
fn source(&self) -> Option<&(error::Error + 'static)> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Decoder(e) => Some(e),
Expand Down
Loading

0 comments on commit e28fce7

Please sign in to comment.