Skip to content

Commit

Permalink
Update to Rust v1.79 and fix warnings (#1903)
Browse files Browse the repository at this point in the history
* Update to Rust v1.79 and fix warnings

* Forgot a warning

* Fix warnings in full node

* Should be good this time

* More warnings

* More warnings
  • Loading branch information
tomaka authored Jul 9, 2024
1 parent 19f159e commit 8638a7f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 76 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.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
steps:
# Checks `rustfmt` formatting
- uses: actions/checkout@v4
Expand All @@ -135,7 +135,7 @@ jobs:
clippy:
runs-on: ubuntu-latest
container:
image: rust:1.77
image: rust:1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -83,7 +83,7 @@ jobs:
build-rust-doc:
runs-on: ubuntu-latest
container:
image: rust:1.77
image: rust:1.79
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -104,7 +104,7 @@ jobs:
build-tests-coverage:
runs-on: ubuntu-latest
container:
image: rust:1.77
image: rust:1.79
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.77
image: rust:1.79
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.77
toolchain: 1.79
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.77
image: rust:1.79
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.77
image: rust:1.79
steps:
- uses: actions/checkout@v4
# Note: `cargo update --workspace` doesn't seem to have any effect.
Expand Down
5 changes: 0 additions & 5 deletions full-node/src/json_rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ impl JsonRpcService {

spawn_client_main_task(
config.tasks_executor.clone(),
config.log_callback.clone(),
config.consensus_service.clone(),
config.database.clone(),
to_requests_handlers.clone(),
Expand All @@ -164,7 +163,6 @@ impl JsonRpcService {
let runtime_caches_service = Arc::new(runtime_caches_service::RuntimeCachesService::new(
runtime_caches_service::Config {
tasks_executor: config.tasks_executor.clone(),
log_callback: config.log_callback.clone(),
database: config.database.clone(),
num_cache_entries: NonZeroUsize::new(16).unwrap(), // TODO: configurable?
},
Expand Down Expand Up @@ -363,7 +361,6 @@ impl JsonRpcBackground {
);
spawn_client_main_task(
self.tasks_executor.clone(),
self.log_callback.clone(),
self.consensus_service.clone(),
self.database.clone(),
self.to_requests_handlers.clone(),
Expand Down Expand Up @@ -547,7 +544,6 @@ fn spawn_client_io_task(

fn spawn_client_main_task(
tasks_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
log_callback: Arc<dyn LogCallback + Send + Sync>,
consensus_service: Arc<consensus_service::ConsensusService>,
database: Arc<database_thread::DatabaseThread>,
to_requests_handlers: async_channel::Sender<requests_handler::Message>,
Expand Down Expand Up @@ -649,7 +645,6 @@ fn spawn_client_main_task(
chain_head_subscriptions::spawn_chain_head_subscription_task(
chain_head_subscriptions::Config {
tasks_executor: tasks_executor.clone(),
log_callback: log_callback.clone(),
receiver: rx,
chain_head_follow_subscription: subscription_start,
with_runtime,
Expand Down
5 changes: 1 addition & 4 deletions full-node/src/json_rpc_service/chain_head_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ use std::{
sync::Arc,
};

use crate::{consensus_service, database_thread, LogCallback};
use crate::{consensus_service, database_thread};

pub struct Config {
/// Function that can be used to spawn background tasks.
///
/// The tasks passed as parameter must be executed until they shut down.
pub tasks_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,

/// Function called in order to notify of something.
pub log_callback: Arc<dyn LogCallback + Send + Sync>,

/// Receiver for actions that the JSON-RPC client wants to perform.
pub receiver: async_channel::Receiver<Message>,

Expand Down
5 changes: 1 addition & 4 deletions full-node/src/json_rpc_service/runtime_caches_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use crate::{database_thread, LogCallback};
use crate::database_thread;

use futures_channel::oneshot;
use futures_lite::{Future, StreamExt as _};
Expand All @@ -33,9 +33,6 @@ pub struct Config {
/// Closure that spawns background tasks.
pub tasks_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,

/// Function called in order to notify of something.
pub log_callback: Arc<dyn LogCallback + Send + Sync>,

/// Database to access blocks.
pub database: Arc<database_thread::DatabaseThread>,

Expand Down
27 changes: 10 additions & 17 deletions lib/src/executor/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum Error {
/// The client passed a memory instance which is smaller than previously observed.
MemoryShrinked,
// TODO: wtf is "Other"?
Other(&'static str),
Other,
}

/// The maximum number of bytes that can be allocated at one time.
Expand All @@ -102,11 +102,6 @@ const ALIGNMENT: u32 = 8;
// to which it belongs.
const HEADER_SIZE: u32 = 8;

/// Create an allocator error.
fn error(msg: &'static str) -> Error {
Error::Other(msg)
}

// The minimum possible allocation size is chosen to be 8 bytes because in that case we would have
// easier time to provide the guaranteed alignment of 8.
//
Expand Down Expand Up @@ -144,7 +139,7 @@ impl Order {
if order < N_ORDERS as u32 {
Ok(Self(order))
} else {
Err(error("invalid order"))
Err(Error::Other)
}
}

Expand Down Expand Up @@ -381,7 +376,7 @@ impl FreeingBumpHeapAllocator {
/// - `size` - size in bytes of the allocation request
pub fn allocate<M: Memory + ?Sized>(&mut self, mem: &mut M, size: u32) -> Result<u32, Error> {
if self.poisoned {
return Err(error("the allocator has been poisoned"));
return Err(Error::Other);
}

let bomb = PoisonBomb {
Expand All @@ -402,7 +397,7 @@ impl FreeingBumpHeapAllocator {
// Remove this header from the free list.
let next_free = Header::read_from(mem, header_ptr)?
.into_free()
.ok_or_else(|| error("free list points to a occupied header"))?;
.ok_or_else(|| Error::Other)?;
self.free_lists[order] = next_free;

header_ptr
Expand Down Expand Up @@ -443,7 +438,7 @@ impl FreeingBumpHeapAllocator {
/// - `ptr` - pointer to the allocated chunk
pub fn deallocate<M: Memory + ?Sized>(&mut self, mem: &mut M, ptr: u32) -> Result<(), Error> {
if self.poisoned {
return Err(error("the allocator has been poisoned"));
return Err(Error::Other);
}

let bomb = PoisonBomb {
Expand All @@ -454,11 +449,11 @@ impl FreeingBumpHeapAllocator {

let header_ptr = u32::from(ptr)
.checked_sub(HEADER_SIZE)
.ok_or_else(|| error("Invalid pointer for deallocation"))?;
.ok_or_else(|| Error::Other)?;

let order = Header::read_from(mem, header_ptr)?
.into_occupied()
.ok_or_else(|| error("the allocation points to an empty header"))?;
.ok_or_else(|| Error::Other)?;

// Update the just freed header and knit it back to the free list.
let prev_head = self.free_lists.replace(order, Link::Ptr(header_ptr));
Expand All @@ -468,7 +463,7 @@ impl FreeingBumpHeapAllocator {
self.total_size = self
.total_size
.checked_sub(order.size() + HEADER_SIZE)
.ok_or_else(|| error("Unable to subtract from total heap size without overflow"))?;
.ok_or_else(|| Error::Other)?;

bomb.disarm();
Ok(())
Expand Down Expand Up @@ -520,16 +515,14 @@ pub trait Memory {

impl Memory for [u8] {
fn read_le_u64(&self, ptr: u32) -> Result<u64, Error> {
let range =
heap_range(ptr, 8, self.len()).ok_or_else(|| error("read out of heap bounds"))?;
let range = heap_range(ptr, 8, self.len()).ok_or_else(|| Error::Other)?;
let bytes = self[range]
.try_into()
.expect("[u8] slice of length 8 must be convertible to [u8; 8]");
Ok(u64::from_le_bytes(bytes))
}
fn write_le_u64(&mut self, ptr: u32, val: u64) -> Result<(), Error> {
let range =
heap_range(ptr, 8, self.len()).ok_or_else(|| error("write out of heap bounds"))?;
let range = heap_range(ptr, 8, self.len()).ok_or_else(|| Error::Other)?;
let bytes = val.to_le_bytes();
self[range].copy_from_slice(&bytes[..]);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions lib/src/executor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4144,7 +4144,7 @@ enum MemAccessVm<'a> {
impl<'a> allocator::Memory for MemAccess<'a> {
fn read_le_u64(&self, ptr: u32) -> Result<u64, allocator::Error> {
if (ptr + 8) > u32::from(self.memory_total_pages) * 64 * 1024 {
return Err(allocator::Error::Other("out of bounds access"));
return Err(allocator::Error::Other);
}

// Note that this function (`read_le_u64`) really should take ̀`&mut self` but that is
Expand Down Expand Up @@ -4215,7 +4215,7 @@ impl<'a> allocator::Memory for MemAccess<'a> {

fn write_le_u64(&mut self, ptr: u32, val: u64) -> Result<(), allocator::Error> {
if (ptr + 8) > u32::from(self.memory_total_pages) * 64 * 1024 {
return Err(allocator::Error::Other("out of bounds access"));
return Err(allocator::Error::Other);
}

let bytes = val.to_le_bytes();
Expand Down
2 changes: 2 additions & 0 deletions light-base/src/json_rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct Config<TPlat: PlatformRef> {
/// This parameter is necessary in order to prevent users from using up too much memory within
/// the client.
// TODO: unused at the moment
#[allow(unused)]
pub max_pending_requests: NonZeroU32,

/// Maximum number of active subscriptions. Any additional subscription will be immediately
Expand All @@ -79,6 +80,7 @@ pub struct Config<TPlat: PlatformRef> {
/// This parameter is necessary in order to prevent users from using up too much memory within
/// the client.
// TODO: unused at the moment
#[allow(unused)]
pub max_subscriptions: u32,

/// Access to the network, and identifier of the chain from the point of view of the network
Expand Down
Loading

0 comments on commit 8638a7f

Please sign in to comment.