Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stacks-network/stacks-core
Browse files Browse the repository at this point in the history
… into fix/clippy-ci-stacks-lib-int-plus-one
jferrant committed Jan 2, 2025
2 parents a94ee8d + 0e9e09f commit 5be43bf
Showing 87 changed files with 453 additions and 474 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
@@ -89,7 +89,8 @@ jobs:
- tests::nakamoto_integrations::miner_writes_proposed_block_to_stackerdb
- tests::nakamoto_integrations::correct_burn_outs
- tests::nakamoto_integrations::vote_for_aggregate_key_burn_op
- tests::nakamoto_integrations::follower_bootup
- tests::nakamoto_integrations::follower_bootup_simple
- tests::nakamoto_integrations::follower_bootup_custom_chain_id
- tests::nakamoto_integrations::forked_tenure_is_ignored
- tests::nakamoto_integrations::nakamoto_attempt_time
- tests::nakamoto_integrations::skip_mining_long_tx
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -37,4 +37,4 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner --no-deps --tests --all-features -- -D warnings
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings
2 changes: 1 addition & 1 deletion libsigner/src/v0/messages.rs
Original file line number Diff line number Diff line change
@@ -1237,7 +1237,7 @@ mod test {
txs: vec![],
};
let tx_merkle_root = {
let txid_vecs = block
let txid_vecs: Vec<_> = block
.txs
.iter()
.map(|tx| tx.txid().as_bytes().to_vec())
3 changes: 1 addition & 2 deletions stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ path = "./src/libcommon.rs"

[dependencies]
rand = { workspace = true }
serde = "1"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1"
serde_stacker = "0.1"
sha3 = "0.10.1"
@@ -77,7 +77,6 @@ testing = ["canonical"]
serde = []
bech32_std = []
bech32_strict = []
strason = []

[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
sha2 = { version = "0.10", features = ["asm"] }
8 changes: 6 additions & 2 deletions stacks-common/src/bitvec.rs
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ pub struct BitVecIter<'a, const MAX_SIZE: u16> {
bitvec: &'a BitVec<MAX_SIZE>,
}

impl<'a, const MAX_SIZE: u16> Iterator for BitVecIter<'a, MAX_SIZE> {
impl<const MAX_SIZE: u16> Iterator for BitVecIter<'_, MAX_SIZE> {
type Item = bool;

fn next(&mut self) -> Option<Self::Item> {
@@ -172,7 +172,7 @@ impl<const MAX_SIZE: u16> BitVec<MAX_SIZE> {
}

pub fn iter(&self) -> BitVecIter<MAX_SIZE> {
let byte = self.data.get(0);
let byte = self.data.first();
BitVecIter {
index: 0,
bitvec: self,
@@ -184,6 +184,10 @@ impl<const MAX_SIZE: u16> BitVec<MAX_SIZE> {
self.len
}

pub fn is_empty(&self) -> bool {
self.len == 0
}

/// Return the number of bytes needed to store `len` bits.
fn data_len(len: u16) -> u16 {
len / 8 + if len % 8 == 0 { 0 } else { 1 }
4 changes: 2 additions & 2 deletions stacks-common/src/deps_common/bech32/mod.rs
Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@ impl<'a> Bech32Writer<'a> {
}
}

impl<'a> WriteBase32 for Bech32Writer<'a> {
impl WriteBase32 for Bech32Writer<'_> {
type Err = fmt::Error;

/// Writes a single 5 bit value of the data part
@@ -211,7 +211,7 @@ impl<'a> WriteBase32 for Bech32Writer<'a> {
}
}

impl<'a> Drop for Bech32Writer<'a> {
impl Drop for Bech32Writer<'_> {
fn drop(&mut self) {
self.write_checksum()
.expect("Unhandled error writing the checksum on drop.")
2 changes: 1 addition & 1 deletion stacks-common/src/deps_common/bitcoin/blockdata/opcodes.rs
Original file line number Diff line number Diff line change
@@ -606,7 +606,7 @@ impl All {
Class::PushBytes(*self as u32)
// 60 opcodes
} else {
Class::Ordinary(unsafe { transmute(*self) })
Class::Ordinary(unsafe { transmute::<All, Ordinary>(*self) })
}
}
}
17 changes: 10 additions & 7 deletions stacks-common/src/deps_common/bitcoin/blockdata/script.rs
Original file line number Diff line number Diff line change
@@ -648,7 +648,7 @@ impl<'de> serde::Deserialize<'de> for Script {
where
E: serde::de::Error,
{
let v: Vec<u8> = ::hex::decode(v).map_err(E::custom)?;
let v: Vec<u8> = crate::util::hash::hex_bytes(v).map_err(E::custom)?;
Ok(Script::from(v))
}

@@ -834,15 +834,18 @@ mod test {
}

#[test]
#[cfg(all(feature = "serde", feature = "strason"))]
#[cfg(feature = "serde")]
fn script_json_serialize() {
use strason::Json;
use serde_json;

let original = hex_script!("827651a0698faaa9a8a7a687");
let json = Json::from_serialize(&original).unwrap();
assert_eq!(json.to_bytes(), b"\"827651a0698faaa9a8a7a687\"");
assert_eq!(json.string(), Some("827651a0698faaa9a8a7a687"));
let des = json.into_deserialize().unwrap();
let json_value = serde_json::to_value(&original).unwrap();
assert_eq!(
serde_json::to_vec(&json_value).unwrap(),
b"\"827651a0698faaa9a8a7a687\""
);
assert_eq!(json_value.to_string(), "\"827651a0698faaa9a8a7a687\"");
let des = serde_json::from_value(json_value).unwrap();
assert_eq!(original, des);
}

Original file line number Diff line number Diff line change
@@ -342,7 +342,7 @@ impl Transaction {
let mut script_len_bytes =
serialize(&script_len).expect("FATAL: failed to encode varint");
length_script.append(&mut script_len_bytes);
length_script.extend_from_slice(&script_bytes);
length_script.extend_from_slice(script_bytes);
length_script
}
}
@@ -361,7 +361,7 @@ impl Transaction {
let mut script_len_bytes =
serialize(&script_len).expect("FATAL: failed to encode varint");
raw_vec.append(&mut script_len_bytes);
raw_vec.extend_from_slice(&script_bytes);
raw_vec.extend_from_slice(script_bytes);
}
Sha256dHash::from_data(&raw_vec)
} else if sighash_type == SigHashType::Single && input_index < self.output.len() {
40 changes: 20 additions & 20 deletions stacks-common/src/deps_common/bitcoin/internal_macros.rs
Original file line number Diff line number Diff line change
@@ -106,16 +106,16 @@ macro_rules! user_enum {
}

#[cfg(feature = "serde")]
impl<'de> $crate::serde::Deserialize<'de> for $name {
impl<'de> serde::Deserialize<'de> for $name {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: $crate::serde::Deserializer<'de>,
D: serde::Deserializer<'de>,
{
use $crate::std::fmt::{self, Formatter};
use std::fmt::{self, Formatter};

struct Visitor;
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = $name;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
@@ -124,7 +124,7 @@ macro_rules! user_enum {

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
E: serde::de::Error,
{
static FIELDS: &'static [&'static str] = &[$(stringify!($txt)),*];

@@ -136,14 +136,14 @@ macro_rules! user_enum {

fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
E: serde::de::Error,
{
self.visit_str(v)
}

fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
E: serde::de::Error,
{
self.visit_str(&v)
}
@@ -222,19 +222,19 @@ macro_rules! hex_script (($s:expr) => (crate::deps_common::bitcoin::blockdata::s
macro_rules! serde_struct_impl {
($name:ident, $($fe:ident),*) => (
#[cfg(feature = "serde")]
impl<'de> $crate::serde::Deserialize<'de> for $name {
impl<'de> serde::Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> Result<$name, D::Error>
where
D: $crate::serde::de::Deserializer<'de>,
D: serde::de::Deserializer<'de>,
{
use $crate::std::fmt::{self, Formatter};
use $crate::serde::de::IgnoredAny;
use std::fmt::{self, Formatter};
use serde::de::IgnoredAny;

#[allow(non_camel_case_types)]
enum Enum { Unknown__Field, $($fe),* }

struct EnumVisitor;
impl<'de> $crate::serde::de::Visitor<'de> for EnumVisitor {
impl<'de> serde::de::Visitor<'de> for EnumVisitor {
type Value = Enum;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
@@ -243,7 +243,7 @@ macro_rules! serde_struct_impl {

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
E: serde::de::Error,
{
match v {
$(
@@ -254,7 +254,7 @@ macro_rules! serde_struct_impl {
}
}

impl<'de> $crate::serde::Deserialize<'de> for Enum {
impl<'de> serde::Deserialize<'de> for Enum {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::de::Deserializer<'de>,
@@ -265,7 +265,7 @@ macro_rules! serde_struct_impl {

struct Visitor;

impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = $name;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
@@ -274,9 +274,9 @@ macro_rules! serde_struct_impl {

fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: $crate::serde::de::MapAccess<'de>,
A: serde::de::MapAccess<'de>,
{
use $crate::serde::de::Error;
use serde::de::Error;

$(let mut $fe = None;)*

@@ -317,12 +317,12 @@ macro_rules! serde_struct_impl {
}

#[cfg(feature = "serde")]
impl<'de> $crate::serde::Serialize for $name {
impl<'de> serde::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: $crate::serde::Serializer,
S: serde::Serializer,
{
use $crate::serde::ser::SerializeStruct;
use serde::ser::SerializeStruct;

// Only used to get the struct length.
static FIELDS: &'static [&'static str] = &[$(stringify!($fe)),*];
1 change: 0 additions & 1 deletion stacks-common/src/deps_common/bitcoin/mod.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
// Clippy flags
#![allow(clippy::needless_range_loop)] // suggests making a big mess of array newtypes
#![allow(clippy::extend_from_slice)] // `extend_from_slice` only available since 1.6

// Coding conventions
#![deny(non_upper_case_globals)]
2 changes: 1 addition & 1 deletion stacks-common/src/deps_common/bitcoin/network/encodable.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
//!
use std::hash::Hash;
use std::{mem, u32};
use std::mem;

use hashbrown::HashMap;

Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ use crate::deps_common::bitcoin::network::address::Address;
use crate::deps_common::bitcoin::network::constants;
use crate::util;

/// Some simple messages
// Some simple messages

/// The `version` message
#[derive(PartialEq, Eq, Clone, Debug)]
8 changes: 4 additions & 4 deletions stacks-common/src/deps_common/bitcoin/network/serialize.rs
Original file line number Diff line number Diff line change
@@ -157,19 +157,19 @@ impl BitcoinHash for Vec<u8> {
}

/// Encode an object into a vector
pub fn serialize<T: ?Sized>(data: &T) -> Result<Vec<u8>, Error>
pub fn serialize<T>(data: &T) -> Result<Vec<u8>, Error>
where
T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>>,
T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>> + ?Sized,
{
let mut encoder = RawEncoder::new(Cursor::new(vec![]));
data.consensus_encode(&mut encoder)?;
Ok(encoder.into_inner().into_inner())
}

/// Encode an object into a hex-encoded string
pub fn serialize_hex<T: ?Sized>(data: &T) -> Result<String, Error>
pub fn serialize_hex<T>(data: &T) -> Result<String, Error>
where
T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>>,
T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>> + ?Sized,
{
let serial = serialize(data)?;
Ok(hex_encode(&serial[..]))
2 changes: 1 addition & 1 deletion stacks-common/src/deps_common/bitcoin/util/hash.rs
Original file line number Diff line number Diff line change
@@ -450,7 +450,7 @@ pub fn bitcoin_merkle_root(data: Vec<Sha256dHash>) -> Sha256dHash {
bitcoin_merkle_root(next)
}

impl<'a, T: BitcoinHash> MerkleRoot for &'a [T] {
impl<T: BitcoinHash> MerkleRoot for &[T] {
fn merkle_root(&self) -> Sha256dHash {
bitcoin_merkle_root(self.iter().map(|obj| obj.bitcoin_hash()).collect())
}
2 changes: 1 addition & 1 deletion stacks-common/src/deps_common/ctrlc/mod.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

#[macro_use]
#![macro_use]

mod error;
mod platform;
5 changes: 3 additions & 2 deletions stacks-common/src/deps_common/httparse/mod.rs
Original file line number Diff line number Diff line change
@@ -169,14 +169,14 @@ impl<'a> Bytes<'a> {
}
}

impl<'a> AsRef<[u8]> for Bytes<'a> {
impl AsRef<[u8]> for Bytes<'_> {
#[inline]
fn as_ref(&self) -> &[u8] {
&self.slice_peek()[self.pos..]
}
}

impl<'a> Iterator for Bytes<'a> {
impl Iterator for Bytes<'_> {
type Item = u8;

#[inline]
@@ -701,6 +701,7 @@ pub fn parse_headers<'b: 'h, 'h>(
}

#[inline]
#[allow(clippy::never_loop)]
fn parse_headers_iter<'a>(headers: &mut &mut [Header<'a>], bytes: &mut Bytes<'a>) -> Result<usize> {
let mut num_headers: usize = 0;
let mut count: usize = 0;
Loading

0 comments on commit 5be43bf

Please sign in to comment.