* EIP-86

* Disable EIP-86 auto activation for now
This commit is contained in:
Arkadiy Paronyan
2017-04-19 14:30:00 +02:00
committed by GitHub
parent 0180b21dd1
commit b50fb71dd1
59 changed files with 433 additions and 289 deletions

View File

@@ -103,6 +103,7 @@ pub struct EthClient<C, SN: ?Sized, S: ?Sized, M, EM> where
external_miner: Arc<EM>,
seed_compute: Mutex<SeedHashCompute>,
options: EthClientOptions,
eip86_transition: u64,
}
impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
@@ -131,6 +132,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
external_miner: em.clone(),
seed_compute: Mutex::new(SeedHashCompute::new()),
options: options,
eip86_transition: client.eip86_transition(),
}
}
@@ -166,7 +168,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
seal_fields: view.seal().into_iter().map(Into::into).collect(),
uncles: block.uncle_hashes().into_iter().map(Into::into).collect(),
transactions: match include_txs {
true => BlockTransactions::Full(block.view().localized_transactions().into_iter().map(Into::into).collect()),
true => BlockTransactions::Full(block.view().localized_transactions().into_iter().map(|t| Transaction::from_localized(t, self.eip86_transition)).collect()),
false => BlockTransactions::Hashes(block.transaction_hashes().into_iter().map(Into::into).collect()),
},
extra_data: Bytes::new(view.extra_data()),
@@ -180,7 +182,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
fn transaction(&self, id: TransactionId) -> Result<Option<Transaction>, Error> {
match take_weak!(self.client).transaction(id) {
Some(t) => Ok(Some(Transaction::from(t))),
Some(t) => Ok(Some(Transaction::from_localized(t, self.eip86_transition))),
None => Ok(None),
}
}
@@ -507,7 +509,8 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
let hash: H256 = hash.into();
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
Ok(self.transaction(TransactionId::Hash(hash))?.or_else(|| miner.transaction(client.chain_info().best_block_number, &hash).map(Into::into)))
let block_number = client.chain_info().best_block_number;
Ok(self.transaction(TransactionId::Hash(hash))?.or_else(|| miner.transaction(block_number, &hash).map(|t| Transaction::from_pending(t, block_number, self.eip86_transition))))
}
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result<Option<Transaction>, Error> {

View File

@@ -25,7 +25,7 @@ use jsonrpc_core::Error;
use jsonrpc_macros::Trailing;
use light::cache::Cache as LightDataCache;
use light::client::Client as LightClient;
use light::client::{Client as LightClient, LightChainClient};
use light::{cht, TransactionQueue};
use light::on_demand::{request, OnDemand};
@@ -123,6 +123,7 @@ impl EthClient {
fn rich_block(&self, id: BlockId, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
let (on_demand, sync) = (self.on_demand.clone(), self.sync.clone());
let (client, engine) = (self.client.clone(), self.client.engine().clone());
let eip86_transition = self.client.eip86_transition();
// helper for filling out a rich block once we've got a block and a score.
let fill_rich = move |block: encoded::Block, score: Option<U256>| {
@@ -149,8 +150,8 @@ impl EthClient {
seal_fields: header.seal().into_iter().cloned().map(Into::into).collect(),
uncles: block.uncle_hashes().into_iter().map(Into::into).collect(),
transactions: match include_txs {
true => BlockTransactions::Full(block.view().localized_transactions().into_iter().map(Into::into).collect()),
false => BlockTransactions::Hashes(block.transaction_hashes().into_iter().map(Into::into).collect()),
true => BlockTransactions::Full(block.view().localized_transactions().into_iter().map(|t| Transaction::from_localized(t, eip86_transition)).collect()),
_ => BlockTransactions::Hashes(block.transaction_hashes().into_iter().map(Into::into).collect()),
},
extra_data: Bytes::new(header.extra_data().to_vec()),
},

View File

@@ -28,6 +28,8 @@ use ethstore::random_phrase;
use ethsync::LightSyncProvider;
use ethcore::account_provider::AccountProvider;
use light::client::LightChainClient;
use jsonrpc_core::Error;
use jsonrpc_macros::Trailing;
use v1::helpers::{errors, ipfs, SigningQueue, SignerService, NetworkSettings};
@@ -53,11 +55,13 @@ pub struct ParityClient {
signer: Option<Arc<SignerService>>,
dapps_interface: Option<String>,
dapps_port: Option<u16>,
eip86_transition: u64,
}
impl ParityClient {
/// Creates new `ParityClient`.
pub fn new(
client: Arc<LightChainClient>,
light_dispatch: Arc<LightDispatcher>,
accounts: Arc<AccountProvider>,
logger: Arc<RotatingLogger>,
@@ -74,6 +78,7 @@ impl ParityClient {
signer: signer,
dapps_interface: dapps_interface,
dapps_port: dapps_port,
eip86_transition: client.eip86_transition(),
}
}
@@ -245,7 +250,7 @@ impl Parity for ParityClient {
Ok(
txq.ready_transactions(chain_info.best_block_number, chain_info.best_block_timestamp)
.into_iter()
.map(Into::into)
.map(|tx| Transaction::from_pending(tx, chain_info.best_block_number, self.eip86_transition))
.collect::<Vec<_>>()
)
}
@@ -256,7 +261,7 @@ impl Parity for ParityClient {
Ok(
txq.future_transactions(chain_info.best_block_number, chain_info.best_block_timestamp)
.into_iter()
.map(Into::into)
.map(|tx| Transaction::from_pending(tx, chain_info.best_block_number, self.eip86_transition))
.collect::<Vec<_>>()
)
}

View File

@@ -69,6 +69,7 @@ pub struct ParityClient<C, M, S: ?Sized, U> where
signer: Option<Arc<SignerService>>,
dapps_interface: Option<String>,
dapps_port: Option<u16>,
eip86_transition: u64,
}
impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
@@ -103,6 +104,7 @@ impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
signer: signer,
dapps_interface: dapps_interface,
dapps_port: dapps_port,
eip86_transition: client.eip86_transition(),
}
}
@@ -288,11 +290,13 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
}
fn pending_transactions(&self) -> Result<Vec<Transaction>, Error> {
Ok(take_weak!(self.miner).pending_transactions().into_iter().map(Into::into).collect::<Vec<_>>())
let block_number = take_weak!(self.client).chain_info().best_block_number;
Ok(take_weak!(self.miner).pending_transactions().into_iter().map(|t| Transaction::from_pending(t, block_number, self.eip86_transition)).collect::<Vec<_>>())
}
fn future_transactions(&self) -> Result<Vec<Transaction>, Error> {
Ok(take_weak!(self.miner).future_transactions().into_iter().map(Into::into).collect::<Vec<_>>())
let block_number = take_weak!(self.client).chain_info().best_block_number;
Ok(take_weak!(self.miner).future_transactions().into_iter().map(|t| Transaction::from_pending(t, block_number, self.eip86_transition)).collect::<Vec<_>>())
}
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>, Error> {
@@ -305,9 +309,10 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
fn local_transactions(&self) -> Result<BTreeMap<H256, LocalTransactionStatus>, Error> {
let transactions = take_weak!(self.miner).local_transactions();
let block_number = take_weak!(self.client).chain_info().best_block_number;
Ok(transactions
.into_iter()
.map(|(hash, status)| (hash.into(), status.into()))
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
.collect()
)
}

View File

@@ -39,9 +39,12 @@ pub struct ParitySetClient<C, M, U, F = fetch::Client> {
updater: Weak<U>,
net: Weak<ManageNetwork>,
fetch: F,
eip86_transition: u64,
}
impl<C, M, U, F> ParitySetClient<C, M, U, F> {
impl<C, M, U, F> ParitySetClient<C, M, U, F>
where C: MiningBlockChainClient + 'static,
{
/// Creates new `ParitySetClient` with given `Fetch`.
pub fn new(client: &Arc<C>, miner: &Arc<M>, updater: &Arc<U>, net: &Arc<ManageNetwork>, fetch: F) -> Self {
ParitySetClient {
@@ -50,6 +53,7 @@ impl<C, M, U, F> ParitySetClient<C, M, U, F> {
updater: Arc::downgrade(updater),
net: Arc::downgrade(net),
fetch: fetch,
eip86_transition: client.eip86_transition(),
}
}
}
@@ -175,8 +179,9 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
fn remove_transaction(&self, hash: H256) -> Result<Option<Transaction>, Error> {
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
let block_number = take_weak!(self.client).chain_info().best_block_number;
let hash = hash.into();
Ok(miner.remove_pending_transaction(&*client, &hash).map(Into::into))
Ok(miner.remove_pending_transaction(&*client, &hash).map(|t| Transaction::from_pending(t, block_number, self.eip86_transition)))
}
}

View File

@@ -227,7 +227,7 @@ fn rpc_parity_remove_transaction() {
let hash = signed.hash();
let request = r#"{"jsonrpc": "2.0", "method": "parity_removeTransaction", "params":[""#.to_owned() + &format!("0x{:?}", hash) + r#""], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"condition":null,"creates":null,"from":"0x0000000000000000000000000000000000000002","gas":"0x76c0","gasPrice":"0x9184e72a000","hash":"0x0072c69d780cdfbfc02fed5c7d184151f9a166971d045e55e27695aaa5bcb55e","input":"0x","networkId":null,"nonce":"0x1","publicKey":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","r":"0x0","raw":"0xe9018609184e72a0008276c0940000000000000000000000000000000000000005849184e72a80808080","s":"0x0","standardV":"0x4","to":"0x0000000000000000000000000000000000000005","transactionIndex":null,"v":"0x0","value":"0x9184e72a"},"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"condition":null,"creates":null,"from":"0x0000000000000000000000000000000000000002","gas":"0x76c0","gasPrice":"0x9184e72a000","hash":"0xa2e0da8a8064e0b9f93e95a53c2db6d01280efb8ac72a708d25487e67dd0f8fc","input":"0x","networkId":null,"nonce":"0x1","publicKey":null,"r":"0x1","raw":"0xe9018609184e72a0008276c0940000000000000000000000000000000000000005849184e72a80800101","s":"0x1","standardV":"0x4","to":"0x0000000000000000000000000000000000000005","transactionIndex":null,"v":"0x0","value":"0x9184e72a"},"id":1}"#;
miner.pending_transactions.lock().insert(hash, signed);
assert_eq!(io.handle_request_sync(&request), Some(response.to_owned()));

View File

@@ -304,7 +304,7 @@ fn should_add_sign_transaction_to_the_queue() {
r#""input":"0x","# +
&format!("\"networkId\":{},", t.network_id().map_or("null".to_owned(), |n| format!("{}", n))) +
r#""nonce":"0x1","# +
&format!("\"publicKey\":\"0x{:?}\",", t.public_key()) +
&format!("\"publicKey\":\"0x{:?}\",", t.public_key().unwrap()) +
&format!("\"r\":\"0x{}\",", U256::from(signature.r()).to_hex()) +
&format!("\"raw\":\"0x{}\",", rlp.to_hex()) +
&format!("\"s\":\"0x{}\",", U256::from(signature.s()).to_hex()) +

View File

@@ -16,8 +16,9 @@
use serde::{Serialize, Serializer};
use serde::ser::SerializeStruct;
use util::Hashable;
use ethcore::miner;
use ethcore::contract_address;
use ethcore::{contract_address, CreateContractAddress};
use ethcore::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction};
use v1::helpers::errors;
use v1::types::{Bytes, H160, H256, U256, H512, TransactionCondition};
@@ -158,9 +159,11 @@ pub struct RichRawTransaction {
pub transaction: Transaction
}
impl From<SignedTransaction> for RichRawTransaction {
fn from(t: SignedTransaction) -> Self {
let tx: Transaction = t.into();
// TODO: change transition to 0 when EIP-86 is commonly used.
let tx: Transaction = Transaction::from_signed(t, 0, u64::max_value());
RichRawTransaction {
raw: tx.raw.clone(),
transaction: tx,
@@ -168,9 +171,11 @@ impl From<SignedTransaction> for RichRawTransaction {
}
}
impl From<LocalizedTransaction> for Transaction {
fn from(mut t: LocalizedTransaction) -> Transaction {
impl Transaction {
/// Convert `LocalizedTransaction` into RPC Transaction.
pub fn from_localized(mut t: LocalizedTransaction, eip86_transition: u64) -> Transaction {
let signature = t.signature();
let scheme = if t.block_number >= eip86_transition { CreateContractAddress::FromCodeHash } else { CreateContractAddress::FromSenderAndNonce };
Transaction {
hash: t.hash().into(),
nonce: t.nonce.into(),
@@ -187,7 +192,7 @@ impl From<LocalizedTransaction> for Transaction {
gas: t.gas.into(),
input: Bytes::new(t.data.clone()),
creates: match t.action {
Action::Create => Some(contract_address(&t.sender(), &t.nonce).into()),
Action::Create => Some(contract_address(scheme, &t.sender(), &t.nonce, &t.data.sha3()).into()),
Action::Call(_) => None,
},
raw: ::rlp::encode(&t.signed).to_vec().into(),
@@ -200,11 +205,11 @@ impl From<LocalizedTransaction> for Transaction {
condition: None,
}
}
}
impl From<SignedTransaction> for Transaction {
fn from(t: SignedTransaction) -> Transaction {
/// Convert `SignedTransaction` into RPC Transaction.
pub fn from_signed(t: SignedTransaction, block_number: u64, eip86_transition: u64) -> Transaction {
let signature = t.signature();
let scheme = if block_number >= eip86_transition { CreateContractAddress::FromCodeHash } else { CreateContractAddress::FromSenderAndNonce };
Transaction {
hash: t.hash().into(),
nonce: t.nonce.into(),
@@ -221,11 +226,11 @@ impl From<SignedTransaction> for Transaction {
gas: t.gas.into(),
input: Bytes::new(t.data.clone()),
creates: match t.action {
Action::Create => Some(contract_address(&t.sender(), &t.nonce).into()),
Action::Create => Some(contract_address(scheme, &t.sender(), &t.nonce, &t.data.sha3()).into()),
Action::Call(_) => None,
},
raw: ::rlp::encode(&t).to_vec().into(),
public_key: Some(t.public_key().into()),
public_key: t.public_key().map(Into::into),
network_id: t.network_id(),
standard_v: t.standard_v().into(),
v: t.original_v().into(),
@@ -234,28 +239,28 @@ impl From<SignedTransaction> for Transaction {
condition: None,
}
}
}
impl From<PendingTransaction> for Transaction {
fn from(t: PendingTransaction) -> Transaction {
let mut r = Transaction::from(t.transaction);
/// Convert `PendingTransaction` into RPC Transaction.
pub fn from_pending(t: PendingTransaction, block_number: u64, eip86_transition: u64) -> Transaction {
let mut r = Transaction::from_signed(t.transaction, block_number, eip86_transition);
r.condition = t.condition.map(|b| b.into());
r
}
}
impl From<miner::LocalTransactionStatus> for LocalTransactionStatus {
fn from(s: miner::LocalTransactionStatus) -> Self {
impl LocalTransactionStatus {
/// Convert `LocalTransactionStatus` into RPC `LocalTransactionStatus`.
pub fn from(s: miner::LocalTransactionStatus, block_number: u64, eip86_transition: u64) -> Self {
use ethcore::miner::LocalTransactionStatus::*;
match s {
Pending => LocalTransactionStatus::Pending,
Future => LocalTransactionStatus::Future,
Mined(tx) => LocalTransactionStatus::Mined(tx.into()),
Dropped(tx) => LocalTransactionStatus::Dropped(tx.into()),
Rejected(tx, err) => LocalTransactionStatus::Rejected(tx.into(), errors::transaction_message(err)),
Replaced(tx, gas_price, hash) => LocalTransactionStatus::Replaced(tx.into(), gas_price.into(), hash.into()),
Invalid(tx) => LocalTransactionStatus::Invalid(tx.into()),
Canceled(tx) => LocalTransactionStatus::Canceled(tx.into()),
Mined(tx) => LocalTransactionStatus::Mined(Transaction::from_signed(tx, block_number, eip86_transition)),
Dropped(tx) => LocalTransactionStatus::Dropped(Transaction::from_signed(tx, block_number, eip86_transition)),
Rejected(tx, err) => LocalTransactionStatus::Rejected(Transaction::from_signed(tx, block_number, eip86_transition), errors::transaction_message(err)),
Replaced(tx, gas_price, hash) => LocalTransactionStatus::Replaced(Transaction::from_signed(tx, block_number, eip86_transition), gas_price.into(), hash.into()),
Invalid(tx) => LocalTransactionStatus::Invalid(Transaction::from_signed(tx, block_number, eip86_transition)),
Canceled(tx) => LocalTransactionStatus::Canceled(Transaction::from_pending(tx, block_number, eip86_transition)),
}
}
}