Page MenuHomePhabricator

[Chronik] Add fallible `Hashed` methods for parsing byte slices and hex string
ClosedPublic

Authored by tobias_ruck on Jul 5 2022, 19:16.

Details

Summary

Parsing hashes from byte slices and hex strings is fallible, add methods that parse them with proper error handling.

Errors are provided through thiserror, which builds us an error enum with Display implementations.

Test Plan

ninja check-bitcoinsuite

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Tail of the build log:

-- Performing Test have_C__std_c89 - Success
-- Performing Test have_C__Wno_long_long
-- Performing Test have_C__Wno_long_long - Success
-- Performing Test have_C__Wno_duplicated_branches
-- Performing Test have_C__Wno_duplicated_branches - Success
-- Performing Test USE_ASM_X86_64
-- Performing Test USE_ASM_X86_64 - Success
-- Found Event component event: /usr/lib/x86_64-linux-gnu/libevent.so
-- Found Event: /usr/include (found suitable version "2.1.8-stable", minimum required is "2.0.22") found components: event 
-- Found Boost: /usr/include (found suitable version "1.67.0", minimum required is "1.59") found components: filesystem system 
-- Found Boost: /usr/include (found suitable version "1.67.0", minimum required is "1.59") found components: thread chrono system date_time atomic 
-- Found Event component pthreads: /usr/lib/x86_64-linux-gnu/libevent_pthreads.so
-- Found Event: /usr/include (found suitable version "2.1.8-stable", minimum required is "2.0.22") found components: pthreads 
-- Found MiniUPnPc component miniupnpc: /usr/lib/x86_64-linux-gnu/libminiupnpc.so
-- Found MiniUPnPc: /usr/include/miniupnpc (found suitable version "2.1", minimum required is "1.9")  
-- Found Boost: /usr/include (found suitable version "1.67.0", minimum required is "1.59") found components: unit_test_framework 
-- Performing Test BOOST_REQUIRES_TEST_DYN_LINK
-- Performing Test BOOST_REQUIRES_TEST_DYN_LINK - Success
-- Found BerkeleyDB component CXX: /usr/lib/x86_64-linux-gnu/libdb_cxx.so
-- Found BerkeleyDB: /usr/include (found suitable version "5.3.28", minimum required is "5.3") found components: CXX 
-- Found SQLite3: /usr/include (found suitable version "3.27.2", minimum required is "3.7.17") 
-- Found ZeroMQ component zmq: /usr/lib/x86_64-linux-gnu/libzmq.so
-- Found ZeroMQ: /usr/include (found suitable version "4.3.1", minimum required is "4.1.5")  
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-pthread (found version "3.6.1") 
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1n")  
-- Looking for EVP_MD_CTX_new
-- Looking for EVP_MD_CTX_new - found
-- Found QREncode component qrencode: /usr/lib/x86_64-linux-gnu/libqrencode.so
-- Found QREncode: /usr/include   
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.61.0 (fe5b13d68 2022-05-18)`
-- Rust Toolchain: 1.61.0-x86_64-unknown-linux-gnu
-- Rust Target: x86_64-unknown-linux-gnu
-- Found Rust: /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc (found version "1.61.0") 
-- Configuring native build in /work/abc-ci-builds/build-chronik/native
-- Configuring done
-- Generating done
-- Build files have been written to: /work/abc-ci-builds/build-chronik
[1/2] cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo test --package bitcoinsuite-*
FAILED: chronik/CMakeFiles/check-bitcoinsuite-test 
cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo test --package bitcoinsuite-*
error: failed to load manifest for workspace member `/work/chronik/bitcoinsuite-error`

Caused by:
  failed to read `/work/chronik/bitcoinsuite-error/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
[2/2] cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo clippy --package bitcoinsuite-* -- -D warnings
FAILED: chronik/CMakeFiles/check-bitcoinsuite-clippy 
cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo clippy --package bitcoinsuite-* -- -D warnings
error: failed to load manifest for workspace member `/work/chronik/bitcoinsuite-error`

Caused by:
  failed to read `/work/chronik/bitcoinsuite-error/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik failed with exit code 1

Tail of the build log:

-- Rust Target: x86_64-unknown-linux-gnu
-- Found Rust: /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc (found version "1.61.0") 
-- Configuring native build in /work/abc-ci-builds/build-chronik/native
-- Configuring done
-- Generating done
-- Build files have been written to: /work/abc-ci-builds/build-chronik
[1/2] cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo test --package bitcoinsuite-*
FAILED: chronik/CMakeFiles/check-bitcoinsuite-test 
cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo test --package bitcoinsuite-*
 Downloading crates ...
  Downloaded thiserror v1.0.31
  Downloaded thiserror-impl v1.0.31
  Downloaded hex-literal v0.3.4
  Downloaded quote v1.0.20
  Downloaded unicode-ident v1.0.1
  Downloaded hex v0.4.3
  Downloaded syn v1.0.98
  Downloaded proc-macro2 v1.0.40
    Blocking waiting for file lock on package cache
   Compiling proc-macro2 v1.0.40
   Compiling quote v1.0.20
   Compiling unicode-ident v1.0.1
   Compiling syn v1.0.98
   Compiling hex v0.4.3
   Compiling hex-literal v0.3.4
   Compiling thiserror-impl v1.0.31
   Compiling thiserror v1.0.31
   Compiling bitcoinsuite-core v0.1.0 (/work/chronik/bitcoinsuite-core)
error[E0583]: file not found for module `block`
  --> chronik/bitcoinsuite-core/src/lib.rs:37:1
   |
37 | pub mod block;
   | ^^^^^^^^^^^^^^
   |
   = help: to create the module `block`, create file "chronik/bitcoinsuite-core/src/block.rs" or "chronik/bitcoinsuite-core/src/block/mod.rs"

For more information about this error, try `rustc --explain E0583`.
error: could not compile `bitcoinsuite-core` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `bitcoinsuite-core` due to previous error
[2/2] cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo clippy --package bitcoinsuite-* -- -D warnings
FAILED: chronik/CMakeFiles/check-bitcoinsuite-clippy 
cd /work && /usr/bin/cmake -E env CARGO_TARGET_DIR="/work/abc-ci-builds/build-chronik/chronik/cargo/build" CARGO_BUILD_RUSTC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustc" CARGO_BUILD_RUSTDOC="/root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/rustdoc" /root/.rustup/toolchains/1.61.0-x86_64-unknown-linux-gnu/bin/cargo clippy --package bitcoinsuite-* -- -D warnings
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on build directory
    Checking hex v0.4.3
    Checking thiserror v1.0.31
    Checking bitcoinsuite-core v0.1.0 (/work/chronik/bitcoinsuite-core)
error[E0583]: file not found for module `block`
  --> chronik/bitcoinsuite-core/src/lib.rs:37:1
   |
37 | pub mod block;
   | ^^^^^^^^^^^^^^
   |
   = help: to create the module `block`, create file "chronik/bitcoinsuite-core/src/block.rs" or "chronik/bitcoinsuite-core/src/block/mod.rs"

For more information about this error, try `rustc --explain E0583`.
error: could not compile `bitcoinsuite-core` due to previous error
ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik failed with exit code 1
This revision is now accepted and ready to land.Jul 7 2022, 07:28