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

Implement caching for service transactions checker #10088

Merged
merged 41 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
234e582
Tx permission contract improvement
VladLupashevskyi Apr 13, 2018
da93f5c
Merge remote-tracking branch 'upstream/master'
VladLupashevskyi Jun 1, 2018
fbe439f
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Jun 2, 2018
7f56abe
Merge remote-tracking branch 'remotes/upstream/master'
VladLupashevskyi Jul 10, 2018
1f9c595
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Nov 14, 2018
5984a41
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Dec 19, 2018
16571bc
Take in account zero gas price certification when doing transact_cont…
VladLupashevskyi Dec 19, 2018
2bf7312
DRY in ServiceTransactionChecker
VladLupashevskyi Jan 9, 2019
33c769f
Fix typos and regroup mod
VladLupashevskyi Jan 9, 2019
fb74e9d
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Jan 9, 2019
b2c127d
Introduce CertifiedAddressesCache
VladLupashevskyi Jan 21, 2019
086cc5b
Introduce refresh_cache for CertifiedAddressesCache
VladLupashevskyi Jan 21, 2019
6cab68f
Add CertifiedAddressesCache read and write on checking
VladLupashevskyi Jan 21, 2019
1ccf28c
Refresh CertifiedAddressesCache on new imported block
VladLupashevskyi Jan 21, 2019
0f4df80
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Jan 21, 2019
cab0989
Separate ChainInfo trait and fix errors after merge
VladLupashevskyi Jan 21, 2019
da776e9
Do not fire an error when service txes contract does not exist
VladLupashevskyi Jan 21, 2019
557bd0c
WIP: Shared certified addresses cache between miner and client + use …
VladLupashevskyi Jan 22, 2019
cd38f3b
Refactor refresh_cache for ServiceTransactionChecker
VladLupashevskyi Jan 22, 2019
96e5bba
Refresh cache fixes
VladLupashevskyi Jan 22, 2019
1863d90
Add cache read in check_address + log when cache is used + improve code
VladLupashevskyi Jan 22, 2019
823f383
Remove ChainInfo from ServiceTransaction dependencies
VladLupashevskyi Jan 22, 2019
79131c6
DRY ServiceTransactionChecker
VladLupashevskyi Jan 22, 2019
51bbad3
Fix Client and Miner in tests
VladLupashevskyi Jan 23, 2019
06a4b2d
Fix node_filter test
VladLupashevskyi Jan 23, 2019
ec610a3
Fix Client::new in add_peer_with_private_config
VladLupashevskyi Jan 23, 2019
118002c
Merge branch 'master' of https://github.com/paritytech/parity
VladLupashevskyi Jan 26, 2019
6e73d1e
WIP: Separated ChainNotify from ethcore trait and implemented ChainNo…
VladLupashevskyi Jan 27, 2019
bffd73e
Fix watcher test
VladLupashevskyi Jan 28, 2019
4e7371d
Merge branch 'master' into master
VladLupashevskyi Jan 28, 2019
0a97ea2
Revert "Merge branch 'master' into master"
VladLupashevskyi Feb 5, 2019
aba3273
Revert "Fix watcher test"
VladLupashevskyi Feb 5, 2019
f383cec
Revert "WIP: Separated ChainNotify from ethcore trait and implemented…
VladLupashevskyi Feb 5, 2019
fbcf37b
Revert "Fix Client::new in add_peer_with_private_config"
VladLupashevskyi Feb 5, 2019
49cdf39
Revert "Fix node_filter test"
VladLupashevskyi Feb 5, 2019
8c2c152
Revert "Fix Client and Miner in tests"
VladLupashevskyi Feb 5, 2019
9c41cdc
Implement ServiceTransactionChecker in miner and delegate it to clien…
VladLupashevskyi Feb 5, 2019
93955a7
Merge master
VladLupashevskyi Feb 5, 2019
3415776
Code improvements
VladLupashevskyi Feb 7, 2019
497b951
Merge branch 'master' of https://github.com/paritytech/parity-ethereum
VladLupashevskyi Feb 7, 2019
04841c6
Merge branch 'master' of https://github.com/paritytech/parity-ethereum
VladLupashevskyi Feb 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ members = [
"parity-clib",
"whisper/cli",
]

[patch.crates-io]
heapsize = { git = "https://github.com/cheme/heapsize.git", branch = "ec-macfix" }
2 changes: 1 addition & 1 deletion docs/CHANGELOG-2.2.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Parity-Ethereum [v2.2.7](https://github.com/paritytech/parity-ethereum/releases/tag/v2.2.7) (2018-01-15)
## Parity-Ethereum [v2.2.7](https://github.com/paritytech/parity-ethereum/releases/tag/v2.2.7) (2019-01-15)

Parity-Ethereum 2.2.7-stable is a consensus-relevant security release that reverts Constantinople on the Ethereum network. Upgrading is mandatory for Ethereum, and strongly recommended for other networks.

Expand Down
3 changes: 1 addition & 2 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,12 @@ impl Provider where {

fn pool_client<'a>(&'a self, nonce_cache: &'a NonceCache) -> miner::pool_client::PoolClient<'a, Client> {
let engine = self.client.engine();
let refuse_service_transactions = true;
miner::pool_client::PoolClient::new(
&*self.client,
nonce_cache,
engine,
Some(&*self.accounts),
refuse_service_transactions,
None, // refuse_service_transactions = true
)
}

Expand Down
13 changes: 8 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRou
use bytes::Bytes;
use call_contract::{CallContract, RegistryInfo};
use ethcore_miner::pool::VerifiedTransaction;
use ethcore_miner::service_transaction_checker::ServiceTransactionChecker;
use ethereum_types::{H256, Address, U256};
use evm::Schedule;
use hash::keccak;
Expand Down Expand Up @@ -2157,10 +2156,14 @@ 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, authoring_params.author) {
Ok(true) => U256::zero(),
_ => self.importer.miner.sensible_gas_price(),
let service_transaction_checker = self.importer.miner.service_transaction_checker();
let gas_price = if let Some(checker) = service_transaction_checker {
match checker.check_address(self, authoring_params.author) {
Ok(true) => U256::zero(),
_ => self.importer.miner.sensible_gas_price(),
}
} else {
self.importer.miner.sensible_gas_price()
};
let transaction = transaction::Transaction {
nonce: self.latest_nonce(&authoring_params.author),
Expand Down
30 changes: 27 additions & 3 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bytes::Bytes;
use call_contract::CallContract;
use ethcore_miner::gas_pricer::GasPricer;
use ethcore_miner::pool::{self, TransactionQueue, VerifiedTransaction, QueueStatus, PrioritizationStrategy};
use ethcore_miner::service_transaction_checker::ServiceTransactionChecker;
#[cfg(feature = "work-notify")]
use ethcore_miner::work_notify::NotifyWork;
use ethereum_types::{H256, U256, Address};
Expand Down Expand Up @@ -232,6 +233,7 @@ pub struct Miner {
engine: Arc<EthEngine>,
accounts: Option<Arc<AccountProvider>>,
io_channel: RwLock<Option<IoChannel<ClientIoMessage>>>,
service_transaction_checker: Option<ServiceTransactionChecker>,
}

impl Miner {
Expand All @@ -258,6 +260,7 @@ impl Miner {
let verifier_options = options.pool_verification_options.clone();
let tx_queue_strategy = options.tx_queue_strategy;
let nonce_cache_size = cmp::max(4096, limits.max_count / 4);
let refuse_service_transactions = options.refuse_service_transactions.clone();
VladLupashevskyi marked this conversation as resolved.
Show resolved Hide resolved

Miner {
sealing: Mutex::new(SealingWork {
Expand All @@ -278,6 +281,11 @@ impl Miner {
accounts,
engine: spec.engine.clone(),
io_channel: RwLock::new(None),
service_transaction_checker: if refuse_service_transactions {
None
} else {
Some(ServiceTransactionChecker::new())
},
}
}

Expand Down Expand Up @@ -336,6 +344,11 @@ impl Miner {
});
}

/// Returns ServiceTransactionChecker
pub fn service_transaction_checker(&self) -> Option<ServiceTransactionChecker> {
self.service_transaction_checker.clone()
}

/// Retrieves an existing pending block iff it's not older than given block number.
///
/// NOTE: This will not prepare a new pending block if it's not existing.
Expand Down Expand Up @@ -363,7 +376,7 @@ impl Miner {
&self.nonce_cache,
&*self.engine,
self.accounts.as_ref().map(|x| &**x),
self.options.refuse_service_transactions,
self.service_transaction_checker.as_ref(),
)
}

Expand Down Expand Up @@ -1248,15 +1261,15 @@ impl miner::MinerService for Miner {
let nonce_cache = self.nonce_cache.clone();
let engine = self.engine.clone();
let accounts = self.accounts.clone();
let refuse_service_transactions = self.options.refuse_service_transactions;
let service_transaction_checker = self.service_transaction_checker.clone();

let cull = move |chain: &::client::Client| {
let client = PoolClient::new(
chain,
&nonce_cache,
&*engine,
accounts.as_ref().map(|x| &**x),
refuse_service_transactions,
service_transaction_checker.as_ref(),
);
queue.cull(client);
};
Expand All @@ -1268,6 +1281,17 @@ impl miner::MinerService for Miner {
self.transaction_queue.cull(client);
}
}
if self.service_transaction_checker.is_some() {
VladLupashevskyi marked this conversation as resolved.
Show resolved Hide resolved
match self.service_transaction_checker.clone().unwrap().refresh_cache(chain) {
VladLupashevskyi marked this conversation as resolved.
Show resolved Hide resolved
Ok(true) => {
trace!(target: "client", "Service transaction cache was refreshed successfully");
},
Ok(false) => {
trace!(target: "client", "Registrar or/and service transactions contract does not exist");
},
Err(e) => error!(target: "client", "Error occurred while refreshing service transaction cache: {}", e)
};
};
}

fn pending_state(&self, latest_block_number: BlockNumber) -> Option<Self::State> {
Expand Down
10 changes: 3 additions & 7 deletions ethcore/src/miner/pool_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct PoolClient<'a, C: 'a> {
engine: &'a EthEngine,
accounts: Option<&'a AccountProvider>,
best_block_header: Header,
service_transaction_checker: Option<ServiceTransactionChecker>,
service_transaction_checker: Option<&'a ServiceTransactionChecker>,
}

impl<'a, C: 'a> Clone for PoolClient<'a, C> {
Expand All @@ -100,7 +100,7 @@ C: BlockInfo + CallContract,
cache: &'a NonceCache,
engine: &'a EthEngine,
accounts: Option<&'a AccountProvider>,
refuse_service_transactions: bool,
service_transaction_checker: Option<&'a ServiceTransactionChecker>,
) -> Self {
let best_block_header = chain.best_block_header();
PoolClient {
Expand All @@ -109,11 +109,7 @@ C: BlockInfo + CallContract,
engine,
accounts,
best_block_header,
service_transaction_checker: if refuse_service_transactions {
None
} else {
Some(Default::default())
},
service_transaction_checker
VladLupashevskyi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading