Additional logging for transactions
This commit is contained in:
parent
5547b44e5a
commit
5086880093
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -274,7 +274,6 @@ name = "ethcore-ipc-codegen"
|
|||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aster 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aster 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethcore-ipc 1.1.0",
|
|
||||||
"quasi 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quasi 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quasi_codegen 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quasi_codegen 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syntex 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syntex 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -101,7 +101,13 @@ pub trait MinerService : Send + Sync {
|
|||||||
fn set_gas_floor_target(&self, target: U256);
|
fn set_gas_floor_target(&self, target: U256);
|
||||||
|
|
||||||
/// Imports transactions to transaction queue.
|
/// 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;
|
||||||
|
|
||||||
|
/// Imports own (node owner) transaction to queue.
|
||||||
|
fn import_own_transaction<T>(&self, transaction: SignedTransaction, fetch_account: T) ->
|
||||||
|
Result<TransactionImportResult, Error>
|
||||||
where T: Fn(&Address) -> AccountDetails;
|
where T: Fn(&Address) -> AccountDetails;
|
||||||
|
|
||||||
/// Returns hashes of transactions currently in pending
|
/// Returns hashes of transactions currently in pending
|
||||||
@ -139,7 +145,17 @@ pub trait MinerService : Send + Sync {
|
|||||||
fn sensible_gas_limit(&self) -> U256 { x!(21000) }
|
fn sensible_gas_limit(&self) -> U256 { x!(21000) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents the result of importing transaction.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum TransactionImportResult {
|
||||||
|
/// Transaction was imported to current queue.
|
||||||
|
Current,
|
||||||
|
/// Transaction was imported to future queue.
|
||||||
|
Future
|
||||||
|
}
|
||||||
|
|
||||||
/// Mining status
|
/// Mining status
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct MinerStatus {
|
pub struct MinerStatus {
|
||||||
/// Number of transactions in queue with state `pending` (ready to be included in block)
|
/// Number of transactions in queue with state `pending` (ready to be included in block)
|
||||||
pub transactions_in_pending_queue: usize,
|
pub transactions_in_pending_queue: usize,
|
||||||
|
@ -23,7 +23,7 @@ use ethcore::client::{BlockChainClient, BlockId};
|
|||||||
use ethcore::block::{ClosedBlock, IsBlock};
|
use ethcore::block::{ClosedBlock, IsBlock};
|
||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails};
|
use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult};
|
||||||
|
|
||||||
/// Keeps track of transactions using priority queue and holds currently mined block.
|
/// Keeps track of transactions using priority queue and holds currently mined block.
|
||||||
pub struct Miner {
|
pub struct Miner {
|
||||||
@ -220,12 +220,20 @@ impl MinerService for Miner {
|
|||||||
*self.gas_floor_target.read().unwrap()
|
*self.gas_floor_target.read().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||||
transaction_queue.add_all(transactions, fetch_account)
|
transaction_queue.add_all(transactions, fetch_account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import_own_transaction<T>(&self, transaction: SignedTransaction, fetch_account: T) ->
|
||||||
|
Result<TransactionImportResult, Error>
|
||||||
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
|
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||||
|
transaction_queue.add(transaction, &fetch_account)
|
||||||
|
}
|
||||||
|
|
||||||
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
||||||
let transaction_queue = self.transaction_queue.lock().unwrap();
|
let transaction_queue = self.transaction_queue.lock().unwrap();
|
||||||
transaction_queue.pending_hashes()
|
transaction_queue.pending_hashes()
|
||||||
|
@ -92,6 +92,7 @@ use util::hash::{Address, H256};
|
|||||||
use util::table::*;
|
use util::table::*;
|
||||||
use ethcore::transaction::*;
|
use ethcore::transaction::*;
|
||||||
use ethcore::error::{Error, TransactionError};
|
use ethcore::error::{Error, TransactionError};
|
||||||
|
use super::TransactionImportResult;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -346,7 +347,7 @@ impl TransactionQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds all signed transactions to queue to be verified and imported
|
/// Adds all signed transactions to queue to be verified and imported
|
||||||
pub fn add_all<T>(&mut self, txs: Vec<SignedTransaction>, fetch_account: T) -> Vec<Result<(), Error>>
|
pub fn add_all<T>(&mut self, txs: Vec<SignedTransaction>, fetch_account: T) -> Vec<Result<TransactionImportResult, Error>>
|
||||||
where T: Fn(&Address) -> AccountDetails {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
|
|
||||||
txs.into_iter()
|
txs.into_iter()
|
||||||
@ -355,7 +356,7 @@ impl TransactionQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add signed transaction to queue to be verified and imported
|
/// Add signed transaction to queue to be verified and imported
|
||||||
pub fn add<T>(&mut self, tx: SignedTransaction, fetch_account: &T) -> Result<(), Error>
|
pub fn add<T>(&mut self, tx: SignedTransaction, fetch_account: &T) -> Result<TransactionImportResult, Error>
|
||||||
where T: Fn(&Address) -> AccountDetails {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
|
|
||||||
trace!(target: "miner", "Importing: {:?}", tx.hash());
|
trace!(target: "miner", "Importing: {:?}", tx.hash());
|
||||||
@ -568,7 +569,7 @@ impl TransactionQueue {
|
|||||||
/// iff `(address, nonce)` is the same but `gas_price` is higher.
|
/// iff `(address, nonce)` is the same but `gas_price` is higher.
|
||||||
///
|
///
|
||||||
/// Returns `true` when transaction was imported successfuly
|
/// Returns `true` when transaction was imported successfuly
|
||||||
fn import_tx(&mut self, tx: VerifiedTransaction, state_nonce: U256) -> Result<(), TransactionError> {
|
fn import_tx(&mut self, tx: VerifiedTransaction, state_nonce: U256) -> Result<TransactionImportResult, TransactionError> {
|
||||||
|
|
||||||
if self.by_hash.get(&tx.hash()).is_some() {
|
if self.by_hash.get(&tx.hash()).is_some() {
|
||||||
// Transaction is already imported.
|
// Transaction is already imported.
|
||||||
@ -590,7 +591,7 @@ impl TransactionQueue {
|
|||||||
// We have a gap - put to future
|
// We have a gap - put to future
|
||||||
Self::replace_transaction(tx, next_nonce, &mut self.future, &mut self.by_hash);
|
Self::replace_transaction(tx, next_nonce, &mut self.future, &mut self.by_hash);
|
||||||
self.future.enforce_limit(&mut self.by_hash);
|
self.future.enforce_limit(&mut self.by_hash);
|
||||||
return Ok(());
|
return Ok(TransactionImportResult::Future);
|
||||||
} else if nonce < state_nonce {
|
} else if nonce < state_nonce {
|
||||||
// Droping transaction
|
// Droping transaction
|
||||||
trace!(target: "miner", "Dropping old transaction: {:?} (nonce: {} < {})", tx.hash(), nonce, next_nonce);
|
trace!(target: "miner", "Dropping old transaction: {:?} (nonce: {} < {})", tx.hash(), nonce, next_nonce);
|
||||||
@ -615,7 +616,7 @@ impl TransactionQueue {
|
|||||||
self.current.enforce_limit(&mut self.by_hash);
|
self.current.enforce_limit(&mut self.by_hash);
|
||||||
|
|
||||||
trace!(target: "miner", "status: {:?}", self.status());
|
trace!(target: "miner", "status: {:?}", self.status());
|
||||||
Ok(())
|
Ok(TransactionImportResult::Current)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces transaction in given set (could be `future` or `current`).
|
/// Replaces transaction in given set (could be `future` or `current`).
|
||||||
|
@ -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> {
|
fn dispatch_transaction(&self, signed_transaction: SignedTransaction) -> Result<Value, Error> {
|
||||||
let hash = signed_transaction.hash();
|
let hash = signed_transaction.hash();
|
||||||
|
|
||||||
let import = {
|
let (import, status) = {
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
let miner = take_weak!(self.miner);
|
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 {
|
AccountDetails {
|
||||||
nonce: client.nonce(&a),
|
nonce: client.nonce(&a),
|
||||||
balance: client.balance(&a),
|
balance: client.balance(&a),
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
let status_after = miner.status();
|
||||||
|
(import, status_after)
|
||||||
};
|
};
|
||||||
|
|
||||||
match import.into_iter().collect::<Result<Vec<_>, _>>() {
|
match import {
|
||||||
Ok(_) => {
|
Ok(res) => {
|
||||||
|
trace!(target: "tx", "Imported transaction to {:?} (hash: {:?})", res, hash);
|
||||||
|
trace!(target: "tx", "Status: {:?}", status);
|
||||||
to_value(&hash)
|
to_value(&hash)
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error sending transaction: {:?}", 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())
|
to_value(&H256::zero())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ use ethcore::error::Error;
|
|||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::BlockChainClient;
|
||||||
use ethcore::block::ClosedBlock;
|
use ethcore::block::ClosedBlock;
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use ethminer::{MinerService, MinerStatus, AccountDetails};
|
use ethminer::{MinerService, MinerStatus, AccountDetails, TransactionImportResult};
|
||||||
|
|
||||||
/// Test miner service.
|
/// Test miner service.
|
||||||
pub struct TestMinerService {
|
pub struct TestMinerService {
|
||||||
@ -101,17 +101,28 @@ impl MinerService for TestMinerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Imports transactions to transaction queue.
|
/// 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 {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
// lets assume that all txs are valid
|
// lets assume that all txs are valid
|
||||||
self.imported_transactions.lock().unwrap().extend_from_slice(&transactions);
|
self.imported_transactions.lock().unwrap().extend_from_slice(&transactions);
|
||||||
|
|
||||||
transactions
|
transactions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|_| Ok(()))
|
.map(|_| Ok(TransactionImportResult::Current))
|
||||||
.collect()
|
.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
|
/// Returns hashes of transactions currently in pending
|
||||||
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
||||||
vec![]
|
vec![]
|
||||||
|
Loading…
Reference in New Issue
Block a user