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

remove binary sv2 serde #1459

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Shourya742
Copy link
Contributor

part of: #1387

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 17.93%. Comparing base (f7b068a) to head (b0aee13).
Report is 1 commits behind head on main.

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     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <ø> (ø)
binary_serde_sv2-coverage ?
binary_sv2-coverage 6.95% <ø> (+1.59%) ⬆️
bip32_derivation-coverage 0.00% <ø> (ø)
buffer_sv2-coverage 25.02% <ø> (ø)
codec_sv2-coverage 0.02% <ø> (+<0.01%) ⬆️
common_messages_sv2-coverage 0.17% <ø> (+0.03%) ⬆️
const_sv2-coverage 0.00% <ø> (ø)
error_handling-coverage 0.00% <ø> (ø)
framing_sv2-coverage 0.37% <ø> (+0.08%) ⬆️
jd_client-coverage 0.42% <ø> (ø)
jd_server-coverage 9.02% <ø> (ø)
job_declaration_sv2-coverage 0.00% <ø> (ø)
key-utils-coverage 2.39% <ø> (ø)
mining-coverage 3.15% <ø> (+0.71%) ⬆️
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.82% <ø> (ø)
noise_sv2-coverage 5.78% <ø> (+1.32%) ⬆️
protocols 23.70% <ø> (-1.11%) ⬇️
roles 6.43% <ø> (ø)
roles_logic_sv2-coverage 11.39% <ø> (+2.30%) ⬆️
sv2_ffi-coverage 0.00% <ø> (ø)
template_distribution_sv2-coverage 0.00% <ø> (ø)
translator_sv2-coverage 9.53% <ø> (ø)
utils 25.13% <ø> (ø)
v1-coverage 3.11% <ø> (+0.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shourya742 Shourya742 force-pushed the 2025-02-06-remove-binary_sv2_serde branch 2 times, most recently from 94bf09f to 934abff Compare February 6, 2025 07:19
@Shourya742 Shourya742 force-pushed the 2025-02-06-remove-binary_sv2_serde branch from 934abff to e175bd3 Compare February 7, 2025 05:12
@plebhash plebhash force-pushed the 2025-02-06-remove-binary_sv2_serde branch from e175bd3 to 93bef4a Compare February 7, 2025 12:19
@plebhash
Copy link
Collaborator

plebhash commented Feb 7, 2025

rebasing due to #1455 (comment)

there's no point in having two directories named binary_sv2 anymore
@plebhash plebhash force-pushed the 2025-02-06-remove-binary_sv2_serde branch from 9419e27 to 9511a53 Compare February 7, 2025 13:16
Copy link
Collaborator

@plebhash plebhash left a 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)

@plebhash
Copy link
Collaborator

plebhash commented Feb 7, 2025

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:

  • take the work of deprecating binary_codec_sv2 crate into a follow-up PR, effectively dropping 67e8e51 from this PR
  • finish cleaning up all references to serde (in Rust Docs, README, etc) on this PR

@Shourya742 Shourya742 force-pushed the 2025-02-06-remove-binary_sv2_serde branch 2 times, most recently from da5edc2 to 390561e Compare February 8, 2025 04:55
plebhash and others added 2 commits February 8, 2025 10:43
no point in keeping this anymore

remove core from docs.yaml
@Shourya742 Shourya742 force-pushed the 2025-02-06-remove-binary_sv2_serde branch from 390561e to b0aee13 Compare February 8, 2025 05:13
@Shourya742 Shourya742 mentioned this pull request Feb 8, 2025
Comment on lines -121 to +115
/// 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`.
Copy link
Collaborator

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`.
Copy link
Collaborator

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.
Copy link
Collaborator

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

Comment on lines -1078 to -1268

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);
}
Copy link
Collaborator

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

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.

2 participants