Fix up the pending set stuff.
This commit is contained in:
parent
1667808ecb
commit
2a51a30d41
@ -792,8 +792,8 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
self.miner.all_transactions()
|
self.miner.pending_transactions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn queue_transactions(&self, transactions: Vec<Bytes>);
|
fn queue_transactions(&self, transactions: Vec<Bytes>);
|
||||||
|
|
||||||
/// list all transactions
|
/// list all transactions
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction>;
|
fn pending_transactions(&self) -> Vec<SignedTransaction>;
|
||||||
|
|
||||||
/// Get the gas price distribution.
|
/// Get the gas price distribution.
|
||||||
fn gas_price_statistics(&self, sample_size: usize, distribution_size: usize) -> Result<Vec<U256>, ()> {
|
fn gas_price_statistics(&self, sample_size: usize, distribution_size: usize) -> Result<Vec<U256>, ()> {
|
||||||
|
@ -500,7 +500,7 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
self.import_transactions(tx);
|
self.import_transactions(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
self.miner.all_transactions()
|
self.miner.pending_transactions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,18 @@ use spec::Spec;
|
|||||||
use engine::Engine;
|
use engine::Engine;
|
||||||
use miner::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
use miner::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
||||||
|
|
||||||
|
/// Different possible definitions for pending transaction set.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum PendingSet {
|
||||||
|
/// Always just the transactions in the queue. These have had only cheap checks.
|
||||||
|
AlwaysQueue,
|
||||||
|
/// Always just the transactions in the sealing block. These have had full checks but
|
||||||
|
/// may be empty if the node is not actively mining or has force_sealing enabled.
|
||||||
|
AlwaysSealing,
|
||||||
|
/// Try the sealing block, but if it is not currently sealing, fallback to the queue.
|
||||||
|
SealingOrElseQueue,
|
||||||
|
}
|
||||||
|
|
||||||
/// Configures the behaviour of the miner.
|
/// Configures the behaviour of the miner.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MinerOptions {
|
pub struct MinerOptions {
|
||||||
@ -42,7 +54,7 @@ pub struct MinerOptions {
|
|||||||
/// If `None`, then no limit.
|
/// If `None`, then no limit.
|
||||||
pub max_tx_gas: Option<U256>,
|
pub max_tx_gas: Option<U256>,
|
||||||
/// Whether we should fallback to providing all the queue's transactions or just pending.
|
/// Whether we should fallback to providing all the queue's transactions or just pending.
|
||||||
pub strict_valid_pending: bool,
|
pub pending_set: PendingSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MinerOptions {
|
impl Default for MinerOptions {
|
||||||
@ -52,7 +64,7 @@ impl Default for MinerOptions {
|
|||||||
reseal_on_external_tx: true,
|
reseal_on_external_tx: true,
|
||||||
reseal_on_own_tx: true,
|
reseal_on_own_tx: true,
|
||||||
max_tx_gas: None,
|
max_tx_gas: None,
|
||||||
strict_valid_pending: false,
|
pending_set: PendingSet::AlwaysQueue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,24 +474,6 @@ impl MinerService for Miner {
|
|||||||
imported
|
imported
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
|
||||||
let queue = self.transaction_queue.lock().unwrap();
|
|
||||||
match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) {
|
|
||||||
(true, Some(pending)) => pending.transactions().iter().map(|t| t.hash()).collect(),
|
|
||||||
_ if self.options.strict_valid_pending => Vec::new(),
|
|
||||||
_ => queue.pending_hashes(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
|
||||||
let queue = self.transaction_queue.lock().unwrap();
|
|
||||||
match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) {
|
|
||||||
(true, Some(pending)) => pending.transactions().iter().find(|t| &t.hash() == hash).cloned(),
|
|
||||||
_ if self.options.strict_valid_pending => None,
|
|
||||||
_ => queue.find(hash),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
let queue = self.transaction_queue.lock().unwrap();
|
let queue = self.transaction_queue.lock().unwrap();
|
||||||
queue.top_transactions()
|
queue.top_transactions()
|
||||||
@ -487,11 +481,41 @@ impl MinerService for Miner {
|
|||||||
|
|
||||||
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
let queue = self.transaction_queue.lock().unwrap();
|
let queue = self.transaction_queue.lock().unwrap();
|
||||||
|
let sw = self.sealing_work.lock().unwrap();
|
||||||
// TODO: should only use the sealing_work when it's current (it could be an old block)
|
// TODO: should only use the sealing_work when it's current (it could be an old block)
|
||||||
match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) {
|
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||||
(true, Some(pending)) => pending.transactions().clone(),
|
true => sw.peek_last_ref(),
|
||||||
_ if self.options.strict_valid_pending => Vec::new(),
|
false => None,
|
||||||
_ => queue.top_transactions(),
|
};
|
||||||
|
match (&self.options.pending_set, sealing_set) {
|
||||||
|
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.top_transactions(),
|
||||||
|
(_, sealing) => sealing.map(|s| s.transactions().clone()).unwrap_or(Vec::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
||||||
|
let queue = self.transaction_queue.lock().unwrap();
|
||||||
|
let sw = self.sealing_work.lock().unwrap();
|
||||||
|
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||||
|
true => sw.peek_last_ref(),
|
||||||
|
false => None,
|
||||||
|
};
|
||||||
|
match (&self.options.pending_set, sealing_set) {
|
||||||
|
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.pending_hashes(),
|
||||||
|
(_, sealing) => sealing.map(|s| s.transactions().iter().map(|t| t.hash()).collect()).unwrap_or(Vec::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
||||||
|
let queue = self.transaction_queue.lock().unwrap();
|
||||||
|
let sw = self.sealing_work.lock().unwrap();
|
||||||
|
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||||
|
true => sw.peek_last_ref(),
|
||||||
|
false => None,
|
||||||
|
};
|
||||||
|
match (&self.options.pending_set, sealing_set) {
|
||||||
|
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.find(hash),
|
||||||
|
(_, sealing) => sealing.and_then(|s| s.transactions().iter().find(|t| &t.hash() == hash).cloned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ mod external;
|
|||||||
mod transaction_queue;
|
mod transaction_queue;
|
||||||
|
|
||||||
pub use self::transaction_queue::{TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
pub use self::transaction_queue::{TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
||||||
pub use self::miner::{Miner, MinerOptions};
|
pub use self::miner::{Miner, MinerOptions, PendingSet};
|
||||||
pub use self::external::{ExternalMiner, ExternalMinerService};
|
pub use self::external::{ExternalMiner, ExternalMinerService};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -141,9 +141,14 @@ Sealing/Mining Options:
|
|||||||
all - reseal on all new transactions [default: all].
|
all - reseal on all new transactions [default: all].
|
||||||
--max-tx-gas GAS Apply a limit of GAS as the maximum amount of gas
|
--max-tx-gas GAS Apply a limit of GAS as the maximum amount of gas
|
||||||
a single transaction may have for it to be mined.
|
a single transaction may have for it to be mined.
|
||||||
--relay-validity REQ Requirements for relaying. REQ may be:
|
--relay-set SET Set of transactions to relay. SET may be:
|
||||||
cheap - Relay only after cheap checks;
|
cheap - Relay any transaction in the queue (this
|
||||||
strict - Relay only once executed [default: cheap].
|
may include invalid transactions);
|
||||||
|
strict - Relay only executed transactions (this
|
||||||
|
guarantees we don't relay invalid transactions, but
|
||||||
|
means we relay nothing if not mining);
|
||||||
|
lenient - Same as struct when mining, and cheap
|
||||||
|
when not [default: cheap].
|
||||||
--usd-per-tx USD Amount of USD to be paid for a basic transaction
|
--usd-per-tx USD Amount of USD to be paid for a basic transaction
|
||||||
[default: 0.005]. The minimum gas price is set
|
[default: 0.005]. The minimum gas price is set
|
||||||
accordingly.
|
accordingly.
|
||||||
@ -296,7 +301,7 @@ pub struct Args {
|
|||||||
pub flag_force_sealing: bool,
|
pub flag_force_sealing: bool,
|
||||||
pub flag_reseal_on_txs: String,
|
pub flag_reseal_on_txs: String,
|
||||||
pub flag_max_tx_gas: Option<String>,
|
pub flag_max_tx_gas: Option<String>,
|
||||||
pub flag_relay_validity: String,
|
pub flag_relay_set: String,
|
||||||
pub flag_author: Option<String>,
|
pub flag_author: Option<String>,
|
||||||
pub flag_usd_per_tx: String,
|
pub flag_usd_per_tx: String,
|
||||||
pub flag_usd_per_eth: String,
|
pub flag_usd_per_eth: String,
|
||||||
|
@ -27,7 +27,7 @@ use util::*;
|
|||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use util::network_settings::NetworkSettings;
|
use util::network_settings::NetworkSettings;
|
||||||
use ethcore::client::{append_path, get_db_path, ClientConfig, Switch, VMType};
|
use ethcore::client::{append_path, get_db_path, ClientConfig, Switch, VMType};
|
||||||
use ethcore::miner::MinerOptions;
|
use ethcore::miner::{MinerOptions, PendingSet};
|
||||||
use ethcore::ethereum;
|
use ethcore::ethereum;
|
||||||
use ethcore::spec::Spec;
|
use ethcore::spec::Spec;
|
||||||
use ethsync::SyncConfig;
|
use ethsync::SyncConfig;
|
||||||
@ -89,10 +89,11 @@ impl Configuration {
|
|||||||
reseal_on_external_tx: ext,
|
reseal_on_external_tx: ext,
|
||||||
reseal_on_own_tx: own,
|
reseal_on_own_tx: own,
|
||||||
max_tx_gas: self.args.flag_max_tx_gas.as_ref().map(|d| Self::decode_u256(d, "--max-tx-gas")),
|
max_tx_gas: self.args.flag_max_tx_gas.as_ref().map(|d| Self::decode_u256(d, "--max-tx-gas")),
|
||||||
strict_valid_pending: match self.args.flag_relay_validity.as_str() {
|
pending_set: match self.args.flag_relay_set.as_str() {
|
||||||
"cheap" => false,
|
"cheap" => PendingSet::AlwaysQueue,
|
||||||
"strict" => true,
|
"strict" => PendingSet::AlwaysSealing,
|
||||||
x => die!("{}: Invalid value for --relay-validity option. Use --help for more information.", x)
|
"lenient" => PendingSet::SealingOrElseQueue,
|
||||||
|
x => die!("{}: Invalid value for --relay-set option. Use --help for more information.", x)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1314,7 +1314,7 @@ impl ChainSync {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut transactions = io.chain().all_transactions();
|
let mut transactions = io.chain().pending_transactions();
|
||||||
if transactions.is_empty() {
|
if transactions.is_empty() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user