Skip to content

Commit

Permalink
Merge #1356
Browse files Browse the repository at this point in the history
1356: refactor: Add CellDep and change OutPoint data structure r=TheWaWaR a=TheWaWaR

1. Add a new `CellDep` data structure, and changed `Transaction`:
``` rust
// For support dep group
pub struct CellDep {
    out_point: OutPoint,
    is_dep_group: bool,
}

// deps changed to cell_deps and header_deps
pub struct Transaction {
    // ...
    cell_deps: Vec<CellDep>,
    header_deps: Vec<H256>,
    // ...
}
```

2. `OutPoint` data structure renamed from origin `CellOutPoint`.
3. `HeaderProvider` changed to `HeaderChecker` because header now lazy loaded.

4. `SourceEntry` rename `Dep` to `CellDep` and add a new variant `CellHeader`, you can load `CellHeader` from `deps.headers` by index in VM.
``` rust
enum SourceEntry {
    Input,
    Output,
    // Cell dep
    CellDep,
    // Header dep
    CellHeader,
}
```

Co-authored-by: Linfeng Qian <[email protected]>
Co-authored-by: Qian Linfeng <[email protected]>
  • Loading branch information
bors[bot] and TheWaWaR committed Aug 11, 2019
2 parents cae9a38 + 7a6fb0b commit 21cf079
Show file tree
Hide file tree
Showing 62 changed files with 2,145 additions and 2,271 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

15 changes: 6 additions & 9 deletions benches/benches/benchmarks/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ckb_core::cell::{resolve_transaction, OverlayCellProvider, TransactionsProvi
use ckb_core::header::{Header, HeaderBuilder};
use ckb_core::script::{Script, ScriptHashType};
use ckb_core::transaction::{
CellInput, CellOutput, CellOutputBuilder, OutPoint, ProposalShortId, Transaction,
CellDep, CellInput, CellOutput, CellOutputBuilder, OutPoint, ProposalShortId, Transaction,
TransactionBuilder,
};
use ckb_core::{capacity_bytes, Bytes, Capacity};
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn gen_always_success_block(
shared: &Shared,
) -> Block {
let tx = create_always_success_tx();
let always_success_out_point = OutPoint::new_cell(tx.hash().to_owned(), 0);
let always_success_out_point = OutPoint::new(tx.hash().to_owned(), 0);
let (_, _, always_success_script) = always_success_cell();
let (number, timestamp, difficulty) = (
p_block.header().number() + 1,
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn create_secp_cellbase(shared: &Shared, parent: &Header) -> Transaction {

pub fn gen_secp_block(blocks: &mut Vec<Block>, p_block: &Block, shared: &Shared) -> Block {
let tx = create_secp_tx();
let secp_out_point = OutPoint::new_cell(tx.hash().to_owned(), 0);
let secp_out_point = OutPoint::new(tx.hash().to_owned(), 0);
let (_, _, secp_script) = secp_cell();
let (number, timestamp, difficulty) = (
p_block.header().number() + 1,
Expand Down Expand Up @@ -369,11 +369,8 @@ fn create_transaction(parent_hash: &H256, lock: Script, dep: OutPoint) -> Transa
None,
))
.output_data(data)
.input(CellInput::new(
OutPoint::new_cell(parent_hash.to_owned(), 0),
0,
))
.dep(dep)
.input(CellInput::new(OutPoint::new(parent_hash.to_owned(), 0), 0))
.cell_dep(CellDep::new_cell(dep))
.build()
}

Expand All @@ -394,7 +391,7 @@ fn create_2out_transaction(inputs: Vec<OutPoint>, lock: Script, dep: OutPoint) -
.output_data(data.clone())
.output_data(data)
.inputs(cell_inputs)
.dep(dep)
.cell_dep(CellDep::new_cell(dep))
.build();

let privkey: Privkey = PRIVKEY.into();
Expand Down
32 changes: 15 additions & 17 deletions chain/src/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use ckb_core::extras::{EpochExt, TransactionInfo};
use ckb_core::header::Header;
use ckb_core::header::HeaderBuilder;
use ckb_core::script::Script;
use ckb_core::transaction::{
CellInput, CellOutPoint, CellOutputBuilder, OutPoint, TransactionBuilder,
};
use ckb_core::transaction::{CellInput, CellOutputBuilder, OutPoint, TransactionBuilder};
use ckb_core::{capacity_bytes, Bytes, Capacity};
use ckb_dao_utils::genesis_dao_data;
use ckb_shared::error::SharedError;
Expand Down Expand Up @@ -111,7 +109,7 @@ fn test_genesis_transaction_spend() {
assert_eq!(
shared
.lock_chain_state()
.cell(&OutPoint::new_cell(genesis_tx_hash, 0)),
.cell(&OutPoint::new(genesis_tx_hash, 0), false),
CellStatus::Dead
);
}
Expand All @@ -138,7 +136,7 @@ fn test_transaction_spend_in_same_block() {
assert_eq!(
shared
.lock_chain_state()
.cell(&OutPoint::new_cell(hash.to_owned().to_owned(), 0)),
.cell(&OutPoint::new(hash.to_owned().to_owned(), 0), false),
CellStatus::Unknown
);
}
Expand Down Expand Up @@ -167,25 +165,25 @@ fn test_transaction_spend_in_same_block() {
assert_eq!(
shared
.lock_chain_state()
.cell(&OutPoint::new_cell(last_cell_base_hash.to_owned(), 0)),
.cell(&OutPoint::new(last_cell_base_hash.to_owned(), 0), false),
CellStatus::Unknown
);

assert_eq!(
shared
.lock_chain_state()
.cell(&OutPoint::new_cell(tx1_hash.to_owned(), 0)),
.cell(&OutPoint::new(tx1_hash.to_owned(), 0), false),
CellStatus::Dead
);

assert_eq!(
shared
.lock_chain_state()
.cell(&OutPoint::new_cell(tx2_hash.to_owned(), 0)),
.cell(&OutPoint::new(tx2_hash.to_owned(), 0), false),
CellStatus::live_cell(CellMeta {
cell_output: tx2_output,
data_bytes: tx2_output_data.len() as u64,
out_point: CellOutPoint {
out_point: OutPoint {
tx_hash: tx2_hash.to_owned(),
index: 0
},
Expand Down Expand Up @@ -222,7 +220,7 @@ fn test_transaction_conflict_in_same_block() {
.expect("process block ok");
}
assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new(
tx1_hash.to_owned(),
0
))),
Expand Down Expand Up @@ -264,7 +262,7 @@ fn test_transaction_conflict_in_different_blocks() {
.expect("process block ok");
}
assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new(
tx1_hash.to_owned(),
0
))),
Expand All @@ -288,7 +286,7 @@ fn test_invalid_out_point_index_in_same_block() {
let tx1_hash = tx1.hash().to_owned();
let tx2 = create_transaction(&tx1_hash, 2);
// create an invalid OutPoint index
let tx3 = create_transaction_with_out_point(OutPoint::new_cell(tx1_hash.clone(), 1), 3);
let tx3 = create_transaction_with_out_point(OutPoint::new(tx1_hash.clone(), 1), 3);
let txs = vec![tx1, tx2, tx3];
// proposal txs
chain.gen_block_with_proposal_txs(txs.clone(), &mock_store);
Expand All @@ -303,7 +301,7 @@ fn test_invalid_out_point_index_in_same_block() {
.expect("process block ok");
}
assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new(
tx1_hash.to_owned(),
1,
)])),
Expand All @@ -327,7 +325,7 @@ fn test_invalid_out_point_index_in_different_blocks() {
let tx1_hash = tx1.hash();
let tx2 = create_transaction(tx1_hash, 2);
// create an invalid OutPoint index
let tx3 = create_transaction_with_out_point(OutPoint::new_cell(tx1_hash.clone(), 1), 3);
let tx3 = create_transaction_with_out_point(OutPoint::new(tx1_hash.clone(), 1), 3);
// proposal txs
chain.gen_block_with_proposal_txs(vec![tx1.clone(), tx2.clone(), tx3.clone()], &mock_store);
// empty N+1 block
Expand All @@ -344,7 +342,7 @@ fn test_invalid_out_point_index_in_different_blocks() {
}

assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new(
tx1_hash.to_owned(),
1,
)])),
Expand Down Expand Up @@ -381,8 +379,8 @@ fn test_genesis_transaction_fetch() {
let consensus = Consensus::default().set_genesis_block(genesis_block);
let (_chain_controller, shared, _parent) = start_chain(Some(consensus));

let out_point = OutPoint::new_cell(root_hash, 0);
let state = shared.lock_chain_state().cell(&out_point);
let out_point = OutPoint::new(root_hash, 0);
let state = shared.lock_chain_state().cell(&out_point, false);
assert!(state.is_live());
}

Expand Down
14 changes: 6 additions & 8 deletions chain/src/tests/delay_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ fn test_dead_cell_in_same_block() {
}

assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new_cell(
tx1_hash, 0
))),
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new(tx1_hash, 0))),
chain_controller
.process_block(
Arc::new(chain2.blocks()[switch_fork_number + 1].clone()),
Expand Down Expand Up @@ -117,7 +115,7 @@ fn test_dead_cell_in_different_block() {
}

assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Dead(OutPoint::new(
tx1_hash.to_owned(),
0
))),
Expand Down Expand Up @@ -155,7 +153,7 @@ fn test_invalid_out_point_index_in_same_block() {
let tx1_hash = tx1.hash().to_owned();
let tx2 = create_transaction(&tx1_hash, 2);
// create an invalid OutPoint index
let tx3 = create_transaction_with_out_point(OutPoint::new_cell(tx1_hash.clone(), 1), 3);
let tx3 = create_transaction_with_out_point(OutPoint::new(tx1_hash.clone(), 1), 3);
let txs = vec![tx1, tx2, tx3];

chain2.gen_block_with_proposal_txs(txs.clone(), &mock_store);
Expand All @@ -178,7 +176,7 @@ fn test_invalid_out_point_index_in_same_block() {
}

assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new(
tx1_hash, 1,
)])),
chain_controller
Expand Down Expand Up @@ -215,7 +213,7 @@ fn test_invalid_out_point_index_in_different_blocks() {
let tx1_hash = tx1.hash();
let tx2 = create_transaction(tx1_hash, 2);
// create an invalid OutPoint index
let tx3 = create_transaction_with_out_point(OutPoint::new_cell(tx1_hash.clone(), 1), 3);
let tx3 = create_transaction_with_out_point(OutPoint::new(tx1_hash.clone(), 1), 3);

chain2.gen_block_with_proposal_txs(vec![tx1.clone(), tx2.clone(), tx3.clone()], &mock_store);
chain2.gen_empty_block(20000u64, &mock_store);
Expand All @@ -239,7 +237,7 @@ fn test_invalid_out_point_index_in_different_blocks() {
}

assert_eq!(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new_cell(
SharedError::UnresolvableTransaction(UnresolvableError::Unknown(vec![OutPoint::new(
tx1_hash.to_owned(),
1,
)])),
Expand Down
7 changes: 4 additions & 3 deletions chain/src/tests/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use ckb_core::block::{Block, BlockBuilder};
use ckb_core::header::{Header, HeaderBuilder};
use ckb_core::script::{Script, ScriptHashType};
use ckb_core::transaction::{
CellInput, CellOutputBuilder, OutPoint, ProposalShortId, Transaction, TransactionBuilder,
CellDep, CellInput, CellOutputBuilder, OutPoint, ProposalShortId, Transaction,
TransactionBuilder,
};
use ckb_core::uncle::UncleBlock;
use ckb_core::{capacity_bytes, Bytes, Capacity};
Expand Down Expand Up @@ -99,10 +100,10 @@ pub(crate) fn create_transaction(parent: &Transaction, index: u32) -> Transactio
)
.output_data(Bytes::new())
.input(CellInput::new(
OutPoint::new_cell(parent.hash().to_owned(), index),
OutPoint::new(parent.hash().to_owned(), index),
0,
))
.dep(always_success_out_point)
.cell_dep(CellDep::new_cell(always_success_out_point))
.build()
}

Expand Down
10 changes: 5 additions & 5 deletions chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ckb_core::block::BlockBuilder;
use ckb_core::cell::{resolve_transaction, OverlayCellProvider, TransactionsProvider};
use ckb_core::header::{Header, HeaderBuilder};
use ckb_core::transaction::{
CellInput, CellOutput, CellOutputBuilder, OutPoint, Transaction, TransactionBuilder,
CellDep, CellInput, CellOutput, CellOutputBuilder, OutPoint, Transaction, TransactionBuilder,
};
use ckb_core::{capacity_bytes, Bytes, Capacity};
use ckb_dao::DaoCalculator;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub(crate) fn create_always_success_tx() -> Transaction {
// NOTE: this is quite a waste of resource but the alternative is to modify 100+
// invocations, let's stick to this way till this becomes a real problem
pub(crate) fn create_always_success_out_point() -> OutPoint {
OutPoint::new_cell(create_always_success_tx().hash().to_owned(), 0)
OutPoint::new(create_always_success_tx().hash().to_owned(), 0)
}

pub(crate) fn start_chain(consensus: Option<Consensus>) -> (ChainController, Shared, Header) {
Expand Down Expand Up @@ -148,12 +148,12 @@ pub(crate) fn create_multi_outputs_transaction(
.outputs(outputs)
.outputs_data(outputs_data)
.inputs(inputs)
.dep(always_success_out_point)
.cell_dep(CellDep::new_cell(always_success_out_point))
.build()
}

pub(crate) fn create_transaction(parent: &H256, unique_data: u8) -> Transaction {
create_transaction_with_out_point(OutPoint::new_cell(parent.to_owned(), 0), unique_data)
create_transaction_with_out_point(OutPoint::new(parent.to_owned(), 0), unique_data)
}

pub(crate) fn create_transaction_with_out_point(
Expand All @@ -173,7 +173,7 @@ pub(crate) fn create_transaction_with_out_point(
))
.output_data(data)
.input(CellInput::new(out_point, 0))
.dep(always_success_out_point)
.cell_dep(CellDep::new_cell(always_success_out_point))
.build()
}

Expand Down
1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ckb-hash = {path = "../util/hash"}
ckb-occupied-capacity = { path = "../util/occupied-capacity"}
bit-vec = "0.5.1"
crossbeam-channel = "0.3"
ckb-util = { path = "../util" }
fnv = "1.0.3"
ckb-merkle-tree = {path = "../util/merkle-tree"}
faster-hex = "0.3"
Expand Down
Loading

0 comments on commit 21cf079

Please sign in to comment.