Private transactions integration pr (#6422)
* Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Private tx execution * Test update * Renamed some methods * Fixed some tests * Reverted submodules * Fixed build * Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Encrypted private transaction message and signed reply added * Private tx execution * Test update * Main scenario completed * Merged with the latest head * Private transactions API * Comments after review fixed * Parameters for private transactions added to parity arguments * New files added * New API methods added * Do not process packets from unconfirmed peers * Merge with ptm_ss branch * Encryption and permissioning with key server added * Fixed compilation after merge * Version of Parity protocol incremented in order to support private transactions * Doc strings for constants added * Proper format for doc string added * fixed some encryptor.rs grumbles * Private transactions functionality moved to the separate crate * Refactoring in order to remove late initialisation * Tests fixed after moving to the separate crate * Fetch method removed * Sync test helpers refactored * Interaction with encryptor refactored * Contract address retrieving via substate removed * Sensible gas limit for private transactions implemented * New private contract with nonces added * Parsing of the response from key server fixed * Build fixed after the merge, native contracts removed * Crate renamed * Tests moved to the separate directory * Handling of errors reworked in order to use error chain * Encodable macro added, new constructor replaced with default * Native ethabi usage removed * Couple conversions optimized * Interactions with client reworked * Errors omitting removed * Fix after merge * Fix after the merge * private transactions improvements in progress * private_transactions -> ethcore/private-tx * making private transactions more idiomatic * private-tx encryptor uses shared FetchClient and is more idiomatic * removed redundant tests, moved integration tests to tests/ dir * fixed failing service test * reenable add_notify on private tx provider * removed private_tx tests from sync module * removed commented out code * Use plain password instead of unlocking account manager * remove dead code * Link to the contract changed * Transaction signature chain replay protection module created * Redundant type conversion removed * Contract address returned by private provider * Test fixed * Addressing grumbles in PrivateTransactions (#8249) * Tiny fixes part 1. * A bunch of additional comments and todos. * Fix ethsync tests. * resolved merge conflicts * final private tx pr (#8318) * added cli option that enables private transactions * fixed failing test * fixed failing test * fixed failing test * fixed failing test
This commit is contained in:
committed by
Marek Kotewicz
parent
c039ab79b5
commit
e6f75bccfe
@@ -5,8 +5,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.10"
|
||||
error-chain = { version = "0.11", default-features = false }
|
||||
ethcore = { path = ".." }
|
||||
ethcore-io = { path = "../../util/io" }
|
||||
ethcore-private-tx = { path = "../private-tx" }
|
||||
ethsync = { path = "../../sync" }
|
||||
kvdb = { path = "../../util/kvdb" }
|
||||
log = "0.3"
|
||||
stop-guard = { path = "../../util/stop-guard" }
|
||||
|
||||
30
ethcore/service/src/error.rs
Normal file
30
ethcore/service/src/error.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethcore;
|
||||
use io;
|
||||
use ethcore_private_tx;
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
PrivateTransactions(ethcore_private_tx::Error, ethcore_private_tx::ErrorKind);
|
||||
}
|
||||
|
||||
foreign_links {
|
||||
Ethcore(ethcore::error::Error);
|
||||
IoError(io::IoError);
|
||||
}
|
||||
}
|
||||
@@ -17,18 +17,25 @@
|
||||
extern crate ansi_term;
|
||||
extern crate ethcore;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethsync;
|
||||
extern crate kvdb;
|
||||
extern crate ethcore_private_tx;
|
||||
extern crate stop_guard;
|
||||
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate tempdir;
|
||||
|
||||
mod error;
|
||||
mod service;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate kvdb_rocksdb;
|
||||
|
||||
mod service;
|
||||
|
||||
pub use service::ClientService;
|
||||
pub use error::{Error, ErrorKind};
|
||||
pub use service::{ClientService, PrivateTxService};
|
||||
|
||||
@@ -24,18 +24,50 @@ use io::{IoContext, TimerToken, IoHandler, IoService, IoError};
|
||||
use kvdb::{KeyValueDB, KeyValueDBHandler};
|
||||
use stop_guard::StopGuard;
|
||||
|
||||
use ethsync::PrivateTxHandler;
|
||||
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
|
||||
use ethcore::error::Error;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
||||
use ethcore::snapshot::{RestorationStatus};
|
||||
use ethcore::spec::Spec;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
|
||||
use ethcore_private_tx;
|
||||
use Error;
|
||||
|
||||
pub struct PrivateTxService {
|
||||
provider: Arc<ethcore_private_tx::Provider>,
|
||||
}
|
||||
|
||||
impl PrivateTxService {
|
||||
fn new(provider: Arc<ethcore_private_tx::Provider>) -> Self {
|
||||
PrivateTxService {
|
||||
provider,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns underlying provider.
|
||||
pub fn provider(&self) -> Arc<ethcore_private_tx::Provider> {
|
||||
self.provider.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl PrivateTxHandler for PrivateTxService {
|
||||
fn import_private_transaction(&self, rlp: &[u8]) -> Result<(), String> {
|
||||
self.provider.import_private_transaction(rlp).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn import_signed_private_transaction(&self, rlp: &[u8]) -> Result<(), String> {
|
||||
self.provider.import_signed_private_transaction(rlp).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Client service setup. Creates and registers client and network services with the IO subsystem.
|
||||
pub struct ClientService {
|
||||
io_service: Arc<IoService<ClientIoMessage>>,
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
private_tx: Arc<PrivateTxService>,
|
||||
database: Arc<KeyValueDB>,
|
||||
_stop_guard: StopGuard,
|
||||
}
|
||||
@@ -50,6 +82,9 @@ impl ClientService {
|
||||
restoration_db_handler: Box<KeyValueDBHandler>,
|
||||
_ipc_path: &Path,
|
||||
miner: Arc<Miner>,
|
||||
account_provider: Arc<AccountProvider>,
|
||||
encryptor: Box<ethcore_private_tx::Encryptor>,
|
||||
private_tx_conf: ethcore_private_tx::ProviderConfig,
|
||||
) -> Result<ClientService, Error>
|
||||
{
|
||||
let io_service = IoService::<ClientIoMessage>::start()?;
|
||||
@@ -70,9 +105,13 @@ impl ClientService {
|
||||
};
|
||||
let snapshot = Arc::new(SnapshotService::new(snapshot_params)?);
|
||||
|
||||
let provider = Arc::new(ethcore_private_tx::Provider::new(client.clone(), account_provider, encryptor, private_tx_conf, io_service.channel())?);
|
||||
let private_tx = Arc::new(PrivateTxService::new(provider));
|
||||
|
||||
let client_io = Arc::new(ClientIoHandler {
|
||||
client: client.clone(),
|
||||
snapshot: snapshot.clone(),
|
||||
private_tx: private_tx.clone(),
|
||||
});
|
||||
io_service.register_handler(client_io)?;
|
||||
|
||||
@@ -84,6 +123,7 @@ impl ClientService {
|
||||
io_service: Arc::new(io_service),
|
||||
client: client,
|
||||
snapshot: snapshot,
|
||||
private_tx,
|
||||
database: client_db,
|
||||
_stop_guard: stop_guard,
|
||||
})
|
||||
@@ -104,6 +144,11 @@ impl ClientService {
|
||||
self.snapshot.clone()
|
||||
}
|
||||
|
||||
/// Get private transaction service.
|
||||
pub fn private_tx_service(&self) -> Arc<PrivateTxService> {
|
||||
self.private_tx.clone()
|
||||
}
|
||||
|
||||
/// Get network service component
|
||||
pub fn io(&self) -> Arc<IoService<ClientIoMessage>> {
|
||||
self.io_service.clone()
|
||||
@@ -122,6 +167,7 @@ impl ClientService {
|
||||
struct ClientIoHandler {
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
private_tx: Arc<PrivateTxService>,
|
||||
}
|
||||
|
||||
const CLIENT_TICK_TIMER: TimerToken = 0;
|
||||
@@ -180,6 +226,9 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
|
||||
ClientIoMessage::NewMessage(ref message) => if let Err(e) = self.client.engine().handle_message(message) {
|
||||
trace!(target: "poa", "Invalid message received: {}", e);
|
||||
},
|
||||
ClientIoMessage::NewPrivateTransaction => if let Err(e) = self.private_tx.provider.on_private_transaction_queued() {
|
||||
warn!("Failed to handle private transaction {:?}", e);
|
||||
},
|
||||
_ => {} // ignore other messages
|
||||
}
|
||||
}
|
||||
@@ -192,6 +241,7 @@ mod tests {
|
||||
|
||||
use tempdir::TempDir;
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::ClientConfig;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::spec::Spec;
|
||||
@@ -200,6 +250,8 @@ mod tests {
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig, CompactionProfile};
|
||||
use super::*;
|
||||
|
||||
use ethcore_private_tx;
|
||||
|
||||
#[test]
|
||||
fn it_can_be_started() {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
@@ -241,6 +293,9 @@ mod tests {
|
||||
restoration_db_handler,
|
||||
tempdir.path(),
|
||||
Arc::new(Miner::with_spec(&spec)),
|
||||
Arc::new(AccountProvider::transient_provider()),
|
||||
Box::new(ethcore_private_tx::NoopEncryptor),
|
||||
Default::default()
|
||||
);
|
||||
assert!(service.is_ok());
|
||||
drop(service.unwrap());
|
||||
|
||||
Reference in New Issue
Block a user