Skip to content

Commit 8638a7f

Browse files
authored
Update to Rust v1.79 and fix warnings (#1903)
* 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
1 parent 19f159e commit 8638a7f

File tree

10 files changed

+40
-76
lines changed

10 files changed

+40
-76
lines changed

.github/workflows/ci.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
test-64bits:
3131
runs-on: ubuntu-latest
3232
container:
33-
image: rust:1.77
33+
image: rust:1.79
3434
steps:
3535
- uses: actions/checkout@v4
3636
- uses: Swatinem/rust-cache@v2
@@ -39,7 +39,7 @@ jobs:
3939
test-32bits:
4040
runs-on: ubuntu-latest
4141
container:
42-
image: rust:1.77
42+
image: rust:1.79
4343
steps:
4444
- run: apt-get update && apt install -y libc6-dev-i386
4545
- uses: actions/checkout@v4
@@ -50,7 +50,7 @@ jobs:
5050
wasm-node-check:
5151
runs-on: ubuntu-latest
5252
container:
53-
image: rust:1.77
53+
image: rust:1.79
5454
steps:
5555
- uses: actions/checkout@v4
5656
- run: rustup target add wasm32-unknown-unknown
@@ -66,7 +66,7 @@ jobs:
6666
check-features:
6767
runs-on: ubuntu-latest
6868
container:
69-
image: rust:1.77
69+
image: rust:1.79
7070
steps:
7171
- uses: actions/checkout@v4
7272
- uses: Swatinem/rust-cache@v2
@@ -100,7 +100,7 @@ jobs:
100100
check-no-std:
101101
runs-on: ubuntu-latest
102102
container:
103-
image: rust:1.77
103+
image: rust:1.79
104104
steps:
105105
- uses: actions/checkout@v4
106106
- run: rustup target add thumbv7m-none-eabi
@@ -112,7 +112,7 @@ jobs:
112112
check-rustdoc-links:
113113
runs-on: ubuntu-latest
114114
container:
115-
image: rust:1.77
115+
image: rust:1.79
116116
steps:
117117
- uses: actions/checkout@v4
118118
- uses: Swatinem/rust-cache@v2
@@ -121,7 +121,7 @@ jobs:
121121
fmt:
122122
runs-on: ubuntu-latest
123123
container:
124-
image: rust:1.77
124+
image: rust:1.79
125125
steps:
126126
# Checks `rustfmt` formatting
127127
- uses: actions/checkout@v4
@@ -135,7 +135,7 @@ jobs:
135135
clippy:
136136
runs-on: ubuntu-latest
137137
container:
138-
image: rust:1.77
138+
image: rust:1.79
139139
steps:
140140
- uses: actions/checkout@v4
141141
# Since build artifacts are specific to a nightly version, we pin the specific nightly
@@ -176,7 +176,7 @@ jobs:
176176
wasm-node-versions-match:
177177
runs-on: ubuntu-latest
178178
container:
179-
image: rust:1.77
179+
image: rust:1.79
180180
steps:
181181
- uses: actions/checkout@v4
182182
- run: apt-get update && apt install -y jq

.github/workflows/deploy.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
build-js-doc:
5757
runs-on: ubuntu-latest
5858
container:
59-
image: rust:1.77
59+
image: rust:1.79
6060
steps:
6161
- uses: actions/checkout@v4
6262
with:
@@ -83,7 +83,7 @@ jobs:
8383
build-rust-doc:
8484
runs-on: ubuntu-latest
8585
container:
86-
image: rust:1.77
86+
image: rust:1.79
8787
steps:
8888
- uses: actions/checkout@v4
8989
with:
@@ -104,7 +104,7 @@ jobs:
104104
build-tests-coverage:
105105
runs-on: ubuntu-latest
106106
container:
107-
image: rust:1.77
107+
image: rust:1.79
108108
steps:
109109
- run: apt update && apt install -y jq
110110
- run: rustup component add llvm-tools-preview
@@ -174,7 +174,7 @@ jobs:
174174
npm-publish:
175175
runs-on: ubuntu-latest
176176
container:
177-
image: rust:1.77
177+
image: rust:1.79
178178
steps:
179179
- uses: actions/checkout@v4
180180
- run: rustup target add wasm32-unknown-unknown
@@ -217,7 +217,7 @@ jobs:
217217
- uses: actions-rs/toolchain@v1
218218
with:
219219
# Ideally we don't want to install any toolchain, but the GH action doesn't support this.
220-
toolchain: 1.77
220+
toolchain: 1.79
221221
profile: minimal
222222
- uses: Swatinem/rust-cache@v2
223223
- id: compute-tag # Compute the tag that we might push.
@@ -244,7 +244,7 @@ jobs:
244244
crates-io-publish:
245245
runs-on: ubuntu-latest
246246
container:
247-
image: rust:1.77
247+
image: rust:1.79
248248
steps:
249249
- uses: actions/checkout@v4
250250
- run: cargo publish --dry-run --locked

.github/workflows/periodic-cargo-update.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
cargo-update:
1010
runs-on: ubuntu-latest
1111
container:
12-
image: rust:1.77
12+
image: rust:1.79
1313
steps:
1414
- uses: actions/checkout@v4
1515
# Note: `cargo update --workspace` doesn't seem to have any effect.

full-node/src/json_rpc_service.rs

-5
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl JsonRpcService {
154154

155155
spawn_client_main_task(
156156
config.tasks_executor.clone(),
157-
config.log_callback.clone(),
158157
config.consensus_service.clone(),
159158
config.database.clone(),
160159
to_requests_handlers.clone(),
@@ -164,7 +163,6 @@ impl JsonRpcService {
164163
let runtime_caches_service = Arc::new(runtime_caches_service::RuntimeCachesService::new(
165164
runtime_caches_service::Config {
166165
tasks_executor: config.tasks_executor.clone(),
167-
log_callback: config.log_callback.clone(),
168166
database: config.database.clone(),
169167
num_cache_entries: NonZeroUsize::new(16).unwrap(), // TODO: configurable?
170168
},
@@ -363,7 +361,6 @@ impl JsonRpcBackground {
363361
);
364362
spawn_client_main_task(
365363
self.tasks_executor.clone(),
366-
self.log_callback.clone(),
367364
self.consensus_service.clone(),
368365
self.database.clone(),
369366
self.to_requests_handlers.clone(),
@@ -547,7 +544,6 @@ fn spawn_client_io_task(
547544

548545
fn spawn_client_main_task(
549546
tasks_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
550-
log_callback: Arc<dyn LogCallback + Send + Sync>,
551547
consensus_service: Arc<consensus_service::ConsensusService>,
552548
database: Arc<database_thread::DatabaseThread>,
553549
to_requests_handlers: async_channel::Sender<requests_handler::Message>,
@@ -649,7 +645,6 @@ fn spawn_client_main_task(
649645
chain_head_subscriptions::spawn_chain_head_subscription_task(
650646
chain_head_subscriptions::Config {
651647
tasks_executor: tasks_executor.clone(),
652-
log_callback: log_callback.clone(),
653648
receiver: rx,
654649
chain_head_follow_subscription: subscription_start,
655650
with_runtime,

full-node/src/json_rpc_service/chain_head_subscriptions.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ use std::{
3131
sync::Arc,
3232
};
3333

34-
use crate::{consensus_service, database_thread, LogCallback};
34+
use crate::{consensus_service, database_thread};
3535

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

42-
/// Function called in order to notify of something.
43-
pub log_callback: Arc<dyn LogCallback + Send + Sync>,
44-
4542
/// Receiver for actions that the JSON-RPC client wants to perform.
4643
pub receiver: async_channel::Receiver<Message>,
4744

full-node/src/json_rpc_service/runtime_caches_service.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18-
use crate::{database_thread, LogCallback};
18+
use crate::database_thread;
1919

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

36-
/// Function called in order to notify of something.
37-
pub log_callback: Arc<dyn LogCallback + Send + Sync>,
38-
3936
/// Database to access blocks.
4037
pub database: Arc<database_thread::DatabaseThread>,
4138

lib/src/executor/allocator.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub enum Error {
8484
/// The client passed a memory instance which is smaller than previously observed.
8585
MemoryShrinked,
8686
// TODO: wtf is "Other"?
87-
Other(&'static str),
87+
Other,
8888
}
8989

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

105-
/// Create an allocator error.
106-
fn error(msg: &'static str) -> Error {
107-
Error::Other(msg)
108-
}
109-
110105
// The minimum possible allocation size is chosen to be 8 bytes because in that case we would have
111106
// easier time to provide the guaranteed alignment of 8.
112107
//
@@ -144,7 +139,7 @@ impl Order {
144139
if order < N_ORDERS as u32 {
145140
Ok(Self(order))
146141
} else {
147-
Err(error("invalid order"))
142+
Err(Error::Other)
148143
}
149144
}
150145

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

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

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

449444
let bomb = PoisonBomb {
@@ -454,11 +449,11 @@ impl FreeingBumpHeapAllocator {
454449

455450
let header_ptr = u32::from(ptr)
456451
.checked_sub(HEADER_SIZE)
457-
.ok_or_else(|| error("Invalid pointer for deallocation"))?;
452+
.ok_or_else(|| Error::Other)?;
458453

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

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

473468
bomb.disarm();
474469
Ok(())
@@ -520,16 +515,14 @@ pub trait Memory {
520515

521516
impl Memory for [u8] {
522517
fn read_le_u64(&self, ptr: u32) -> Result<u64, Error> {
523-
let range =
524-
heap_range(ptr, 8, self.len()).ok_or_else(|| error("read out of heap bounds"))?;
518+
let range = heap_range(ptr, 8, self.len()).ok_or_else(|| Error::Other)?;
525519
let bytes = self[range]
526520
.try_into()
527521
.expect("[u8] slice of length 8 must be convertible to [u8; 8]");
528522
Ok(u64::from_le_bytes(bytes))
529523
}
530524
fn write_le_u64(&mut self, ptr: u32, val: u64) -> Result<(), Error> {
531-
let range =
532-
heap_range(ptr, 8, self.len()).ok_or_else(|| error("write out of heap bounds"))?;
525+
let range = heap_range(ptr, 8, self.len()).ok_or_else(|| Error::Other)?;
533526
let bytes = val.to_le_bytes();
534527
self[range].copy_from_slice(&bytes[..]);
535528
Ok(())

lib/src/executor/host.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,7 @@ enum MemAccessVm<'a> {
41444144
impl<'a> allocator::Memory for MemAccess<'a> {
41454145
fn read_le_u64(&self, ptr: u32) -> Result<u64, allocator::Error> {
41464146
if (ptr + 8) > u32::from(self.memory_total_pages) * 64 * 1024 {
4147-
return Err(allocator::Error::Other("out of bounds access"));
4147+
return Err(allocator::Error::Other);
41484148
}
41494149

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

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

42214221
let bytes = val.to_le_bytes();

light-base/src/json_rpc_service.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct Config<TPlat: PlatformRef> {
7171
/// This parameter is necessary in order to prevent users from using up too much memory within
7272
/// the client.
7373
// TODO: unused at the moment
74+
#[allow(unused)]
7475
pub max_pending_requests: NonZeroU32,
7576

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

8486
/// Access to the network, and identifier of the chain from the point of view of the network

0 commit comments

Comments
 (0)