Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dash-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

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

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion dash-spv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ anyhow = "1.0"
# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
bincode = "1.3"
bincode = "2.0.1"

# Logging
tracing = "0.1"
Expand Down
7 changes: 4 additions & 3 deletions dash-spv/src/chain/chainlock_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl ChainLockManager {

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

Expand Down Expand Up @@ -416,8 +416,9 @@ impl ChainLockManager {
for height in start_height..=end_height {
let key = format!("chainlock:{}", height);
if let Some(data) = storage.load_metadata(&key).await? {
match bincode::deserialize::<ChainLock>(&data) {
Ok(chain_lock) => {
match bincode::decode_from_slice::<ChainLock, _>(&data, bincode::config::standard())
{
Ok((chain_lock, _)) => {
// Cache it
let entry = ChainLockEntry {
chain_lock: chain_lock.clone(),
Expand Down
5 changes: 3 additions & 2 deletions dash-spv/src/storage/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub(super) async fn load_block_index(
let index_path = manager.base_path.join("headers/index.dat");

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

atomic_write(path, &data).await
Expand Down
32 changes: 18 additions & 14 deletions dash-spv/src/storage/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ impl DiskStorageManager {
chain_lock: &dashcore::ChainLock,
) -> StorageResult<()> {
let path = self.base_path.join("chainlocks").join(format!("chainlock_{:08}.bin", height));
let data = bincode::serialize(chain_lock).map_err(|e| {
crate::error::StorageError::WriteFailed(format!(
"Failed to serialize chain lock: {}",
e
))
})?;
let data =
bincode::encode_to_vec(chain_lock, bincode::config::standard()).map_err(|e| {
crate::error::StorageError::WriteFailed(format!(
"Failed to serialize chain lock: {}",
e
))
})?;

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

let data = tokio::fs::read(&path).await?;
let chain_lock = bincode::deserialize(&data).map_err(|e| {
crate::error::StorageError::ReadFailed(format!(
"Failed to deserialize chain lock: {}",
e
))
})?;
let chain_lock =
bincode::decode_from_slice(&data, bincode::config::standard()).map_err(|e| {
crate::error::StorageError::ReadFailed(format!(
"Failed to deserialize chain lock: {}",
e
))
})?;

Ok(Some(chain_lock))
Ok(Some(chain_lock.0))
}

/// Get ChainLocks in a height range.
Expand Down Expand Up @@ -181,7 +183,9 @@ impl DiskStorageManager {
if height >= start_height && height <= end_height {
let path = entry.path();
let data = tokio::fs::read(&path).await?;
if let Ok(chain_lock) = bincode::deserialize(&data) {
if let Ok((chain_lock, _)) =
bincode::decode_from_slice(&data, bincode::config::standard())
{
chain_locks.push((height, chain_lock));
}
}
Expand Down
6 changes: 3 additions & 3 deletions dash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ bitcoinconsensus = { version = "0.20.2-0.5.0", default-features = false, optiona
hex_lit = "0.1.1"
anyhow = { version= "1.0" }
hex = { version= "0.4" }
bincode = { version= "=2.0.0-rc.3", optional = true }
bincode_derive = { version= "=2.0.0-rc.3", optional = true }
bincode = { version = "2.0.1", optional = true }
bincode_derive = { version = "2.0.1", optional = true }
blsful = { git = "https://github.com/dashpay/agora-blsful", rev = "0c34a7a488a0bd1c9a9a2196e793b303ad35c900", optional = true }
ed25519-dalek = { version = "2.1", features = ["rand_core"], optional = true }
blake3 = "1.8.1"
Expand All @@ -75,7 +75,7 @@ serde_json = "1.0.140"
serde_test = "1.0.177"
serde_derive = "1.0.219"
secp256k1 = { features = [ "recovery", "rand", "hashes" ], version="0.30.0" }
bincode = { version= "=2.0.0-rc.3" }
bincode = { version = "2.0.1" }
assert_matches = "1.5.0"
dashcore = { path = ".", features = ["core-block-hash-use-x11", "message_verification", "quorum_validation", "signer"] }
criterion = "0.5"
Expand Down
16 changes: 8 additions & 8 deletions dash/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ impl bincode::Encode for Address {
}

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

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

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

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for AddressType {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for AddressType {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let val = u8::borrow_decode(decoder)?;
Expand Down
2 changes: 1 addition & 1 deletion hashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ actual-schemars = { package = "schemars", version = "1.0", optional = true }
secp256k1 = { default-features = false, features = ["hashes"], version= "0.30.0" }

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

[dev-dependencies]
serde_test = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions hashes/src/bincode_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ macro_rules! bincode_impl {
}
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions hashes/src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ macro_rules! hash_trait_impls {
}

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

#[cfg(feature = "bincode")]
impl<'de, $($gen: $gent),*> bincode::BorrowDecode<'de> for Hash<$($gen),*> {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
impl<'de, C $(, $gen: $gent)*> bincode::BorrowDecode<'de, C> for Hash<$($gen),*> {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(decoder: &mut D) -> Result<Self, bincode::error::DecodeError> {
use std::convert::TryInto;
// Decode a borrowed reference to a byte slice
let bytes: &[u8] = bincode::BorrowDecode::borrow_decode(decoder)?;
Expand Down
2 changes: 1 addition & 1 deletion key-wallet-ffi/IMPORT_WALLET_FFI.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cargo build --features bincode

## Serialization Format

The wallet bytes must be in bincode format (version 2.0.0-rc.3). The serialization includes:
The wallet bytes must be in bincode format (version 2.0). The serialization includes:
- Wallet seed and key material
- Account information
- Address pools and indices
Expand Down
4 changes: 2 additions & 2 deletions key-wallet-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default = ["std", "bincode"]
std = ["key-wallet/std", "dashcore/std", "dashcore_hashes/std", "secp256k1/std"]
serde = ["dep:serde", "key-wallet/serde", "dashcore/serde"]
getrandom = ["key-wallet/getrandom"]
bincode = ["dep:bincode","key-wallet/bincode"]
bincode = ["dep:bincode", "key-wallet/bincode"]

[dependencies]
key-wallet = { path = "../key-wallet", default-features = false }
Expand All @@ -22,7 +22,7 @@ dashcore_hashes = { path = "../hashes", default-features = false }
secp256k1 = { version = "0.30.0", default-features = false, features = ["recovery"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
async-trait = "0.1"
bincode = { version = "=2.0.0-rc.3", optional = true }
bincode = { version = "2.0.1", optional = true }
zeroize = { version = "1.8", features = ["derive"] }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions key-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ sha2 = { version = "0.10", default-features = false }
bs58 = { version = "0.5", default-features = false, features = ["check", "alloc"], optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
# Serialization
bincode = { version = "=2.0.0-rc.3", optional = true }
bincode_derive = { version = "=2.0.0-rc.3", optional = true }
bincode = { version = "2.0.1", optional = true }
bincode_derive = { version = "2.0.1", optional = true }
base64 = { version = "0.22", optional = true }
serde_json = { version = "1.0", optional = true }
hex = { version = "0.4"}
Expand Down
24 changes: 12 additions & 12 deletions key-wallet/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ impl bincode::Encode for ExtendedPrivKey {
}

#[cfg(feature = "bincode")]
impl bincode::Decode for ExtendedPrivKey {
fn decode<D: bincode::de::Decoder>(
impl<C> bincode::Decode<C> for ExtendedPrivKey {
fn decode<D: bincode::de::Decoder<Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::decode(decoder)?;
Expand All @@ -402,8 +402,8 @@ impl bincode::Decode for ExtendedPrivKey {
}

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for ExtendedPrivKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for ExtendedPrivKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::borrow_decode(decoder)?;
Expand Down Expand Up @@ -498,8 +498,8 @@ impl bincode::Encode for ExtendedPubKey {
}

#[cfg(feature = "bincode")]
impl bincode::Decode for ExtendedPubKey {
fn decode<D: bincode::de::Decoder>(
impl<C> bincode::Decode<C> for ExtendedPubKey {
fn decode<D: bincode::de::Decoder<Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::decode(decoder)?;
Expand All @@ -525,8 +525,8 @@ impl bincode::Decode for ExtendedPubKey {
}

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for ExtendedPubKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for ExtendedPubKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::borrow_decode(decoder)?;
Expand Down Expand Up @@ -956,17 +956,17 @@ impl bincode::Encode for DerivationPath {
}

#[cfg(feature = "bincode")]
impl bincode::Decode for DerivationPath {
fn decode<D: bincode::de::Decoder>(
impl<C> bincode::Decode<C> for DerivationPath {
fn decode<D: bincode::de::Decoder<Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
Ok(DerivationPath(Vec::<ChildNumber>::decode(decoder)?))
}
}

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for DerivationPath {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for DerivationPath {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
Ok(DerivationPath(Vec::<ChildNumber>::borrow_decode(decoder)?))
Expand Down
20 changes: 10 additions & 10 deletions key-wallet/src/derivation_bls_bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ impl bincode::Encode for ExtendedBLSPrivKey {
}

#[cfg(feature = "bincode")]
impl bincode::Decode for ExtendedBLSPrivKey {
fn decode<D: bincode::de::Decoder>(
impl<C> bincode::Decode<C> for ExtendedBLSPrivKey {
fn decode<D: bincode::de::Decoder<Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::decode(decoder)?;
Expand All @@ -556,11 +556,11 @@ impl bincode::Decode for ExtendedBLSPrivKey {
}

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for ExtendedBLSPrivKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for ExtendedBLSPrivKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
<Self as bincode::Decode>::decode(decoder)
<Self as bincode::Decode<C>>::decode(decoder)
}
}

Expand All @@ -584,8 +584,8 @@ impl bincode::Encode for ExtendedBLSPubKey {
}

#[cfg(feature = "bincode")]
impl bincode::Decode for ExtendedBLSPubKey {
fn decode<D: bincode::de::Decoder>(
impl<C> bincode::Decode<C> for ExtendedBLSPubKey {
fn decode<D: bincode::de::Decoder<Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
let network = Network::decode(decoder)?;
Expand Down Expand Up @@ -614,11 +614,11 @@ impl bincode::Decode for ExtendedBLSPubKey {
}

#[cfg(feature = "bincode")]
impl<'de> bincode::BorrowDecode<'de> for ExtendedBLSPubKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
impl<'de, C> bincode::BorrowDecode<'de, C> for ExtendedBLSPubKey {
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, bincode::error::DecodeError> {
<Self as bincode::Decode>::decode(decoder)
<Self as bincode::Decode<C>>::decode(decoder)
}
}

Expand Down
Loading