Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable tendermint no_std and error handle by flex-error #890

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2e97844
Enable no_std support
en Apr 20, 2021
601b91f
fix tendermint Cargo.toml, add 'default-features' to use no_std
Apr 20, 2021
3cba120
fix tendermint soure code to support no_std, but now have some error,…
Apr 22, 2021
9a74165
fix: set config,net default std
Apr 22, 2021
fdbf551
move anomaly
Apr 22, 2021
f1a3acb
fix ..
Apr 25, 2021
03df333
remove anomaly and replace anyhow
May 18, 2021
7218ea0
add some fix, but have error
May 18, 2021
ce4448a
update ...
May 19, 2021
8d03730
update ...
May 19, 2021
9613130
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 19, 2021
6cb2a0b
modify primitive no_std_time mod
May 23, 2021
06a09a9
supprot tendermint no_std features
Apr 20, 2021
3ebcc4c
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 23, 2021
9a0ce8c
Merge branch 'master' into octopus-no-std
DaviRain-Su May 23, 2021
d8ff8d9
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 23, 2021
9381876
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 24, 2021
10a4082
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 24, 2021
d66f3c0
Merge branch 'octopus-no-std' of github.com:octopus-network/tendermin…
May 24, 2021
281b540
fix proto to support no_std
May 26, 2021
0b33a89
add flex-error
Jun 1, 2021
1034095
add Infallible ChronoParse SubtleEncoding SerdeJson Toml error
Jun 2, 2021
535d6a4
reset temdermint-proto
Jun 3, 2021
07f7026
fix some bugs
Jun 3, 2021
10105bb
remove tendermint-proro error handle anomaly replace anyhow
Jun 4, 2021
9e18096
reset tendermint-proto
Jun 4, 2021
ea319d7
update ...
Jun 4, 2021
d49781c
update tendermint-p2p, error handle use anyhow
Jun 4, 2021
3536964
add Parse, ParseInt, ParseUrl error
Jun 9, 2021
a901c8e
remove IntegerOverflow DisplayError
Jun 9, 2021
90ce955
renove NegativeVakudatorIndex DisplayError
Jun 9, 2021
58bf0da
renove NoVoteFound DisplayError
Jun 9, 2021
87af5f4
renove NegativePower DisplayError
Jun 9, 2021
bd6f32a
renove InvalidMessageType DisplayError
Jun 9, 2021
19f569e
renove MissingPublicKey DisplayError
Jun 9, 2021
685f538
renove some DisplayError
Jun 9, 2021
667ba43
renove some DisplayError
Jun 9, 2021
5d1589b
update tenderint cargo.toml
Jun 9, 2021
ae835fe
add From trait
Jun 9, 2021
9d5c940
format code
Jun 9, 2021
47a1a38
remove p2p project anyhow crate and update .gitignore
Jun 10, 2021
abbf5c1
foramt p2p Cargo.toml
Jun 10, 2021
dafcf13
format code
Jun 10, 2021
f790c3b
update Cargo.toml
Jun 10, 2021
23504a7
fix bug
Jun 10, 2021
4557ea6
upgrate k256 version
Jun 11, 2021
2de7c9e
update Infallible error
Jun 11, 2021
1dd613a
Remove Infallible and implement Into for Timestamp directly
Jun 11, 2021
467dd56
fix error
Jun 17, 2021
cbc7f4c
Merge upstream
Jun 23, 2021
341a041
Format code
Jun 23, 2021
437c96e
fix clippy
Jun 23, 2021
ce34310
format code
Jun 23, 2021
47bab2f
Merge Upstream
Jun 29, 2021
26e972b
Update no_std Used by sp-std replace no-std-compat
Jun 29, 2021
0bccca1
fix bug
Jul 10, 2021
3ce0bbb
Update flex-error version and git registry
Jul 10, 2021
8540fe7
Update ...
Jul 28, 2021
d4d0b44
Merge upstream
Jul 28, 2021
6225e76
Update tendermint Error
Jul 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions light-client/src/components/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ impl Verifier for ProdVerifier {
&*self.voting_power_calculator,
&*self.commit_validator,
&*self.hasher,
&trusted,
&untrusted,
trusted,
untrusted,
options,
now,
)
Expand Down
2 changes: 1 addition & 1 deletion light-client/src/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod prod {
#[pre(self.peer_map.contains_key(&peer))]
fn rpc_client_for(&self, peer: PeerId) -> Result<rpc::HttpClient, IoError> {
let peer_addr = self.peer_map.get(&peer).unwrap().to_owned();
Ok(rpc::HttpClient::new(peer_addr).map_err(IoError::from)?)
rpc::HttpClient::new(peer_addr).map_err(IoError::from)
}
}
}
4 changes: 2 additions & 2 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ impl LightClient {
/// should be trusted based on a previously verified light block.
/// - When doing _forward_ verification, the Scheduler component decides which height to try to
/// verify next, in case the current block pass verification but cannot be trusted yet.
/// - When doing _backward_ verification, the Hasher component is used to determine
/// whether the `last_block_id` hash of a block matches the hash of the block right below it.
/// - When doing _backward_ verification, the Hasher component is used to determine whether the
/// `last_block_id` hash of a block matches the hash of the block right below it.
///
/// ## Implements
/// - [LCV-DIST-SAFE.1]
Expand Down
4 changes: 2 additions & 2 deletions light-client/src/peer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<T> PeerList<T> {
/// - The given peer id must not be the primary peer id.
/// - The given peer must be in the witness list
#[pre(faulty_witness != self.primary && self.witnesses.contains(&faulty_witness))]
#[post(Self::invariant(&self))]
#[post(Self::invariant(self))]
pub fn replace_faulty_witness(&mut self, faulty_witness: PeerId) -> Option<PeerId> {
let mut result = None;

Expand All @@ -137,7 +137,7 @@ impl<T> PeerList<T> {
///
/// ## Errors
/// - If there are no witness left, returns `ErrorKind::NoWitnessLeft`.
#[post(ret.is_ok() ==> Self::invariant(&self))]
#[post(ret.is_ok() ==> Self::invariant(self))]
pub fn replace_faulty_primary(
&mut self,
primary_error: Option<Error>,
Expand Down
6 changes: 3 additions & 3 deletions light-client/src/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ pub fn verify(
vp.is_header_from_past(&untrusted.signed_header.header, options.clock_drift, now)?;

// Ensure the header validator hashes match the given validators
vp.validator_sets_match(&untrusted, &*hasher)?;
vp.validator_sets_match(untrusted, &*hasher)?;

// Ensure the header next validator hashes match the given next validators
vp.next_validators_match(&untrusted, &*hasher)?;
vp.next_validators_match(untrusted, &*hasher)?;

// Ensure the header matches the commit
vp.header_matches_commit(&untrusted.signed_header, hasher)?;
Expand All @@ -266,7 +266,7 @@ pub fn verify(
if untrusted.height() == trusted_next_height {
// If the untrusted block is the very next block after the trusted block,
// check that their (next) validator sets hashes match.
vp.valid_next_validator_set(&untrusted, trusted)?;
vp.valid_next_validator_set(untrusted, trusted)?;
} else {
// Otherwise, ensure that the untrusted block has a greater height than
// the trusted block.
Expand Down
2 changes: 1 addition & 1 deletion light-client/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl Supervisor {
.collect();

self.fork_detector
.detect_forks(verified_block, &trusted_block, witnesses)
.detect_forks(verified_block, trusted_block, witnesses)
}

/// Run the supervisor event loop in the same thread.
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/secret_connection/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PublicKey {
pub fn from_raw_ed25519(bytes: &[u8]) -> Result<Self, Error> {
ed25519::PublicKey::from_bytes(bytes)
.map(Self::Ed25519)
.map_err(|_| error::Kind::Crypto.into())
.map_err(|_| error::crypto_error())
}

/// Get Ed25519 public key
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/abci_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use std::convert::{TryFrom, TryInto};
use tendermint::block;
use tendermint::Error;
use tendermint::error::Error;
use tendermint_proto::abci::ResponseInfo;

/// Request ABCI information from a node
Expand Down
14 changes: 6 additions & 8 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
//!
//! Several client-related features are provided at present:
//!
//! * `http-client` - Provides [`HttpClient`], which is a basic RPC client that
//! interacts with remote Tendermint nodes via **JSON-RPC over HTTP or
//! HTTPS**. This client does not provide [`event::Event`] subscription
//! functionality. See the [Tendermint RPC] for more details.
//! * `websocket-client` - Provides [`WebSocketClient`], which provides full
//! client functionality, including general RPC functionality as well as
//! [`event::Event`] subscription functionality. Can be used over secure
//! (`wss://`) and unsecure (`ws://`) connections.
//! * `http-client` - Provides [`HttpClient`], which is a basic RPC client that interacts with
//! remote Tendermint nodes via **JSON-RPC over HTTP or HTTPS**. This client does not provide
//! [`event::Event`] subscription functionality. See the [Tendermint RPC] for more details.
//! * `websocket-client` - Provides [`WebSocketClient`], which provides full client functionality,
//! including general RPC functionality as well as [`event::Event`] subscription functionality.
//! Can be used over secure (`wss://`) and unsecure (`ws://`) connections.
//!
//! ### Mock Clients
//!
Expand Down
70 changes: 50 additions & 20 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,66 @@ rustdoc-args = ["--cfg", "docsrs"]
crate-type = ["cdylib", "rlib"]

[dependencies]
anomaly = "0.2"
anyhow = {version = "1.0", default-features = false}
flex-error = { version = "0.3.0", default-features = false, features = ["anyhow_tracer"] }
async-trait = "0.1"
bytes = "1.0"
chrono = { version = "0.4", features = ["serde"] }
ed25519 = "1"
ed25519-dalek = { version = "1", features = ["serde"] }
futures = "0.3"
num-traits = "0.2"
once_cell = "1.3"
prost = "0.7"
prost-types = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_bytes = "0.11"
bytes = { version = "1.0", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["serde", "clock"] }
ed25519 = { version = "1", default-features = false }
# use features (u64 backend)
ed25519-dalek = { version = "1", default-features = false, features = ["serde", "u64_backend"] }
# TODO(thane): Remove once https://github.com/myrrlyn/funty/issues/3 is fixed
funty = { version = "=1.1.0", default-features = false }
futures = { version = "0.3", default-features = false }
num-traits = { version = "0.2", default-features = false }
once_cell = { version = "1.3", default-features = false }
prost = { version = "0.7", default-features = false }
prost-types = { version = "0.7", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
# use features (alloc)
serde_json = { version = "1", default-features = false, features = ["alloc"] }
serde_bytes = { version = "0.11", default-features = false }
serde_repr = "0.1"
sha2 = { version = "0.9", default-features = false }
signature = "1.2"
subtle = "2"
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
thiserror = "1"
signature = { version = "1.2", default-features = false }
subtle = { version = "2", default-features = false }
subtle-encoding = { version = "0.5", default-features = false, features = ["bech32-preview"] }
tendermint-proto = { version = "0.21.0", path = "../proto" }
toml = { version = "0.5" }
url = { version = "2.2" }
zeroize = { version = "1.1", features = ["zeroize_derive"] }
zeroize = { version = "1.1", default-features = false, features = ["zeroize_derive", "alloc"] }
k256 = { version = "0.9", default-features = false, optional = true, features = ["ecdsa"] }
ripemd160 = { version = "0.9", default-features = false, optional = true }
sp-std = { version = "3.0.0", default-features = false}
displaydoc = {version = "0.2", default-features = false }

k256 = { version = "0.9", optional = true, features = ["ecdsa"] }
ripemd160 = { version = "0.9", optional = true }

[features]
secp256k1 = ["k256", "ripemd160"]
default = ["std"]
std = [
'bytes/std',
'chrono/std',
'ed25519-dalek/std',
'funty/std',
'futures/std',
'num-traits/std',
'once_cell/std',
'prost/std',
'serde/std',
'serde_json/std',
'serde_bytes/std',
'sha2/std',
'signature/std',
'subtle/std',
'subtle-encoding/std',
'k256/std',
'ripemd160/std',
'sp-std/std',
'flex-error/std',
'anyhow/std',
'displaydoc/std',
]

[dev-dependencies]
pretty_assertions = "0.7.2"
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/abci/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::vec::Vec;

/// ABCI transaction data.
///
Expand Down
10 changes: 7 additions & 3 deletions tendermint/src/abci/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
//!
//! <https://tendermint.com/docs/spec/abci/apps.html#gas>

use crate::{Error, Kind};
use crate::error::{self, Error};
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{self, Display},
str::FromStr,
};
use alloc::format;
use alloc::string::{String, ToString};

/// Gas: representation of transaction processing resource costs
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
Expand Down Expand Up @@ -44,8 +46,10 @@ impl Display for Gas {
impl FromStr for Gas {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
Ok(Self::from(s.parse::<u64>().map_err(|_| Kind::Parse)?))
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s.parse::<u64>().map_err(|e| {
error::parse_int_error("Gas decode error".into(), e)
})?))
}
}

Expand Down
1 change: 1 addition & 0 deletions tendermint/src/abci/info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
use alloc::string::String;

/// ABCI info
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
7 changes: 5 additions & 2 deletions tendermint/src/abci/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::Display;
use std::{
borrow::ToOwned,
fmt::{self, Display},
};
use alloc::string::String;

/// ABCI log data
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
4 changes: 3 additions & 1 deletion tendermint/src/abci/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{
borrow::ToOwned,
fmt::{self, Display},
str::FromStr,
};
use alloc::string::String;

/// Path to ABCI data
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
Expand All @@ -20,7 +22,7 @@ impl Display for Path {
impl FromStr for Path {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Path(s.to_owned()))
}
}
6 changes: 5 additions & 1 deletion tendermint/src/abci/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
use super::{code::Code, data::Data, gas::Gas, info::Info, log::Log, tag::Tag};
use crate::{consensus, serializers, validator};
use serde::{Deserialize, Deserializer, Serialize};
use std::fmt::{self, Display};
use std::{
fmt::{self, Display},
vec::Vec,
};
use alloc::string::String;

/// Responses for ABCI calls which occur during block processing.
///
Expand Down
5 changes: 3 additions & 2 deletions tendermint/src/abci/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{fmt, str::FromStr};
use alloc::string::String;
use tendermint_proto::serializers::bytes::base64string;

/// Tags
Expand Down Expand Up @@ -34,7 +35,7 @@ impl AsRef<str> for Key {
impl FromStr for Key {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Key(s.into()))
}
}
Expand Down Expand Up @@ -64,7 +65,7 @@ impl AsRef<str> for Value {
impl FromStr for Value {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Value(s.into()))
}
}
Expand Down
5 changes: 3 additions & 2 deletions tendermint/src/abci/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ mod hash;

pub use self::hash::Hash;
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::{fmt, slice};
use std::{fmt, prelude::*, slice};
use subtle_encoding::base64;
use tendermint_proto::types::Data as RawData;

use alloc::format;
use alloc::string::String;
/// Transactions are arbitrary byte arrays whose contents are validated by the
/// underlying Tendermint application.
#[derive(Clone, Debug, Eq, PartialEq)] // Custom serde serialization used by RPC /broadcast_tx_async endpoint
Expand Down
8 changes: 5 additions & 3 deletions tendermint/src/abci/transaction/hash.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Transaction hashes

use crate::error::{Error, Kind};
use crate::error::{self, Error};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{self, Debug, Display},
str::FromStr,
};
use alloc::format;
use alloc::string::{String, ToString};
use subtle::{self, ConstantTimeEq};
use subtle_encoding::hex;

Expand Down Expand Up @@ -64,10 +66,10 @@ impl FromStr for Hash {
// Accept either upper or lower case hex
let bytes = hex::decode_upper(s)
.or_else(|_| hex::decode(s))
.map_err(|_| Kind::Parse.context("hash decode"))?;
.map_err(|_| error::parse_error("hash decode error".into()))?;

if bytes.len() != LENGTH {
return Err(Kind::Parse.context("hash length").into());
return Err(error::parse_error("hash length error".into()));
}

let mut result_bytes = [0u8; LENGTH];
Expand Down
Loading