From 6aba887f058fe853e74cf97cbb6311ad87173236 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Sat, 24 Nov 2018 01:41:56 -0500 Subject: [PATCH] Allow specifying local accounts via CLI * Add `tx-queue-locals` CLI option * ethcore: modify miner to check options vec before importing transaction * modify tests (ethcore/parity) Resolves #9634 --- ethcore/src/miner/miner.rs | 10 ++++++++-- parity/cli/mod.rs | 7 +++++++ parity/cli/tests/config.full.toml | 1 + parity/configuration.rs | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 39dac1f2b21..242c000f4f5 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -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
, /// Strategy to use for prioritizing transactions in the queue. pub tx_queue_strategy: PrioritizationStrategy, /// Simple senders penalization. @@ -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, @@ -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) @@ -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, diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index cc7e1d4ce71..daee1a11150 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -745,6 +745,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) = 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", @@ -1331,6 +1335,7 @@ struct Mining { tx_queue_size: Option, tx_queue_per_sender: Option, tx_queue_mem_limit: Option, + tx_queue_locals: Option>, tx_queue_strategy: Option, tx_queue_ban_count: Option, tx_queue_ban_time: Option, @@ -1768,6 +1773,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), @@ -2037,6 +2043,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, diff --git a/parity/cli/tests/config.full.toml b/parity/cli/tests/config.full.toml index 8bf97cac6e1..6b93b22affd 100644 --- a/parity/cli/tests/config.full.toml +++ b/parity/cli/tests/config.full.toml @@ -128,6 +128,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 diff --git a/parity/configuration.rs b/parity/configuration.rs index 6bc90ec5629..6f5ca2c18c8 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -555,6 +555,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,