Skip to content

Commit

Permalink
Fix rustc 1.77 issues and lints (kaspanet#442)
Browse files Browse the repository at this point in the history
* remove BorshSchema due to rustc 1.77 issues
* fix seal macro hash error due to rustc 1.77
* fix all rustc 1.77 lints
* add MSRV to `Cargo.toml`
* suppress lints instead of making fields public
* propagate `package.rust-version` to all workspace crates
  • Loading branch information
aspect authored Mar 26, 2024
1 parent d7ecfa2 commit 6fd7029
Show file tree
Hide file tree
Showing 87 changed files with 309 additions and 255 deletions.
76 changes: 76 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ members = [
]

[workspace.package]
rust-version = "1.77.0"
version = "0.13.5"
authors = ["Kaspa developers"]
license = "MIT/Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "kaspa-cli"
description = "Kaspa CLI"
keywords = ["kaspa", "wallet", "cli", "rpc"]
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions components/addressmanager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-addressmanager"
description = "Kaspa address manager"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions components/connectionmanager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-connectionmanager"
description = "Kaspa connection manager"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions components/consensusmanager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-consensusmanager"
description = "Kaspa consensus library"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions components/consensusmanager/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ pub use tokio::task::spawn_blocking;

use crate::BlockProcessingBatch;

#[allow(dead_code)]
#[derive(Clone)]
pub struct SessionOwnedReadGuard(Arc<RfRwLockOwnedReadGuard>);

#[allow(dead_code)]
pub struct SessionReadGuard<'a>(RfRwLockReadGuard<'a>);

pub struct SessionWriteGuard<'a>(RfRwLockWriteGuard<'a>);
Expand Down
1 change: 1 addition & 0 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-consensus"
description = "Kaspa consensus library"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions consensus/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-consensus-core"
description = "Kaspa consensus core"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/api/stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema, Default)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BlockCount {
pub header_count: u64,
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{hashing, BlueWorkType};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use js_sys::{Array, Object};
use kaspa_hashes::Hash;
use kaspa_utils::hex::ToHex;
Expand All @@ -8,7 +8,7 @@ use serde_wasm_bindgen::*;
use wasm_bindgen::prelude::*;
use workflow_wasm::prelude::*;

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
#[wasm_bindgen(inspectable)]
pub struct Header {
Expand Down
6 changes: 3 additions & 3 deletions consensus/core/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use kaspa_addresses::Prefix;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::{Debug, Display, Formatter};
Expand All @@ -15,7 +15,7 @@ pub enum NetworkTypeError {
}

u8_try_from! {
#[derive(Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
#[wasm_bindgen]
pub enum NetworkType {
Expand Down Expand Up @@ -157,7 +157,7 @@ pub enum NetworkIdError {
InvalidNetworkId(String),
}

#[derive(Clone, Copy, Debug, BorshSerialize, BorshDeserialize, BorshSchema, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
#[wasm_bindgen(inspectable)]
pub struct NetworkId {
#[wasm_bindgen(js_name = "type")]
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/subnets.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::fmt::{Debug, Display, Formatter};
use std::str::{self, FromStr};

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use kaspa_utils::hex::{FromHex, ToHex};
use kaspa_utils::{serde_impl_deser_fixed_bytes_ref, serde_impl_ser_fixed_bytes_ref};

/// The size of the array used to store subnetwork IDs.
pub const SUBNETWORK_ID_SIZE: usize = 20;

/// The domain representation of a Subnetwork ID
#[derive(Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash, BorshSerialize, BorshDeserialize)]
pub struct SubnetworkId([u8; SUBNETWORK_ID_SIZE]);

impl Debug for SubnetworkId {
Expand Down
10 changes: 5 additions & 5 deletions consensus/core/src/tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod script_public_key;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use kaspa_utils::hex::ToHex;
use kaspa_utils::mem_size::MemSizeEstimator;
use kaspa_utils::{serde_bytes, serde_bytes_fixed_ref};
Expand Down Expand Up @@ -28,7 +28,7 @@ pub type TransactionId = kaspa_hashes::Hash;
/// set such as whether or not it was contained in a coinbase tx, the daa
/// score of the block that accepts the tx, its public key script, and how
/// much it pays.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
#[wasm_bindgen(inspectable, js_name = TxUtxoEntry)]
pub struct UtxoEntry {
Expand All @@ -52,7 +52,7 @@ impl MemSizeEstimator for UtxoEntry {}
pub type TransactionIndexType = u32;

/// Represents a Kaspa transaction outpoint
#[derive(Eq, Hash, PartialEq, Debug, Copy, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Eq, Hash, PartialEq, Debug, Copy, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionOutpoint {
#[serde(with = "serde_bytes_fixed_ref")]
Expand All @@ -73,7 +73,7 @@ impl Display for TransactionOutpoint {
}

/// Represents a Kaspa transaction input
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionInput {
pub previous_outpoint: TransactionOutpoint,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl std::fmt::Debug for TransactionInput {
}

/// Represents a Kaspad transaction output
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionOutput {
pub value: u64,
Expand Down
22 changes: 1 addition & 21 deletions consensus/core/src/tx/script_public_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::borrow::Cow;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use core::fmt::Formatter;
use kaspa_utils::{
hex::{FromHex, ToHex},
Expand Down Expand Up @@ -350,26 +350,6 @@ impl BorshDeserialize for ScriptPublicKey {
}
}

impl BorshSchema for ScriptPublicKey {
fn add_definitions_recursively(
definitions: &mut std::collections::HashMap<borsh::schema::Declaration, borsh::schema::Definition>,
) {
let fields = borsh::schema::Fields::NamedFields(std::vec![
("version".to_string(), <u16>::declaration()),
("script".to_string(), <Vec<u8>>::declaration())
]);
let definition = borsh::schema::Definition::Struct { fields };
Self::add_definition(Self::declaration(), definition, definitions);
<u16>::add_definitions_recursively(definitions);
// `<Vec<u8>>` can be safely used as scheme definition for smallvec. See comments above.
<Vec<u8>>::add_definitions_recursively(definitions);
}

fn declaration() -> borsh::schema::Declaration {
"ScriptPublicKey".to_string()
}
}

impl TryFrom<JsValue> for ScriptPublicKey {
type Error = JsValue;

Expand Down
1 change: 1 addition & 0 deletions consensus/notify/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-consensus-notify"
description = "Kaspa consensus notifier"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions consensus/pow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-pow"
description = "Kaspa proof-of-work"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions consensus/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-consensus-wasm"
description = "Kaspa consensus core WASM bindings"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-core"
description = "Kaspa core"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crypto/addresses/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kaspa-addresses"
description = "Kaspa address"
rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand Down
Loading

0 comments on commit 6fd7029

Please sign in to comment.