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 40 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ light-client-js/pkg/
light-client-js/examples/verifier-web/node_modules/
light-client-js/examples/verifier-web/dist/
light-client-js/examples/verifier-web/package-lock.json

# clion
.idea
xla marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ description = """
chacha20poly1305 = "0.7"
ed25519-dalek = "1"
eyre = "0.6"
anyhow = "1.0"
xla marked this conversation as resolved.
Show resolved Hide resolved
flume = "0.10"
hkdf = "0.10.0"
merlin = "2"
Expand All @@ -30,7 +31,6 @@ subtle-encoding = { version = "0.5" }
thiserror = "1"
x25519-dalek = "1.1"
zeroize = "1"

xla marked this conversation as resolved.
Show resolved Hide resolved
# path dependencies
tendermint = { path = "../tendermint", version = "0.19.0" }
tendermint-proto = { path = "../proto", version = "0.19.0" }
Expand Down
4 changes: 2 additions & 2 deletions p2p/src/secret_connection/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ed25519_dalek as ed25519;
use sha2::{digest::Digest, Sha256};
use std::fmt::{self, Display};
use tendermint::{
error::{self, Error},
error::{self, KindError as Error},
node,
};

Expand All @@ -20,7 +20,7 @@ impl PublicKey {
pub fn from_raw_ed25519(bytes: &[u8]) -> Result<PublicKey, Error> {
ed25519::PublicKey::from_bytes(bytes)
.map(PublicKey::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
71 changes: 50 additions & 21 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,65 @@ rustdoc-args = ["--cfg", "docsrs"]
crate-type = ["cdylib", "rlib"]

[dependencies]
anomaly = "0.2"
anyhow = {version = "1.0", default-features = false}
flex-error = { version = "0.2.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.19.0", path = "../proto" }
toml = { version = "0.5" }
url = { version = "2.2" }
zeroize = { version = "1.1", features = ["zeroize_derive"] }

k256 = { version = "0.8", optional = true, features = ["ecdsa"] }
ripemd160 = { version = "0.9", optional = true }
zeroize = { version = "1.1", default-features = false, features = ["zeroize_derive", "alloc"] }
k256 = { version = "0.7", default-features = false, optional = true, features = ["ecdsa"] }
ripemd160 = { version = "0.9", default-features = false, optional = true }
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
displaydoc = {version = "0.2", default-features = false }

[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',
'no-std-compat/std',
'flex-error/std',
'anyhow/std',
'displaydoc/std',
]

[dev-dependencies]
proptest = "0.10.1"
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,8 +5,10 @@
//!
//! <https://tendermint.com/docs/spec/abci/apps.html#gas>

use crate::{Error, Kind};
use crate::error::{self, KindError as Error};
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::prelude::v1::format;
use std::string::{String, ToString};
use std::{
fmt::{self, Display},
str::FromStr,
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 std::string::String;

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

/// ABCI log data
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
6 changes: 4 additions & 2 deletions tendermint/src/abci/path.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Paths to ABCI data

use crate::error::Error;
use crate::error::KindError as Error;
use serde::{Deserialize, Serialize};
use std::string::String;
use std::{
borrow::ToOwned,
fmt::{self, Display},
str::FromStr,
};
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::string::String;
use std::{
fmt::{self, Display},
vec::Vec,
};

/// Responses for ABCI calls which occur during block processing.
///
Expand Down
7 changes: 4 additions & 3 deletions tendermint/src/abci/tag.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Tags

use crate::error::Error;
use crate::error::KindError as Error;
use serde::{Deserialize, Serialize};
use std::string::String;
use std::{fmt, str::FromStr};
use tendermint_proto::serializers::bytes::base64string;

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
3 changes: 3 additions & 0 deletions tendermint/src/abci/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ mod hash;

pub use self::hash::Hash;
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::prelude::v1::format;
use std::prelude::v1::*;
use std::string::String;
use std::{fmt, slice};
use subtle_encoding::base64;
use tendermint_proto::types::Data as RawData;
Expand Down
11 changes: 8 additions & 3 deletions tendermint/src/abci/transaction/hash.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
//! Transaction hashes

use crate::error::{Error, Kind};
use crate::error::{self, KindError as Error};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

use std::{
fmt::{self, Debug, Display},
str::FromStr,
};

use std::prelude::v1::format;
use std::string::{String, ToString};

use subtle::{self, ConstantTimeEq};
use subtle_encoding::hex;

Expand Down Expand Up @@ -64,10 +69,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
13 changes: 7 additions & 6 deletions tendermint/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Tendermint accounts

use crate::{
error::{Error, Kind},
public_key::Ed25519,
};
use crate::error::{self, KindError as Error};
use crate::public_key::Ed25519;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use sha2::{Digest, Sha256};
Expand All @@ -20,6 +18,9 @@ use crate::public_key::Secp256k1;
#[cfg(feature = "secp256k1")]
use ripemd160::Ripemd160;
use std::convert::TryFrom;
use std::prelude::v1::format;
use std::string::String;
use std::vec::Vec;
use tendermint_proto::Protobuf;

/// Size of an account ID in bytes
Expand All @@ -36,7 +37,7 @@ impl TryFrom<Vec<u8>> for Id {

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
if value.len() != LENGTH {
return Err(Kind::InvalidAccountIdLength.into());
return Err(error::invalid_account_id_length_error());
}
let mut slice: [u8; LENGTH] = [0; LENGTH];
slice.copy_from_slice(&value[..]);
Expand Down Expand Up @@ -118,7 +119,7 @@ impl FromStr for Id {
// Accept either upper or lower case hex
let bytes = hex::decode_upper(s)
.or_else(|_| hex::decode(s))
.map_err(|_| Kind::Parse.context("account id decode"))?;
.map_err(|_| error::parse_error("id decode".into()))?;

bytes.try_into()
}
Expand Down
Loading