work is in progress
This commit is contained in:
commit
47aacbb819
@ -37,10 +37,10 @@ use transaction::LocalizedTransaction;
|
||||
use extras::TransactionAddress;
|
||||
use filter::Filter;
|
||||
use log_entry::LocalizedLogEntry;
|
||||
use util::keys::store::SecretStore;
|
||||
pub use block_queue::{BlockQueueConfig, BlockQueueInfo};
|
||||
pub use blockchain::{TreeRoute, BlockChainConfig, CacheSize as BlockChainCacheSize};
|
||||
|
||||
|
||||
/// Uniquely identifies block.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum BlockId {
|
||||
@ -233,7 +233,6 @@ pub struct Client<V = CanonVerifier> where V: Verifier {
|
||||
author: RwLock<Address>,
|
||||
extra_data: RwLock<Bytes>,
|
||||
verifier: PhantomData<V>,
|
||||
secret_store: Arc<RwLock<SecretStore>>,
|
||||
}
|
||||
|
||||
const HISTORY: u64 = 1000;
|
||||
@ -269,9 +268,6 @@ impl<V> Client<V> where V: Verifier {
|
||||
let panic_handler = PanicHandler::new_in_arc();
|
||||
panic_handler.forward_from(&block_queue);
|
||||
|
||||
let secret_store = Arc::new(RwLock::new(SecretStore::new()));
|
||||
secret_store.write().unwrap().try_import_existing();
|
||||
|
||||
Ok(Arc::new(Client {
|
||||
chain: chain,
|
||||
engine: engine,
|
||||
@ -285,7 +281,6 @@ impl<V> Client<V> where V: Verifier {
|
||||
author: RwLock::new(Address::new()),
|
||||
extra_data: RwLock::new(Vec::new()),
|
||||
verifier: PhantomData,
|
||||
secret_store: secret_store,
|
||||
}))
|
||||
}
|
||||
|
||||
@ -310,11 +305,6 @@ impl<V> Client<V> where V: Verifier {
|
||||
last_hashes
|
||||
}
|
||||
|
||||
/// Secret store (key manager)
|
||||
pub fn secret_store(&self) -> &Arc<RwLock<SecretStore>> {
|
||||
&self.secret_store
|
||||
}
|
||||
|
||||
fn check_and_close_block(&self, block: &PreverifiedBlock) -> Result<ClosedBlock, ()> {
|
||||
let engine = self.engine.deref().deref();
|
||||
let header = &block.header;
|
||||
|
@ -49,10 +49,11 @@ use ethcore::spec::*;
|
||||
use ethcore::client::*;
|
||||
use ethcore::service::{ClientService, NetSyncMessage};
|
||||
use ethcore::ethereum;
|
||||
use ethsync::{EthSync, SyncConfig, SyncStatusProvider};
|
||||
use ethsync::{EthSync, SyncConfig, SyncProvider};
|
||||
use docopt::Docopt;
|
||||
use daemonize::Daemonize;
|
||||
use number_prefix::{binary_prefix, Standalone, Prefixed};
|
||||
use util::keys::store::*;
|
||||
|
||||
fn die_with_message(msg: &str) -> ! {
|
||||
println!("ERROR: {}", msg);
|
||||
@ -79,7 +80,7 @@ Protocol Options:
|
||||
or olympic, frontier, homestead, mainnet, morden, or testnet [default: homestead].
|
||||
--testnet Equivalent to --chain testnet (geth-compatible).
|
||||
--networkid INDEX Override the network identifier from the chain we are on.
|
||||
--archive Client should not prune the state/storage trie.
|
||||
--pruning Client should prune the state/storage trie.
|
||||
-d --datadir PATH Specify the database & configuration directory path [default: $HOME/.parity]
|
||||
--keys-path PATH Specify the path for JSON key files to be found [default: $HOME/.web3/keys]
|
||||
--identity NAME Specify your node's name.
|
||||
@ -140,7 +141,7 @@ struct Args {
|
||||
flag_identity: String,
|
||||
flag_cache: Option<usize>,
|
||||
flag_keys_path: String,
|
||||
flag_archive: bool,
|
||||
flag_pruning: bool,
|
||||
flag_no_bootstrap: bool,
|
||||
flag_listen_address: String,
|
||||
flag_public_address: Option<String>,
|
||||
@ -195,7 +196,7 @@ fn setup_log(init: &Option<String>) {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str, cors_domain: &str, apis: Vec<&str>) -> Option<Arc<PanicHandler>> {
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, secret_store: Arc<SecretStore>, url: &str, cors_domain: &str, apis: Vec<&str>) -> Option<Arc<PanicHandler>> {
|
||||
use rpc::v1::*;
|
||||
|
||||
let server = rpc::RpcServer::new();
|
||||
@ -204,7 +205,7 @@ fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str, cors_dom
|
||||
"web3" => server.add_delegate(Web3Client::new().to_delegate()),
|
||||
"net" => server.add_delegate(NetClient::new(&sync).to_delegate()),
|
||||
"eth" => {
|
||||
server.add_delegate(EthClient::new(&client, &sync).to_delegate());
|
||||
server.add_delegate(EthClient::new(&client, &sync, &secret_store).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(&client).to_delegate());
|
||||
}
|
||||
_ => {
|
||||
@ -402,7 +403,7 @@ impl Configuration {
|
||||
client_config.blockchain.max_cache_size = self.args.flag_cache_max_size;
|
||||
}
|
||||
}
|
||||
client_config.prefer_journal = !self.args.flag_archive;
|
||||
client_config.prefer_journal = self.args.flag_pruning;
|
||||
client_config.name = self.args.flag_identity.clone();
|
||||
client_config.queue.max_mem_use = self.args.flag_queue_max_size;
|
||||
let mut service = ClientService::start(client_config, spec, net_settings, &Path::new(&self.path())).unwrap();
|
||||
@ -414,6 +415,13 @@ impl Configuration {
|
||||
// Sync
|
||||
let sync = EthSync::register(service.network(), sync_config, client);
|
||||
|
||||
// Secret Store
|
||||
let secret_store = Arc::new(SecretStore::new());
|
||||
{
|
||||
let import_ref = Arc::make_mut(&mut secret_store);
|
||||
import_ref.try_import_existing();
|
||||
}
|
||||
|
||||
// Setup rpc
|
||||
if self.args.flag_jsonrpc || self.args.flag_rpc {
|
||||
let url = format!("{}:{}",
|
||||
@ -424,7 +432,7 @@ impl Configuration {
|
||||
let cors = self.args.flag_rpccorsdomain.as_ref().unwrap_or(&self.args.flag_jsonrpc_cors);
|
||||
// TODO: use this as the API list.
|
||||
let apis = self.args.flag_rpcapi.as_ref().unwrap_or(&self.args.flag_jsonrpc_apis);
|
||||
let server_handler = setup_rpc_server(service.client(), sync.clone(), &url, cors, apis.split(",").collect());
|
||||
let server_handler = setup_rpc_server(service.client(), sync.clone(), secret_store.clone(), &url, cors, apis.split(",").collect());
|
||||
if let Some(handler) = server_handler {
|
||||
panic_handler.forward_from(handler.deref());
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
//! Eth rpc implementation.
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Weak, Mutex, RwLock};
|
||||
use ethsync::{SyncStatusProvider, SyncState};
|
||||
use ethsync::{SyncProvider, SyncState};
|
||||
use jsonrpc_core::*;
|
||||
use util::numbers::*;
|
||||
use util::sha3::*;
|
||||
@ -33,14 +33,14 @@ use v1::helpers::{PollFilter, PollManager};
|
||||
use util::keys::store::AccountProvider;
|
||||
|
||||
/// Eth rpc implementation.
|
||||
pub struct EthClient<C, S, A> where C: BlockChainClient, S: SyncStatusProvider, A: AccountProvider {
|
||||
pub struct EthClient<C, S, A> where C: BlockChainClient, S: SyncProvider, A: AccountProvider {
|
||||
client: Weak<C>,
|
||||
sync: Weak<S>,
|
||||
accounts: Weak<A>,
|
||||
hashrates: RwLock<HashMap<H256, u64>>,
|
||||
}
|
||||
|
||||
impl<C, S, A> EthClient<C, S, A> where C: BlockChainClient, S: SyncStatusProvider, A: AccountProvider {
|
||||
impl<C, S, A> EthClient<C, S, A> where C: BlockChainClient, S: SyncProvider, A: AccountProvider {
|
||||
/// Creates new EthClient.
|
||||
pub fn new(client: &Arc<C>, sync: &Arc<S>, accounts: &Arc<A>) -> Self {
|
||||
EthClient {
|
||||
@ -97,7 +97,7 @@ impl<C, S, A> EthClient<C, S, A> where C: BlockChainClient, S: SyncStatusProvide
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, S, A> Eth for EthClient<C, S, A> where C: BlockChainClient + 'static, S: SyncStatusProvider + 'static, A: AccountProvider + 'static {
|
||||
impl<C, S, A> Eth for EthClient<C, S, A> where C: BlockChainClient + 'static, S: SyncProvider + 'static, A: AccountProvider + 'static {
|
||||
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => to_value(&U256::from(take_weak!(self.sync).status().protocol_version)),
|
||||
|
@ -17,15 +17,15 @@
|
||||
//! Net rpc implementation.
|
||||
use std::sync::{Arc, Weak};
|
||||
use jsonrpc_core::*;
|
||||
use ethsync::SyncStatusProvider;
|
||||
use ethsync::SyncProvider;
|
||||
use v1::traits::Net;
|
||||
|
||||
/// Net rpc implementation.
|
||||
pub struct NetClient<S> where S: SyncStatusProvider {
|
||||
pub struct NetClient<S> where S: SyncProvider {
|
||||
sync: Weak<S>
|
||||
}
|
||||
|
||||
impl<S> NetClient<S> where S: SyncStatusProvider {
|
||||
impl<S> NetClient<S> where S: SyncProvider {
|
||||
/// Creates new NetClient.
|
||||
pub fn new(sync: &Arc<S>) -> Self {
|
||||
NetClient {
|
||||
@ -34,7 +34,7 @@ impl<S> NetClient<S> where S: SyncStatusProvider {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Net for NetClient<S> where S: SyncStatusProvider + 'static {
|
||||
impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
|
||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||
Ok(Value::U64(take_weak!(self.sync).status().protocol_version as u64))
|
||||
}
|
||||
|
@ -95,9 +95,11 @@ impl Default for SyncConfig {
|
||||
}
|
||||
|
||||
/// Current sync status
|
||||
pub trait SyncStatusProvider: Send + Sync {
|
||||
pub trait SyncProvider: Send + Sync {
|
||||
/// Get sync status
|
||||
fn status(&self) -> SyncStatus;
|
||||
/// Insert transaction in the sync transaction queue
|
||||
fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction);
|
||||
}
|
||||
|
||||
/// Ethereum network protocol handler
|
||||
@ -130,9 +132,16 @@ impl EthSync {
|
||||
pub fn restart(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
||||
self.sync.write().unwrap().restart(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncProvider for EthSync {
|
||||
/// Get sync status
|
||||
fn status(&self) -> SyncStatus {
|
||||
self.sync.read().unwrap().status()
|
||||
}
|
||||
|
||||
/// Insert transaction in transaction queue
|
||||
pub fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction) {
|
||||
fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction) {
|
||||
use util::numbers::*;
|
||||
|
||||
let nonce_fn = |a: &Address| self.chain.state().nonce(a) + U256::one();
|
||||
@ -141,13 +150,6 @@ impl EthSync {
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncStatusProvider for EthSync {
|
||||
/// Get sync status
|
||||
fn status(&self) -> SyncStatus {
|
||||
self.sync.read().unwrap().status()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
||||
fn initialize(&self, io: &NetworkContext<SyncMessage>) {
|
||||
io.register_timer(0, 1000).expect("Error registering sync timer");
|
||||
|
Loading…
Reference in New Issue
Block a user