From d1fafacd2eb689980f165b2ce5ebf572bb5c2ac1 Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 9 May 2018 12:14:06 +0200 Subject: [PATCH 1/3] block_header can fail so return Result --- rpc/src/v1/impls/light/parity.rs | 9 ++++----- rpc/src/v1/impls/parity.rs | 6 +++--- rpc/src/v1/traits/parity.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 982c7ff3633..26aab2bf10b 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -390,14 +390,14 @@ impl Parity for ParityClient { }) } - fn block_header(&self, number: Trailing) -> BoxFuture { + fn block_header(&self, number: Trailing) -> BoxFuture> { use ethcore::encoded; let engine = self.light_dispatch.client.engine().clone(); let from_encoded = move |encoded: encoded::Header| { - let header = encoded.decode().expect("decoding error"); // REVIEW: not sure what to do here; what is a decent return value for the error case here? + let header = encoded.decode().map_err(errors::decode)?; let extra_info = engine.extra_info(&header); - RichHeader { + Ok(RichHeader { inner: Header { hash: Some(header.hash().into()), size: Some(encoded.rlp().as_raw().len().into()), @@ -418,9 +418,8 @@ impl Parity for ParityClient { extra_data: Bytes::new(header.extra_data().clone()), }, extra_info: extra_info, - } + }) }; - // Note: Here we treat `Pending` as `Latest`. // Since light clients don't produce pending blocks // (they don't have state) we can safely fallback to `Latest`. diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 08d5147202c..e30c07fc7de 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -428,7 +428,7 @@ impl Parity for ParityClient where }) } - fn block_header(&self, number: Trailing) -> BoxFuture { + fn block_header(&self, number: Trailing) -> BoxFuture> { const EXTRA_INFO_PROOF: &str = "Object exists in blockchain (fetched earlier), extra_info is always available if object exists; qed"; let number = number.unwrap_or_default(); @@ -451,10 +451,10 @@ impl Parity for ParityClient where (header, Some(info)) }; - Box::new(future::ok(RichHeader { + Box::new(future::ok(Ok(RichHeader { inner: header.into(), extra_info: extra.unwrap_or_default(), - })) + }))) } fn ipfs_cid(&self, content: Bytes) -> Result { diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 83d8b19811c..d84d501fdac 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -214,7 +214,7 @@ build_rpc_trait! { /// Get block header. /// Same as `eth_getBlockByNumber` but without uncles and transactions. #[rpc(name = "parity_getBlockHeaderByNumber")] - fn block_header(&self, Trailing) -> BoxFuture; + fn block_header(&self, Trailing) -> BoxFuture>; /// Get IPFS CIDv0 given protobuf encoded bytes. #[rpc(name = "parity_cidV0")] From f0b7d9491d35cf3ccfb60f944f16f7a0e8f18cf3 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 11 May 2018 09:06:21 +0200 Subject: [PATCH 2/3] Restore previous return type based on feedback --- rpc/src/v1/impls/light/parity.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 6 +++--- rpc/src/v1/traits/parity.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 26aab2bf10b..025538fc427 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -390,7 +390,7 @@ impl Parity for ParityClient { }) } - fn block_header(&self, number: Trailing) -> BoxFuture> { + fn block_header(&self, number: Trailing) -> BoxFuture { use ethcore::encoded; let engine = self.light_dispatch.client.engine().clone(); @@ -429,7 +429,7 @@ impl Parity for ParityClient { BlockNumber::Latest | BlockNumber::Pending => BlockId::Latest, }; - Box::new(self.fetcher().header(id).map(from_encoded)) + Box::new(self.fetcher().header(id).and_then(from_encoded)) } fn ipfs_cid(&self, content: Bytes) -> Result { diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index e30c07fc7de..08d5147202c 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -428,7 +428,7 @@ impl Parity for ParityClient where }) } - fn block_header(&self, number: Trailing) -> BoxFuture> { + fn block_header(&self, number: Trailing) -> BoxFuture { const EXTRA_INFO_PROOF: &str = "Object exists in blockchain (fetched earlier), extra_info is always available if object exists; qed"; let number = number.unwrap_or_default(); @@ -451,10 +451,10 @@ impl Parity for ParityClient where (header, Some(info)) }; - Box::new(future::ok(Ok(RichHeader { + Box::new(future::ok(RichHeader { inner: header.into(), extra_info: extra.unwrap_or_default(), - }))) + })) } fn ipfs_cid(&self, content: Bytes) -> Result { diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index d84d501fdac..83d8b19811c 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -214,7 +214,7 @@ build_rpc_trait! { /// Get block header. /// Same as `eth_getBlockByNumber` but without uncles and transactions. #[rpc(name = "parity_getBlockHeaderByNumber")] - fn block_header(&self, Trailing) -> BoxFuture>; + fn block_header(&self, Trailing) -> BoxFuture; /// Get IPFS CIDv0 given protobuf encoded bytes. #[rpc(name = "parity_cidV0")] From 9c399d6a3f248c728a901a21807a8802750675cb Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 11 May 2018 09:06:44 +0200 Subject: [PATCH 3/3] Fix failing doc tests running on non-code --- util/journaldb/src/earlymergedb.rs | 6 +++--- util/journaldb/src/refcounteddb.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/journaldb/src/earlymergedb.rs b/util/journaldb/src/earlymergedb.rs index e76cdcd313a..c26a67e0ad2 100644 --- a/util/journaldb/src/earlymergedb.rs +++ b/util/journaldb/src/earlymergedb.rs @@ -57,7 +57,7 @@ enum RemoveFrom { /// the removals actually take effect. /// /// journal format: -/// ``` +/// ```text /// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, n] => [ ... ] @@ -76,7 +76,7 @@ enum RemoveFrom { /// which includes an original key, if any. /// /// The semantics of the `counter` are: -/// ``` +/// ```text /// insert key k: /// counter already contains k: count += 1 /// counter doesn't contain k: @@ -92,7 +92,7 @@ enum RemoveFrom { /// /// Practically, this means that for each commit block turning from recent to ancient we do the /// following: -/// ``` +/// ```text /// is_canonical: /// inserts: Ignored (left alone in the backing database). /// deletes: Enacted; however, recent history queue is checked for ongoing references. This is diff --git a/util/journaldb/src/refcounteddb.rs b/util/journaldb/src/refcounteddb.rs index 944d81d3733..d182d5cf803 100644 --- a/util/journaldb/src/refcounteddb.rs +++ b/util/journaldb/src/refcounteddb.rs @@ -40,7 +40,7 @@ use util::{DatabaseKey, DatabaseValueView, DatabaseValueRef}; /// the removals actually take effect. /// /// journal format: -/// ``` +/// ```text /// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, n] => [ ... ]