-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
5fb92f0
to
03ebe80
Compare
83879fa
to
c0312a3
Compare
} else { | ||
Ok(NodeType::Extension(ExtNode::new( | ||
cur_key, | ||
DiskAddress::null(), |
There was a problem hiding this comment.
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()
?
firewood/src/merkle/node.rs
Outdated
pub enum Error { | ||
#[error("decoding error")] | ||
Decode(#[from] bincode::Error), | ||
} |
There was a problem hiding this comment.
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
firewood/src/merkle/node.rs
Outdated
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
fe8c118
to
4fab38e
Compare
There was a problem hiding this 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
firewood/src/merkle/node.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
firewood/src/merkle/node.rs
Outdated
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); |
There was a problem hiding this comment.
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
firewood/src/proof.rs
Outdated
|
||
// consume items returning the item at index | ||
|
||
let data: Vec<u8> = items.into_element_at(index).decode()?; |
There was a problem hiding this comment.
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.
firewood/src/proof.rs
Outdated
// Ok(_) => Err(ProofError::DecodeError(rlp::DecoderError::RlpInvalidLength)), | ||
// Err(e) => Err(ProofError::DecodeError(e)), | ||
_ => Err(ProofError::DecodeError(Box::new( | ||
bincode::ErrorKind::Custom(String::from("")), |
There was a problem hiding this comment.
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)),
firewood/src/proof.rs
Outdated
@@ -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( |
There was a problem hiding this comment.
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
firewood/src/proof.rs
Outdated
@@ -1077,3 +1132,17 @@ fn unset_node_ref<K: AsRef<[u8]>, S: ShaleStore<Node> + Send + Sync>( | |||
} | |||
} | |||
} | |||
|
|||
trait IntoElementAt { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: test_encode_decode?
There was a problem hiding this comment.
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
359554f
to
810623b
Compare
810623b
to
c49c09b
Compare
c49c09b
to
7eef09e
Compare
Use bincode to encode Nodes and add encoding/decoding test.