EpicCash / epic

Blockchain Node Server with integrated Stratum Mining Server
https://epiccash.com
Apache License 2.0
24 stars 36 forks source link

Resolve Compiler Warnings #108

Closed who-biz closed 9 months ago

who-biz commented 9 months ago

This, when combined with #106 and #107, resolves all displayed compiler warnings for our given dependency state.

We do have some areas of code that are missing docs. As a result, I commented out many #[warn(missing_docs)] directives in code.

All of these were performed in this commit (line highlighted for demonstration in diff): https://github.com/EpicCash/epic/commit/acc157ef481ac7be18a72e5eefd6be57a6620d80#diff-27f4d3db6f3d4186c01baf2c708602ed942e2c994e0aaf61f822c246ef477b5dR22

While not urgent, we should go through and uncomment each of these, and add docs that are missing.

Then, Epic can be published as a crate, for use by CypherStack and others, accompanied by worthy documentation.


Details on warnings these commits resolve:

  1. Update zip dep to 0.5.11, resolve deprecated function warnings https://github.com/EpicCash/epic/commit/3b584079a209007c5ac45b35453023844312fb3c
warning: use of deprecated method `zip::ZipWriter::<W>::start_file_from_path`: by stripping `..`s from the path, the meaning of paths can change. Use `start_file` instead.
  --> util/src/zip.rs:43:21
   |
43 |             writer.get_mut().start_file_from_path(x, options)?;
   |                              ^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated method `zip::read::ZipFile::<'a>::sanitized_name`: by stripping `..`s from the path, the meaning of paths can change.
                         `mangled_name` can be used if this behaviour is desirable
  --> util/src/zip.rs:63:31
   |
63 |                 let path = dest.join(file.sanitized_name());
   |                                           ^^^^^^^^^^^^^^

warning: use of deprecated method `zip::read::ZipFile::<'a>::sanitized_name`: by stripping `..`s from the path, the meaning of paths can change.
                         `mangled_name` can be used if this behaviour is desirable
   --> util/src/zip.rs:151:24
    |
151 |             let san_name = file.sanitized_name();
    |  

These changes were cross-referenced with Grin upstream, to emulate their choices of replacement functions.


  1. Various warnings resolution https://github.com/EpicCash/epic/commit/88743b1790527e0fa0eda0fc44ceda5fadbdd784:

in core/src/core/id.rs:

warning: unused doc comment
  --> core/src/core/id.rs:77:1
   |
77 | / /// We want to sort short_ids in a canonical and consistent manner so we can
78 | | /// verify sort order in the same way we do for full inputs|outputs|kernels
79 | | /// themselves.
   | |_--------------^
   |   |
   |   rustdoc does not generate documentation for macro invocations
   |
   = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
   = note: `#[warn(unused_doc_comments)]` on by default

in chain/src/store.rs:

warning: value assigned to `prev_header` is never read
   --> chain/src/store.rs:516:14
    |
516 |                     let mut prev_header = None;
    |                             ^^^^^^^^^^^
    |
    = help: maybe it is overwritten before being read?
    = note: `#[warn(unused_assignments)]` on by default

warning: value assigned to `prev_header` is never read
   --> chain/src/store.rs:759:14
    |
759 |                     let mut prev_header = None;
    |                             ^^^^^^^^^^^
    |
    = help: maybe it is overwritten before being read?

These were resolved by removing duplicate conditions that set prev_header = None. None is now default value, so we only populate it on successful if evaluation. else conditions are irrelevant here.

in src/bin/tui/mining.rs:

warning: variant `PowDifficulty` is never constructed
  --> src/bin/tui/mining.rs:44:2
   |
40 | enum StratumWorkerColumn {
   |      ------------------- variant in this enum
...
44 |     PowDifficulty,
   |     ^^^^^^^^^^^^^
   |
   = note: `StratumWorkerColumn` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

warning: variant `SecondaryScaling` is never constructed
   --> src/bin/tui/mining.rs:112:2
    |
107 | enum DiffColumn {
    |      ---------- variant in this enum
...
112 |     SecondaryScaling,
    |     ^^^^^^^^^^^^^^^^
    |

  1. Resolve deprecation warnings for DateTime, TimeZone functions https://github.com/EpicCash/epic/commit/4179d5b98bc3325115991c47147632e120ee2a19

There were a lot of these warnings to resolve, but they boil down to 2 separate ones, really. Examples provided below, but shown once for brevity.

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead
   --> src/bin/tui/mining.rs:134:43
    |
134 |         let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
    |                                                 ^^^^^^^^

warning: use of deprecated method `chrono::DateTime::<Tz>::timestamp_nanos`: use `timestamp_nanos_opt()` instead
  --> src/bin/tui/status.rs:66:35
   |
66 |                     let start = prev_update_time.timestamp_nanos();
   |