Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## Version 1.11.0

- Use modern crates anyhow and thiserror instead of failure

## Version 1.10.4

- Fix build for WASM target
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
build = 'build.rs'
edition = '2021'
name = 'ever_block'
version = '1.10.4'
version = '1.11.0'

[dependencies]
aes-ctr = '0.6'
anyhow = '1.0'
base64 = '0.13'
blst = { features = [ 'portable' ], version = '0.3.5' }
crc = '3.0'
curve25519-dalek = '4.0'
ed25519 = '2.2'
ed25519-dalek = { features = [ 'hazmat', 'rand_core' ], version = '2.0' }
failure = '0.1'
getrandom = { features = [ 'js' ], version = '0.2' }
hex = '0.4'
lazy_static = '1.4'
log = '0.4'
num = '0.4'
num-derive = '0.3'
num-derive = '0.4'
num-traits = '0.2'
rand = '0.8'
serde = { features = [ 'derive', 'rc' ], version = '1.0.105' }
serde_json = '1.0'
sha2 = '0.10'
smallvec = { features = [ 'const_new', 'union', 'write' ], version = '1.10' }
thiserror = '1.0'
x25519-dalek = '2.0'
lockfree = { git = 'https://github.com/everx-labs/lockfree.git' }

Expand All @@ -39,6 +40,7 @@ export_key = [ ]
gosh = [ ]
groth = [ ]
signature_with_id = [ ]
std = [ ]

[[bench]]
harness = false
Expand Down
14 changes: 7 additions & 7 deletions src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use crate::{fail, Result};
use rand::{Rng, RngCore};
use std::collections::HashMap;

/*
Expand Down Expand Up @@ -423,7 +424,7 @@ impl BlsKeyPair {

pub fn gen_key_pair() -> Result<KeyPair> {
let mut ikm = [0u8; BLS_KEY_MATERIAL_LEN];
rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut ikm);
rand::thread_rng().fill_bytes(&mut ikm);
BlsKeyPair::gen_key_pair_based_on_key_material(&ikm)
}

Expand Down Expand Up @@ -580,15 +581,15 @@ impl NodesInfo {
*/

pub fn generate_random_msg() -> Vec<u8> {
let msg_len = rand::Rng::gen_range(&mut rand::thread_rng(), 2..100);
let msg_len = rand::thread_rng().gen_range(2..100);
let mut msg = vec![0u8; msg_len as usize];
rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut msg);
rand::thread_rng().fill_bytes(&mut msg);
msg
}

pub fn generate_random_msg_of_fixed_len( msg_len: i32) -> Vec<u8> {
let mut msg = vec![0u8; msg_len as usize];
rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut msg);
rand::thread_rng().fill_bytes(&mut msg);
msg
}

Expand All @@ -599,7 +600,7 @@ pub fn gen_signer_indexes(n: u16, k: u16) -> Vec<u16> {
let mut indexes = Vec::new();

for _i in 0..k {
indexes.push(rand::Rng::gen_range(&mut rng, 0..n));
indexes.push(rng.gen_range(0..n));
}

if indexes.len() == (k as usize) {
Expand All @@ -609,8 +610,7 @@ pub fn gen_signer_indexes(n: u16, k: u16) -> Vec<u16> {
}

pub fn gen_random_index(n: u16) -> u16 {
let mut rng = rand::thread_rng();
rand::Rng::gen_range(&mut rng, 0..n)
rand::thread_rng().gen_range(0..n)
}

pub fn create_random_nodes_info(total_num_of_nodes: u16, attempts: u16) -> NodesInfo{
Expand Down
8 changes: 4 additions & 4 deletions src/cell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ fn build_big_cell_buf(
level_mask: u8,
refs: usize,
store_hashes: bool,
hashes: Option<[UInt256; 4]>,
hashes: Option<&[UInt256; 4]>,
depths: Option<[u16; 4]>
) -> Result<Vec<u8>> {
if level_mask != 0 {
Expand Down Expand Up @@ -911,7 +911,7 @@ fn build_cell_buf(
level_mask: u8,
refs: usize,
store_hashes: bool,
hashes: Option<[UInt256; 4]>,
hashes: Option<&[UInt256; 4]>,
depths: Option<[u16; 4]>
) -> Result<Vec<u8>> {
if cell_type == CellType::Big {
Expand Down Expand Up @@ -1105,9 +1105,9 @@ impl CellData {
depths: Option<[u16; 4]>
) -> Result<Self> {
let buffer = if cell_type == CellType::Big {
build_big_cell_buf(data, level_mask, refs as usize, store_hashes, hashes.clone(), depths)?
build_big_cell_buf(data, level_mask, refs as usize, store_hashes, hashes.as_ref(), depths)?
} else {
build_cell_buf(cell_type, data, level_mask, refs as usize, store_hashes, hashes.clone(), depths)?
build_cell_buf(cell_type, data, level_mask, refs as usize, store_hashes, hashes.as_ref(), depths)?
};
#[cfg(test)]
check_cell_buf(&buffer[..], false)?;
Expand Down
34 changes: 17 additions & 17 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,53 @@
* limitations under the License.
*/

#[derive(Debug, failure::Fail)]
#[derive(Debug, thiserror::Error)]
pub enum BlockError {
/// Fatal error.
#[fail(display = "Fatal error: {}", 0)]
#[error("Fatal error: {0}")]
FatalError(String),
/// Invalid argument.
#[fail(display = "Invalid argument: {}", 0)]
#[error("Invalid argument: {0}")]
InvalidArg(String),
/// Invalid TL-B constructor tag.
#[fail(display = "Invalid TL-B constructor tag `#{:x}` while parsing `{}` struct", t, s)]
#[error("Invalid TL-B constructor tag `#{:x}` while parsing `{}` struct", .t, .s)]
InvalidConstructorTag {
t: u32,
s: String,
},
/// Invalid data.
#[fail(display = "Invalid data: {}", 0)]
#[error("Invalid data: {0}")]
InvalidData(String),
/// Invalid index.
#[fail(display = "Invalid index: {}", 0)]
#[error("Invalid index: {0}")]
InvalidIndex(usize),
/// Invalid operation.
#[fail(display = "Invalid operation: {}", 0)]
#[error("Invalid operation: {0}")]
InvalidOperation(String),
/// Item is not found.
#[fail(display = "{} is not found", 0)]
#[error("{0} is not found")]
NotFound(String),
/// Other error.
#[fail(display = "{}", 0)]
#[error("{0}")]
Other(String),
/// Attempting to read data from pruned branch cell.
#[fail(display = "Attempting to read {} from pruned branch cell", 0)]
#[error("Attempting to read {0} from pruned branch cell")]
PrunedCellAccess(String),
/// Wrong hash.
#[fail(display = "Wrong hash")]
#[error("Wrong hash")]
WrongHash,
/// Wrong merkle proof.
#[fail(display = "Wrong merkle proof: {}", 0)]
#[error("Wrong merkle proof: {0}")]
WrongMerkleProof(String),
/// Wrong merkle update.
#[fail(display = "Wrong merkle update: {}", 0)]
#[error("Wrong merkle update: {0}")]
WrongMerkleUpdate(String),
#[fail(display = "Bad signature")]
#[error("Bad signature")]
BadSignature,
#[fail(display = "Unexpected struct variant: exp={} real={}", 0, 1)]
#[error("Unexpected struct variant: exp={0} real={1}")]
UnexpectedStructVariant(String, String),
#[fail(display = "Unsupported serde opts: {} {:x}", 0, 1)]
#[error("Unsupported serde opts: {0} {:x}", .1)]
UnsupportedSerdeOptions(String, usize),
#[fail(display = "Mismatched serde options: {} exp={} real={}", 0, 1, 2)]
#[error("Mismatched serde options: {0} exp={1} real={2}")]
MismatchedSerdeOptions(String, usize, usize),
}
48 changes: 24 additions & 24 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ use std::{
};
use smallvec::SmallVec;

pub type Error = failure::Error;
pub type Error = anyhow::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub type Failure = Option<Error>;
pub type Status = Result<()>;

#[macro_export]
macro_rules! error {
($error:literal) => {
failure::err_msg(format!("{} {}:{}", $error, file!(), line!()))
anyhow::format_err!("{} {}:{}", $error, file!(), line!())
};
($error:expr) => {
failure::Error::from($error)
anyhow::Error::from($error)
};
($fmt:expr, $($arg:tt)+) => {
failure::err_msg(format!("{} {}:{}", format!($fmt, $($arg)*), file!(), line!()))
anyhow::format_err!("{} {}:{}", format!($fmt, $($arg)*), file!(), line!())
};
}

#[macro_export]
macro_rules! fail {
($error:literal) => {
return Err(failure::err_msg(format!("{} {}:{}", $error, file!(), line!())))
return Err(anyhow::format_err!("{} {}:{}", $error, file!(), line!()))
};
// uncomment to explicit panic for any ExceptionCode
// (ExceptionCode::CellUnderflow) => {
Expand All @@ -62,7 +62,7 @@ macro_rules! fail {
return Err($crate::error!($error))
};
($fmt:expr, $($arg:tt)*) => {
return Err(failure::err_msg(format!("{} {}:{}", format!($fmt, $($arg)*), file!(), line!())))
return Err(anyhow::format_err!("{} {}:{}", format!($fmt, $($arg)*), file!(), line!()))
};
}

Expand Down Expand Up @@ -305,41 +305,41 @@ impl FromStr for AccountId {

// Exceptions *****************************************************************

#[derive(Clone, Copy, Debug, num_derive::FromPrimitive, PartialEq, Eq, failure::Fail)]
#[derive(Clone, Copy, Debug, num_derive::FromPrimitive, PartialEq, Eq, thiserror::Error)]
pub enum ExceptionCode {
#[fail(display = "normal termination")]
#[error("normal termination")]
NormalTermination = 0,
#[fail(display = "alternative termination")]
#[error("alternative termination")]
AlternativeTermination = 1,
#[fail(display = "stack underflow")]
#[error("stack underflow")]
StackUnderflow = 2,
#[fail(display = "stack overflow")]
#[error("stack overflow")]
StackOverflow = 3,
#[fail(display = "integer overflow")]
#[error("integer overflow")]
IntegerOverflow = 4,
#[fail(display = "range check error")]
#[error("range check error")]
RangeCheckError = 5,
#[fail(display = "invalid opcode")]
#[error("invalid opcode")]
InvalidOpcode = 6,
#[fail(display = "type check error")]
#[error("type check error")]
TypeCheckError = 7,
#[fail(display = "cell overflow")]
#[error("cell overflow")]
CellOverflow = 8,
#[fail(display = "cell underflow")]
#[error("cell underflow")]
CellUnderflow = 9,
#[fail(display = "dictionaty error")]
#[error("dictionaty error")]
DictionaryError = 10,
#[fail(display = "unknown error")]
#[error("unknown error")]
UnknownError = 11,
#[fail(display = "fatal error")]
#[error("fatal error")]
FatalError = 12,
#[fail(display = "out of gas")]
#[error("out of gas")]
OutOfGas = 13,
#[fail(display = "illegal instruction")]
#[error("illegal instruction")]
IllegalInstruction = 14,
#[fail(display = "pruned cell")]
#[error("pruned cell")]
PrunedCellAccess = 15,
#[fail(display = "big cell")]
#[error("big cell")]
BigCellAccess = 16
}

Expand Down
2 changes: 1 addition & 1 deletion src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl ValidatorSet {
let mut prng = ValidatorSetPRNG::new(shard_pfx, workchain_id, cc_seqno);
let full_list = if cc_config.isolate_mc_validators {
if self.total <= self.main && !(self.main == 0 && self.total == 0) {
fail!(failure::format_err!("Count of validators is too small to make sharde's subset while `isolate_mc_validators` flag is set (total={}, main={})", self.total, self.main))
fail!("Count of validators is too small to make sharde's subset while `isolate_mc_validators` flag is set (total={}, main={})", self.total, self.main)
}
let list = self.list[self.main.as_usize()..].to_vec();
Cow::Owned(
Expand Down