Skip to content

Commit 53d699c

Browse files
lklimekxdustinface
andauthored
refactor: bump bincode to 2.0.1 (#356)
* build(deps): bump bincode to 2.0.1 * Update dash-network/Cargo.toml Co-authored-by: Kevin Rombach <[email protected]> * chore(dash-spv): replace bincode 1.3.3 with bincode 2.0.1 --------- Co-authored-by: Kevin Rombach <[email protected]>
1 parent c0da350 commit 53d699c

File tree

19 files changed

+100
-94
lines changed

19 files changed

+100
-94
lines changed

dash-network/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
1515

1616
# Optional dependencies for serialization
1717
serde = { version = "1.0", default-features = false, optional = true, features = ["derive", "alloc"] }
18-
bincode = { version = "=2.0.0-rc.3", optional = true, default-features = false }
19-
bincode_derive = { version= "=2.0.0-rc.3", optional = true }
18+
bincode = { version = "2.0.1", optional = true, default-features = false }
19+
bincode_derive = { version = "2.0.1", optional = true }
2020

2121
[features]
2222
default = ["std"]

dash-spv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ anyhow = "1.0"
3333
# Serialization
3434
serde = { version = "1.0", features = ["derive"] }
3535
serde_json = "1.0"
36-
bincode = "1.3"
36+
bincode = "2.0.1"
3737

3838
# Logging
3939
tracing = "0.1"

dash-spv/src/chain/chainlock_manager.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl ChainLockManager {
334334

335335
// Store persistently
336336
let key = format!("chainlock:{}", chain_lock.block_height);
337-
let data = bincode::serialize(&chain_lock)
337+
let data = bincode::encode_to_vec(&chain_lock, bincode::config::standard())
338338
.map_err(|e| StorageError::Serialization(e.to_string()))?;
339339
storage.store_metadata(&key, &data).await?;
340340

@@ -416,8 +416,9 @@ impl ChainLockManager {
416416
for height in start_height..=end_height {
417417
let key = format!("chainlock:{}", height);
418418
if let Some(data) = storage.load_metadata(&key).await? {
419-
match bincode::deserialize::<ChainLock>(&data) {
420-
Ok(chain_lock) => {
419+
match bincode::decode_from_slice::<ChainLock, _>(&data, bincode::config::standard())
420+
{
421+
Ok((chain_lock, _)) => {
421422
// Cache it
422423
let entry = ChainLockEntry {
423424
chain_lock: chain_lock.clone(),

dash-spv/src/storage/headers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ pub(super) async fn load_block_index(
5858
let index_path = manager.base_path.join("headers/index.dat");
5959

6060
if let Ok(content) = tokio::fs::read(&index_path).await {
61-
bincode::deserialize(&content)
61+
bincode::decode_from_slice(&content, bincode::config::standard())
62+
.map(|(index, _)| index)
6263
.map_err(|e| StorageError::ReadFailed(format!("Failed to deserialize index: {}", e)))
6364
} else {
6465
manager.block_headers.write().await.build_block_index_from_segments().await
@@ -70,7 +71,7 @@ pub(super) async fn save_index_to_disk(
7071
path: &Path,
7172
index: &HashMap<BlockHash, u32>,
7273
) -> StorageResult<()> {
73-
let data = bincode::serialize(index)
74+
let data = bincode::encode_to_vec(index, bincode::config::standard())
7475
.map_err(|e| StorageError::WriteFailed(format!("Failed to serialize index: {}", e)))?;
7576

7677
atomic_write(path, &data).await

dash-spv/src/storage/state.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ impl DiskStorageManager {
123123
chain_lock: &dashcore::ChainLock,
124124
) -> StorageResult<()> {
125125
let path = self.base_path.join("chainlocks").join(format!("chainlock_{:08}.bin", height));
126-
let data = bincode::serialize(chain_lock).map_err(|e| {
127-
crate::error::StorageError::WriteFailed(format!(
128-
"Failed to serialize chain lock: {}",
129-
e
130-
))
131-
})?;
126+
let data =
127+
bincode::encode_to_vec(chain_lock, bincode::config::standard()).map_err(|e| {
128+
crate::error::StorageError::WriteFailed(format!(
129+
"Failed to serialize chain lock: {}",
130+
e
131+
))
132+
})?;
132133

133134
atomic_write(&path, &data).await?;
134135
tracing::debug!("Stored chain lock at height {}", height);
@@ -144,14 +145,15 @@ impl DiskStorageManager {
144145
}
145146

146147
let data = tokio::fs::read(&path).await?;
147-
let chain_lock = bincode::deserialize(&data).map_err(|e| {
148-
crate::error::StorageError::ReadFailed(format!(
149-
"Failed to deserialize chain lock: {}",
150-
e
151-
))
152-
})?;
148+
let chain_lock =
149+
bincode::decode_from_slice(&data, bincode::config::standard()).map_err(|e| {
150+
crate::error::StorageError::ReadFailed(format!(
151+
"Failed to deserialize chain lock: {}",
152+
e
153+
))
154+
})?;
153155

154-
Ok(Some(chain_lock))
156+
Ok(Some(chain_lock.0))
155157
}
156158

157159
/// Get ChainLocks in a height range.
@@ -181,7 +183,9 @@ impl DiskStorageManager {
181183
if height >= start_height && height <= end_height {
182184
let path = entry.path();
183185
let data = tokio::fs::read(&path).await?;
184-
if let Ok(chain_lock) = bincode::deserialize(&data) {
186+
if let Ok((chain_lock, _)) =
187+
bincode::decode_from_slice(&data, bincode::config::standard())
188+
{
185189
chain_locks.push((height, chain_lock));
186190
}
187191
}

dash/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ bitcoinconsensus = { version = "0.20.2-0.5.0", default-features = false, optiona
6161
hex_lit = "0.1.1"
6262
anyhow = { version= "1.0" }
6363
hex = { version= "0.4" }
64-
bincode = { version= "=2.0.0-rc.3", optional = true }
65-
bincode_derive = { version= "=2.0.0-rc.3", optional = true }
64+
bincode = { version = "2.0.1", optional = true }
65+
bincode_derive = { version = "2.0.1", optional = true }
6666
blsful = { git = "https://github.com/dashpay/agora-blsful", rev = "0c34a7a488a0bd1c9a9a2196e793b303ad35c900", optional = true }
6767
ed25519-dalek = { version = "2.1", features = ["rand_core"], optional = true }
6868
blake3 = "1.8.1"
@@ -75,7 +75,7 @@ serde_json = "1.0.140"
7575
serde_test = "1.0.177"
7676
serde_derive = "1.0.219"
7777
secp256k1 = { features = [ "recovery", "rand", "hashes" ], version="0.30.0" }
78-
bincode = { version= "=2.0.0-rc.3" }
78+
bincode = { version = "2.0.1" }
7979
assert_matches = "1.5.0"
8080
dashcore = { path = ".", features = ["core-block-hash-use-x11", "message_verification", "quorum_validation", "signer"] }
8181
criterion = "0.5"

dash/src/address.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ impl bincode::Encode for Address {
863863
}
864864

865865
#[cfg(feature = "bincode")]
866-
impl bincode::Decode for Address {
867-
fn decode<D: bincode::de::Decoder>(
866+
impl<C> bincode::Decode<C> for Address {
867+
fn decode<D: bincode::de::Decoder<Context = C>>(
868868
decoder: &mut D,
869869
) -> Result<Self, bincode::error::DecodeError> {
870870
use core::str::FromStr;
@@ -876,8 +876,8 @@ impl bincode::Decode for Address {
876876
}
877877

878878
#[cfg(feature = "bincode")]
879-
impl<'de> bincode::BorrowDecode<'de> for Address {
880-
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
879+
impl<'de, C> bincode::BorrowDecode<'de, C> for Address {
880+
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
881881
decoder: &mut D,
882882
) -> Result<Self, bincode::error::DecodeError> {
883883
use core::str::FromStr;
@@ -899,8 +899,8 @@ impl bincode::Encode for AddressType {
899899
}
900900

901901
#[cfg(feature = "bincode")]
902-
impl bincode::Decode for AddressType {
903-
fn decode<D: bincode::de::Decoder>(
902+
impl<C> bincode::Decode<C> for AddressType {
903+
fn decode<D: bincode::de::Decoder<Context = C>>(
904904
decoder: &mut D,
905905
) -> Result<Self, bincode::error::DecodeError> {
906906
let val = u8::decode(decoder)?;
@@ -916,8 +916,8 @@ impl bincode::Decode for AddressType {
916916
}
917917

918918
#[cfg(feature = "bincode")]
919-
impl<'de> bincode::BorrowDecode<'de> for AddressType {
920-
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
919+
impl<'de, C> bincode::BorrowDecode<'de, C> for AddressType {
920+
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
921921
decoder: &mut D,
922922
) -> Result<Self, bincode::error::DecodeError> {
923923
let val = u8::borrow_decode(decoder)?;

hashes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ actual-schemars = { package = "schemars", version = "1.0", optional = true }
3535
secp256k1 = { default-features = false, features = ["hashes"], version= "0.30.0" }
3636

3737
rs-x11-hash = { version = "0.1.8", optional = true }
38-
bincode = { version= "=2.0.0-rc.3", optional = true }
38+
bincode = { version = "2.0.1", optional = true }
3939

4040
[dev-dependencies]
4141
serde_test = "1.0"

hashes/src/bincode_macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ macro_rules! bincode_impl {
3232
}
3333
}
3434

35-
impl<$($gen: $gent),*> bincode::Decode for $t<$($gen),*> {
36-
fn decode<D: bincode::de::Decoder>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
35+
impl<C $(, $gen: $gent)*> bincode::Decode<C> for $t<$($gen),*> {
36+
fn decode<D: bincode::de::Decoder<Context = C>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
3737
// Decode a fixed-length byte array and then reconstruct via from_byte_array
3838
let bytes: [u8; $len] = <[u8; $len]>::decode(decoder)?;
3939
Ok(Self::from_byte_array(bytes))
4040
}
4141
}
4242

43-
impl<'de, $($gen: $gent),*> bincode::BorrowDecode<'de> for $t<$($gen),*> {
44-
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
43+
impl<'de, C $(, $gen: $gent)*> bincode::BorrowDecode<'de, C> for $t<$($gen),*> {
44+
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
4545
// Decode a borrowed reference, then use from_bytes_ref (and clone, since our type is Copy)
4646
use std::convert::TryInto;
4747

hashes/src/internal_macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ macro_rules! hash_trait_impls {
148148
}
149149

150150
#[cfg(feature = "bincode")]
151-
impl<$($gen: $gent),*> bincode::Decode for Hash<$($gen),*> {
152-
fn decode<D: bincode::de::Decoder>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
151+
impl<C $(, $gen: $gent)*> bincode::Decode<C> for Hash<$($gen),*> {
152+
fn decode<D: bincode::de::Decoder<Context = C>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
153153
use crate::Hash;
154154
// Decode a fixed-length byte array and then create the Hash
155155
let bytes: [u8; $bits / 8] = <[u8; $bits / 8]>::decode(decoder)?;
@@ -158,8 +158,8 @@ macro_rules! hash_trait_impls {
158158
}
159159

160160
#[cfg(feature = "bincode")]
161-
impl<'de, $($gen: $gent),*> bincode::BorrowDecode<'de> for Hash<$($gen),*> {
162-
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
161+
impl<'de, C $(, $gen: $gent)*> bincode::BorrowDecode<'de, C> for Hash<$($gen),*> {
162+
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
163163
use std::convert::TryInto;
164164
// Decode a borrowed reference to a byte slice
165165
let bytes: &[u8] = bincode::BorrowDecode::borrow_decode(decoder)?;

0 commit comments

Comments
 (0)