diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index ade0844ec..6bb445399 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1840,6 +1840,8 @@ impl BlockChainClient for Client { } impl MiningBlockChainClient for Client { + fn as_block_chain_client(&self) -> &BlockChainClient { self } + fn latest_schedule(&self) -> Schedule { self.engine.schedule(self.latest_env_info().number) } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index d06f94768..cc2f08bab 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -365,6 +365,8 @@ pub fn get_temp_state_db() -> GuardedTempResult { } impl MiningBlockChainClient for TestBlockChainClient { + fn as_block_chain_client(&self) -> &BlockChainClient { self } + fn latest_schedule(&self) -> Schedule { Schedule::new_post_eip150(24576, true, true, true) } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 3ff60baf9..58a05e4e0 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -308,6 +308,9 @@ pub trait MiningBlockChainClient: BlockChainClient { /// Returns latest schedule. fn latest_schedule(&self) -> Schedule; + + /// Returns base of this trait + fn as_block_chain_client(&self) -> &BlockChainClient; } /// Client facilities used by internally sealing Engines. diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index df82a926c..16d3e94d4 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -410,6 +410,7 @@ impl Miner { }; let mut invalid_transactions = HashSet::new(); + let mut non_allowed_transactions = HashSet::new(); let mut transactions_to_penalize = HashSet::new(); let block_number = open_block.block().fields().header.number(); @@ -418,7 +419,15 @@ impl Miner { for tx in transactions { let hash = tx.hash(); let start = Instant::now(); - let result = open_block.push_transaction(tx, None); + // Check whether transaction type is allowed for sender + let result = match self.engine.machine().verify_transaction(&tx, open_block.header(), chain.as_block_chain_client()) { + Err(Error::Transaction(TransactionError::NotAllowed)) => { + Err(TransactionError::NotAllowed.into()) + } + _ => { + open_block.push_transaction(tx, None) + } + }; let took = start.elapsed(); // Check for heavy transactions @@ -459,6 +468,12 @@ impl Miner { }, // already have transaction - ignore Err(Error::Transaction(TransactionError::AlreadyImported)) => {}, + Err(Error::Transaction(TransactionError::NotAllowed)) => { + non_allowed_transactions.insert(hash); + debug!(target: "miner", + "Skipping non-allowed transaction for sender {:?}", + hash); + }, Err(e) => { invalid_transactions.insert(hash); debug!(target: "miner", @@ -481,6 +496,9 @@ impl Miner { for hash in invalid_transactions { queue.remove(&hash, &fetch_nonce, RemovalReason::Invalid); } + for hash in non_allowed_transactions { + queue.remove(&hash, &fetch_nonce, RemovalReason::NotAllowed); + } for hash in transactions_to_penalize { queue.penalize(&hash); } @@ -679,6 +697,9 @@ impl Miner { Err(e) }, Ok(transaction) => { + // This check goes here because verify_transaction takes SignedTransaction parameter + self.engine.machine().verify_transaction(&transaction, &best_block_header, client.as_block_chain_client())?; + let origin = self.accounts.as_ref().and_then(|accounts| { match accounts.has_account(transaction.sender()).unwrap_or(false) { true => Some(TransactionOrigin::Local), diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index f553e187e..efc2b4f03 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -543,6 +543,8 @@ pub enum RemovalReason { Invalid, /// Transaction was canceled Canceled, + /// Transaction is not allowed, + NotAllowed, } /// Point in time when transaction was inserted. @@ -1012,6 +1014,9 @@ impl TransactionQueue { RemovalReason::Invalid => self.local_transactions.mark_invalid( transaction.transaction.into() ), + RemovalReason::NotAllowed => self.local_transactions.mark_invalid( + transaction.transaction.into() + ), RemovalReason::Canceled => self.local_transactions.mark_canceled( PendingTransaction::new(transaction.transaction, transaction.condition) ),