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

Block, BlockHeader and Block messages #21

Merged
merged 17 commits into from
Sep 27, 2019
Merged

Block, BlockHeader and Block messages #21

merged 17 commits into from
Sep 27, 2019

Conversation

dconnolly
Copy link
Contributor

@dconnolly dconnolly commented Sep 24, 2019

Resolves #7


/// The hash value of the previous block (header) this
/// particular block references.
prev_block: BlockHeaderHash,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these fields except the txns come out of BlockHeader, is there a better way to do this without straight-up serializing BlockHeader etc as the Block message?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, what if the Block variant of the Message enum just contains a Block object, and the message codec calls Block::zcash_serialize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love it. 💃

@dconnolly dconnolly marked this pull request as ready for review September 26, 2019 07:05

impl BlockHeader {
/// Get the SHA-256d hash in internal byte order of this block header.
pub fn hash(&self) -> [u8; 32] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have impl From<BlockHeader> for BlockHeaderHash, I think we don't need this function? We can just use BlockHeaderHash::from(block_header) or even block_header.into().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, removing. I think this was a leftover artifact before we decided to do BlockHeaderHash::from() instead.

.expect("The merkle tree of transactions must serialize.");
Self(hash_writer.finish())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these impls (L29-L54) live with the MerkleTree definition in merkle_tree.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think you are correct.

}

impl<T> MerkleTree<T> {
pub fn get_root(&self) -> Sha256 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a duplicate of impl From<MerkleTree> for MerkleRootHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it is, hm.

use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};

// XXX: Depending on if we implement SproutNoteCommitmentTree or
// similar, it may be worth it to define a NoteCommitmentTree trait.
Copy link
Contributor

Choose a reason for hiding this comment

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

not a comment scoped to this PR, but branching point for further discussion in a separate issue: we may need a sprout note commitment tree, even if we checkpoint on sapling activation, in order to do sprout-on-groth16 proofs to move old sprout value.

@hdevalence
Copy link
Contributor

I think some of the MerkleTree impls should move into merkle_tree.rs, but other than that this LGTM!

Copy link
Contributor

@hdevalence hdevalence left a comment

Choose a reason for hiding this comment

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

oops, forgot to put the preceding as a review status

Block { ref block } => {
block
.zcash_serialize(&mut writer)
.expect("Blocks must serialize.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one can error (unlike the hash-writer case, where we know the writer is infallible) if there's an error in the underlying writer, so maybe this bubble the error with ??

@dconnolly dconnolly mentioned this pull request Mar 5, 2021
53 tasks
skyl added a commit to skyl/zebra that referenced this pull request Sep 25, 2024
Fix bugs identified in test/stage of big refactor
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.

Sketch out Block type and block message type.
2 participants