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

Backporting to beta #4203

Merged
merged 4 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 15 additions & 5 deletions js/src/modals/UpgradeParity/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const STEP_UPDATING = 1;
const STEP_COMPLETED = 2;
const STEP_ERROR = 2;

const CHECK_INTERVAL = 1 * A_MINUTE;
let instance = null;

export default class Store {
@observable available = null;
Expand All @@ -44,8 +44,6 @@ export default class Store {

this.loadStorage();
this.checkUpgrade();

setInterval(this.checkUpgrade, CHECK_INTERVAL);
}

@computed get isVisible () {
Expand Down Expand Up @@ -119,10 +117,10 @@ export default class Store {

checkUpgrade = () => {
if (!this._api) {
return;
return Promise.resolve(false);
}

Promise
return Promise
.all([
this._api.parity.upgradeReady(),
this._api.parity.consensusCapability(),
Expand All @@ -134,11 +132,23 @@ export default class Store {
}

this.setVersions(available, version, consensusCapability);

return true;
})
.catch((error) => {
console.warn('checkUpgrade', error);

return false;
});
}

static get (api) {
if (!instance) {
instance = new Store(api);
}

return instance;
}
}

export {
Expand Down
30 changes: 16 additions & 14 deletions js/src/redux/providers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BalancesProvider from './balances';
import { statusBlockNumber, statusCollection, statusLogs } from './statusActions';
import { isEqual } from 'lodash';

import { LOG_KEYS, getLogger } from '~/config';
import UpgradeStore from '~/modals/UpgradeParity/store';

import BalancesProvider from './balances';
import { statusBlockNumber, statusCollection, statusLogs } from './statusActions';

const log = getLogger(LOG_KEYS.Signer);
let instance = null;

export default class Status {
_apiStatus = {};
_status = {};
_longStatus = {};
_minerSettings = {};
_timeoutIds = {};
_blockNumberSubscriptionId = null;
_timestamp = Date.now();

constructor (store, api) {
this._api = api;
this._store = store;

this._apiStatus = {};
this._status = {};
this._longStatus = {};
this._minerSettings = {};

this._timeoutIds = {};
this._blockNumberSubscriptionId = null;

this._timestamp = Date.now();
this._upgradeStore = UpgradeStore.get(api);

// On connecting, stop all subscriptions
api.on('connecting', this.stop, this);
Expand Down Expand Up @@ -281,10 +282,11 @@ export default class Status {
this._api.parity.netChain(),
this._api.parity.netPort(),
this._api.parity.rpcSettings(),
this._api.parity.enode()
this._api.parity.enode(),
this._upgradeStore.checkUpgrade()
])
.then(([
netPeers, clientVersion, netVersion, defaultExtraData, netChain, netPort, rpcSettings, enode
netPeers, clientVersion, netVersion, defaultExtraData, netChain, netPort, rpcSettings, enode, upgradeStatus
]) => {
const isTest =
netVersion === '2' || // morden
Expand Down
8 changes: 6 additions & 2 deletions js/src/views/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Application extends Component {
}

store = new Store(this.context.api);
upgradeStore = new UpgradeStore(this.context.api);
upgradeStore = UpgradeStore.get(this.context.api);

render () {
const [root] = (window.location.hash || '').replace('#/', '').split('/');
Expand All @@ -65,7 +65,11 @@ class Application extends Component {

return (
<div>
{ isMinimized ? this.renderMinimized() : this.renderApp() }
{
isMinimized
? this.renderMinimized()
: this.renderApp()
}
<Connection />
<ParityBar dapp={ isMinimized } />
</div>
Expand Down
37 changes: 29 additions & 8 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,27 @@ fn latest_exe_path() -> Option<PathBuf> {
.and_then(|mut f| { let mut exe = String::new(); f.read_to_string(&mut exe).ok().map(|_| updates_path(&exe)) })
}

#[cfg(windows)]
fn global_cleanup() {
extern "system" { pub fn WSACleanup() -> i32; }
// We need to cleanup all sockets before spawning another Parity process. This makes shure everything is cleaned up.
// The loop is required because of internal refernce counter for winsock dll. We don't know how many crates we use do
// initialize it. There's at least 2 now.
for _ in 0.. 10 {
unsafe { WSACleanup(); }
}
}

#[cfg(not(windows))]
fn global_cleanup() {}

// Starts ~/.parity-updates/parity and returns the code it exits with.
fn run_parity() -> Option<i32> {
global_cleanup();
use ::std::ffi::OsString;
let prefix = vec![OsString::from("--can-restart"), OsString::from("--force-direct")];
latest_exe_path().and_then(|exe| process::Command::new(exe)
.args(&(env::args_os().chain(prefix.into_iter()).collect::<Vec<_>>()))
.args(&(env::args_os().skip(1).chain(prefix.into_iter()).collect::<Vec<_>>()))
.status()
.map(|es| es.code().unwrap_or(128))
.ok()
Expand Down Expand Up @@ -266,17 +281,23 @@ fn main() {
let exe = std::env::current_exe().ok();
let development = exe.as_ref().and_then(|p| p.parent().and_then(|p| p.parent()).and_then(|p| p.file_name()).map(|n| n == "target")).unwrap_or(false);
let same_name = exe.as_ref().map(|p| p.file_stem().map_or(false, |s| s == "parity") && p.extension().map_or(true, |x| x == "exe")).unwrap_or(false);
let latest_exe = latest_exe_path();
let have_update = latest_exe.as_ref().map_or(false, |p| p.exists());
let is_non_updated_current = exe.map_or(false, |exe| latest_exe.as_ref().map_or(false, |lexe| exe.canonicalize().ok() != lexe.canonicalize().ok()));
trace_main!("Starting up {} (force-direct: {}, development: {}, same-name: {}, have-update: {}, non-updated-current: {})", std::env::current_exe().map(|x| format!("{}", x.display())).unwrap_or("<unknown>".to_owned()), force_direct, development, same_name, have_update, is_non_updated_current);
if !force_direct && !development && same_name && have_update && is_non_updated_current {
trace_main!("Starting up {} (force-direct: {}, development: {}, same-name: {})", std::env::current_exe().map(|x| format!("{}", x.display())).unwrap_or("<unknown>".to_owned()), force_direct, development, same_name);
if !force_direct && !development && same_name {
// looks like we're not running ~/.parity-updates/parity when the user is expecting otherwise.
// Everything run inside a loop, so we'll be able to restart from the child into a new version seamlessly.
loop {
// If we fail to run the updated parity then fallback to local version.
trace_main!("Attempting to run latest update ({})...", latest_exe.as_ref().expect("guarded by have_update; latest_exe must exist for have_update; qed").display());
let exit_code = run_parity().unwrap_or_else(|| { trace_main!("Falling back to local..."); main_direct(true) });
let latest_exe = latest_exe_path();
let have_update = latest_exe.as_ref().map_or(false, |p| p.exists());
let is_non_updated_current = exe.as_ref().map_or(false, |exe| latest_exe.as_ref().map_or(false, |lexe| exe.canonicalize().ok() != lexe.canonicalize().ok()));
trace_main!("Starting... (have-update: {}, non-updated-current: {})", have_update, is_non_updated_current);
let exit_code = if have_update && is_non_updated_current {
trace_main!("Attempting to run latest update ({})...", latest_exe.as_ref().expect("guarded by have_update; latest_exe must exist for have_update; qed").display());
run_parity().unwrap_or_else(|| { trace_main!("Falling back to local..."); main_direct(true) })
} else {
trace_main!("No latest update. Attempting to direct...");
main_direct(true)
};
trace_main!("Latest exited with {}", exit_code);
if exit_code != PLEASE_RESTART_EXIT_CODE {
trace_main!("Quitting...");
Expand Down
3 changes: 2 additions & 1 deletion updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ impl Updater {
if s.fetching.is_none() {
info!(target: "updater", "Attempting to get parity binary {}", b);
s.fetching = Some(latest.track.clone());
drop(s);
let weak_self = self.weak_self.lock().clone();
let f = move |r: Result<PathBuf, fetch::Error>| if let Some(this) = weak_self.upgrade() { this.fetch_done(r) };
self.fetcher.lock().as_ref().expect("Created on `new`; qed").fetch(b, Box::new(f));
Expand Down Expand Up @@ -311,7 +312,7 @@ impl Updater {
impl ChainNotify for Updater {
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
match (self.client.upgrade(), self.sync.upgrade()) {
(Some(ref c), Some(ref s)) if s.status().is_syncing(c.queue_info()) => self.poll(),
(Some(ref c), Some(ref s)) if !s.status().is_syncing(c.queue_info()) => self.poll(),
_ => {},
}
}
Expand Down
Loading