Skip to content

Commit

Permalink
Allow specifying local accounts via CLI
Browse files Browse the repository at this point in the history
 * Add `tx-queue-locals` CLI option
 * ethcore: modify miner to check options vec before importing transaction
 * modify tests (ethcore/parity)
Resolves openethereum#9634
  • Loading branch information
Andrew Plaza authored and insipx committed Dec 31, 2018
1 parent 9136c81 commit 530002d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub struct MinerOptions {
/// will be invalid if mined.
pub infinite_pending_block: bool,

/// Prioritized Local Addresses
pub tx_queue_locals: Vec<Address>,
/// Strategy to use for prioritizing transactions in the queue.
pub tx_queue_strategy: PrioritizationStrategy,
/// Simple senders penalization.
Expand Down Expand Up @@ -163,6 +165,7 @@ impl Default for MinerOptions {
work_queue_size: 20,
enable_resubmission: true,
infinite_pending_block: false,
tx_queue_locals: Vec::new(),
tx_queue_strategy: PrioritizationStrategy::GasPriceOnly,
tx_queue_penalization: Penalization::Disabled,
tx_queue_no_unfamiliar_locals: false,
Expand Down Expand Up @@ -913,11 +916,13 @@ impl miner::MinerService for Miner {
pending: PendingTransaction,
trusted: bool
) -> Result<(), transaction::Error> {
// treat the tx as local if the option is enabled, or if we have the account
// treat the tx as local if the option is enabled, if we have the account, or if
// the acc is specified as local
let sender = pending.sender();
let treat_as_local = trusted
|| !self.options.tx_queue_no_unfamiliar_locals
|| self.accounts.as_ref().map(|accts| accts.has_account(sender)).unwrap_or(false);
|| self.accounts.as_ref().map(|accts| accts.has_account(sender)).unwrap_or(false)
|| self.options.tx_queue_locals.iter().any(|addr| *addr == sender);

if treat_as_local {
self.import_own_transaction(chain, pending)
Expand Down Expand Up @@ -1339,6 +1344,7 @@ mod tests {
enable_resubmission: true,
infinite_pending_block: false,
tx_queue_penalization: Penalization::Disabled,
tx_queue_locals: Vec::new(),
tx_queue_strategy: PrioritizationStrategy::GasPriceOnly,
tx_queue_no_unfamiliar_locals: false,
refuse_service_transactions: false,
Expand Down
7 changes: 7 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ usage! {
"--tx-queue-per-sender=[LIMIT]",
"Maximum number of transactions per sender in the queue. By default it's 1% of the entire queue, but not less than 16.",

ARG arg_tx_queue_locals: (Option<String>) = None, or |c: &Config| c.mining.as_ref()?.tx_queue_locals.as_ref().map(|vec| vec.join(",")),
"--tx-queue-locals=[ACCOUNTS]",
"Specify local accounts for which transactions are prioritized in the queue. ACCOUNTS is a comma-delimited list of addresses.",

ARG arg_tx_queue_strategy: (String) = "gas_price", or |c: &Config| c.mining.as_ref()?.tx_queue_strategy.clone(),
"--tx-queue-strategy=[S]",
"Prioritization strategy used to order transactions in the queue. S may be: gas_price - Prioritize txs with high gas price",
Expand Down Expand Up @@ -1348,6 +1352,7 @@ struct Mining {
tx_queue_size: Option<usize>,
tx_queue_per_sender: Option<usize>,
tx_queue_mem_limit: Option<u32>,
tx_queue_locals: Option<Vec<String>>,
tx_queue_strategy: Option<String>,
tx_queue_ban_count: Option<u16>,
tx_queue_ban_time: Option<u16>,
Expand Down Expand Up @@ -1789,6 +1794,7 @@ mod tests {
arg_tx_queue_size: 8192usize,
arg_tx_queue_per_sender: None,
arg_tx_queue_mem_limit: 4u32,
arg_tx_queue_locals: Some("0xdeadbeefcafe0000000000000000000000000000".into()),
arg_tx_queue_strategy: "gas_factor".into(),
arg_tx_queue_ban_count: Some(1u16),
arg_tx_queue_ban_time: Some(180u16),
Expand Down Expand Up @@ -2062,6 +2068,7 @@ mod tests {
tx_queue_size: Some(8192),
tx_queue_per_sender: None,
tx_queue_mem_limit: None,
tx_queue_locals: None,
tx_queue_strategy: None,
tx_queue_ban_count: None,
tx_queue_ban_time: None,
Expand Down
1 change: 1 addition & 0 deletions parity/cli/tests/config.full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ price_update_period = "hourly"
gas_floor_target = "8000000"
gas_cap = "10000000"
tx_queue_size = 8192
tx_queue_locals = ["0xdeadbeefcafe0000000000000000000000000000"]
tx_queue_strategy = "gas_factor"
tx_queue_ban_count = 1
tx_queue_ban_time = 180 #s
Expand Down
1 change: 1 addition & 0 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ impl Configuration {
infinite_pending_block: self.args.flag_infinite_pending_block,

tx_queue_penalization: to_queue_penalization(self.args.arg_tx_time_limit)?,
tx_queue_locals: to_addresses(&self.args.arg_tx_queue_locals)?,
tx_queue_strategy: to_queue_strategy(&self.args.arg_tx_queue_strategy)?,
tx_queue_no_unfamiliar_locals: self.args.flag_tx_queue_no_unfamiliar_locals,
refuse_service_transactions: self.args.flag_refuse_service_transactions,
Expand Down

0 comments on commit 530002d

Please sign in to comment.