Skip to content

Commit

Permalink
fix rebasing hicks
Browse files Browse the repository at this point in the history
  • Loading branch information
liamsi committed Feb 8, 2020
1 parent 02cb776 commit 5cd3724
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion light-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
gumdrop = "0.7"
serde = { version = "1", features = ["serde_derive"] }
tendermint = { version = "0.11", path = "../tendermint" }
tendermint = { version = "0.12.0-rc0", path = "../tendermint" }
tokio = "0.2"

[dependencies.abscissa_core]
Expand Down
3 changes: 1 addition & 2 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ impl Runnable for StartCmd {

println!(
"attempting bisection from height {:?} to height {:?}",
latest_trusted_height,
latest_peer_height,
latest_trusted_height, latest_peer_height,
);

let now = &SystemTime::now();
Expand Down
25 changes: 10 additions & 15 deletions light-node/src/requester.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use tendermint::block;
use tendermint::lite;
use tendermint::block::signed_header::SignedHeader as TMCommit;
use tendermint::block::Header as TMHeader;
use tendermint::rpc;
use tendermint::validator;
use tendermint::{block, lite};

use core::future::Future;
use tendermint::lite::{Height, SignedHeader};
use tendermint::validator::Set;
use tokio::runtime::Builder;

/// RPCRequester wraps the Tendermint rpc::Client.
Expand All @@ -17,33 +20,26 @@ impl RPCRequester {
}
}

impl lite::types::Requester for RPCRequester {
type SignedHeader = block::signed_header::SignedHeader;
type ValidatorSet = validator::Set;
type TMSignedHeader = SignedHeader<TMCommit, TMHeader>;

impl lite::types::Requester<TMCommit, TMHeader> for RPCRequester {
/// Request the signed header at height h.
/// If h==0, request the latest signed header.
/// TODO: use an enum instead of h==0.
fn signed_header<H>(&self, h: H) -> Result<Self::SignedHeader, lite::Error>
where
H: Into<block::Height>,
{
fn signed_header(&self, h: Height) -> Result<TMSignedHeader, lite::Error> {
let height: block::Height = h.into();
let r = match height.value() {
0 => block_on(self.client.latest_commit()),
_ => block_on(self.client.commit(height)),
};
match r {
Ok(response) => Ok(response.signed_header),
Ok(response) => Ok(response.signed_header.into()),
Err(_error) => Err(lite::Error::RequestFailed),
}
}

/// Request the validator set at height h.
fn validator_set<H>(&self, h: H) -> Result<Self::ValidatorSet, lite::Error>
where
H: Into<block::Height>,
{
fn validator_set(&self, h: Height) -> Result<Set, lite::Error> {
let r = block_on(self.client.validators(h));
match r {
Ok(response) => Ok(validator::Set::new(response.validators)),
Expand All @@ -66,7 +62,6 @@ mod tests {
use super::*;
use tendermint::lite::types::Header as LiteHeader;
use tendermint::lite::types::Requester as LiteRequester;
use tendermint::lite::types::SignedHeader as LiteSignedHeader;
use tendermint::lite::types::ValidatorSet as LiteValSet;
use tendermint::rpc;

Expand Down
21 changes: 10 additions & 11 deletions light-node/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::state::State;
use tendermint::block::Height;
use tendermint::lite::{Error, Header, SignedHeader, Store, TrustedState};
use tendermint::lite::{Error, Header, Height, TrustedState};

use std::collections::HashMap;
use tendermint::block;

pub type State = TrustedState<block::signed_header::SignedHeader, block::header::Header>;

#[derive(Default)]
pub struct MemStore {
Expand All @@ -13,25 +14,23 @@ pub struct MemStore {
impl MemStore {
pub fn new() -> MemStore {
MemStore {
height: Height::from(0),
height: 0,
store: HashMap::new(),
}
}
}

impl Store for MemStore {
type TrustedState = State;

fn add(&mut self, trusted: &Self::TrustedState) -> Result<(), Error> {
impl MemStore {
pub fn add(&mut self, trusted: State) -> Result<(), Error> {
let height = trusted.last_header().header().height();
self.height = height;
self.store.insert(height, trusted.clone());
self.store.insert(height, trusted);
Ok(())
}

fn get(&self, h: Height) -> Result<&Self::TrustedState, Error> {
pub fn get(&self, h: Height) -> Result<&State, Error> {
let mut height = h;
if h.value() == 0 {
if h == 0 {
height = self.height
}
match self.store.get(&height) {
Expand Down

0 comments on commit 5cd3724

Please sign in to comment.