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

Commit

Permalink
[beta] Backports (#6163)
Browse files Browse the repository at this point in the history
* Light client improvements (#6156)

* no seal checking

* import command and --no-seal-check for light client

* fix eth_call

* tweak registry dapps lookup

* ignore failed requests to non-server peers

* Fix connecting to wildcard addresses. (#6167)

* Don't display an overlay in case the time sync check fails. (#6164)

* Small improvements to time estimation.

* Temporarily disable NTP time check by default.
  • Loading branch information
arkpar authored Jul 27, 2017
1 parent a554b81 commit 65e4bad
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 64 deletions.
10 changes: 8 additions & 2 deletions dapps/src/api/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ impl SimpleNtp {
impl Ntp for SimpleNtp {
fn drift(&self) -> BoxFuture<Duration, Error> {
let address = self.address.clone();
if &*address == "none" {
return futures::future::err(Error::Ntp("NTP server is not provided.".into())).boxed();
}

self.pool.spawn_fn(move || {
let packet = ntp::request(&*address)?;
let dest_time = ::time::now_utc().to_timespec();
Expand All @@ -114,7 +118,9 @@ impl Ntp for SimpleNtp {
}
}

const MAX_RESULTS: usize = 4;
// NOTE In a positive scenario first results will be seen after:
// MAX_RESULTS * UPDATE_TIMEOUT_OK_SECS seconds.
const MAX_RESULTS: usize = 7;
const UPDATE_TIMEOUT_OK_SECS: u64 = 30;
const UPDATE_TIMEOUT_ERR_SECS: u64 = 2;

Expand Down Expand Up @@ -225,7 +231,7 @@ mod tests {

fn time_checker() -> TimeChecker<FakeNtp> {
let last_result = Arc::new(RwLock::new(
(Instant::now(), vec![Err(Error::Ntp("NTP server unavailable.".into()))].into())
(Instant::now(), vec![Err(Error::Ntp("NTP server unavailable".into()))].into())
));

TimeChecker {
Expand Down
5 changes: 4 additions & 1 deletion ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct Config {
pub db_wal: bool,
/// Should it do full verification of blocks?
pub verify_full: bool,
/// Should it check the seal of blocks?
pub check_seal: bool,
}

impl Default for Config {
Expand All @@ -69,6 +71,7 @@ impl Default for Config {
db_compaction: CompactionProfile::default(),
db_wal: true,
verify_full: true,
check_seal: true,
}
}
}
Expand Down Expand Up @@ -168,7 +171,7 @@ impl Client {
let gh = ::rlp::encode(&spec.genesis_header());

Ok(Client {
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true),
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, config.check_seal),
engine: spec.engine.clone(),
chain: HeaderChain::new(db.clone(), chain_col, &gh, cache)?,
report: RwLock::new(ClientReport::default()),
Expand Down
34 changes: 25 additions & 9 deletions ethcore/light/src/on_demand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@ struct Peer {
}

impl Peer {
// whether this peer can fulfill the
fn can_fulfill(&self, c: &Capabilities) -> bool {
let caps = &self.capabilities;
// whether this peer can fulfill the necessary capabilities for the given
// request.
fn can_fulfill(&self, request: &Capabilities) -> bool {
let local_caps = &self.capabilities;
let can_serve_since = |req, local| {
match (req, local) {
(Some(request_block), Some(serve_since)) => request_block >= serve_since,
(Some(_), None) => false,
(None, _) => true,
}
};

caps.serve_headers == c.serve_headers &&
caps.serve_chain_since >= c.serve_chain_since &&
caps.serve_state_since >= c.serve_chain_since
local_caps.serve_headers >= request.serve_headers &&
can_serve_since(request.serve_chain_since, local_caps.serve_chain_since) &&
can_serve_since(request.serve_state_since, local_caps.serve_state_since)
}
}

Expand Down Expand Up @@ -244,7 +252,7 @@ impl OnDemand {
peers: RwLock::new(HashMap::new()),
in_transit: RwLock::new(HashMap::new()),
cache: cache,
no_immediate_dispatch: true,
no_immediate_dispatch: false,
}
}

Expand All @@ -266,7 +274,6 @@ impl OnDemand {
-> Result<Receiver<Vec<Response>>, basic_request::NoSuchOutput>
{
let (sender, receiver) = oneshot::channel();

if requests.is_empty() {
assert!(sender.send(Vec::new()).is_ok(), "receiver still in scope; qed");
return Ok(receiver);
Expand Down Expand Up @@ -335,6 +342,7 @@ impl OnDemand {
// dispatch pending requests, and discard those for which the corresponding
// receiver has been dropped.
fn dispatch_pending(&self, ctx: &BasicContext) {

// wrapper future for calling `poll_cancel` on our `Senders` to preserve
// the invariant that it's always within a task.
struct CheckHangup<'a, T: 'a>(&'a mut Sender<T>);
Expand All @@ -360,6 +368,8 @@ impl OnDemand {
if self.pending.read().is_empty() { return }
let mut pending = self.pending.write();

debug!(target: "on_demand", "Attempting to dispatch {} pending requests", pending.len());

// iterate over all pending requests, and check them for hang-up.
// then, try and find a peer who can serve it.
let peers = self.peers.read();
Expand All @@ -378,23 +388,29 @@ impl OnDemand {

match ctx.request_from(*peer_id, pending.net_requests.clone()) {
Ok(req_id) => {
trace!(target: "on_demand", "Dispatched request {} to peer {}", req_id, peer_id);
self.in_transit.write().insert(req_id, pending);
return None
}
Err(net::Error::NoCredits) => {}
Err(net::Error::NoCredits) | Err(net::Error::NotServer) => {}
Err(e) => debug!(target: "on_demand", "Error dispatching request to peer: {}", e),
}
}

// TODO: maximum number of failures _when we have peers_.
Some(pending)
})
.collect(); // `pending` now contains all requests we couldn't dispatch.

debug!(target: "on_demand", "Was unable to dispatch {} requests.", pending.len());
}

// submit a pending request set. attempts to answer from cache before
// going to the network. if complete, sends response and consumes the struct.
fn submit_pending(&self, ctx: &BasicContext, mut pending: Pending) {
// answer as many requests from cache as we can, and schedule for dispatch
// if incomplete.

pending.answer_from_cache(&*self.cache);
if let Some(mut pending) = pending.try_complete() {
pending.update_net_requests();
Expand Down
3 changes: 2 additions & 1 deletion js/src/redux/providers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ export default class Status {

_overallStatus = (health) => {
const all = [health.peers, health.sync, health.time].filter(x => x);
const allNoTime = [health.peers, health.sync].filter(x => x);
const statuses = all.map(x => x.status);
const bad = statuses.find(x => x === STATUS_BAD);
const needsAttention = statuses.find(x => x === STATUS_WARN);
const needsAttention = allNoTime.map(x => x.status).find(x => x === STATUS_WARN);
const message = all.map(x => x.message).filter(x => x);

if (all.length) {
Expand Down
2 changes: 1 addition & 1 deletion js/src/redux/providers/statusReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const initialState = {
status: DEFAULT_STATUS
},
overall: {
isReady: false,
isNotReady: true,
status: DEFAULT_STATUS,
message: []
}
Expand Down
31 changes: 22 additions & 9 deletions js/src/secureApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@ export default class SecureApi extends Api {
return 'dapps.parity';
}

const { host } = this._dappsAddress;

if (!host || host === '0.0.0.0') {
return window.location.hostname;
}

return host;
return this._dappsAddress.host;
}

get isConnecting () {
Expand Down Expand Up @@ -173,6 +167,25 @@ export default class SecureApi extends Api {
});
}

/**
* Resolves a wildcard address to `window.location.hostname`;
*/
_resolveHost (url) {
const parts = url ? url.split(':') : [];
const port = parts[1];
let host = parts[0];

if (!host) {
return host;
}

if (host === '0.0.0.0') {
host = window.location.hostname;
}

return port ? `${host}:${port}` : host;
}

/**
* Returns a Promise that gets resolved with
* a boolean: `true` if the node is up, `false`
Expand Down Expand Up @@ -316,8 +329,8 @@ export default class SecureApi extends Api {
this._uiApi.parity.wsUrl()
])
.then(([dappsUrl, wsUrl]) => {
this._dappsUrl = dappsUrl;
this._wsUrl = wsUrl;
this._dappsUrl = this._resolveHost(dappsUrl);
this._wsUrl = this._resolveHost(wsUrl);
});
}

Expand Down
2 changes: 1 addition & 1 deletion js/src/views/SyncWarning/syncWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SyncWarning extends Component {

function mapStateToProps (state) {
const { health } = state.nodeStatus;
const isNotAvailableYet = health.overall.isReady;
const isNotAvailableYet = health.overall.isNotReady;
const isOk = isNotAvailableYet || health.overall.status === 'ok';

return {
Expand Down
Loading

0 comments on commit 65e4bad

Please sign in to comment.