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

feat: Refactor OutPoint and add dep group support #1331

Closed
wants to merge 21 commits into from

Conversation

TheWaWaR
Copy link
Contributor

@TheWaWaR TheWaWaR commented Aug 2, 2019

  • Change struct OutPoint
  • Add enum CellDep
  • Change trait CellProvider and trait HeaderProvider
  • Add dep group support
  • Fix tests for chain module
  • Add tests for dep group
  • Rebase to develop

@nervos-bot
Copy link

nervos-bot bot commented Aug 2, 2019

@keroro520 is assigned as the chief reviewer

@TheWaWaR TheWaWaR force-pushed the dep-group-support branch from 7c8230e to 399cc9b Compare August 2, 2019 09:39
core/src/cell.rs Show resolved Hide resolved
core/src/cell.rs Outdated Show resolved Hide resolved
core/src/cell.rs Show resolved Hide resolved
core/src/cell.rs Show resolved Hide resolved
core/src/cell.rs Show resolved Hide resolved
core/src/cell.rs Show resolved Hide resolved
core/src/transaction.rs Outdated Show resolved Hide resolved
block_hash: H256;
dep_type: uint8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a enum type here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should change Script.hash_type to enum as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a note regarding this here:

ckb/core/src/script.rs

Lines 11 to 15 in 59e7b47

// NOTE: we could've used enum as well in the wire format, but as of
// flatbuffer 1.11.0, unused constants will be generated in the Rust
// code for enum types, resulting in both compiler warnings and clippy
// errors. So for now we are sticking to a single integer in the wire
// format, and only use enums in core data structures.

core/src/cell.rs Show resolved Hide resolved
core/src/transaction.rs Show resolved Hide resolved
@keroro520
Copy link
Contributor

Previously we are allowed to specify block_hash in input-out-point, to ensure that the previous_output was contained in the given block.

I notice this PR remove block_hash from OutPoint, so that means we don't support this kind of inputs?

@TheWaWaR
Copy link
Contributor Author

TheWaWaR commented Aug 5, 2019

I notice this PR remove block_hash from OutPoint, so that means we don't support this kind of inputs?

Yes, we now should define this relationship in dep. dao is a good use case to learn this.

76e2a6b#diff-2d93f2ba5649afea4f5fbe0659022793R209

@TheWaWaR TheWaWaR force-pushed the dep-group-support branch from df0584f to 2704bd5 Compare August 5, 2019 17:19
util/jsonrpc-types/src/blockchain.rs Outdated Show resolved Hide resolved
@TheWaWaR TheWaWaR force-pushed the dep-group-support branch from 2704bd5 to 69204a7 Compare August 6, 2019 04:29
util/jsonrpc-types/src/blockchain.rs Outdated Show resolved Hide resolved
@TheWaWaR TheWaWaR marked this pull request as ready for review August 6, 2019 06:18
@TheWaWaR TheWaWaR requested a review from a team August 6, 2019 06:18
@TheWaWaR TheWaWaR force-pushed the dep-group-support branch from 6894bcd to 1584d94 Compare August 6, 2019 09:21
let tx_hash = H256::from_slice(&data[tx_hash_start..tx_hash_end])
.expect("Invalid tx hash length");
let mut index_bytes = [0u8; mem::size_of::<u32>()];
index_bytes.copy_from_slice(&data[index_start..index_end]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index_bytes.copy_from_slice(&data[index_start..]);

/// Convert OutPoint to one dep group data item
pub fn to_group_data(&self) -> Vec<u8> {
[self.tx_hash.to_vec(), self.index.to_le_bytes().to_vec()].concat()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests for the from/to conversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to CellKey's implementation (see the code above in the same file).

@@ -31,7 +32,7 @@ impl BlockInfo {
pub struct CellMeta {
#[serde(skip)]
pub cell_output: CellOutput,
pub out_point: CellOutPoint,
pub out_point: OutPoint,
pub block_info: Option<BlockInfo>,
pub cellbase: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another struct TransactionInfo https://github.com/nervosnetwork/ckb/blob/develop/core/src/extras.rs#L19
It's similar to the BlockInfo, it seems that we can remove the BlockInfo, and we can remove the pub cellbase: bool as well, I think whether it's a cellbase depends on the position in the Block. https://github.com/nervosnetwork/ckb/blob/develop/store/src/store.rs#L195

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a new issue for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead(OutPoint),
Unknown(Vec<OutPoint>),
OutOfOrder(OutPoint),
}

pub fn parse_dep_group_data(data: Bytes) -> Result<Vec<OutPoint>, usize> {
// tx hash (32 bytes) + output index (4 bytes)
const OUT_POINT_LEN: usize = mem::size_of::<H256>() + mem::size_of::<u32>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put it in transaction.rs?

@TheWaWaR
Copy link
Contributor Author

TheWaWaR commented Aug 8, 2019

Close this by: #1356

@TheWaWaR TheWaWaR closed this Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants