Skip to content

Commit

Permalink
Fix a few merge hicks (catch up with latest changes from master)
Browse files Browse the repository at this point in the history
rename some vars and more logical bisection in cmd
  • Loading branch information
liamsi committed Feb 8, 2020
1 parent 7cc055f commit 02cb776
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 77 deletions.
49 changes: 15 additions & 34 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ use crate::prelude::*;
use core::future::Future;
use tendermint::hash;
use tendermint::lite;
use tendermint::lite::{Error, Header, Requester, SignedHeader, Store, TrustedState};
use tendermint::lite::{Error, Header, Height, Requester, TrustThresholdFraction};
use tendermint::rpc;
use tendermint::{block::Height, Hash};
use tendermint::Hash;
use tokio::runtime::Builder;

use tendermint::lite::ValidatorSet as _;

use crate::config::LightNodeConfig;
use crate::requester::RPCRequester;
use crate::state::State;
use crate::store::MemStore;
use crate::threshold::TrustThresholdOneThird;

use crate::store::{MemStore, State};
use abscissa_core::{config, Command, FrameworkError, Options, Runnable};
use std::time::{Duration, SystemTime};

Expand All @@ -37,11 +34,6 @@ pub struct StartCmd {
rpc_addr: String,
}

// TODO: this should also somehow be configurable ...
// we can't simply add this as a field in the config because this either would
// be a trait (`TrustThreshold`) or immediately and impl thereof (`TrustThresholdOneThird`).
static THRESHOLD: &TrustThresholdOneThird = &TrustThresholdOneThird {};

impl Runnable for StartCmd {
/// Start the application.
fn run(&self) {
Expand All @@ -59,46 +51,35 @@ impl Runnable for StartCmd {

println!("Requesting from {}.", config.rpc_address);

subjective_init(
Height::from(config.subjective_init.height),
vals_hash,
&mut store,
&req,
)
.unwrap();
subjective_init(config.subjective_init.height, vals_hash, &mut store, &req).unwrap();

loop {
let latest = (&req).signed_header(0).unwrap();
let latest_peer_height = latest.header().height();
let latest_sh = (&req).signed_header(0).unwrap();
let latest_peer_height = latest_sh.header().height();

let latest = store.get(Height::from(0)).unwrap();
let latest_height = latest.last_header().header().height();
let latest_trusted = store.get(0).unwrap();
let latest_trusted_height = latest_trusted.last_header().header().height();

// only bisect to higher heights
if latest_peer_height <= latest_height {
if latest_peer_height <= latest_trusted_height {
std::thread::sleep(Duration::new(1, 0));
continue;
}

println!(
"attempting bisection from height {:?} to height {:?}",
store
.get(Height::from(0))
.unwrap()
.last_header()
.header()
.height(),
latest_trusted_height,
latest_peer_height,
);

let now = &SystemTime::now();
lite::verify_and_update_bisection(
lite::verify_bisection(
latest_trusted.to_owned(),
latest_peer_height,
THRESHOLD, // TODO
TrustThresholdFraction::default(), // TODO
&config.trusting_period,
now,
&req,
&mut store,
)
.unwrap();

Expand Down Expand Up @@ -159,13 +140,13 @@ fn subjective_init(

// TODO: validate signed_header.commit() with the vals ...

let next_vals = req.validator_set(height.increment())?;
let next_vals = req.validator_set(height + 1)?;

// TODO: check next_vals ...

let trusted_state = &State::new(&signed_header, &next_vals);

store.add(trusted_state)?;
store.add(trusted_state.to_owned())?;

Ok(())
}
Expand Down
2 changes: 0 additions & 2 deletions light-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ pub mod config;
pub mod error;
pub mod prelude;
pub mod requester;
pub mod state;
pub mod store;
pub mod threshold;
30 changes: 0 additions & 30 deletions light-node/src/state.rs

This file was deleted.

11 changes: 0 additions & 11 deletions light-node/src/threshold.rs

This file was deleted.

0 comments on commit 02cb776

Please sign in to comment.