RPCs for mode change (#3002)
* Allow warnings. * Add RPCs to allow ad-hoc mode changes. * Add the JSAPI interfaces * Add missing file.
This commit is contained in:
@@ -45,6 +45,7 @@ use block::*;
|
||||
use transaction::{LocalizedTransaction, SignedTransaction, Action};
|
||||
use blockchain::extras::TransactionAddress;
|
||||
use types::filter::Filter;
|
||||
use types::mode::Mode as IpcMode;
|
||||
use log_entry::LocalizedLogEntry;
|
||||
use verification::queue::BlockQueue;
|
||||
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
||||
@@ -123,7 +124,7 @@ impl SleepState {
|
||||
/// Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue.
|
||||
/// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue.
|
||||
pub struct Client {
|
||||
mode: Mode,
|
||||
mode: Mutex<Mode>,
|
||||
chain: RwLock<Arc<BlockChain>>,
|
||||
tracedb: RwLock<TraceDB<BlockChain>>,
|
||||
engine: Arc<Engine>,
|
||||
@@ -221,7 +222,7 @@ impl Client {
|
||||
let client = Client {
|
||||
sleep_state: Mutex::new(SleepState::new(awake)),
|
||||
liveness: AtomicBool::new(awake),
|
||||
mode: config.mode.clone(),
|
||||
mode: Mutex::new(config.mode.clone()),
|
||||
chain: RwLock::new(chain),
|
||||
tracedb: tracedb,
|
||||
engine: engine,
|
||||
@@ -614,7 +615,8 @@ impl Client {
|
||||
self.block_queue.collect_garbage();
|
||||
self.tracedb.read().collect_garbage();
|
||||
|
||||
match self.mode {
|
||||
let mode = self.mode.lock().clone();
|
||||
match mode {
|
||||
Mode::Dark(timeout) => {
|
||||
let mut ss = self.sleep_state.lock();
|
||||
if let Some(t) = ss.last_activity {
|
||||
@@ -838,12 +840,24 @@ impl BlockChainClient for Client {
|
||||
}
|
||||
|
||||
fn keep_alive(&self) {
|
||||
if self.mode != Mode::Active {
|
||||
let mode = self.mode.lock().clone();
|
||||
if mode != Mode::Active {
|
||||
self.wake_up();
|
||||
(*self.sleep_state.lock()).last_activity = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
fn mode(&self) -> IpcMode { self.mode.lock().clone().into() }
|
||||
|
||||
fn set_mode(&self, mode: IpcMode) {
|
||||
*self.mode.lock() = mode.clone().into();
|
||||
match mode {
|
||||
IpcMode::Active => self.wake_up(),
|
||||
IpcMode::Off => self.sleep(),
|
||||
_ => {(*self.sleep_state.lock()).last_activity = Some(Instant::now()); }
|
||||
}
|
||||
}
|
||||
|
||||
fn best_block_header(&self) -> Bytes {
|
||||
self.chain.read().best_block_header()
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ pub enum Mode {
|
||||
/// Goes offline after RLP is inactive for some (given) time and
|
||||
/// stays inactive.
|
||||
Dark(Duration),
|
||||
/// Always off.
|
||||
Off,
|
||||
}
|
||||
|
||||
impl Default for Mode {
|
||||
|
||||
@@ -37,6 +37,7 @@ use error::{ImportResult};
|
||||
use evm::{Factory as EvmFactory, VMType, Schedule};
|
||||
use miner::{Miner, MinerService, TransactionImportResult};
|
||||
use spec::Spec;
|
||||
use types::mode::Mode;
|
||||
|
||||
use verification::queue::QueueInfo;
|
||||
use block::{OpenBlock, SealedBlock};
|
||||
@@ -625,4 +626,8 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||
self.miner.pending_transactions(self.chain_info().best_block_number)
|
||||
}
|
||||
|
||||
fn mode(&self) -> Mode { Mode::Active }
|
||||
|
||||
fn set_mode(&self, _: Mode) { unimplemented!(); }
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ use block_import_error::BlockImportError;
|
||||
use ipc::IpcConfig;
|
||||
use types::blockchain_info::BlockChainInfo;
|
||||
use types::block_status::BlockStatus;
|
||||
use types::mode::Mode;
|
||||
|
||||
#[ipc(client_ident="RemoteClient")]
|
||||
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
||||
@@ -225,6 +226,10 @@ pub trait BlockChainClient : Sync + Send {
|
||||
let (corpus, _) = raw_corpus.split_at(raw_len-raw_len/40);
|
||||
Histogram::new(corpus, bucket_number)
|
||||
}
|
||||
|
||||
fn mode(&self) -> Mode;
|
||||
|
||||
fn set_mode(&self, mode: Mode);
|
||||
}
|
||||
|
||||
/// Extended client interface used for mining
|
||||
|
||||
Reference in New Issue
Block a user