Skip to content

Commit

Permalink
Merge branch 'master' into readable_protocol_version_aware
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed May 27, 2019
2 parents 17c5ffd + 4b88a9b commit 5ce6046
Show file tree
Hide file tree
Showing 25 changed files with 265 additions and 61 deletions.
8 changes: 3 additions & 5 deletions .ci/win.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
diff --git a/Cargo.toml b/Cargo.toml
index fc8615b6..5ffbf06f 100644
index d4cda375..3e3124e9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,8 +45,8 @@ cursive = { version = "0.11.0", default-features = false, features = ["pancurses
@@ -45,8 +45,6 @@ cursive = { version = "0.12", default-features = false, features = ["pancurses-b
[target.'cfg(windows)'.dependencies.pancurses]
version = "0.16.0"
features = ["win32"]
-[target.'cfg(unix)'.dependencies]
-cursive = "0.11.0"
+#[target.'cfg(unix)'.dependencies]
+#cursive = "0.11.0"
-cursive = "0.12"

[build-dependencies]
built = "0.3"
72 changes: 60 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ grin_servers = { path = "./servers", version = "1.1.0-beta.2" }
grin_util = { path = "./util", version = "1.1.0-beta.2" }

[target.'cfg(windows)'.dependencies]
cursive = { version = "0.11.0", default-features = false, features = ["pancurses-backend"] }
cursive = { version = "0.12", default-features = false, features = ["pancurses-backend"] }
[target.'cfg(windows)'.dependencies.pancurses]
version = "0.16.0"
features = ["win32"]
[target.'cfg(unix)'.dependencies]
cursive = "0.11.0"
cursive = "0.12"

[build-dependencies]
built = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ where
}
}

fn build_request<'a>(
url: &'a str,
fn build_request(
url: &str,
method: &str,
api_secret: Option<String>,
body: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions api/tests/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use grin_util as util;
use crate::api::*;
use hyper::{Body, Request, StatusCode};
use std::net::SocketAddr;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::{thread, time};

Expand All @@ -27,7 +27,7 @@ pub struct CounterMiddleware {
impl CounterMiddleware {
fn new() -> CounterMiddleware {
CounterMiddleware {
counter: ATOMIC_USIZE_INIT,
counter: AtomicUsize::new(0),
}
}

Expand Down
5 changes: 4 additions & 1 deletion chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,18 @@ impl Chain {
let is_more_work = head.is_some();

let mut is_next_block = false;
let mut reorg_depth = None;
if let Some(head) = head {
if head.prev_block_h == prev_head.last_block_h {
is_next_block = true;
} else {
reorg_depth = Some(prev_head.height.saturating_sub(head.height) + 1);
}
}

match (is_more_work, is_next_block) {
(true, true) => BlockStatus::Next,
(true, false) => BlockStatus::Reorg,
(true, false) => BlockStatus::Reorg(reorg_depth.unwrap_or(0)),
(false, _) => BlockStatus::Fork,
}
}
Expand Down
16 changes: 9 additions & 7 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl TxHashSet {
/// of blocks to the txhashset and the checking of the current tree roots.
///
/// The unit of work is always discarded (always rollback) as this is read-only.
pub fn extending_readonly<'a, F, T>(trees: &'a mut TxHashSet, inner: F) -> Result<T, Error>
pub fn extending_readonly<F, T>(trees: &mut TxHashSet, inner: F) -> Result<T, Error>
where
F: FnOnce(&mut Extension<'_>) -> Result<T, Error>,
{
Expand Down Expand Up @@ -366,7 +366,7 @@ where

/// Readonly view on the UTXO set.
/// Based on the current txhashset output_pmmr.
pub fn utxo_view<'a, F, T>(trees: &'a TxHashSet, inner: F) -> Result<T, Error>
pub fn utxo_view<F, T>(trees: &TxHashSet, inner: F) -> Result<T, Error>
where
F: FnOnce(&UTXOView<'_>) -> Result<T, Error>,
{
Expand All @@ -391,7 +391,7 @@ where
/// via last_pos.
/// We create a new db batch for this view and discard it (rollback)
/// when we are done with the view.
pub fn rewindable_kernel_view<'a, F, T>(trees: &'a TxHashSet, inner: F) -> Result<T, Error>
pub fn rewindable_kernel_view<F, T>(trees: &TxHashSet, inner: F) -> Result<T, Error>
where
F: FnOnce(&mut RewindableKernelView<'_>) -> Result<T, Error>,
{
Expand Down Expand Up @@ -642,7 +642,7 @@ impl<'a> HeaderExtension<'a> {
/// Get the header at the specified height based on the current state of the header extension.
/// Derives the MMR pos from the height (insertion index) and retrieves the header hash.
/// Looks the header up in the db by hash.
pub fn get_header_by_height(&mut self, height: u64) -> Result<BlockHeader, Error> {
pub fn get_header_by_height(&self, height: u64) -> Result<BlockHeader, Error> {
let pos = pmmr::insertion_to_pmmr_index(height + 1);
if let Some(hash) = self.get_header_hash(pos) {
let header = self.batch.get_block_header(&hash)?;
Expand All @@ -654,7 +654,7 @@ impl<'a> HeaderExtension<'a> {

/// Compares the provided header to the header in the header MMR at that height.
/// If these match we know the header is on the current chain.
pub fn is_on_current_chain(&mut self, header: &BlockHeader) -> Result<(), Error> {
pub fn is_on_current_chain(&self, header: &BlockHeader) -> Result<(), Error> {
let chain_header = self.get_header_by_height(header.height)?;
if chain_header.hash() == header.hash() {
Ok(())
Expand Down Expand Up @@ -949,7 +949,9 @@ impl<'a> Extension<'a> {
}

if output_pos != rproof_pos {
return Err(ErrorKind::Other(format!("output vs rproof MMRs different pos")).into());
return Err(
ErrorKind::Other(format!("output vs rproof MMRs different pos")).into(),
);
}
}

Expand Down Expand Up @@ -991,7 +993,7 @@ impl<'a> Extension<'a> {

/// Compares the provided header to the header in the header MMR at that height.
/// If these match we know the header is on the current chain.
pub fn is_on_current_chain(&mut self, header: &BlockHeader) -> Result<(), Error> {
pub fn is_on_current_chain(&self, header: &BlockHeader) -> Result<(), Error> {
let chain_header = self.get_header_by_height(header.height)?;
if chain_header.hash() == header.hash() {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ pub enum BlockStatus {
Fork,
/// Block updates the chain head via a (potentially disruptive) "reorg".
/// Previous block was not our previous chain head.
Reorg,
Reorg(u64),
}
Loading

0 comments on commit 5ce6046

Please sign in to comment.