Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Added checking tx-type using transactions permission contract for miners #7359

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ pub fn get_temp_state_db() -> GuardedTempResult<StateDB> {
}

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)
}
Expand Down
3 changes: 3 additions & 0 deletions ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 22 additions & 1 deletion ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess open_block's parent state always has to be available in the client, so this is fine.

Err(Error::Transaction(TransactionError::NotAllowed)) => {
Err(TransactionError::NotAllowed.into())
}
_ => {
open_block.push_transaction(tx, None)
}
};
let took = start.elapsed();

// Check for heavy transactions
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions ethcore/src/miner/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ pub enum RemovalReason {
Invalid,
/// Transaction was canceled
Canceled,
/// Transaction is not allowed,
NotAllowed,
}

/// Point in time when transaction was inserted.
Expand Down Expand Up @@ -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)
),
Expand Down