-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement caching for service transactions checker #10088
Changes from 7 commits
234e582
da93f5c
fbe439f
7f56abe
1f9c595
5984a41
16571bc
2bf7312
33c769f
fb74e9d
b2c127d
086cc5b
6cab68f
1ccf28c
0f4df80
cab0989
da776e9
557bd0c
cd38f3b
96e5bba
1863d90
823f383
79131c6
51bbad3
06a4b2d
ec610a3
118002c
6e73d1e
bffd73e
4e7371d
0a97ea2
aba3273
f383cec
fbcf37b
49cdf39
8c2c152
9c41cdc
93955a7
3415776
497b951
04841c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ use header::{BlockNumber, Header, ExtendedHeader}; | |
use io::IoChannel; | ||
use log_entry::LocalizedLogEntry; | ||
use miner::{Miner, MinerService}; | ||
use miner::service_transaction_checker::ServiceTransactionChecker; | ||
use ethcore_miner::pool::VerifiedTransaction; | ||
use parking_lot::{Mutex, RwLock}; | ||
use rand::OsRng; | ||
|
@@ -2112,10 +2113,15 @@ impl BlockChainClient for Client { | |
|
||
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> { | ||
let authoring_params = self.importer.miner.authoring_params(); | ||
let service_transaction_checker = ServiceTransactionChecker::default(); | ||
let gas_price = match service_transaction_checker.check_address(self, address) { | ||
Ok(true) => U256::zero(), | ||
_ => self.importer.miner.sensible_gas_price(), | ||
}; | ||
let transaction = Transaction { | ||
nonce: self.latest_nonce(&authoring_params.author), | ||
action: Action::Call(address), | ||
gas: self.importer.miner.sensible_gas_limit(), | ||
gas: gas_price, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant to change |
||
gas_price: self.importer.miner.sensible_gas_price(), | ||
value: U256::zero(), | ||
data: data, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
//! Keeps track of transactions and currently sealed pending block. | ||
|
||
mod miner; | ||
mod service_transaction_checker; | ||
pub mod service_transaction_checker; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please group with other |
||
|
||
pub mod pool_client; | ||
#[cfg(feature = "stratum")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
use client::{RegistryInfo, CallContract, BlockId}; | ||
use transaction::SignedTransaction; | ||
use ethabi::FunctionOutputDecoder; | ||
use ethereum_types::Address; | ||
|
||
use_contract!(service_transaction, "res/contracts/service_transaction.json"); | ||
|
||
|
@@ -29,7 +30,7 @@ const SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME: &'static str = "service_transa | |
pub struct ServiceTransactionChecker; | ||
|
||
impl ServiceTransactionChecker { | ||
/// Checks if given address is whitelisted to send service transactions. | ||
/// Checks if given address in tx is whitelisted to send service transactions. | ||
pub fn check<C: CallContract + RegistryInfo>(&self, client: &C, tx: &SignedTransaction) -> Result<bool, String> { | ||
let sender = tx.sender(); | ||
let hash = tx.hash(); | ||
|
@@ -48,4 +49,13 @@ impl ServiceTransactionChecker { | |
let value = client.call_contract(BlockId::Latest, address, data)?; | ||
decoder.decode(&value).map_err(|e| e.to_string()) | ||
} | ||
|
||
/// Checks if given address is whitelisted to send service transactions. | ||
pub fn check_address<C: CallContract + RegistryInfo>(&self, client: &C, sender: Address) -> Result<bool, String> { | ||
VladLupashevskyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let contract_address = client.registry_address(SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME.to_owned(), BlockId::Latest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the performance be a concern here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that an issue, some cache would be nice (best would be if previously queried registry entries would be refreshed after a block is imported), but the code is not super hot (only in |
||
.ok_or_else(|| "contract is not configured")?; | ||
let (data, decoder) = service_transaction::functions::certified::call(sender); | ||
let value = client.call_contract(BlockId::Latest, contract_address, data)?; | ||
decoder.decode(&value).map_err(|e| e.to_string()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address
is contract address you try to call, not the sender (which should be checked here).