Skip to content

Commit

Permalink
rust 1.78 compatibility (kaspanet#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect authored and D-Stacks committed Jul 10, 2024
1 parent 3ffcf65 commit 40734e7
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,4 @@ overflow-checks = true
inherits = "release"
debug = true
strip = false

3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ features = [

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio.workspace = true

[lints.clippy]
empty_docs = "allow"
1 change: 1 addition & 0 deletions components/addressmanager/src/stores/address_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub trait AddressesStoreReader {

pub trait AddressesStore: AddressesStoreReader {
fn set(&mut self, key: AddressKey, entry: Entry) -> StoreResult<()>;
#[allow(dead_code)]
fn set_failed_count(&mut self, key: AddressKey, connection_failed_count: u64) -> StoreResult<()>;
fn remove(&mut self, key: AddressKey) -> StoreResult<()>;
}
Expand Down
3 changes: 3 additions & 0 deletions consensus/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ harness = false

[features]
devnet-prealloc = []

[lints.clippy]
empty_docs = "allow"
2 changes: 1 addition & 1 deletion consensus/core/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn sign_with_multiple_v2(mut mutable_tx: SignableTransaction, privkeys: Vec<
let mut additional_signatures_required = false;
for i in 0..mutable_tx.tx.inputs.len() {
let script = mutable_tx.entries[i].as_ref().unwrap().script_public_key.script();
if let Some(schnorr_key) = map.get(&script.to_vec()) {
if let Some(schnorr_key) = map.get(script) {
let sig_hash = calc_schnorr_signature_hash(&mutable_tx.as_verifiable(), i, SIG_HASH_ALL, &mut reused_values);
let msg = secp256k1::Message::from_slice(sig_hash.as_bytes().as_slice()).unwrap();
let sig: [u8; 64] = *schnorr_key.sign_schnorr(msg).as_ref();
Expand Down
3 changes: 3 additions & 0 deletions consensus/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ rand.workspace = true

workflow-wasm.workspace = true
workflow-log.workspace = true

[lints.clippy]
empty_docs = "allow"
1 change: 1 addition & 0 deletions crypto/txscript/src/data_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) trait DataStack {
fn pop_items<const SIZE: usize, T: Debug>(&mut self) -> Result<[T; SIZE], TxScriptError>
where
Vec<u8>: OpcodeData<T>;
#[allow(dead_code)]
fn peek_items<const SIZE: usize, T: Debug>(&self) -> Result<[T; SIZE], TxScriptError>
where
Vec<u8>: OpcodeData<T>;
Expand Down
2 changes: 1 addition & 1 deletion crypto/txscript/src/opcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ mod test {
let mut reused_values = SigHashReusedValues::new();
for ErrorTestCase { init, code, error } in tests {
let mut vm = TxScriptEngine::new(&mut reused_values, &cache);
vm.dstack = init.clone();
vm.dstack.clone_from(&init);
assert_eq!(
code.execute(&mut vm)
.expect_err(format!("Opcode {} should have errored (init: {:?})", code.value(), init.clone()).as_str()),
Expand Down
2 changes: 1 addition & 1 deletion kaspad/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Args {
config.is_archival = self.archival;
// TODO: change to `config.enable_sanity_checks = self.sanity` when we reach stable versions
config.enable_sanity_checks = true;
config.user_agent_comments = self.user_agent_comments.clone();
config.user_agent_comments.clone_from(&self.user_agent_comments);
config.block_template_cache_lifetime = self.block_template_cache_lifetime;
config.p2p_listen_address = self.listen.unwrap_or(ContextualNetAddress::unspecified());
config.externalip = self.externalip.map(|v| v.normalize(config.default_p2p_port()));
Expand Down
1 change: 1 addition & 0 deletions kos/src/metrics/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl MetricsIpc {
}
}

#[allow(dead_code)]
#[async_trait]
pub trait MetricsCtl: Send + Sync + 'static {
async fn post_data(&self, data: MetricsSnapshot) -> Result<()>;
Expand Down
1 change: 1 addition & 0 deletions mining/src/mempool/model/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub(crate) trait Pool {

/// Returns an index over either high or low priority transaction ids which can
/// in turn be topologically ordered.
#[allow(dead_code)]
fn index(&self, priority: Priority) -> PoolIndex {
let transactions: TransactionIdSet =
self.all().iter().filter_map(|(id, tx)| if tx.priority == priority { Some(*id) } else { None }).collect();
Expand Down
3 changes: 3 additions & 0 deletions rpc/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ workflow-wasm.workspace = true

[dev-dependencies]
serde_json.workspace = true

[lints.clippy]
empty_docs = "allow"
4 changes: 2 additions & 2 deletions rpc/core/src/model/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

pub type RpcAddress = kaspa_addresses::Address;

///
/// Represents a UTXO entry of an address returned by the `GetUtxosByAddresses` RPC.
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcUtxosByAddressesEntry {
Expand All @@ -13,7 +13,7 @@ pub struct RpcUtxosByAddressesEntry {
pub utxo_entry: RpcUtxoEntry,
}

///
/// Represents a balance of an address returned by the `GetBalancesByAddresses` RPC.
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcBalancesByAddressesEntry {
Expand Down
4 changes: 2 additions & 2 deletions rpc/wrpc/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ impl KaspaRpcClient {
// or 1.2.3.4:port where port is based on the network type.
//
if (parse_output.scheme.is_some() || !path_str.is_empty()) && parse_output.port.is_none() {
Ok(format!("{}://{}{}", scheme, parse_output.host.to_string(), path_str))
Ok(format!("{}://{}{}", scheme, parse_output.host, path_str))
} else {
Ok(format!("{}://{}:{}{}", scheme, parse_output.host.to_string(), port, path_str))
Ok(format!("{}://{}:{}{}", scheme, parse_output.host, port, path_str))
}
}

Expand Down
14 changes: 7 additions & 7 deletions rpc/wrpc/client/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Display for ParseHostOutput<'_> {
if let Some(scheme) = self.scheme {
write!(f, "{}://", scheme)?;
}
write!(f, "{}", self.host.to_string())?;
write!(f, "{}", self.host)?;
if let Some(port) = self.port {
write!(f, ":{}", port)?;
}
Expand All @@ -31,13 +31,13 @@ pub enum Host<'a> {
Ipv6(Ipv6Addr),
}

impl ToString for Host<'_> {
fn to_string(&self) -> String {
impl Display for Host<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Host::Domain(domain) => domain.to_string(),
Host::Hostname(hostname) => hostname.to_string(),
Host::Ipv4(ipv4) => ipv4.to_string(),
Host::Ipv6(ipv6) => format!("[{}]", ipv6),
Host::Domain(domain) => write!(f, "{}", domain),
Host::Hostname(hostname) => write!(f, "{}", hostname),
Host::Ipv4(ipv4) => write!(f, "{}", ipv4),
Host::Ipv6(ipv6) => write!(f, "[{}]", ipv6),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions utils/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ trait RwLockTrait<T> {
type WriteGuard;
fn new(value: T) -> Self;
async fn read_(&self) -> Self::ReadGuard;
#[allow(dead_code)]
async fn write_(&self) -> Self::WriteGuard;
}

Expand Down
3 changes: 3 additions & 0 deletions wallet/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ serde_repr.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio.workspace = true

[lints.clippy]
empty_docs = "allow"
6 changes: 3 additions & 3 deletions wallet/core/src/storage/local/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
}

pub fn insert(&mut self, id: Id, data: Arc<Data>) -> Result<()> {
if self.map.get(&id).is_some() {
if self.map.contains_key(&id) {
self.map.remove(&id);
self.vec.retain(|d| d.id() != &id);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ where
pub fn store_multiple(&mut self, data: Vec<Data>) -> Result<()> {
for data in data.into_iter() {
let id = data.id().clone();
if self.map.get(&id).is_some() {
if self.map.contains_key(&id) {
self.map.remove(&id);
self.vec.retain(|d| d.id() != &id);
}
Expand All @@ -98,7 +98,7 @@ where

pub fn store_single(&mut self, data: &Data) -> Result<()> {
let id = data.id();
if self.map.get(id).is_some() {
if self.map.contains_key(id) {
self.map.remove(id);
self.vec.retain(|d| d.id() != id);
}
Expand Down
3 changes: 2 additions & 1 deletion wallet/core/src/tx/generator/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl FeesExpected {
}

trait PendingTransactionExtension {
#[allow(dead_code)]
fn tuple(self) -> (PendingTransaction, Transaction);
fn expect<SOMPI>(self, expected: &Expected<SOMPI>) -> Self
where
Expand Down Expand Up @@ -297,7 +298,7 @@ impl Harness {
Rc::new(Harness { generator, accumulator: RefCell::new(Accumulator::default()) })
}

pub fn fetch<SOMPI: Into<Sompi>>(self: &Rc<Self>, expected: &Expected<SOMPI>) -> Rc<Self>
pub fn fetch<SOMPI>(self: &Rc<Self>, expected: &Expected<SOMPI>) -> Rc<Self>
where
SOMPI: Into<Sompi> + Debug + Copy,
{
Expand Down
2 changes: 1 addition & 1 deletion wallet/core/src/utxo/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl UtxoProcessor {
}

pub async fn bind_rpc(&self, rpc: Option<Rpc>) -> Result<()> {
*self.inner.rpc.lock().unwrap() = rpc.clone();
self.inner.rpc.lock().unwrap().clone_from(&rpc);
self.sync_proc().bind_rpc(rpc).await?;
Ok(())
}
Expand Down

0 comments on commit 40734e7

Please sign in to comment.