* `duration_ns: u64 -> duration: Duration` (#8457) * duration_ns: u64 -> duration: Duration * format on millis {:.2} -> {} * Keep all enacted blocks notify in order (#8524) * Keep all enacted blocks notify in order * Collect is unnecessary * Update ChainNotify to use ChainRouteType * Fix all ethcore fn defs * Wrap the type within ChainRoute * Fix private-tx and sync api * Fix secret_store API * Fix updater API * Fix rpc api * Fix informant api * Eagerly cache enacted/retracted and remove contain_enacted/retracted * Fix indent * tests: should use full expr form for struct constructor * Use into_enacted_retracted to further avoid copy * typo: not a function * rpc/tests: ChainRoute -> ChainRoute::new * Handle removed logs in filter changes and add geth compatibility field (#8796) * Add removed geth compatibility field in log * Fix mocked tests * Add field block hash in PollFilter * Store last block hash info for log filters * Implement canon route * Use canon logs for fetching reorg logs Light client removed logs fetching is disabled. It looks expensive. * Make sure removed flag is set * Address grumbles * Fixed AuthorityRound deadlock on shutdown, closes #8088 (#8803) * CI: Fix docker tags (#8822) * scripts: enable docker builds for beta and stable * scripts: docker latest should be beta not master * scripts: docker latest is master * ethcore: fix ancient block error msg handling (#8832) * Disable parallel verification and skip verifiying already imported txs. (#8834) * Reject transactions that are already in pool without verifying them. * Avoid verifying already imported transactions. * Fix concurrent access to signer queue (#8854) * Fix concurrent access to signer queue * Put request back to the queue if confirmation failed * typo: fix docs and rename functions to be more specific `request_notify` does not need to be public, and it's renamed to `notify_result`. `notify` is renamed to `notify_message`. * Change trace info "Transaction" -> "Request" * Don't allocate in expect_valid_rlp unless necessary (#8867) * don't allocate via format! in case there's no error * fix test? * fixed ipc leak, closes #8774 (#8876) * Add new ovh bootnodes and fix port for foundation bootnode 3.2 (#8886) * Add new ovh bootnodes and fix port for foundation bootnode 3.2 * Remove old bootnodes. * Remove duplicate 1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082 * Block 0 is valid in queries (#8891) Early exit for block nr 0 leads to spurious error about pruning: `…your node is running with state pruning…`. Fixes #7547, #8762 * Add ETC Cooperative-run load balanced parity node (#8892) * Minor fix in chain supplier and light provider (#8906) * fix chain supplier increment * fix light provider block_headers * Check whether we need resealing in miner and unwrap has_account in account_provider (#8853) * Remove unused Result wrap in has_account * Check whether we need to reseal for external transactions * Fix reference to has_account interface * typo: missing ) * Refactor duplicates to prepare_and_update_sealing * Fix build * Allow disabling local-by-default for transactions with new config entry (#8882) * Add tx_queue_allow_unknown_local config option - Previous commit messages: dispatcher checks if we have the sender account Add `tx_queue_allow_unknown_local` to MinerOptions Add `tx_queue_allow_unknown_local` to config fix order in MinerOptions to match Configuration add cli flag for tx_queue_allow_unknown_local Update refs to `tx_queue_allow_unknown_local` Add tx_queue_allow_unknown_local to config test revert changes to dispatcher Move tx_queue_allow_unknown_local to `import_own_transaction` Fix var name if statement should return the values derp de derp derp derp semicolons Reset dispatch file to how it was before fix compile issues + change from FLAG to ARG add test and use `into` import MinerOptions, clone the secret Fix tests? Compiler/linter issues fixed Fix linter msg - case of constants IT LIVES refactor to omit yucky explict return update comments Fix based on diff AccountProvider.has_account method * Refactor flag name + don't change import_own_tx behaviour fix arg name Note: force commit to try and get gitlab tests working again 😠 * Add fn to TestMinerService * Avoid race condition from trusted sources - refactor the miner tests a bit to cut down on code reuse - add `trusted` param to dispatch_transaction and import_claimed_local_transaction Add param to `import_claimed_local_transaction` Fix fn sig in tests
192 lines
7.3 KiB
Rust
192 lines
7.3 KiB
Rust
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity.
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
//! Miner module
|
|
//! Keeps track of transactions and currently sealed pending block.
|
|
|
|
mod miner;
|
|
mod service_transaction_checker;
|
|
|
|
pub mod pool_client;
|
|
pub mod stratum;
|
|
|
|
pub use self::miner::{Miner, MinerOptions, Penalization, PendingSet, AuthoringParams};
|
|
|
|
use std::sync::Arc;
|
|
use std::collections::BTreeMap;
|
|
|
|
use bytes::Bytes;
|
|
use ethereum_types::{H256, U256, Address};
|
|
use ethcore_miner::pool::{VerifiedTransaction, QueueStatus, local_transactions};
|
|
|
|
use block::{Block, SealedBlock};
|
|
use client::{
|
|
CallContract, RegistryInfo, ScheduleInfo,
|
|
BlockChain, BlockProducer, SealedBlockImporter, ChainInfo,
|
|
AccountData, Nonce,
|
|
};
|
|
use error::Error;
|
|
use header::{BlockNumber, Header};
|
|
use receipt::{RichReceipt, Receipt};
|
|
use transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction};
|
|
use state::StateInfo;
|
|
|
|
/// Provides methods to verify incoming external transactions
|
|
pub trait TransactionVerifierClient: Send + Sync
|
|
// Required for ServiceTransactionChecker
|
|
+ CallContract + RegistryInfo
|
|
// Required for verifiying transactions
|
|
+ BlockChain + ScheduleInfo + AccountData
|
|
{}
|
|
|
|
/// Extended client interface used for mining
|
|
pub trait BlockChainClient: TransactionVerifierClient + BlockProducer + SealedBlockImporter {}
|
|
|
|
/// Miner client API
|
|
pub trait MinerService : Send + Sync {
|
|
/// Type representing chain state
|
|
type State: StateInfo + 'static;
|
|
|
|
// Sealing
|
|
|
|
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
|
/// Will check the seal, but not actually insert the block into the chain.
|
|
fn submit_seal(&self, pow_hash: H256, seal: Vec<Bytes>) -> Result<SealedBlock, Error>;
|
|
|
|
/// Is it currently sealing?
|
|
fn is_currently_sealing(&self) -> bool;
|
|
|
|
/// Get the sealing work package preparing it if doesn't exist yet.
|
|
///
|
|
/// Returns `None` if engine seals internally.
|
|
fn work_package<C>(&self, chain: &C) -> Option<(H256, BlockNumber, u64, U256)>
|
|
where C: BlockChain + CallContract + BlockProducer + SealedBlockImporter + Nonce + Sync;
|
|
|
|
/// Update current pending block
|
|
fn update_sealing<C>(&self, chain: &C)
|
|
where C: BlockChain + CallContract + BlockProducer + SealedBlockImporter + Nonce + Sync;
|
|
|
|
|
|
// Notifications
|
|
|
|
/// Called when blocks are imported to chain, updates transactions queue.
|
|
/// `is_internal_import` indicates that the block has just been created in miner and internally sealed by the engine,
|
|
/// so we shouldn't attempt creating new block again.
|
|
fn chain_new_blocks<C>(&self, chain: &C, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256], is_internal_import: bool)
|
|
where C: BlockChainClient;
|
|
|
|
|
|
// Pending block
|
|
|
|
/// Get a list of all pending receipts from pending block.
|
|
fn pending_receipts(&self, best_block: BlockNumber) -> Option<BTreeMap<H256, Receipt>>;
|
|
|
|
/// Get a particular receipt from pending block.
|
|
fn pending_receipt(&self, best_block: BlockNumber, hash: &H256) -> Option<RichReceipt>;
|
|
|
|
/// Get `Some` `clone()` of the current pending block's state or `None` if we're not sealing.
|
|
fn pending_state(&self, latest_block_number: BlockNumber) -> Option<Self::State>;
|
|
|
|
/// Get `Some` `clone()` of the current pending block header or `None` if we're not sealing.
|
|
fn pending_block_header(&self, latest_block_number: BlockNumber) -> Option<Header>;
|
|
|
|
/// Get `Some` `clone()` of the current pending block or `None` if we're not sealing.
|
|
fn pending_block(&self, latest_block_number: BlockNumber) -> Option<Block>;
|
|
|
|
/// Get `Some` `clone()` of the current pending block transactions or `None` if we're not sealing.
|
|
fn pending_transactions(&self, latest_block_number: BlockNumber) -> Option<Vec<SignedTransaction>>;
|
|
|
|
// Block authoring
|
|
|
|
/// Get current authoring parameters.
|
|
fn authoring_params(&self) -> AuthoringParams;
|
|
|
|
/// Set the lower and upper bound of gas limit we wish to target when sealing a new block.
|
|
fn set_gas_range_target(&self, gas_range_target: (U256, U256));
|
|
|
|
/// Set the extra_data that we will seal blocks with.
|
|
fn set_extra_data(&self, extra_data: Bytes);
|
|
|
|
/// Set info necessary to sign consensus messages and block authoring.
|
|
///
|
|
/// On PoW password is optional.
|
|
fn set_author(&self, address: Address, password: Option<String>) -> Result<(), ::account_provider::SignError>;
|
|
|
|
// Transaction Pool
|
|
|
|
/// Imports transactions to transaction queue.
|
|
fn import_external_transactions<C>(&self, client: &C, transactions: Vec<UnverifiedTransaction>)
|
|
-> Vec<Result<(), transaction::Error>>
|
|
where C: BlockChainClient;
|
|
|
|
/// Imports own (node owner) transaction to queue.
|
|
fn import_own_transaction<C>(&self, chain: &C, transaction: PendingTransaction)
|
|
-> Result<(), transaction::Error>
|
|
where C: BlockChainClient;
|
|
|
|
/// Imports transactions from potentially external sources, with behaviour determined
|
|
/// by the config flag `tx_queue_allow_unfamiliar_locals`
|
|
fn import_claimed_local_transaction<C>(&self, chain: &C, transaction: PendingTransaction, trusted: bool)
|
|
-> Result<(), transaction::Error>
|
|
where C: BlockChainClient;
|
|
|
|
/// Removes transaction from the pool.
|
|
///
|
|
/// Attempts to "cancel" a transaction. If it was not propagated yet (or not accepted by other peers)
|
|
/// there is a good chance that the transaction will actually be removed.
|
|
/// NOTE: The transaction is not removed from pending block if there is one.
|
|
fn remove_transaction(&self, hash: &H256) -> Option<Arc<VerifiedTransaction>>;
|
|
|
|
/// Query transaction from the pool given it's hash.
|
|
fn transaction(&self, hash: &H256) -> Option<Arc<VerifiedTransaction>>;
|
|
|
|
/// Returns next valid nonce for given address.
|
|
///
|
|
/// This includes nonces of all transactions from this address in the pending queue
|
|
/// if they are consecutive.
|
|
/// NOTE: pool may contain some future transactions that will become pending after
|
|
/// transaction with nonce returned from this function is signed on.
|
|
fn next_nonce<C>(&self, chain: &C, address: &Address) -> U256
|
|
where C: Nonce + Sync;
|
|
|
|
/// Get a list of all ready transactions.
|
|
///
|
|
/// Depending on the settings may look in transaction pool or only in pending block.
|
|
fn ready_transactions<C>(&self, chain: &C) -> Vec<Arc<VerifiedTransaction>>
|
|
where C: ChainInfo + Nonce + Sync;
|
|
|
|
/// Get a list of all transactions in the pool (some of them might not be ready for inclusion yet).
|
|
fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>>;
|
|
|
|
/// Get a list of local transactions with statuses.
|
|
fn local_transactions(&self) -> BTreeMap<H256, local_transactions::Status>;
|
|
|
|
/// Get current queue status.
|
|
///
|
|
/// Status includes verification thresholds and current pool utilization and limits.
|
|
fn queue_status(&self) -> QueueStatus;
|
|
|
|
// Misc
|
|
|
|
/// Suggested gas price.
|
|
fn sensible_gas_price(&self) -> U256;
|
|
|
|
/// Suggested gas limit.
|
|
fn sensible_gas_limit(&self) -> U256;
|
|
}
|