Skip to content

Commit

Permalink
Update to Rust v1.77 (#1744)
Browse files Browse the repository at this point in the history
* Update to Rust v1.77

* Silence the new warnings
  • Loading branch information
tomaka authored Apr 4, 2024
1 parent 94ba730 commit a6c2b5b
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 53 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
test-64bits:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
Expand All @@ -39,7 +39,7 @@ jobs:
test-32bits:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- run: apt-get update && apt install -y libc6-dev-i386
- uses: actions/checkout@v4
Expand All @@ -50,7 +50,7 @@ jobs:
wasm-node-check:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- run: rustup target add wasm32-unknown-unknown
Expand All @@ -66,7 +66,7 @@ jobs:
check-features:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
check-no-std:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- run: rustup target add thumbv7m-none-eabi
Expand All @@ -112,7 +112,7 @@ jobs:
check-rustdoc-links:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
Expand All @@ -121,7 +121,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
# Checks `rustfmt` formatting
- uses: actions/checkout@v4
Expand All @@ -135,7 +135,7 @@ jobs:
clippy:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
# Since build artifacts are specific to a nightly version, we pin the specific nightly
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
wasm-node-versions-match:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- run: apt-get update && apt install -y jq
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
build-js-doc:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -83,7 +83,7 @@ jobs:
build-rust-doc:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -104,7 +104,7 @@ jobs:
build-tests-coverage:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- run: apt update && apt install -y jq
- run: rustup component add llvm-tools-preview
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
npm-publish:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- run: rustup target add wasm32-unknown-unknown
Expand Down Expand Up @@ -217,7 +217,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
# Ideally we don't want to install any toolchain, but the GH action doesn't support this.
toolchain: 1.76
toolchain: 1.77
profile: minimal
- uses: Swatinem/rust-cache@v2
- id: compute-tag # Compute the tag that we might push.
Expand All @@ -244,7 +244,7 @@ jobs:
crates-io-publish:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
- run: cargo publish --dry-run --locked
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/periodic-cargo-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
cargo-update:
runs-on: ubuntu-latest
container:
image: rust:1.76
image: rust:1.77
steps:
- uses: actions/checkout@v4
# Note: `cargo update --workspace` doesn't seem to have any effect.
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions lib/src/chain_spec/light_sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fn gap_epochs<'a, E: nom::error::ParseError<&'a [u8]>>(
}

#[derive(Debug)]
#[allow(dead_code)] // Necessary to silence warnings about unused fields.
pub(super) enum PersistedEpochHeader {
Genesis(EpochHeader, EpochHeader),
Regular(EpochHeader),
Expand Down Expand Up @@ -192,6 +193,7 @@ fn epoch_header<'a, E: nom::error::ParseError<&'a [u8]>>(
}

#[derive(Debug)]
#[allow(dead_code)] // Necessary to silence warnings about unused fields.
pub(super) enum PersistedEpoch {
Genesis(BabeEpoch, BabeEpoch),
Regular(BabeEpoch),
Expand Down
3 changes: 3 additions & 0 deletions lib/src/json_rpc/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn parse_request(request_json: &str) -> Result<Request, ParseError> {

if let Some(id) = &serde_request.id {
// Because of https://github.com/serde-rs/json/issues/742, we can't use ̀`&str`.
#[allow(dead_code)] // Necessary to silence warnings about unused fields.
#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(untagged)]
Expand Down Expand Up @@ -55,6 +56,7 @@ pub fn parse_response(response_json: &str) -> Result<Response, ParseError> {
result,
}) => {
// Because of https://github.com/serde-rs/json/issues/742, we can't use ̀`&str`.
#[allow(dead_code)] // Necessary to silence warnings about unused fields.
#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(untagged)]
Expand Down Expand Up @@ -86,6 +88,7 @@ pub fn parse_response(response_json: &str) -> Result<Response, ParseError> {
},
}) if id.get() != "null" => {
// Because of https://github.com/serde-rs/json/issues/742, we can't use ̀`&str`.
#[allow(dead_code)] // Necessary to silence warnings about unused fields.
#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(untagged)]
Expand Down
26 changes: 12 additions & 14 deletions light-base/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use alloc::borrow::Cow;
use core::{fmt, future::Future, ops, panic::UnwindSafe, pin::Pin, str, time::Duration};
use core::{
fmt,
future::Future,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
ops,
panic::UnwindSafe,
pin::Pin,
str,
time::Duration,
};
use futures_util::future;

pub use smoldot::libp2p::read_write;
Expand Down Expand Up @@ -372,12 +381,12 @@ impl<'a> From<&'a Address<'a>> for ConnectionType {
Address::WebSocketIp {
ip: IpAddr::V4(ip), ..
} => ConnectionType::WebSocketIpv4 {
remote_is_localhost: no_std_net::Ipv4Addr::from(*ip).is_loopback(),
remote_is_localhost: Ipv4Addr::from(*ip).is_loopback(),
},
Address::WebSocketIp {
ip: IpAddr::V6(ip), ..
} => ConnectionType::WebSocketIpv6 {
remote_is_localhost: no_std_net::Ipv6Addr::from(*ip).is_loopback(),
remote_is_localhost: Ipv6Addr::from(*ip).is_loopback(),
},
Address::WebSocketDns {
hostname, secure, ..
Expand Down Expand Up @@ -475,17 +484,6 @@ pub enum MultiStreamAddress<'a> {
},
}

/// Either an IPv4 or IPv6 address.
///
/// > **Note**: This enum is the same as `std::net::IpAddr`, but is copy-pasted here in order to
/// > be no-std-compatible.
// TODO: replace this with `core::net::IpAddr` once it's stable: https://github.com/rust-lang/rust/issues/108443
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum IpAddr {
V4([u8; 4]),
V6([u8; 16]),
}

// TODO: find a way to keep this private somehow?
#[macro_export]
macro_rules! log_inner {
Expand Down
19 changes: 11 additions & 8 deletions light-base/src/platform/address_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

use smoldot::libp2p::multiaddr::{Multiaddr, Protocol};

use super::{Address, ConnectionType, IpAddr, MultiStreamAddress};
use core::str;
use super::{Address, ConnectionType, MultiStreamAddress};
use core::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
str,
};

pub enum AddressOrMultiStreamAddress<'a> {
Address(Address<'a>),
Expand Down Expand Up @@ -50,13 +53,13 @@ pub fn multiaddr_to_address(multiaddr: &Multiaddr) -> Result<AddressOrMultiStrea
Ok(match (proto1, proto2, proto3, proto4) {
(Protocol::Ip4(ip), Protocol::Tcp(port), None, None) => {
AddressOrMultiStreamAddress::Address(Address::TcpIp {
ip: IpAddr::V4(ip),
ip: IpAddr::V4(Ipv4Addr::from(ip)),
port,
})
}
(Protocol::Ip6(ip), Protocol::Tcp(port), None, None) => {
AddressOrMultiStreamAddress::Address(Address::TcpIp {
ip: IpAddr::V6(ip),
ip: IpAddr::V6(Ipv6Addr::from(ip)),
port,
})
}
Expand All @@ -71,13 +74,13 @@ pub fn multiaddr_to_address(multiaddr: &Multiaddr) -> Result<AddressOrMultiStrea
}),
(Protocol::Ip4(ip), Protocol::Tcp(port), Some(Protocol::Ws), None) => {
AddressOrMultiStreamAddress::Address(Address::WebSocketIp {
ip: IpAddr::V4(ip),
ip: IpAddr::V4(Ipv4Addr::from(ip)),
port,
})
}
(Protocol::Ip6(ip), Protocol::Tcp(port), Some(Protocol::Ws), None) => {
AddressOrMultiStreamAddress::Address(Address::WebSocketIp {
ip: IpAddr::V6(ip),
ip: IpAddr::V6(Ipv6Addr::from(ip)),
port,
})
}
Expand Down Expand Up @@ -121,7 +124,7 @@ pub fn multiaddr_to_address(multiaddr: &Multiaddr) -> Result<AddressOrMultiStrea
return Err(Error::InvalidMultihashLength);
};
AddressOrMultiStreamAddress::MultiStreamAddress(MultiStreamAddress::WebRtc {
ip: IpAddr::V4(ip),
ip: IpAddr::V4(Ipv4Addr::from(ip)),
port,
remote_certificate_sha256,
})
Expand All @@ -140,7 +143,7 @@ pub fn multiaddr_to_address(multiaddr: &Multiaddr) -> Result<AddressOrMultiStrea
return Err(Error::InvalidMultihashLength);
};
AddressOrMultiStreamAddress::MultiStreamAddress(MultiStreamAddress::WebRtc {
ip: IpAddr::V6(ip),
ip: IpAddr::V6(Ipv6Addr::from(ip)),
port,
remote_certificate_sha256,
})
Expand Down
1 change: 0 additions & 1 deletion wasm-node/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ futures-lite = { version = "2.3.0", default-features = false, features = ["alloc
futures-util = { version = "0.3.27", default-features = false }
hashbrown = { version = "0.14.0", default-features = false }
nom = { version = "7.1.3", default-features = false }
no-std-net = { version = "0.6.0", default-features = false }
pin-project = "1.1.5"
slab = { version = "0.4.8", default-features = false }
smoldot = { version = "0.17.0", path = "../../lib", default-features = false }
Expand Down
28 changes: 15 additions & 13 deletions wasm-node/rust/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use alloc::{
use async_lock::Mutex;
use core::{
fmt::{self, Write as _},
future, iter, mem, ops, pin, str,
future, iter, mem,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
ops, pin, str,
sync::atomic::{AtomicU32, AtomicU64, Ordering},
task,
time::Duration,
Expand Down Expand Up @@ -314,36 +316,36 @@ impl smoldot_light::platform::PlatformRef for PlatformRef {

let encoded_address: Vec<u8> = match address {
smoldot_light::platform::Address::TcpIp {
ip: smoldot_light::platform::IpAddr::V4(ip),
ip: IpAddr::V4(ip),
port,
} => iter::once(0u8)
.chain(port.to_be_bytes())
.chain(no_std_net::Ipv4Addr::from(ip).to_string().bytes())
.chain(Ipv4Addr::from(ip).to_string().bytes())
.collect(),
smoldot_light::platform::Address::TcpIp {
ip: smoldot_light::platform::IpAddr::V6(ip),
ip: IpAddr::V6(ip),
port,
} => iter::once(1u8)
.chain(port.to_be_bytes())
.chain(no_std_net::Ipv6Addr::from(ip).to_string().bytes())
.chain(Ipv6Addr::from(ip).to_string().bytes())
.collect(),
smoldot_light::platform::Address::TcpDns { hostname, port } => iter::once(2u8)
.chain(port.to_be_bytes())
.chain(hostname.as_bytes().iter().copied())
.collect(),
smoldot_light::platform::Address::WebSocketIp {
ip: smoldot_light::platform::IpAddr::V4(ip),
ip: IpAddr::V4(ip),
port,
} => iter::once(4u8)
.chain(port.to_be_bytes())
.chain(no_std_net::Ipv4Addr::from(ip).to_string().bytes())
.chain(Ipv4Addr::from(ip).to_string().bytes())
.collect(),
smoldot_light::platform::Address::WebSocketIp {
ip: smoldot_light::platform::IpAddr::V6(ip),
ip: IpAddr::V6(ip),
port,
} => iter::once(5u8)
.chain(port.to_be_bytes())
.chain(no_std_net::Ipv6Addr::from(ip).to_string().bytes())
.chain(Ipv6Addr::from(ip).to_string().bytes())
.collect(),
smoldot_light::platform::Address::WebSocketDns {
hostname,
Expand Down Expand Up @@ -423,22 +425,22 @@ impl smoldot_light::platform::PlatformRef for PlatformRef {

let encoded_address: Vec<u8> = match address {
smoldot_light::platform::MultiStreamAddress::WebRtc {
ip: smoldot_light::platform::IpAddr::V4(ip),
ip: IpAddr::V4(ip),
port,
remote_certificate_sha256,
} => iter::once(16u8)
.chain(port.to_be_bytes())
.chain(remote_certificate_sha256.iter().copied())
.chain(no_std_net::Ipv4Addr::from(ip).to_string().bytes())
.chain(Ipv4Addr::from(ip).to_string().bytes())
.collect(),
smoldot_light::platform::MultiStreamAddress::WebRtc {
ip: smoldot_light::platform::IpAddr::V6(ip),
ip: IpAddr::V6(ip),
port,
remote_certificate_sha256,
} => iter::once(17u8)
.chain(port.to_be_bytes())
.chain(remote_certificate_sha256.iter().copied())
.chain(no_std_net::Ipv6Addr::from(ip).to_string().bytes())
.chain(Ipv6Addr::from(ip).to_string().bytes())
.collect(),
};

Expand Down

0 comments on commit a6c2b5b

Please sign in to comment.