-
Notifications
You must be signed in to change notification settings - Fork 141
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
remove binary sv2 serde #1459
base: main
Are you sure you want to change the base?
remove binary sv2 serde #1459
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1459 +/- ##
==========================================
- Coverage 19.34% 17.93% -1.42%
==========================================
Files 144 127 -17
Lines 10963 9539 -1424
==========================================
- Hits 2121 1711 -410
+ Misses 8842 7828 -1014
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
94bf09f
to
934abff
Compare
934abff
to
e175bd3
Compare
e175bd3
to
93bef4a
Compare
rebasing due to #1455 (comment) |
there's no point in having two directories named binary_sv2 anymore
9419e27
to
9511a53
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.
there's still things to be done here
@Shourya742 please finish 67e8e51, there's some details on the commit message
also, the code is still full of references to serde
(comments, README)
as discussed in a call with @Shourya742 , we are going to proceed the following way:
|
da5edc2
to
390561e
Compare
no point in keeping this anymore remove core from docs.yaml
…ich dont require it
390561e
to
b0aee13
Compare
/// This structure uses a generic type `T` and a lifetime parameter `'a` | ||
/// to ensure compatibility with `serde-sv2`. | ||
/// This structure uses a generic type `T` and a lifetime parameter `'a`. |
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.
given that the original motivation for the lifetime parameter was serde-sv2
compatibility, shouldn't we also do something about that?
it seems now there's no real motivation for this anymore, and simply removing the comment will make it hard for us to understand in the future
@@ -163,8 +156,7 @@ impl<'a, T: GetSize> GetSize for Seq0255<'a, T> { | |||
} | |||
|
|||
/// [`Seq064K`] represents a sequence with a maximum length of 65535 elements. | |||
/// This structure uses a generic type `T` and a lifetime parameter `'a` | |||
/// to ensure compatibility with `serde-sv2`. | |||
/// This structure uses a generic type `T` and a lifetime parameter `'a`. |
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.
given that the original motivation for the lifetime parameter was serde-sv2
compatibility, shouldn't we also do something about that?
it seems now there's no real motivation for this anymore, and simply removing the comment will make it hard for us to understand in the future
@@ -455,12 +447,12 @@ impl<'a, const ISFIXED: bool, const SIZE: usize, const HEADERSIZE: usize, const | |||
} | |||
} | |||
|
|||
/// The liftime is here only for type compatibility with serde-sv2 | |||
/// The lifetime 'a is defined. |
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.
given that the original motivation for the lifetime parameter was serde-sv2
compatibility, shouldn't we also do something about that?
it seems now there's no real motivation for this anymore, and simply removing the comment will make it hard for us to understand in the future
|
||
let coinbase_tx_suffix_vec = decode_hex(&block.coinbase_tx_suffix) | ||
.expect("Could not decode hex `String` to `Vec<u8>`"); | ||
let coinbase_tx_suffix: B064K = coinbase_tx_suffix_vec | ||
.try_into() | ||
.expect("Could not convert `Vec<u8>` to `B064K`"); | ||
|
||
TestBlock { | ||
block_hash, | ||
version: block.version, | ||
prev_hash, | ||
time: block.time, | ||
merkle_root, | ||
nbits: block.nbits, | ||
nonce: block.nonce, | ||
coinbase_tx_prefix, | ||
coinbase_script, | ||
coinbase_tx_suffix, | ||
path, | ||
} | ||
} | ||
#[test] | ||
#[cfg(feature = "serde")] | ||
fn gets_merkle_root_from_path() { | ||
let block = get_test_block(); | ||
let expect: Vec<u8> = block.merkle_root; | ||
|
||
let actual = merkle_root_from_path( | ||
block.coinbase_tx_prefix.inner_as_ref(), | ||
&block.coinbase_script, | ||
block.coinbase_tx_suffix.inner_as_ref(), | ||
&block.path.inner_as_ref(), | ||
); | ||
assert_eq!(expect, actual); | ||
} | ||
|
||
#[test] | ||
#[cfg(feature = "serde")] | ||
fn gets_new_header() -> Result<(), Error> { | ||
let block = get_test_block(); | ||
|
||
if !block.prev_hash.len() == 32 { | ||
return Err(Error::ExpectedLen32(block.prev_hash.len())); | ||
} | ||
if !block.merkle_root.len() == 32 { | ||
return Err(Error::ExpectedLen32(block.merkle_root.len())); | ||
} | ||
let mut prev_hash_arr = [0u8; 32]; | ||
prev_hash_arr.copy_from_slice(&block.prev_hash); | ||
let prev_hash = DHash::from_inner(prev_hash_arr); | ||
|
||
let mut merkle_root_arr = [0u8; 32]; | ||
merkle_root_arr.copy_from_slice(&block.merkle_root); | ||
let merkle_root = DHash::from_inner(merkle_root_arr); | ||
|
||
let expect = BlockHeader { | ||
version: block.version as i32, | ||
prev_blockhash: BlockHash::from_hash(prev_hash), | ||
merkle_root: TxMerkleNode::from_hash(merkle_root), | ||
time: block.time, | ||
bits: block.nbits, | ||
nonce: block.nonce, | ||
}; | ||
|
||
let actual_block = get_test_block(); | ||
let actual = new_header( | ||
block.version as i32, | ||
&actual_block.prev_hash, | ||
&actual_block.merkle_root, | ||
block.time, | ||
block.nbits, | ||
block.nonce, | ||
)?; | ||
assert_eq!(actual, expect); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(feature = "serde")] | ||
fn gets_new_header_hash() { | ||
let block = get_test_block(); | ||
let expect = block.block_hash; | ||
let block = get_test_block(); | ||
let prev_hash: [u8; 32] = block.prev_hash.to_vec().try_into().unwrap(); | ||
let prev_hash = DHash::from_inner(prev_hash); | ||
let merkle_root: [u8; 32] = block.merkle_root.to_vec().try_into().unwrap(); | ||
let merkle_root = DHash::from_inner(merkle_root); | ||
let header = BlockHeader { | ||
version: block.version as i32, | ||
prev_blockhash: BlockHash::from_hash(prev_hash), | ||
merkle_root: TxMerkleNode::from_hash(merkle_root), | ||
time: block.time, | ||
bits: block.nbits, | ||
nonce: block.nonce, | ||
}; | ||
|
||
let actual = new_header_hash(header); | ||
|
||
assert_eq!(actual, expect); | ||
} |
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.
these tests are asserting functionality from roles_logic_sv2
I would assume that they were written with serde
just for convenience
but I don't think it's wise to throw them away just because we are dropping serde
support
the best thing to do would be to adapt them to work without serde
part of: #1387