Skip to content

Commit

Permalink
Revert "Merge pull request #4512 from driftluo/impl-from-into-for-gen…
Browse files Browse the repository at this point in the history
…-type"

This reverts commit 18c68f5, reversing
changes made to 0274984.
  • Loading branch information
zhangsoledad committed Oct 9, 2024
1 parent d8fc09a commit 54d5edb
Show file tree
Hide file tree
Showing 248 changed files with 4,189 additions and 7,165 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL:=help
SHELL = /bin/sh
MOLC := moleculec
MOLC_VERSION := 0.8.0
MOLC_VERSION := 0.7.5
VERBOSE := $(if ${CI},--verbose,)
CLIPPY_OPTS := -D warnings -D clippy::clone_on_ref_ptr -D clippy::redundant_clone -D clippy::enum_glob_use -D clippy::fallible_impl_from \
-A clippy::mutable_key_type -A clippy::upper_case_acronyms -A clippy::needless_return
Expand Down
14 changes: 7 additions & 7 deletions benches/benches/benchmarks/overall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const SIZES: &[usize] = &[2usize];

fn block_assembler_config() -> BlockAssemblerConfig {
let (_, _, secp_script) = secp_cell();
let args = JsonBytes::from_bytes(secp_script.args().into());
let args = JsonBytes::from_bytes(secp_script.args().unpack());
let hash_type = ScriptHashType::try_from(secp_script.hash_type()).expect("checked data");

BlockAssemblerConfig {
code_hash: secp_script.code_hash().into(),
code_hash: secp_script.code_hash().unpack(),
hash_type: hash_type.into(),
args,
message: Default::default(),
Expand Down Expand Up @@ -92,21 +92,21 @@ pub fn setup_chain(txs_size: usize) -> (Shared, ChainController) {
.map(|i| {
let data = Bytes::from(i.to_le_bytes().to_vec());
let output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000))
.capacity(capacity_bytes!(50_000).pack())
.lock(secp_script.clone())
.build();
TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), 0))
.output(output.clone())
.output(output)
.output_data(&data)
.output_data(&data)
.output_data(data.pack())
.output_data(data.pack())
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.dao(dao)
.transaction(tx)
.transactions(transactions)
Expand Down Expand Up @@ -207,7 +207,7 @@ fn bench(c: &mut Criterion) {
let raw_header = raw_block.header().raw();
let header = Header::new_builder()
.raw(raw_header)
.nonce(random::<u128>())
.nonce(random::<u128>().pack())
.build();
let block = raw_block.as_builder().header(header).build().into_view();

Expand Down
17 changes: 10 additions & 7 deletions benches/benches/benchmarks/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,32 @@ const DEFAULT_CODE_HASH: H256 =

fn script() -> Script {
Script::new_builder()
.code_hash(DEFAULT_CODE_HASH)
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
.hash_type(ScriptHashType::Type)
.code_hash(DEFAULT_CODE_HASH.pack())
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
.hash_type(ScriptHashType::Type.into())
.build()
}

fn cell_dep(genesis: &BlockView) -> CellDep {
let tx_hash = genesis.transaction(1).unwrap().hash();
let out_point = OutPoint::new_builder().tx_hash(tx_hash).index(0u32).build();
let out_point = OutPoint::new_builder()
.tx_hash(tx_hash)
.index(0u32.pack())
.build();

CellDep::new_builder()
.out_point(out_point)
.dep_type(DepType::DepGroup)
.dep_type(DepType::DepGroup.into())
.build()
}

fn block_assembler_config() -> BlockAssemblerConfig {
let secp_script = script();
let args = JsonBytes::from_bytes(secp_script.args().into());
let args = JsonBytes::from_bytes(secp_script.args().unpack());
let hash_type = ScriptHashType::try_from(secp_script.hash_type()).expect("checked data");

BlockAssemblerConfig {
code_hash: secp_script.code_hash().into(),
code_hash: secp_script.code_hash().unpack(),
hash_type: hash_type.into(),
args,
message: Default::default(),
Expand Down
72 changes: 36 additions & 36 deletions benches/benches/benchmarks/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ pub fn new_always_success_chain(txs_size: usize, chains_num: usize) -> Chains {
.input(CellInput::new(OutPoint::null(), 0))
.output(
CellOutput::new_builder()
.capacity(capacity_bytes!(50_000))
.capacity(capacity_bytes!(50_000).pack())
.lock(always_success_script.clone())
.build(),
)
.output_data(data)
.output_data(data.pack())
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.dao(dao)
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.transaction(tx)
.transactions(transactions)
.build();
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn create_always_success_tx() -> TransactionView {
.witness(script.clone().into_witness())
.input(CellInput::new(OutPoint::null(), 0))
.output(always_success_cell.clone())
.output_data(always_success_cell_data)
.output_data(always_success_cell_data.pack())
.build()
}

Expand All @@ -110,11 +110,11 @@ pub fn create_always_success_cellbase(shared: &Shared, parent: &HeaderView) -> T
builder
.output(
CellOutput::new_builder()
.capacity(capacity)
.capacity(capacity.pack())
.lock(always_success_script.clone())
.build(),
)
.output_data(Bytes::new())
.output_data(Bytes::new().pack())
.build()
}
}
Expand Down Expand Up @@ -185,11 +185,11 @@ pub fn gen_always_success_block(
.transactions(transactions)
.proposals(proposals)
.parent_hash(p_block.hash())
.number(number)
.timestamp(timestamp)
.compact_target(epoch.compact_target())
.epoch(epoch.number_with_fraction(number))
.nonce(random::<u128>())
.number(number.pack())
.timestamp(timestamp.pack())
.compact_target(epoch.compact_target().pack())
.epoch(epoch.number_with_fraction(number).pack())
.nonce(random::<u128>().pack())
.dao(dao)
.build();

Expand All @@ -208,7 +208,7 @@ lazy_static! {
let data: Bytes = raw_data.to_vec().into();

let cell = CellOutput::new_builder()
.capacity(Capacity::bytes(data.len()).unwrap())
.capacity(Capacity::bytes(data.len()).unwrap().pack())
.build();
(cell, data)
};
Expand All @@ -219,13 +219,13 @@ lazy_static! {
let data: Bytes = raw_data.to_vec().into();

let cell = CellOutput::new_builder()
.capacity(Capacity::bytes(data.len()).unwrap())
.capacity(Capacity::bytes(data.len()).unwrap().pack())
.build();

let script = Script::new_builder()
.code_hash(CellOutput::calc_data_hash(&data))
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
.hash_type(ScriptHashType::Data)
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
.hash_type(ScriptHashType::Data.into())
.build();

(cell, data, script)
Expand All @@ -244,7 +244,7 @@ pub fn create_secp_tx() -> TransactionView {
let (ref secp_data_cell, ref secp_data_cell_data) = secp_data_cell();
let (ref secp_cell, ref secp_cell_data, ref script) = secp_cell();
let outputs = vec![secp_data_cell.clone(), secp_cell.clone()];
let outputs_data = vec![secp_data_cell_data.into(), secp_cell_data.into()];
let outputs_data = vec![secp_data_cell_data.pack(), secp_cell_data.pack()];
TransactionBuilder::default()
.witness(script.clone().into_witness())
.input(CellInput::new(OutPoint::null(), 0))
Expand All @@ -263,21 +263,21 @@ pub fn new_secp_chain(txs_size: usize, chains_num: usize) -> Chains {
.map(|i| {
let data = Bytes::from(i.to_le_bytes().to_vec());
let output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000))
.capacity(capacity_bytes!(50_000).pack())
.lock(secp_script.clone())
.build();
TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), 0))
.output(output.clone())
.output(output)
.output_data(&data)
.output_data(&data)
.output_data(data.pack())
.output_data(data.pack())
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.dao(dao)
.transaction(tx)
.transactions(transactions)
Expand Down Expand Up @@ -318,11 +318,11 @@ pub fn create_secp_cellbase(shared: &Shared, parent: &HeaderView) -> Transaction
builder
.output(
CellOutput::new_builder()
.capacity(capacity)
.capacity(capacity.pack())
.lock(secp_script.clone())
.build(),
)
.output_data(Bytes::new())
.output_data(Bytes::new().pack())
.build()
}
}
Expand Down Expand Up @@ -395,11 +395,11 @@ pub fn gen_secp_block(
.transactions(transactions)
.proposals(proposals)
.parent_hash(p_block.hash())
.number(number)
.timestamp(timestamp)
.compact_target(epoch.compact_target())
.epoch(epoch.number_with_fraction(number))
.nonce(random::<u128>())
.number(number.pack())
.timestamp(timestamp.pack())
.compact_target(epoch.compact_target().pack())
.epoch(epoch.number_with_fraction(number).pack())
.nonce(random::<u128>().pack())
.dao(dao)
.build();

Expand All @@ -412,11 +412,11 @@ fn create_transaction(parent_hash: &Byte32, lock: Script, dep: OutPoint) -> Tran
TransactionBuilder::default()
.output(
CellOutput::new_builder()
.capacity(capacity_bytes!(50_000))
.capacity(capacity_bytes!(50_000).pack())
.lock(lock)
.build(),
)
.output_data(data)
.output_data(data.pack())
.input(CellInput::new(OutPoint::new(parent_hash.to_owned(), 0), 0))
.cell_dep(CellDep::new_builder().out_point(dep).build())
.build()
Expand All @@ -431,7 +431,7 @@ pub fn create_2out_transaction(

let cell_inputs = inputs.into_iter().map(|pts| CellInput::new(pts, 0));
let cell_output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000))
.capacity(capacity_bytes!(50_000).pack())
.lock(lock)
.build();

Expand All @@ -440,15 +440,15 @@ pub fn create_2out_transaction(
let raw = TransactionBuilder::default()
.output(cell_output.clone())
.output(cell_output)
.output_data(&data)
.output_data(&data)
.output_data(data.pack())
.output_data(data.pack())
.inputs(cell_inputs)
.cell_deps(cell_deps)
.build();

let privkey: Privkey = PRIVKEY.into();
let witness: WitnessArgs = WitnessArgs::new_builder()
.lock(Some(Bytes::from(vec![0u8; 65])))
.lock(Some(Bytes::from(vec![0u8; 65])).pack())
.build();
let witness_len: u64 = witness.as_bytes().len() as u64;
let non_sig_witnesses = vec![Bytes::new(); inputs_count - 1];
Expand All @@ -470,10 +470,10 @@ pub fn create_2out_transaction(
.expect("sign tx")
.serialize()
.into();
let witness = witness.as_builder().lock(Some(sig)).build();
let witness = witness.as_builder().lock(Some(sig).pack()).build();

let mut witnesses = vec![witness.as_bytes().into()];
witnesses.extend(non_sig_witnesses.into_iter().map(|w| w.into()));
let mut witnesses = vec![witness.as_bytes().pack()];
witnesses.extend(non_sig_witnesses.into_iter().map(|w| w.pack()));

raw.as_advanced_builder().set_witnesses(witnesses).build()
}
Expand Down
5 changes: 3 additions & 2 deletions block-filter/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ckb_store::{ChainDB, ChainStore};
use ckb_types::{
core::HeaderView,
packed::{Byte32, CellOutput, OutPoint},
prelude::*,
utilities::{build_filter_data, FilterDataProvider},
};

Expand All @@ -25,7 +26,7 @@ impl<'a> FilterDataProvider for WrappedChainDB<'a> {
fn cell(&self, out_point: &OutPoint) -> Option<CellOutput> {
self.inner
.get_transaction(&out_point.tx_hash())
.and_then(|(tx, _)| tx.outputs().get(out_point.index().into()))
.and_then(|(tx, _)| tx.outputs().get(out_point.index().unpack()))
}
}

Expand Down Expand Up @@ -157,7 +158,7 @@ impl BlockFilter {
db_transaction
.insert_block_filter(
&header.hash(),
&filter_data.as_slice().into(),
&filter_data.pack(),
&parent_block_filter_hash,
)
.expect("insert_block_filter should be ok");
Expand Down
4 changes: 2 additions & 2 deletions chain/src/init_load_unverified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ckb_stop_handler::has_received_stop_signal;
use ckb_store::ChainStore;
use ckb_types::core::{BlockNumber, BlockView};
use ckb_types::packed;
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Reader};
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Pack, Reader};
use std::cmp;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
Expand All @@ -34,7 +34,7 @@ impl InitLoadUnverified {
}

fn find_unverified_block_hashes(&self, check_unverified_number: u64) -> Vec<packed::Byte32> {
let pack_number: packed::Uint64 = check_unverified_number.into();
let pack_number: packed::Uint64 = check_unverified_number.pack();
let prefix = pack_number.as_slice();

// If a block has `COLUMN_NUMBER_HASH` but not `BlockExt`,
Expand Down
9 changes: 5 additions & 4 deletions chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod verify;
pub use chain_controller::ChainController;
use ckb_logger::{error, info};
use ckb_store::{ChainDB, ChainStore};
use ckb_types::prelude::{Pack, Unpack};
use ckb_types::{BlockNumberAndHash, H256};
pub use init::start_chain_services;

Expand Down Expand Up @@ -88,11 +89,11 @@ impl From<LonelyBlock> for LonelyBlockHash {
switch,
verify_callback,
} = val;
let block_hash_h256: H256 = block.hash().into();
let block_hash_h256: H256 = block.hash().unpack();
let block_number: BlockNumber = block.number();
let parent_hash_h256: H256 = block.parent_hash().into();
let block_hash = block_hash_h256.into();
let parent_hash = parent_hash_h256.into();
let parent_hash_h256: H256 = block.parent_hash().unpack();
let block_hash = block_hash_h256.pack();
let parent_hash = parent_hash_h256.pack();

let epoch_number: EpochNumber = block.epoch().number();

Expand Down
Loading

0 comments on commit 54d5edb

Please sign in to comment.