Skip to content

Commit

Permalink
[ci] update to rust stable (#336)
Browse files Browse the repository at this point in the history
0o-de-lally authored Jan 27, 2025
1 parent 8c7fc88 commit 7025a07
Showing 19 changed files with 55 additions and 304 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build_env/action.yaml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ runs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.78.0
toolchain: stable
override: true

- name: install rustfmt clippy
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@
#![allow(clippy::unnecessary_wraps)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(clippy::doc_lazy_continuation)]
#![allow(clippy::empty_line_after_doc_comments)]

use crate::version_five::{
language_storage_v5::{ModuleIdV5 as ModuleId, TypeTagV5 as TypeTag},
legacy_address_v5::LegacyAddressV5 as AccountAddress,
24 changes: 9 additions & 15 deletions compatibility/src/sdk/v5_2_0_transaction_script_builder.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@
#![allow(clippy::unnecessary_wraps)]
#![allow(unused_imports)]
#![allow(dead_code)]
// legacy code from diem, clippy warnings since 1.80
#![allow(clippy::doc_lazy_continuation)]
#![allow(clippy::empty_line_after_doc_comments)]
use crate::version_five::{
language_storage_v5::{ModuleIdV5 as ModuleId, TypeTagV5 as TypeTag},
legacy_address_v5::LegacyAddressV5 as AccountAddress,
@@ -4421,7 +4424,6 @@ pub fn encode_create_child_vasp_account_script_function(
/// | `human_name` | `vector<u8>` | ASCII-encoded human name for the Designated Dealer. |
/// | `add_all_currencies` | `bool` | Whether to publish preburn, balance, and tier info resources for all known (SCS) currencies or just `Currency` when the account is created. |
///

/// # Common Abort Conditions
/// | Error Category | Error Reason | Description |
/// | ---------------- | -------------- | ------------- |
@@ -4695,9 +4697,7 @@ pub fn encode_create_validator_account_script_function(
/// # Events
/// Successful execution will emit:
/// * A `DiemAccount::CreateAccountEvent` with the `created` field being `new_account_address`,
/// and the `rold_id` field being `Roles::VALIDATOR_OPERATOR_ROLE_ID`. This is emitted on the
/// `DiemAccount::AccountOperationsCapability` `creation_events` handle.
///
/// and the `rold_id` field being `Roles::VALIDATOR_OPERATOR_ROLE_ID`. This is emitted on the `DiemAccount::AccountOperationsCapability` `creation_events` handle.
/// # Parameters
/// | Name | Type | Description |
/// | ------ | ------ | ------------- |
@@ -5058,11 +5058,9 @@ pub fn encode_peer_to_peer_with_metadata_script_function(
///
/// # Events
/// Successful execution of this script emits two events:
/// * `DiemAccount::SentPaymentEvent ` on `account`'s `DiemAccount::DiemAccount` `sent_events`
/// handle with the `payee` and `payer` fields being `account`'s address; and
/// * `DiemAccount::SentPaymentEvent ` on `account`'s `DiemAccount::DiemAccount` `sent_events` handle with the `payee` and `payer` fields being `account`'s address; and
/// * A `Diem::PreburnEvent` with `Token`'s currency code on the
/// `Diem::CurrencyInfo<Token`'s `preburn_events` handle for `Token` and with
/// `preburn_address` set to `account`'s address.
/// `Diem::CurrencyInfo<Token`'s `preburn_events` handle for `Token` and with `preburn_address` set to `account`'s address.
///
/// # Parameters
/// | Name | Type | Description |
@@ -5504,9 +5502,7 @@ pub fn encode_rotate_authentication_key_with_recovery_address_script_function(
///
/// # Events
/// Successful execution of this transaction emits two events:
/// * A `DualAttestation::ComplianceKeyRotationEvent` containing the new compliance public key, and
/// the blockchain time at which the key was updated emitted on the `DualAttestation::Credential`
/// `compliance_key_rotation_events` handle published under `account`; and
/// * A `DualAttestation::ComplianceKeyRotationEvent` containing the new compliance public key, and the blockchain time at which the key was updated emitted on the `DualAttestation::Credential` `compliance_key_rotation_events` handle published under `account`; and
/// * A `DualAttestation::BaseUrlRotationEvent` containing the new base url to be used for
/// off-chain communication, and the blockchain time at which the url was updated emitted on the
/// `DualAttestation::Credential` `base_url_rotation_events` handle published under `account`.
@@ -6543,11 +6539,9 @@ pub fn encode_cancel_burn_script(token: TypeTag, preburn_address: AccountAddress
/// ## Events
/// Successful execution with a `child_initial_balance` greater than zero will emit:
/// * A `DiemAccount::SentPaymentEvent` with the `payer` field being the Parent VASP's address,
/// and payee field being `child_address`. This is emitted on the Parent VASP's
/// `DiemAccount::DiemAccount` `sent_events` handle.
/// and payee field being `child_address`. This is emitted on the Parent VASP's `DiemAccount::DiemAccount` `sent_events` handle.
/// * A `DiemAccount::ReceivedPaymentEvent` with the `payer` field being the Parent VASP's address,
/// and payee field being `child_address`. This is emitted on the new Child VASPS's
/// `DiemAccount::DiemAccount` `received_events` handle.
/// and payee field being `child_address`. This is emitted on the new Child VASPS's `DiemAccount::DiemAccount` `received_events` handle.
///
/// # Parameters
/// | Name | Type | Description |
2 changes: 2 additions & 0 deletions compatibility/src/sdk/v6_libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]
// legacy code from diem, clippy warnings since 1.80
#![allow(clippy::doc_lazy_continuation)]
use diem_types::{
account_address::AccountAddress,
transaction::{EntryFunction, TransactionPayload},
6 changes: 3 additions & 3 deletions compatibility/src/sdk/v7_libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@

#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_arguments, clippy::doc_lazy_continuation)]
use diem_types::{
account_address::AccountAddress,
transaction::{EntryFunction, TransactionPayload},
@@ -44,8 +44,8 @@ type Bytes = Vec<u8>;
// explorer and data warehouse
//////// end ////////
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "fuzzing", derive(proptest_derive::Arbitrary))]
#[cfg_attr(feature = "fuzzing", proptest(no_params))]
// #[cfg_attr(feature = "fuzzing", derive(proptest_derive::Arbitrary))]
// #[cfg_attr(feature = "fuzzing", proptest(no_params))]
pub enum EntryFunctionCall {
/// Offers rotation capability on behalf of `account` to the account at address `recipient_address`.
/// An account can delegate its rotation capability to only one other address at one time. If the account
244 changes: 4 additions & 240 deletions compatibility/src/version_five/hash_value_v5.rs
Original file line number Diff line number Diff line change
@@ -114,11 +114,6 @@ use std::{
};
use tiny_keccak::{Hasher, Sha3};

/// A prefix used to begin the salt of every diem hashable structure. The salt
/// consists in this global prefix, concatenated with the specified
/// serialization name of the struct.
// pub(crate) const DIEM_HASH_PREFIX: &[u8] = b"DIEM::";

/// Output value of our hash function. Intentionally opaque for safety and modularity.
#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct HashValueV5 {
@@ -269,7 +264,7 @@ impl HashValueV5 {
/// generating basic mock hash values.
///
/// Ex: HashValue::from_u64(0x1234) => HashValue([0, .., 0, 0x12, 0x34])
#[cfg(any(test, feature = "fuzzing"))]
#[cfg(test)]
pub fn from_u64(v: u64) -> Self {
let mut hash = [0u8; Self::LENGTH];
let bytes = v.to_be_bytes();
@@ -439,7 +434,7 @@ impl<'a> HashValueBitIterator<'a> {
}
}

impl<'a> std::iter::Iterator for HashValueBitIterator<'a> {
impl std::iter::Iterator for HashValueBitIterator<'_> {
type Item = bool;

fn next(&mut self) -> Option<Self::Item> {
@@ -451,241 +446,10 @@ impl<'a> std::iter::Iterator for HashValueBitIterator<'a> {
}
}

impl<'a> std::iter::DoubleEndedIterator for HashValueBitIterator<'a> {
impl std::iter::DoubleEndedIterator for HashValueBitIterator<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
self.pos.next_back().map(|x| self.get_bit(x))
}
}

impl<'a> std::iter::ExactSizeIterator for HashValueBitIterator<'a> {}

// /// A type that can be cryptographically hashed to produce a `HashValue`.
// ///
// /// In most cases, this trait should not be implemented manually but rather derived using
// /// the macros `serde::Serialize`, `CryptoHasher`, and `BCSCryptoHash`.
// pub trait CryptoHash {
// /// The associated `Hasher` type which comes with a unique salt for this type.
// type Hasher: CryptoHasher;

// /// Hashes the object and produces a `HashValue`.
// fn hash(&self) -> HashValue;
// }

// /// A trait for representing the state of a cryptographic hasher.
// pub trait CryptoHasher: Default + std::io::Write {
// /// the seed used to initialize hashing `Self` before the serialization bytes of the actual value
// fn seed() -> &'static [u8; 32];

// /// Write bytes into the hasher.
// fn update(&mut self, bytes: &[u8]);

// /// Finish constructing the [`HashValue`].
// fn finish(self) -> HashValue;

// /// Convenience method to compute the hash of a complete byte slice.
// fn hash_all(bytes: &[u8]) -> HashValue {
// let mut hasher = Self::default();
// hasher.update(bytes);
// hasher.finish()
// }
// }

// /// The default hasher underlying generated implementations of `CryptoHasher`.
// #[doc(hidden)]
// #[derive(Clone)]
// pub struct DefaultHasher {
// state: Sha3,
// }

// impl DefaultHasher {
// #[doc(hidden)]
// /// This function does not return a HashValue in the sense of our usual
// /// hashes, but a construction of initial bytes that are fed into any hash
// /// provided we're passed a (bcs) serialization name as argument.
// pub fn prefixed_hash(buffer: &[u8]) -> [u8; HashValue::LENGTH] {
// // The salt is initial material we prefix to actual value bytes for
// // domain separation. Its length is variable.
// let salt: Vec<u8> = [DIEM_HASH_PREFIX, buffer].concat();
// // The seed is a fixed-length hash of the salt, thereby preventing
// // suffix attacks on the domain separation bytes.
// HashValue::sha3_256_of(&salt[..]).hash
// }

// #[doc(hidden)]
// pub fn new(typename: &[u8]) -> Self {
// let mut state = Sha3::v256();
// if !typename.is_empty() {
// state.update(&Self::prefixed_hash(typename));
// }
// DefaultHasher { state }
// }

// #[doc(hidden)]
// pub fn update(&mut self, bytes: &[u8]) {
// self.state.update(bytes);
// }

// #[doc(hidden)]
// pub fn finish(self) -> HashValue {
// let mut hasher = HashValue::default();
// self.state.finalize(hasher.as_ref_mut());
// hasher
// }
// }

// impl fmt::Debug for DefaultHasher {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(f, "DefaultHasher: state = Sha3")
// }
// }

// macro_rules! define_hasher {
// (
// $(#[$attr:meta])*
// ($hasher_type: ident, $hasher_name: ident, $seed_name: ident, $salt: expr)
// ) => {

// #[derive(Clone, Debug)]
// $(#[$attr])*
// pub struct $hasher_type(DefaultHasher);

// impl $hasher_type {
// fn new() -> Self {
// $hasher_type(DefaultHasher::new($salt))
// }
// }

// static $hasher_name: Lazy<$hasher_type> = Lazy::new(|| { $hasher_type::new() });
// static $seed_name: OnceCell<[u8; 32]> = OnceCell::new();

// impl Default for $hasher_type {
// fn default() -> Self {
// $hasher_name.clone()
// }
// }

// impl CryptoHasher for $hasher_type {
// fn seed() -> &'static [u8;32] {
// $seed_name.get_or_init(|| {
// DefaultHasher::prefixed_hash($salt)
// })
// }

// fn update(&mut self, bytes: &[u8]) {
// self.0.update(bytes);
// }

// fn finish(self) -> HashValue {
// self.0.finish()
// }
// }

// impl std::io::Write for $hasher_type {
// fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
// self.0.update(bytes);
// Ok(bytes.len())
// }
// fn flush(&mut self) -> std::io::Result<()> {
// Ok(())
// }
// }
// };
// }

// define_hasher! {
// /// The hasher used to compute the hash of an internal node in the transaction accumulator.
// (
// TransactionAccumulatorHasher,
// TRANSACTION_ACCUMULATOR_HASHER,
// TRANSACTION_ACCUMULATOR_SEED,
// b"TransactionAccumulator"
// )
// }

// define_hasher! {
// /// The hasher used to compute the hash of an internal node in the event accumulator.
// (
// EventAccumulatorHasher,
// EVENT_ACCUMULATOR_HASHER,
// EVENT_ACCUMULATOR_SEED,
// b"EventAccumulator"
// )
// }

// define_hasher! {
// /// The hasher used to compute the hash of an internal node in the Sparse Merkle Tree.
// (
// SparseMerkleInternalHasher,
// SPARSE_MERKLE_INTERNAL_HASHER,
// SPARSE_MERKLE_INTERNAL_SEED,
// b"SparseMerkleInternal"
// )
// }

// define_hasher! {
// /// The hasher used to compute the hash of an internal node in the transaction accumulator.
// (
// VoteProposalHasher,
// VOTE_PROPOSAL_HASHER,
// VOTE_PROPOSAL_SEED,
// b"VoteProposalHasher"
// )
// }

// define_hasher! {
// /// The hasher used only for testing. It doesn't have a salt.
// (TestOnlyHasher, TEST_ONLY_HASHER, TEST_ONLY_SEED, b"")
// }

// fn create_literal_hash(word: &str) -> HashValue {
// let mut s = word.as_bytes().to_vec();
// assert!(s.len() <= HashValue::LENGTH);
// s.resize(HashValue::LENGTH, 0);
// HashValue::from_slice(&s).expect("Cannot fail")
// }

// /// Placeholder hash of `Accumulator`.
// pub static ACCUMULATOR_PLACEHOLDER_HASH: Lazy<HashValue> =
// Lazy::new(|| create_literal_hash("ACCUMULATOR_PLACEHOLDER_HASH"));

// /// Placeholder hash of `SparseMerkleTree`.
// pub static SPARSE_MERKLE_PLACEHOLDER_HASH: Lazy<HashValue> =
// Lazy::new(|| create_literal_hash("SPARSE_MERKLE_PLACEHOLDER_HASH"));

// /// Block id reserved as the id of parent block of the genesis block.
// pub static PRE_GENESIS_BLOCK_ID: Lazy<HashValue> =
// Lazy::new(|| create_literal_hash("PRE_GENESIS_BLOCK_ID"));

// /// Genesis block id is used as a parent of the very first block executed by the executor.
// pub static GENESIS_BLOCK_ID: Lazy<HashValue> = Lazy::new(|| {
// // This maintains the invariant that block.id() == block.hash(), for
// // the genesis block and allows us to (de/)serialize it consistently
// HashValue::new([
// 0x5e, 0x10, 0xba, 0xd4, 0x5b, 0x35, 0xed, 0x92, 0x9c, 0xd6, 0xd2, 0xc7, 0x09, 0x8b, 0x13,
// 0x5d, 0x02, 0xdd, 0x25, 0x9a, 0xe8, 0x8a, 0x8d, 0x09, 0xf4, 0xeb, 0x5f, 0xba, 0xe9, 0xa6,
// 0xf6, 0xe4,
// ])
// });

// /// Provides a test_only_hash() method that can be used in tests on types that implement
// /// `serde::Serialize`.
// ///
// /// # Example
// /// ```
// /// use diem_crypto::hash::TestOnlyHash;
// ///
// /// b"hello world".test_only_hash();
// /// ```
// pub trait TestOnlyHash {
// /// Generates a hash used only for tests.
// fn test_only_hash(&self) -> HashValue;
// }

// impl<T: ser::Serialize + ?Sized> TestOnlyHash for T {
// fn test_only_hash(&self) -> HashValue {
// let bytes = bcs::to_bytes(self).expect("serialize failed during hash.");
// let mut hasher = TestOnlyHasher::default();
// hasher.update(&bytes);
// hasher.finish()
// }
// }
impl std::iter::ExactSizeIterator for HashValueBitIterator<'_> {}
11 changes: 6 additions & 5 deletions compatibility/src/version_five/state_snapshot_v5.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! read-archive
//! state_snapshot
// legacy code from diem, clippy warnings since 1.80
#![allow(clippy::doc_lazy_continuation)]

use crate::version_five::{account_blob_v5::AccountStateBlob, hash_value_v5::HashValueV5};

@@ -45,10 +48,8 @@ pub struct AccountStateBlobRecord(HashValueV5, AccountStateBlob);
////// SNAPSHOT FILE IO //////
/// read snapshot manifest file into struct
pub fn v5_read_from_snapshot_manifest(path: &Path) -> Result<StateSnapshotBackupV5, Error> {
let config = std::fs::read_to_string(path).map_err(|e| {
format!("Error: cannot read file {:?}, error: {:?}", &path, &e);
e
})?;
let config =
std::fs::read_to_string(path).context(format!("Error: cannot read file at {:?}", &path))?;

let map: StateSnapshotBackupV5 = serde_json::from_str(&config)?;

8 changes: 3 additions & 5 deletions compatibility/src/version_five/transaction_manifest_v5.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0
use anyhow::{ensure, Result};
use anyhow::{ensure, Context, Result};
use diem_backup_cli::storage::FileHandle;
use diem_types::transaction::Version;
use serde::{Deserialize, Serialize};
@@ -78,10 +78,8 @@ impl TransactionBackup {
////// TX FILES IO //////
/// read tx manifest file into struct
pub fn v5_read_from_transaction_manifest(path: &Path) -> Result<TransactionBackup> {
let config = std::fs::read_to_string(path).map_err(|e| {
format!("Error: cannot read file {:?}, error: {:?}", &path, &e);
e
})?;
let config =
std::fs::read_to_string(path).context(format!("Error: cannot read file {:?}", &path))?;

let map: TransactionBackup = serde_json::from_str(&config)?;

12 changes: 4 additions & 8 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@

#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_arguments, clippy::doc_lazy_continuation)]
use diem_types::{
account_address::AccountAddress,
transaction::{EntryFunction, TransactionPayload},
@@ -94,8 +94,7 @@ pub enum EntryFunctionCall {

/// Generic authentication key rotation function that allows the user to rotate their authentication key from any scheme to any scheme.
/// To authorize the rotation, we need two signatures:
/// - the first signature `cap_rotate_key` refers to the signature by the account owner's current key on a valid `RotationProofChallenge`,
/// demonstrating that the user intends to and has the capability to rotate the authentication key of this account;
/// - the first signature `cap_rotate_key` refers to the signature by the account owner's current key on a valid `RotationProofChallenge`,demonstrating that the user intends to and has the capability to rotate the authentication key of this account;
/// - the second signature `cap_update_table` refers to the signature by the new key (that the account owner wants to rotate to) on a
/// valid `RotationProofChallenge`, demonstrating that the user owns the new private key, and has the authority to update the
/// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
@@ -1043,14 +1042,11 @@ pub fn account_revoke_signer_capability(
/// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
/// To verify these two signatures, we need their corresponding public key and public key scheme: we use `from_scheme` and `from_public_key_bytes`
/// to verify `cap_rotate_key`, and `to_scheme` and `to_public_key_bytes` to verify `cap_update_table`.
/// A scheme of 0 refers to an Ed25519 key and a scheme of 1 refers to Multi-Ed25519 keys.
/// `originating address` refers to an account's original/first address.
///
/// A scheme of 0 refers to an Ed25519 key and a scheme of 1 refers to Multi-Ed25519 keys. `originating address` refers to an account's original/first address.
/// Here is an example attack if we don't ask for the second signature `cap_update_table`:
/// Alice has rotated her account `addr_a` to `new_addr_a`. As a result, the following entry is created, to help Alice when recovering her wallet:
/// `OriginatingAddress[new_addr_a]` -> `addr_a`
/// Alice has had bad day: her laptop blew up and she needs to reset her account on a new one.
/// (Fortunately, she still has her secret key `new_sk_a` associated with her new address `new_addr_a`, so she can do this.)
/// Alice has had bad day: her laptop blew up and she needs to reset her account on a new one. (Fortunately, she still has her secret key `new_sk_a` associated with her new address `new_addr_a`, so she can do this.)
///
/// But Bob likes to mess with Alice.
/// Bob creates an account `addr_b` and maliciously rotates it to Alice's new address `new_addr_a`. Since we are no longer checking a PoK,
10 changes: 5 additions & 5 deletions framework/src/builder/framework_generate_upgrade_proposal.rs
Original file line number Diff line number Diff line change
@@ -146,11 +146,11 @@ pub fn write_to_file(result: Vec<(String, String)>, proposal_dir: PathBuf) -> an
Ok(())
}
/// Need to create a dummy package so that we can build the script into bytecode
/// so that we can then get the hash of the script.
/// ... so that we can then submit it as part of a proposal framework/libra-framework/sources/modified_source/diem_governance.move
/// ... so that then the VM doesn't complain about its size /diem-move/diem-vm/src/diem_vm_impl.rs
/// ... and so that when the proposal is approved a third party can execute the source upgrade.
/// so that:
/// * we can then get the hash of the script.
/// * then submit it as part of a proposal framework/libra-framework/sources/modified_source/diem_governance.move
/// * then the VM doesn't complain about its size /diem-move/diem-vm/src/diem_vm_impl.rs
/// * and so that when the proposal is approved a third party can execute the source upgrade.
pub fn init_move_dir_wrapper(
package_dir: PathBuf,
script_name: &str,
2 changes: 1 addition & 1 deletion framework/src/framework_cli.rs
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ impl GovernanceScript {
}
println!("A governance script dir does not exist here.");
if dialoguer::Confirm::new()
.with_prompt(&format!(
.with_prompt(format!(
"create a script template at {:?}",
&self.script_dir.display()
))
2 changes: 1 addition & 1 deletion tools/genesis/src/wizard.rs
Original file line number Diff line number Diff line change
@@ -321,7 +321,7 @@ impl GenesisWizard {
fn _download_snapshot(&mut self, _app_cfg: &AppCfg) -> anyhow::Result<PathBuf> {
if let Some(e) = self.epoch {
if !Confirm::new()
.with_prompt(&format!("So are we migrating data from epoch {}?", e))
.with_prompt(format!("So are we migrating data from epoch {}?", e))
.interact()
.unwrap()
{
8 changes: 3 additions & 5 deletions tools/storage/src/read_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! read-archive
use anyhow::{anyhow, Error, Result};
use anyhow::{anyhow, Context, Error, Result};
use diem_backup_cli::{
backup_types::{
epoch_ending::manifest::EpochEndingBackup, state_snapshot::manifest::StateSnapshotBackup,
@@ -27,10 +27,8 @@ use tokio::{fs::OpenOptions, io::AsyncRead};
////// SNAPSHOT FILE IO //////
/// read snapshot manifest file into object
pub fn load_snapshot_manifest(path: &Path) -> Result<StateSnapshotBackup, Error> {
let config = std::fs::read_to_string(path).map_err(|e| {
format!("Error: cannot read file {:?}, error: {:?}", &path, &e);
e
})?;
let config =
std::fs::read_to_string(path).context(format!("Error: cannot read file at {:?}", path))?;

let map: StateSnapshotBackup = serde_json::from_str(&config)?;

8 changes: 3 additions & 5 deletions tools/storage/src/read_tx_chunk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};

use diem_backup_cli::backup_types::transaction::manifest::TransactionBackup;
use diem_backup_cli::backup_types::transaction::manifest::TransactionChunk;
@@ -13,10 +13,8 @@ use libra_backwards_compatibility::version_five::state_snapshot_v5::open_for_rea

/// read snapshot manifest file into object
pub fn load_tx_chunk_manifest(path: &Path) -> anyhow::Result<TransactionBackup> {
let s = std::fs::read_to_string(path).map_err(|e| {
format!("Error: cannot read file {:?}, error: {:?}", &path, &e);
e
})?;
let s =
std::fs::read_to_string(path).context(format!("Error: cannot read file at {:?}", path))?;

let map: TransactionBackup = serde_json::from_str(&s)?;

5 changes: 2 additions & 3 deletions tools/wallet/src/core/key_factory.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ use crate::core::mnemonic::Mnemonic;
use anyhow::{anyhow, Result};
use byteorder::{ByteOrder, LittleEndian};
use hmac::Hmac;
use mirai_annotations::*;
use pbkdf2::pbkdf2;
use serde::{Deserialize, Serialize};
use std::ops::AddAssign;
@@ -63,8 +62,8 @@ impl ChildNumber {

impl std::ops::AddAssign for ChildNumber {
fn add_assign(&mut self, other: Self) {
assume!(self.0 <= u64::MAX / 2); // invariant
assume!(other.0 <= u64::MAX / 2); // invariant
// assume!(self.0 <= u64::MAX / 2); // invariant
// assume!(other.0 <= u64::MAX / 2); // invariant
*self = Self(self.0 + other.0)
}
}
9 changes: 5 additions & 4 deletions tools/wallet/src/core/mnemonic.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
use anyhow::{bail, Result};
#[cfg(test)]
use diem_temppath::TempPath;
use mirai_annotations::*;
// use mirai_annotations::*; // TODO: enable mirai
#[cfg(test)]
use rand::rngs::OsRng;
#[cfg(test)]
@@ -171,7 +171,7 @@ struct U11BitWriter {
impl U11BitWriter {
/// Create a new `BitWriter` around the given writer.
fn new(mnemonic_len: usize) -> U11BitWriter {
precondition!(mnemonic_len <= 24);
// precondition!(mnemonic_len <= 24);
U11BitWriter {
bytes: Vec::with_capacity(11 * mnemonic_len / 8 + 1),
unused: 8,
@@ -201,7 +201,8 @@ impl U11BitWriter {
nbits_remaining -= 8;
self.bytes.push((value >> nbits_remaining) as u8);
}
verify!(nbits_remaining < 8);

// verify!(nbits_remaining < 8);

// Put the remaining bits in the buffer.
if nbits_remaining > 0 {
@@ -222,7 +223,7 @@ impl U11BitWriter {
const MASKS: [u16; 8] = [0, 0b1, 0b11, 0b111, 0b1111, 0b11111, 0b11_1111, 0b111_1111];

// TODO: update this to hashmap or trie.
const WORDS: [&str; 2048] = [
static WORDS: [&str; 2048] = [
"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd",
"abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire",
"across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address",
1 change: 0 additions & 1 deletion tools/wallet/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! 0L key scheme
#![forbid(unsafe_code)]

pub mod key_factory;
pub mod legacy_scheme;
pub mod mnemonic;
1 change: 0 additions & 1 deletion tools/wallet/src/keys.rs
Original file line number Diff line number Diff line change
@@ -219,7 +219,6 @@ pub fn generate_key_objects_from_legacy(
}

/// Testing deterministic hkdf for bls
fn bls_generate_key(ikm: &[u8]) -> anyhow::Result<bls12381::PrivateKey> {
let priv_key = blst::min_pk::SecretKey::key_gen(ikm, &[])
.map_err(|e| anyhow!("blst key gen failed: {:?}", e))?;
1 change: 0 additions & 1 deletion types/src/core_types/app_cfg.rs
Original file line number Diff line number Diff line change
@@ -510,7 +510,6 @@ pub fn get_nickname(acc: AccountAddress) -> String {
/// Transaction types
#[derive(Debug, Clone, Serialize, Deserialize, clap::ValueEnum)]
#[clap(rename_all = "kebab_case")]

pub enum TxType {
/// critical txs
Baseline,

0 comments on commit 7025a07

Please sign in to comment.