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

chore: bump rust-toolchain to 1.54 #319

Merged
merged 2 commits into from
Aug 30, 2021
Merged
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: 2 additions & 2 deletions crates/block-producer/src/block_producer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use crate::{
produce_block::{produce_block, ProduceBlockParam, ProduceBlockResult},
Expand Down Expand Up @@ -575,7 +575,7 @@ impl BlockProducer {
}

if let Some(reverted_deposits) =
crate::deposit::revert(&rollup_context, &self.config, revert_custodians)?
crate::deposit::revert(rollup_context, &self.config, revert_custodians)?
{
log::info!("reverted deposits {}", reverted_deposits.inputs.len());

Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl Challenger {
tx_skeleton.outputs_mut().extend(cancel_output.burn_cells);

// Signature verification needs an owner cell
if !has_lock_cell(&tx_skeleton, &self.wallet.lock_script()) {
if !has_lock_cell(&tx_skeleton, self.wallet.lock_script()) {
let spent_inputs = verifier_context.spent_inputs;

let owner_input = self
Expand Down
4 changes: 2 additions & 2 deletions crates/block-producer/src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub async fn build_mock_transaction(
ckb_output.into()
},
data: ckb_jsonrpc_types::JsonBytes::from_bytes(input_cell.data),
header: input_block_hash.clone().map(|h| h.into()),
header: input_block_hash.map(|h| h.into()),
};
inputs.push(mock_input);
if let Some(input_block_hash) = input_block_hash {
Expand Down Expand Up @@ -168,7 +168,7 @@ pub async fn build_mock_transaction(
ckb_output.into()
},
data: { ckb_jsonrpc_types::JsonBytes::from_bytes(dep_cell.data) },
header: dep_cell_block_hash.clone().map(|h| h.into()),
header: dep_cell_block_hash.map(|h| h.into()),
};
cell_deps.push(mock_cell_dep);
if let Some(dep_cell_block_hash) = dep_cell_block_hash {
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/poller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use crate::{types::ChainEvent, utils::to_result};
use anyhow::{anyhow, Result};
Expand Down
8 changes: 4 additions & 4 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ pub fn run(config: Config, skip_config_check: bool) -> Result<()> {
ckb_fixed_hash::H256::from_slice(&hash).unwrap()
};
let rollup_config_hash =
ckb_fixed_hash::H256::from_slice(&rollup_config_hash.as_slice()).unwrap();
ckb_fixed_hash::H256::from_slice(rollup_config_hash.as_slice()).unwrap();
log::info!("Rollup type script hash: {}", rollup_type_script_hash);
log::info!("Rollup config hash: {}", rollup_config_hash);
}
Expand Down Expand Up @@ -538,7 +538,7 @@ pub fn run(config: Config, skip_config_check: bool) -> Result<()> {
fn check_ckb_version(rpc_client: &RPCClient) -> Result<()> {
let ckb_version = smol::block_on(rpc_client.get_ckb_version())?;
let ckb_version = ckb_version.split('(').collect::<Vec<&str>>()[0].trim_end();
if Version::parse(&ckb_version)? < Version::parse(MIN_CKB_VERSION)? {
if Version::parse(ckb_version)? < Version::parse(MIN_CKB_VERSION)? {
return Err(anyhow!(
"The version of CKB node {} is lower than the minimum version {}",
ckb_version,
Expand Down Expand Up @@ -575,12 +575,12 @@ fn check_rollup_config_cell(
let unregistered_eoas = cell_data
.allowed_eoa_type_hashes()
.into_iter()
.filter(|item| !eoa_set.contains(&item))
.filter(|item| !eoa_set.contains(item))
.collect::<Vec<_>>();
let unregistered_contracts = cell_data
.allowed_contract_type_hashes()
.into_iter()
.filter(|item| !contract_set.contains(&item))
.filter(|item| !contract_set.contains(item))
.collect::<Vec<_>>();
if !unregistered_eoas.is_empty() || !unregistered_contracts.is_empty() {
return Err(anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/transaction_skeleton.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use crate::types::SignatureEntry;
use anyhow::{anyhow, Result};
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use crate::debugger;
use crate::transaction_skeleton::TransactionSkeleton;
Expand Down
10 changes: 5 additions & 5 deletions crates/chain/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use anyhow::{anyhow, Result};
use gw_common::{sparse_merkle_tree, state::State, H256};
Expand Down Expand Up @@ -638,8 +638,8 @@ impl Chain {
// Check current state
let expected_state = l2block.raw().prev_account();
let state_db = StateDBTransaction::from_checkpoint(
&db,
CheckPoint::from_block_hash(&db, parent_block_hash, SubState::Block)?,
db,
CheckPoint::from_block_hash(db, parent_block_hash, SubState::Block)?,
StateDBMode::ReadOnly,
)?;
let tree = state_db.state_tree()?;
Expand Down Expand Up @@ -927,10 +927,10 @@ fn package_bad_blocks(db: &StoreTransaction, start_block_hash: &H256) -> Result<

let tip_block_number = tip_block.raw().number().unpack();
let start_block_number = {
let number = db.get_block_number(&start_block_hash)?;
let number = db.get_block_number(start_block_hash)?;
number.ok_or_else(|| anyhow!("challenge block number not found"))?
};
assert_eq!(start_block_number < tip_block_number, true);
assert!(start_block_number < tip_block_number);

let to_block = |number: u64| {
let hash = db.get_block_hash_by_number(number)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/challenge/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn build_tx_kv_witness(
let parent_block_hash = db
.get_block_hash_by_number(raw_block.number().unpack())?
.ok_or_else(|| anyhow!("parent block not found"))?;
let chain_view = ChainView::new(&db, parent_block_hash);
let chain_view = ChainView::new(db, parent_block_hash);
let block_info = BlockInfo::new_builder()
.number(raw_block.number().to_entity())
.timestamp(raw_block.timestamp().to_entity())
Expand Down Expand Up @@ -483,7 +483,7 @@ fn build_tx_kv_witness(
let return_data_hash = opt_run_result.map(|result| {
let return_data_hash: [u8; 32] = {
let mut hasher = new_blake2b();
hasher.update(&result.return_data.as_slice());
hasher.update(result.return_data.as_slice());
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
hash
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/offchain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use crate::Wallet;

Expand Down
29 changes: 15 additions & 14 deletions crates/challenge/src/offchain/mock_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,20 @@ impl MockBlockParam {
let sender_script = get_script(&tree, sender_id)?;
let receiver_script = get_script(&tree, receiver_id)?;

let mut kv_state: Vec<(H256, H256)> = Vec::new();
kv_state.push((
build_account_field_key(sender_id, GW_ACCOUNT_SCRIPT_HASH_TYPE),
sender_script.hash().into(),
));
kv_state.push((
build_account_field_key(receiver_id, GW_ACCOUNT_SCRIPT_HASH_TYPE),
receiver_script.hash().into(),
));
kv_state.push((
build_account_field_key(sender_id, GW_ACCOUNT_NONCE_TYPE),
H256::from_u32(tx.raw().nonce().unpack()),
));
let kv_state: Vec<(H256, H256)> = vec![
(
build_account_field_key(sender_id, GW_ACCOUNT_SCRIPT_HASH_TYPE),
sender_script.hash().into(),
),
(
build_account_field_key(receiver_id, GW_ACCOUNT_SCRIPT_HASH_TYPE),
receiver_script.hash().into(),
),
(
build_account_field_key(sender_id, GW_ACCOUNT_NONCE_TYPE),
H256::from_u32(tx.raw().nonce().unpack()),
),
];
assert_eq!(
tree.get_nonce(sender_id)?,
Unpack::<u32>::unpack(&tx.raw().nonce())
Expand Down Expand Up @@ -539,7 +540,7 @@ impl MockBlockParam {
let return_data_hash = {
let return_data_hash: [u8; 32] = {
let mut hasher = new_blake2b();
hasher.update(&run_result.return_data.as_slice());
hasher.update(run_result.return_data.as_slice());
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
hash
Expand Down
4 changes: 2 additions & 2 deletions crates/challenge/src/offchain/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl TxDataLoader {
};

let out_points =
OutPointVec::from_slice(&data).map_err(|_| anyhow!("invalid dep group"))?;
OutPointVec::from_slice(data).map_err(|_| anyhow!("invalid dep group"))?;
let cell_deps = out_points.into_iter().map(to_meta);

resolved_cell_deps.extend(cell_deps.collect::<Result<Vec<_>>>()?);
Expand Down Expand Up @@ -196,7 +196,7 @@ impl TxDataLoader {
}

fn get_cell_meta(&self, out_point: &OutPoint) -> Option<CellMeta> {
self.get_cell_info(&out_point).map(|ci| {
self.get_cell_info(out_point).map(|ci| {
CellMetaBuilder::from_cell_output(ci.output.to_owned(), ci.data.to_owned())
.out_point(out_point.clone())
.build()
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/utils/transaction_skeleton.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::clippy::mutable_key_type)]
#![allow(clippy::mutable_key_type)]

use anyhow::{anyhow, Result};
use gw_poa::GeneratedPoA;
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn build_short_script_hash_to_script_hash_key(short_script_hash: &[u8]) -> H
hasher.update(&[GW_SHORT_SCRIPT_HASH_TO_SCRIPT_HASH_TYPE]);
let len = short_script_hash.len() as u32;
hasher.update(&len.to_le_bytes());
hasher.update(&short_script_hash);
hasher.update(short_script_hash);
hasher.finalize(&mut key);
key.into()
}
Expand Down Expand Up @@ -140,7 +140,7 @@ pub trait State {
)?;
// script hash to id
self.update_raw(
build_script_hash_to_account_id_key(&script_hash.as_slice()),
build_script_hash_to_account_id_key(script_hash.as_slice()),
H256::from_u32(id),
)?;
// short script hash to script hash
Expand Down
2 changes: 1 addition & 1 deletion crates/db/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RocksDB {
let opts = Options::default();
let cf_descriptors: Vec<_> = cf_names
.iter()
.map(|ref c| ColumnFamilyDescriptor::new(*c, Options::default()))
.map(|c| ColumnFamilyDescriptor::new(c, Options::default()))
.collect();
(opts, cf_descriptors)
};
Expand Down
6 changes: 3 additions & 3 deletions crates/generator/src/account_lock_manage/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl LockAlgorithm for Secp256k1Eth {
&ctx.rollup_script_hash,
&sender_script,
&receiver_script,
&tx,
tx,
);
self.verify_message(
sender_script.args().unpack(),
Expand Down Expand Up @@ -237,7 +237,7 @@ impl LockAlgorithm for Secp256k1Tron {
&ctx.rollup_script_hash,
&sender_script,
&receiver_script,
&tx,
tx,
);

self.verify_message(
Expand Down Expand Up @@ -280,7 +280,7 @@ fn calc_godwoken_signing_message(
tx: &L2Transaction,
) -> H256 {
tx.raw().calc_message(
&rollup_type_hash,
rollup_type_hash,
&sender_script.hash().into(),
&receiver_script.hash().into(),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/dummy_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CodeStore for DummyState {
self.scripts.insert(script_hash, script);
}
fn get_script(&self, script_hash: &H256) -> Option<Script> {
self.scripts.get(&script_hash).cloned()
self.scripts.get(script_hash).cloned()
}
fn get_script_hash_by_short_address(&self, script_hash_prefix: &[u8]) -> Option<H256> {
self.scripts.iter().find_map(|(script_hash, _script)| {
Expand Down
4 changes: 2 additions & 2 deletions crates/generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl Generator {
.get_lock_algorithm(&lock_code_hash.into())
.ok_or(LockAlgorithmError::UnknownAccountLock)?;
let valid_signature =
lock_algo.verify_tx(&self.rollup_context, script, receiver_script, &tx)?;
lock_algo.verify_tx(&self.rollup_context, script, receiver_script, tx)?;
if !valid_signature {
return Err(LockAlgorithmError::InvalidSignature.into());
}
Expand Down Expand Up @@ -425,7 +425,7 @@ impl Generator {
hex::encode(script_hash.as_slice())
);
state
.get_script(&script_hash)
.get_script(script_hash)
.and_then(|script| {
// only accept type script hash type for now
if script.hash_type() == ScriptHashType::Type.into() {
Expand Down
14 changes: 7 additions & 7 deletions crates/generator/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn load_data_h256<Mac: SupportMachine>(machine: &mut Mac, addr: u64) -> Result<H
Ok(H256::from(data))
}

#[allow(clippy::clippy::needless_range_loop)]
#[allow(clippy::needless_range_loop)]
fn load_bytes<Mac: SupportMachine>(
machine: &mut Mac,
addr: u64,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'a, S: State, C: ChainStore, Mac: SupportMachine> Syscalls<Mac> for L2Sysca
let value = self.get_raw(&key)?;
machine
.memory_mut()
.store_bytes(value_addr, &value.as_slice())?;
.store_bytes(value_addr, value.as_slice())?;
machine.set_register(A0, Mac::REG::from_u8(SUCCESS));
Ok(true)
}
Expand Down Expand Up @@ -482,10 +482,10 @@ impl<'a, S: State, C: ChainStore, Mac: SupportMachine> Syscalls<Mac> for L2Sysca

impl<'a, S: State, C: ChainStore> L2Syscalls<'a, S, C> {
fn get_raw(&mut self, key: &H256) -> Result<H256, VMError> {
let value = match self.result.write_values.get(&key) {
let value = match self.result.write_values.get(key) {
Some(value) => *value,
None => {
let tree_value = self.state.get_raw(&key).map_err(|_| VMError::Unexpected)?;
let tree_value = self.state.get_raw(key).map_err(|_| VMError::Unexpected)?;
self.result.read_values.insert(*key, tree_value);
tree_value
}
Expand All @@ -510,8 +510,8 @@ impl<'a, S: State, C: ChainStore> L2Syscalls<'a, S, C> {
.result
.new_scripts
.get(script_hash)
.map(|data| Script::from_slice(&data).expect("Script"))
.or_else(|| self.code_store.get_script(&script_hash));
.map(|data| Script::from_slice(data).expect("Script"))
.or_else(|| self.code_store.get_script(script_hash));

if let Some(ref script) = opt_script {
self.result.get_scripts.insert(script.as_slice().to_vec());
Expand All @@ -524,7 +524,7 @@ impl<'a, S: State, C: ChainStore> L2Syscalls<'a, S, C> {
.write_data
.get(data_hash)
.map(|data| Bytes::from(data.clone()))
.or_else(|| self.code_store.get_data(&data_hash))
.or_else(|| self.code_store.get_data(data_hash))
}
fn get_script_hash(&mut self, id: u32) -> Result<H256, VMError> {
let value = self
Expand Down
8 changes: 4 additions & 4 deletions crates/generator/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<S: State + CodeStore> StateExt for S {
self.set_account_count(id)?;
}
for (script_hash, script) in &run_result.new_scripts {
self.insert_script(*script_hash, Script::from_slice(&script).expect("script"));
self.insert_script(*script_hash, Script::from_slice(script).expect("script"));
}
for (data_hash, data) in &run_result.write_data {
self.insert_data(*data_hash, Bytes::from(data.clone()));
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<S: State + CodeStore> StateExt for S {
let amount = request.amount().unpack();
if sudt_script_hash != CKB_SUDT_SCRIPT_ARGS.into() {
// find or create Simple UDT account
let l2_sudt_script = build_l2_sudt_script(&ctx, &sudt_script_hash);
let l2_sudt_script = build_l2_sudt_script(ctx, &sudt_script_hash);
let l2_sudt_script_hash: [u8; 32] = l2_sudt_script.hash();
let sudt_id = match self.get_account_id_by_script_hash(&l2_sudt_script_hash.into())? {
Some(id) => id,
Expand Down Expand Up @@ -183,7 +183,7 @@ impl<S: State + CodeStore> StateExt for S {
let raw = request.raw();
let account_script_hash: H256 = raw.account_script_hash().unpack();
let l2_sudt_script_hash: [u8; 32] =
build_l2_sudt_script(&ctx, &raw.sudt_script_hash().unpack()).hash();
build_l2_sudt_script(ctx, &raw.sudt_script_hash().unpack()).hash();
let amount: u128 = raw.amount().unpack();
let withdrawal_short_address = to_short_address(&account_script_hash);
// find user account
Expand All @@ -196,7 +196,7 @@ impl<S: State + CodeStore> StateExt for S {
let sudt_id: u32 = raw.fee().sudt_id().unpack();
let amount: u128 = raw.fee().amount().unpack();
let block_producer_script_hash = self.get_script_hash(block_producer_id)?;
let block_producer_short_address = to_short_address(&&block_producer_script_hash);
let block_producer_short_address = to_short_address(&block_producer_script_hash);
self.pay_fee(
withdrawal_short_address,
block_producer_short_address,
Expand Down
Loading