Remove private transactions
This commit is contained in:
@@ -17,11 +17,8 @@
|
||||
use api::PAR_PROTOCOL;
|
||||
use bytes::Bytes;
|
||||
use chain::{
|
||||
sync_packet::{
|
||||
PacketInfo, SyncPacket,
|
||||
SyncPacket::{PrivateTransactionPacket, SignedPrivateTransactionPacket},
|
||||
},
|
||||
ChainSync, SyncSupplier, ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_3,
|
||||
sync_packet::{PacketInfo, SyncPacket},
|
||||
ChainSync, SyncSupplier, ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_2,
|
||||
};
|
||||
use ethcore::{
|
||||
client::{
|
||||
@@ -36,7 +33,7 @@ use ethcore::{
|
||||
use ethereum_types::H256;
|
||||
use io::{IoChannel, IoContext, IoHandler};
|
||||
use network::{self, client_version::ClientVersion, PacketId, PeerId, ProtocolId, SessionInfo};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
sync::Arc,
|
||||
@@ -44,7 +41,6 @@ use std::{
|
||||
use sync_io::SyncIo;
|
||||
use tests::snapshot::*;
|
||||
|
||||
use private_tx::SimplePrivateTxHandler;
|
||||
use types::BlockNumber;
|
||||
use SyncConfig;
|
||||
|
||||
@@ -177,7 +173,7 @@ where
|
||||
|
||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
||||
if protocol == &PAR_PROTOCOL {
|
||||
PAR_PROTOCOL_VERSION_3.0
|
||||
PAR_PROTOCOL_VERSION_2.0
|
||||
} else {
|
||||
self.eth_protocol_version(peer_id)
|
||||
}
|
||||
@@ -262,7 +258,6 @@ where
|
||||
pub snapshot_service: Arc<TestSnapshotService>,
|
||||
pub sync: RwLock<ChainSync>,
|
||||
pub queue: RwLock<VecDeque<TestPacket>>,
|
||||
pub private_tx_handler: Arc<SimplePrivateTxHandler>,
|
||||
pub io_queue: RwLock<VecDeque<ChainMessageType>>,
|
||||
new_blocks_queue: RwLock<VecDeque<NewBlockMessage>>,
|
||||
}
|
||||
@@ -285,22 +280,6 @@ where
|
||||
ChainMessageType::Consensus(data) => {
|
||||
self.sync.write().propagate_consensus_packet(&mut io, data)
|
||||
}
|
||||
ChainMessageType::PrivateTransaction(transaction_hash, data) => {
|
||||
self.sync.write().propagate_private_transaction(
|
||||
&mut io,
|
||||
transaction_hash,
|
||||
PrivateTransactionPacket,
|
||||
data,
|
||||
)
|
||||
}
|
||||
ChainMessageType::SignedPrivateTransaction(transaction_hash, data) => {
|
||||
self.sync.write().propagate_private_transaction(
|
||||
&mut io,
|
||||
transaction_hash,
|
||||
SignedPrivateTransactionPacket,
|
||||
data,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,15 +405,13 @@ impl TestNet<EthPeer<TestBlockChainClient>> {
|
||||
for _ in 0..n {
|
||||
let chain = TestBlockChainClient::new();
|
||||
let ss = Arc::new(TestSnapshotService::new());
|
||||
let private_tx_handler = Arc::new(SimplePrivateTxHandler::default());
|
||||
let sync = ChainSync::new(config.clone(), &chain, Some(private_tx_handler.clone()));
|
||||
let sync = ChainSync::new(config.clone(), &chain);
|
||||
net.peers.push(Arc::new(EthPeer {
|
||||
sync: RwLock::new(sync),
|
||||
snapshot_service: ss,
|
||||
chain: Arc::new(chain),
|
||||
miner: Arc::new(Miner::new_for_tests(&Spec::new_test(), None)),
|
||||
queue: RwLock::new(VecDeque::new()),
|
||||
private_tx_handler,
|
||||
io_queue: RwLock::new(VecDeque::new()),
|
||||
new_blocks_queue: RwLock::new(VecDeque::new()),
|
||||
}));
|
||||
@@ -476,16 +453,14 @@ impl TestNet<EthPeer<EthcoreClient>> {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let private_tx_handler = Arc::new(SimplePrivateTxHandler::default());
|
||||
let ss = Arc::new(TestSnapshotService::new());
|
||||
let sync = ChainSync::new(config, &*client, Some(private_tx_handler.clone()));
|
||||
let sync = ChainSync::new(config, &*client);
|
||||
let peer = Arc::new(EthPeer {
|
||||
sync: RwLock::new(sync),
|
||||
snapshot_service: ss,
|
||||
chain: client,
|
||||
miner,
|
||||
queue: RwLock::new(VecDeque::new()),
|
||||
private_tx_handler,
|
||||
io_queue: RwLock::new(VecDeque::new()),
|
||||
new_blocks_queue: RwLock::new(VecDeque::new()),
|
||||
});
|
||||
@@ -604,15 +579,11 @@ impl<C: FlushingBlockChainClient> TestNet<EthPeer<C>> {
|
||||
|
||||
pub struct TestIoHandler {
|
||||
pub client: Arc<EthcoreClient>,
|
||||
pub private_tx_queued: Mutex<usize>,
|
||||
}
|
||||
|
||||
impl TestIoHandler {
|
||||
pub fn new(client: Arc<EthcoreClient>) -> Self {
|
||||
TestIoHandler {
|
||||
client,
|
||||
private_tx_queued: Mutex::default(),
|
||||
}
|
||||
TestIoHandler { client }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +591,6 @@ impl IoHandler<ClientIoMessage> for TestIoHandler {
|
||||
fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) {
|
||||
match *net_message {
|
||||
ClientIoMessage::Execute(ref exec) => {
|
||||
*self.private_tx_queued.lock() += 1;
|
||||
(*exec.0)(&self.client);
|
||||
}
|
||||
_ => {} // ignore other messages
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
mod chain;
|
||||
mod consensus;
|
||||
pub mod helpers;
|
||||
mod private;
|
||||
pub mod snapshot;
|
||||
|
||||
#[cfg(feature = "ipc")]
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethcore::{
|
||||
client::{BlockChainClient, ClientIoMessage},
|
||||
engines,
|
||||
executive::contract_address,
|
||||
miner::{self, MinerService},
|
||||
spec::Spec,
|
||||
test_helpers::push_block_with_transactions,
|
||||
CreateContractAddress,
|
||||
};
|
||||
use ethcore_private_tx::{
|
||||
Importer, NoopEncryptor, Provider, ProviderConfig, SignedPrivateTransaction, StoringKeyProvider,
|
||||
};
|
||||
use ethkey::KeyPair;
|
||||
use hash::keccak;
|
||||
use io::{IoChannel, IoHandler};
|
||||
use rlp::Rlp;
|
||||
use rustc_hex::FromHex;
|
||||
use std::sync::Arc;
|
||||
use tests::helpers::{TestIoHandler, TestNet};
|
||||
use types::{
|
||||
ids::BlockId,
|
||||
transaction::{Action, Transaction},
|
||||
};
|
||||
use SyncConfig;
|
||||
|
||||
fn seal_spec() -> Spec {
|
||||
let spec_data = include_str!("../res/private_spec.json");
|
||||
Spec::load(&::std::env::temp_dir(), spec_data.as_bytes()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_private_transaction() {
|
||||
// Setup two clients
|
||||
let s0 = KeyPair::from_secret_slice(&keccak("1")).unwrap();
|
||||
let s1 = KeyPair::from_secret_slice(&keccak("0")).unwrap();
|
||||
|
||||
let signer = Arc::new(ethcore_private_tx::KeyPairSigner(vec![
|
||||
s0.clone(),
|
||||
s1.clone(),
|
||||
]));
|
||||
|
||||
let mut net = TestNet::with_spec(2, SyncConfig::default(), seal_spec);
|
||||
let client0 = net.peer(0).chain.clone();
|
||||
let client1 = net.peer(1).chain.clone();
|
||||
let io_handler0: Arc<dyn IoHandler<ClientIoMessage>> =
|
||||
Arc::new(TestIoHandler::new(net.peer(0).chain.clone()));
|
||||
let io_handler1: Arc<dyn IoHandler<ClientIoMessage>> =
|
||||
Arc::new(TestIoHandler::new(net.peer(1).chain.clone()));
|
||||
|
||||
net.peer(0)
|
||||
.miner
|
||||
.set_author(miner::Author::Sealer(engines::signer::from_keypair(
|
||||
s0.clone(),
|
||||
)));
|
||||
net.peer(1)
|
||||
.miner
|
||||
.set_author(miner::Author::Sealer(engines::signer::from_keypair(
|
||||
s1.clone(),
|
||||
)));
|
||||
net.peer(0)
|
||||
.chain
|
||||
.engine()
|
||||
.register_client(Arc::downgrade(&net.peer(0).chain) as _);
|
||||
net.peer(1)
|
||||
.chain
|
||||
.engine()
|
||||
.register_client(Arc::downgrade(&net.peer(1).chain) as _);
|
||||
net.peer(0)
|
||||
.chain
|
||||
.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler0)));
|
||||
net.peer(1)
|
||||
.chain
|
||||
.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler1)));
|
||||
|
||||
let (address, _) = contract_address(
|
||||
CreateContractAddress::FromSenderAndNonce,
|
||||
&s0.address(),
|
||||
&0.into(),
|
||||
&[],
|
||||
);
|
||||
let chain_id = client0.signing_chain_id();
|
||||
|
||||
// Exhange statuses
|
||||
net.sync();
|
||||
|
||||
// Setup private providers
|
||||
let validator_config = ProviderConfig {
|
||||
validator_accounts: vec![s1.address()],
|
||||
signer_account: None,
|
||||
};
|
||||
|
||||
let signer_config = ProviderConfig {
|
||||
validator_accounts: Vec::new(),
|
||||
signer_account: Some(s0.address()),
|
||||
};
|
||||
|
||||
let private_keys = Arc::new(StoringKeyProvider::default());
|
||||
|
||||
let pm0 = Arc::new(Provider::new(
|
||||
client0.clone(),
|
||||
net.peer(0).miner.clone(),
|
||||
signer.clone(),
|
||||
Box::new(NoopEncryptor::default()),
|
||||
signer_config,
|
||||
IoChannel::to_handler(Arc::downgrade(&io_handler0)),
|
||||
private_keys.clone(),
|
||||
));
|
||||
pm0.add_notify(net.peers[0].clone());
|
||||
|
||||
let pm1 = Arc::new(Provider::new(
|
||||
client1.clone(),
|
||||
net.peer(1).miner.clone(),
|
||||
signer.clone(),
|
||||
Box::new(NoopEncryptor::default()),
|
||||
validator_config,
|
||||
IoChannel::to_handler(Arc::downgrade(&io_handler1)),
|
||||
private_keys.clone(),
|
||||
));
|
||||
pm1.add_notify(net.peers[1].clone());
|
||||
|
||||
// Create and deploy contract
|
||||
let private_contract_test = "6060604052341561000f57600080fd5b60d88061001d6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630c55699c146046578063bc64b76d14607457600080fd5b3415605057600080fd5b60566098565b60405180826000191660001916815260200191505060405180910390f35b3415607e57600080fd5b6096600480803560001916906020019091905050609e565b005b60005481565b8060008160001916905550505600a165627a7a723058206acbdf4b15ca4c2d43e1b1879b830451a34f1e9d02ff1f2f394d8d857e79d2080029".from_hex().unwrap();
|
||||
let mut private_create_tx = Transaction::default();
|
||||
private_create_tx.action = Action::Create;
|
||||
private_create_tx.data = private_contract_test;
|
||||
private_create_tx.gas = 200000.into();
|
||||
let private_create_tx_signed = private_create_tx.sign(&s0.secret(), None);
|
||||
let validators = vec![s1.address()];
|
||||
let (public_tx, _) = pm0
|
||||
.public_creation_transaction(
|
||||
BlockId::Latest,
|
||||
&private_create_tx_signed,
|
||||
&validators,
|
||||
0.into(),
|
||||
)
|
||||
.unwrap();
|
||||
let public_tx = public_tx.sign(&s0.secret(), chain_id);
|
||||
|
||||
let public_tx_copy = public_tx.clone();
|
||||
push_block_with_transactions(&client0, &[public_tx]);
|
||||
push_block_with_transactions(&client1, &[public_tx_copy]);
|
||||
|
||||
net.sync();
|
||||
|
||||
//Create private transaction for modifying state
|
||||
let mut private_tx = Transaction::default();
|
||||
private_tx.action = Action::Call(address.clone());
|
||||
private_tx.data = "bc64b76d2a00000000000000000000000000000000000000000000000000000000000000"
|
||||
.from_hex()
|
||||
.unwrap(); //setX(42)
|
||||
private_tx.gas = 120000.into();
|
||||
private_tx.nonce = 1.into();
|
||||
let private_tx = private_tx.sign(&s0.secret(), None);
|
||||
assert!(pm0.create_private_transaction(private_tx).is_ok());
|
||||
|
||||
//send private transaction message to validator
|
||||
net.sync();
|
||||
|
||||
let validator_handler = net.peer(1).private_tx_handler.clone();
|
||||
let received_private_transactions = validator_handler.txs.lock().clone();
|
||||
assert_eq!(received_private_transactions.len(), 1);
|
||||
|
||||
//process received private transaction message
|
||||
let private_transaction = received_private_transactions[0].clone();
|
||||
assert!(pm1.import_private_transaction(&private_transaction).is_ok());
|
||||
|
||||
//send signed response
|
||||
net.sync();
|
||||
|
||||
let sender_handler = net.peer(0).private_tx_handler.clone();
|
||||
let received_signed_private_transactions = sender_handler.signed_txs.lock().clone();
|
||||
assert_eq!(received_signed_private_transactions.len(), 1);
|
||||
|
||||
//process signed response
|
||||
let signed_private_transaction = received_signed_private_transactions[0].clone();
|
||||
assert!(pm0
|
||||
.import_signed_private_transaction(&signed_private_transaction)
|
||||
.is_ok());
|
||||
let signature: SignedPrivateTransaction =
|
||||
Rlp::new(&signed_private_transaction).as_val().unwrap();
|
||||
assert!(pm0.process_signature(&signature).is_ok());
|
||||
let local_transactions = net.peer(0).miner.local_transactions();
|
||||
assert_eq!(local_transactions.len(), 1);
|
||||
}
|
||||
Reference in New Issue
Block a user