Skip to content

Commit

Permalink
Implemented a call to reportMalicious with 0 gas price (#59)
Browse files Browse the repository at this point in the history
* Make calls service transactions i.e. zero gas price.

* call reportMalicious with 0 gas price

* call reportBenign with 0 gas price as well
  • Loading branch information
afck authored and DemiMarie committed Jan 23, 2019
1 parent 2f9b727 commit 1795ee0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
12 changes: 7 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2154,15 +2154,17 @@ impl BlockChainClient for Client {
}
}

fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> {
fn transact(&self, action: Action, data: Bytes, gas: Option<U256>, gas_price: Option<U256>)
-> Result<(), transaction::Error>
{
let authoring_params = self.importer.miner.authoring_params();
let transaction = transaction::Transaction {
nonce: self.latest_nonce(&authoring_params.author),
action: Action::Call(address),
gas: self.importer.miner.sensible_gas_limit(),
gas_price: self.importer.miner.sensible_gas_price(),
action,
gas: gas.unwrap_or_else(|| self.importer.miner.sensible_gas_limit()),
gas_price: gas_price.unwrap_or_else(|| self.importer.miner.sensible_gas_price()),
value: U256::zero(),
data: data,
data,
};
let chain_id = self.engine.signing_chain_id(&self.latest_env_info());
let signature = self.engine.sign(transaction.hash(chain_id))
Expand Down
10 changes: 6 additions & 4 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,12 +875,14 @@ impl BlockChainClient for TestBlockChainClient {
}
}

fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> {
fn transact(&self, action: Action, data: Bytes, gas: Option<U256>, gas_price: Option<U256>)
-> Result<(), transaction::Error>
{
let transaction = Transaction {
nonce: self.latest_nonce(&self.miner.authoring_params().author),
action: Action::Call(address),
gas: self.spec.gas_limit,
gas_price: U256::zero(),
action,
gas: gas.unwrap_or(self.spec.gas_limit),
gas_price: gas_price.unwrap_or(U256::zero()),
value: U256::default(),
data: data,
};
Expand Down
10 changes: 9 additions & 1 deletion ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,15 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra
fn pruning_info(&self) -> PruningInfo;

/// Schedule state-altering transaction to be executed on the next pending block.
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error>;
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> {
self.transact(Action::Call(address), data, None, None)
}

/// Schedule state-altering transaction to be executed on the next pending block with the given gas parameters.
///
/// If they are `None`, sensible values are selected automatically.
fn transact(&self, action: Action, data: Bytes, gas: Option<U256>, gas_price: Option<U256>)
-> Result<(), transaction::Error>;

/// Get the address of the registry itself.
fn registrar_address(&self) -> Option<Address>;
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/engines/authority_round/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl RandomnessPhase {

// Schedule the transaction that commits the hash.
let data = aura_random::functions::commit_hash::call(secret_hash);
contract.schedule_call_transaction(data).map_err(PhaseError::TransactionFailed)?;
contract.schedule_service_transaction(data).map_err(PhaseError::TransactionFailed)?;

// Store the newly generated secret.
Ok(Some(secret))
Expand All @@ -210,7 +210,7 @@ impl RandomnessPhase {

// We are now sure that we have the correct secret and can reveal it.
let data = aura_random::functions::reveal_secret::call(secret);
contract.schedule_call_transaction(data).map_err(PhaseError::TransactionFailed)?;
contract.schedule_service_transaction(data).map_err(PhaseError::TransactionFailed)?;

// We still pass back the secret -- if anything fails later down the line, we can
// resume by simply creating another transaction.
Expand Down
10 changes: 5 additions & 5 deletions ethcore/src/engines/authority_round/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use std::fmt;

use ethabi;
use ethereum_types::Address;
use ethereum_types::{Address, U256};

use client::{BlockId, EngineClient};
use transaction;
use transaction::{self, Action};

/// A contract bound to a client and block number.
///
Expand Down Expand Up @@ -79,11 +79,11 @@ impl<'a> BoundContract<'a> {
.map_err(CallError::DecodeFailed)
}

/// Schedules a transaction that calls a contract.
/// Schedules a service transaction (with gas price zero) that calls a contract.
///
/// Causes `client` to schedule a call to the bound contract. The `call` value can be serialized
/// by calling any api function generated by the `use_contract!` macro.
pub fn schedule_call_transaction<D>(&self, call: (ethabi::Bytes, D)) -> Result<(), CallError> {
pub fn schedule_service_transaction<D>(&self, call: (ethabi::Bytes, D)) -> Result<(), CallError> {
// NOTE: The second item of `call` is actually meaningless, since the function will only be
// executed later on when the transaction is processed. For this reason, there is no
// `ethabi::FunctionOutputDecoder` trait bound on it, even though the `use_contract`
Expand All @@ -95,7 +95,7 @@ impl<'a> BoundContract<'a> {
.as_full_client()
.ok_or(CallError::NotFullClient)?;

cl.transact_contract(self.contract_addr, data)
cl.transact(Action::Call(self.contract_addr), data, None, Some(U256::zero()))
.map_err(CallError::TransactionFailed)
}
}
3 changes: 2 additions & 1 deletion ethcore/src/engines/validator_set/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use machine::{AuxiliaryData, Call, EthereumMachine};
use parking_lot::RwLock;
use types::BlockNumber;
use types::header::Header;
use transaction::Action;

use client::EngineClient;

Expand Down Expand Up @@ -58,7 +59,7 @@ impl ValidatorContract {

match client.as_full_client() {
Some(c) => {
c.transact_contract(self.contract_address, data)
c.transact(Action::Call(self.contract_address), data, None, Some(0.into()))
.map_err(|e| format!("Transaction import error: {}", e))?;
Ok(())
},
Expand Down
1 change: 0 additions & 1 deletion ethcore/src/engines/validator_set/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use heapsize::HeapSizeOf;
use types::BlockNumber;
use types::header::Header;

use error::Error;
use machine::{AuxiliaryData, Call, EthereumMachine};
use super::{ValidatorSet, SimpleList};

Expand Down

0 comments on commit 1795ee0

Please sign in to comment.