Skip to content

Commit

Permalink
Merge pull request DMDcoin#96 from dforsten/dforsten/hbbft_no_failure
Browse files Browse the repository at this point in the history
Using a version of hbbft/threshold_crypto not using the deprecated "failure" crate
Testet in alpha2 without encountering problems
  • Loading branch information
SurfingNerd authored Jan 29, 2024
2 parents 0fe2000 + a460408 commit d9997ea
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 473 deletions.
490 changes: 133 additions & 357 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/accounts/ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ itertools = "0.5"
parking_lot = "0.11.1"
parity-crypto = { version = "0.6.2", features = [ "publickey"] }
ethereum-types = "0.9.2"
smallvec = "0.6"
smallvec = "0.6.14"
parity-wordlist = "1.3"
tempdir = "0.3"
lazy_static = "1.2.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ethkey = { path = "../accounts/ethkey" }
evm = { path = "../vm/evm" }
globset = "0.4"
hash-db = "0.11.0"
hbbft = { git = "https://github.com/surfingnerd/hbbft", rev = "cf0c45aa669b9c10abab1a0f4f2b33595879b60b" }
hbbft_testing = { git = "https://github.com/poanetwork/hbbft" }
hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" }
hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" }
hex_fmt = "0.3.0"
itertools = "0.5"
journaldb = { path = "../db/journaldb" }
Expand Down
6 changes: 3 additions & 3 deletions crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn engine_signer_to_synckeygen<'a>(
.expect("Signer's public key must be available!"),
None => Public::from(H512::from_low_u64_be(0)),
};
let mut rng = rand_065::thread_rng();
let mut rng = rand::thread_rng();
let num_nodes = pub_keys.len();
SyncKeyGen::new(public, wrapper, pub_keys, max_faulty(num_nodes), &mut rng)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn part_of_address(
return Ok(None);
}
let deserialized_part: Part = bincode::deserialize(&serialized_part).unwrap();
let mut rng = rand_065::thread_rng();
let mut rng = rand::thread_rng();
let outcome = skg
.handle_part(vmap.get(&address).unwrap(), deserialized_part, &mut rng)
.unwrap();
Expand Down Expand Up @@ -171,7 +171,7 @@ pub struct KeyPairWrapper {
impl<'a> PublicKey for PublicWrapper {
type Error = crypto::publickey::Error;
type SecretKey = KeyPairWrapper;
fn encrypt<M: AsRef<[u8]>, R: rand_065::Rng>(
fn encrypt<M: AsRef<[u8]>, R: rand::Rng>(
&self,
msg: M,
_rng: &mut R,
Expand Down
4 changes: 2 additions & 2 deletions crates/ethcore/src/engines/hbbft/contribution.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand_065::{self, distributions::Standard, Rng};
use rand::{self, distributions::Standard, Rng};
use rlp::RlpStream;
use std::time::UNIX_EPOCH;
use types::transaction::SignedTransaction;
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Contribution {
s.drain()
})
.collect();
let mut rng = rand_065::thread_rng();
let mut rng = rand::thread_rng();

Contribution {
transactions: ser_txns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ ethcore = { path = "../../../.." }
ethereum-types = "0.9.2"
ethkey = { path = "../../../../../accounts/ethkey" }
ethstore = { path = "../../../../../accounts/ethstore"}
hbbft = { git = "https://github.com/poanetwork/hbbft", rev = "4857b7f9c7a0f513caca97c308d352c6a77fe5c2" }
hbbft_testing = { git = "https://github.com/poanetwork/hbbft" }
hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" }
hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" }
parity-crypto = { version = "0.6.2", features = ["publickey"] }
rand = "0.6.5"
rand = "0.7.3"
rustc-hex = "2.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/ethcore/src/engines/hbbft/hbbft_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,13 +1669,13 @@ mod tests {
honey_badger::{HoneyBadger, HoneyBadgerBuilder},
NetworkInfo,
};
use rand_065;
use rand;
use std::sync::Arc;
use types::transaction::SignedTransaction;

#[test]
fn test_single_contribution() {
let mut rng = rand_065::thread_rng();
let mut rng = rand::thread_rng();
let net_infos = NetworkInfo::generate_map(0..1usize, &mut rng)
.expect("NetworkInfo generation is expected to always succeed");

Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/src/engines/hbbft/hbbft_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ impl HbbftState {
// Now we can select the transactions to include in our contribution.
let input_contribution = Contribution::new(&signed_transactions);

let mut rng = rand_065::thread_rng();
let mut rng = rand::thread_rng();
let step = honey_badger.propose(&input_contribution, &mut rng);
match step {
Ok(step) => Some((step, network_info)),
Expand Down
4 changes: 2 additions & 2 deletions crates/ethcore/src/engines/hbbft/sealing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ impl Decodable for RlpSig<Signature> {
#[cfg(test)]
mod tests {
use super::*;
use rand_065;
use rand;
use rlp;

#[test]
fn test_rlp_signature() {
let sig: Signature = rand_065::random();
let sig: Signature = rand::random();
let encoded = rlp::encode(&RlpSig(&sig));
let decoded: RlpSig<Signature> = rlp::decode(&encoded).expect("decode RlpSignature");
assert_eq!(decoded.0, sig);
Expand Down
1 change: 0 additions & 1 deletion crates/ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ extern crate parity_util_mem;
extern crate parking_lot;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rand;
extern crate rand_065;
extern crate rayon;
extern crate reth_util;
extern crate rlp;
Expand Down
3 changes: 1 addition & 2 deletions crates/net/network-devp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ mio = "0.6.8"
bytes = "0.4"
rand = "0.7.3"
tiny-keccak = "1.4"
rust-crypto = "0.2.34"
slab = "0.2"
igd = "0.7"
igd = "0.8"
libc = "0.2.7"
parking_lot = "0.11.1"
ansi_term = "0.10"
Expand Down
1 change: 0 additions & 1 deletion crates/net/network-devp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

extern crate ansi_term; //TODO: remove this
extern crate bytes;
extern crate crypto as rcrypto;
extern crate ethcore_io as io;
extern crate ethcore_network as network;
extern crate ethereum_types;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/v1/helpers/eip191.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn hash_message(version: EIP191Version, message: Value) -> Result<H256, Erro
let typed_data =
from_value::<EIP712>(message).map_err(map_serde_err("StructuredData"))?;

hash_structured_data(typed_data).map_err(|err| errors::invalid_call_data(err.kind()))?
hash_structured_data(typed_data).map_err(|err| errors::invalid_call_data(err))?
}

EIP191Version::PresignedTransaction => {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/v1/impls/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<D: Dispatcher + 'static> Personal for PersonalClient<D> {

let data = match hash_structured_data(typed_data) {
Ok(d) => d,
Err(err) => return Box::new(future::err(errors::invalid_call_data(err.kind()))),
Err(err) => return Box::new(future::err(errors::invalid_call_data(err))),
};
let dispatcher = self.dispatcher.clone();
let accounts = Arc::new(dispatch::Signer::new(self.accounts.clone())) as _;
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Parity Technologies <[email protected]>"]
[dependencies]
fnv = "1.0"
mio = { version = "0.6.8", optional = true }
crossbeam-deque = "0.6"
crossbeam-deque = "0.7.4"
parking_lot = "0.11.1"
log = "0.4"
slab = "0.4"
Expand Down
8 changes: 2 additions & 6 deletions crates/runtime/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ mod tests {
struct MyHandler(atomic::AtomicBool);

#[derive(Clone)]
struct MyMessage {
data: u32,
}
struct MyMessage {}

impl IoHandler<MyMessage> for MyHandler {
fn initialize(&self, io: &IoContext<MyMessage>) {
Expand Down Expand Up @@ -285,9 +283,7 @@ mod tests {
struct MyHandler(atomic::AtomicUsize);

#[derive(Clone)]
struct MyMessage {
data: u32,
}
struct MyMessage {}

impl IoHandler<MyMessage> for MyHandler {
fn initialize(&self, io: &IoContext<MyMessage>) {
Expand Down
3 changes: 2 additions & 1 deletion crates/runtime/io/src/service_mio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ where
event_loop: &mut EventLoop<IoManager<Message>>,
handlers: Arc<RwLock<Slab<Arc<dyn IoHandler<Message>>>>>,
) -> Result<(), IoError> {
let (worker, stealer) = deque::fifo();
let worker = deque::Worker::new_fifo();
let stealer = worker.stealer();
let num_workers = 4;
let work_ready_mutex = Arc::new(Mutex::new(()));
let work_ready = Arc::new(Condvar::new());
Expand Down
9 changes: 5 additions & 4 deletions crates/runtime/io/src/service_non_mio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ where
pub fn start(_symbolic_name: &'static str) -> Result<IoService<Message>, IoError> {
// This minimal implementation of IoService does have named Workers
// like the mio-dependent one does, so _symbolic_name is ignored.
let (tx, rx) = deque::fifo();
let tx = deque::Worker::new_fifo();
let rx = tx.stealer();

let shared = Arc::new(Shared {
handlers: RwLock::new(Slab::with_capacity(MAX_HANDLERS)),
Expand Down Expand Up @@ -370,8 +371,8 @@ where
match rx.steal() {
deque::Steal::Retry => continue,
deque::Steal::Empty => thread::park(),
deque::Steal::Data(WorkTask::Shutdown) => break,
deque::Steal::Data(WorkTask::UserMessage(message)) => {
deque::Steal::Success(WorkTask::Shutdown) => break,
deque::Steal::Success(WorkTask::UserMessage(message)) => {
for id in 0..MAX_HANDLERS {
if let Some(handler) = shared.handlers.read().get(id) {
let ctxt = IoContext {
Expand All @@ -382,7 +383,7 @@ where
}
}
}
deque::Steal::Data(WorkTask::TimerTrigger { handler_id, token }) => {
deque::Steal::Success(WorkTask::TimerTrigger { handler_id, token }) => {
if let Some(handler) = shared.handlers.read().get(handler_id) {
let ctxt = IoContext {
handler: handler_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/io/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Worker {

while !deleting.load(AtomicOrdering::SeqCst) {
match stealer.steal() {
deque::Steal::Data(work) => {
deque::Steal::Success(work) => {
Worker::do_work(work, channel.clone())
}
deque::Steal::Retry => {}
Expand Down
2 changes: 1 addition & 1 deletion crates/util/EIP-712/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ethabi = "12.0.0"
keccak-hash = "0.5.0"
ethereum-types = "0.9.2"
logos = "0.12.0"
failure = "0.1.7"
thiserror = "1.0"
itertools = "0.7"
lazy_static = "1.1"
regex = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/util/EIP-712/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ mod tests {

let typed_data = from_str::<EIP712>(TEST).expect("alas error!");
assert_eq!(
hash_structured_data(typed_data).unwrap_err().kind(),
hash_structured_data(typed_data).unwrap_err(),
ErrorKind::UnequalArrayItems(2, "Person[2]".into(), 1)
)
}
Expand Down
93 changes: 16 additions & 77 deletions crates/util/EIP-712/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,101 +14,40 @@
// You should have received a copy of the GNU General Public License
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.

use failure::{Backtrace, Context, Fail};
use std::fmt::{self, Display};
use thiserror::Error;
use validator::{ValidationErrors, ValidationErrorsKind};

pub(crate) type Result<T> = ::std::result::Result<T, Error>;
/// Error type
#[derive(Debug)]
pub struct Error {
inner: Context<ErrorKind>,
}
/// Possible errors encountered while hashing/encoding an EIP-712 compliant data structure
#[derive(Clone, Fail, Debug, PartialEq)]
pub(crate) type Result<T> = ::std::result::Result<T, ErrorKind>;

#[derive(Error, Debug, PartialEq)]
pub enum ErrorKind {
/// if we fail to deserialize from a serde::Value as a type specified in message types
/// fail with this error.
#[fail(display = "Expected type '{}' for field '{}'", _0, _1)]
#[error("Expected type '{0}' for field '{1}'")]
UnexpectedType(String, String),
/// the primary type supplied doesn't exist in the MessageTypes
#[fail(display = "The given primaryType wasn't found in the types field")]
#[error("The given primaryType wasn't found in the types field")]
NonExistentType,
/// an invalid address was encountered during encoding
#[fail(
display = "Address string should be a 0x-prefixed 40 character string, got '{}'",
_0
)]
#[error("Address string should be a 0x-prefixed 40 character string, got '{0}'")]
InvalidAddressLength(usize),
/// a hex parse error occured
#[fail(display = "Failed to parse hex '{}'", _0)]
#[error("Failed to parse hex '{0}'")]
HexParseError(String),
/// the field was declared with a unknown type
#[fail(display = "The field '{}' has an unknown type '{}'", _0, _1)]
#[error("The field '{0}' has an unknown type '{1}'")]
UnknownType(String, String),
/// Unexpected token
#[fail(display = "Unexpected token '{}' while parsing typename '{}'", _0, _1)]
#[error("Unexpected token '{0}' while parsing typename '{1}'")]
UnexpectedToken(String, String),
/// the user has attempted to define a typed array with a depth > 10
#[fail(display = "Maximum depth for nested arrays is 10")]
#[error("Maximum depth for nested arrays is 10")]
UnsupportedArrayDepth,
/// FieldType validation error
#[fail(display = "{}", _0)]
#[error("{0}")]
ValidationError(String),
/// the typed array defined in message types was declared with a fixed length
/// that is of unequal length with the items to be encoded
#[fail(
display = "Expected {} items for array type {}, got {} items",
_0, _1, _2
)]
#[error("Expected {0} items for array type {1}, got {2} items")]
UnequalArrayItems(u64, String, u64),
/// Typed array length doesn't fit into a u64
#[fail(display = "Attempted to declare fixed size with length {}", _0)]
#[error("Attempted to declare fixed size with length {0}")]
InvalidArraySize(String),
}

pub(crate) fn serde_error(expected: &str, field: Option<&str>) -> ErrorKind {
ErrorKind::UnexpectedType(expected.to_owned(), field.unwrap_or("").to_owned())
}

impl Fail for Error {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}

fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.inner, f)
}
}

impl Error {
/// extract the error kind
pub fn kind(&self) -> ErrorKind {
self.inner.get_context().clone()
}
}

impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
Error {
inner: Context::new(kind),
}
}
}

impl From<Context<ErrorKind>> for Error {
fn from(inner: Context<ErrorKind>) -> Error {
Error { inner }
}
}

impl From<ValidationErrors> for Error {
impl From<ValidationErrors> for ErrorKind {
fn from(error: ValidationErrors) -> Self {
let mut string: String = "".into();
for (field_name, error_kind) in error.errors() {
Expand All @@ -128,6 +67,6 @@ impl From<ValidationErrors> for Error {
),
}
}
ErrorKind::ValidationError(string).into()
ErrorKind::ValidationError(string)
}
}
2 changes: 0 additions & 2 deletions crates/util/EIP-712/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,3 @@ mod parser;
pub use crate::eip712::EIP712;
/// the EIP-712 encoding function
pub use crate::encode::hash_structured_data;
/// encoding Error types
pub use crate::error::{Error, ErrorKind};

0 comments on commit d9997ea

Please sign in to comment.