Skip to content

Commit

Permalink
Make calls service transactions i.e. zero gas price.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Jan 9, 2019
1 parent 4e7e838 commit 72c70c7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
12 changes: 7 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,15 +2110,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 {
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 @@ -859,12 +859,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
12 changes: 10 additions & 2 deletions ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use header::{BlockNumber};
use log_entry::LocalizedLogEntry;
use receipt::LocalizedReceipt;
use trace::LocalizedTrace;
use transaction::{self, LocalizedTransaction, SignedTransaction};
use transaction::{self, LocalizedTransaction, SignedTransaction, Action};
use verification::queue::QueueInfo as BlockQueueInfo;
use verification::queue::kind::blocks::Unverified;
use state::StateInfo;
Expand Down Expand Up @@ -388,7 +388,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 @@ -198,7 +198,7 @@ impl RandomnessPhase {

// Schedule the transaction that commits the hash.
contract
.schedule_call_transaction(aura_random::functions::commit_hash::call(
.schedule_service_transaction(aura_random::functions::commit_hash::call(
secret_hash,
signature,
))
Expand All @@ -224,7 +224,7 @@ impl RandomnessPhase {
let signature: Bytes =
signer.sign(secret.into()).map_err(PhaseError::Sign)?.as_ref().into();
contract
.schedule_call_transaction(aura_random::functions::reveal_secret::call(
.schedule_service_transaction(aura_random::functions::reveal_secret::call(
secret, signature,
))
.map_err(PhaseError::TransactionFailed)?;
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 @@ -78,11 +78,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 @@ -94,7 +94,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)
}
}

0 comments on commit 72c70c7

Please sign in to comment.