More work.

This commit is contained in:
Gav Wood 2016-11-24 17:19:48 +01:00
parent 03ef95ba50
commit 735df6c30f
No known key found for this signature in database
GPG Key ID: C49C1ACA1CC9B252
5 changed files with 53 additions and 19 deletions

View File

@ -14,7 +14,8 @@
"eip155Transition": 10, "eip155Transition": 10,
"eip160Transition": 10, "eip160Transition": 10,
"eip161abcTransition": 10, "eip161abcTransition": 10,
"eip161dTransition": 10 "eip161dTransition": 10,
"maxCodeSize": 24576
} }
} }
}, },

View File

@ -54,7 +54,7 @@ use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
use client::{ use client::{
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient, BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode, MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode,
ChainNotify, UpdatePolicy, ChainNotify,
}; };
use client::Error as ClientError; use client::Error as ClientError;
use env_info::EnvInfo; use env_info::EnvInfo;

View File

@ -97,10 +97,6 @@ impl Default for UpdatePolicy {
} }
} }
impl UpdatePolicy {
pub fn new() -> Self { Default::default() }
}
/// Operating mode for the client. /// Operating mode for the client.
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
pub enum Mode { pub enum Mode {

View File

@ -21,47 +21,84 @@ use client::operations::Operations;
use client::{Client, UpdatePolicy, BlockId}; use client::{Client, UpdatePolicy, BlockId};
pub struct ReleaseInfo { pub struct ReleaseInfo {
fork_supported: usize, pub latest_known_fork: usize,
latest_known_fork: usize,
latest: VersionInfo, pub latest: VersionInfo,
latest_fork: usize, pub latest_fork: usize,
latest_binary: Option<H256>, pub latest_binary: Option<H256>,
} }
pub struct Updater { pub struct Updater {
client: Weak<Client>, client: Weak<Client>,
operations: Operations, operations: Operations,
update_policy: UpdatePolicy,
pub this: VersionInfo, pub this: VersionInfo,
pub this_fork: Option<usize>,
pub release_info: Option<ReleaseInfo>, pub release_info: Option<ReleaseInfo>,
} }
impl Updater { impl Updater {
pub fn new(client: Weak<Client>, operations: Address, _update_policy: UpdatePolicy) -> Self { pub fn new(client: Weak<Client>, operations: Address, update_policy: UpdatePolicy) -> Self {
let mut u = Updater { let mut u = Updater {
client: client.clone(), client: client.clone(),
operations: Operations::new(operations, move |a, d| client.upgrade().ok_or("No client!".into()).and_then(|c| c.call_contract(a, d))), operations: Operations::new(operations, move |a, d| client.upgrade().ok_or("No client!".into()).and_then(|c| c.call_contract(a, d))),
update_policy: update_policy,
this: VersionInfo::this(), this: VersionInfo::this(),
this_fork: None,
release_info: None, release_info: None,
}; };
let (fork, track, _, _) = self.operations.release(client_id, &v.hash.into())?;
u.this_fork = if track > 0 { Some(fork) } else { None };
u.release_info = u.get_release_info().ok(); u.release_info = u.get_release_info().ok();
// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if u.this.track == ReleaseTrack::Unknown { if u.this.track == ReleaseTrack::Unknown {
u.this.track = ReleaseTrack::Nightly; u.this.track = ReleaseTrack::Nightly;
} }
u u
} }
/// Is the currently running client capable of supporting the current chain?
/// `Some` answer or `None` if information on the running client is not available.
pub fn is_capable(&self) -> Option<bool> {
self.release_info.and_then(|relinfo| {
relinfo.fork_supported.map(|fork_supported| {
let current_number = self.client.upgrade().map_or(0, |c| c.block_number(BlockId::Latest).unwrap_or(0));
fork_supported >= relinfo.latest_fork || current_number < relinfo.latest_fork
})
})
}
/// The release which is ready to be upgraded to, if any. If this returns `Some`, then
/// `execute_upgrade` may be called.
pub fn upgrade_ready(&self) -> Option<VersionInfo> {
unimplemented!()
}
/// Actually upgrades the client. Assumes that the binary has been downloaded.
/// @returns `true` on success.
pub fn execute_upgrade(&mut self) -> bool {
unimplemented!()
}
/// Our version info.
pub fn version_info() -> &VersionInfo { &self.this }
/// Information gathered concerning the release.
pub fn release_info() -> &Option<ReleaseInfo> { &self.release_info }
fn get_release_info(&mut self) -> Result<ReleaseInfo, String> { fn get_release_info(&mut self) -> Result<ReleaseInfo, String> {
//601e0fb0fd7e9e1cec18f8872e8713117cab4e84
if self.this.track == ReleaseTrack::Unknown { if self.this.track == ReleaseTrack::Unknown {
return Err(format!("Current executable ({}) is unreleased.", H160::from(self.this.hash))); return Err(format!("Current executable ({}) is unreleased.", H160::from(self.this.hash)));
} }
let client_id = "parity"; let client_id = "parity";
let latest_known_fork = self.operations.latest_fork()?;
let our_fork = self.operations.release(client_id, &self.this.hash.into())?.0;
let latest_release = self.operations.latest_in_track(client_id, self.this.track.into())?; let latest_release = self.operations.latest_in_track(client_id, self.this.track.into())?;
let (fork, track, semver, _critical) = self.operations.release(client_id, &latest_release)?; let (fork, track, semver, _critical) = self.operations.release(client_id, &latest_release)?;
let maybe_latest_binary = self.operations.checksum(client_id, &latest_release, &platform())?; let maybe_latest_binary = self.operations.checksum(client_id, &latest_release, &platform())?;

View File

@ -77,7 +77,7 @@ usage! {
flag_mode: String = "last", or |c: &Config| otry!(c.parity).mode.clone(), flag_mode: String = "last", or |c: &Config| otry!(c.parity).mode.clone(),
flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(), flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(),
flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.clone(), flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.clone(),
flag_auto_update: String = "consensus", or |c: &Config| otry!(c.parity).auto_update.clone(), flag_auto_update: String = "critical", or |c: &Config| otry!(c.parity).auto_update.clone(),
flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(), flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(),
flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(), flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(),
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(), flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
@ -508,7 +508,7 @@ mod tests {
flag_mode: "last".into(), flag_mode: "last".into(),
flag_mode_timeout: 300u64, flag_mode_timeout: 300u64,
flag_mode_alarm: 3600u64, flag_mode_alarm: 3600u64,
flag_auto_update: "consensus".into(), flag_auto_update: "critical".into(),
flag_no_download: false, flag_no_download: false,
flag_no_consensus: false, flag_no_consensus: false,
flag_chain: "xyz".into(), flag_chain: "xyz".into(),