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

Generalize Node Encoding Scheme #269

Merged
merged 4 commits into from
Sep 25, 2023
Merged

Generalize Node Encoding Scheme #269

merged 4 commits into from
Sep 25, 2023

Conversation

richardpringle
Copy link
Contributor

@richardpringle richardpringle commented Sep 22, 2023

Use bincode to encode Nodes and add encoding/decoding test.

@richardpringle richardpringle marked this pull request as ready for review September 22, 2023 00:10
@richardpringle richardpringle marked this pull request as draft September 22, 2023 00:10
@richardpringle richardpringle marked this pull request as ready for review September 22, 2023 00:11
@richardpringle richardpringle marked this pull request as draft September 22, 2023 00:11
@patrick-ogrady patrick-ogrady changed the title rlwhat Generalize Node Encoding Scheme Sep 22, 2023
} else {
Ok(NodeType::Extension(ExtNode::new(
cur_key,
DiskAddress::null(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xinifinity, why is this DiskAddress::null()?

pub enum Error {
#[error("decoding error")]
Decode(#[from] bincode::Error),
}
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 think I can remove this wrapped error and just use bincode::Error

fn calc_eth_rlp<S: ShaleStore<Node>>(&self, store: &S) -> Vec<u8> {
let mut stream = rlp::RlpStream::new_list(17);
// let mut stream = rlp::RlpStream::new_list(NBRANCH + 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still have to delete the old, commented code

Copy link
Collaborator

Choose a reason for hiding this comment

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

I did this on another PR

// Ok(EXT_NODE_SIZE) => {
// [Encoded<Vec<u8>>; 2]
// 0 is always Encoded::Data
// 1 could be either
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 should remove these comments, they aren't relevant here

Copy link
Collaborator

@rkuris rkuris left a comment

Choose a reason for hiding this comment

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

All comments can be addressed in followups

@@ -78,44 +79,67 @@ impl BranchNode {
}

fn calc_eth_rlp<S: ShaleStore<Node>>(&self, store: &S) -> Vec<u8> {
let mut stream = rlp::RlpStream::new_list(17);
// let mut stream = rlp::RlpStream::new_list(NBRANCH + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove commented code

fn calc_eth_rlp<S: ShaleStore<Node>>(&self, store: &S) -> Vec<u8> {
let mut stream = rlp::RlpStream::new_list(17);
// let mut stream = rlp::RlpStream::new_list(NBRANCH + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I did this on another PR


// consume items returning the item at index

let data: Vec<u8> = items.into_element_at(index).decode()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Not a fan of a trait only used in one place, just inline it or use a macro.

// Ok(_) => Err(ProofError::DecodeError(rlp::DecoderError::RlpInvalidLength)),
// Err(e) => Err(ProofError::DecodeError(e)),
_ => Err(ProofError::DecodeError(Box::new(
bincode::ErrorKind::Custom(String::from("")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

bad => Err(ProofError::DecodeError(Box::new(
                bincode::ErrorKind::Custom(format!("{} invalid", bad)),

@@ -225,7 +249,10 @@ impl<N: AsRef<[u8]> + Send> Proof<N> {
hash: Some(sub_hash),
})
}
_ => Err(ProofError::DecodeError(rlp::DecoderError::RlpInvalidLength)),
// _ => Err(ProofError::DecodeError(rlp::DecoderError::RlpInvalidLength)),
_ => Err(ProofError::DecodeError(Box::new(
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as above; knowing the value might make debugging a little easier

@@ -1077,3 +1132,17 @@ fn unset_node_ref<K: AsRef<[u8]>, S: ShaleStore<Node> + Send + Sync>(
}
}
}

trait IntoElementAt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove this trait; see earlier comment

@@ -1381,4 +1383,87 @@ mod test {
check(node);
}
}
#[test]
fn test_encode() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: test_encode_decode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is your commit! You can PR the change after this lands

@richardpringle richardpringle merged commit 9f6cc49 into main Sep 25, 2023
5 checks passed
@richardpringle richardpringle deleted the rlwhat branch September 25, 2023 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants