Additional logging for transactions

This commit is contained in:
Tomasz Drwięga
2016-04-17 18:26:15 +02:00
parent 5547b44e5a
commit 5086880093
6 changed files with 58 additions and 17 deletions

View File

@@ -182,24 +182,30 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
fn dispatch_transaction(&self, signed_transaction: SignedTransaction) -> Result<Value, Error> {
let hash = signed_transaction.hash();
let import = {
let (import, status) = {
let client = take_weak!(self.client);
let miner = take_weak!(self.miner);
miner.import_transactions(vec![signed_transaction], |a: &Address| {
let import = miner.import_own_transaction(signed_transaction, |a: &Address| {
AccountDetails {
nonce: client.nonce(&a),
balance: client.balance(&a),
}
})
});
let status_after = miner.status();
(import, status_after)
};
match import.into_iter().collect::<Result<Vec<_>, _>>() {
Ok(_) => {
match import {
Ok(res) => {
trace!(target: "tx", "Imported transaction to {:?} (hash: {:?})", res, hash);
trace!(target: "tx", "Status: {:?}", status);
to_value(&hash)
}
Err(e) => {
warn!("Error sending transaction: {:?}", e);
trace!(target: "tx", "Failed to import transaction {:?} (hash: {:?})", e, hash);
trace!(target: "tx", "Status: {:?}", status);
to_value(&H256::zero())
}
}

View File

@@ -22,7 +22,7 @@ use ethcore::error::Error;
use ethcore::client::BlockChainClient;
use ethcore::block::ClosedBlock;
use ethcore::transaction::SignedTransaction;
use ethminer::{MinerService, MinerStatus, AccountDetails};
use ethminer::{MinerService, MinerStatus, AccountDetails, TransactionImportResult};
/// Test miner service.
pub struct TestMinerService {
@@ -101,17 +101,28 @@ impl MinerService for TestMinerService {
}
/// Imports transactions to transaction queue.
fn import_transactions<T>(&self, transactions: Vec<SignedTransaction>, _fetch_account: T) -> Vec<Result<(), Error>>
fn import_transactions<T>(&self, transactions: Vec<SignedTransaction>, _fetch_account: T) ->
Vec<Result<TransactionImportResult, Error>>
where T: Fn(&Address) -> AccountDetails {
// lets assume that all txs are valid
self.imported_transactions.lock().unwrap().extend_from_slice(&transactions);
transactions
.iter()
.map(|_| Ok(()))
.map(|_| Ok(TransactionImportResult::Current))
.collect()
}
/// Imports transactions to transaction queue.
fn import_own_transaction<T>(&self, transaction: SignedTransaction, _fetch_account: T) ->
Result<TransactionImportResult, Error>
where T: Fn(&Address) -> AccountDetails {
// lets assume that all txs are valid
self.imported_transactions.lock().unwrap().push(transaction);
Ok(TransactionImportResult::Current)
}
/// Returns hashes of transactions currently in pending
fn pending_transactions_hashes(&self) -> Vec<H256> {
vec![]